From 62126ee9ac6a51c8d023950e1a2a2d1d3823a4d7 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Thu, 22 Feb 2007 16:46:34 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@320 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../LocaisRealizacaoDataProvider.java | 60 ++++++++ .../LocaisRealizacaoWindow.java | 139 ++++++++++++++++++ 2 files changed, 199 insertions(+) diff --git a/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java b/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java index 9be19256..a2ae347b 100644 --- a/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java +++ b/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoDataProvider.java @@ -13,10 +13,12 @@ import com.evolute.utils.Singleton; import com.evolute.utils.arrays.Virtual2DArray; import com.evolute.utils.db.DBManager; import com.evolute.utils.db.Executer; +import com.evolute.utils.sql.Assignment; import com.evolute.utils.sql.Expression; import com.evolute.utils.sql.Field; import com.evolute.utils.sql.Select; import com.evolute.utils.sql.Select2; +import com.evolute.utils.sql.Update; import com.evolute.utils.tables.ColumnizedMappable; import java.util.Date; @@ -135,4 +137,62 @@ public class LocaisRealizacaoDataProvider return ( ( Number ) array.get( 0, 0 ) ).intValue(); } } + + public Integer[] getPrestadoresIDByEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data ) + throws Exception + { + Select select = + new Select2( + new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new Integer[]{ Select2.JOIN_INNER }, + new Expression[]{ + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) }, + new String[]{ "DISTINCT prestador_id" }, + new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( tipo ) ), + null, + null, + null, + null ); + Virtual2DArray array = EXECUTER.executeQuery( select ); + Integer ids[] = new Integer[ array.columnLength() ]; + for( int n = 0; n < ids.length; n++ ) + { + ids[ n ] = ( Integer ) array.get( n, 0 ); + } + return ids; + } + + public void setPrestadorIDForEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data, Integer prestadorID ) + throws Exception + { + Select select = + new Select2( + new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new Integer[]{ Select2.JOIN_INNER }, + new Expression[]{ + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) }, + new String[]{ "marcacoes_trabalhador.id" }, + new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( tipo ) ), + null, + null, + null, + null ); + Virtual2DArray array = EXECUTER.executeQuery( select ); +System.out.println( select + "\n\n\n" + array.columnLength() ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + Update update = + new Update( "marcacoes_trabalhador", + new Assignment[]{ + new Assignment( "prestador_id", prestadorID ) }, + new Field( "id" ).isEqual( id ) ); + EXECUTER.executeQuery( update ); +System.out.println( update ); + } + } } diff --git a/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoWindow.java b/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoWindow.java index 2e32d7e4..3fec87ea 100644 --- a/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoWindow.java +++ b/trunk/siprp/medicina/locais_realizacao/LocaisRealizacaoWindow.java @@ -39,6 +39,8 @@ import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import siprp.data.Marcacao; @@ -90,6 +92,7 @@ public class LocaisRealizacaoWindow extends JFrame setSize( 1000, 700 ); JLabel dataLabel = new JLabel( "Data" ); dataPanel = new JCalendarPanel( this ); + carregarButton = new JButton( "Carregar" ); carregarButton.addActionListener( this ); recarregarPrestadoresButton = new JButton( "Recarregar Prestadores" ); @@ -118,6 +121,15 @@ public class LocaisRealizacaoWindow extends JFrame prestadoresECDsCombo = new JComboBox(); enviarECDsButton = new JButton( "Atribuir" ); enviarECDsButton.addActionListener( this ); + dataPanel.addChangeListener( new ChangeListener(){ + public void stateChanged(ChangeEvent e) + { + empresasTable.clearSelection(); + Vector values = empresasModel.getValues(); + values.clear(); + empresasModel.setValues( values ); + } + } ); getContentPane().setLayout( new BorderLayout( 5, 5 ) ); JPanel upperPanel = new JPanel(); @@ -209,6 +221,15 @@ public class LocaisRealizacaoWindow extends JFrame { recarregarPrestadores(); } + else if( source.equals( enviarConsultasButton ) ) + { + enviarConsultas(); + } + else if( source.equals( enviarECDsButton ) ) + { + enviarECDs(); + } + } public void valueChanged(ListSelectionEvent e) @@ -302,11 +323,79 @@ public class LocaisRealizacaoWindow extends JFrame { numeroConsultasLabel.setText( "" + countConsultas ); enviarConsultasButton.setEnabled( true ); + Integer[] escolhidos = + provider.getPrestadoresIDByEstabelecimentoAndTipo( estabelecimentoID, + Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA, data ); + if( escolhidos.length == 1 ) + { + numeroConsultasLabel.setForeground( Color.green.darker() ); + } + else + { + numeroConsultasLabel.setForeground( Color.red.darker() ); + } + int e; + for( e = 0; e < escolhidos.length; e++ ) + { + if( escolhidos[ e ] != null ) + { + break; + } + } + if( e == escolhidos.length || escolhidos[ e ] == null ) + { + prestadoresConsultasCombo.setSelectedIndex( 0 ); + } + else + { + for( int p = 0; p < prestadoresConsultasCombo.getItemCount(); p++ ) + { + IDObject prestador = ( IDObject ) prestadoresConsultasCombo.getItemAt( p ); + if( prestador.getID().equals( escolhidos[ e ] ) ) + { + prestadoresConsultasCombo.setSelectedIndex( p ); + } + } + } } if( countECDs > 0 ) { numeroECDsLabel.setText( "" + countECDs ); enviarECDsButton.setEnabled( true ); + Integer[] escolhidos = + provider.getPrestadoresIDByEstabelecimentoAndTipo( estabelecimentoID, + Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES, data ); + if( escolhidos.length == 1 ) + { + numeroECDsLabel.setForeground( Color.green.darker() ); + } + else + { + numeroECDsLabel.setForeground( Color.red.darker() ); + } + int e; + for( e = 0; e < escolhidos.length; e++ ) + { + if( escolhidos[ e ] != null ) + { + break; + } + } + if( e == escolhidos.length || escolhidos[ e ] == null ) + { + prestadoresECDsCombo.setSelectedIndex( 0 ); + } + else + { + for( int p = 0; p < prestadoresECDsCombo.getItemCount(); p++ ) + { + IDObject prestador = ( IDObject ) prestadoresECDsCombo.getItemAt( p ); + if( prestador.getID().equals( escolhidos[ e ] ) ) + { + prestadoresECDsCombo.setSelectedIndex( e ); + } + } + } } } catch( Exception ex ) @@ -339,4 +428,54 @@ public class LocaisRealizacaoWindow extends JFrame DialogException.showExceptionMessage( ex, "Erro a carregar prestadores", true ); } } + + protected void enviarECDs() + { + Date data = dataPanel.getDate(); + int selectedEstabelecimento = estabelecimentosTable.getSelectedRow(); + if( data == null || selectedEstabelecimento == -1 ) + { + return; + } + Integer estabelecimentoID = ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( selectedEstabelecimento ) ).getID(); + try + { + Integer prestadorID = ( ( IDObject ) prestadoresECDsCombo.getSelectedItem() ).getID(); + if( PRESTADOR_ID_SIPRP.equals( prestadorID ) ) + { + prestadorID = null; + } + provider.setPrestadorIDForEstabelecimentoAndTipo( estabelecimentoID, + Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES, data, prestadorID ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a atribuir", true ); + } + } + + protected void enviarConsultas() + { + Date data = dataPanel.getDate(); + int selectedEstabelecimento = estabelecimentosTable.getSelectedRow(); + if( data == null || selectedEstabelecimento == -1 ) + { + return; + } + Integer estabelecimentoID = ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( selectedEstabelecimento ) ).getID(); + try + { + Integer prestadorID = ( ( IDObject ) prestadoresConsultasCombo.getSelectedItem() ).getID(); + if( PRESTADOR_ID_SIPRP.equals( prestadorID ) ) + { + prestadorID = null; + } + provider.setPrestadorIDForEstabelecimentoAndTipo( estabelecimentoID, + Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA, data, prestadorID ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a atribuir", true ); + } + } }