From 330c1f1a09cbf8c298b4464509ce002ea8bf1ff6 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 15 May 2006 17:14:09 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@259 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/alter3.sql | 32 + trunk/build.xml | 90 ++ trunk/jpox.bat | 5 + trunk/jpox.sh | 5 + trunk/siprp/clientes/AvisosPanel.java | 576 +++++++ .../siprp/clientes/ClientesDataProvider.java | 197 +++ trunk/siprp/clientes/ClientesWindow.java | 1433 +++++++++++++++++ trunk/siprp/clientes/ContactoPanel.java | 181 +++ trunk/siprp/clientes/EmpresaPanel.java | 933 +++++++++++ .../siprp/clientes/EstabelecimentoPanel.java | 450 ++++++ .../siprp/clientes/EtiquetaChooserDialog.java | 89 + trunk/siprp/clientes/EtiquetaPrinter.java | 200 +++ .../HistoricoEstabelecimentoPanel.java | 272 ++++ .../siprp/clientes/MarcacaoEmpresaPanel.java | 287 ++++ trunk/siprp/clientes/MarcacaoPanel.java | 625 +++++++ .../siprp/clientes/NoticiasDataProvider.java | 96 ++ trunk/siprp/clientes/NoticiasDialog.java | 101 ++ .../siprp/clientes/PerfilProtocoloPanel.java | 153 ++ trunk/siprp/clientes/ProtocoloPanel.java | 111 ++ trunk/siprp/clientes/TrabalhadorPanel.java | 611 +++++++ trunk/siprp/clientes/UserDataProvider.java | 156 ++ trunk/siprp/clientes/UserPanel.java | 232 +++ trunk/siprp/clientes/UserWindow.java | 66 + trunk/siprp/clientes/etiqueta.xsl | 91 ++ trunk/siprp/clientes/etiquetas.dtd | 16 + trunk/siprp/data/ActualizacaoSaveHandler.java | 51 + trunk/siprp/data/ActualizacaoSaveable.java | 16 + trunk/siprp/data/Aviso.java | 186 +++ trunk/siprp/data/AvisoConstants.java | 18 + trunk/siprp/data/AvisoData.java | 68 + trunk/siprp/data/AvisoID.java | 22 + trunk/siprp/data/Contacto.java | 152 ++ trunk/siprp/data/ContactoData.java | 63 + trunk/siprp/data/ContactoID.java | 22 + trunk/siprp/data/DisableDeleteHandler.java | 70 + trunk/siprp/data/DisableDeleteable.java | 16 + trunk/siprp/data/Empresa.java | 713 ++++++++ trunk/siprp/data/EmpresaData.java | 111 ++ trunk/siprp/data/EmpresaID.java | 25 + trunk/siprp/data/Estabelecimento.java | 220 +++ trunk/siprp/data/EstabelecimentoData.java | 69 + trunk/siprp/data/EstabelecimentoID.java | 25 + trunk/siprp/data/Etiqueta.java | 270 ++++ trunk/siprp/data/EtiquetaData.java | 74 + trunk/siprp/data/EtiquetaID.java | 25 + trunk/siprp/data/Exame.java | 305 ++++ trunk/siprp/data/ExameData.java | 77 + trunk/siprp/data/ExameID.java | 22 + trunk/siprp/data/Historico.java | 58 + .../siprp/data/HistoricoEstabelecimento.java | 101 ++ .../data/HistoricoEstabelecimentoData.java | 60 + .../data/HistoricoEstabelecimentoID.java | 22 + trunk/siprp/data/Marcacao.java | 345 ++++ trunk/siprp/data/MarcacaoEmpresa.java | 118 ++ trunk/siprp/data/MarcacaoEmpresaData.java | 61 + trunk/siprp/data/MarcacaoEmpresaID.java | 22 + trunk/siprp/data/MarcacaoEstabelecimento.java | 186 +++ .../data/MarcacaoEstabelecimentoData.java | 67 + .../siprp/data/MarcacaoEstabelecimentoID.java | 25 + trunk/siprp/data/MarcacaoListLoader.java | 80 + .../data/MarcacaoSaveAndDeleteHandler.java | 258 +++ trunk/siprp/data/MarcacaoTrabalhador.java | 203 +++ .../data/MarcacaoTrabalhadorConstants.java | 17 + trunk/siprp/data/MarcacaoTrabalhadorData.java | 69 + trunk/siprp/data/MarcacaoTrabalhadorID.java | 25 + trunk/siprp/data/Medico.java | 100 ++ trunk/siprp/data/MedicoData.java | 61 + trunk/siprp/data/MedicoID.java | 22 + trunk/siprp/data/SearchExecuterFactory.java | 180 +++ trunk/siprp/data/TecnicoHST.java | 134 ++ trunk/siprp/data/TecnicoHSTData.java | 63 + trunk/siprp/data/TecnicoHSTID.java | 25 + trunk/siprp/data/Trabalhador.java | 356 ++++ trunk/siprp/data/TrabalhadorData.java | 82 + trunk/siprp/data/TrabalhadorID.java | 25 + trunk/siprp/data/package.jdo | 1104 +++++++++++++ .../estatistica/EstatisticaDataProvider.java | 777 +++++++++ .../siprp/estatistica/EstatisticaWindow.java | 1323 +++++++++++++++ trunk/siprp/higiene/HigieneDataProvider.java | 255 +++ trunk/siprp/higiene/alter2.sql | 18 + trunk/siprp/higiene/mapa/DiaLine.java | 62 + trunk/siprp/higiene/mapa/DiaPanel.java | 101 ++ trunk/siprp/higiene/mapa/DiaRenderer.java | 65 + .../siprp/higiene/mapa/MapaHigienePanel.java | 112 ++ .../siprp/higiene/mapa/MapaHigieneWindow.java | 139 ++ trunk/siprp/higiene/mapa/TecnicosPanel.java | 63 + .../marcacoes/CorTecnicoCellRenderer.java | 41 + .../marcacoes/MarcacaoVisitaHSTPanel.java | 306 ++++ .../marcacoes/MarcacaoVisitaHSTPanel.xml | 93 ++ .../marcacoes/MarcacoesHigieneUpperPanel.java | 199 +++ .../marcacoes/MarcacoesHigieneWindow.java | 519 ++++++ .../higiene/marcacoes/TecnicoEditor.java | 317 ++++ .../higiene/marcacoes/TecnicoRenderer.java | 58 + .../siprp/impressaofichas/FichasPrinter.java | 146 ++ .../ImpressaoFichasDataProvider.java | 217 +++ .../ImpressaoFichasWindow.java | 421 +++++ trunk/siprp/impressaofichas/lista_fichas.xsl | 74 + trunk/siprp/pesquisas/PesquisasProvider.java | 751 +++++++++ trunk/siprp/pesquisas/PesquisasWindow.java | 578 +++++++ trunk/siprp/web/WebUpdater.java | 1210 ++++++++++++++ trunk/siprp_create.sql | 569 +++++++ trunk/updtprop.txt | 7 + 102 files changed, 21918 insertions(+) create mode 100644 trunk/alter3.sql create mode 100644 trunk/build.xml create mode 100644 trunk/jpox.bat create mode 100644 trunk/jpox.sh create mode 100644 trunk/siprp/clientes/AvisosPanel.java create mode 100644 trunk/siprp/clientes/ClientesDataProvider.java create mode 100644 trunk/siprp/clientes/ClientesWindow.java create mode 100644 trunk/siprp/clientes/ContactoPanel.java create mode 100644 trunk/siprp/clientes/EmpresaPanel.java create mode 100644 trunk/siprp/clientes/EstabelecimentoPanel.java create mode 100644 trunk/siprp/clientes/EtiquetaChooserDialog.java create mode 100644 trunk/siprp/clientes/EtiquetaPrinter.java create mode 100644 trunk/siprp/clientes/HistoricoEstabelecimentoPanel.java create mode 100644 trunk/siprp/clientes/MarcacaoEmpresaPanel.java create mode 100644 trunk/siprp/clientes/MarcacaoPanel.java create mode 100644 trunk/siprp/clientes/NoticiasDataProvider.java create mode 100644 trunk/siprp/clientes/NoticiasDialog.java create mode 100644 trunk/siprp/clientes/PerfilProtocoloPanel.java create mode 100644 trunk/siprp/clientes/ProtocoloPanel.java create mode 100644 trunk/siprp/clientes/TrabalhadorPanel.java create mode 100644 trunk/siprp/clientes/UserDataProvider.java create mode 100644 trunk/siprp/clientes/UserPanel.java create mode 100644 trunk/siprp/clientes/UserWindow.java create mode 100644 trunk/siprp/clientes/etiqueta.xsl create mode 100644 trunk/siprp/clientes/etiquetas.dtd create mode 100644 trunk/siprp/data/ActualizacaoSaveHandler.java create mode 100644 trunk/siprp/data/ActualizacaoSaveable.java create mode 100644 trunk/siprp/data/Aviso.java create mode 100644 trunk/siprp/data/AvisoConstants.java create mode 100644 trunk/siprp/data/AvisoData.java create mode 100644 trunk/siprp/data/AvisoID.java create mode 100644 trunk/siprp/data/Contacto.java create mode 100644 trunk/siprp/data/ContactoData.java create mode 100644 trunk/siprp/data/ContactoID.java create mode 100644 trunk/siprp/data/DisableDeleteHandler.java create mode 100644 trunk/siprp/data/DisableDeleteable.java create mode 100644 trunk/siprp/data/Empresa.java create mode 100644 trunk/siprp/data/EmpresaData.java create mode 100644 trunk/siprp/data/EmpresaID.java create mode 100644 trunk/siprp/data/Estabelecimento.java create mode 100644 trunk/siprp/data/EstabelecimentoData.java create mode 100644 trunk/siprp/data/EstabelecimentoID.java create mode 100644 trunk/siprp/data/Etiqueta.java create mode 100644 trunk/siprp/data/EtiquetaData.java create mode 100644 trunk/siprp/data/EtiquetaID.java create mode 100644 trunk/siprp/data/Exame.java create mode 100644 trunk/siprp/data/ExameData.java create mode 100644 trunk/siprp/data/ExameID.java create mode 100644 trunk/siprp/data/Historico.java create mode 100644 trunk/siprp/data/HistoricoEstabelecimento.java create mode 100644 trunk/siprp/data/HistoricoEstabelecimentoData.java create mode 100644 trunk/siprp/data/HistoricoEstabelecimentoID.java create mode 100644 trunk/siprp/data/Marcacao.java create mode 100644 trunk/siprp/data/MarcacaoEmpresa.java create mode 100644 trunk/siprp/data/MarcacaoEmpresaData.java create mode 100644 trunk/siprp/data/MarcacaoEmpresaID.java create mode 100644 trunk/siprp/data/MarcacaoEstabelecimento.java create mode 100644 trunk/siprp/data/MarcacaoEstabelecimentoData.java create mode 100644 trunk/siprp/data/MarcacaoEstabelecimentoID.java create mode 100644 trunk/siprp/data/MarcacaoListLoader.java create mode 100644 trunk/siprp/data/MarcacaoSaveAndDeleteHandler.java create mode 100644 trunk/siprp/data/MarcacaoTrabalhador.java create mode 100644 trunk/siprp/data/MarcacaoTrabalhadorConstants.java create mode 100644 trunk/siprp/data/MarcacaoTrabalhadorData.java create mode 100644 trunk/siprp/data/MarcacaoTrabalhadorID.java create mode 100644 trunk/siprp/data/Medico.java create mode 100644 trunk/siprp/data/MedicoData.java create mode 100644 trunk/siprp/data/MedicoID.java create mode 100644 trunk/siprp/data/SearchExecuterFactory.java create mode 100644 trunk/siprp/data/TecnicoHST.java create mode 100644 trunk/siprp/data/TecnicoHSTData.java create mode 100644 trunk/siprp/data/TecnicoHSTID.java create mode 100644 trunk/siprp/data/Trabalhador.java create mode 100644 trunk/siprp/data/TrabalhadorData.java create mode 100644 trunk/siprp/data/TrabalhadorID.java create mode 100644 trunk/siprp/data/package.jdo create mode 100644 trunk/siprp/estatistica/EstatisticaDataProvider.java create mode 100644 trunk/siprp/estatistica/EstatisticaWindow.java create mode 100644 trunk/siprp/higiene/HigieneDataProvider.java create mode 100644 trunk/siprp/higiene/alter2.sql create mode 100644 trunk/siprp/higiene/mapa/DiaLine.java create mode 100644 trunk/siprp/higiene/mapa/DiaPanel.java create mode 100644 trunk/siprp/higiene/mapa/DiaRenderer.java create mode 100644 trunk/siprp/higiene/mapa/MapaHigienePanel.java create mode 100644 trunk/siprp/higiene/mapa/MapaHigieneWindow.java create mode 100644 trunk/siprp/higiene/mapa/TecnicosPanel.java create mode 100644 trunk/siprp/higiene/marcacoes/CorTecnicoCellRenderer.java create mode 100644 trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java create mode 100644 trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.xml create mode 100644 trunk/siprp/higiene/marcacoes/MarcacoesHigieneUpperPanel.java create mode 100644 trunk/siprp/higiene/marcacoes/MarcacoesHigieneWindow.java create mode 100644 trunk/siprp/higiene/marcacoes/TecnicoEditor.java create mode 100644 trunk/siprp/higiene/marcacoes/TecnicoRenderer.java create mode 100644 trunk/siprp/impressaofichas/FichasPrinter.java create mode 100644 trunk/siprp/impressaofichas/ImpressaoFichasDataProvider.java create mode 100644 trunk/siprp/impressaofichas/ImpressaoFichasWindow.java create mode 100644 trunk/siprp/impressaofichas/lista_fichas.xsl create mode 100644 trunk/siprp/pesquisas/PesquisasProvider.java create mode 100644 trunk/siprp/pesquisas/PesquisasWindow.java create mode 100644 trunk/siprp/web/WebUpdater.java create mode 100644 trunk/siprp_create.sql create mode 100644 trunk/updtprop.txt diff --git a/trunk/alter3.sql b/trunk/alter3.sql new file mode 100644 index 00000000..4bfea09d --- /dev/null +++ b/trunk/alter3.sql @@ -0,0 +1,32 @@ +UPDATE trabalhadores SET perfil=1 WHERE perfil IS NULL; +UPDATE marcacoes_trabalhador SET motivo = + ( SELECT tipo FROM exames WHERE exames.trabalhador_id = marcacoes_trabalhador.trabalhador_id AND + exames.data = marcacoes_trabalhador.data ) +WHERE motivo IS NULL AND realizada = 'y'; + +CREATE TABLE etiquetas +( + id serial NOT NULL, + descricao varchar(255) NOT NULL, + descricao_plain varchar, + altura float4, + largura float4, + margem_esquerda float4, + margem_cima float4, + colunas int4, + linhas int4, + continua char(1) NOT NULL DEFAULT 'n'::bpchar, + altura_folha float4, + largura_folha float4, + margem_vertical_folha float4, + margem_horizontal_folha float4, + CONSTRAINT etiquetas_pkey PRIMARY KEY (id) +) +WITHOUT OIDS; +ALTER TABLE etiquetas OWNER TO postgres; + +ALTER TABLE estabelecimentos ADD medico_id int4 REFERENCES medicos( id ); + +insert into etiquetas ( descricao, descricao_plain, altura, largura, margem_esquerda, margem_cima, colunas, linhas, continua, altura_folha, largura_folha, + margem_horizontal_folha, margem_vertical_folha ) + values( 'Etiquetas em folha A4', 'etiquetas em folha a4', 3.7125, 10.5, 0.0, 0.0, 2, 8, 'n', 29.7, 21.0, 0.7, 0.5 ); \ No newline at end of file diff --git a/trunk/build.xml b/trunk/build.xml new file mode 100644 index 00000000..d0a1900e --- /dev/null +++ b/trunk/build.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/jpox.bat b/trunk/jpox.bat new file mode 100644 index 00000000..ee741b8b --- /dev/null +++ b/trunk/jpox.bat @@ -0,0 +1,5 @@ +cd build +cd classes +java -cp .;../../evutils;../../jpox;../../jpox/jpox-1.0.4.jar;../../jpox/jpox-enhancer-1.0.4.jar;../../jars/log4j-1.2.8.jar;../../jdo/jdo.jar;../../jdo;../../jpox/bcel-5.1.jar org.jpox.enhancer.JPOXEnhancer siprp/data/package.jdo +cd .. +cd .. \ No newline at end of file diff --git a/trunk/jpox.sh b/trunk/jpox.sh new file mode 100644 index 00000000..9359f31e --- /dev/null +++ b/trunk/jpox.sh @@ -0,0 +1,5 @@ +cd build +cd classes +java -cp .:../../evutils:../../jpox:../../jpox/jpox-1.0.4.jar:../../jpox/jpox-enhancer-1.0.4.jar:../../jars/log4j-1.2.8.jar:../../jdo/jdo.jar:../../jdo:../../jpox/bcel-5.1.jar org.jpox.enhancer.JPOXEnhancer siprp/data/package.jdo +cd .. +cd .. \ No newline at end of file diff --git a/trunk/siprp/clientes/AvisosPanel.java b/trunk/siprp/clientes/AvisosPanel.java new file mode 100644 index 00000000..2f37826e --- /dev/null +++ b/trunk/siprp/clientes/AvisosPanel.java @@ -0,0 +1,576 @@ +/* + * AvisosPanel.java + * + * Created on 21 de Maio de 2004, 13:06 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import java.text.*; +import java.util.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.ui.*; + +import siprp.*; +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class AvisosPanel extends JPanel + implements ActionListener, ControllableComponent +{ + private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT ); + private JDOProvider JDO; + private FichaDataProvider provider; + private SIPRPTracker tracker; + + private JPanel empresaPanel; + private JPanel estabelecimentosPanel; + private JPanel trabalhadoresPanel; + +// private AvisoData avisos[]; +// private AvisoData avisosEmpresa[]; +// private AvisoData avisosEstabelecimento[]; +// private AvisoData avisosTrabalhador[]; + + private Object avisosEmpresa[][]; + private Object avisosEstabelecimento[][]; + private Object avisosTrabalhador[][]; + + private boolean refreshed = false; + + private Hashtable buttonHash; + private Hashtable buttonTypeHash; + + /** Creates a new instance of AvisosPanel */ + public AvisosPanel(/* AvisoData avisosEmpresa[], AvisoData avisosEstabelecimento[], AvisoData avisosTrabalhador[]*/ ) + throws Exception + { +// this.avisosEmpresa = new AvisoData[ 0 ]; +// this.avisosEstabelecimento = new AvisoData[ 0 ]; +// this.avisosTrabalhador = new AvisoData[ 0 ]; +// setupComponents(); + buttonHash = new Hashtable(); + buttonTypeHash = new Hashtable(); + JDO = (JDOProvider) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); +// System.out.println( "public AvisosPanel() JDO: " + JDO ); + } + + private void setupComponents() + { + empresaPanel = new JPanel(); + empresaPanel.setBorder( + BorderFactory.createTitledBorder( + BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Empresas" ) ); + empresaPanel.setLayout( new GridLayout( avisosEmpresa.length, 1 ) ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + for( int n = 0; n < avisosEmpresa.length; n++ ) + { + JPanel pan = new JPanel(); + GridBagLayout gridbag = new GridBagLayout(); + pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); +// EmpresaData empresa = (EmpresaData)avisosEmpresa[ n ].get( AvisoData.EMPRESA ); + pan.setLayout( gridbag ); + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridx = 0; + constraints.weightx = 0; + constraints.gridwidth = 1; + JButton tratarButton = new JButton( "Tratar" ); + gridbag.setConstraints( tratarButton, constraints ); + pan.add( tratarButton ); + //buttonHash.put( tratarButton, avisosEmpresa[ n ] ); +// buttonHash.put( tratarButton, new Integer( n ) ); +// buttonHash.put( tratarButton, avisosEmpresa[ n ].get( AvisoData.ID ) ); + buttonHash.put( tratarButton, avisosEmpresa[ n ][ 0 ] ); + buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_EMPRESA ) ); + tratarButton.addActionListener( this ); + + constraints.gridx = 1; + constraints.weightx = 1; + constraints.gridheight = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; +// JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + JLabel empresaLabel = new JLabel( "" + avisosEmpresa[ n ][ 3 ] ); + gridbag.setConstraints( empresaLabel, constraints ); + pan.add( empresaLabel ); + + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + //JLabel descricaoLabel = new JLabel( (String)avisosEmpresa[ n ].get( AvisoData.DESCRICAO ) ); + JLabel descricaoLabel = criarDescricao( avisosEmpresa[ n ] ); + gridbag.setConstraints( descricaoLabel, constraints ); + pan.add( descricaoLabel ); + + empresaPanel.add( pan ); + } + + estabelecimentosPanel = new JPanel(); + estabelecimentosPanel.setBorder( + BorderFactory.createTitledBorder( + BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Estabelecimentos" ) ); + estabelecimentosPanel.setLayout( new GridLayout( avisosEstabelecimento.length, 1 ) ); + + for( int n = 0; n < avisosEstabelecimento.length; n++ ) + { + Date dataAviso = ( Date ) avisosEstabelecimento[ n ][ 5 ]; + Date dataEvento = ( Date ) avisosEstabelecimento[ n ][ 1 ]; + Calendar calAviso = Calendar.getInstance(); + calAviso.setTime( dataAviso ); + Calendar calEvento = Calendar.getInstance(); + calEvento.setTime( dataEvento ); + boolean mesmoDia = + ( calAviso.get( Calendar.YEAR ) == calEvento.get( Calendar.YEAR ) ) && + ( calAviso.get( Calendar.MONTH ) == calEvento.get( Calendar.MONTH ) ) && + ( calAviso.get( Calendar.DAY_OF_MONTH ) == calEvento.get( Calendar.DAY_OF_MONTH ) ); + JPanel pan = new JPanel(); + GridBagLayout gridbag = new GridBagLayout(); + pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); +// EstabelecimentoData estabelecimento = (EstabelecimentoData)avisosEstabelecimento[ n ].get( AvisoData.ESTABELECIMENTO ); +// EmpresaData empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA ); + pan.setLayout( gridbag ); + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridx = 0; + constraints.weightx = 0; + constraints.gridwidth = 1; + JButton tratarButton = new JButton( mesmoDia ? "Confirmar" : "Marcar" ); + gridbag.setConstraints( tratarButton, constraints ); + pan.add( tratarButton ); + //buttonHash.put( tratarButton, avisosEstabelecimento[ n ] ); +// buttonHash.put( tratarButton, new Integer( n + avisosEmpresa.length ) ); +// buttonHash.put( tratarButton, avisosEstabelecimento[ n ].get( AvisoData.ID ) ); + buttonHash.put( tratarButton, avisosEstabelecimento[ n ][ 0 ] ); + buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_ESTABELECIMENTO ) ); + tratarButton.addActionListener( this ); + + constraints.gridx = 1; + constraints.weightx = 1; + constraints.gridheight = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; +// JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + JLabel empresaLabel = new JLabel( "" + avisosEstabelecimento[ n ][ 3 ] ); + gridbag.setConstraints( empresaLabel, constraints ); + pan.add( empresaLabel ); + +// JLabel estabelecimentoLabel = new JLabel( "" + estabelecimento.get( EstabelecimentoData.NOME ) ); + JLabel estabelecimentoLabel = new JLabel( "" + avisosEstabelecimento[ n ][ 4 ] ); + gridbag.setConstraints( estabelecimentoLabel, constraints ); + pan.add( estabelecimentoLabel ); + + constraints.gridwidth = GridBagConstraints.REMAINDER; + //JLabel descricaoLabel = new JLabel( (String)avisosEstabelecimento[ n ].get( AvisoData.DESCRICAO ) ); + JLabel descricaoLabel = criarDescricao( avisosEstabelecimento[ n ] ); + gridbag.setConstraints( descricaoLabel, constraints ); + pan.add( descricaoLabel ); + + estabelecimentosPanel.add( pan ); + } + + trabalhadoresPanel = new JPanel(); + trabalhadoresPanel.setBorder( + BorderFactory.createTitledBorder( + BorderFactory.createLineBorder( new Color( 0.0f, 0.0f, 0.0f, 0.0f ), 1 ), "Trabalhadores" ) ); + trabalhadoresPanel.setLayout( new GridLayout( avisosTrabalhador.length, 1 ) ); + + for( int n = 0; n < avisosTrabalhador.length; n++ ) + { + Date dataAviso = ( Date ) avisosTrabalhador[ n ][ 6 ]; + Date dataEvento = ( Date ) avisosTrabalhador[ n ][ 1 ]; + Calendar calAviso = Calendar.getInstance(); + calAviso.setTime( dataAviso ); + Calendar calEvento = Calendar.getInstance(); + calEvento.setTime( dataEvento ); + boolean mesmoDia = + ( calAviso.get( Calendar.YEAR ) == calEvento.get( Calendar.YEAR ) ) && + ( calAviso.get( Calendar.MONTH ) == calEvento.get( Calendar.MONTH ) ) && + ( calAviso.get( Calendar.DAY_OF_MONTH ) == calEvento.get( Calendar.DAY_OF_MONTH ) ); + JPanel pan = new JPanel(); + GridBagLayout gridbag = new GridBagLayout(); + pan.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); +// TrabalhadorData trabalhador = (TrabalhadorData)avisosTrabalhador[ n ].get( AvisoData.TRABALHADOR ); +// EstabelecimentoData estabelecimento = (EstabelecimentoData)trabalhador.get( TrabalhadorData.ESTABELECIMENTO ); +// EmpresaData empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA ); + pan.setLayout( gridbag ); + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridx = 0; + constraints.weightx = 0; + constraints.gridwidth = 1; + JButton tratarButton = new JButton( mesmoDia ? "Confirmar" : "Marcar" ); + gridbag.setConstraints( tratarButton, constraints ); + pan.add( tratarButton ); + //buttonHash.put( tratarButton, avisosTrabalhador[ n ] ); +// buttonHash.put( tratarButton, new Integer( n + avisosEmpresa.length + avisosEstabelecimento.length ) ); +// buttonHash.put( tratarButton, avisosTrabalhador[ n ].get( AvisoData.ID ) ); + buttonHash.put( tratarButton, avisosTrabalhador[ n ][ 0 ] ); + buttonTypeHash.put( tratarButton, new Integer( AvisoConstants.TIPO_TRABALHADOR ) ); + tratarButton.addActionListener( this ); + + constraints.gridx = 1; + constraints.weightx = 1; + constraints.gridheight = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; +// JLabel empresaLabel = new JLabel( "" + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + JLabel empresaLabel = new JLabel( "" + avisosTrabalhador[ n ][ 3 ] ); + gridbag.setConstraints( empresaLabel, constraints ); + pan.add( empresaLabel ); + +// JLabel estabelecimentoLabel = new JLabel( "" + estabelecimento.get( EstabelecimentoData.NOME ) ); + JLabel estabelecimentoLabel = new JLabel( "" + avisosTrabalhador[ n ][ 4 ] ); + gridbag.setConstraints( estabelecimentoLabel, constraints ); + pan.add( estabelecimentoLabel ); + +// JLabel trabalhadorLabel = new JLabel( "" + trabalhador.get( TrabalhadorData.NOME ) ); + JLabel trabalhadorLabel = new JLabel( "" + avisosTrabalhador[ n ][ 5 ] ); + gridbag.setConstraints( trabalhadorLabel, constraints ); + pan.add( trabalhadorLabel ); + constraints.gridwidth = GridBagConstraints.REMAINDER; + //JLabel descricaoLabel = new JLabel( (String)avisosTrabalhador[ n ].get( AvisoData.DESCRICAO ) ); + JLabel descricaoLabel = criarDescricao( avisosTrabalhador[ n ] ); + gridbag.setConstraints( descricaoLabel, constraints ); + pan.add( descricaoLabel ); + + trabalhadoresPanel.add( pan ); + } + +// Vector v = new Vector( Arrays.asList( avisosEmpresa ) ); +// v.addAll( Arrays.asList( avisosTrabalhador ) ); +// v.addAll( Arrays.asList( avisosEstabelecimento ) ); +// avisos = (AvisoData []) v.toArray( new AvisoData[0] ); + + JScrollPane scp = new JScrollPane(); + setLayout( new GridLayout( 1, 1 ) ); + add( scp ); + JPanel contentPanel = new JPanel(); + scp.setViewportView( contentPanel ); + contentPanel.setLayout( new BoxLayout( contentPanel, BoxLayout.Y_AXIS ) ); + if( avisosEmpresa.length > 0 ) + { + contentPanel.add( empresaPanel ); + } + if( avisosTrabalhador.length > 0 ) + { + contentPanel.add( new JLabel( " " ) ); + contentPanel.add( trabalhadoresPanel ); + } + if( avisosEstabelecimento.length > 0 ) + { + contentPanel.add( new JLabel( " " ) ); + contentPanel.add( estabelecimentosPanel ); + } + } + + public void refresh() + { + if( refreshed ) + { + return; + } + refreshed = true; + try + { + provider = ( FichaDataProvider ) FichaDataProvider.getProvider(); +// Collection c = AvisoData.load( AvisoData.class, " estabelecimento_id == \"null\" ", +// AvisoData.DATA_EVENTO + " ascending" ); + +// Collection c = AvisoData.load( AvisoData.class, "(tipo == " + AvisoData.TIPO_EMPRESA+")",// + ") && ( data_aviso <= CURRENT_DATE )", +// AvisoData.DATA_EVENTO + " ascending" ); +// Collection c = AvisoData.load( AvisoData.class, new Object[]{ /*new Integer( AvisoData.TIPO_EMPRESA ), */new Date() }, +// new String[]{ /*"tipo", */"data_aviso" }, +// new String[]{ "=="/*, "==" */}, +// new String[]{ AvisoData.DATA_EVENTO + " ascending" } ); + +// if( c == null ) +// { +// avisosEmpresa = new AvisoData[ 0 ]; +// } +// else +// { +// +// avisosEmpresa = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] ); +// } + +// Integer ids[] = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_EMPRESA ), new Date() ); +// avisosEmpresa = new AvisoData[ ids.length ]; +// if( JDO == null ) +// { +// JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); +// } +//// System.out.println( "JDO: " + JDO ); +// for( int n = 0; n < avisosEmpresa.length; n++ ) +// { +// avisosEmpresa[ n ] = (AvisoData) JDO.load( AvisoData.class, ids[ n ] ); +// } +// +////System.out.println( "EmpresaData " + avisosEmpresa.length ); +//// c = AvisoData.load( AvisoData.class, " tipo == " + AvisoData.TIPO_ESTABELECIMENTO,// + ") && ( data_aviso <= new Date() )", +//// AvisoData.DATA_EVENTO + " ascending" ); +//// c = AvisoData.load( AvisoData.class, "estabelecimento_id != \"null\" " +//// + " && trabalhador_id == \"null\"", AvisoData.DATA_EVENTO + " ascending" ); +//// if( c == null ) +//// { +//// avisosEstabelecimento = new AvisoData[ 0 ]; +//// } +//// else +//// { +//// avisosEstabelecimento = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] ); +//// } +// +// ids = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_ESTABELECIMENTO ), new Date() ); +// avisosEstabelecimento = new AvisoData[ ids.length ]; +// for( int n = 0; n < avisosEstabelecimento.length; n++ ) +// { +// avisosEstabelecimento[ n ] = (AvisoData) JDO.load( AvisoData.class, new Object[]{ids[ n ]}, new String[]{ "id" } ); +// } +////System.out.println( "EstabelecimentoData " + avisosEstabelecimento.length ); +//// c = AvisoData.load( AvisoData.class, " tipo == " + AvisoData.TIPO_TRABALHADOR,// + ") && ( data_aviso <= new Date() )", +//// AvisoData.DATA_EVENTO + " ascending" ); +//// c = AvisoData.load( AvisoData.class, "trabalhador_id != \"null\"", AvisoData.DATA_EVENTO + " ascending" ); +//// if( c == null ) +//// { +//// avisosTrabalhador = new AvisoData[ 0 ]; +//// } +//// else +//// { +//// avisosTrabalhador = ( AvisoData[] )c.toArray( new AvisoData[ c.size() ] ); +//// } +// ids = provider.getAvisosIDByTipoAndDate( new Integer( AvisoConstants.TIPO_TRABALHADOR ), new Date() ); +// +// avisosTrabalhador = new AvisoData[ ids.length ]; +// for( int n = 0; n < avisosTrabalhador.length; n++ ) +// { +// avisosTrabalhador[ n ] = (AvisoData) JDO.load( AvisoData.class, ids[ n ] ); +// } +//System.out.println( "trabalhador " + avisosTrabalhador.length ); + avisosEmpresa = provider.getAvisosEmpresaByDate( new Date() ); + avisosEstabelecimento = provider.getAvisosEstabelecimentoByDate( new Date() ); + avisosTrabalhador = provider.getAvisosTrabalhadorByDate( new Date() ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + setupComponents(); + setVisible( true ); + repaint(); + } + + private JLabel criarDescricao( Object aviso[] ) + { + Date dataEvento = ( Date )aviso[ 1 ]; + + String descricao = (String)aviso[ 2 ]; + Calendar cal = Calendar.getInstance(); + cal.setTime( dataEvento ); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + dataEvento = cal.getTime(); + + cal = Calendar.getInstance(); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + Date hoje = cal.getTime(); + + if( !hoje.after( dataEvento ) && !hoje.before( dataEvento ) ) + { + descricao += " hoje"; + } + else + { + descricao += " no dia " + DATE_FORMAT.format( dataEvento ); + } + JLabel descricaoLabel = new JLabel( descricao ); + if( hoje.after( dataEvento ) ) + { + descricaoLabel.setForeground( Color.red ); + } + else if( hoje.equals( dataEvento ) ) + { + descricaoLabel.setForeground( Color.green.darker() ); + } + return descricaoLabel; + } + +// private JLabel criarDescricao( AvisoData aviso ) +// { +// Date dataEvento = ( Date )aviso.get( AvisoData.DATA_EVENTO ); +// +// String descricao = (String)aviso.get( AvisoData.DESCRICAO ); +// String descricao2 = (String)aviso.get( AvisoData.DESCRICAO ); +// Calendar cal = Calendar.getInstance(); +// cal.setTime( dataEvento ); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// dataEvento = cal.getTime(); +// +// cal = Calendar.getInstance(); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// Date hoje = cal.getTime(); +// +// if( !hoje.after( dataEvento ) && !hoje.before( dataEvento ) ) +// { +// descricao += " hoje"; +// } +// else +// { +// descricao += " no dia " + DATE_FORMAT.format( dataEvento ); +// } +// JLabel descricaoLabel = new JLabel( descricao ); +// if( hoje.after( dataEvento ) ) +// { +// descricaoLabel.setForeground( Color.red ); +// } +// else if( hoje.equals( dataEvento ) ) +// { +// descricaoLabel.setForeground( Color.green.darker() ); +// } +// return descricaoLabel; +// } + + public void actionPerformed( ActionEvent e ) + { + if( JDO == null ) + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + Object source = e.getSource(); + if( source instanceof JButton ) + { +// AvisoData aviso = (AvisoData) buttonHash.get( source ); + try + { + ( (JButton) source ).setEnabled( false ); + Integer id = (Integer)buttonHash.get( source ); + if( id == null ) + { + return; + } + buttonHash.remove( source ); + AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, id ); + if( aviso == null ) + { + JOptionPane.showMessageDialog( null, "Este aviso j\u00e1 foi tratado.", "J\u00e1 tratado", + JOptionPane.WARNING_MESSAGE ); + return; + } + Hashtable dataHash = aviso.getHashData(); + Date dataEvento = (Date)dataHash.get( AvisoData.DATA_EVENTO ); + Calendar cal = Calendar.getInstance(); + cal.setTime( dataEvento ); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + dataEvento = cal.getTime(); + + cal = Calendar.getInstance(); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + Date hoje = cal.getTime(); + if( hoje.before( dataEvento ) ) + { + AvisoData novoAviso = new AvisoData(); + novoAviso.setHashData( dataHash ); + novoAviso.set( AvisoData.DATA_AVISO, dataEvento ); + novoAviso.save(); + } + + Integer tipo = (Integer) aviso.get( AvisoData.TIPO ); + TrabalhadorData trabalhador; + EstabelecimentoData estabelecimento; + EmpresaData empresa; + + switch( tipo.intValue() ) + { + case AvisoConstants.TIPO_TRABALHADOR: + trabalhador = (TrabalhadorData) aviso.get( AvisoData.TRABALHADOR ); + estabelecimento = (EstabelecimentoData) trabalhador.get( TrabalhadorData.ESTABELECIMENTO ); + empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA ); + aviso.delete(); + tracker.getMedicinaWindow().setVisible( true ); + tracker.getMedicinaWindow().setEmpresaAndEstabelecimentoAndTrabalhador( (Integer) empresa.get( EmpresaData.ID ), + ( Integer ) estabelecimento.get( EstabelecimentoData.ID ), + ( Integer ) trabalhador.get( TrabalhadorData.ID ) ); + break; + + case AvisoConstants.TIPO_ESTABELECIMENTO: + estabelecimento = (EstabelecimentoData) aviso.get( AvisoData.ESTABELECIMENTO ); + empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA ); + aviso.delete(); + tracker.getHigieneWindow().setVisible( true ); + tracker.getHigieneWindow().setEmpresaAndEstabelecimento( (Integer) empresa.get( EmpresaData.ID ), + ( Integer ) estabelecimento.get( EstabelecimentoData.ID ) ); + break; + + case AvisoConstants.TIPO_EMPRESA: + empresa = (EmpresaData) aviso.get( AvisoData.EMPRESA ); + aviso.delete(); + ClientesWindow clientesWindow = tracker.getClientesWindow(); + clientesWindow.setVisible( true ); + clientesWindow.setJDOObject( empresa ); + break; + } +System.out.println( "delete aviso" ); +// aviso.set( AvisoData.TRABALHADOR, null ); +// aviso.set( AvisoData.ESTABELECIMENTO, null ); +// aviso.set( AvisoData.EMPRESA, null ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a limpar o aviso", true ); + } + } + } + + public void clear() + { + } + + public void fill(Object value) + { + } + + public Object save() + { + return null; + } + + public void setEnabled( boolean enable ) + { + Set buttonSet = buttonHash.keySet(); + JButton buttons[] = (JButton[]) buttonSet.toArray( new JButton[0] ); + for( int n = 0;n < buttons.length; n++ ) + { + buttons[ n ].setEnabled( enable ); + } + } + + public void setEnabled( boolean enable, int type ) + { + Set buttonSet = buttonHash.keySet(); + JButton buttons[] = (JButton[]) buttonSet.toArray( new JButton[0] ); + for( int n = 0;n < buttons.length; n++ ) + { + Integer buttonType = ( Integer ) buttonTypeHash.get( buttons[ n ] ); + if( buttonType.intValue() == type ) + { + buttons[ n ].setEnabled( enable ); + } + } + } + + public void setTracker( SIPRPTracker tracker ) + { + this.tracker = tracker; + } +} diff --git a/trunk/siprp/clientes/ClientesDataProvider.java b/trunk/siprp/clientes/ClientesDataProvider.java new file mode 100644 index 00000000..aea2b4c2 --- /dev/null +++ b/trunk/siprp/clientes/ClientesDataProvider.java @@ -0,0 +1,197 @@ +/* + * ClientesDataProvider.java + * + * Created on January 27, 2006, 12:50 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.clientes; + +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.strings.*; + +/** + * + * @author fpalma + */ +public class ClientesDataProvider extends MetaProvider +{ + private static final Object LOCK = new Object(); + private static ClientesDataProvider instance = null; + private final Executer executer; + + private Integer etiquetaID; + + /** Creates a new instance of ClientesDataProvider */ + public ClientesDataProvider() + throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + executer = dbm.getSharedExecuter( this ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new ClientesDataProvider(); + } + } + return instance; + } + + public IDObject[] getAllGruposProtocoloReais() + throws Exception + { + return getAllGruposProtocoloPorTipo( true ); + } + + public IDObject[] getAllGruposProtocoloFalsos() + throws Exception + { + return getAllGruposProtocoloPorTipo( false ); + } + + public IDObject[] getAllGruposProtocoloPorTipo( boolean real ) + throws Exception + { + Select select = + new Select( new String[]{ "prt_grupos_protocolo" }, + new String[]{ "id", "descricao", "ordem" }, + new Field( "grupo_real" ).isEqual( real ? "y" : "n" ), + new String[]{ "ordem" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + IDObject grupos[] = new IDObject[ array.columnLength() ]; + for( int n = 0; n < grupos.length; n++ ) + { + grupos[ n ] = new MappableObject( ( Integer ) array.get( n, 0 ), ( String ) array.get( n, 1 ) ); + } + return grupos; + } + + public Hashtable getAllTiposElementosProtocoloByGrupo() + throws Exception + { + Select select = + new Select( new String[]{ "prt_tipos_elementos_protocolo" }, + new String[]{ "id", "descricao", "ordem", "grupo_protocolo_id" }, + null, + new String[]{ "grupo_protocolo_id", "ordem" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + Hashtable tipos = new Hashtable(); + for( int n = 0; n < array.columnLength(); n++ ) + { + IDObject tipo = new MappableObject( ( Integer ) array.get( n, 0 ), ( String ) array.get( n, 1 ) ); + Integer grupoID = ( Integer ) array.get( n, 3 ); + if( !tipos.containsKey( grupoID ) ) + { + tipos.put( grupoID, new Vector() ); + } + Vector tiposGrupo = ( Vector ) tipos.get( grupoID ); + tiposGrupo.add( tipo ); + } + return tipos; + } + + public void setElementosProtocoloForEmpresa( Integer empresaID, Integer elementos[][] ) + throws Exception + { +// executer.executeQuery( Begin.BEGIN ); + try + { + Delete delete = + new Delete( "prt_elementos_protocolo", + new Field( "empresa_id" ).isEqual( empresaID ) ); + executer.executeQuery( delete ); + for( int p = 0; p < elementos.length; p++ ) + { + Integer numeroPerfil = new Integer( p + 1 ); + for( int e = 0; e < elementos[ p ].length; e++ ) + { + Insert insert = + new Insert( "prt_elementos_protocolo", + new Assignment[]{ + new Assignment( new Field( "empresa_id" ), empresaID ), + new Assignment( new Field( "tipo_elemento_protocolo_id" ), elementos[ p ][ e ] ), + new Assignment( new Field( "numero_perfil" ), numeroPerfil ) } ); + executer.executeQuery( insert, null ); + } + } +// executer.executeQuery( Commit.COMMIT ); + } + catch( Exception ex ) + { +// executer.executeQuery( Rollback.ROLLBACK ); + throw ex; + } + } + + public Integer[][] getElementosProtocoloForEmpresa( Integer empresaID, int numeroPerfis ) + throws Exception + { + Select select = + new Select( new String[]{ "prt_elementos_protocolo" }, + new String[]{ "tipo_elemento_protocolo_id", "numero_perfil" }, + new Field( "empresa_id" ).isEqual( empresaID ) , + new String[]{ "numero_perfil" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + Vector data[] = new Vector[ numeroPerfis ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + int perfil = ( ( Integer ) array.get( n, 1 ) ).intValue() - 1; + Integer tipo = ( Integer ) array.get( n, 0 ); + if( data[ perfil ] == null ) + { + data[ perfil ] = new Vector(); + } + data[ perfil ].add( tipo ); + } + Integer elementos[][] = new Integer[ numeroPerfis ][]; + for( int n = 0; n < numeroPerfis; n++ ) + { + if( data[ n ] == null ) + { + elementos[ n ] = new Integer[ 0 ]; + } + else + { + elementos[ n ] = ( Integer [] ) data[ n ].toArray( new Integer[ data[ n ].size() ] ); + } + } + return elementos; + } + + public Integer getEtiquetaID() + throws Exception + { + if( etiquetaID == null ) + { + Select select = + new Select( new String[]{ "etiquetas" }, + new String[]{ "max(id)" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return null; + } + etiquetaID = ( Integer ) array.get( 0, 0 ); + } + return etiquetaID; + } +} diff --git a/trunk/siprp/clientes/ClientesWindow.java b/trunk/siprp/clientes/ClientesWindow.java new file mode 100644 index 00000000..4c545622 --- /dev/null +++ b/trunk/siprp/clientes/ClientesWindow.java @@ -0,0 +1,1433 @@ +/* + * ClientesWindow.java + * + * Created on 12 de Maio de 2004, 18:11 + */ + +package siprp.clientes; + +import java.awt.*; +import java.io.*; +import java.text.*; +import java.util.*; +import javax.swing.*; +import javax.swing.event.*; + +import com.evolute.utils.*; +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.date.*; +import com.evolute.utils.fop.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.strings.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.dialog.*; +import com.evolute.utils.ui.panel.*; +import com.evolute.utils.ui.search.*; +import com.evolute.utils.ui.text.*; +import com.evolute.utils.ui.window.*; +import com.evolute.utils.xml.*; + +import siprp.*; +import siprp.data.*; +import siprp.ficha.*; +import siprp.importer.*; + +/** + * + * @author fpalma + */ +public class ClientesWindow extends EditorWindow + implements ListSelectionListener +{ + private static final DateFormat DF = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) ); + + public static final Hashtable TR_IMPORT_NAMES_TO_TRAB = new Hashtable(); + public static final Hashtable TR_IMPORT_NAMES_TO_DEMISSOES = new Hashtable(); + + static + { + TR_IMPORT_NAMES_TO_TRAB.put( Importer.NOME, TrabalhadorData.NOME ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.SEXO, TrabalhadorData.SEXO ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.NACIONALIDADE, TrabalhadorData.NACIONALIDADE ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.DATA_NASCIMENTO, TrabalhadorData.DATA_NASCIMENTO ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.NUMERO_MECANOGRAFICO, TrabalhadorData.NUMERO_MECANOGRAFICO ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.DATA_ADMISSAO, TrabalhadorData.DATA_ADMISSAO ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.CATEGORIA, TrabalhadorData.CATEGORIA ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.LOCAL_TRABALHO, TrabalhadorData.LOCAL_TRABALHO ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.FUNCAO, TrabalhadorData.FUNCAO_PROPOSTA ); + TR_IMPORT_NAMES_TO_TRAB.put( Importer.DATA_ADMISSAO_FUNCAO, TrabalhadorData.DATA_ADMISSAO_FUNCAO ); + + TR_IMPORT_NAMES_TO_DEMISSOES.put( Importer.NOME, TrabalhadorData.NOME ); + TR_IMPORT_NAMES_TO_DEMISSOES.put( Importer.DATA_DEMISSAO, TrabalhadorData.DATA_DEMISSAO ); + +// JDOObject.registerOperationHandlerForClass( DisableDeleteHandler.INSTANCE, EmpresaData.class ); +// JDOObject.registerOperationHandlerForClass( DisableDeleteHandler.INSTANCE, EstabelecimentoData.class ); +// JDOObject.registerOperationHandlerForClass( DisableDeleteHandler.INSTANCE, TrabalhadorData.class ); +// +// JDOObject.registerOperationHandlerForClass( MarcacaoSaveAndDeleteHandler.INSTANCE, MarcacaoEmpresaData.class ); +// JDOObject.registerOperationHandlerForClass( MarcacaoSaveAndDeleteHandler.INSTANCE, MarcacaoEstabelecimentoData.class ); +// JDOObject.registerOperationHandlerForClass( MarcacaoSaveAndDeleteHandler.INSTANCE, MarcacaoTrabalhadorData.class ); + } + + public static final int INDEX_EMPRESA = 0; + public static final int INDEX_ESTABELECIMENTO = 1; + public static final int INDEX_TRABALHADOR = 2; + + private static int hierarchy[] = new int[]{0,0,1}; + private static int permissions[][] = + new int[][]{ { NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, SELECT_BYNAME_INDEX, DELETE_INDEX }, + { NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, DELETE_INDEX }, + { NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, DELETE_INDEX } }; + + private JDOProvider JDO; + private ClientesDataProvider clientesProvider; + private ControllableComponent panels[] = new ControllableComponent[ 4 ]; + private EmpresaPanel empresaPanel; + private JPanel estabelecimentoOuterPanel; + private JTabbedPane tabbedPane; + private JTextField estabelecimentoText; + private EstabelecimentoPanel estabelecimentoPanel; + private TrabalhadorPanel trabalhadorPanel; + + private SIPRPTracker tracker; + + private EmpresaData empresa; + private Integer elementosProtocolo[][]; + private EstabelecimentoData estabelecimento; + private TrabalhadorData trabalhador; + + private AvisosPanel avisos; + + protected boolean webAware; + +// public static void main( String args[] ) +// throws Exception +// { +// ClientesWindow window = new ClientesWindow(); +// window.show(); +// } + + /** Creates a new instance of ClientesWindow */ + public ClientesWindow( AvisosPanel avisos ) + throws Exception + { + super( permissions ); + this.avisos = avisos; + webAware = ( ( Boolean ) Singleton.getInstance( SingletonConstants.WEB_AWARE ) ).booleanValue(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + clientesProvider = ( ClientesDataProvider ) ClientesDataProvider.getProvider(); + setEditorManagerHierarchy( hierarchy ); + setupComponents(); + this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); + } + + private void setupComponents() + throws Exception + { + setSize( 1000, 740 ); + setTitle( "Gest\u00e3o de Clientes" ); + + changeGroupName( INDEX_ESTABELECIMENTO, "Estabelecimento" ); + JPanel toolbarEstabelecimento = getToolbarPanel( INDEX_ESTABELECIMENTO ); + + changeGroupName( INDEX_TRABALHADOR, "Trabalhador" ); + JPanel toolbarTrabalhador = getToolbarPanel( INDEX_TRABALHADOR ); + + tabbedPane = new JTabbedPane(); + empresaPanel = new EmpresaPanel(); + empresaPanel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), + "Empresa/Entidade" ) ); + estabelecimentoText = new JTextField(); + estabelecimentoPanel = new EstabelecimentoPanel( toolbarEstabelecimento, estabelecimentoText, empresaPanel.getEstabelecimentosTable() ); + estabelecimentoOuterPanel = new JPanel(); + estabelecimentoOuterPanel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), + "Estabelecimento" ) ); + JLabel estabelecimentoLabel = new JLabel( "Designa\u00e7\u00e3o" ); + + trabalhadorPanel = new TrabalhadorPanel( toolbarTrabalhador, empresaPanel.getEstabelecimentosTable() ); + + GridBagLayout gridbag = new GridBagLayout(); + getContentPane().setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + + constraints.weighty = 0.5; + constraints.gridheight = 1; + gridbag.setConstraints( empresaPanel, constraints ); + getContentPane().add( empresaPanel ); + + constraints.weighty = 0.5; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints( estabelecimentoOuterPanel, constraints ); + getContentPane().add( estabelecimentoOuterPanel ); + + gridbag = new GridBagLayout(); + estabelecimentoOuterPanel.setLayout( gridbag ); + constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.BOTH; + + constraints.weightx = 0; + constraints.gridwidth = 1; + constraints.weighty = 0; + constraints.gridheight = 1; + gridbag.setConstraints( estabelecimentoLabel, constraints ); + estabelecimentoOuterPanel.add( estabelecimentoLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( estabelecimentoText, constraints ); + estabelecimentoOuterPanel.add( estabelecimentoText ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints( tabbedPane, constraints ); + estabelecimentoOuterPanel.add( tabbedPane ); + + tabbedPane.add( "Dados", estabelecimentoPanel ); + tabbedPane.add( "Trabalhadores", trabalhadorPanel ); + + panels[ INDEX_EMPRESA ] = empresaPanel; + panels[ INDEX_ESTABELECIMENTO ] = estabelecimentoPanel; + panels[ INDEX_TRABALHADOR ] = trabalhadorPanel; + //empresaPanel.addListSelectionListener( estabelecimentoPanel ); + empresaPanel.addListSelectionListener( trabalhadorPanel ); + empresaPanel.addListSelectionListener( this ); + trabalhadorPanel.addListSelectionListener( this ); + + registerAction( new ActionHandler(){ + public void execute() + { + excel(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction; + } + }, "Importar", + "Importar de Excel", "excel", + 0, true ); + + registerAction( new ActionHandler(){ + public void execute() + { + excelDemissoes(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction; + } + }, "Demiss\u00f5es", + "Demiss\u00f5es por Excel", null, + 0, true ); + + registerAction( new ActionHandler(){ + public void execute() + { + mudarEstabelecimento(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction; + } + }, "Mudar Estabelecimento", + "Mudar Estabelecimento", null, + INDEX_TRABALHADOR, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + imprimirFicha(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction ; + } + }, "Imprimir Ficha de Aptid\u00e3o", + "Imprimir Ficha de Aptid\u00e3o", null, + INDEX_TRABALHADOR, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + imprimirEtiquetaTrabalhador(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction ; + } + }, "Imprimir Etiqueta", + "Imprimir Etiqueta de Trabalhador", null, + INDEX_TRABALHADOR, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + imprimirEtiquetaEstabelecimento(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction ; + } + }, "Imprimir Etiqueta", + "Imprimir Etiqueta de Estabelecimento", null, + INDEX_ESTABELECIMENTO, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + restaurarEmpresa(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return true; + } + }, "Restaurar Empresa", + "Restaurar Empresa", null, + INDEX_EMPRESA, false ); + + if( webAware ) + { + registerAction( new ActionHandler(){ + public void execute() + { + utilizadorWeb( false ); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return editAction; + } + }, "Utilizador Web da Empresa", + "Utilizador Web da Empresa", null, + INDEX_EMPRESA, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + utilizadorWeb( true ); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return true; + } + }, "Utilizador Web", + "Utilizador Web", null, + INDEX_EMPRESA, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + noticias(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return true; + } + }, "Not\u00edcias", + "Not\u00edcias", null, + INDEX_EMPRESA, false ); + } + + registerAction( new ActionHandler(){ + public void execute() + { + restaurarEstabelecimento(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return newAction || saveAction; + } + }, "Restaurar Estabelecimento", + "Restaurar Estabelecimento", null, + INDEX_ESTABELECIMENTO, false ); + + registerAction( new ActionHandler(){ + public void execute() + { + restaurarTrabalhador(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return newAction || saveAction; + } + }, "Restaurar Trabalhador", + "Restaurar Trabalhador", null, + INDEX_TRABALHADOR, false ); + + new CopyPasteHandler( estabelecimentoText ); + } + + public boolean searchByName( ) + { + SearchDialog search; + Integer empresaID; +// switch( index ) +// { +// case INDEX_EMPRESA: + search = new SearchDialog( SearchExecuterFactory.getSearchExecuter( EmpresaData.class ), null, false, null, true ); + empresaID = ( Integer )search.getSelected(); + if( empresaID != null ) + { + try + { + empresa = (EmpresaData) JDO.load( EmpresaData.class, empresaID ); + elementosProtocolo = clientesProvider.getElementosProtocoloForEmpresa( empresaID, 2 ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar a empresa", true ); + empresa = null; + } + reload( INDEX_EMPRESA ); + } +// break; +// } + return true; + } + + public boolean newItem( int index ) + { + return true; + } + + public void reload( int index ) + { +//System.out.println( "RELOAD: " + index + " e: " + empresa + " e: " +estabelecimento + " t: " + trabalhador ); + switch( index ) + { + case INDEX_EMPRESA: + empresaPanel.fill( new Object[]{ empresa, elementosProtocolo } ); + estabelecimentoPanel.setEmpresa( empresa ); + break; + + case INDEX_ESTABELECIMENTO: +// trabalhadorPanel.fill( null ); + estabelecimentoPanel.fill( estabelecimento ); + trabalhadorPanel.setEstabelecimento( estabelecimento ); + break; + + case INDEX_TRABALHADOR: + trabalhadorPanel.fill( trabalhador ); +// trabalhadorPanel.reload(); + break; + + } + } + + public boolean save( int index ) + { + boolean isNew = false; + Object object = panels[ index ].save(); + try + { + switch( index ) + { + case INDEX_EMPRESA: + empresa = (EmpresaData) ( ( Object [] )object )[ 0 ]; + if( empresa.get( EmpresaData.ID ) == null ) + { + isNew = true; + } + elementosProtocolo = (Integer [][]) ( ( Object [] )object )[ 1 ]; + // System.out.println( empresa.debug() ); + ContactoData c1 = ( ContactoData )empresa.get( EmpresaData.CONTACTO_1 ); + ContactoData c2 = ( ContactoData )empresa.get( EmpresaData.CONTACTO_2 ); +// empresa.set( EmpresaData.CONTACTO_1, null ); +// empresa.set( EmpresaData.CONTACTO_2, null ); +// empresa.save(); + +// empresa.set( EmpresaData.CONTACTO_1, c1 ); + +// empresa.set( EmpresaData.CONTACTO_2, c2 ); + c1.save(); + c2.save(); + +// empresa.set( EmpresaData.INACTIVO, "n" ); + empresa.set( EmpresaData.DESIGNACAO_SOCIAL_PLAIN, + com.evolute.utils.strings.StringPlainer.convertString( ( String ) + empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ) ); + empresa.save(); + clientesProvider.setElementosProtocoloForEmpresa( + ( Integer ) empresa.get( EmpresaData.ID ), elementosProtocolo ); + + if( isNew ) + { + estabelecimentoPanel.setEmpresa( empresa ); + } + ( ( EmpresaPanel )panels[ INDEX_EMPRESA ] ).reloadMarcacoes(); + break; + + case INDEX_ESTABELECIMENTO: + estabelecimento = (EstabelecimentoData) object; + if( estabelecimento.get( EstabelecimentoData.ID ) == null ) + { + isNew = true; + } + ContactoData c = ( ContactoData )estabelecimento.get( EstabelecimentoData.CONTACTO ); + c.save(); + if( estabelecimento.get( EstabelecimentoData.EMPRESA ) == null ) + { + JOptionPane.showMessageDialog( this, "Erro a guardar estabelecimento (NULL).", "Erro...", + JOptionPane.ERROR_MESSAGE ); + return false; + } + estabelecimento.set( EstabelecimentoData.NOME_PLAIN, + com.evolute.utils.strings.StringPlainer.convertString( ( String ) + estabelecimento.get( EstabelecimentoData.NOME ) ) ); + estabelecimento.save(); + estabelecimentoPanel.postSave(); + if( isNew ) + { + trabalhadorPanel.setEstabelecimento( estabelecimento ); + } + break; + + case INDEX_TRABALHADOR: + trabalhador = (TrabalhadorData) object; + trabalhador.set( TrabalhadorData.NOME_PLAIN, + com.evolute.utils.strings.StringPlainer.convertString( ( String ) + trabalhador.get( TrabalhadorData.NOME ) ) ); + trabalhador.save(); + trabalhadorPanel.postSave(); + break; + + default: + ( ( JDOObject )object ).save(); + } +// object.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + return false; + } + //reload( index ); + return true; + } + + public void enableComponents( int index, boolean enable ) + { + panels[ index ].setEnabled( enable ); + avisos.setEnabled( !empresaPanel.isEnabled() && !estabelecimentoPanel.isEnabled() && !trabalhadorPanel.isEnabled(), + AvisoConstants.TIPO_EMPRESA ); + } + + public void clear( int index ) + { + panels[ index ].fill( null ); + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + Integer id; + if( source.equals( empresaPanel ) ) + { + id = empresaPanel.getSelectedEstabelecimento(); + if( id != null ) + { + select( INDEX_ESTABELECIMENTO ); + try + { + estabelecimento = ( EstabelecimentoData ) JDO.load( EstabelecimentoData.class, id ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar o estabelecimento", true ); + estabelecimento = null; + } + + } + else + { + estabelecimento = null; + } + reload( INDEX_ESTABELECIMENTO ); + } + else if( source.equals( trabalhadorPanel ) ) + { + id = trabalhadorPanel.getSelectedTrabalhador(); +//System.out.println( "trabalhadorid: " + id ); + if( id != null ) + { + try + { + trabalhador = (TrabalhadorData) JDO.load( TrabalhadorData.class, id ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar o trabalhador", true ); + trabalhador = null; + } + select( INDEX_TRABALHADOR ); + } + else + { + trabalhador = null; + } + + reload( INDEX_TRABALHADOR ); + } + } + + public boolean delete( int index ) + { + String yes = "Sim"; + String no = "N\u00e3o"; + switch( index ) + { + case INDEX_EMPRESA: + if( empresa == null ) + { + return false; + } + if( JOptionPane.showOptionDialog( + this, "Tem a certeza que quer apagar esta Empresa?", "Apagar Empresa...", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{ no, yes }, no ) == 1 ) + { + try + { + empresa.delete(); + empresa = null; + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a apagar", true ); + return false; + } + return true; + } + break; + case INDEX_ESTABELECIMENTO: + if( estabelecimento == null ) + { + return false; + } + if( JOptionPane.showOptionDialog( + this, "Tem a certeza que quer apagar este Estabelecimento?", "Apagar Estabelecimento...", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{ no, yes }, no ) == 1 ) + { + try + { + estabelecimento.delete(); + estabelecimento = null; + reload( INDEX_EMPRESA ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a apagar", true ); + return false; + } + return true; + } + break; + case INDEX_TRABALHADOR: + if( trabalhador == null ) + { + return false; + } + if( JOptionPane.showOptionDialog( + this, "Tem a certeza que quer apagar este Trabalhador?", "Apagar Trabalhador...", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{ no, yes }, no ) == 1 ) + { + try + { + TrabalhadorData trabalhadorAux = trabalhador; + trabalhador = null; + trabalhadorAux.delete(); + + reload( INDEX_ESTABELECIMENTO ); + try + { + trabalhadorPanel.reloaList(); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a apagar", true ); + return false; + } + return true; + } + break; + } + return false; + } + + private void excel() + { + FileDialog fd = new FileDialog( this, "Escolha um ficheiro Excel:", FileDialog.LOAD ); + fd.setDirectory( System.getProperty( "user.home" ) ); + fd.setFilenameFilter( new FilenameFilter() { + public boolean accept( File dir, String name ) + { + return (name!=null) && (name.indexOf( ".xls" ) != -1); + } + } ); + fd.setVisible( true ); + //String filename = "c:\\test.xls"; + String filename = fd.getFile(); + if( filename != null ) + { + filename = fd.getDirectory() + File.separator + filename; + try + { + Importer importer = new Importer( this, filename, true, Importer.TYPE_ADMISSAO ); + Hashtable hash[] = importer.getMultipleData(); + Vector activate = new Vector(); + if( hash != null ) + { + // load all (active) trabalhadores for this company + IDObject trab[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllTrabalhadoresForEmpresa( + ( Integer )empresa.get( EmpresaData.ID ) ); + Hashtable trabalhadores = new Hashtable(); + for( int i = 0; i < trab.length; ++i ) + { + trabalhadores.put( trab[ i ].toString().trim().toLowerCase(), trab[ i ].getID() ); + } + // load all active estabelecimentos for this company + IDObject estab[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllEstabelecimentosForEmpresa( + ( Integer )empresa.get( EmpresaData.ID ) ); + Hashtable estabelecimentos = new Hashtable(); + for( int i = 0; i < estab.length; ++i ) + { + estabelecimentos.put( estab[ i ].toString().trim().toLowerCase(), estab[ i ].getID() ); + } + Hashtable estabCache = new Hashtable(); + for( int i = 0; i < hash.length; ++i ) + { +// if( hash[ i ] == null ) +// { +// continue; +// } + for( int j = 0; j < Importer.NAMES.length; ++j ) + { + if( hash[ i ] == null ) + { + continue; + } + Object value = hash[ i ].remove( Importer.NAMES[ j ] ); + if( Importer.NAMES[ j ].equals( Importer.NOME ) ) + { + if( value != null + && trabalhadores.get( value.toString().trim().toLowerCase() ) == null ) + { + trabalhadores.put( value.toString().trim().toLowerCase(), value ); + + hash[ i ].put( TR_IMPORT_NAMES_TO_TRAB.get( Importer.NOME ), + value.toString().trim() ); + hash[ i ].put( TrabalhadorData.NOME_PLAIN, + com.evolute.utils.strings.StringPlainer.convertString( value.toString().trim(), false, false ) ); + } + else + { + Integer tID = (Integer) trabalhadores.get( value.toString().trim().toLowerCase() ); + if( tID != null ) + { + activate.add( tID ); + } + hash[ i ] = null; + } + } + else if( Importer.NAMES[ j ].equals( Importer.LOCAL_TRABALHO ) ) + { + if( value == null ) + { + value = "sede"; + } + Integer eid = ( Integer )estabelecimentos.get( value.toString().trim().toLowerCase() ); + EstabelecimentoData esta; + if( eid == null ) + { + // save this estab + esta = new EstabelecimentoData(); + esta.set( EstabelecimentoData.EMPRESA, empresa ); + esta.set( EstabelecimentoData.NOME, value.toString().trim() ); + esta.set( EstabelecimentoData.NOME_PLAIN, com.evolute.utils.strings.StringPlainer.convertString( value.toString().trim(), false, false ) ); + esta.save(); + estabelecimentos.put( value.toString().trim().toLowerCase(), + esta.get( EstabelecimentoData.ID ) ); + + } + else + { + esta = ( EstabelecimentoData )estabCache.get( value ); + if( esta == null ) + { + esta = (EstabelecimentoData) JDO.load( EstabelecimentoData.class, eid ); + estabCache.put( value, esta ); + } + } +//System.out.println( "Put " + i + " esta " + esta.debug() ); + hash[ i ].put( TrabalhadorData.ESTABELECIMENTO, + esta ); + hash[ i ].put( TR_IMPORT_NAMES_TO_TRAB.get( Importer.LOCAL_TRABALHO ), + value.toString().trim() ); + } + else + { + if( Importer.NAMES[ j ].indexOf( Importer.DATA_PREFIX ) == 0 ) + { + value = DateUtils.guessDate( (String)value ); + if( value != null ) + { + hash[ i ].put( TR_IMPORT_NAMES_TO_TRAB.get( Importer.NAMES[ j ] ), + value ); + } + } + else + { + if( Importer.NAMES[ j ].equals( Importer.SEXO ) ) + { + if( value == null || ( (String) value ).length() == 0 ) + { + value = "m"; + } + else + { + value = ( (String) value ).substring(0,1).toLowerCase(); + if( !value.equals( "m" ) && !value.equals( "f" ) ) + { + value = "m"; + } + } + } + if( value != null ) + { + hash[ i ].put( TR_IMPORT_NAMES_TO_TRAB.get( Importer.NAMES[ j ] ), + value.toString().trim() ); + } + } + } + } + } + for( int i = 0; i < hash.length; ++i ) + { + if( hash[ i ] == null ) + { + continue; + } + // save trab + TrabalhadorData tr = new TrabalhadorData(); + tr.setHashData( hash[ i ] ); +// o estabelecimento nao faz parte da lista por causa do UI + tr.set( TrabalhadorData.ESTABELECIMENTO, + hash[ i ].get( TrabalhadorData.ESTABELECIMENTO ) ); + tr.set( TrabalhadorData.PERFIL, new Integer( 1 ) ); +// System.out.println( "T: " + i + "\n" + tr.debug() ); + tr.save(); + } + for( int i = 0; i < activate.size(); i++ ) + { + TrabalhadorData trabalhadorR = (TrabalhadorData)JDO.load( TrabalhadorData.class, ( Integer ) activate.elementAt( i ) ); + trabalhadorR.set( TrabalhadorData.INACTIVO, "n" ); + trabalhadorR.save(); + } + } + reload( INDEX_EMPRESA ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + JOptionPane.showMessageDialog( this, "Erro a importar", "Erro...", JOptionPane.ERROR_MESSAGE ); + } + } + + } + + private void excelDemissoes() + { + FileDialog fd = new FileDialog( this, "Escolha um ficheiro Excel:", FileDialog.LOAD ); + fd.setDirectory( System.getProperty( "user.home" ) ); + fd.setFilenameFilter( new FilenameFilter() { + public boolean accept( File dir, String name ) + { + return (name!=null) && (name.indexOf( ".xls" ) != -1); + } + } ); + fd.setVisible( true ); + //String filename = "c:\\test.xls"; + String filename = fd.getFile(); + if( filename != null ) + { + filename = fd.getDirectory() + File.separator + filename; + try + { + Importer importer = new Importer( this, filename, true, Importer.TYPE_DEMISSAO ); + Hashtable hash[] = importer.getMultipleData(); + Vector invalidos = new Vector(); + Vector validos = new Vector(); + Vector semData = new Vector(); + if( hash != null ) + { + // load all (active) trabalhadores for this company + IDObject trab[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllTrabalhadoresForEmpresa( + ( Integer )empresa.get( EmpresaData.ID ) ); + Hashtable trabalhadores = new Hashtable(); + for( int i = 0; i < trab.length; ++i ) + { + trabalhadores.put( trab[ i ].toString().trim().toLowerCase(), trab[ i ].getID() ); + } + Hashtable estabCache = new Hashtable(); + for( int i = 0; i < hash.length; ++i ) + { +// if( hash[ i ] == null ) +// { +// continue; +// } + for( int j = 0; j < Importer.NAMES_DEMISSAO.length; ++j ) + { + if( hash[ i ] == null ) + { + continue; + } + Object value = hash[ i ].remove( Importer.NAMES_DEMISSAO[ j ] ); + if( Importer.NAMES_DEMISSAO[ j ].equals( Importer.NOME ) ) + { + if( value != null + && !trabalhadores.containsKey( value.toString().trim().toLowerCase() ) ) + { + invalidos.add( new String[]{ value.toString().trim(), + StringPlainer.convertString( value.toString().trim(), false, false ) } ); + hash[ i ] = null; + } + else if( value != null ) + { + Integer tID = (Integer) trabalhadores.get( value.toString().trim().toLowerCase() ); + hash[ i ].put( TrabalhadorData.ID, tID ); + validos.add( new String[]{ value.toString().trim(), + StringPlainer.convertString( value.toString().trim(), false, false ) } ); + } + else + { + hash[ i ] = null; + } + } + else if( Importer.NAMES_DEMISSAO[ j ].equals( Importer.DATA_DEMISSAO ) ) + { + value = DateUtils.guessDate( (String)value ); + if( value != null ) + { + hash[ i ].put( TR_IMPORT_NAMES_TO_DEMISSOES.get( Importer.NAMES_DEMISSAO[ j ] ), + value ); + } + else + { + hash[ i ] = null; + validos.removeElementAt( validos.size() - 1 ); + semData.add( new String[]{ value.toString().trim(), + StringPlainer.convertString( value.toString().trim(), false, false ) } ); + } + } + } + } +System.out.println( "HASH.LENGTH: " + hash.length ); + for( int i = 0; i < hash.length; ++i ) + { +System.out.println( "HASH[ " + i + " ]: " + hash[ i ] ); + if( hash[ i ] == null ) + { +System.out.println( "TRABALHADOR:continue" ); + continue; + } +System.out.println( "TRABALHADOR:not continue" ); + TrabalhadorData tr = (TrabalhadorData)JDO.load( TrabalhadorData.class, ( Integer ) hash[ i ].get( TrabalhadorData.ID ) ); +System.out.println( "TRABALHADORID: " + tr.get( TrabalhadorData.ID ) ); + tr.set( TrabalhadorData.DATA_DEMISSAO, hash[ i ].get( TrabalhadorData.DATA_DEMISSAO ) ); +System.out.println( "TRABALHADORDEMISSAO: " + tr.get( TrabalhadorData.DATA_DEMISSAO ) ); + tr.save(); + } + StringBuffer buff = new StringBuffer( "" ); + buff.append( "Demitidos:\n" ); + for( int i = 0; i < validos.size(); i++ ) + { + buff.append( ( ( String [] ) validos.elementAt( i ) )[ 1 ] + "\n" ); + } + buff.append( "\nSem data ou data inv\u00e1lida:\n" ); + for( int i = 0; i < semData.size(); i++ ) + { + buff.append( ( ( String [] ) semData.elementAt( i ) )[ 1 ] + "\n" ); + } + buff.append( "\nN\u00e3o encontrados na base de dados:\n" ); + for( int i = 0; i < invalidos.size(); i++ ) + { + buff.append( ( ( String [] ) invalidos.elementAt( i ) )[ 1 ] + "\n" ); + } + new LongMessageDialog( this, false, buff.toString(), new Dimension( 600, 500 ) ); + } + reload( INDEX_EMPRESA ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + JOptionPane.showMessageDialog( this, "Erro a importar", "Erro...", JOptionPane.ERROR_MESSAGE ); + } + } + + } + + public void mudarEstabelecimento() + { + ListAction lAction = new ListAction(){ + public String getListActionName() + { + return "Escolher"; + } + + public boolean executeListAction( int line, Object value ) + { + if( trabalhador == null ) + { + return false; + } + try + { + EstabelecimentoData eatabelecimentoNovo = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, ( (IDObject)value ).getID() ); + trabalhador.set( TrabalhadorData.ESTABELECIMENTO, eatabelecimentoNovo ); + trabalhador.save(); + trabalhador = null; + reload( INDEX_ESTABELECIMENTO ); + trabalhadorPanel.reloaList(); + } + catch( Exception ex ) + { + ex.printStackTrace(); + return false; + } + return true; + } + }; + + try + { + IDObject estab[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllEstabelecimentosForEmpresa( + ( Integer )empresa.get( EmpresaData.ID ) ); + ListActionDialog dialog = new ListActionDialog( this, "Escolher Estabelecimento", new String []{ "Designa\u00e7\u00e3o" }, + new Vector( Arrays.asList( estab ) ), lAction ); + dialog.setSize( 250, 200 ); + dialog.setVisible( true ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } + + public void setJDOObject( JDOObject object ) + { + empresa = null; + estabelecimento = null; + trabalhador = null; + reload(0); + if( object instanceof TrabalhadorData ) + { + tabbedPane.setSelectedIndex( 1 ); + trabalhador = (TrabalhadorData) object; + estabelecimento = (EstabelecimentoData)trabalhador.get( TrabalhadorData.ESTABELECIMENTO ); + empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA ); + } + else if( object instanceof EstabelecimentoData ) + { + tabbedPane.setSelectedIndex( 0 ); + estabelecimento = (EstabelecimentoData)object; + empresa = (EmpresaData)estabelecimento.get( EstabelecimentoData.EMPRESA ); + } + else if( object instanceof EmpresaData ) + { + empresa = (EmpresaData)object; + } + if( empresa != null ) + { + try + { + elementosProtocolo = + clientesProvider.getElementosProtocoloForEmpresa( + ( Integer ) empresa.get( EmpresaData.ID ), 2 ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados do protocolo.", true ); + elementosProtocolo = new Integer[2][0]; + } + } + reload(0); + if( empresa != null ) + { + select( INDEX_EMPRESA ); + } + if( estabelecimento != null ) + { + empresaPanel.setSelectedEstabelecimento( estabelecimento ); + } + if( trabalhador != null ) + { + trabalhadorPanel.setSelectedTrabalhador( trabalhador ); + } + } + + public void postSetup() + { + } + + public void restaurarEmpresa() + { + ListAction lAction = new ListAction(){ + public String getListActionName() + { + return "Restaurar"; + } + + public boolean executeListAction( int line, Object value ) + { + try + { + EmpresaData empresaR = (EmpresaData)JDO.load( EmpresaData.class, ( (IDObject)value ).getID() ); + empresaR.set( EmpresaData.INACTIVO, "n" ); + empresaR.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a restaurar a Empresa", true ); + return false; + } + return true; + } + }; + + try + { + IDObject empresas[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllEmpresasDeleted(); + ListActionDialog dialog = new ListActionDialog( this, "Restaurar Empresa", new String []{ "Designa\u00e7\u00e3o Social" }, + new Vector( Arrays.asList( empresas ) ), lAction ); + dialog.setSize( 250, 200 ); + dialog.setVisible( true ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a criar lista de Empresas", true ); + ex.printStackTrace(); + } + } + + public void restaurarEstabelecimento() + { + ListAction lAction = new ListAction(){ + public String getListActionName() + { + return "Restaurar"; + } + + public boolean executeListAction( int line, Object value ) + { + try + { + EstabelecimentoData estabelecimentoR = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, ( (IDObject)value ).getID() ); + estabelecimentoR.set( EstabelecimentoData.INACTIVO, "n" ); + estabelecimentoR.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a restaurar o Estabelecimento", true ); + return false; + } + return true; + } + }; + if( empresa == null ) + { + return; + } + try + { + IDObject estabelecimentos[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllEstabelecimentosDeletedForEmpresa( ( Integer ) empresa.get( EmpresaData.ID ) ); + ListActionDialog dialog = new ListActionDialog( this, "Restaurar Estabelecimento", new String []{ "Nome" }, + new Vector( Arrays.asList( estabelecimentos ) ), lAction ); + dialog.setSize( 250, 200 ); + dialog.setVisible( true ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a criar lista de Estabelecimentos", true ); + ex.printStackTrace(); + } + } + + public void restaurarTrabalhador() + { + ListAction lAction = new ListAction(){ + public String getListActionName() + { + return "Restaurar"; + } + + public boolean executeListAction( int line, Object value ) + { + try + { + TrabalhadorData trabalhadorR = (TrabalhadorData)JDO.load( TrabalhadorData.class, ( (IDObject)value ).getID() ); + trabalhadorR.set( TrabalhadorData.INACTIVO, "n" ); + trabalhadorR.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a restaurar o Trabalhador", true ); + return false; + } + return true; + } + }; + if( estabelecimento == null ) + { + return; + } + try + { + IDObject trabalhadores[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllTrabalhadoresDeletedForEstabelecimento( ( Integer ) estabelecimento.get( EstabelecimentoData.ID ) ); + ListActionDialog dialog = new ListActionDialog( this, "Restaurar Trabalhador", new String []{ "Nome" }, + new Vector( Arrays.asList( trabalhadores ) ), lAction ); + dialog.setSize( 250, 200 ); + dialog.setVisible( true ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a criar lista de Trabalhadores", true ); + ex.printStackTrace(); + } + } + + protected void utilizadorWeb( boolean siprp ) + { +// new Exception().printStackTrace(); + if( !siprp && empresa == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher uma empresa", "Erro...", + JOptionPane.ERROR_MESSAGE ); + } + try + { + + UserWindow window = new UserWindow( this, siprp ? null : ( Integer ) empresa.get( EmpresaData.ID ) ); + window.setVisible( true ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a estabelecer a liga\u00e7\u00e3o com a p\u00e1gina", true ); + } + } + + public void noticias() + { + try + { + NoticiasDialog dialog = new NoticiasDialog( this ); + dialog.setVisible( true ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar not\u00edcias", true ); + } + } + + public void imprimirFicha() + { + ListAction lAction = new ListAction(){ + public String getListActionName() + { + return "Escolher"; + } + + public boolean executeListAction( int line, Object value ) + { + if( trabalhador == null ) + { + return false; + } + try + { + printFicha(( (IDObject)value ).getID() ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + return false; + } + return true; + } + }; + if( trabalhador == null ) + { + return; + } + Vector linhas; + try + { + IDObject fichas[] = ( ( FichaDataProvider )FichaDataProvider.getProvider() + ).getAllFichasForTrabalhador( ( Integer ) trabalhador.get( TrabalhadorData.ID ) ); + linhas = new Vector( Arrays.asList( fichas ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a criar lista de Fichas anteriores", true ); + return; + } + ListActionDialog dialog = new ListActionDialog( this, "Imprimir Fichas Anteriores", new String[]{ "Data" }, + linhas, lAction ); + dialog.setSize( 250, 200 ); + dialog.setVisible( true ); + } + + private void printFicha( Integer exameID ) + throws Exception + { +// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); + ExameData exame = (ExameData) JDO.load( ExameData.class, exameID ); + byte pdf[] = (byte []) exame.get( ExameData.PDF ); + if( exame == null ) + { + throw new Exception( "N\u00e3o existe exame" ); + } + TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR ); + String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) ); + nomeFicheiro.replaceAll( " ", "_" ); + ExamePDF ePDF = new ExamePDF(); + ePDF.print( pdf, nomeFicheiro ); + } + + public void setTracker( SIPRPTracker tracker ) + { + this.tracker = tracker; + estabelecimentoPanel.setTracker( tracker ); + trabalhadorPanel.setTracker( tracker ); + } + + public void imprimirEtiquetaTrabalhador() + { + if( trabalhador == null ) + { + return; + } + String nomeEmpresa = ( ( String ) empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + String nomeTrabalhador = ( ( String ) trabalhador.get( TrabalhadorData.NOME ) ); + String numeroMecanografico = ( ( String ) trabalhador.get( TrabalhadorData.NUMERO_MECANOGRAFICO ) ); + String sexo = "m".equals( trabalhador.get( TrabalhadorData.SEXO ) ) ? "M" : "F"; + Date data = ( Date ) trabalhador.get( TrabalhadorData.DATA_NASCIMENTO ); + String dataNascimento = data != null ? DF.format( data ) : "--"; + String nacionalidade = ( String ) trabalhador.get( TrabalhadorData.NACIONALIDADE ); + data = ( Date ) trabalhador.get( TrabalhadorData.DATA_ADMISSAO ); + String dataAdmissao = data != null ? DF.format( data ) : "--"; + String categoria = ( String ) trabalhador.get( TrabalhadorData.CATEGORIA ); + String funcao = ( String ) trabalhador.get( TrabalhadorData.FUNCAO_PROPOSTA ); + try + { + Integer id = clientesProvider.getEtiquetaID(); + EtiquetaData etiqueta = ( EtiquetaData ) JDO.load( EtiquetaData.class, id ); + EtiquetaPrinter printer = new EtiquetaPrinter( etiqueta ); + Vector linhas = new Vector(); + linhas.add( new Object[]{ nomeEmpresa, new Double( 1.0 ) } ); + linhas.add( new Object[]{ nomeTrabalhador, new Double( 1.0 ) } ); + linhas.add( new Object[]{ "N\u00ba mec.:" + ( numeroMecanografico != null ? numeroMecanografico.toString() : "" ), new Double( 0.80 ), + "Sexo:" + sexo, new Double( 0.20 ) } ); + linhas.add( new Object[]{ "Data nasc:" + dataNascimento, new Double( 0.4 ), + "Nacionalidade:" + nacionalidade, new Double( 0.85 ) } ); + linhas.add( new Object[]{ "Data adm.:" + dataAdmissao, new Double( 0.4 ), + "Categoria:" + categoria, new Double( 0.6 ) } ); + linhas.add( new Object[]{ "Fun\u00e7\u00e3o:" + funcao, new Double( 1.0 ) } ); + printer.print( linhas ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar etiqueta.", true ); + } + } + + public void imprimirEtiquetaEstabelecimento() + { + if( estabelecimento == null ) + { + return; + } + String nomeEmpresa = ( ( String ) empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + String nomeEstabelecimento = ( ( String ) estabelecimento.get( EstabelecimentoData.NOME ) ); + ContactoData contacto = ( ContactoData )estabelecimento.get( EstabelecimentoData.CONTACTO ); + String nomeContacto = ""; + if( contacto != null ) + { + nomeContacto = ( String )contacto.get( ContactoData.NOME ); + } + String morada = ( ( String ) estabelecimento.get( EstabelecimentoData.MORADA ) ); + String codigoPostal = ( ( String ) estabelecimento.get( EstabelecimentoData.CODIGO_POSTAL ) ); + String local = ( ( String ) estabelecimento.get( EstabelecimentoData.LOCALIDADE ) ); + + try + { + Integer id = clientesProvider.getEtiquetaID(); + EtiquetaData etiqueta = ( EtiquetaData ) JDO.load( EtiquetaData.class, id ); + EtiquetaPrinter printer = new EtiquetaPrinter( etiqueta ); + Vector linhas = new Vector(); + linhas.add( new Object[]{ nomeEmpresa, new Double( 1.0 ) } ); + linhas.add( new Object[]{ nomeContacto, new Double( 1.0 ) } ); + linhas.add( new Object[]{ morada, new Double( 1.0 ) } ); + linhas.add( new Object[]{ codigoPostal + " " + local, new Double( 1.0 ) } ); + printer.print( linhas ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar etiqueta.", true ); + } + } +} diff --git a/trunk/siprp/clientes/ContactoPanel.java b/trunk/siprp/clientes/ContactoPanel.java new file mode 100644 index 00000000..71c5dae3 --- /dev/null +++ b/trunk/siprp/clientes/ContactoPanel.java @@ -0,0 +1,181 @@ +/* + * ContactoPanel.java + * + * Created on 14 de Maio de 2004, 15:26 + */ + +package siprp.clientes; + +import java.awt.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.dataui.*; +import com.evolute.utils.ui.text.*; + +import siprp.data.*; +/** + * + * @author fpalma + */ +public class ContactoPanel extends JPanel + implements ControllableComponent +{ + private ContactoData contacto; + private ComponentsHashtable components; + + private JTextField nomeText; + private JTextField cargoText; + private JTextField telefoneText; + private JTextField telemovelText; + private JTextField faxText; + private JTextField emailText; + + /** Creates a new instance of ContactoPanel */ + public ContactoPanel() + { + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + JLabel nomeLabel = new JLabel( "Nome" ); + nomeText = new JTextField(); + JLabel cargoLabel = new JLabel( "Cargo" ); + cargoText = new JTextField(); + JLabel telefoneLabel = new JLabel( "Telef." ); + telefoneText = new JTextField(); + JLabel telemovelLabel = new JLabel( "Tlm." ); + telemovelText = new JTextField(); + JLabel faxLabel = new JLabel( "Fax" ); + faxText = new JTextField(); + JLabel emailLabel = new JLabel( "Email" ); + emailText = new JTextField(); + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridheight = 1; + constraints.weighty = 0; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( nomeLabel, constraints ); + add( nomeLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( nomeText, constraints ); + add( nomeText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( cargoLabel, constraints ); + add( cargoLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( cargoText, constraints ); + add( cargoText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( telefoneLabel, constraints ); + add( telefoneLabel ); + + constraints.weightx = .5; + constraints.gridwidth = 1; + gridbag.setConstraints( telefoneText, constraints ); + add( telefoneText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( telemovelLabel, constraints ); + add( telemovelLabel ); + + constraints.weightx = .5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( telemovelText, constraints ); + add( telemovelText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( faxLabel, constraints ); + add( faxLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( faxText, constraints ); + add( faxText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( emailLabel, constraints ); + add( emailLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( emailText, constraints ); + add( emailText ); + + new CopyPasteHandler( nomeText ); + new CopyPasteHandler( cargoText ); + new CopyPasteHandler( telefoneText ); + new CopyPasteHandler( telemovelText ); + new CopyPasteHandler( faxText ); + new CopyPasteHandler( emailText ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( ContactoData.NOME, nomeText ); + components.putComponent( ContactoData.CARGO, cargoText ); + components.putComponent( ContactoData.TELEFONE, telefoneText ); + components.putComponent( ContactoData.TELEMOVEL, telemovelText ); + components.putComponent( ContactoData.FAX, faxText ); + components.putComponent( ContactoData.EMAIL, emailText ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + contacto = null; + } + + public void fill(Object value) + { + clear(); + contacto = ( ContactoData ) value; + if( contacto == null ) + { + return; + } + String names[] = contacto.getFieldNames(); + ComponentController.fill( names, contacto.getHashData(), components ); + } + + public Object save() + { + if( contacto == null ) + { + contacto = new ContactoData(); + } + + String names[] = contacto.getFieldNames(); + Hashtable hash = new Hashtable(); + ComponentController.save( names, hash, components ); + contacto.setHashData( hash ); + return contacto; + } + + public void setEnabled( boolean enable ) + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + } +} diff --git a/trunk/siprp/clientes/EmpresaPanel.java b/trunk/siprp/clientes/EmpresaPanel.java new file mode 100644 index 00000000..79d78098 --- /dev/null +++ b/trunk/siprp/clientes/EmpresaPanel.java @@ -0,0 +1,933 @@ +/* + * EmpresaPanel.java + * + * Created on 12 de Maio de 2004, 19:08 + */ + +package siprp.clientes; + +import java.awt.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.documents.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.*; +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class EmpresaPanel extends JPanel + implements ControllableComponent, ListSelectionListener +{ + private JDOProvider JDO; + + private FichaDataProvider provider; + private EmpresaData empresa; + private ComponentsHashtable components; + + private Integer id; + + private JTextField designacaoSocialText; + private JTextField moradaText; + private JTextField codigoPostalText; + private JTextField localText; + private JTextField distritoText; + private JTextField concelhoText; + private JTextField codigo1Text; + private JTextField codigo2Text; + private JTextField codigo3Text; +// private JTextField perfil1Text; +// private JTextField perfil2Text; + private JComboBox servicosCombo; + private JTextField precoHigieneText; + private JTextField precoMedicinaText; + private JTextField modalidadePagamentoText; + private ContactoPanel contacto1Panel; + private ContactoPanel contacto2Panel; + private JCalendarPanel envioPropostaPanel; + private JCalendarPanel aceitacaoPropostaPanel; + private JCalendarPanel cancelamentoPanel; + private JCalendarPanel envioContratoPanel; + private JCalendarPanel recepcaoContratoPanel; + private JCalendarPanel envioIdictPanel; + private JCalendarPanel relatorioAnualPanel; + private JTextField caeText; + private JTextField actividadeText; + private JTextField contribuinteText; + private JTextField segSocialText; + private JPanel marcacoesPanel; + private JPanel listaMarcacoesPanel; + private BaseTable marcacoesTable; + private MarcacaoEmpresaPanel marcacaoPanel; + private CardLayout marcacoesCardLayout; + private ProtocoloPanel protocoloPanel; +// private UserPanel userPanel; + + private BaseTable estabelecimentosTable; + private VectorTableModel estabelecimentosModel; + + private boolean webAware; + + private Vector listSelectionListeners; + + /** Creates a new instance of EmpresaPanel */ + public EmpresaPanel() + throws Exception + { + webAware = ( ( Boolean ) Singleton.getInstance( SingletonConstants.WEB_AWARE ) ).booleanValue(); + provider = (FichaDataProvider)FichaDataProvider.getProvider(); + listSelectionListeners = new Vector(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + throws Exception + { + String codeFormat = ( String ) Singleton.getInstance( SingletonConstants.CODIGO_EMPRESA_FORMAT ); + String formatElements[] = codeFormat.split( " " ); + int formatFieldLengths[] = new int[ formatElements.length ]; + String fieldSeparators[] = new String[ formatElements.length ]; + int n1 = 0; + int n2 = 0; + for( ; n1 < formatElements.length; n1++ ) + { + try + { + formatFieldLengths[ n2 ] = Integer.parseInt( formatElements[ n1 ] ); + n2++; + } + catch( NumberFormatException ex ) + { + fieldSeparators[ n2 - 1 ] = formatElements[ n1 ]; + } + } + int countFields = n2; + + JLabel designacaoSocialLabel = new JLabel( "Designa\u00e7\u00e3o Social" ); + designacaoSocialText = new StateTextField(); + JLabel codigoLabel = new JLabel( "C\u00f3digo" ); + JPanel codigoPanel = new JPanel(); + codigo1Text = new StateTextField(); + if( countFields > 0 && formatFieldLengths[ 0 ] > 0 ) + { + codigo1Text.setDocument( new MaximumLengthDocument( formatFieldLengths[ 0 ] ) ); + } + codigo2Text = new StateTextField(); + if( countFields > 1 && formatFieldLengths[ 1 ] > 0 ) + { + codigo2Text.setDocument( new MaximumLengthDocument( formatFieldLengths[ 1 ] ) ); + } + codigo3Text = new StateTextField(); + if( countFields > 2 && formatFieldLengths[ 2 ] > 0 ) + { + codigo3Text.setDocument( new MaximumLengthDocument( formatFieldLengths[ 2 ] ) ); + } +// JLabel perfisLabel = new JLabel( "Perfis (A/B)" ); +// perfil1Text = new JTextField(); +// JLabel perfil2Label = new JLabel( "/" ); +// perfil2Text = new JTextField(); + servicosCombo = new JComboBox(); + servicosCombo.setPreferredSize( new Dimension( 120, 20 ) ); + + JLabel precoLabel = new JLabel( "Pre\u00e7os" ); + JLabel precoHigieneLabel = new JLabel( " Higiene" ); + precoHigieneText = new JTextField(); + precoHigieneText.setDocument( new DoubleDocument( 15, true ) ); + JLabel higieneEuroLabel = new JLabel( "\u20ac" ); + JLabel precoMedicinaLabel = new JLabel( " Medicina" ); + precoMedicinaText = new JTextField(); + precoMedicinaText.setDocument( new DoubleDocument( 15, true ) ); + JLabel medicinaEuroLabel = new JLabel( "\u20ac" ); + JLabel modalidadePagamentoLabel = new JLabel( "Periodicidade" ); + modalidadePagamentoText = new JTextField(); + + JLabel moradaLabel = new JLabel( "Morada" ); + moradaText = new StateTextField(); + JLabel codigoPostalLabel = new JLabel( "C\u00f3digo Postal" ); + codigoPostalText = new StateTextField(); + codigoPostalText.setPreferredSize( new Dimension( 50, 20 ) ); + codigoPostalText.setDocument( new MaximumLengthDocument( 8 ) ); + JLabel localLabel = new JLabel( "Localidade" ); + localText = new StateTextField(); + JLabel distritoLabel = new JLabel( "Distrito" ); + distritoText = new JTextField(); + JLabel concelhoLabel = new JLabel( "Concelho" ); + concelhoText = new JTextField(); + contacto1Panel = new ContactoPanel(); + contacto1Panel.setBorder( BorderFactory.createEtchedBorder() ); + contacto2Panel = new ContactoPanel(); + contacto2Panel.setBorder( BorderFactory.createEtchedBorder() ); + JLabel envioPropostaLabel = new JLabel( "Proposta" ); + envioPropostaPanel = new JCalendarPanel( null ); + JLabel aceitacaoPropostaLabel = new JLabel( "Aceita\u00e7\u00e3o" ); + aceitacaoPropostaPanel = new JCalendarPanel( null ); + JLabel cancelamentoLabel = new JLabel( "Cancelamento" ); + cancelamentoPanel = new JCalendarPanel( null ); + JLabel envioContratoLabel = new JLabel( "Envio Contrato" ); + envioContratoPanel = new JCalendarPanel( null ); + JLabel recepcaoContratoLabel = new JLabel( "Recep\u00e7\u00e3o" ); + recepcaoContratoPanel = new JCalendarPanel( null ); + JLabel envioIdictLabel = new JLabel( "Mod. 1360" ); + envioIdictPanel = new JCalendarPanel( null ); + JLabel relatorioAnualLabel = new JLabel( "Relat\u00f3rio Anual" ); + relatorioAnualPanel = new JCalendarPanel( null ); + JTabbedPane tabbedPane = new JTabbedPane(); + JLabel caeLabel = new JLabel( "CAE" ); + caeText = new JTextField(); + JLabel actividadeLabel = new JLabel( " - " ); + actividadeText = new JTextField(); + JLabel contribuinteLabel = new JLabel( "Contribuinte" ); + contribuinteText = new JTextField(); + JLabel segSocialLabel = new JLabel( "Seguran\u00e7a Social" ); + segSocialText = new JTextField(); + JPanel moradaPanel = new JPanel(); + marcacoesPanel = new JPanel(); + protocoloPanel = new ProtocoloPanel(); +// userPanel = new UserPanel(); + + JScrollPane estabelecimentosScroll = new JScrollPane(); + estabelecimentosScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + estabelecimentosModel = new VectorTableModel( new String[]{ "Estabelecimentos" } ); + estabelecimentosTable = new BaseTable( estabelecimentosModel ); + estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + estabelecimentosTable.getSelectionModel().addListSelectionListener( this ); + estabelecimentosScroll.setViewportView( estabelecimentosTable ); + + JPanel dadosEmpresaPanel = new JPanel(); + JPanel contactosPanel = new JPanel(); + JScrollPane contactosScroll = new JScrollPane(); + contactosScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + contactosScroll.setViewportView( contactosPanel ); + contactosScroll.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Contactos" ) ); + JPanel formalidadesPanel = new JPanel(); + + JPanel pad; + + JPanel upperPanel = new JPanel(); + GridBagLayout gridbag = new GridBagLayout(); + upperPanel.setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( designacaoSocialLabel, constraints ); + upperPanel.add( designacaoSocialLabel ); + + constraints.weightx = 0.9; + constraints.gridwidth = 5; + gridbag.setConstraints( designacaoSocialText, constraints ); + upperPanel.add( designacaoSocialText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( codigoLabel, constraints ); + upperPanel.add( codigoLabel ); + + constraints.weightx = 0.1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( codigoPanel, constraints ); + upperPanel.add( codigoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; +// gridbag.setConstraints( moradaLabel, constraints ); +// upperPanel.add( moradaLabel ); + gridbag.setConstraints( caeLabel, constraints ); + upperPanel.add( caeLabel ); + + constraints.weightx = 0.2; + constraints.gridwidth = 1; + gridbag.setConstraints( caeText, constraints ); + upperPanel.add( caeText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; +// gridbag.setConstraints( moradaLabel, constraints ); +// upperPanel.add( moradaLabel ); + gridbag.setConstraints( actividadeLabel, constraints ); + upperPanel.add( actividadeLabel ); + + constraints.weightx = 0.6; + constraints.gridwidth = 1; + gridbag.setConstraints( actividadeText, constraints ); + upperPanel.add( actividadeText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; +// gridbag.setConstraints( codigoPostalLabel, constraints ); +// upperPanel.add( codigoPostalLabel ); + gridbag.setConstraints( contribuinteLabel, constraints ); + upperPanel.add( contribuinteLabel ); + + constraints.weightx = 0.1; + constraints.gridwidth = 1; + gridbag.setConstraints( contribuinteText, constraints ); + upperPanel.add( contribuinteText ); + + constraints.weightx = 0; + constraints.gridwidth = 2; +// gridbag.setConstraints( localLabel, constraints ); +// upperPanel.add( localLabel ); + gridbag.setConstraints( segSocialLabel, constraints ); + upperPanel.add( segSocialLabel ); + + constraints.weightx = 0.1; + constraints.gridwidth = 1; + gridbag.setConstraints( segSocialText, constraints ); + upperPanel.add( segSocialText ); + + + gridbag = new GridBagLayout(); + dadosEmpresaPanel.setLayout( gridbag ); + constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + + contactosPanel.setLayout( new GridLayout( 1, 2 ) ); + contactosPanel.add( contacto1Panel ); + contactosPanel.add( contacto2Panel ); + + gridbag = new GridBagLayout(); + formalidadesPanel.setLayout( gridbag ); + constraints.weighty = 0; + constraints.gridheight = 1; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( envioPropostaLabel, constraints ); + formalidadesPanel.add( envioPropostaLabel ); + + constraints.weightx = 0.3; + gridbag.setConstraints( envioPropostaPanel, constraints ); + formalidadesPanel.add( envioPropostaPanel ); + + constraints.weightx = 0; + gridbag.setConstraints( cancelamentoLabel, constraints ); + formalidadesPanel.add( cancelamentoLabel ); + + constraints.weightx = 0.2; + constraints.gridwidth = 1; +// JPanel perfisPanel = new JPanel(); + gridbag.setConstraints( cancelamentoPanel, constraints ); + formalidadesPanel.add( cancelamentoPanel ); + + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( precoLabel, constraints ); + formalidadesPanel.add( precoLabel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( aceitacaoPropostaLabel, constraints ); + formalidadesPanel.add( aceitacaoPropostaLabel ); + + constraints.weightx = 0.3; + constraints.gridwidth = 1; + gridbag.setConstraints( aceitacaoPropostaPanel, constraints ); + formalidadesPanel.add( aceitacaoPropostaPanel ); + + constraints.weightx = 0.2; + constraints.gridwidth = 2; + gridbag.setConstraints( servicosCombo, constraints ); + formalidadesPanel.add( servicosCombo ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( precoHigieneLabel, constraints ); + formalidadesPanel.add( precoHigieneLabel ); + + constraints.weightx = 0.4; + constraints.gridwidth = 1; + gridbag.setConstraints( precoHigieneText, constraints ); + formalidadesPanel.add( precoHigieneText ); + + constraints.weightx = 0; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( higieneEuroLabel, constraints ); + formalidadesPanel.add( higieneEuroLabel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( envioContratoLabel, constraints ); + formalidadesPanel.add( envioContratoLabel ); + + constraints.weightx = 0.3; + gridbag.setConstraints( envioContratoPanel, constraints ); + formalidadesPanel.add( envioContratoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( relatorioAnualLabel, constraints ); + formalidadesPanel.add( relatorioAnualLabel ); + + constraints.weightx = 0.2; + constraints.gridwidth = 1; + gridbag.setConstraints( relatorioAnualPanel, constraints ); + formalidadesPanel.add( relatorioAnualPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( precoMedicinaLabel, constraints ); + formalidadesPanel.add( precoMedicinaLabel ); + + constraints.weightx = 0.4; + constraints.gridwidth = 1; + gridbag.setConstraints( precoMedicinaText, constraints ); + formalidadesPanel.add( precoMedicinaText ); + + constraints.weightx = 0; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( medicinaEuroLabel, constraints ); + formalidadesPanel.add( medicinaEuroLabel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( recepcaoContratoLabel, constraints ); + formalidadesPanel.add( recepcaoContratoLabel ); + + constraints.weightx = 0.3; + constraints.gridwidth = 1; + gridbag.setConstraints( recepcaoContratoPanel, constraints ); + formalidadesPanel.add( recepcaoContratoPanel ); + + constraints.weightx = 0.2; + constraints.gridwidth = 2; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + formalidadesPanel.add( pad ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( modalidadePagamentoLabel, constraints ); + formalidadesPanel.add( modalidadePagamentoLabel ); + + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( modalidadePagamentoText, constraints ); + formalidadesPanel.add( modalidadePagamentoText ); + + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( envioIdictLabel, constraints ); + formalidadesPanel.add( envioIdictLabel ); + + constraints.weightx = 0.3; + gridbag.setConstraints( envioIdictPanel, constraints ); + formalidadesPanel.add( envioIdictPanel ); + + constraints.weightx = 0.7; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + formalidadesPanel.add( pad ); + +// constraints.weightx = 0.5; +// constraints.gridwidth = GridBagConstraints.REMAINDER; +// pad = new JPanel(); +// gridbag.setConstraints( pad, constraints ); +// formalidadesPanel.add( pad ); + + setLayout( new BorderLayout() ); + add( upperPanel, BorderLayout.NORTH ); + JPanel lowerPanel = new JPanel(); + add( lowerPanel, BorderLayout.CENTER ); + + gridbag = new GridBagLayout(); + lowerPanel.setLayout( gridbag ); + constraints.fill = GridBagConstraints.BOTH; + constraints.insets = new Insets( 0, 0, 0, 0 ); + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + + constraints.weightx = 0.55; + constraints.gridwidth = 1; +// lowerPanel.setLayout( new BorderLayout() ); + //lowerPanel.add( dadosEmpresaPanel ); + //lowerPanel.add( new JPanel() ); + gridbag.setConstraints( tabbedPane, constraints ); + lowerPanel.add( tabbedPane ); +// lowerPanel.add( tabbedPane, BorderLayout.CENTER ); + tabbedPane.add( "Contactos", contactosPanel ); + tabbedPane.add( "Morada", moradaPanel ); + tabbedPane.add( "Formalidades", formalidadesPanel ); + tabbedPane.add( "Protocolo", protocoloPanel ); + tabbedPane.add( "Tarefas", marcacoesPanel ); + +// if( webAware ) +// { +// tabbedPane.add( "Utilizador da P\u00e1gina", userPanel ); +// } + + constraints.weightx = 0.45; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( estabelecimentosScroll, constraints ); + lowerPanel.add( estabelecimentosScroll ); +// lowerPanel.add( estabelecimentosScroll, BorderLayout.EAST ); + + gridbag = new GridBagLayout(); + codigoPanel.setLayout( gridbag ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.insets = new Insets( 1, 0, 1, 2 ); + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + + if( countFields > 0 ) + { + constraints.weightx = 0.2; + constraints.gridwidth = 1; + gridbag.setConstraints( codigo1Text, constraints ); + codigoPanel.add( codigo1Text ); + + if( fieldSeparators[ 0 ] != null ) + { + constraints.weightx = 0; + JLabel divLabel = new JLabel( fieldSeparators[ 0 ] ); + gridbag.setConstraints( divLabel, constraints ); + codigoPanel.add( divLabel ); + } + } + + if( countFields > 1 ) + { + constraints.weightx = 0.5; + gridbag.setConstraints( codigo2Text, constraints ); + codigoPanel.add( codigo2Text ); + + if( fieldSeparators[ 1 ] != null ) + { + constraints.weightx = 0; + JLabel divLabel = new JLabel( fieldSeparators[ 1 ] ); + gridbag.setConstraints( divLabel, constraints ); + codigoPanel.add( divLabel ); + } +// constraints.weightx = 0; +// JLabel divLabel = new JLabel( "/" ); +// gridbag.setConstraints( divLabel, constraints ); +// codigoPanel.add( divLabel ); + } + + if( countFields > 2 ) + { + constraints.weightx = 0.2; +// constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( codigo3Text, constraints ); + codigoPanel.add( codigo3Text ); + + if( fieldSeparators[ 2 ] != null ) + { + constraints.weightx = 0; + JLabel divLabel = new JLabel( fieldSeparators[ 2 ] ); + gridbag.setConstraints( divLabel, constraints ); + codigoPanel.add( divLabel ); + } + } + + +// gridbag = new GridBagLayout(); +// perfisPanel.setLayout( gridbag ); +// constraints.fill = GridBagConstraints.HORIZONTAL; +// constraints.insets = new Insets( 1, 0, 1, 2 ); +// constraints.weighty = 1; +// constraints.gridheight = GridBagConstraints.REMAINDER; +// +// constraints.weightx = 0.5; +// constraints.gridwidth = 1; +// gridbag.setConstraints( perfil1Text, constraints ); +// perfisPanel.add( perfil1Text ); +// +// constraints.weightx = 0; +// constraints.gridwidth = 1; +// gridbag.setConstraints( perfil2Label, constraints ); +// perfisPanel.add( perfil2Label ); +// +// constraints.weightx = 0.5; +// //constraints.gridwidth = GridBagConstraints.REMAINDER; +// gridbag.setConstraints( perfil2Text, constraints ); +// perfisPanel.add( perfil2Text ); + + + gridbag = new GridBagLayout(); + moradaPanel.setLayout( gridbag ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( moradaLabel, constraints ); + moradaPanel.add( moradaLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( moradaText, constraints ); + moradaPanel.add( moradaText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( codigoPostalLabel, constraints ); + moradaPanel.add( codigoPostalLabel ); + + constraints.weightx = 0.3; + gridbag.setConstraints( codigoPostalText, constraints ); + moradaPanel.add( codigoPostalText ); + + constraints.weightx = 0.7; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + moradaPanel.add( pad ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( localLabel, constraints ); + moradaPanel.add( localLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( localText, constraints ); + moradaPanel.add( localText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( distritoLabel, constraints ); + moradaPanel.add( distritoLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( distritoText, constraints ); + moradaPanel.add( distritoText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( concelhoLabel, constraints ); + moradaPanel.add( concelhoLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( concelhoText, constraints ); + moradaPanel.add( concelhoText ); + + + listaMarcacoesPanel = new JPanel(); + listaMarcacoesPanel.setLayout( new GridLayout( 1, 1 ) ); + VectorTableModel marcacoesModel = new VectorTableModel( new String[]{ "Data", "Realizada", "Texto" } ); + marcacoesTable = new BaseTable( marcacoesModel ); + marcacoesTable.setToolTipColumn( 2 ); + marcacoesTable.fixColumnWidth( 0, 150 ); + marcacoesTable.fixColumnWidth( 1, 80 ); + marcacoesTable.setNonResizableNorReordable(); + JScrollPane marcacoesScp = new JScrollPane( marcacoesTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + listaMarcacoesPanel.add( marcacoesScp ); + + marcacoesCardLayout = new CardLayout(); + marcacaoPanel = new MarcacaoEmpresaPanel( this ); + marcacoesPanel.setLayout( marcacoesCardLayout ); + marcacoesPanel.add( MarcacaoEmpresaPanel.LIST_PANEL, listaMarcacoesPanel ); + marcacoesPanel.add( MarcacaoEmpresaPanel.EDIT_PANEL, marcacaoPanel ); + + marcacoesTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){ + public void valueChanged( ListSelectionEvent e ) + { + int selected = marcacoesTable.getSelectedRow(); + if( selected == -1 || e.getValueIsAdjusting() ) + { + return; + } + Object row = ( (VectorTableModel)marcacoesTable.getModel() ).getRowAt( selected ); + marcacoesTable.clearSelection(); + marcacaoPanel.setEmpresa( empresa ); + if( row != null && row instanceof MarcacaoEmpresaData ) + { + marcacaoPanel.fill( row ); + } + else + { + marcacaoPanel.fill( null ); + } + marcacoesCardLayout.show( marcacoesPanel, MarcacaoEmpresaPanel.EDIT_PANEL ); + } + } ); + + servicosCombo.addItem( new MappableObject( new Integer( 1 ), "SHST" ) ); + servicosCombo.addItem( new MappableObject( new Integer( 2 ), "Medicina do Trabalho" ) ); + servicosCombo.addItem( new MappableObject( new Integer( 3 ), "Higiene e Seguran\u00e7a" ) ); + servicosCombo.addItem( new MappableObject( new Integer( 4 ), "Forma\u00e7\u00e3o" ) ); + servicosCombo.addItem( new MappableObject( new Integer( 5 ), "Estudos Especificos HS" ) ); + servicosCombo.addItem( new MappableObject( new Integer( 6 ), "Sinal\u00e9tica" ) ); + + new CopyPasteHandler( designacaoSocialText ); + new CopyPasteHandler( moradaText ); + new CopyPasteHandler( codigoPostalText ); + new CopyPasteHandler( localText ); + new CopyPasteHandler( distritoText ); + new CopyPasteHandler( concelhoText ); + new CopyPasteHandler( codigo1Text ); + new CopyPasteHandler( codigo2Text ); + new CopyPasteHandler( codigo3Text ); +// new CopyPasteHandler( perfil1Text ); +// new CopyPasteHandler( perfil2Text ); + new CopyPasteHandler( precoHigieneText ); + new CopyPasteHandler( precoMedicinaText ); + new CopyPasteHandler( modalidadePagamentoText ); + new CopyPasteHandler( caeText ); + new CopyPasteHandler( actividadeText ); + new CopyPasteHandler( contribuinteText ); + new CopyPasteHandler( segSocialText ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( EmpresaData.DESIGNACAO_SOCIAL, designacaoSocialText ); + components.putComponent( EmpresaData.MORADA, moradaText ); + components.putComponent( EmpresaData.CODIGO_POSTAL, codigoPostalText ); + components.putComponent( EmpresaData.LOCALIDADE, localText ); + components.putComponent( EmpresaData.DISTRITO, distritoText ); + components.putComponent( EmpresaData.CONCELHO, concelhoText ); + components.putComponent( EmpresaData.DATA_PROPOSTA, envioPropostaPanel ); + components.putComponent( EmpresaData.DATA_ACEITACAO, aceitacaoPropostaPanel ); + components.putComponent( EmpresaData.DATA_CANCELAMENTO, cancelamentoPanel ); + components.putDummy( EmpresaData.PERFIL_1 ); + components.putDummy( EmpresaData.PERFIL_2); + components.putComponent( EmpresaData.DATA_ENVIO_CONTRATO, envioContratoPanel ); + components.putComponent( EmpresaData.DATA_RECEPCAO_CONTRATO, recepcaoContratoPanel ); + components.putComponent( EmpresaData.DATA_ENVIO_IDICT, envioIdictPanel ); + components.putComponent( EmpresaData.DATA_RELATORIO_ANUAL, relatorioAnualPanel ); + components.putComponent( EmpresaData.CODIGO_1, codigo1Text ); + components.putComponent( EmpresaData.CODIGO_2, codigo2Text ); + components.putComponent( EmpresaData.CODIGO_3, codigo3Text ); + components.putComponent( EmpresaData.CAE, caeText ); + components.putComponent( EmpresaData.ACTIVIDADE, actividadeText ); + components.putComponent( EmpresaData.CONTRIBUINTE, contribuinteText ); + components.putComponent( EmpresaData.SEGURANCA_SOCIAL, segSocialText ); + components.putComponent( EmpresaData.CONTACTO_1, contacto1Panel ); + components.putComponent( EmpresaData.CONTACTO_2, contacto2Panel ); + components.putComponent( EmpresaData.SERVICOS, servicosCombo ); + components.putComponent( EmpresaData.PRECO_HIGIENE, precoHigieneText ); + components.putComponent( EmpresaData.PRECO_MEDICINA, precoMedicinaText ); + components.putComponent( EmpresaData.PERIODICIDADE, modalidadePagamentoText ); + components.putDummy( EmpresaData.SERVICO_SAUDE_TIPO ); + components.putDummy( EmpresaData.SERVICO_SAUDE_DESIGNACAO ); + components.putDummy( EmpresaData.SERVICO_HIGIENE_TIPO ); + components.putDummy( EmpresaData.SERVICO_HIGIENE_DESIGNACAO ); + components.putDummy( EmpresaData.DESIGNACAO_SOCIAL_PLAIN ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + estabelecimentosModel.clearAll(); + protocoloPanel.clear(); + clearMarcacoes(); + empresa = null; + } + + public void fill(Object value) + { + clear(); + + if( value == null || ( ( Object[] )value )[ 0 ] == null ) + { +// userPanel.setEmpresaID( null ); + return; + } + empresa = ( EmpresaData ) ( ( Object [] )value )[ 0 ]; + Integer elementosProtocolo[][] = ( Integer [][] ) ( ( Object [] )value )[ 1 ]; + + String names[] = ( String[] ) components.keySet().toArray( new String[ components.size() ] ); + ComponentController.fill( names, empresa.getHashData(), components ); + id = (Integer) empresa.get( EmpresaData.ID ); + IDObject estabelecimentos[]; + try + { + estabelecimentos = provider.getAllEstabelecimentosForEmpresa( id ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar a lista de estabelecimentos", true ); + estabelecimentos = new IDObject[0]; + } + reloadMarcacoes(); + Vector v = new Vector( Arrays.asList( estabelecimentos ) ); + estabelecimentosModel.setValues( v ); + + Vector dadosProtocolo[] = new Vector[]{ new Vector(), new Vector() }; + boolean analisesExamesA[] = new boolean[2]; + analisesExamesA[ 0 ] = "y".equals( empresa.get( EmpresaData.A_CONSULTAS ) ); + analisesExamesA[ 1 ] = "y".equals( empresa.get( EmpresaData.A_EXAMES ) ); + dadosProtocolo[ 0 ].add( analisesExamesA ); + dadosProtocolo[ 0 ].add( elementosProtocolo[ 0 ] ); + boolean analisesExamesB[] = new boolean[2]; + analisesExamesB[ 0 ] = "y".equals( empresa.get( EmpresaData.B_CONSULTAS ) ); + analisesExamesB[ 1 ] = "y".equals( empresa.get( EmpresaData.B_EXAMES ) ); + dadosProtocolo[ 1 ].add( analisesExamesB ); + dadosProtocolo[ 1 ].add( elementosProtocolo[ 1 ] ); + protocoloPanel.fill( dadosProtocolo ); +// if( webAware ) +// { +// userPanel.setEmpresaID( (Integer) empresa.get( EmpresaData.ID ) ); +// userPanel.setEnabled( id != null ); +// } + } + + public Object save() + { + if( empresa == null ) + { + empresa = new EmpresaData(); + } + + String names[] = ( String[] ) components.keySet().toArray( new String[ components.size() ] ); + Hashtable hash = empresa.getHashData(); + ComponentController.save( names, hash, components ); + empresa.setHashData( hash ); + Vector dadosProtocolo[] = ( Vector[] ) protocoloPanel.save(); + boolean analisesExamesA[] = ( boolean [] ) dadosProtocolo[ 0 ].elementAt( 0 ); + empresa.set( EmpresaData.A_CONSULTAS, analisesExamesA[ 0 ] ? "y" : "n" ); + empresa.set( EmpresaData.A_EXAMES, analisesExamesA[ 1 ] ? "y" : "n" ); + boolean analisesExamesB[] = ( boolean [] ) dadosProtocolo[ 1 ].elementAt( 0 ); + empresa.set( EmpresaData.B_CONSULTAS, analisesExamesB[ 0 ] ? "y" : "n" ); + empresa.set( EmpresaData.B_EXAMES, analisesExamesB[ 1 ] ? "y" : "n" ); + Integer elementosProtocolo[][] = + new Integer[][]{ ( Integer [] ) dadosProtocolo[ 0 ].elementAt( 1 ), + ( Integer [] ) dadosProtocolo[ 1 ].elementAt( 1 ) }; + return new Object[] { empresa, elementosProtocolo }; + } + + public void setEnabled( boolean enable ) + { + super.setEnabled( enable ); + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + protocoloPanel.setEnabled( enable ); + //estabelecimentosTable.setEnabled( enable ); + } + + public void addListSelectionListener( ListSelectionListener listener ) + { + listSelectionListeners.add( listener ); + } + + public void removeListSelectionListener( ListSelectionListener listener ) + { + listSelectionListeners.remove( listener ); + } + + public void valueChanged( ListSelectionEvent e ) + { + for( int n = 0; n < listSelectionListeners.size(); n++ ) + { + ListSelectionEvent newEvent = + new ListSelectionEvent( this, e.getFirstIndex(), e.getLastIndex(), e.getValueIsAdjusting() ); + ( (ListSelectionListener) listSelectionListeners.elementAt( n ) ).valueChanged( newEvent ); + } + } + + public Integer getSelectedEstabelecimento() + { + int selected = estabelecimentosTable.getSelectedRow(); + if( selected == -1 ) + { + return null; + } + return ( (IDObject) estabelecimentosModel.getRowAt( selected ) ).getID(); + } + + public void reload() + { + int selected = estabelecimentosTable.getSelectedRow(); + fill( empresa ); + if( selected != -1 ) + { + estabelecimentosTable.setRowSelectionInterval( selected, selected ); + } + } + + public JTable getEstabelecimentosTable() + { + return estabelecimentosTable; + } + + public void setSelectedEstabelecimento( EstabelecimentoData estab ) + { + IDObject lista[] = (IDObject [])estabelecimentosModel.getValues().toArray( new IDObject[ 0 ] ); + Integer id = (Integer)estab.get( EstabelecimentoData.ID ); + for( int n = 0; n < lista.length; n++ ) + { + if( lista[ n ].getID().equals( id ) ) + { + estabelecimentosTable.setRowSelectionInterval( n, n ); + return; + } + } + estabelecimentosTable.clearSelection(); + } + + protected void reloadMarcacoes() + { + try + { + Collection marcacoesCollection = + JDO.listLoad( MarcacaoEmpresa.class, new Object[]{ empresa.get( EmpresaData.ID ) }, + new String []{ "empresa.id" }, new String[]{ "data descending" } ); + Vector marcacoes = new Vector(); + marcacoes.add( new ColumnizedObject(){ + public Object getValue( int col ) + { + switch( col ) + { + case 0: case 1: + return ""; + case 2: + return "NOVA TAREFA..."; + } + return null; + } + } ); + if( marcacoesCollection != null ) + { + marcacoes.addAll( marcacoesCollection ); + } + marcacoesTable.clearSelection(); + ( (VectorTableModel) marcacoesTable.getModel() ).setValues( marcacoes ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar as Marca\u00e7\u00f5es", true ); + } + showMarcacoes(); + } + + protected void showMarcacoes() + { + marcacoesCardLayout.show( marcacoesPanel, MarcacaoEmpresaPanel.LIST_PANEL ); + } + + protected void clearMarcacoes() + { + ( (VectorTableModel) marcacoesTable.getModel() ).clearAll(); + } +} diff --git a/trunk/siprp/clientes/EstabelecimentoPanel.java b/trunk/siprp/clientes/EstabelecimentoPanel.java new file mode 100644 index 00000000..07d20df7 --- /dev/null +++ b/trunk/siprp/clientes/EstabelecimentoPanel.java @@ -0,0 +1,450 @@ +/* + * EstabelecimentoPanel.java + * + * Created on 14 de Maio de 2004, 12:21 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.documents.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.*; +import siprp.data.*; +/** + * + * @author fpalma + */ +public class EstabelecimentoPanel extends JPanel + implements ControllableComponent, ListSelectionListener, ActionListener +{ + public static int disables = 0; + + private JDOProvider JDO; + + private EstabelecimentoData estabelecimento; + private ComponentsHashtable components; + + private EmpresaData empresa; + + private JTable estabelecimentosTable; + private JPanel toolbarPanel; + + private JTextField designacaoText; + private JTextField moradaText; + private JTextField localText; + private JTextField codigoPostalText; + private ContactoPanel contactoPanel; + private JTextArea historicoText; + private JButton marcacoesButton; + + private JPanel historicoPanel; + private JPanel listaHistoricoPanel; + private BaseTable historicoTable; + private HistoricoEstabelecimentoPanel edicaoHistoricoPanel; + private CardLayout historicoCardLayout; + +// private MarcacaoPanel marcacaoPanel; + private SIPRPTracker tracker; + + private boolean lastEnable = false; + + /** Creates a new instance of EstabelecimentoPanel */ + public EstabelecimentoPanel( JPanel toolbarPanel, JTextField designacaoText, JTable estabelecimentosTable ) + { + this.toolbarPanel = toolbarPanel; + this.designacaoText = designacaoText; + this.estabelecimentosTable = estabelecimentosTable; + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + JPanel dadosEstabelecimentoPanel = new JPanel(); + JLabel designacaoLabel = new JLabel( "Designa\u00e7\u00e3o" ); + //designacaoText = new JTextField(); + JLabel moradaLabel = new JLabel( "Morada" ); + moradaText = new JTextField(); + JLabel codigoPostalLabel = new JLabel( "C\u00f3digo Postal" ); + codigoPostalText = new JTextField(); + codigoPostalText.setDocument( new MaximumLengthDocument( 8 ) ); + JLabel localLabel = new JLabel( "Local" ); + localText = new JTextField(); + contactoPanel = new ContactoPanel(); + contactoPanel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), + "Contacto" ) ); + marcacoesButton = new JButton( "Marca\u00e7\u00f5es" ); + marcacoesButton.addActionListener( this ); + JPanel pad; + historicoText = new JTextArea(); + new CopyPasteHandler( historicoText ); + historicoText.setLineWrap( true ); + historicoText.setWrapStyleWord( true ); + JScrollPane observacoesScp = new JScrollPane( historicoText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + observacoesScp.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Observa\u00e7\u00f5es" ) ); + historicoPanel = new JPanel(); + historicoPanel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Hist\u00f3rico" ) ); +// marcacaoPanel = new MarcacaoPanel( true, "Realizada", "Relat\u00f3rio", Marcacao.TIPO_MARCACAO_ESTABELECIMENTO ); +// marcacaoPanel.setCalendarDialogOrientation( JCalendarDialog.ABOVE, JCalendarDialog.LEFT ); +// marcacaoPanel.setBorder( BorderFactory.createTitledBorder( +// BorderFactory.createEtchedBorder(), +// "Visita" ) ); + + GridBagLayout gridbag = new GridBagLayout(); + dadosEstabelecimentoPanel.setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridheight = 1; + constraints.weighty = 0; + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( toolbarPanel, constraints ); + dadosEstabelecimentoPanel.add( toolbarPanel ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 1; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + dadosEstabelecimentoPanel.add( pad ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( moradaLabel, constraints ); + dadosEstabelecimentoPanel.add( moradaLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( moradaText, constraints ); + dadosEstabelecimentoPanel.add( moradaText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( codigoPostalLabel, constraints ); + dadosEstabelecimentoPanel.add( codigoPostalLabel ); + + constraints.weightx = 0.3; + constraints.gridwidth = 1; + gridbag.setConstraints( codigoPostalText, constraints ); + dadosEstabelecimentoPanel.add( codigoPostalText ); + + constraints.weightx = 0.7; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + dadosEstabelecimentoPanel.add( pad ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( localLabel, constraints ); + dadosEstabelecimentoPanel.add( localLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( localText, constraints ); + dadosEstabelecimentoPanel.add( localText ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( marcacoesButton, constraints ); + dadosEstabelecimentoPanel.add( marcacoesButton ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( contactoPanel, constraints ); + + gridbag = new GridBagLayout(); + setLayout( gridbag ); + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( dadosEstabelecimentoPanel, constraints ); + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( contactoPanel, constraints ); + constraints.weightx = 0.5; + constraints.weighty = 1; + constraints.gridwidth = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints( historicoPanel, constraints ); + constraints.weightx = 0.5; + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( observacoesScp, constraints ); + add( dadosEstabelecimentoPanel ); + add( contactoPanel ); + add( historicoPanel ); + add( observacoesScp ); + + listaHistoricoPanel = new JPanel(); + listaHistoricoPanel.setLayout( new GridLayout( 1, 1 ) ); + VectorTableModel marcacoesModel = new VectorTableModel( new String[]{ "Data", "Texto" } ); + historicoTable = new BaseTable( marcacoesModel ); + historicoTable.setToolTipColumn( 1 ); + historicoTable.fixColumnWidth( 0, 150 ); + historicoTable.setNonResizableNorReordable(); + JScrollPane listaHistoricoScp = new JScrollPane( historicoTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + listaHistoricoPanel.add( listaHistoricoScp ); + + historicoCardLayout = new CardLayout(); + edicaoHistoricoPanel = new HistoricoEstabelecimentoPanel( this ); + historicoPanel.setLayout( historicoCardLayout ); + historicoPanel.add( HistoricoEstabelecimentoPanel.LIST_PANEL, listaHistoricoPanel ); + historicoPanel.add( HistoricoEstabelecimentoPanel.EDIT_PANEL, edicaoHistoricoPanel ); + + historicoTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){ + public void valueChanged( ListSelectionEvent e ) + { + int selected = historicoTable.getSelectedRow(); + if( selected == -1 || e.getValueIsAdjusting() ) + { + return; + } + Object row = ( (VectorTableModel)historicoTable.getModel() ).getRowAt( selected ); + historicoTable.clearSelection(); + edicaoHistoricoPanel.setEstabelecimento( estabelecimento ); + if( row != null && row instanceof HistoricoEstabelecimentoData ) + { + edicaoHistoricoPanel.fill( row ); + } + else + { + edicaoHistoricoPanel.fill( null ); + } + historicoCardLayout.show( historicoPanel, HistoricoEstabelecimentoPanel.EDIT_PANEL ); + } + } ); + + new CopyPasteHandler( designacaoText ); + new CopyPasteHandler( moradaText ); + new CopyPasteHandler( localText ); + new CopyPasteHandler( codigoPostalText ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( EstabelecimentoData.NOME, designacaoText ); + components.putComponent( EstabelecimentoData.MORADA, moradaText ); + components.putComponent( EstabelecimentoData.LOCALIDADE, localText ); + components.putComponent( EstabelecimentoData.CODIGO_POSTAL, codigoPostalText ); + components.putComponent( EstabelecimentoData.CONTACTO, contactoPanel ); +// components.putComponent( EstabelecimentoData.HISTORICO, historicoText ); + components.putComponent( EstabelecimentoData.HISTORICO, historicoText ); + components.putDummy( EstabelecimentoData.EMPRESA ); + components.putDummy( EstabelecimentoData.NOME_PLAIN ); +// components.putDummy( EstabelecimentoData.INACTIVO ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + clearHistorico(); + estabelecimento = null; + } + + public void fill(Object value) + { + clear(); + estabelecimento = ( EstabelecimentoData ) value; +// marcacaoPanel.setEnabled( estabelecimento != null ); +// marcacaoPanel.fill( estabelecimento ); + if( estabelecimento == null ) + { + estabelecimentosTable.clearSelection(); + return; + } + String names[] = estabelecimento.getFieldNames(); + ComponentController.fill( names, estabelecimento.getHashData(), components ); + reloadHistorico(); + } + + public Object save() + { + if( estabelecimento == null ) + { + estabelecimento = new EstabelecimentoData(); + } + + String names[] = estabelecimento.getFieldNames(); + Hashtable hash = new Hashtable(); + ComponentController.save( names, hash, components ); + estabelecimento.setHashData( hash ); + estabelecimento.set( EstabelecimentoData.EMPRESA, empresa ); + return estabelecimento; + } + + public void postSave() + { + int selected = estabelecimentosTable.getSelectedRow(); + if( estabelecimento != null ) + { + IDObject obj = new MappableObject( (Integer) estabelecimento.get( EstabelecimentoData.ID ), estabelecimento.get( EstabelecimentoData.NOME ) ); + VectorTableModel model = (VectorTableModel)estabelecimentosTable.getModel(); + if( selected == -1 ) + { + model.insertRowAt( obj, estabelecimentosTable.getRowCount() ); + estabelecimentosTable.setRowSelectionInterval( estabelecimentosTable.getRowCount() - 1, estabelecimentosTable.getRowCount() - 1 ); + } + else + { + model.removeRowAt( selected ); + model.insertRowAt( obj, selected ); + estabelecimentosTable.setRowSelectionInterval( selected, selected ); + } + } + } + + public void setEnabled( boolean enable ) + { + super.setEnabled( enable ); + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + if( enable != lastEnable ) + { + if( enable ) + { + disables++; + } + else + { + disables--; + } + lastEnable = enable; + } + estabelecimentosTable.setEnabled( disables == 0 ); +// if( estabelecimento == null ) +// { +// marcacaoPanel.setEnabled( false ); +// } + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( source instanceof EmpresaPanel ) + { + Integer id = ( ( EmpresaPanel ) source ).getSelectedEstabelecimento(); + if( id != null ) + { + try + { + EstabelecimentoData estab = ( EstabelecimentoData ) JDO.load( EstabelecimentoData.class, id ); + fill( estab ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar o estabelecimento", true ); + clear(); + } + } + else + { + clear(); + } + } + } + + public void reload() + { + fill( estabelecimento ); + } + + public void setEmpresa( EmpresaData empresa ) + { + this.empresa = empresa; + } + + protected void reloadHistorico() + { + try + { + Collection historicoCollection = + JDO.listLoad( HistoricoEstabelecimento.class, new Object[]{ estabelecimento.get( EstabelecimentoData.ID ) }, + new String []{ "estabelecimento.id" }, new String[]{ "data descending" } ); + Vector historico = new Vector(); + historico.add( new ColumnizedObject(){ + public Object getValue( int col ) + { + switch( col ) + { + case 0: + return ""; + case 1: + return "NOVO EVENTO..."; + } + return null; + } + } ); + if( historicoCollection != null ) + { + historico.addAll( historicoCollection ); + } + historicoTable.clearSelection(); + ( (VectorTableModel) historicoTable.getModel() ).setValues( historico ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar as Marca\u00e7\u00f5es", true ); + } + showHistorico(); + } + + protected void showHistorico() + { + historicoCardLayout.show( historicoPanel, HistoricoEstabelecimentoPanel.LIST_PANEL ); + } + + protected void clearHistorico() + { + ( (VectorTableModel) historicoTable.getModel() ).clearAll(); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( marcacoesButton ) ) + { + if( empresa == null || estabelecimento == null ) + { + return; + } + else + { + tracker.getHigieneWindow().setVisible( true ); + tracker.getHigieneWindow().setEmpresaAndEstabelecimento( (Integer) empresa.get( EmpresaData.ID ), + ( Integer ) estabelecimento.get( EstabelecimentoData.ID ) ); + } + } + } + + public void setTracker( SIPRPTracker tracker ) + { + this.tracker = tracker; + } +} diff --git a/trunk/siprp/clientes/EtiquetaChooserDialog.java b/trunk/siprp/clientes/EtiquetaChooserDialog.java new file mode 100644 index 00000000..d6324e91 --- /dev/null +++ b/trunk/siprp/clientes/EtiquetaChooserDialog.java @@ -0,0 +1,89 @@ +/* + * EtiquetaChooserPanel.java + * + * Created on 27 de Fevereiro de 2006, 11:21 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.ui.*; + +/** + * + * @author Frederico + */ +public class EtiquetaChooserDialog extends CustomJDialog + implements ActionListener +{ + private int rows; + private int cols; + private final Hashtable positionHash = new Hashtable(); + + private int choice[]; + + /** Creates a new instance of EtiquetaChooserPanel */ + public EtiquetaChooserDialog( JFrame owner, int rows, int cols ) + { + super( owner, true ); + this.rows = rows; + this.cols = cols; + setupComponents(); + if( owner != null ) + { + centerSuper(); + } + else + { + center(); + } + } + + private void setupComponents() + { + setTitle( "Escolha a posi\u00e7\u00e3o" ); + setSize( cols * 200, rows * 50 ); + setLayout( new GridLayout( rows, cols ) ); + for( int r = 0; r < rows; r++ ) + { + for( int c = 0; c < cols; c++ ) + { + JButton button = new JButton( "( " + ( r + 1 ) + " , " + ( c + 1 ) + " )" ); + add( button ); + positionHash.put( button, new int[]{ r, c } ); + button.addActionListener( this ); + } + } + } + + protected void close() + { + SwingUtilities.invokeLater( new Runnable(){ + public void run() + { + setVisible( false ); + dispose(); + } + } ); + } + + public int[] choose() + { + setVisible( true ); + return choice; + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + choice = positionHash.get( ( JButton ) source ); + close(); + } +} diff --git a/trunk/siprp/clientes/EtiquetaPrinter.java b/trunk/siprp/clientes/EtiquetaPrinter.java new file mode 100644 index 00000000..a03c4c0e --- /dev/null +++ b/trunk/siprp/clientes/EtiquetaPrinter.java @@ -0,0 +1,200 @@ +/* + * EtiquetaPrinter.java + * + * Created on 27 de Fevereiro de 2006, 14:41 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.clientes; + +import java.io.*; +import java.text.*; +import java.util.*; + +import com.evolute.utils.fop.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.xml.*; + +import siprp.data.*; + +/** + * + * @author Frederico + */ +public class EtiquetaPrinter +{ + protected static final DecimalFormat N_F = new DecimalFormat(); + + static + { + DecimalFormatSymbols dfs = new DecimalFormatSymbols( new Locale( "pt", "PT" ) ); + dfs.setDecimalSeparator( '.' ); + N_F.setDecimalFormatSymbols( dfs ); + N_F.setMaximumFractionDigits( 4 ); + N_F.setMinimumFractionDigits( 0 ); + } + + protected Double altura; + protected Double largura; + protected Double margemEsquerda; + protected Double margemCima; + protected Integer colunas; + protected Integer linhas; + protected boolean continua; + protected Double alturaFolha; + protected Double larguraFolha; + protected Double margemVerticalFolha; + protected Double margemHorizontalFolha; + + /** Creates a new instance of EtiquetaPrinter */ + public EtiquetaPrinter( EtiquetaData etiqueta ) + { + altura = ( Double ) etiqueta.get( EtiquetaData.ALTURA ); + largura = ( Double ) etiqueta.get( EtiquetaData.LARGURA ); + margemEsquerda = ( Double ) etiqueta.get( EtiquetaData.MARGEM_ESQUERDA ); + margemCima = ( Double ) etiqueta.get( EtiquetaData.MARGEM_CIMA ); + colunas = ( Integer ) etiqueta.get( EtiquetaData.COLUNAS ); + linhas = ( Integer ) etiqueta.get( EtiquetaData.LINHAS ); + continua = "y".equals( etiqueta.get( EtiquetaData.CONTINUA ) ); + alturaFolha = ( Double ) etiqueta.get( EtiquetaData.ALTURA_FOLHA ); + larguraFolha = ( Double ) etiqueta.get( EtiquetaData.LARGURA_FOLHA ); + margemVerticalFolha = ( Double ) etiqueta.get( EtiquetaData.MARGEM_VERTICAL_FOLHA ); + margemHorizontalFolha = ( Double ) etiqueta.get( EtiquetaData.MARGEM_HORIZONTAL_FOLHA ); + } + + public void print( Vector data ) + { + int pos[] = new EtiquetaChooserDialog( null, linhas.intValue(), colunas.intValue() ).choose(); + if( pos == null ) + { + return; + } + int row = pos[ 0 ]; + int col = pos[ 1 ]; + String header = ""; + SimpleXMLElement styleSheet = + new SimpleXMLElement( "xsl:stylesheet" ); + styleSheet.addAttribute( "version", "1.1" ); + styleSheet.addAttribute( "xmlns:xsl", "http://www.w3.org/1999/XSL/Transform" ); + styleSheet.addAttribute( "xmlns:fo", "http://www.w3.org/1999/XSL/Format" ); + styleSheet.addAttribute( "exclude-result-prefixes", "fo" ); + styleSheet.setCompact( false ); + + SimpleXMLElement output = + new SimpleXMLElement( "xsl:output" ); + styleSheet.addElement( output ); + output.addAttribute( "method", "xml" ); + output.addAttribute( "version", "1.0" ); + output.addAttribute( "omit-xml-declaration", "no" ); + output.addAttribute( "indent", "yes" ); + + SimpleXMLElement template = + new SimpleXMLElement( "xsl:template" ); + styleSheet.addElement( template ); + template.addAttribute( "match", "ETIQUETA" ); + + SimpleXMLElement root = + new SimpleXMLElement( "fo:root" ); + template.addElement( root ); + + SimpleXMLElement layoutMasterSet = + new SimpleXMLElement( "fo:layout-master-set" ); + root.addElement( layoutMasterSet ); + + SimpleXMLElement simplePageMaster = + new SimpleXMLElement( "fo:simple-page-master" ); + layoutMasterSet.addElement( simplePageMaster ); + simplePageMaster.addAttribute( "master-name", "simpleA4" ); + simplePageMaster.addAttribute( "page-height", N_F.format( alturaFolha ) + "cm" ); + simplePageMaster.addAttribute( "page-width", N_F.format( larguraFolha ) + "cm" ); + simplePageMaster.addAttribute( "margin-top", N_F.format( ( row == 0 ? margemVerticalFolha : 0.0 ) + row * ( altura + margemCima ) ) + "cm" ); + simplePageMaster.addAttribute( "margin-bottom", "0.5cm" ); + simplePageMaster.addAttribute( "margin-left", N_F.format( ( col == 0 ? margemHorizontalFolha : 0.0 ) + col * ( largura + margemEsquerda ) ) + "cm" ); + simplePageMaster.addAttribute( "margin-right", N_F.format( col == colunas - 1 ? margemHorizontalFolha : 0.0 ) ); + + SimpleXMLElement regionBody = + new SimpleXMLElement( "fo:region-body" ); + simplePageMaster.addElement( regionBody ); + + SimpleXMLElement pageSequence = + new SimpleXMLElement( "fo:page-sequence" ); + root.addElement( pageSequence ); + pageSequence.addAttribute( "master-reference", "simpleA4" ); + + SimpleXMLElement flow = + new SimpleXMLElement( "fo:flow" ); + pageSequence.addElement( flow ); + flow.addAttribute( "flow-name", "xsl-region-body" ); + + for( Object line[] : data ) + { + SimpleXMLElement lineXML = createLine( line, largura - ( col == 0 || col == colunas - 1 ? margemHorizontalFolha : 0.0 ) ); + flow.addElement( lineXML ); + } +//System.out.println( "XSL: " + styleSheet.toString() ); + String xml = ""; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + FOPCreator creator = new FOPCreator(); + InputStream xmlIn = new ByteArrayInputStream( xml.getBytes() ); + try + { + creator.createFOfromXML( xmlIn, new ByteArrayInputStream( (header+styleSheet).getBytes() ), out ); + ByteArrayInputStream in = new ByteArrayInputStream( out.toString().getBytes() ); + Hashtable printOptions = new Hashtable(); +//System.out.println( "OUT: " + out.toString() ); + com.evolute.utils.fop.FOPPrinter printer = new com.evolute.utils.fop.FOPPrinter(); + printer.printFO( in, false, true, printOptions ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a imprimir", true ); + } + } + + protected SimpleXMLElement createLine( Object[] line, Double larguraDisponival ) + { + SimpleXMLElement table = + new SimpleXMLElement( "fo:table" ); + table.addAttribute( "table-layout", "fixed" ); + table.addAttribute( "width", N_F.format( larguraDisponival ) + "cm" ); + table.addAttribute( "space-before.optimum", "0pt" ); + table.addAttribute( "space-after.optimum", "0pt" ); + + for( int n = 1; n < line.length; n += 2 ) + { + SimpleXMLElement tableColumn = + new SimpleXMLElement( "fo:table-column" ); + table.addElement( tableColumn ); + tableColumn.addAttribute( "column-width", N_F.format( ( ( Double ) line[ n ] ) * larguraDisponival ) + "cm" ); + } + + SimpleXMLElement tableBody = + new SimpleXMLElement( "fo:table-body" ); + table.addElement( tableBody ); + + SimpleXMLElement tableRow = + new SimpleXMLElement( "fo:table-row" ); + tableBody.addElement( tableRow ); + + for( int n = 0; n < line.length; n += 2 ) + { + SimpleXMLElement tableCell = + new SimpleXMLElement( "fo:table-cell" ); + tableRow.addElement( tableCell ); + + SimpleXMLElement block = + new SimpleXMLElement( "fo:block" ); + tableCell.addElement( block ); + block.addAttribute( "font-size", "10pt" ); + block.addAttribute( "text-align", "left" ); +// block.addAttribute( "wrap-option", "no-wrap" ); +// block.addAttribute( "overflow", "scroll" ); + + block.addTextElement( ( String ) line[ n ] ); + } + + return table; + } +} diff --git a/trunk/siprp/clientes/HistoricoEstabelecimentoPanel.java b/trunk/siprp/clientes/HistoricoEstabelecimentoPanel.java new file mode 100644 index 00000000..e48c55ab --- /dev/null +++ b/trunk/siprp/clientes/HistoricoEstabelecimentoPanel.java @@ -0,0 +1,272 @@ +/* + * HistoricoEstabelecimentoPanel.java + * + * Created on 7 de Dezembro de 2004, 15:17 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.toolbar.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class HistoricoEstabelecimentoPanel extends JPanel + implements ControllableComponent, DocumentListener, ActionListener +{ + protected static final String LIST_PANEL = "LIST_PANEL"; + protected static final String FULL_LIST_PANEL = "FULL_LIST_PANEL"; + protected static final String EDIT_PANEL = "EDIT_PANEL"; + + private ComponentsHashtable components; + private EstabelecimentoPanel owner; + + private JCalendarPanel calendarPanel; + private JTextArea text; + private JButton saveButton; + private JButton cancelButton; + + private EstabelecimentoData estabelecimento; + private boolean changed = false; + private boolean filling = false; + + private HistoricoEstabelecimentoData historico; + + public HistoricoEstabelecimentoPanel( EstabelecimentoPanel owner ) + { + this.owner = owner; + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + calendarPanel = new JCalendarPanel( null ); +// calendarPanel.addDocumentListener( this ); + text = new JTextArea(); + new CopyPasteHandler( text ); +// text.getDocument().addDocumentListener( this ); + text.setLineWrap( true ); + text.setWrapStyleWord( true ); + JScrollPane textScp = new JScrollPane( text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + saveButton = new JButton( "Guardar" ); + saveButton.addActionListener( this ); + cancelButton = new JButton( "Voltar" ); + cancelButton.addActionListener( this ); + + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + + constraints.weightx = 0; + constraints.gridwidth = 1; + constraints.weighty = 0; + constraints.gridheight = 1; + calendarPanel.setPreferredSize( new Dimension( 130, 30 ) ); + gridbag.setConstraints( calendarPanel, constraints ); + add( calendarPanel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + JPanel buttonPanel = new JPanel(); + gridbag.setConstraints( buttonPanel, constraints ); + add( buttonPanel ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1; + gridbag.setConstraints( textScp, constraints ); + add( textScp ); + + buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); + initButtons(); + buttonPanel.add( cancelButton ); + buttonPanel.add( saveButton ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( HistoricoEstabelecimentoData.DATA, calendarPanel ); + components.putComponent( HistoricoEstabelecimentoData.TEXTO, text ); + components.putDummy( HistoricoEstabelecimentoData.ESTABELECIMENTO ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + historico = null; + } + + public void fill(Object value) + { + filling = true; + clear(); + initButtons(); + historico = (HistoricoEstabelecimentoData)value; + if( historico == null ) + { + filling = false; + return; + } + String names[] = historico.getFieldNames(); + ComponentController.fill( names, historico.getHashData(), components ); + filling = false; + } + + public Object save() + { + if( historico == null ) + { + historico = new HistoricoEstabelecimentoData(); + } + + String names[] = historico.getFieldNames(); + Hashtable hash = new Hashtable(); + + ComponentController.save( names, hash, components ); + hash.put( HistoricoEstabelecimentoData.ESTABELECIMENTO, estabelecimento ); + historico.setHashData( hash ); + return historico; + } + + public void setEnabled(boolean enable) + { + super.setEnabled( enable ); + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + } + + public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + public void insertUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + public void removeUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + private void startEditedState() + { + if( !filling ) + { + calendarPanel.removeDocumentListener( this ); + text.getDocument().removeDocumentListener( this ); + changed = true; + saveButton.setEnabled( true ); + changeButton(); + } + } + + private void initButtons() + { + saveButton.setEnabled( false ); + calendarPanel.addDocumentListener( this ); + text.getDocument().addDocumentListener( this ); + ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader(); + Icon normal = new ImageIcon( cl.getResource( "buttons/save_normal.gif" ) ); + Icon rollover = new ImageIcon( cl.getResource( "buttons/save_rollover.gif" ) ); + Icon pressed = new ImageIcon( cl.getResource( "buttons/save_pressed.gif" ) ); + Icon disabled = new ImageIcon( cl.getResource( "buttons/save_disabled.gif" ) ); + saveButton.setIcon( normal ); + saveButton.setRolloverIcon( rollover ); + saveButton.setPressedIcon( pressed ); + saveButton.setDisabledIcon( disabled ); + saveButton.setText( null ); + saveButton.setBorderPainted( false ); + saveButton.setRequestFocusEnabled( false ); + saveButton.setMargin( new Insets( 0, 0, 0, 0 ) ); + saveButton.setToolTipText( "Gravar" ); + + normal = new ImageIcon( cl.getResource( "buttons/shiftl_normal.gif" ) ); + rollover = new ImageIcon( cl.getResource( "buttons/shiftl_rollover.gif" ) ); + pressed = new ImageIcon( cl.getResource( "buttons/shiftl_pressed.gif" ) ); + disabled = new ImageIcon( cl.getResource( "buttons/shiftl_disabled.gif" ) ); + cancelButton.setIcon( normal ); + cancelButton.setRolloverIcon( rollover ); + cancelButton.setPressedIcon( pressed ); + cancelButton.setDisabledIcon( disabled ); + cancelButton.setText( null ); + cancelButton.setBorderPainted( false ); + cancelButton.setRequestFocusEnabled( false ); + cancelButton.setMargin( new Insets( 0, 0, 0, 0 ) ); + cancelButton.setToolTipText( "Voltar \u00e0 lista" ); + + } + + private void changeButton() + { + ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader(); + Icon normal = new ImageIcon( cl.getResource( "buttons/cancel_normal.gif" ) ); + Icon rollover = new ImageIcon( cl.getResource( "buttons/cancel_rollover.gif" ) ); + Icon pressed = new ImageIcon( cl.getResource( "buttons/cancel_pressed.gif" ) ); + Icon disabled = new ImageIcon( cl.getResource( "buttons/cancel_disabled.gif" ) ); + cancelButton.setIcon( normal ); + cancelButton.setRolloverIcon( rollover ); + cancelButton.setPressedIcon( pressed ); + cancelButton.setDisabledIcon( disabled ); + cancelButton.setToolTipText( "Cancelar" ); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( saveButton ) ) + { + if( calendarPanel.getDate() == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher uma data", "Erro...", JOptionPane.ERROR_MESSAGE ); + return; + } + HistoricoEstabelecimentoData hist = ( HistoricoEstabelecimentoData ) save(); + + try + { + hist.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + return; + } + owner.reloadHistorico(); + } + else if( source.equals( cancelButton ) ) + { + owner.showHistorico(); + } + + } + + public void setEstabelecimento( EstabelecimentoData estabelecimento ) + { + this.estabelecimento = estabelecimento; + } +} diff --git a/trunk/siprp/clientes/MarcacaoEmpresaPanel.java b/trunk/siprp/clientes/MarcacaoEmpresaPanel.java new file mode 100644 index 00000000..56adfc21 --- /dev/null +++ b/trunk/siprp/clientes/MarcacaoEmpresaPanel.java @@ -0,0 +1,287 @@ +/* + * MarcacaoEmpresaPanel.java + * + * Created on 25 de Junho de 2004, 20:32 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.toolbar.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class MarcacaoEmpresaPanel extends JPanel + implements ControllableComponent, DocumentListener, ActionListener, ChangeListener +{ + protected static final String LIST_PANEL = "LIST_PANEL"; + protected static final String EDIT_PANEL = "EDIT_PANEL"; + + private ComponentsHashtable components; + private EmpresaPanel owner; + + private JCalendarPanel calendarPanel; + private JTextArea text; + private JCheckBox realizadaCheck; + private JButton saveButton; + private JButton cancelButton; + + private EmpresaData empresa; + private boolean changed = false; + private boolean filling = false; + + private MarcacaoEmpresaData marcacao; + + /** Creates a new instance of MarcacaoEmpresaPanel */ + public MarcacaoEmpresaPanel( EmpresaPanel owner ) + { + this.owner = owner; + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + calendarPanel = new JCalendarPanel( null ); +// calendarPanel.addDocumentListener( this ); + text = new JTextArea(); + new CopyPasteHandler( text ); +// text.getDocument().addDocumentListener( this ); + text.setLineWrap( true ); + text.setWrapStyleWord( true ); + JScrollPane textScp = new JScrollPane( text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + realizadaCheck = new JCheckBox( "Realizada" ); + saveButton = new JButton( "Guardar" ); + saveButton.addActionListener( this ); + cancelButton = new JButton( "Voltar" ); + cancelButton.addActionListener( this ); + + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + + constraints.weightx = 0; + constraints.gridwidth = 1; + constraints.weighty = 0; + constraints.gridheight = 1; + calendarPanel.setPreferredSize( new Dimension( 130, 30 ) ); + gridbag.setConstraints( calendarPanel, constraints ); + add( calendarPanel ); + + gridbag.setConstraints( realizadaCheck, constraints ); + add( realizadaCheck ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + JPanel buttonPanel = new JPanel(); + gridbag.setConstraints( buttonPanel, constraints ); + add( buttonPanel ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1; + gridbag.setConstraints( textScp, constraints ); + add( textScp ); + + buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); + initButtons(); + buttonPanel.add( cancelButton ); + buttonPanel.add( saveButton ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( MarcacaoEmpresaData.DATA, calendarPanel ); + components.putComponent( MarcacaoEmpresaData.TEXTO, text ); + components.putComponent( MarcacaoEmpresaData.REALIZADA, realizadaCheck ); + components.putDummy( MarcacaoEmpresaData.EMPRESA ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + marcacao = null; + } + + public void fill(Object value) + { + filling = true; + clear(); + initButtons(); + marcacao = (MarcacaoEmpresaData)value; + if( marcacao == null ) + { + filling = false; + return; + } + String names[] = marcacao.getFieldNames(); + ComponentController.fill( names, marcacao.getHashData(), components ); + filling = false; + } + + public Object save() + { + if( marcacao == null ) + { + marcacao = new MarcacaoEmpresaData(); + } + + String names[] = marcacao.getFieldNames(); + Hashtable hash = new Hashtable(); + + ComponentController.save( names, hash, components ); + hash.put( MarcacaoEmpresaData.EMPRESA, empresa ); + marcacao.setHashData( hash ); + System.out.println( "EMPRESA:: " + marcacao.get( MarcacaoEmpresaData.EMPRESA ) ); + return marcacao; + } + + public void setEnabled(boolean enable) + { + super.setEnabled( enable ); + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + } + + public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + public void insertUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + public void removeUpdate(javax.swing.event.DocumentEvent documentEvent) + { + startEditedState(); + } + + private void startEditedState() + { + if( !filling ) + { + calendarPanel.removeDocumentListener( this ); + text.getDocument().removeDocumentListener( this ); + realizadaCheck.removeChangeListener( this ); + changed = true; + saveButton.setEnabled( true ); + changeButton(); + } + } + + private void initButtons() + { + saveButton.setEnabled( false ); + calendarPanel.addDocumentListener( this ); + realizadaCheck.addChangeListener( this ); + text.getDocument().addDocumentListener( this ); + ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader(); + Icon normal = new ImageIcon( cl.getResource( "buttons/save_normal.gif" ) ); + Icon rollover = new ImageIcon( cl.getResource( "buttons/save_rollover.gif" ) ); + Icon pressed = new ImageIcon( cl.getResource( "buttons/save_pressed.gif" ) ); + Icon disabled = new ImageIcon( cl.getResource( "buttons/save_disabled.gif" ) ); + saveButton.setIcon( normal ); + saveButton.setRolloverIcon( rollover ); + saveButton.setPressedIcon( pressed ); + saveButton.setDisabledIcon( disabled ); + saveButton.setText( null ); + saveButton.setBorderPainted( false ); + saveButton.setRequestFocusEnabled( false ); + saveButton.setMargin( new Insets( 0, 0, 0, 0 ) ); + saveButton.setToolTipText( "Gravar" ); + + normal = new ImageIcon( cl.getResource( "buttons/shiftl_normal.gif" ) ); + rollover = new ImageIcon( cl.getResource( "buttons/shiftl_rollover.gif" ) ); + pressed = new ImageIcon( cl.getResource( "buttons/shiftl_pressed.gif" ) ); + disabled = new ImageIcon( cl.getResource( "buttons/shiftl_disabled.gif" ) ); + cancelButton.setIcon( normal ); + cancelButton.setRolloverIcon( rollover ); + cancelButton.setPressedIcon( pressed ); + cancelButton.setDisabledIcon( disabled ); + cancelButton.setText( null ); + cancelButton.setBorderPainted( false ); + cancelButton.setRequestFocusEnabled( false ); + cancelButton.setMargin( new Insets( 0, 0, 0, 0 ) ); + cancelButton.setToolTipText( "Voltar \u00e0 lista" ); + + } + + private void changeButton() + { + ClassLoader cl = new EVUtilsImageLib().getClass().getClassLoader(); + Icon normal = new ImageIcon( cl.getResource( "buttons/cancel_normal.gif" ) ); + Icon rollover = new ImageIcon( cl.getResource( "buttons/cancel_rollover.gif" ) ); + Icon pressed = new ImageIcon( cl.getResource( "buttons/cancel_pressed.gif" ) ); + Icon disabled = new ImageIcon( cl.getResource( "buttons/cancel_disabled.gif" ) ); + cancelButton.setIcon( normal ); + cancelButton.setRolloverIcon( rollover ); + cancelButton.setPressedIcon( pressed ); + cancelButton.setDisabledIcon( disabled ); + cancelButton.setToolTipText( "Cancelar" ); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( saveButton ) ) + { + if( calendarPanel.getDate() == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher uma data", "Erro...", JOptionPane.ERROR_MESSAGE ); + return; + } + MarcacaoEmpresaData marc = ( MarcacaoEmpresaData ) save(); + + try + { + marc.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + return; + } + owner.reloadMarcacoes(); + } + else if( source.equals( cancelButton ) ) + { + owner.showMarcacoes(); + } + + } + + public void setEmpresa( EmpresaData empresa ) + { + this.empresa = empresa; + } + + public void stateChanged(javax.swing.event.ChangeEvent changeEvent) + { + startEditedState(); + } + +} diff --git a/trunk/siprp/clientes/MarcacaoPanel.java b/trunk/siprp/clientes/MarcacaoPanel.java new file mode 100644 index 00000000..007feabf --- /dev/null +++ b/trunk/siprp/clientes/MarcacaoPanel.java @@ -0,0 +1,625 @@ +/* + * MarcacaoPanel.java + * + * Created on 14 de Maio de 2004, 15:52 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.panel.*; + +import siprp.*; +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class MarcacaoPanel extends JPanel + implements ControllableComponent, ActionListener +{ + private final String COLUMN_NAMES_REL[]; + private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT ); + + private Marcacao marcacoes[]; + private ComponentsHashtable components; + private int tipo; + + private final boolean comRelatorio; + + private Box anteriorPanel; + private JPanel correntePanel; + + private String realizadoLabelText; + private String relatorioLabelText; + + private JLabel dataMarcacaoAnteriorLabel; + private JCheckBox realizadaCheckBox; + private JCalendarPanel dataRelatorioPanel; + private JCalendarPanel dataMarcacaoPanel; + private JButton enviarEmailButton; + private JLabel dataEnvioMailLabel; + private JButton historicoButton; + + private TrabalhadorData trabalhador; + private EstabelecimentoData estabelecimento; + + private MarcacaoListLoader loader; + private Marcacao current; + private Marcacao last; + + private boolean filling = false; + + /** Creates a new instance of MarcacaoPanel */ + public MarcacaoPanel( boolean comRelatorio, String realizadoLabelText, String relatorioLabelText, int tipo ) + { + this.comRelatorio = comRelatorio; + this.realizadoLabelText = realizadoLabelText; + this.relatorioLabelText = relatorioLabelText; + this.tipo = tipo; + COLUMN_NAMES_REL = new String[ comRelatorio ? 3 : 2 ]; + COLUMN_NAMES_REL[ 0 ] = "Data"; + COLUMN_NAMES_REL[ 1 ] = realizadoLabelText; + if( comRelatorio ) + { + COLUMN_NAMES_REL[ 2 ] = relatorioLabelText; + } + loader = new MarcacaoListLoader(); + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + anteriorPanel = new Box( BoxLayout.X_AXIS ); + anteriorPanel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), + "Anterior" ) ); + correntePanel = new JPanel(); +// correntePanel.setBorder( BorderFactory.createTitledBorder( +// BorderFactory.createEtchedBorder(), +// "Corrente" ) ); + JPanel dataPanel = new JPanel(); + Box relatorioBox = new Box( BoxLayout.X_AXIS ); + + dataMarcacaoAnteriorLabel = new JLabel( "-" ); + dataEnvioMailLabel = new JLabel( "" ); + realizadaCheckBox = new JCheckBox( realizadoLabelText + " " ); + realizadaCheckBox.addChangeListener( new ChangeListener(){ + public void stateChanged( ChangeEvent e ) + { +System.out.println( "stateChanged" ); + if( last != null && !filling ) + { +System.out.println( "stateChanged2" ); + last.set( Marcacao.REALIZADA, realizadaCheckBox.isSelected() ? "y": "n" ); + try + { + last.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + realizadaCheckBox.setSelected( realizadaCheckBox.isSelected() ); + } + } + } + } ); + JLabel relatorioLabel = new JLabel( relatorioLabelText ); + dataRelatorioPanel = new JCalendarPanel( null ); + dataRelatorioPanel.addDocumentListener( new DocumentListener(){ + public void changedUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcarRelatorio(); + } + } + + public void insertUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcarRelatorio(); + } + } + + public void removeUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcarRelatorio(); + } + } + + private void marcarRelatorio() + { + last.set( Marcacao.DATA_RELATORIO, dataRelatorioPanel.getDate() ); + try + { + last.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + } + } + } ); + + dataMarcacaoPanel = new JCalendarPanel( null ); + dataMarcacaoPanel.addDocumentListener( new DocumentListener(){ + public void changedUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcar(); + } + } + + public void insertUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcar(); + } + } + + public void removeUpdate( DocumentEvent e ) + { + if( !filling ) + { + marcar(); + } + } + } ); + enviarEmailButton = new JButton( "Enviar Email" ); + enviarEmailButton.addActionListener( this ); + historicoButton = new JButton( "H" ); + historicoButton.addActionListener( this ); + + anteriorPanel.add( dataPanel ); + if( comRelatorio ) + { + anteriorPanel.add( relatorioBox ); + anteriorPanel.add( relatorioLabel ); + anteriorPanel.add( dataRelatorioPanel ); + } + + dataPanel.setLayout( new GridLayout( 1, 2 ) ); + dataPanel.add( dataMarcacaoAnteriorLabel ); + dataPanel.add( realizadaCheckBox ); + + correntePanel.setLayout( new GridLayout( 1, 2 ) ); + correntePanel.add( dataMarcacaoPanel ); + correntePanel.add( enviarEmailButton ); + + //setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) ); + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0.5; + constraints.gridheight = 1; + constraints.weightx = 1; + constraints.gridwidth = 1; + + gridbag.setConstraints( anteriorPanel, constraints ); + add( anteriorPanel ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 1; + constraints.gridheight = 2; + constraints.weightx = 0; + constraints.gridwidth = GridBagConstraints.REMAINDER; + historicoButton.setPreferredSize( new Dimension( 20, 40 ) ); + gridbag.setConstraints( historicoButton, constraints ); + add( historicoButton ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0.5; + constraints.gridheight = 1; + constraints.weightx = 1; + constraints.gridwidth = 1; + constraints.gridx = 0; + gridbag.setConstraints( correntePanel, constraints ); + add( correntePanel ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( Marcacao.DATA, dataMarcacaoPanel ); + components.putComponent( Marcacao.REALIZADA, realizadaCheckBox ); + components.putComponent( Marcacao.DATA_RELATORIO, dataRelatorioPanel ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + dataMarcacaoAnteriorLabel.setText( "" ); + dataEnvioMailLabel.setText( "" ); + marcacoes = null; + trabalhador = null; + estabelecimento = null; + current = null; + last = null; + } + + public void fill( Object value ) + { + filling = true; + clear(); + if( value == null ) + { + setEnabled( false ); + filling = false; + return; + } + switch( tipo ) + { + case Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES: case Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA: + if( ! ( value instanceof TrabalhadorData ) ) + { + filling = false; + return ; + } + trabalhador = (TrabalhadorData) value; + try + { + marcacoes = loader.load( tipo, (Integer)trabalhador.get( TrabalhadorData.ID ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar as marca\u00e7\u00f5es", true ); + marcacoes = null; + } + break; + + case Marcacao.TIPO_MARCACAO_ESTABELECIMENTO: + if( ! ( value instanceof EstabelecimentoData ) ) + { + filling = false; + return ; + } + estabelecimento = (EstabelecimentoData) value; + try + { + marcacoes = loader.load( tipo, (Integer)estabelecimento.get( EstabelecimentoData.ID ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar as marca\u00e7\u00f5es", true ); + marcacoes = null; + } + break; + } + if( marcacoes == null || marcacoes.length == 0 ) + { + filling = false; + return; + } + Date lastDate = (Date) marcacoes[ 0 ].get( Marcacao.DATA ); + current = null; + last = null; + if( !lastDate.after( new Date() ) ) + { + current = null; + last = marcacoes[ 0 ]; + } + else + { + current = marcacoes[ 0 ]; + if( marcacoes.length > 1 ) + { + last = marcacoes[ 1 ]; + } + } + fillCurrent(); + fillLast(); + filling = false; + } + + private void fillCurrent() + { + if( current != null ) + { + Date dataMarcacao = (Date) current.get( Marcacao.DATA ); + dataMarcacaoPanel.setDate( dataMarcacao ); + Date dataMail = (Date) current.get( Marcacao.DATA_EMAIL ); + if( dataMail == null ) + { + enviarEmailButton.setEnabled( dataMarcacao != null ); + dataEnvioMailLabel.setText( "" ); + } + else + { + enviarEmailButton.setEnabled( false ); + dataEnvioMailLabel.setText( DATE_FORMAT.format( dataMail ) ); + } + } + else + { + enviarEmailButton.setEnabled( false ); + } + } + + private void fillLast() + { + if( last != null ) + { + Date dataMarcacao = (Date) last.get( Marcacao.DATA ); + dataMarcacaoAnteriorLabel.setText( DATE_FORMAT.format( dataMarcacao ) ); + String realizada = (String) last.get( Marcacao.REALIZADA ); + boolean isRealizada = "y".equals( realizada ); + realizadaCheckBox.setSelected( isRealizada ); + realizadaCheckBox.setEnabled( !isRealizada ); + Date dataRelatorio = (Date) last.get( Marcacao.DATA_RELATORIO ); + dataRelatorioPanel.setDate( dataRelatorio ); + } + else + { + realizadaCheckBox.setEnabled( false ); + dataRelatorioPanel.setEnabled( false ); + } + } + + public Object save() + { +// if( marcacoes == null ) +// { +// marcacoes = new Marcacao[ 0 ]; +// } +// if( marcacoes[ marcacoes.length - 1 ] == null ) +// { +// marcacoes[ marcacoes.length - 1 ] = Marcacao.getMarcacao( tipo ); +// } +// if( marcacoes.length > 1 ) +// { +// } + return null; + } + + public void setEnabled( boolean enable ) + { + filling = true; + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + if( !enable ) + { + enviarEmailButton.setEnabled( false ); + } + if( last == null ) + { + realizadaCheckBox.setEnabled( false ); + dataRelatorioPanel.setEnabled( false ); + } + filling = false; + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( enviarEmailButton ) ) + { + Date today = new Date(); + current.set( Marcacao.DATA_EMAIL, today ); + String subject = "."; + String texto = ""; + EstabelecimentoData estab = null; + if( current instanceof MarcacaoTrabalhadorData ) + { + TrabalhadorData trab = ( TrabalhadorData )current.get( MarcacaoTrabalhadorData.TRABALHADOR ); + String nome = ( String )trab.get( TrabalhadorData.NOME ); + String data = DateFormat.getDateInstance( DateFormat.SHORT ).format( ( Date )current.get( MarcacaoTrabalhadorData.DATA ) ); + if( ( ( Number )current.get( MarcacaoTrabalhadorData.TIPO ) ).intValue() == MarcacaoTrabalhadorConstants.TIPO_EXAMES ) + { + subject = ( String ) Singleton.getInstance( SingletonConstants.SUBJECT_EXAMES ); + subject = subject.replaceAll( CompanyDataLoader.NOME, nome ); + texto = ( String ) Singleton.getInstance( SingletonConstants.LETTER_EXAMES ); + texto = texto.replaceAll( CompanyDataLoader.DATA, data ); + texto = texto.replaceAll( CompanyDataLoader.NOME, nome ); +// subject = "Marca\u00E7\u00E3o de exame"; +// texto = "Vimos pelo presente informar que '" + nome + "' dever\u00E1 comparecer " +// + "nas nossas instala\u00E7\u00F5es para a realiza\u00E7\u00E3o dos exames de Medicina " +// + "do Trabalho, no dia '" + data + "', pelas 08H30." +// + "%0A%0A" +// + "Relembramos que o colaborador dever\u00E1 comparecer em jejum." +// + "%0A%0A" +// + "Caso n\u00E3o seja poss\u00EDvel a compar\u00EAncia deste colaborador na data " +// + "indicada, contacte-nos, por favor, atrav\u00E9s do telefone 21 350 45 40 " +//// + "indicada, contacte-nos, por favor, atrav\u00E9s do telefone 21 210 21 21 " +// + "ou respondendo ao remetente desta mensagem." +// + "%0A%0A%0A" +// + "Cumprimentos,%0A%0ASIPRP"; +//// + "Cumprimentos,"; + } + else + { + subject = ( String ) Singleton.getInstance( SingletonConstants.SUBJECT_CONSULTA ); + subject = subject.replaceAll( CompanyDataLoader.NOME, nome ); + texto = ( String ) Singleton.getInstance( SingletonConstants.LETTER_CONSULTA ); + texto = texto.replaceAll( CompanyDataLoader.DATA, data ); + texto = texto.replaceAll( CompanyDataLoader.NOME, nome ); +// subject = "Marca\u00E7\u00E3o de consulta"; +// texto = "Vimos pelo presente informar que '" + nome + "' dever\u00E1 comparecer " +// + "nas nossas instala\u00E7\u00F5es para a realiza\u00E7\u00E3o da consulta de Medicina " +// + "do Trabalho, no dia '" + data + "', pelas 08H30." +// + "%0A%0A" +// + "%0A%0A" +// + "Solicitamos, tamb\u00E9m, que o colaborador seja portador do Boletim de Vacinas e " +// + "dos \u00FAltimos exames complementares realizados." +// + "%0A%0A" +// + "%0A%0A" +// + "Caso n\u00E3o seja poss\u00EDvel a compar\u00EAncia deste colaborador na data " +// + "indicada, contacte-nos, por favor, atrav\u00E9s do telefone 21 350 45 40 " +//// + "indicada, contacte-nos, por favor, atrav\u00E9s do telefone 21 210 21 21 " +// + "ou respondendo ao remetente desta mensagem." +// + "%0A%0A%0A" +// + "Cumprimentos," +// + "%0A%0ASIPRP" +// + "%0A%0AATRIUM SALDANHA" +// + "%0A%0APra\u00e7a Duque de Saldanha, 1 - 9\u00BAC" +// + "%0A%0A1050-094 Lisboa"; + } + estab = ( EstabelecimentoData )trab.get( TrabalhadorData.ESTABELECIMENTO ); + } + else + { + estab = ( EstabelecimentoData )current.get( MarcacaoEstabelecimentoData.ESTABELECIMENTO ); + String sede = ( String )estab.get( EstabelecimentoData.NOME ); + subject = ( String ) Singleton.getInstance( SingletonConstants.SUBJECT_VISITA ); + subject = subject.replaceAll( CompanyDataLoader.NOME, sede ); + String morada = ( String )estab.get( EstabelecimentoData.MORADA ); + String data = DateFormat.getDateInstance( DateFormat.SHORT ).format( ( Date )current.get( MarcacaoEstabelecimentoData.DATA ) ); + texto = ( String ) Singleton.getInstance( SingletonConstants.LETTER_VISITA ); + texto = texto.replaceAll( CompanyDataLoader.DATA, data ); + texto = texto.replaceAll( CompanyDataLoader.NOME, sede ); + texto = texto.replaceAll( CompanyDataLoader.MORADA, morada ); +// texto = "Vimos pelo presente informar que iremos efectuar a auditoria de Higiene e " +// + "Seguran\u00E7a \u00E0s vossas instala\u00E7\u00F5es de '" + sede + "', no dia '" + data + "'." +// + "%0A%0A" +// + "Agradecemos que nos confirme, pela mesma via, o nome do representante " +// + "da empresa que nos ir\u00E1 acompanhar e a vossa disponibilidade para a " +// + "realiza\u00E7\u00E3o da visita na data indicada." +// + "%0A%0A" +// + "Caso necessite de qualquer esclarecimento, contacte-nos, por favor, " +// + "atrav\u00E9s dos telefones 21 350 45 43 (Pedro Vieira), 21 350 45 44 " +// + "(Catarina Leonardo) ou responda ao remetente desta mensagem." +//// + "atrav\u00E9s dos telefones 21 210 21 21 (Colaborador), 21 210 21 21 " +//// + "(Outro Colaborador) ou responda ao remetente desta mensagem." +// + "%0A%0A%0A" +// + "Cumprimentos,%0A%0ASIPRP"; +//// + "Cumprimentos,"; + + + } + ContactoData cont = ( ContactoData )estab.get( EstabelecimentoData.CONTACTO ); + String mail = ""; + if( cont != null ) + { + mail = ( String )cont.get( ContactoData.EMAIL ); + } + try + { + current.save(); + if( System.getProperty( "os.name" ).startsWith( "Windows" ) ) + { + mail = mail.replaceAll( " ", "%20" ); + subject = subject.replaceAll( " ", "%20" ); + texto = texto.replaceAll( " ", "%20" ); + Process proc = Runtime.getRuntime().exec( "cmd.exe /c start mailto:\"" + mail + + "?subject=" + subject + "&body=" +// + "?subject=" + subject + "&body=" + + texto + ); + } + else + { + mail = mail.replaceAll( " ", "%20" ); + subject = subject.replaceAll( " ", "%20" ); + texto = texto.replaceAll( " ", "%20" ); +// System.out.println( "mailto:" + mail +// // + "?subject=SIPRP - " + subject + "&body=" +// + "?subject=" + subject + "&body=" +// + texto ); + Process proc = Runtime.getRuntime().exec( new String[]{ "/usr/bin/open", "/Applications/Mail.app", "mailto:" + mail + // + "?subject=SIPRP - " + subject + "&body=" + + "?subject=" + subject + "&body=" + + texto } ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a enviar mail", true ); + } + dataEnvioMailLabel.setText( DATE_FORMAT.format( today ) ); + } + else if( source.equals( historicoButton ) ) + { + Vector v = new Vector(); + if( marcacoes != null ) + { + v.addAll( Arrays.asList( marcacoes ) ); + } + ListActionDialog dialog = + new ListActionDialog( null, "Anteriores", + COLUMN_NAMES_REL, + v, null ); + dialog.show(); + } + } + + public void marcar() + { +System.out.println( "MARCAR" ); + Date data = dataMarcacaoPanel.getDate(); + Vector aux = new Vector(); + if( marcacoes != null ) + { + aux.addAll( Arrays.asList( marcacoes ) ); + } + if( current == null && data != null ) + { + current = Marcacao.getMarcacao( tipo ); + current.set( Marcacao.REALIZADA, "n" ); + + aux.insertElementAt( current, 0 ); + switch( tipo ) + { + case Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES: case Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA: + current.set( MarcacaoTrabalhadorData.TRABALHADOR, trabalhador ); + current.set( MarcacaoTrabalhadorData.TIPO, new Integer( tipo ) ); + break; + + case Marcacao.TIPO_MARCACAO_ESTABELECIMENTO: + current.set( MarcacaoEstabelecimentoData.ESTABELECIMENTO, estabelecimento ); + break; + } + marcacoes = ( Marcacao [])aux.toArray( new Marcacao[0] ); +// System.out.println( "INSERI ! !! ! ! !! ! " ); + } + else if( current != null && data == null ) + { + aux.remove( 0 ); + marcacoes = ( Marcacao [])aux.toArray( new Marcacao[0] ); +// System.out.println( "REMOVI ! !! ! ! !! ! " ); + } + current.set( Marcacao.DATA, data ); + + try + { + if( data != null ) + { + current.save(); + enviarEmailButton.setEnabled( true ); + } + else + { + System.out.println( "DELETE DA MARCACAO" ); + current.delete(); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + } + } + + public void setCalendarDialogOrientation( int vertical, int horizontal ) + { + dataRelatorioPanel.setOrientation( vertical, horizontal ); + dataMarcacaoPanel.setOrientation( vertical, horizontal ); + } +} diff --git a/trunk/siprp/clientes/NoticiasDataProvider.java b/trunk/siprp/clientes/NoticiasDataProvider.java new file mode 100644 index 00000000..a678cd7c --- /dev/null +++ b/trunk/siprp/clientes/NoticiasDataProvider.java @@ -0,0 +1,96 @@ +/* + * NoticiasDataProvider.java + * + * Created on 24 de Maio de 2005, 15:39 + */ + +package siprp.clientes; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.ui.search.*; +import com.evolute.utils.sql.*; + +import siprp.*; + +/** + * + * @author fpalma + */ +public class NoticiasDataProvider extends MetaProvider +{ + private static final Object LOCK = new Object(); + private static NoticiasDataProvider instance = null; + private final Executer executer; + + /** Creates a new instance of NoticiasDataProvider */ + public NoticiasDataProvider() + throws Exception + { + boolean webAware = ( ( Boolean ) Singleton.getInstance( SingletonConstants.WEB_AWARE ) ).booleanValue(); + DBManager dbm; + if( webAware ) + { + String url = ( String ) Singleton.getInstance( SingletonConstants.WEB_URL_PREFIX ); + url += ( String ) Singleton.getInstance( SingletonConstants.WEB_URL ) + "/"; + url += ( String ) Singleton.getInstance( SingletonConstants.WEB_DB_NAME ) + "/"; + String user = ( String ) Singleton.getInstance( SingletonConstants.WEB_USER ); + String pwd = ( String ) Singleton.getInstance( SingletonConstants.WEB_PASSWORD ); + dbm = new JDBCManager( url, user, pwd, 10, 8, 8, null ); + executer = dbm.getSharedExecuter( this ); + } + else + { + dbm = null; + executer = null; + } + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new NoticiasDataProvider(); + } + } + return instance; + } + + public String getNoticias() + throws Exception + { + Select subSelect = + new Select( new String[]{ "not_noticias" }, + new String[]{ "MAX(id)" }, null ); + + Select select = + new Select( new String[]{ "not_noticias" }, + new String[]{ "noticia" }, + new Field( "id" ).isEqual( subSelect ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return ""; + } + return array.get( 0, 0 ).toString().trim(); + } + + public void saveNoticias( String noticias ) + throws Exception + { + + + Insert insert = + new Insert( "not_noticias", + new Assignment[]{ new Assignment( new Field( "utilizador" ), Singleton.getInstance( Singleton.USERNAME ) ), + new Assignment( new Field( "data" ), Singleton.getInstance( Singleton.TODAY ) ), + new Assignment( new Field( "noticia" ), noticias.trim() ) } ); + executer.executeQuery( insert ); + } +} diff --git a/trunk/siprp/clientes/NoticiasDialog.java b/trunk/siprp/clientes/NoticiasDialog.java new file mode 100644 index 00000000..5e432c05 --- /dev/null +++ b/trunk/siprp/clientes/NoticiasDialog.java @@ -0,0 +1,101 @@ +/* + * NoticiasPanel.java + * + * Created on 24 de Maio de 2005, 15:12 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.panel.*; +/** + * + * @author fpalma + */ +public class NoticiasDialog extends CustomJDialog + implements ActionListener +{ + protected HTMLEditorPanel textText; + protected JButton okButton; + protected JButton cancelButton; + + protected NoticiasDataProvider provider; + + /** Creates a new instance of NoticiasPanel */ + public NoticiasDialog( JFrame owner ) + throws Exception + { + super( owner, true ); + provider = (NoticiasDataProvider)NoticiasDataProvider.getProvider(); + setupComponents(); + if( owner != null ) + { + centerSuper(); + } + else + { + center(); + } + textText.fill( provider.getNoticias() ); + } + + private void setupComponents() + { + setTitle( "Editar Texto das Not\u00edcias" ); + setSize( 300, 200 ); + + textText = new HTMLEditorPanel( true ); +// textText.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), +// "Texto" ) ); + okButton = new JButton( "OK" ); + okButton.addActionListener( this ); + cancelButton = new JButton( "Cancelar" ); + cancelButton.addActionListener( this ); + + getContentPane().setLayout( new BorderLayout() ); + getContentPane().add( textText, BorderLayout.CENTER ); + JPanel buttonPanel = new JPanel(); + getContentPane().add( buttonPanel, BorderLayout.SOUTH ); + + buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); + buttonPanel.add( okButton ); + buttonPanel.add( cancelButton ); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( okButton ) ) + { + try + { + provider.saveNoticias( (String) textText.save() ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar not\u00edcias", true ); + return; + } + close(); + } + else if( source.equals( cancelButton ) ) + { + close(); + } + } + + public void close() + { + SwingUtilities.invokeLater( new Thread(){ + public void run() + { + setVisible( false ); + dispose(); + } + } ); + } +} diff --git a/trunk/siprp/clientes/PerfilProtocoloPanel.java b/trunk/siprp/clientes/PerfilProtocoloPanel.java new file mode 100644 index 00000000..bfe2a4e8 --- /dev/null +++ b/trunk/siprp/clientes/PerfilProtocoloPanel.java @@ -0,0 +1,153 @@ +/* + * PerfilProtocoloPanel.java + * + * Created on January 27, 2006, 12:24 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.ui.panel.*; + +/** + * + * @author fpalma + */ +public class PerfilProtocoloPanel extends JPanel + implements ControllableComponent, ItemListener +{ + protected JCheckBox consultasCheck; + protected JCheckBox examesCheck; + protected CheckBoxPanel tiposCheck[]; + + protected IDObject grupos[]; + protected IDObject tipos[][]; + + /** Creates a new instance of PerfilProtocoloPanel */ + public PerfilProtocoloPanel( IDObject grupos[], IDObject tipos[][] ) + { + this.grupos = grupos; + this.tipos = tipos; + setupComponents(); + } + + private void setupComponents() + { + consultasCheck = new JCheckBox( "Consultas" ); + examesCheck = new JCheckBox( "Exames" ); + examesCheck.addItemListener( this ); + tiposCheck = new CheckBoxPanel[ grupos.length ]; + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.weightx = 1; + constraints.gridheight = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( consultasCheck, constraints ); + gridbag.setConstraints( examesCheck, constraints ); + + add( consultasCheck ); + add( examesCheck ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = grupos.length > 0 ? 1.0 / grupos.length : 0.0; + for( int n = 0; n < grupos.length; n++ ) + { + tiposCheck[ n ] = setupComponentsGrupo( n ); + gridbag.setConstraints( tiposCheck[ n ], constraints ); + add( tiposCheck[ n ] ); + tiposCheck[ n ].setEnabled( false ); + } + } + + private CheckBoxPanel setupComponentsGrupo( int indice ) + { + String desc = grupos[ indice ].toString(); + CheckBoxPanel panel = new CheckBoxPanel( tipos[ indice ] ); + panel.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), desc ) ); + return panel; + } + + public void fill( Object data ) + { + clear(); + if( data != null ) + { + Vector list = ( Vector ) data; + boolean consultasExames[] = (boolean[]) list.elementAt( 0 ); + Integer tiposEscolhidos[] = ( Integer [] ) list.elementAt( 1 ); + consultasCheck.setSelected( consultasExames[ 0 ] ); + examesCheck.setSelected( consultasExames[ 1 ] ); + for( int n = 0; n < tiposCheck.length; n++ ) + { + tiposCheck[ n ].fill( tiposEscolhidos ); + } + } + } + + public Object save() + { + boolean consultasExames[] = new boolean[ 2 ]; + consultasExames[ 0 ] = consultasCheck.isSelected(); + consultasExames[ 1 ] = examesCheck.isSelected(); + Vector tiposEscolhidos = new Vector(); + if( consultasExames[ 1 ] ) + { + for( int n = 0; n < tiposCheck.length; n++ ) + { + tiposEscolhidos.addAll( Arrays.asList( tiposCheck[ n ].getSelected() ) ); + } + } + Vector list = new Vector(); + list.add( consultasExames ); + list.add( tiposEscolhidos.toArray( new Integer[ tiposEscolhidos.size() ] ) ); + return list; + } + + public void setEnabled( boolean enable ) + { + consultasCheck.setEnabled( enable ); + examesCheck.setEnabled( enable ); + for( int n = 0; n < tiposCheck.length; n++ ) + { + tiposCheck[ n ].setEnabled( enable && examesCheck.isSelected() ); + } + } + + public void clear() + { + consultasCheck.setSelected( false ); + examesCheck.setSelected( false ); + for( int n = 0; n < tiposCheck.length; n++ ) + { + tiposCheck[ n ].clear(); + } + } + + public void itemStateChanged( ItemEvent e ) + { + Object source = e.getSource(); + if( source.equals( examesCheck ) ) + { + for( int n = 0; n < tiposCheck.length; n++ ) + { + tiposCheck[ n ].setEnabled( examesCheck.isEnabled() && examesCheck.isSelected() ); + } + } + } +} diff --git a/trunk/siprp/clientes/ProtocoloPanel.java b/trunk/siprp/clientes/ProtocoloPanel.java new file mode 100644 index 00000000..af0e2ae0 --- /dev/null +++ b/trunk/siprp/clientes/ProtocoloPanel.java @@ -0,0 +1,111 @@ +/* + * ProtocoloPanel.java + * + * Created on January 27, 2006, 12:23 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.clientes; + +import java.awt.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; + +/** + * + * @author fpalma + */ +public class ProtocoloPanel extends JPanel + implements ControllableComponent +{ + protected ClientesDataProvider provider; + + protected IDObject grupos[]; + protected IDObject tipos[][]; + + protected PerfilProtocoloPanel perfisPanels[]; + + /** Creates a new instance of ProtocoloPanel */ + public ProtocoloPanel() + throws Exception + { + provider = ( ClientesDataProvider ) ClientesDataProvider.getProvider(); + IDObject gruposReais[] = provider.getAllGruposProtocoloReais(); + Vector gruposAux = new Vector( Arrays.asList( gruposReais ) ); + gruposAux.add( new MappableObject( new Integer( 0 ), "Outros" ) ); + grupos = ( IDObject[] ) gruposAux.toArray( new IDObject[ gruposReais.length + 1 ] ); + + IDObject gruposFalsos[] = provider.getAllGruposProtocoloFalsos(); + + Hashtable tiposHash = provider.getAllTiposElementosProtocoloByGrupo(); + tipos = new IDObject[ grupos.length ][]; + for( int n = 0; n < gruposReais.length; n++ ) + { + Vector tiposGrupo = ( Vector ) tiposHash.get( gruposReais[ n ].getID() ); + tipos[ n ] = ( IDObject[] ) tiposGrupo.toArray( new IDObject[ tiposGrupo.size() ] ); + } + Vector outros = new Vector(); + for( int n = 0; n < gruposFalsos.length; n++ ) + { + Vector tiposGrupo = ( Vector ) tiposHash.get( gruposFalsos[ n ].getID() ); + outros.addAll( tiposGrupo ); + } + tipos[ gruposReais.length ] = ( IDObject[] ) outros.toArray( new IDObject[ outros.size() ] ); + setupComponents(); + } + + private void setupComponents() + { + perfisPanels = new PerfilProtocoloPanel[ 2 ]; + + setLayout( new GridLayout( 1, 2 ) ); + + perfisPanels[ 0 ] = new PerfilProtocoloPanel( grupos, tipos ); + JScrollPane perfilAScp = + new JScrollPane( perfisPanels[ 0 ], JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + perfilAScp.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Perfil A" ) ); + add( perfilAScp ); + + perfisPanels[ 1 ] = new PerfilProtocoloPanel( grupos, tipos ); + JScrollPane perfilBScp = + new JScrollPane( perfisPanels[ 1 ], JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + perfilBScp.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Perfil B" ) ); + add( perfilBScp ); + } + + public void fill( Object data ) + { + Vector lists[] = ( Vector [] ) data; + perfisPanels[ 0 ].fill( lists[ 0 ] ); + perfisPanels[ 1 ].fill( lists[ 1 ] ); + } + + public Object save() + { + Vector lists[] = new Vector[ 2 ]; + lists[ 0 ] = ( Vector ) perfisPanels[ 0 ].save(); + lists[ 1 ] = ( Vector ) perfisPanels[ 1 ].save(); + return lists; + } + + public void setEnabled( boolean enable ) + { + perfisPanels[ 0 ].setEnabled( enable ); + perfisPanels[ 1 ].setEnabled( enable ); + } + + public void clear() + { + perfisPanels[ 0 ].clear(); + perfisPanels[ 1 ].clear(); + } +} diff --git a/trunk/siprp/clientes/TrabalhadorPanel.java b/trunk/siprp/clientes/TrabalhadorPanel.java new file mode 100644 index 00000000..f19a0eee --- /dev/null +++ b/trunk/siprp/clientes/TrabalhadorPanel.java @@ -0,0 +1,611 @@ +/* + * TrabalhadorPanel.java + * + * Created on 14 de Maio de 2004, 12:29 + */ + +package siprp.clientes; + +import javax.swing.*; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.date.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.panel.*; +import com.evolute.utils.ui.text.*; + +import siprp.*; +import siprp.data.*; +import siprp.importer.*; + +/** + * + * @author fpalma + */ +public class TrabalhadorPanel extends JPanel + implements ControllableComponent, ListSelectionListener, ActionListener +{ + private FichaDataProvider provider; + private TrabalhadorData trabalhador; + private ComponentsHashtable components; + + private EstabelecimentoData estabelecimento; + private JTable estabelecimentosTable; + + private JPanel toolbarPanel; + + private JPanel dadosTrabalhadorPanel; + + private JTextField nomeText; + private RadioButtonFixedPanel sexoPanel; + private JCalendarPanel dataNascimentoPanel; + private JTextField nacionalidadeText; + private JTextField numeroMecanograficoText; + private JCalendarPanel dataAdmissaoPanel; + private JTextField categoriaText; + private JTextField localText; + private JTextField funcaoText; + private JCalendarPanel dataAdmissaoFuncaoPanel; + private JCalendarPanel dataDemissaoPanel; + private JTextField observacoesText; + //private JComboBox perfilCombo; + private RadioButtonFixedPanel perfilPanel; + + private SIPRPTracker tracker; + + private BaseTable trabalhadoresTable; + private VectorTableModel trabalhadoresModel; + + private JButton marcacoesButton; +// private MarcacaoPanel examesPanel; +// private MarcacaoPanel consultaPanel; + + private Vector listeners; + + private boolean lastEnable = false; + + /** Creates a new instance of TrabalhadorPanel */ + public TrabalhadorPanel( JPanel toolbarPanel, JTable estabelecimentosTable ) + throws Exception + { + this.toolbarPanel = toolbarPanel; + this.estabelecimentosTable = estabelecimentosTable; + provider = ( FichaDataProvider )FichaDataProvider.getProvider(); + listeners = new Vector(); + setupComponents(); + setupComponentsHashtable(); + } + + private void setupComponents() + { + dadosTrabalhadorPanel = new JPanel(); +// JPanel marcacoesPanel = new JPanel(); + + JLabel nomeLabel = new JLabel( "Nome" ); + nomeText = new JTextField(); + JLabel sexoLabel = new JLabel( "Sexo" ); + sexoPanel = + new RadioButtonFixedPanel( + new IDObject[]{ new MappableObject( new Integer( 1 ), "M" ), + new MappableObject( new Integer( 2 ), "F" ) }, + 1, 2, RadioButtonPanel.ORIENTATION_HORIZONTAL, false ); + JLabel dataNascimentoLabel = new JLabel( "Data de Nascimento" ); + dataNascimentoPanel = new JCalendarPanel( null ); + JLabel nacionalidadeLabel = new JLabel( "Nacionalidade" ); + nacionalidadeText = new JTextField(); + JLabel numeroMecanograficoLabel = new JLabel( "N\u00famero Mecanogr\u00e1fico/Outro" ); + numeroMecanograficoText = new JTextField(); + JLabel dataAdmissaoLabel = new JLabel( "Data de Admiss\u00e3o" ); + dataAdmissaoPanel = new JCalendarPanel( null ); + JLabel categoriaLabel = new JLabel( "Categoria Profissional" ); + categoriaText = new JTextField(); + JLabel localLabel = new JLabel( "Local de Trabalho" ); + localText = new JTextField(); + JLabel funcaoLabel = new JLabel( "Fun\u00e7\u00e3o Proposta" ); + funcaoText = new JTextField(); + JLabel dataAdmissaoFuncaoLabel = new JLabel( "Data de Admiss\u00e3o na Fun\u00e7\u00e3o" ); + dataAdmissaoFuncaoPanel = new JCalendarPanel( null ); + JLabel perfilLabel = new JLabel( "Perfil" ); +// perfilCombo = new JComboBox(); +// perfilCombo.addItem( new MappableObject( new Integer( 1 ), "A" ) ); +// perfilCombo.addItem( new MappableObject( new Integer( 2 ), "B" ) ); + perfilPanel = new RadioButtonFixedPanel( + new IDObject[]{ new MappableObject( new Integer( 1 ), "A" ), + new MappableObject( new Integer( 2 ), "B" ) }, + 1, 2, RadioButtonPanel.ORIENTATION_HORIZONTAL, false ); + JLabel dataDemissaoLabel = new JLabel( "Data de Demiss\u00e3o" ); + dataDemissaoPanel = new JCalendarPanel( null ); + JLabel observacoesLabel = new JLabel( "Observa\u00e7\u00f5es" ); + observacoesText = new JTextField(); + marcacoesButton = new JButton( "Marca\u00e7\u00f5es" ); + marcacoesButton.addActionListener( this ); + + JScrollPane trabalhadoresScroll = new JScrollPane(); + trabalhadoresScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + trabalhadoresScroll.setPreferredSize( new Dimension( 250, 300 ) ); + trabalhadoresModel = new VectorTableModel( new String[]{ "Trabalhadores" } ); + trabalhadoresTable = new BaseTable( trabalhadoresModel ); + trabalhadoresTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + trabalhadoresTable.setNonResizableNorReordable(); + trabalhadoresScroll.setViewportView( trabalhadoresTable ); + + JPanel pad; + + GridBagLayout gridbag = new GridBagLayout(); + dadosTrabalhadorPanel.setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.gridwidth = 1; + constraints.weightx = 0; + + gridbag.setConstraints( nomeLabel, constraints ); + dadosTrabalhadorPanel.add( nomeLabel ); + + constraints.weightx = 1; + constraints.gridwidth = 3; + gridbag.setConstraints( nomeText, constraints ); + dadosTrabalhadorPanel.add( nomeText ); + + constraints.gridwidth = 1; + constraints.weightx = 0; + gridbag.setConstraints( sexoLabel, constraints ); + dadosTrabalhadorPanel.add( sexoLabel ); + + constraints.weightx = 0; + //constraints.gridwidth = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + JPanel sexoOuterPanel = new JPanel(); + sexoOuterPanel.setLayout( new GridLayout( 1, 2 ) ); + sexoOuterPanel.add( sexoPanel ); + sexoOuterPanel.add( new JPanel() ); + gridbag.setConstraints( sexoOuterPanel, constraints ); + dadosTrabalhadorPanel.add( sexoOuterPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 2; + gridbag.setConstraints( nacionalidadeLabel, constraints ); + dadosTrabalhadorPanel.add( nacionalidadeLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( nacionalidadeText, constraints ); + dadosTrabalhadorPanel.add( nacionalidadeText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( dataNascimentoLabel, constraints ); + dadosTrabalhadorPanel.add( dataNascimentoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( dataNascimentoPanel, constraints ); + dadosTrabalhadorPanel.add( dataNascimentoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 2; + gridbag.setConstraints( numeroMecanograficoLabel, constraints ); + dadosTrabalhadorPanel.add( numeroMecanograficoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( numeroMecanograficoText, constraints ); + dadosTrabalhadorPanel.add( numeroMecanograficoText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( dataAdmissaoLabel, constraints ); + dadosTrabalhadorPanel.add( dataAdmissaoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( dataAdmissaoPanel, constraints ); + dadosTrabalhadorPanel.add( dataAdmissaoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 2; + gridbag.setConstraints( categoriaLabel, constraints ); + dadosTrabalhadorPanel.add( categoriaLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( categoriaText, constraints ); + dadosTrabalhadorPanel.add( categoriaText ); + + constraints.weightx = 0; + gridbag.setConstraints( localLabel, constraints ); + dadosTrabalhadorPanel.add( localLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( localText, constraints ); + dadosTrabalhadorPanel.add( localText ); + + constraints.weightx = 0; + constraints.gridwidth = 2; + gridbag.setConstraints( funcaoLabel, constraints ); + dadosTrabalhadorPanel.add( funcaoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( funcaoText, constraints ); + dadosTrabalhadorPanel.add( funcaoText ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( dataAdmissaoFuncaoLabel, constraints ); + dadosTrabalhadorPanel.add( dataAdmissaoFuncaoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( dataAdmissaoFuncaoPanel, constraints ); + dadosTrabalhadorPanel.add( dataAdmissaoFuncaoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 2; + gridbag.setConstraints( perfilLabel, constraints ); + dadosTrabalhadorPanel.add( perfilLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; +// gridbag.setConstraints( perfilCombo, constraints ); +// dadosTrabalhadorPanel.add( perfilCombo ); + gridbag.setConstraints( perfilPanel, constraints ); + dadosTrabalhadorPanel.add( perfilPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( dataDemissaoLabel, constraints ); + dadosTrabalhadorPanel.add( dataDemissaoLabel ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( dataDemissaoPanel, constraints ); + dadosTrabalhadorPanel.add( dataDemissaoPanel ); + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( observacoesLabel, constraints ); + dadosTrabalhadorPanel.add( observacoesLabel ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( observacoesText, constraints ); + dadosTrabalhadorPanel.add( observacoesText ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( marcacoesButton, constraints ); + dadosTrabalhadorPanel.add( marcacoesButton ); + +// examesPanel = new MarcacaoPanel( false, "Realizados", "", Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ); +// examesPanel.setCalendarDialogOrientation( JCalendarDialog.ABOVE, JCalendarDialog.RIGHT ); +// examesPanel.setBorder( BorderFactory.createTitledBorder( +// BorderFactory.createEtchedBorder(), +// "Exames" ) ); +// consultaPanel = new MarcacaoPanel( true, "Realizada", "Ficha de Aptid\u00e3o", Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ); +// consultaPanel.setCalendarDialogOrientation( JCalendarDialog.ABOVE, JCalendarDialog.LEFT ); +// consultaPanel.setBorder( BorderFactory.createTitledBorder( +// BorderFactory.createEtchedBorder(), +// "Consulta" ) ); +// //marcacoesPanel.setLayout( new BoxLayout( marcacoesPanel, BoxLayout.X_AXIS ) ); +// marcacoesPanel.setLayout( new GridLayout( 1, 2 ) ); +// marcacoesPanel.add( examesPanel ); +// marcacoesPanel.add( consultaPanel ); + + JPanel leftPanel = new JPanel(); + leftPanel.setLayout( new BorderLayout() ); + leftPanel.add( toolbarPanel, BorderLayout.NORTH ); + leftPanel.add( trabalhadoresScroll, BorderLayout.CENTER ); + + setLayout( new BorderLayout() ); + add( leftPanel, BorderLayout.WEST ); + add( dadosTrabalhadorPanel, BorderLayout.CENTER ); +// add( marcacoesPanel, BorderLayout.SOUTH ); + + trabalhadoresTable.getSelectionModel().addListSelectionListener( this ); + + new CopyPasteHandler( nomeText ); + new CopyPasteHandler( nacionalidadeText ); + new CopyPasteHandler( numeroMecanograficoText ); + new CopyPasteHandler( categoriaText ); + new CopyPasteHandler( localText ); + new CopyPasteHandler( funcaoText ); + new CopyPasteHandler( observacoesText ); + } + + private void setupComponentsHashtable() + { + components = new ComponentsHashtable(); + components.putComponent( TrabalhadorData.NOME, nomeText ); + components.putComponent( TrabalhadorData.SEXO, new ControllableComponent() + { + public void fill( Object value ) + { + if( value != null && value.equals( "f" ) ) + { + sexoPanel.fill( new Integer(2) ); + } + else + { + sexoPanel.fill( new Integer(1) ); + } + } + + public Object save() + { + Integer id = (Integer)sexoPanel.save(); + if( id != null && id.intValue() == 1 ) + { + return "m"; + } + return "f"; + } + + public void clear() + { + sexoPanel.clear(); + } + + public void setEnabled( boolean enable ) + { + sexoPanel.setEnabled( enable ); + } + } ); + components.putComponent( TrabalhadorData.DATA_NASCIMENTO, dataNascimentoPanel ); + components.putComponent( TrabalhadorData.NACIONALIDADE, nacionalidadeText ); + components.putComponent( TrabalhadorData.NUMERO_MECANOGRAFICO, numeroMecanograficoText ); + components.putComponent( TrabalhadorData.DATA_ADMISSAO, dataAdmissaoPanel ); + components.putComponent( TrabalhadorData.CATEGORIA, categoriaText ); + components.putComponent( TrabalhadorData.LOCAL_TRABALHO, localText ); + components.putComponent( TrabalhadorData.FUNCAO_PROPOSTA, funcaoText ); + components.putComponent( TrabalhadorData.DATA_ADMISSAO_FUNCAO, dataAdmissaoFuncaoPanel ); + components.putComponent( TrabalhadorData.DATA_DEMISSAO, dataDemissaoPanel ); + components.putDummy( TrabalhadorData.OBSERVACOES ); + components.putComponent( TrabalhadorData.OBSERVACOES_GESTAO, observacoesText ); + components.putComponent( TrabalhadorData.PERFIL, perfilPanel ); +// components.putDummy( TrabalhadorData.INACTIVO ); + components.putDummy( TrabalhadorData.ESTABELECIMENTO ); + components.putDummy( TrabalhadorData.NOME_PLAIN ); + } + + public void clear() + { + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.clear( names, components ); + trabalhador = null; + } + + public void fill(Object value) + { + clear(); + trabalhador = ( TrabalhadorData ) value; +// examesPanel.setEnabled( trabalhador != null ); +// examesPanel.fill( trabalhador ); +// consultaPanel.setEnabled( trabalhador != null ); +// consultaPanel.fill( trabalhador ); + if( trabalhador == null ) + { + trabalhadoresTable.clearSelection(); + return; + } + String names[] = trabalhador.getFieldNames(); + ComponentController.fill( names, trabalhador.getHashData(), components ); + } + + public Object save() + { + + if( trabalhador == null ) + { + trabalhador = new TrabalhadorData(); + } + + String names[] = trabalhador.getFieldNames(); + Hashtable hash = new Hashtable(); + ComponentController.save( names, hash, components ); + trabalhador.setHashData( hash ); + trabalhador.set( TrabalhadorData.ESTABELECIMENTO, estabelecimento ); + return trabalhador; + } + + public void setEnabled( boolean enable ) + { + super.setEnabled( enable ); + String names[] = (String[])components.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, components ); + trabalhadoresTable.setEnabled( !enable ); + if( lastEnable != enable ) + { + if( enable ) + { + EstabelecimentoPanel.disables++; + } + else + { + EstabelecimentoPanel.disables--; + } + lastEnable = enable; + } + estabelecimentosTable.setEnabled( EstabelecimentoPanel.disables == 0 ); +// if( trabalhador == null ) +// { +// examesPanel.setEnabled( false ); +// consultaPanel.setEnabled( false ); +// } + } + + public void reloaList() + throws Exception + { + if( estabelecimento == null ) + { + trabalhadoresModel.clearAll(); + } + else + { + Integer id = ( Integer )estabelecimento.get( EstabelecimentoData.ID ); + IDObject []trabalhadores = provider.getAllTrabalhadoresForEstabelecimento( id ); + trabalhadoresModel.setValues( new Vector( Arrays.asList( trabalhadores ) ) ); + } + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( source instanceof EmpresaPanel ) + { + Integer id = ( ( EmpresaPanel ) source ).getSelectedEstabelecimento(); + if( id != null ) + { + try + { + IDObject []trabalhadores = provider.getAllTrabalhadoresForEstabelecimento( id ); + trabalhadoresModel.setValues( new Vector( Arrays.asList( trabalhadores ) ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os trabalhadores", true ); + clear(); + } + } + else + { + trabalhadoresModel.clearAll(); + clear(); + } + } + else if( source.equals( trabalhadoresTable.getSelectionModel() ) ) + { +// int selected = trabalhadoresTable.getSelectedRow(); +// if( selected == -1 ) +// { +// clear(); +// +// } +// else +// { +// Integer id = ( ( IDObject ) trabalhadoresModel.getRowAt( selected ) ).getID();; +// try +// { +// TrabalhadorData trabalhador = (TrabalhadorData) TrabalhadorData.load( TrabalhadorData.class, id ); +// fill( trabalhador ); +// } +// catch( Exception ex ) +// { +// DialogException.showExceptionMessage( ex, "Erro a carregar o trabalhador", true ); +// clear(); +// } + for( int n = 0; n < listeners.size(); n++ ) + { + ListSelectionEvent newEvent = + new ListSelectionEvent( this, e.getFirstIndex(), e.getLastIndex(), e.getValueIsAdjusting() ); + ( (ListSelectionListener) listeners.elementAt( n ) ).valueChanged( newEvent ); + } +// } + } + } + + public void postSave() + { + int selected = trabalhadoresTable.getSelectedRow(); +//System.out.println( "postSave TRABALHADOR PANEL " + selected + " : " + ( trabalhador == null ) ); + if( trabalhador != null ) + { + IDObject obj = new MappableObject( (Integer) trabalhador.get( TrabalhadorData.ID ), trabalhador.get( TrabalhadorData.NOME ) ); + if( selected == -1 ) + { + trabalhadoresModel.insertRowAt( obj, trabalhadoresTable.getRowCount() ); + trabalhadoresTable.setRowSelectionInterval( trabalhadoresTable.getRowCount() - 1, trabalhadoresTable.getRowCount() - 1 ); + } + else + { + trabalhadoresModel.removeRowAt( selected ); + trabalhadoresModel.insertRowAt( obj, selected ); + trabalhadoresTable.setRowSelectionInterval( selected, selected ); + } + } + } + + public void reload() + { + fill( trabalhador ); + } + + public void addListSelectionListener( ListSelectionListener listener ) + { + listeners.add( listener ); + } + + public void removeListSelectionListener( ListSelectionListener listener ) + { + listeners.remove( listener ); + } + + public Integer getSelectedTrabalhador() + { + int selected = trabalhadoresTable.getSelectedRow(); + if( selected == -1 ) + { + return null; + } + return ( (IDObject) trabalhadoresModel.getRowAt( selected ) ).getID(); + } + + public void setEstabelecimento( EstabelecimentoData estabelecimento ) + { + this.estabelecimento = estabelecimento; + } + + public void setSelectedTrabalhador( TrabalhadorData trab ) + { + IDObject lista[] = (IDObject [])trabalhadoresModel.getValues().toArray( new IDObject[ 0 ] ); + Integer id = (Integer)trab.get( TrabalhadorData.ID ); + for( int n = 0; n < lista.length; n++ ) + { + if( lista[ n ].getID().equals( id ) ) + { + trabalhadoresTable.setRowSelectionInterval( n, n ); + return; + } + } + trabalhadoresTable.clearSelection(); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( marcacoesButton ) ) + { + if( trabalhador == null ) + { + return; + } + else + { + EstabelecimentoData estabelecimento = ( EstabelecimentoData ) trabalhador.get( TrabalhadorData.ESTABELECIMENTO ); + EmpresaData empresa = ( EmpresaData ) estabelecimento.get( EstabelecimentoData.EMPRESA ); + tracker.getMedicinaWindow().setVisible( true ); + tracker.getMedicinaWindow().setEmpresaAndEstabelecimentoAndTrabalhador( (Integer) empresa.get( EmpresaData.ID ), + ( Integer ) estabelecimento.get( EstabelecimentoData.ID ), + ( Integer ) trabalhador.get( TrabalhadorData.ID ) ); + } + } + } + + public void setTracker( SIPRPTracker tracker ) + { + this.tracker = tracker; + } +} diff --git a/trunk/siprp/clientes/UserDataProvider.java b/trunk/siprp/clientes/UserDataProvider.java new file mode 100644 index 00000000..1d89bc93 --- /dev/null +++ b/trunk/siprp/clientes/UserDataProvider.java @@ -0,0 +1,156 @@ +/* + * UserDataProvider.java + * + * Created on 8 de Novembro de 2004, 18:38 + */ + +package siprp.clientes; + +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.ui.search.*; +import com.evolute.utils.sql.*; + +import siprp.*; +/** + * + * @author fpalma + */ +public class UserDataProvider extends MetaProvider +{ + private static final String RESERVED_ROLES_MANAGER = "manager"; + private static final String RESERVED_ROLES_ADMIN = "admin"; + private static final Object LOCK = new Object(); + private static UserDataProvider instance = null; + private final Executer executer; + + protected final Expression excludeReserved; + + /** Creates a new instance of UserDataProvider */ + public UserDataProvider() + throws Exception + { + boolean webAware = ( ( Boolean ) Singleton.getInstance( SingletonConstants.WEB_AWARE ) ).booleanValue(); + DBManager dbm; + if( webAware ) + { + String url = ( String ) Singleton.getInstance( SingletonConstants.WEB_URL_PREFIX ); + url += ( String ) Singleton.getInstance( SingletonConstants.WEB_URL ) + "/"; + url += ( String ) Singleton.getInstance( SingletonConstants.WEB_DB_NAME ) + "/"; + String user = ( String ) Singleton.getInstance( SingletonConstants.WEB_USER ); + String pwd = ( String ) Singleton.getInstance( SingletonConstants.WEB_PASSWORD ); + dbm = new JDBCManager( url, user, pwd, 10, 8, 8, null ); + executer = dbm.getSharedExecuter( this ); + } + else + { + dbm = null; + executer = null; + } + excludeReserved = new Field( "role" ).isDifferent( RESERVED_ROLES_MANAGER ).and( + new Field( "role" ).isDifferent( RESERVED_ROLES_ADMIN ) ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new UserDataProvider(); + } + } + return instance; + } + + public String getUserName( Integer empresaID ) + throws Exception + { +System.out.println( "getUserName( " +empresaID+ " )" ) ; + Select select = new Select( new String[]{ "roles" }, new String[]{ "username" }, + new Field( "role" ).isEqual( empresaID == null ? "siprpuser" : empresaID.toString() ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 ) + { + return null; + } + return array.get( 0, 0 ).toString(); + } + + public void saveUser( String userName, String password, Integer empresaID, boolean isNew ) + throws Exception + { + if( isNew ) + { + Insert insert = + new Insert( "roles", + new Assignment[]{ new Assignment( new Field( "username" ), userName ), + new Assignment( new Field( "role" ), empresaID == null ? "siprpuser" : empresaID.toString() ) } ); + executer.executeQuery( insert, null ); + insert = + new Insert( "users", + new Assignment[]{ new Assignment( new Field( "username" ), userName ), + new Assignment( new Field( "password" ), password ) } ); + executer.executeQuery( insert, null ); + } + else + { + Select select = new Select( new String[]{ "roles" }, new String[]{ "username" }, + new Field( "role" ).isEqual( empresaID == null ? "siprpuser" : empresaID.toString() ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 ) + { + saveUser( userName, password, empresaID, true ); + return; + } + String oldName = array.get( 0, 0 ).toString(); + Update update = + new Update( "roles", + new Assignment[]{ new Assignment( new Field( "username" ), userName ), + new Assignment( new Field( "role" ), empresaID == null ? "siprpuser" : empresaID.toString() ) }, + new Field( "username" ).isEqual( oldName ).and( excludeReserved ) ); + executer.executeQuery( update ); + update = + new Update( "users", + new Assignment[]{ new Assignment( new Field( "username" ), userName ), + new Assignment( new Field( "password" ), password ) }, + new Field( "username" ).isEqual( oldName ) ); + executer.executeQuery( update ); + } + } + + public boolean checkNewName( String name, Integer empresaID ) + throws Exception + { + Select select = new Select( new String[]{ "roles" }, new String[]{ "username" }, + new Field( "role" ).isDifferent( empresaID == null ? "siprpuser" : empresaID.toString() ).and( + new Field( "lower( username )" ).isEqual( new Field( "lower( '" + name + "' )" ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() != 0 ) + { + if( empresaID != null ) + { + return false; + } + else + { + select = new Select( new String[]{ "roles" }, new String[]{ "username" }, + new Field( "role" ).isEqual( empresaID == null ? "siprpuser" : empresaID.toString() ).and( + new Field( "lower( username )" ).isEqual( new Field( "lower( '" + name + "' )" ) ) ) ); + array = executer.executeQuery( select ); + if( array.columnLength() == 0 ) + { + return false; + } + } + } + + return true; + } +} diff --git a/trunk/siprp/clientes/UserPanel.java b/trunk/siprp/clientes/UserPanel.java new file mode 100644 index 00000000..d9a8bf2f --- /dev/null +++ b/trunk/siprp/clientes/UserPanel.java @@ -0,0 +1,232 @@ +/* + * UserPanel.java + * + * Created on 8 de Novembro de 2004, 17:03 + */ + +package siprp.clientes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; + +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; +/** + * + * @author fpalma + */ +public class UserPanel extends JPanel + implements DocumentListener, FocusListener, ActionListener +{ + private UserDataProvider provider; + + private JTextField userNameText; + private JTextField passwordText; + private JButton applyButton; + private JButton cancelButton; + + private boolean passwordEdited = false; + private boolean hasPassword = false; + private boolean error = false; + private Integer empresaID; + +// public static void main( String args[] ) +// { +// JFrame frame = new JFrame(); +// frame.setSize( 300, 200 ); +// frame.getContentPane().setLayout( new GridLayout( 1, 1 ) ); +// frame.getContentPane().add( new UserPanel() ); +// frame.show(); +// } + + /** Creates a new instance of UserPanel */ + public UserPanel() + throws Exception + { + provider = ( UserDataProvider ) UserDataProvider.getProvider(); + setupComponents(); + } + + private void setupComponents() + { + JLabel userNameLabel = new JLabel( "Utilizador" ); + userNameText = new JTextField(); + JLabel passwordLabel = new JLabel( "Senha" ); + passwordText = new JTextField(); + applyButton = new JButton( "Actualizar" ); + cancelButton = new JButton( "Cancelar" ); + + userNameText.setPreferredSize( new Dimension( 200, 20 ) ); + passwordText.setPreferredSize( new Dimension( 200, 20 ) ); + passwordText.setText( "" ); + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( userNameLabel, constraints ); + gridbag.setConstraints( passwordLabel, constraints ); + gridbag.setConstraints( userNameText, constraints ); + gridbag.setConstraints( passwordText, constraints ); + JPanel buttonPanel = new JPanel(); + gridbag.setConstraints( buttonPanel, constraints ); + + add( userNameLabel ); + add( userNameText ); + add( passwordLabel ); + add( passwordText ); + add( buttonPanel ); + + buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); + buttonPanel.add( applyButton ); + buttonPanel.add( cancelButton ); + + passwordText.addFocusListener( this ); + passwordText.getDocument().addDocumentListener( this ); + + applyButton.addActionListener( this ); + cancelButton.addActionListener( this ); + + new CopyPasteHandler( userNameText ); + new CopyPasteHandler( passwordText ); + } + + public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) + { + passwordEdited = true; + } + + public void insertUpdate(javax.swing.event.DocumentEvent documentEvent) + { + passwordEdited = true; + } + + public void removeUpdate(javax.swing.event.DocumentEvent documentEvent) + { + passwordEdited = true; + } + + public void focusGained(java.awt.event.FocusEvent focusEvent) + { + if( !passwordEdited ) + { + passwordText.getDocument().removeDocumentListener( this ); + passwordText.setText( "" ); + passwordText.getDocument().addDocumentListener( this ); + } + } + + public void focusLost(java.awt.event.FocusEvent focusEvent) + { + } + + public void actionPerformed(java.awt.event.ActionEvent actionEvent) + { + try + { + Object source = actionEvent.getSource(); + if( applyButton.equals( source ) ) + { + if( save() ) + { + hasPassword = true; + } + refresh(); + } + else if( cancelButton.equals( source ) ) + { + reload(); + refresh(); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro na liga\u00e7\u00e3o \u00e0 Base de Dados WEB", true ); + } + } + + private void refresh() + { + passwordText.getDocument().removeDocumentListener( this ); + if( !passwordEdited ) + { + if( hasPassword ) + { + passwordText.setText( "" ); + } + else + { + passwordText.setText( "" ); + } + } + passwordText.getDocument().addDocumentListener( this ); + } + + public void setEmpresaID( Integer empresaID ) + { + try + { + userNameText.setText( "" ); + passwordText.setText( "" ); + passwordEdited = false; + hasPassword = false; + this.empresaID = empresaID; +// if( empresaID == null ) +// { +// return; +// } + reload(); + refresh(); + error = false; + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro na liga\u00e7\u00e3o \u00e0 Base de Dados WEB", true ); + userNameText.setText( "Erro na liga\u00e7\u00e3o" ); + setEnabled( false ); + error = true; + } + } + + private boolean save() + throws Exception + { + if( !provider.checkNewName( userNameText.getText(), empresaID ) ) + { + JOptionPane.showMessageDialog( null, "O Utilizador " + userNameText.getText() + " j\u00e1 est\u00e1 em uso por outra entidade." ); + return false; + } + provider.saveUser( userNameText.getText(), passwordText.getText(), empresaID, !hasPassword ); + passwordEdited = false; + return true; + } + + private boolean reload() + throws Exception + { + String userName = provider.getUserName( empresaID ); + if( userName != null ) + { + userNameText.setText( userName ); + hasPassword = true; + } + passwordEdited = false; + return true; + } + + public void setEnabled( boolean enable ) + { + userNameText.setEnabled( enable && !error ); + passwordText.setEnabled( enable && !error ); + applyButton.setEnabled( enable && !error ); + cancelButton.setEnabled( enable && !error ); + } +} diff --git a/trunk/siprp/clientes/UserWindow.java b/trunk/siprp/clientes/UserWindow.java new file mode 100644 index 00000000..31943edd --- /dev/null +++ b/trunk/siprp/clientes/UserWindow.java @@ -0,0 +1,66 @@ +/* + * UserWindow.java + * + * Created on 15 de Março de 2005, 11:35 + */ + +package siprp.clientes; + +import java.awt.*; +import javax.swing.*; + +import com.evolute.utils.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.ui.*; + +import siprp.data.*; +/** + * + * @author fpalma + */ +public class UserWindow extends CustomJDialog +{ + protected JDOProvider JDO; +// protected JTextField empresaText; + protected UserPanel userPanel; + protected Integer empresaID; + + /** Creates a new instance of UserWindow */ + public UserWindow( JFrame owner, Integer empresaID ) + throws Exception + { + super( owner, true ); + this.empresaID = empresaID; + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + centerSuper(); + } + + private void setupComponents() + throws Exception + { + setSize( 500, 200 ); + userPanel = new UserPanel(); +// empresaText = new JTextField(); + getContentPane().setLayout( new BorderLayout() ); +// getContentPane().add( empresaText, BorderLayout.NORTH ); + getContentPane().add( userPanel, BorderLayout.CENTER ); + + if( empresaID == null ) + { +// empresaText.setText( "SIPRP" ); + setTitle( "SIPRP" ); + } + else + { + EmpresaData empresa = ( EmpresaData )JDO.load( EmpresaData.class, empresaID ); + if( empresa == null ) + { + return; + } +// empresaText.setText( (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + setTitle( (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + } + userPanel.setEmpresaID( empresaID ); + } +} diff --git a/trunk/siprp/clientes/etiqueta.xsl b/trunk/siprp/clientes/etiqueta.xsl new file mode 100644 index 00000000..4603a50b --- /dev/null +++ b/trunk/siprp/clientes/etiqueta.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + Cuidado Prestado + + + + + Código + + + + + Valor + + + + + Benef. + + + + + Entidade + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/siprp/clientes/etiquetas.dtd b/trunk/siprp/clientes/etiquetas.dtd new file mode 100644 index 00000000..69d2b4f1 --- /dev/null +++ b/trunk/siprp/clientes/etiquetas.dtd @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/trunk/siprp/data/ActualizacaoSaveHandler.java b/trunk/siprp/data/ActualizacaoSaveHandler.java new file mode 100644 index 00000000..087e6213 --- /dev/null +++ b/trunk/siprp/data/ActualizacaoSaveHandler.java @@ -0,0 +1,51 @@ +/* + * StampSaveHandler.java + * + * Created on 15 de Março de 2005, 15:00 + */ + +package siprp.data; + +import java.util.*; + +import com.evolute.utils.jdo.*; +/** + * + * @author fpalma + */ +public class ActualizacaoSaveHandler implements JDOOperationHandlerInterface +{ + public static final ActualizacaoSaveHandler INSTANCE = new ActualizacaoSaveHandler(); + + /** Creates a new instance of StampSaveHandler */ + public ActualizacaoSaveHandler() + { + } + + public boolean handle(JDOObject object, int operation, int moment) throws Exception + { + if( !( object instanceof ActualizacaoSaveable ) ) + { + return false; + } + switch( operation ) + { + case OP_SAVE: + return save( object, moment ); + + case OP_DELETE: + return false; + } + return false; + } + + protected boolean save( JDOObject object, int moment ) + { + if( moment != MOMENT_BEFORE ) + { + return false; + } + object.set( ActualizacaoSaveable.ACTUALIZACAO, new Date() ); + return true; + } +} diff --git a/trunk/siprp/data/ActualizacaoSaveable.java b/trunk/siprp/data/ActualizacaoSaveable.java new file mode 100644 index 00000000..5427c27f --- /dev/null +++ b/trunk/siprp/data/ActualizacaoSaveable.java @@ -0,0 +1,16 @@ +/* + * ActualizacaoSaveable.java + * + * Created on 15 de Março de 2005, 15:32 + */ + +package siprp.data; + +/** + * + * @author fpalma + */ +public interface ActualizacaoSaveable +{ + public static final String ACTUALIZACAO = "actualizacao"; +} diff --git a/trunk/siprp/data/Aviso.java b/trunk/siprp/data/Aviso.java new file mode 100644 index 00000000..791fad87 --- /dev/null +++ b/trunk/siprp/data/Aviso.java @@ -0,0 +1,186 @@ +/* +* Aviso.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Aviso implements JDOInnerObject +{ + private Integer id; + private Integer tipo; + private Empresa empresa; + private Estabelecimento estabelecimento; + private Trabalhador trabalhador; + private Integer evento_id; + private Date data_aviso; + private Date data_evento; + private String descricao; + + public Aviso() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == AvisoData.ID ) + { + return id; + } + else if( fieldName == AvisoData.TIPO ) + { + return tipo; + } + else if( fieldName == AvisoData.EMPRESA ) + { + return empresa; + } + else if( fieldName == AvisoData.ESTABELECIMENTO ) + { + return estabelecimento; + } + else if( fieldName == AvisoData.TRABALHADOR ) + { + return trabalhador; + } + else if( fieldName == AvisoData.EVENTO_ID ) + { + return evento_id; + } + else if( fieldName == AvisoData.DATA_AVISO ) + { + return data_aviso; + } + else if( fieldName == AvisoData.DATA_EVENTO ) + { + return data_evento; + } + else if( fieldName == AvisoData.DESCRICAO ) + { + return descricao; + } + else if( fieldName.equals( AvisoData.ID ) ) + { + return id; + } + else if( fieldName.equals( AvisoData.TIPO ) ) + { + return tipo; + } + else if( fieldName.equals( AvisoData.EMPRESA ) ) + { + return empresa; + } + else if( fieldName.equals( AvisoData.ESTABELECIMENTO ) ) + { + return estabelecimento; + } + else if( fieldName.equals( AvisoData.TRABALHADOR ) ) + { + return trabalhador; + } + else if( fieldName.equals( AvisoData.EVENTO_ID ) ) + { + return evento_id; + } + else if( fieldName.equals( AvisoData.DATA_AVISO ) ) + { + return data_aviso; + } + else if( fieldName.equals( AvisoData.DATA_EVENTO ) ) + { + return data_evento; + } + else if( fieldName.equals( AvisoData.DESCRICAO ) ) + { + return descricao; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == AvisoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == AvisoData.TIPO ) + { + tipo = ( Integer ) value; + } + else if( fieldName == AvisoData.EMPRESA ) + { + empresa = ( Empresa ) value; + } + else if( fieldName == AvisoData.ESTABELECIMENTO ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName == AvisoData.TRABALHADOR ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName == AvisoData.EVENTO_ID ) + { + evento_id = ( Integer ) value; + } + else if( fieldName == AvisoData.DATA_AVISO ) + { + data_aviso = ( Date ) value; + } + else if( fieldName == AvisoData.DATA_EVENTO ) + { + data_evento = ( Date ) value; + } + else if( fieldName == AvisoData.DESCRICAO ) + { + descricao = ( String ) value; + } + else if( fieldName.equals( AvisoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( AvisoData.TIPO ) ) + { + tipo = ( Integer ) value; + } + else if( fieldName.equals( AvisoData.EMPRESA ) ) + { + empresa = ( Empresa ) value; + } + else if( fieldName.equals( AvisoData.ESTABELECIMENTO ) ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName.equals( AvisoData.TRABALHADOR ) ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName.equals( AvisoData.EVENTO_ID ) ) + { + evento_id = ( Integer ) value; + } + else if( fieldName.equals( AvisoData.DATA_AVISO ) ) + { + data_aviso = ( Date ) value; + } + else if( fieldName.equals( AvisoData.DATA_EVENTO ) ) + { + data_evento = ( Date ) value; + } + else if( fieldName.equals( AvisoData.DESCRICAO ) ) + { + descricao = ( String ) value; + } + } + + public Class getOuterClass() + { + return AvisoData.class; + } +} diff --git a/trunk/siprp/data/AvisoConstants.java b/trunk/siprp/data/AvisoConstants.java new file mode 100644 index 00000000..1f8ca61f --- /dev/null +++ b/trunk/siprp/data/AvisoConstants.java @@ -0,0 +1,18 @@ +/* + * AvisoConstants.java + * + * Created on 11 de Outubro de 2004, 13:03 + */ + +package siprp.data; + +/** + * + * @author fpalma + */ +public interface AvisoConstants +{ + public static final int TIPO_TRABALHADOR = 0; + public static final int TIPO_ESTABELECIMENTO = 1; + public static final int TIPO_EMPRESA = 2; +} diff --git a/trunk/siprp/data/AvisoData.java b/trunk/siprp/data/AvisoData.java new file mode 100644 index 00000000..dace2057 --- /dev/null +++ b/trunk/siprp/data/AvisoData.java @@ -0,0 +1,68 @@ +/* +* AvisoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class AvisoData extends JDOObject + implements AvisoConstants +{ + public static final String ID = "id"; + public static final String TIPO = "tipo"; + public static final String EMPRESA = "empresa"; + public static final String ESTABELECIMENTO = "estabelecimento"; + public static final String TRABALHADOR = "trabalhador"; + public static final String EVENTO_ID = "evento_id"; + public static final String DATA_AVISO = "data_aviso"; + public static final String DATA_EVENTO = "data_evento"; + public static final String DESCRICAO = "descricao"; + + public static final String FIELD_NAMES[] = new String[]{ + TIPO, EMPRESA, ESTABELECIMENTO, TRABALHADOR, EVENTO_ID, DATA_AVISO, DATA_EVENTO, + DESCRICAO, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, TIPO, EMPRESA, ESTABELECIMENTO, TRABALHADOR, EVENTO_ID, DATA_AVISO, DATA_EVENTO, + DESCRICAO, }; + + private HashMap dataHash; + + public AvisoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Aviso.class; + } +} diff --git a/trunk/siprp/data/AvisoID.java b/trunk/siprp/data/AvisoID.java new file mode 100644 index 00000000..9a7cfb3f --- /dev/null +++ b/trunk/siprp/data/AvisoID.java @@ -0,0 +1,22 @@ +/* +* AvisoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class AvisoID extends IntegerID +{ + public AvisoID() + { + } + + public AvisoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Contacto.java b/trunk/siprp/data/Contacto.java new file mode 100644 index 00000000..38941701 --- /dev/null +++ b/trunk/siprp/data/Contacto.java @@ -0,0 +1,152 @@ +/* +* Contacto.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Contacto implements JDOInnerObject +{ + private Integer id; + private String nome; + private String cargo; + private String telefone; + private String telemovel; + private String fax; + private String email; + + public Contacto() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == ContactoData.ID ) + { + return id; + } + else if( fieldName == ContactoData.NOME ) + { + return nome; + } + else if( fieldName == ContactoData.CARGO ) + { + return cargo; + } + else if( fieldName == ContactoData.TELEFONE ) + { + return telefone; + } + else if( fieldName == ContactoData.TELEMOVEL ) + { + return telemovel; + } + else if( fieldName == ContactoData.FAX ) + { + return fax; + } + else if( fieldName == ContactoData.EMAIL ) + { + return email; + } + else if( fieldName.equals( ContactoData.ID ) ) + { + return id; + } + else if( fieldName.equals( ContactoData.NOME ) ) + { + return nome; + } + else if( fieldName.equals( ContactoData.CARGO ) ) + { + return cargo; + } + else if( fieldName.equals( ContactoData.TELEFONE ) ) + { + return telefone; + } + else if( fieldName.equals( ContactoData.TELEMOVEL ) ) + { + return telemovel; + } + else if( fieldName.equals( ContactoData.FAX ) ) + { + return fax; + } + else if( fieldName.equals( ContactoData.EMAIL ) ) + { + return email; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == ContactoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == ContactoData.NOME ) + { + nome = ( String ) value; + } + else if( fieldName == ContactoData.CARGO ) + { + cargo = ( String ) value; + } + else if( fieldName == ContactoData.TELEFONE ) + { + telefone = ( String ) value; + } + else if( fieldName == ContactoData.TELEMOVEL ) + { + telemovel = ( String ) value; + } + else if( fieldName == ContactoData.FAX ) + { + fax = ( String ) value; + } + else if( fieldName == ContactoData.EMAIL ) + { + email = ( String ) value; + } + else if( fieldName.equals( ContactoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( ContactoData.NOME ) ) + { + nome = ( String ) value; + } + else if( fieldName.equals( ContactoData.CARGO ) ) + { + cargo = ( String ) value; + } + else if( fieldName.equals( ContactoData.TELEFONE ) ) + { + telefone = ( String ) value; + } + else if( fieldName.equals( ContactoData.TELEMOVEL ) ) + { + telemovel = ( String ) value; + } + else if( fieldName.equals( ContactoData.FAX ) ) + { + fax = ( String ) value; + } + else if( fieldName.equals( ContactoData.EMAIL ) ) + { + email = ( String ) value; + } + } + + public Class getOuterClass() + { + return ContactoData.class; + } +} diff --git a/trunk/siprp/data/ContactoData.java b/trunk/siprp/data/ContactoData.java new file mode 100644 index 00000000..a3fd1829 --- /dev/null +++ b/trunk/siprp/data/ContactoData.java @@ -0,0 +1,63 @@ +/* +* ContactoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class ContactoData extends JDOObject +{ + public static final String ID = "id"; + public static final String NOME = "nome"; + public static final String CARGO = "cargo"; + public static final String TELEFONE = "telefone"; + public static final String TELEMOVEL = "telemovel"; + public static final String FAX = "fax"; + public static final String EMAIL = "email"; + + public static final String FIELD_NAMES[] = new String[]{ + NOME, CARGO, TELEFONE, TELEMOVEL, FAX, EMAIL, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, NOME, CARGO, TELEFONE, TELEMOVEL, FAX, EMAIL, }; + + private HashMap dataHash; + + public ContactoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Contacto.class; + } +} diff --git a/trunk/siprp/data/ContactoID.java b/trunk/siprp/data/ContactoID.java new file mode 100644 index 00000000..a142d5ef --- /dev/null +++ b/trunk/siprp/data/ContactoID.java @@ -0,0 +1,22 @@ +/* +* ContactoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 13/Out/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class ContactoID extends IntegerID +{ + public ContactoID() + { + } + + public ContactoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/DisableDeleteHandler.java b/trunk/siprp/data/DisableDeleteHandler.java new file mode 100644 index 00000000..d6f2650e --- /dev/null +++ b/trunk/siprp/data/DisableDeleteHandler.java @@ -0,0 +1,70 @@ +/* + * DeleteHandler.java + * + * Created on 11 de Outubro de 2004, 16:04 + */ + +package siprp.data; + +import com.evolute.utils.jdo.*; + +/** + * + * @author fpalma + */ +public class DisableDeleteHandler implements JDOOperationHandlerInterface +{ + public static final DisableDeleteHandler INSTANCE = new DisableDeleteHandler(); + + /** Creates a new instance of DeleteHandler */ + public DisableDeleteHandler() + { + } + + public boolean handle( JDOObject object, int operation, int moment ) + throws Exception + { + if( !( object instanceof DisableDeleteable ) ) + { + return false; + } + switch( operation ) + { + case OP_SAVE: + return save( object, moment ); + + case OP_DELETE: + return delete( object, moment ); + + } + return false; + } + + protected boolean save( JDOObject object, int moment ) + throws Exception + { + if( moment != MOMENT_BEFORE ) + { + return false; + } + String old = (String) object.get( DisableDeleteable.INACTIVO ); + if( old == null ) + { + object.set( DisableDeleteable.INACTIVO, "n" ); + } + return true; + } + + protected boolean delete( JDOObject object, int moment ) + throws Exception + { + if( moment != MOMENT_INSTEAD ) + { + return false; + } + object.set( DisableDeleteable.INACTIVO, "y" ); + object.save(); + return true; + } + +} diff --git a/trunk/siprp/data/DisableDeleteable.java b/trunk/siprp/data/DisableDeleteable.java new file mode 100644 index 00000000..b3ba4e52 --- /dev/null +++ b/trunk/siprp/data/DisableDeleteable.java @@ -0,0 +1,16 @@ +/* + * DisableDeleteable.java + * + * Created on 11 de Outubro de 2004, 16:09 + */ + +package siprp.data; + +/** + * + * @author fpalma + */ +public interface DisableDeleteable +{ + public static final String INACTIVO = "inactivo"; +} diff --git a/trunk/siprp/data/Empresa.java b/trunk/siprp/data/Empresa.java new file mode 100644 index 00000000..bc4af209 --- /dev/null +++ b/trunk/siprp/data/Empresa.java @@ -0,0 +1,713 @@ +/* +* Empresa.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Jan 31, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Empresa implements JDOInnerObject +{ + private Integer id; + private String designacao_social; + private String designacao_social_plain; + private Integer servico_saude_tipo; + private String servico_saude_designacao; + private Integer servico_higiene_tipo; + private String servico_higiene_designacao; + private String morada; + private String codigo_postal; + private String localidade; + private String distrito; + private String concelho; + private Date data_proposta; + private Date data_aceitacao; + private Date data_cancelamento; + private String perfil_1; + private String perfil_2; + private Date data_envio_contrato; + private Date data_recepcao_contrato; + private Date data_envio_idict; + private Date data_relatorio_anual; + private String codigo_1; + private String codigo_2; + private String codigo_3; + private String cae; + private String actividade; + private String contribuinte; + private String seguranca_social; + private Double preco_higiene; + private Double preco_medicina; + private String periodicidade; + private Contacto contacto_1; + private Contacto contacto_2; + private Integer servicos; + private String inactivo; + private Date actualizacao; + private String a_consultas; + private String a_exames; + private String b_consultas; + private String b_exames; + + public Empresa() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == EmpresaData.ID ) + { + return id; + } + else if( fieldName == EmpresaData.DESIGNACAO_SOCIAL ) + { + return designacao_social; + } + else if( fieldName == EmpresaData.DESIGNACAO_SOCIAL_PLAIN ) + { + return designacao_social_plain; + } + else if( fieldName == EmpresaData.SERVICO_SAUDE_TIPO ) + { + return servico_saude_tipo; + } + else if( fieldName == EmpresaData.SERVICO_SAUDE_DESIGNACAO ) + { + return servico_saude_designacao; + } + else if( fieldName == EmpresaData.SERVICO_HIGIENE_TIPO ) + { + return servico_higiene_tipo; + } + else if( fieldName == EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) + { + return servico_higiene_designacao; + } + else if( fieldName == EmpresaData.MORADA ) + { + return morada; + } + else if( fieldName == EmpresaData.CODIGO_POSTAL ) + { + return codigo_postal; + } + else if( fieldName == EmpresaData.LOCALIDADE ) + { + return localidade; + } + else if( fieldName == EmpresaData.DISTRITO ) + { + return distrito; + } + else if( fieldName == EmpresaData.CONCELHO ) + { + return concelho; + } + else if( fieldName == EmpresaData.DATA_PROPOSTA ) + { + return data_proposta; + } + else if( fieldName == EmpresaData.DATA_ACEITACAO ) + { + return data_aceitacao; + } + else if( fieldName == EmpresaData.DATA_CANCELAMENTO ) + { + return data_cancelamento; + } + else if( fieldName == EmpresaData.PERFIL_1 ) + { + return perfil_1; + } + else if( fieldName == EmpresaData.PERFIL_2 ) + { + return perfil_2; + } + else if( fieldName == EmpresaData.DATA_ENVIO_CONTRATO ) + { + return data_envio_contrato; + } + else if( fieldName == EmpresaData.DATA_RECEPCAO_CONTRATO ) + { + return data_recepcao_contrato; + } + else if( fieldName == EmpresaData.DATA_ENVIO_IDICT ) + { + return data_envio_idict; + } + else if( fieldName == EmpresaData.DATA_RELATORIO_ANUAL ) + { + return data_relatorio_anual; + } + else if( fieldName == EmpresaData.CODIGO_1 ) + { + return codigo_1; + } + else if( fieldName == EmpresaData.CODIGO_2 ) + { + return codigo_2; + } + else if( fieldName == EmpresaData.CODIGO_3 ) + { + return codigo_3; + } + else if( fieldName == EmpresaData.CAE ) + { + return cae; + } + else if( fieldName == EmpresaData.ACTIVIDADE ) + { + return actividade; + } + else if( fieldName == EmpresaData.CONTRIBUINTE ) + { + return contribuinte; + } + else if( fieldName == EmpresaData.SEGURANCA_SOCIAL ) + { + return seguranca_social; + } + else if( fieldName == EmpresaData.PRECO_HIGIENE ) + { + return preco_higiene; + } + else if( fieldName == EmpresaData.PRECO_MEDICINA ) + { + return preco_medicina; + } + else if( fieldName == EmpresaData.PERIODICIDADE ) + { + return periodicidade; + } + else if( fieldName == EmpresaData.CONTACTO_1 ) + { + return contacto_1; + } + else if( fieldName == EmpresaData.CONTACTO_2 ) + { + return contacto_2; + } + else if( fieldName == EmpresaData.SERVICOS ) + { + return servicos; + } + else if( fieldName == EmpresaData.INACTIVO ) + { + return inactivo; + } + else if( fieldName == EmpresaData.ACTUALIZACAO ) + { + return actualizacao; + } + else if( fieldName == EmpresaData.A_CONSULTAS ) + { + return a_consultas; + } + else if( fieldName == EmpresaData.A_EXAMES ) + { + return a_exames; + } + else if( fieldName == EmpresaData.B_CONSULTAS ) + { + return b_consultas; + } + else if( fieldName == EmpresaData.B_EXAMES ) + { + return b_exames; + } + else if( fieldName.equals( EmpresaData.ID ) ) + { + return id; + } + else if( fieldName.equals( EmpresaData.DESIGNACAO_SOCIAL ) ) + { + return designacao_social; + } + else if( fieldName.equals( EmpresaData.DESIGNACAO_SOCIAL_PLAIN ) ) + { + return designacao_social_plain; + } + else if( fieldName.equals( EmpresaData.SERVICO_SAUDE_TIPO ) ) + { + return servico_saude_tipo; + } + else if( fieldName.equals( EmpresaData.SERVICO_SAUDE_DESIGNACAO ) ) + { + return servico_saude_designacao; + } + else if( fieldName.equals( EmpresaData.SERVICO_HIGIENE_TIPO ) ) + { + return servico_higiene_tipo; + } + else if( fieldName.equals( EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) ) + { + return servico_higiene_designacao; + } + else if( fieldName.equals( EmpresaData.MORADA ) ) + { + return morada; + } + else if( fieldName.equals( EmpresaData.CODIGO_POSTAL ) ) + { + return codigo_postal; + } + else if( fieldName.equals( EmpresaData.LOCALIDADE ) ) + { + return localidade; + } + else if( fieldName.equals( EmpresaData.DISTRITO ) ) + { + return distrito; + } + else if( fieldName.equals( EmpresaData.CONCELHO ) ) + { + return concelho; + } + else if( fieldName.equals( EmpresaData.DATA_PROPOSTA ) ) + { + return data_proposta; + } + else if( fieldName.equals( EmpresaData.DATA_ACEITACAO ) ) + { + return data_aceitacao; + } + else if( fieldName.equals( EmpresaData.DATA_CANCELAMENTO ) ) + { + return data_cancelamento; + } + else if( fieldName.equals( EmpresaData.PERFIL_1 ) ) + { + return perfil_1; + } + else if( fieldName.equals( EmpresaData.PERFIL_2 ) ) + { + return perfil_2; + } + else if( fieldName.equals( EmpresaData.DATA_ENVIO_CONTRATO ) ) + { + return data_envio_contrato; + } + else if( fieldName.equals( EmpresaData.DATA_RECEPCAO_CONTRATO ) ) + { + return data_recepcao_contrato; + } + else if( fieldName.equals( EmpresaData.DATA_ENVIO_IDICT ) ) + { + return data_envio_idict; + } + else if( fieldName.equals( EmpresaData.DATA_RELATORIO_ANUAL ) ) + { + return data_relatorio_anual; + } + else if( fieldName.equals( EmpresaData.CODIGO_1 ) ) + { + return codigo_1; + } + else if( fieldName.equals( EmpresaData.CODIGO_2 ) ) + { + return codigo_2; + } + else if( fieldName.equals( EmpresaData.CODIGO_3 ) ) + { + return codigo_3; + } + else if( fieldName.equals( EmpresaData.CAE ) ) + { + return cae; + } + else if( fieldName.equals( EmpresaData.ACTIVIDADE ) ) + { + return actividade; + } + else if( fieldName.equals( EmpresaData.CONTRIBUINTE ) ) + { + return contribuinte; + } + else if( fieldName.equals( EmpresaData.SEGURANCA_SOCIAL ) ) + { + return seguranca_social; + } + else if( fieldName.equals( EmpresaData.PRECO_HIGIENE ) ) + { + return preco_higiene; + } + else if( fieldName.equals( EmpresaData.PRECO_MEDICINA ) ) + { + return preco_medicina; + } + else if( fieldName.equals( EmpresaData.PERIODICIDADE ) ) + { + return periodicidade; + } + else if( fieldName.equals( EmpresaData.CONTACTO_1 ) ) + { + return contacto_1; + } + else if( fieldName.equals( EmpresaData.CONTACTO_2 ) ) + { + return contacto_2; + } + else if( fieldName.equals( EmpresaData.SERVICOS ) ) + { + return servicos; + } + else if( fieldName.equals( EmpresaData.INACTIVO ) ) + { + return inactivo; + } + else if( fieldName.equals( EmpresaData.ACTUALIZACAO ) ) + { + return actualizacao; + } + else if( fieldName.equals( EmpresaData.A_CONSULTAS ) ) + { + return a_consultas; + } + else if( fieldName.equals( EmpresaData.A_EXAMES ) ) + { + return a_exames; + } + else if( fieldName.equals( EmpresaData.B_CONSULTAS ) ) + { + return b_consultas; + } + else if( fieldName.equals( EmpresaData.B_EXAMES ) ) + { + return b_exames; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == EmpresaData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == EmpresaData.DESIGNACAO_SOCIAL ) + { + designacao_social = ( String ) value; + } + else if( fieldName == EmpresaData.DESIGNACAO_SOCIAL_PLAIN ) + { + designacao_social_plain = ( String ) value; + } + else if( fieldName == EmpresaData.SERVICO_SAUDE_TIPO ) + { + servico_saude_tipo = ( Integer ) value; + } + else if( fieldName == EmpresaData.SERVICO_SAUDE_DESIGNACAO ) + { + servico_saude_designacao = ( String ) value; + } + else if( fieldName == EmpresaData.SERVICO_HIGIENE_TIPO ) + { + servico_higiene_tipo = ( Integer ) value; + } + else if( fieldName == EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) + { + servico_higiene_designacao = ( String ) value; + } + else if( fieldName == EmpresaData.MORADA ) + { + morada = ( String ) value; + } + else if( fieldName == EmpresaData.CODIGO_POSTAL ) + { + codigo_postal = ( String ) value; + } + else if( fieldName == EmpresaData.LOCALIDADE ) + { + localidade = ( String ) value; + } + else if( fieldName == EmpresaData.DISTRITO ) + { + distrito = ( String ) value; + } + else if( fieldName == EmpresaData.CONCELHO ) + { + concelho = ( String ) value; + } + else if( fieldName == EmpresaData.DATA_PROPOSTA ) + { + data_proposta = ( Date ) value; + } + else if( fieldName == EmpresaData.DATA_ACEITACAO ) + { + data_aceitacao = ( Date ) value; + } + else if( fieldName == EmpresaData.DATA_CANCELAMENTO ) + { + data_cancelamento = ( Date ) value; + } + else if( fieldName == EmpresaData.PERFIL_1 ) + { + perfil_1 = ( String ) value; + } + else if( fieldName == EmpresaData.PERFIL_2 ) + { + perfil_2 = ( String ) value; + } + else if( fieldName == EmpresaData.DATA_ENVIO_CONTRATO ) + { + data_envio_contrato = ( Date ) value; + } + else if( fieldName == EmpresaData.DATA_RECEPCAO_CONTRATO ) + { + data_recepcao_contrato = ( Date ) value; + } + else if( fieldName == EmpresaData.DATA_ENVIO_IDICT ) + { + data_envio_idict = ( Date ) value; + } + else if( fieldName == EmpresaData.DATA_RELATORIO_ANUAL ) + { + data_relatorio_anual = ( Date ) value; + } + else if( fieldName == EmpresaData.CODIGO_1 ) + { + codigo_1 = ( String ) value; + } + else if( fieldName == EmpresaData.CODIGO_2 ) + { + codigo_2 = ( String ) value; + } + else if( fieldName == EmpresaData.CODIGO_3 ) + { + codigo_3 = ( String ) value; + } + else if( fieldName == EmpresaData.CAE ) + { + cae = ( String ) value; + } + else if( fieldName == EmpresaData.ACTIVIDADE ) + { + actividade = ( String ) value; + } + else if( fieldName == EmpresaData.CONTRIBUINTE ) + { + contribuinte = ( String ) value; + } + else if( fieldName == EmpresaData.SEGURANCA_SOCIAL ) + { + seguranca_social = ( String ) value; + } + else if( fieldName == EmpresaData.PRECO_HIGIENE ) + { + preco_higiene = ( Double ) value; + } + else if( fieldName == EmpresaData.PRECO_MEDICINA ) + { + preco_medicina = ( Double ) value; + } + else if( fieldName == EmpresaData.PERIODICIDADE ) + { + periodicidade = ( String ) value; + } + else if( fieldName == EmpresaData.CONTACTO_1 ) + { + contacto_1 = ( Contacto ) value; + } + else if( fieldName == EmpresaData.CONTACTO_2 ) + { + contacto_2 = ( Contacto ) value; + } + else if( fieldName == EmpresaData.SERVICOS ) + { + servicos = ( Integer ) value; + } + else if( fieldName == EmpresaData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName == EmpresaData.ACTUALIZACAO ) + { + actualizacao = ( Date ) value; + } + else if( fieldName == EmpresaData.A_CONSULTAS ) + { + a_consultas = ( String ) value; + } + else if( fieldName == EmpresaData.A_EXAMES ) + { + a_exames = ( String ) value; + } + else if( fieldName == EmpresaData.B_CONSULTAS ) + { + b_consultas = ( String ) value; + } + else if( fieldName == EmpresaData.B_EXAMES ) + { + b_exames = ( String ) value; + } + else if( fieldName.equals( EmpresaData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( EmpresaData.DESIGNACAO_SOCIAL ) ) + { + designacao_social = ( String ) value; + } + else if( fieldName.equals( EmpresaData.DESIGNACAO_SOCIAL_PLAIN ) ) + { + designacao_social_plain = ( String ) value; + } + else if( fieldName.equals( EmpresaData.SERVICO_SAUDE_TIPO ) ) + { + servico_saude_tipo = ( Integer ) value; + } + else if( fieldName.equals( EmpresaData.SERVICO_SAUDE_DESIGNACAO ) ) + { + servico_saude_designacao = ( String ) value; + } + else if( fieldName.equals( EmpresaData.SERVICO_HIGIENE_TIPO ) ) + { + servico_higiene_tipo = ( Integer ) value; + } + else if( fieldName.equals( EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) ) + { + servico_higiene_designacao = ( String ) value; + } + else if( fieldName.equals( EmpresaData.MORADA ) ) + { + morada = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CODIGO_POSTAL ) ) + { + codigo_postal = ( String ) value; + } + else if( fieldName.equals( EmpresaData.LOCALIDADE ) ) + { + localidade = ( String ) value; + } + else if( fieldName.equals( EmpresaData.DISTRITO ) ) + { + distrito = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CONCELHO ) ) + { + concelho = ( String ) value; + } + else if( fieldName.equals( EmpresaData.DATA_PROPOSTA ) ) + { + data_proposta = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.DATA_ACEITACAO ) ) + { + data_aceitacao = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.DATA_CANCELAMENTO ) ) + { + data_cancelamento = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.PERFIL_1 ) ) + { + perfil_1 = ( String ) value; + } + else if( fieldName.equals( EmpresaData.PERFIL_2 ) ) + { + perfil_2 = ( String ) value; + } + else if( fieldName.equals( EmpresaData.DATA_ENVIO_CONTRATO ) ) + { + data_envio_contrato = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.DATA_RECEPCAO_CONTRATO ) ) + { + data_recepcao_contrato = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.DATA_ENVIO_IDICT ) ) + { + data_envio_idict = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.DATA_RELATORIO_ANUAL ) ) + { + data_relatorio_anual = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.CODIGO_1 ) ) + { + codigo_1 = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CODIGO_2 ) ) + { + codigo_2 = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CODIGO_3 ) ) + { + codigo_3 = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CAE ) ) + { + cae = ( String ) value; + } + else if( fieldName.equals( EmpresaData.ACTIVIDADE ) ) + { + actividade = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CONTRIBUINTE ) ) + { + contribuinte = ( String ) value; + } + else if( fieldName.equals( EmpresaData.SEGURANCA_SOCIAL ) ) + { + seguranca_social = ( String ) value; + } + else if( fieldName.equals( EmpresaData.PRECO_HIGIENE ) ) + { + preco_higiene = ( Double ) value; + } + else if( fieldName.equals( EmpresaData.PRECO_MEDICINA ) ) + { + preco_medicina = ( Double ) value; + } + else if( fieldName.equals( EmpresaData.PERIODICIDADE ) ) + { + periodicidade = ( String ) value; + } + else if( fieldName.equals( EmpresaData.CONTACTO_1 ) ) + { + contacto_1 = ( Contacto ) value; + } + else if( fieldName.equals( EmpresaData.CONTACTO_2 ) ) + { + contacto_2 = ( Contacto ) value; + } + else if( fieldName.equals( EmpresaData.SERVICOS ) ) + { + servicos = ( Integer ) value; + } + else if( fieldName.equals( EmpresaData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( EmpresaData.ACTUALIZACAO ) ) + { + actualizacao = ( Date ) value; + } + else if( fieldName.equals( EmpresaData.A_CONSULTAS ) ) + { + a_consultas = ( String ) value; + } + else if( fieldName.equals( EmpresaData.A_EXAMES ) ) + { + a_exames = ( String ) value; + } + else if( fieldName.equals( EmpresaData.B_CONSULTAS ) ) + { + b_consultas = ( String ) value; + } + else if( fieldName.equals( EmpresaData.B_EXAMES ) ) + { + b_exames = ( String ) value; + } + } + + public Class getOuterClass() + { + return EmpresaData.class; + } +} diff --git a/trunk/siprp/data/EmpresaData.java b/trunk/siprp/data/EmpresaData.java new file mode 100644 index 00000000..eea9b2e5 --- /dev/null +++ b/trunk/siprp/data/EmpresaData.java @@ -0,0 +1,111 @@ +/* +* EmpresaData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Jan 31, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class EmpresaData extends JDOObject + implements DisableDeleteable, ActualizacaoSaveable +{ + public static final String ID = "id"; + public static final String DESIGNACAO_SOCIAL = "designacao_social"; + public static final String DESIGNACAO_SOCIAL_PLAIN = "designacao_social_plain"; + public static final String SERVICO_SAUDE_TIPO = "servico_saude_tipo"; + public static final String SERVICO_SAUDE_DESIGNACAO = "servico_saude_designacao"; + public static final String SERVICO_HIGIENE_TIPO = "servico_higiene_tipo"; + public static final String SERVICO_HIGIENE_DESIGNACAO = "servico_higiene_designacao"; + public static final String MORADA = "morada"; + public static final String CODIGO_POSTAL = "codigo_postal"; + public static final String LOCALIDADE = "localidade"; + public static final String DISTRITO = "distrito"; + public static final String CONCELHO = "concelho"; + public static final String DATA_PROPOSTA = "data_proposta"; + public static final String DATA_ACEITACAO = "data_aceitacao"; + public static final String DATA_CANCELAMENTO = "data_cancelamento"; + public static final String PERFIL_1 = "perfil_1"; + public static final String PERFIL_2 = "perfil_2"; + public static final String DATA_ENVIO_CONTRATO = "data_envio_contrato"; + public static final String DATA_RECEPCAO_CONTRATO = "data_recepcao_contrato"; + public static final String DATA_ENVIO_IDICT = "data_envio_idict"; + public static final String DATA_RELATORIO_ANUAL = "data_relatorio_anual"; + public static final String CODIGO_1 = "codigo_1"; + public static final String CODIGO_2 = "codigo_2"; + public static final String CODIGO_3 = "codigo_3"; + public static final String CAE = "cae"; + public static final String ACTIVIDADE = "actividade"; + public static final String CONTRIBUINTE = "contribuinte"; + public static final String SEGURANCA_SOCIAL = "seguranca_social"; + public static final String PRECO_HIGIENE = "preco_higiene"; + public static final String PRECO_MEDICINA = "preco_medicina"; + public static final String PERIODICIDADE = "periodicidade"; + public static final String CONTACTO_1 = "contacto_1"; + public static final String CONTACTO_2 = "contacto_2"; + public static final String SERVICOS = "servicos"; + public static final String INACTIVO = "inactivo"; + public static final String ACTUALIZACAO = "actualizacao"; + public static final String A_CONSULTAS = "a_consultas"; + public static final String A_EXAMES = "a_exames"; + public static final String B_CONSULTAS = "b_consultas"; + public static final String B_EXAMES = "b_exames"; + + public static final String FIELD_NAMES[] = new String[]{ + DESIGNACAO_SOCIAL, DESIGNACAO_SOCIAL_PLAIN, SERVICO_SAUDE_TIPO, + SERVICO_SAUDE_DESIGNACAO, SERVICO_HIGIENE_TIPO, SERVICO_HIGIENE_DESIGNACAO, + MORADA, CODIGO_POSTAL, LOCALIDADE, DISTRITO, CONCELHO, DATA_PROPOSTA, + DATA_ACEITACAO, DATA_CANCELAMENTO, PERFIL_1, PERFIL_2, DATA_ENVIO_CONTRATO, + DATA_RECEPCAO_CONTRATO, DATA_ENVIO_IDICT, DATA_RELATORIO_ANUAL, CODIGO_1, + CODIGO_2, CODIGO_3, CAE, ACTIVIDADE, CONTRIBUINTE, SEGURANCA_SOCIAL, PRECO_HIGIENE, + PRECO_MEDICINA, PERIODICIDADE, CONTACTO_1, CONTACTO_2, SERVICOS, A_CONSULTAS, + A_EXAMES, B_CONSULTAS, B_EXAMES, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DESIGNACAO_SOCIAL, DESIGNACAO_SOCIAL_PLAIN, SERVICO_SAUDE_TIPO, + SERVICO_SAUDE_DESIGNACAO, SERVICO_HIGIENE_TIPO, SERVICO_HIGIENE_DESIGNACAO, + MORADA, CODIGO_POSTAL, LOCALIDADE, DISTRITO, CONCELHO, DATA_PROPOSTA, + DATA_ACEITACAO, DATA_CANCELAMENTO, PERFIL_1, PERFIL_2, DATA_ENVIO_CONTRATO, + DATA_RECEPCAO_CONTRATO, DATA_ENVIO_IDICT, DATA_RELATORIO_ANUAL, CODIGO_1, + CODIGO_2, CODIGO_3, CAE, ACTIVIDADE, CONTRIBUINTE, SEGURANCA_SOCIAL, PRECO_HIGIENE, + PRECO_MEDICINA, PERIODICIDADE, CONTACTO_1, CONTACTO_2, SERVICOS, INACTIVO, + ACTUALIZACAO, A_CONSULTAS, A_EXAMES, B_CONSULTAS, B_EXAMES, }; + + private HashMap dataHash; + + public EmpresaData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Empresa.class; + } +} diff --git a/trunk/siprp/data/EmpresaID.java b/trunk/siprp/data/EmpresaID.java new file mode 100644 index 00000000..68fcce9d --- /dev/null +++ b/trunk/siprp/data/EmpresaID.java @@ -0,0 +1,25 @@ +/* +* EmpresaID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on Jan 31, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class EmpresaID extends IntegerID + implements Serializable +{ + public EmpresaID() + { + } + + public EmpresaID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Estabelecimento.java b/trunk/siprp/data/Estabelecimento.java new file mode 100644 index 00000000..e14be8da --- /dev/null +++ b/trunk/siprp/data/Estabelecimento.java @@ -0,0 +1,220 @@ +/* +* Estabelecimento.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Estabelecimento implements JDOInnerObject +{ + private Integer id; + private String nome; + private String nome_plain; + private String morada; + private String codigo_postal; + private String localidade; + private String historico; + private Empresa empresa; + private Contacto contacto; + private String inactivo; + private Date actualizacao; + + public Estabelecimento() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == EstabelecimentoData.ID ) + { + return id; + } + else if( fieldName == EstabelecimentoData.NOME ) + { + return nome; + } + else if( fieldName == EstabelecimentoData.NOME_PLAIN ) + { + return nome_plain; + } + else if( fieldName == EstabelecimentoData.MORADA ) + { + return morada; + } + else if( fieldName == EstabelecimentoData.CODIGO_POSTAL ) + { + return codigo_postal; + } + else if( fieldName == EstabelecimentoData.LOCALIDADE ) + { + return localidade; + } + else if( fieldName == EstabelecimentoData.HISTORICO ) + { + return historico; + } + else if( fieldName == EstabelecimentoData.EMPRESA ) + { + return empresa; + } + else if( fieldName == EstabelecimentoData.CONTACTO ) + { + return contacto; + } + else if( fieldName == EstabelecimentoData.INACTIVO ) + { + return inactivo; + } + else if( fieldName == EstabelecimentoData.ACTUALIZACAO ) + { + return actualizacao; + } + else if( fieldName.equals( EstabelecimentoData.ID ) ) + { + return id; + } + else if( fieldName.equals( EstabelecimentoData.NOME ) ) + { + return nome; + } + else if( fieldName.equals( EstabelecimentoData.NOME_PLAIN ) ) + { + return nome_plain; + } + else if( fieldName.equals( EstabelecimentoData.MORADA ) ) + { + return morada; + } + else if( fieldName.equals( EstabelecimentoData.CODIGO_POSTAL ) ) + { + return codigo_postal; + } + else if( fieldName.equals( EstabelecimentoData.LOCALIDADE ) ) + { + return localidade; + } + else if( fieldName.equals( EstabelecimentoData.HISTORICO ) ) + { + return historico; + } + else if( fieldName.equals( EstabelecimentoData.EMPRESA ) ) + { + return empresa; + } + else if( fieldName.equals( EstabelecimentoData.CONTACTO ) ) + { + return contacto; + } + else if( fieldName.equals( EstabelecimentoData.INACTIVO ) ) + { + return inactivo; + } + else if( fieldName.equals( EstabelecimentoData.ACTUALIZACAO ) ) + { + return actualizacao; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == EstabelecimentoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == EstabelecimentoData.NOME ) + { + nome = ( String ) value; + } + else if( fieldName == EstabelecimentoData.NOME_PLAIN ) + { + nome_plain = ( String ) value; + } + else if( fieldName == EstabelecimentoData.MORADA ) + { + morada = ( String ) value; + } + else if( fieldName == EstabelecimentoData.CODIGO_POSTAL ) + { + codigo_postal = ( String ) value; + } + else if( fieldName == EstabelecimentoData.LOCALIDADE ) + { + localidade = ( String ) value; + } + else if( fieldName == EstabelecimentoData.HISTORICO ) + { + historico = ( String ) value; + } + else if( fieldName == EstabelecimentoData.EMPRESA ) + { + empresa = ( Empresa ) value; + } + else if( fieldName == EstabelecimentoData.CONTACTO ) + { + contacto = ( Contacto ) value; + } + else if( fieldName == EstabelecimentoData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName == EstabelecimentoData.ACTUALIZACAO ) + { + actualizacao = ( Date ) value; + } + else if( fieldName.equals( EstabelecimentoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( EstabelecimentoData.NOME ) ) + { + nome = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.NOME_PLAIN ) ) + { + nome_plain = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.MORADA ) ) + { + morada = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.CODIGO_POSTAL ) ) + { + codigo_postal = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.LOCALIDADE ) ) + { + localidade = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.HISTORICO ) ) + { + historico = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.EMPRESA ) ) + { + empresa = ( Empresa ) value; + } + else if( fieldName.equals( EstabelecimentoData.CONTACTO ) ) + { + contacto = ( Contacto ) value; + } + else if( fieldName.equals( EstabelecimentoData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( EstabelecimentoData.ACTUALIZACAO ) ) + { + actualizacao = ( Date ) value; + } + } + + public Class getOuterClass() + { + return EstabelecimentoData.class; + } +} diff --git a/trunk/siprp/data/EstabelecimentoData.java b/trunk/siprp/data/EstabelecimentoData.java new file mode 100644 index 00000000..e11cfb6b --- /dev/null +++ b/trunk/siprp/data/EstabelecimentoData.java @@ -0,0 +1,69 @@ +/* +* EstabelecimentoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class EstabelecimentoData extends JDOObject + implements DisableDeleteable, ActualizacaoSaveable +{ + public static final String ID = "id"; + public static final String NOME = "nome"; + public static final String NOME_PLAIN = "nome_plain"; + public static final String MORADA = "morada"; + public static final String CODIGO_POSTAL = "codigo_postal"; + public static final String LOCALIDADE = "localidade"; + public static final String HISTORICO = "historico"; + public static final String EMPRESA = "empresa"; + public static final String CONTACTO = "contacto"; + public static final String INACTIVO = "inactivo"; + public static final String ACTUALIZACAO = "actualizacao"; + + public static final String FIELD_NAMES[] = new String[]{ + NOME, NOME_PLAIN, MORADA, CODIGO_POSTAL, LOCALIDADE, HISTORICO, EMPRESA, CONTACTO, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, NOME, NOME_PLAIN, MORADA, CODIGO_POSTAL, LOCALIDADE, HISTORICO, EMPRESA, CONTACTO, + INACTIVO, ACTUALIZACAO, }; + + private HashMap dataHash; + + public EstabelecimentoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Estabelecimento.class; + } +} diff --git a/trunk/siprp/data/EstabelecimentoID.java b/trunk/siprp/data/EstabelecimentoID.java new file mode 100644 index 00000000..3824759b --- /dev/null +++ b/trunk/siprp/data/EstabelecimentoID.java @@ -0,0 +1,25 @@ +/* +* EstabelecimentoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class EstabelecimentoID extends IntegerID + implements Serializable +{ + public EstabelecimentoID() + { + } + + public EstabelecimentoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Etiqueta.java b/trunk/siprp/data/Etiqueta.java new file mode 100644 index 00000000..7a35bb38 --- /dev/null +++ b/trunk/siprp/data/Etiqueta.java @@ -0,0 +1,270 @@ +/* +* Etiqueta.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 27/Fev/2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.*; + +public final class Etiqueta implements JDOInnerObject +{ + private Integer id; + private String descricao; + private String descricao_plain; + private Double altura; + private Double largura; + private Double margem_esquerda; + private Double margem_cima; + private Integer colunas; + private Integer linhas; + private String continua; + private Double altura_folha; + private Double largura_folha; + private Double margem_vertical_folha; + private Double margem_horizontal_folha; + + public Etiqueta() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == EtiquetaData.ID ) + { + return id; + } + else if( fieldName == EtiquetaData.DESCRICAO ) + { + return descricao; + } + else if( fieldName == EtiquetaData.DESCRICAO_PLAIN ) + { + return descricao_plain; + } + else if( fieldName == EtiquetaData.ALTURA ) + { + return altura; + } + else if( fieldName == EtiquetaData.LARGURA ) + { + return largura; + } + else if( fieldName == EtiquetaData.MARGEM_ESQUERDA ) + { + return margem_esquerda; + } + else if( fieldName == EtiquetaData.MARGEM_CIMA ) + { + return margem_cima; + } + else if( fieldName == EtiquetaData.COLUNAS ) + { + return colunas; + } + else if( fieldName == EtiquetaData.LINHAS ) + { + return linhas; + } + else if( fieldName == EtiquetaData.CONTINUA ) + { + return continua; + } + else if( fieldName == EtiquetaData.ALTURA_FOLHA ) + { + return altura_folha; + } + else if( fieldName == EtiquetaData.LARGURA_FOLHA ) + { + return largura_folha; + } + else if( fieldName == EtiquetaData.MARGEM_VERTICAL_FOLHA ) + { + return margem_vertical_folha; + } + else if( fieldName == EtiquetaData.MARGEM_HORIZONTAL_FOLHA ) + { + return margem_horizontal_folha; + } + else if( fieldName.equals( EtiquetaData.ID ) ) + { + return id; + } + else if( fieldName.equals( EtiquetaData.DESCRICAO ) ) + { + return descricao; + } + else if( fieldName.equals( EtiquetaData.DESCRICAO_PLAIN ) ) + { + return descricao_plain; + } + else if( fieldName.equals( EtiquetaData.ALTURA ) ) + { + return altura; + } + else if( fieldName.equals( EtiquetaData.LARGURA ) ) + { + return largura; + } + else if( fieldName.equals( EtiquetaData.MARGEM_ESQUERDA ) ) + { + return margem_esquerda; + } + else if( fieldName.equals( EtiquetaData.MARGEM_CIMA ) ) + { + return margem_cima; + } + else if( fieldName.equals( EtiquetaData.COLUNAS ) ) + { + return colunas; + } + else if( fieldName.equals( EtiquetaData.LINHAS ) ) + { + return linhas; + } + else if( fieldName.equals( EtiquetaData.CONTINUA ) ) + { + return continua; + } + else if( fieldName.equals( EtiquetaData.ALTURA_FOLHA ) ) + { + return altura_folha; + } + else if( fieldName.equals( EtiquetaData.LARGURA_FOLHA ) ) + { + return largura_folha; + } + else if( fieldName.equals( EtiquetaData.MARGEM_VERTICAL_FOLHA ) ) + { + return margem_vertical_folha; + } + else if( fieldName.equals( EtiquetaData.MARGEM_HORIZONTAL_FOLHA ) ) + { + return margem_horizontal_folha; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == EtiquetaData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == EtiquetaData.DESCRICAO ) + { + descricao = ( String ) value; + } + else if( fieldName == EtiquetaData.DESCRICAO_PLAIN ) + { + descricao_plain = ( String ) value; + } + else if( fieldName == EtiquetaData.ALTURA ) + { + altura = ( Double ) value; + } + else if( fieldName == EtiquetaData.LARGURA ) + { + largura = ( Double ) value; + } + else if( fieldName == EtiquetaData.MARGEM_ESQUERDA ) + { + margem_esquerda = ( Double ) value; + } + else if( fieldName == EtiquetaData.MARGEM_CIMA ) + { + margem_cima = ( Double ) value; + } + else if( fieldName == EtiquetaData.COLUNAS ) + { + colunas = ( Integer ) value; + } + else if( fieldName == EtiquetaData.LINHAS ) + { + linhas = ( Integer ) value; + } + else if( fieldName == EtiquetaData.CONTINUA ) + { + continua = ( String ) value; + } + else if( fieldName == EtiquetaData.ALTURA_FOLHA ) + { + altura_folha = ( Double ) value; + } + else if( fieldName == EtiquetaData.LARGURA_FOLHA ) + { + largura_folha = ( Double ) value; + } + else if( fieldName == EtiquetaData.MARGEM_VERTICAL_FOLHA ) + { + margem_vertical_folha = ( Double ) value; + } + else if( fieldName == EtiquetaData.MARGEM_HORIZONTAL_FOLHA ) + { + margem_horizontal_folha = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( EtiquetaData.DESCRICAO ) ) + { + descricao = ( String ) value; + } + else if( fieldName.equals( EtiquetaData.DESCRICAO_PLAIN ) ) + { + descricao_plain = ( String ) value; + } + else if( fieldName.equals( EtiquetaData.ALTURA ) ) + { + altura = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.LARGURA ) ) + { + largura = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.MARGEM_ESQUERDA ) ) + { + margem_esquerda = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.MARGEM_CIMA ) ) + { + margem_cima = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.COLUNAS ) ) + { + colunas = ( Integer ) value; + } + else if( fieldName.equals( EtiquetaData.LINHAS ) ) + { + linhas = ( Integer ) value; + } + else if( fieldName.equals( EtiquetaData.CONTINUA ) ) + { + continua = ( String ) value; + } + else if( fieldName.equals( EtiquetaData.ALTURA_FOLHA ) ) + { + altura_folha = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.LARGURA_FOLHA ) ) + { + largura_folha = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.MARGEM_VERTICAL_FOLHA ) ) + { + margem_vertical_folha = ( Double ) value; + } + else if( fieldName.equals( EtiquetaData.MARGEM_HORIZONTAL_FOLHA ) ) + { + margem_horizontal_folha = ( Double ) value; + } + } + + public Class getOuterClass() + { + return EtiquetaData.class; + } +} diff --git a/trunk/siprp/data/EtiquetaData.java b/trunk/siprp/data/EtiquetaData.java new file mode 100644 index 00000000..8d244d95 --- /dev/null +++ b/trunk/siprp/data/EtiquetaData.java @@ -0,0 +1,74 @@ +/* +* EtiquetaData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 27/Fev/2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class EtiquetaData extends JDOObject +{ + public static final String ID = "id"; + public static final String DESCRICAO = "descricao"; + public static final String DESCRICAO_PLAIN = "descricao_plain"; + public static final String ALTURA = "altura"; + public static final String LARGURA = "largura"; + public static final String MARGEM_ESQUERDA = "margem_esquerda"; + public static final String MARGEM_CIMA = "margem_cima"; + public static final String COLUNAS = "colunas"; + public static final String LINHAS = "linhas"; + public static final String CONTINUA = "continua"; + public static final String ALTURA_FOLHA = "altura_folha"; + public static final String LARGURA_FOLHA = "largura_folha"; + public static final String MARGEM_VERTICAL_FOLHA = "margem_vertical_folha"; + public static final String MARGEM_HORIZONTAL_FOLHA = "margem_horizontal_folha"; + + public static final String FIELD_NAMES[] = new String[]{ + DESCRICAO, DESCRICAO_PLAIN, ALTURA, LARGURA, MARGEM_ESQUERDA, MARGEM_CIMA, COLUNAS, + LINHAS, CONTINUA, ALTURA_FOLHA, LARGURA_FOLHA, MARGEM_VERTICAL_FOLHA, + MARGEM_HORIZONTAL_FOLHA, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DESCRICAO, DESCRICAO_PLAIN, ALTURA, LARGURA, MARGEM_ESQUERDA, MARGEM_CIMA, + COLUNAS, LINHAS, CONTINUA, ALTURA_FOLHA, LARGURA_FOLHA, MARGEM_VERTICAL_FOLHA, + MARGEM_HORIZONTAL_FOLHA, }; + + private HashMap dataHash; + + public EtiquetaData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Etiqueta.class; + } +} diff --git a/trunk/siprp/data/EtiquetaID.java b/trunk/siprp/data/EtiquetaID.java new file mode 100644 index 00000000..d014ef55 --- /dev/null +++ b/trunk/siprp/data/EtiquetaID.java @@ -0,0 +1,25 @@ +/* +* EtiquetaID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 27/Fev/2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class EtiquetaID extends IntegerID + implements Serializable +{ + public EtiquetaID() + { + } + + public EtiquetaID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Exame.java b/trunk/siprp/data/Exame.java new file mode 100644 index 00000000..b00c1146 --- /dev/null +++ b/trunk/siprp/data/Exame.java @@ -0,0 +1,305 @@ +/* +* Exame.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 28/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Exame implements JDOInnerObject +{ + private Integer id; + private Date data; + private Integer tipo; + private Integer ocasional; + private String outro_tipo; + private Integer resultado; + private String outra_funcao_1; + private String outra_funcao_2; + private String outra_funcao_3; + private String outra_funcao_4; + private Date proximo_exame; + private String outras_recomendacoes; + private Trabalhador trabalhador; + private Medico medico; + private byte[] pdf; + private String inactivo; + + public Exame() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == ExameData.ID ) + { + return id; + } + else if( fieldName == ExameData.DATA ) + { + return data; + } + else if( fieldName == ExameData.TIPO ) + { + return tipo; + } + else if( fieldName == ExameData.OCASIONAL ) + { + return ocasional; + } + else if( fieldName == ExameData.OUTRO_TIPO ) + { + return outro_tipo; + } + else if( fieldName == ExameData.RESULTADO ) + { + return resultado; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_1 ) + { + return outra_funcao_1; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_2 ) + { + return outra_funcao_2; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_3 ) + { + return outra_funcao_3; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_4 ) + { + return outra_funcao_4; + } + else if( fieldName == ExameData.PROXIMO_EXAME ) + { + return proximo_exame; + } + else if( fieldName == ExameData.OUTRAS_RECOMENDACOES ) + { + return outras_recomendacoes; + } + else if( fieldName == ExameData.TRABALHADOR ) + { + return trabalhador; + } + else if( fieldName == ExameData.MEDICO ) + { + return medico; + } + else if( fieldName == ExameData.PDF ) + { + return pdf; + } + else if( fieldName == ExameData.INACTIVO ) + { + return inactivo; + } + else if( fieldName.equals( ExameData.ID ) ) + { + return id; + } + else if( fieldName.equals( ExameData.DATA ) ) + { + return data; + } + else if( fieldName.equals( ExameData.TIPO ) ) + { + return tipo; + } + else if( fieldName.equals( ExameData.OCASIONAL ) ) + { + return ocasional; + } + else if( fieldName.equals( ExameData.OUTRO_TIPO ) ) + { + return outro_tipo; + } + else if( fieldName.equals( ExameData.RESULTADO ) ) + { + return resultado; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_1 ) ) + { + return outra_funcao_1; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_2 ) ) + { + return outra_funcao_2; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_3 ) ) + { + return outra_funcao_3; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_4 ) ) + { + return outra_funcao_4; + } + else if( fieldName.equals( ExameData.PROXIMO_EXAME ) ) + { + return proximo_exame; + } + else if( fieldName.equals( ExameData.OUTRAS_RECOMENDACOES ) ) + { + return outras_recomendacoes; + } + else if( fieldName.equals( ExameData.TRABALHADOR ) ) + { + return trabalhador; + } + else if( fieldName.equals( ExameData.MEDICO ) ) + { + return medico; + } + else if( fieldName.equals( ExameData.PDF ) ) + { + return pdf; + } + else if( fieldName.equals( ExameData.INACTIVO ) ) + { + return inactivo; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == ExameData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == ExameData.DATA ) + { + data = ( Date ) value; + } + else if( fieldName == ExameData.TIPO ) + { + tipo = ( Integer ) value; + } + else if( fieldName == ExameData.OCASIONAL ) + { + ocasional = ( Integer ) value; + } + else if( fieldName == ExameData.OUTRO_TIPO ) + { + outro_tipo = ( String ) value; + } + else if( fieldName == ExameData.RESULTADO ) + { + resultado = ( Integer ) value; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_1 ) + { + outra_funcao_1 = ( String ) value; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_2 ) + { + outra_funcao_2 = ( String ) value; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_3 ) + { + outra_funcao_3 = ( String ) value; + } + else if( fieldName == ExameData.OUTRA_FUNCAO_4 ) + { + outra_funcao_4 = ( String ) value; + } + else if( fieldName == ExameData.PROXIMO_EXAME ) + { + proximo_exame = ( Date ) value; + } + else if( fieldName == ExameData.OUTRAS_RECOMENDACOES ) + { + outras_recomendacoes = ( String ) value; + } + else if( fieldName == ExameData.TRABALHADOR ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName == ExameData.MEDICO ) + { + medico = ( Medico ) value; + } + else if( fieldName == ExameData.PDF ) + { + pdf = ( byte[] ) value; + } + else if( fieldName == ExameData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( ExameData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( ExameData.DATA ) ) + { + data = ( Date ) value; + } + else if( fieldName.equals( ExameData.TIPO ) ) + { + tipo = ( Integer ) value; + } + else if( fieldName.equals( ExameData.OCASIONAL ) ) + { + ocasional = ( Integer ) value; + } + else if( fieldName.equals( ExameData.OUTRO_TIPO ) ) + { + outro_tipo = ( String ) value; + } + else if( fieldName.equals( ExameData.RESULTADO ) ) + { + resultado = ( Integer ) value; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_1 ) ) + { + outra_funcao_1 = ( String ) value; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_2 ) ) + { + outra_funcao_2 = ( String ) value; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_3 ) ) + { + outra_funcao_3 = ( String ) value; + } + else if( fieldName.equals( ExameData.OUTRA_FUNCAO_4 ) ) + { + outra_funcao_4 = ( String ) value; + } + else if( fieldName.equals( ExameData.PROXIMO_EXAME ) ) + { + proximo_exame = ( Date ) value; + } + else if( fieldName.equals( ExameData.OUTRAS_RECOMENDACOES ) ) + { + outras_recomendacoes = ( String ) value; + } + else if( fieldName.equals( ExameData.TRABALHADOR ) ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName.equals( ExameData.MEDICO ) ) + { + medico = ( Medico ) value; + } + else if( fieldName.equals( ExameData.PDF ) ) + { + pdf = ( byte[] ) value; + } + else if( fieldName.equals( ExameData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + } + + public Class getOuterClass() + { + return ExameData.class; + } +} diff --git a/trunk/siprp/data/ExameData.java b/trunk/siprp/data/ExameData.java new file mode 100644 index 00000000..2ad3f40f --- /dev/null +++ b/trunk/siprp/data/ExameData.java @@ -0,0 +1,77 @@ +/* +* ExameData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 28/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class ExameData extends JDOObject + implements DisableDeleteable +{ + public static final String ID = "id"; + public static final String DATA = "data"; + public static final String TIPO = "tipo"; + public static final String OCASIONAL = "ocasional"; + public static final String OUTRO_TIPO = "outro_tipo"; + public static final String RESULTADO = "resultado"; + public static final String OUTRA_FUNCAO_1 = "outra_funcao_1"; + public static final String OUTRA_FUNCAO_2 = "outra_funcao_2"; + public static final String OUTRA_FUNCAO_3 = "outra_funcao_3"; + public static final String OUTRA_FUNCAO_4 = "outra_funcao_4"; + public static final String PROXIMO_EXAME = "proximo_exame"; + public static final String OUTRAS_RECOMENDACOES = "outras_recomendacoes"; + public static final String TRABALHADOR = "trabalhador"; + public static final String MEDICO = "medico"; + public static final String PDF = "pdf"; + public static final String INACTIVO = "inactivo"; + + public static final String FIELD_NAMES[] = new String[]{ + DATA, TIPO, OCASIONAL, OUTRO_TIPO, RESULTADO, OUTRA_FUNCAO_1, OUTRA_FUNCAO_2, + OUTRA_FUNCAO_3, OUTRA_FUNCAO_4, PROXIMO_EXAME, OUTRAS_RECOMENDACOES, + TRABALHADOR, MEDICO, PDF, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DATA, TIPO, OCASIONAL, OUTRO_TIPO, RESULTADO, OUTRA_FUNCAO_1, OUTRA_FUNCAO_2, + OUTRA_FUNCAO_3, OUTRA_FUNCAO_4, PROXIMO_EXAME, OUTRAS_RECOMENDACOES, + TRABALHADOR, MEDICO, PDF, INACTIVO, }; + + private HashMap dataHash; + + public ExameData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Exame.class; + } +} diff --git a/trunk/siprp/data/ExameID.java b/trunk/siprp/data/ExameID.java new file mode 100644 index 00000000..3fc144de --- /dev/null +++ b/trunk/siprp/data/ExameID.java @@ -0,0 +1,22 @@ +/* +* ExameID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 28/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class ExameID extends IntegerID +{ + public ExameID() + { + } + + public ExameID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Historico.java b/trunk/siprp/data/Historico.java new file mode 100644 index 00000000..3a641ee1 --- /dev/null +++ b/trunk/siprp/data/Historico.java @@ -0,0 +1,58 @@ +/* + * Historico.java + * + * Created on 7 de Dezembro de 2004, 16:50 + */ + +package siprp.data; + +import java.text.*; +import java.util.*; + +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; + +import siprp.*; +/** + * + * @author fpalma + */ +public abstract class Historico extends JDOObject + implements ColumnizedObject +{ + protected static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT ); + + public static final String DATA = "data"; + public static final String TEXTO = "texto"; + + /** Creates a new instance of Historico */ + public Historico() + { + } + + public Object getValue(int col) + { + switch( col ) + { + case 0: + Date data = (Date) get( DATA ); + String dataStr = DATE_FORMAT.format( data ); + return dataStr; + + case 1: + String textoStr = (String ) get( TEXTO ); + if( textoStr == null ) + { + textoStr = ""; + } + textoStr = textoStr.trim(); + int index = textoStr.indexOf( "\n" ); + if( index != -1 ) + { + textoStr = textoStr.substring( 0, index ); + } + return textoStr; + } + return null; + } +} diff --git a/trunk/siprp/data/HistoricoEstabelecimento.java b/trunk/siprp/data/HistoricoEstabelecimento.java new file mode 100644 index 00000000..0bd186b8 --- /dev/null +++ b/trunk/siprp/data/HistoricoEstabelecimento.java @@ -0,0 +1,101 @@ +/* +* HistoricoEstabelecimento.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class HistoricoEstabelecimento implements JDOInnerObject +{ + private Integer id; + private Date data; + private String texto; + private Estabelecimento estabelecimento; + + public HistoricoEstabelecimento() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == HistoricoEstabelecimentoData.ID ) + { + return id; + } + else if( fieldName == HistoricoEstabelecimentoData.DATA ) + { + return data; + } + else if( fieldName == HistoricoEstabelecimentoData.TEXTO ) + { + return texto; + } + else if( fieldName == HistoricoEstabelecimentoData.ESTABELECIMENTO ) + { + return estabelecimento; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.ID ) ) + { + return id; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.DATA ) ) + { + return data; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.TEXTO ) ) + { + return texto; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.ESTABELECIMENTO ) ) + { + return estabelecimento; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == HistoricoEstabelecimentoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == HistoricoEstabelecimentoData.DATA ) + { + data = ( Date ) value; + } + else if( fieldName == HistoricoEstabelecimentoData.TEXTO ) + { + texto = ( String ) value; + } + else if( fieldName == HistoricoEstabelecimentoData.ESTABELECIMENTO ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.DATA ) ) + { + data = ( Date ) value; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.TEXTO ) ) + { + texto = ( String ) value; + } + else if( fieldName.equals( HistoricoEstabelecimentoData.ESTABELECIMENTO ) ) + { + estabelecimento = ( Estabelecimento ) value; + } + } + + public Class getOuterClass() + { + return HistoricoEstabelecimentoData.class; + } +} diff --git a/trunk/siprp/data/HistoricoEstabelecimentoData.java b/trunk/siprp/data/HistoricoEstabelecimentoData.java new file mode 100644 index 00000000..38f82221 --- /dev/null +++ b/trunk/siprp/data/HistoricoEstabelecimentoData.java @@ -0,0 +1,60 @@ +/* +* HistoricoEstabelecimentoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class HistoricoEstabelecimentoData extends Historico +{ + public static final String ID = "id"; + public static final String DATA = "data"; + public static final String TEXTO = "texto"; + public static final String ESTABELECIMENTO = "estabelecimento"; + + public static final String FIELD_NAMES[] = new String[]{ + DATA, TEXTO, ESTABELECIMENTO, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DATA, TEXTO, ESTABELECIMENTO, }; + + private HashMap dataHash; + + public HistoricoEstabelecimentoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return HistoricoEstabelecimento.class; + } +} diff --git a/trunk/siprp/data/HistoricoEstabelecimentoID.java b/trunk/siprp/data/HistoricoEstabelecimentoID.java new file mode 100644 index 00000000..1513d1bc --- /dev/null +++ b/trunk/siprp/data/HistoricoEstabelecimentoID.java @@ -0,0 +1,22 @@ +/* +* HistoricoEstabelecimentoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class HistoricoEstabelecimentoID extends IntegerID +{ + public HistoricoEstabelecimentoID() + { + } + + public HistoricoEstabelecimentoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Marcacao.java b/trunk/siprp/data/Marcacao.java new file mode 100644 index 00000000..55759225 --- /dev/null +++ b/trunk/siprp/data/Marcacao.java @@ -0,0 +1,345 @@ +/* + * Marcacao.java + * + * Created on 21 de Maio de 2004, 16:59 + */ + +package siprp.data; + +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; + +import siprp.*; +/** + * + * @author fpalma + */ +public abstract class Marcacao extends JDOObject + implements ColumnizedObject + //, JDOOperationHandlerInterface +{ + public static final int TIPO_MARCACAO_TRABALHADOR_EXAMES = 0; + public static final int TIPO_MARCACAO_TRABALHADOR_CONSULTA = 1; + public static final int TIPO_MARCACAO_ESTABELECIMENTO = 2; + public static final int TIPO_MARCACAO_EMPRESA = 3; + + public static final String DATA = "data"; + public static final String REALIZADA = "realizada"; + public static final String DATA_EMAIL = "data_email"; + public static final String DATA_RELATORIO = "data_relatorio"; + public static final String ANTECEDENCIA_AVISO = "antecedencia_aviso"; + + protected static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT ); + protected static JDOProvider JDO; + + + public static Marcacao getMarcacao( int tipo ) + { + switch( tipo ) + { + case TIPO_MARCACAO_TRABALHADOR_EXAMES: case TIPO_MARCACAO_TRABALHADOR_CONSULTA: + return new MarcacaoTrabalhadorData(); + + case TIPO_MARCACAO_ESTABELECIMENTO: + return new MarcacaoEstabelecimentoData(); + + case TIPO_MARCACAO_EMPRESA: + return new MarcacaoEmpresaData(); + } + return null; + } + + public Object getValue( int col ) + { + switch( col ) + { + case 0: + Date data = (Date) get( DATA ); + String dataStr = DATE_FORMAT.format( data ); + return dataStr; + + case 1: + String realizada = (String) get( REALIZADA ); +// if( this instanceof MarcacaoEmpresaData ) +// { +// return new Boolean( "y".equals( realizada ) ); +// } +// else +// { + + realizada = "y".equals( realizada ) ? "Sim" : "N\u00e3o"; + return realizada; +// } + + case 2: + if( this instanceof MarcacaoEmpresaData ) + { + String textoStr = (String ) get( MarcacaoEmpresaData.TEXTO ); + if( textoStr == null ) + { + textoStr = ""; + } + textoStr = textoStr.trim(); + int index = textoStr.indexOf( "\n" ); + if( index != -1 ) + { + textoStr = textoStr.substring( 0, index ); + } + return textoStr; + } + else + { + Date dataRelatorio = (Date) get( DATA_RELATORIO ); + String dataRelatorioStr = ( dataRelatorio != null ? DATE_FORMAT.format( dataRelatorio ) : "" ); + return dataRelatorioStr; + } + + default: + return null; + } + } + + public static void saveMarcacaoConsultaForTrabalhadorID( Integer trabalhadorID, Date date ) + throws Exception + { + if( date != null ) + { + date = (Date)date.clone(); + } + FichaDataProvider provider = (FichaDataProvider) FichaDataProvider.getProvider(); + if( trabalhadorID == null ) + { + return; + } + Integer marcacaoID = provider.getMarcacaoIDByTrabalhador( trabalhadorID ); + MarcacaoTrabalhadorData marcacao; + if( marcacaoID == null ) + { + marcacao = null; + } + else + { + if( JDO == null ) + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + marcacao = ( MarcacaoTrabalhadorData ) JDO.load( MarcacaoTrabalhadorData.class, marcacaoID ); + } + if( date == null && marcacao != null ) + { + marcacao.delete(); + } + else if( date != null && marcacao != null ) + { + marcacao.set( Marcacao.DATA, date ); + marcacao.save(); + } + else if( date != null && marcacao == null ) + { + marcacao = new MarcacaoTrabalhadorData(); + if( JDO == null ) + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + TrabalhadorData trab = (TrabalhadorData)JDO.load( TrabalhadorData.class, trabalhadorID ); + marcacao.set( MarcacaoTrabalhadorData.TRABALHADOR, trab ); + marcacao.set( MarcacaoTrabalhadorData.TIPO, new Integer( MarcacaoTrabalhadorData.TIPO_CONSULTA ) ); + marcacao.set( Marcacao.DATA, date ); + marcacao.set( Marcacao.REALIZADA, "n" ); + marcacao.set( MarcacaoTrabalhadorData.ESTADO, new Integer( siprp.medicina.MedicinaDataProvider.ESTADO_POR_REALIZAR ) ); + marcacao.set( MarcacaoTrabalhadorData.MOTIVO, new Integer( 2 ) ); + marcacao.save(); + } + } +// +// public boolean handle( JDOObject object, int operation, int moment ) +// throws Exception +// { +// switch( operation ) +// { +// case JDOOperationHandlerInterface.OP_SAVE: +// switch( moment ) +// { +// case JDOOperationHandlerInterface.MOMENT_BEFORE: +// return preSave( (Marcacao) object ); +// +// case JDOOperationHandlerInterface.MOMENT_AFTER: +// return postSave( (Marcacao) object ); +// } +// return false; +// +// case JDOOperationHandlerInterface.OP_DELETE: +// switch( moment ) +// { +// case JDOOperationHandlerInterface.MOMENT_BEFORE: +// return preDelete( (Marcacao) object ); +// +// case JDOOperationHandlerInterface.MOMENT_AFTER: +// return postDelete( (Marcacao) object ); +// } +// return false; +// } +// return false; +// } +// +// protected boolean preSave( Marcacao object ) +// throws Exception +// { +// return false; +// } +// +// protected boolean postSave( Marcacao object ) +// throws Exception +// { +// if( object instanceof MarcacaoEmpresaData ) +// { +// AvisoData aviso = (AvisoData) load( AvisoData.class, new Object[]{ get( MarcacaoEmpresaData.ID ), new Integer( AvisoData.TIPO_EMPRESA ) }, new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); +// if( aviso == null ) +// { +// aviso = new AvisoData(); +// } +// aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_EMPRESA ) ); +// EmpresaData empresa = ( EmpresaData ) object.get( MarcacaoEmpresaData.EMPRESA ); +// aviso.set( AvisoData.EMPRESA, empresa ); +// aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoEmpresaData.ID ) ); +// Date dataEvento = (Date) object.get( DATA ); +// aviso.set( AvisoData.DATA_EVENTO, dataEvento ); +// aviso.set( AvisoData.DATA_AVISO, dataEvento ); +// String descricao = "Tarefa "; +// aviso.set( AvisoData.DESCRICAO, descricao ); +// aviso.save(); +// } +// else if( object instanceof MarcacaoEstabelecimentoData ) +// { +// AvisoData aviso = (AvisoData) load( AvisoData.class, new Object[]{ get( MarcacaoEstabelecimentoData.ID ), new Integer( AvisoData.TIPO_ESTABELECIMENTO ) }, new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); +// if( aviso == null ) +// { +// aviso = new AvisoData(); +// } +// aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_ESTABELECIMENTO ) ); +// EstabelecimentoData estabelecimento = ( EstabelecimentoData ) object.get( MarcacaoEstabelecimentoData.ESTABELECIMENTO ); +// aviso.set( AvisoData.ESTABELECIMENTO, estabelecimento ); +// EmpresaData empresa = ( EmpresaData )estabelecimento.get( EstabelecimentoData.EMPRESA ); +// aviso.set( AvisoData.EMPRESA, empresa ); +// aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoEstabelecimentoData.ID ) ); +// Date dataEvento = (Date) object.get( DATA ); +// Date dataAviso = new Date( dataEvento.getTime() ); +// Calendar cal = Calendar.getInstance(); +// cal.setTime( dataAviso ); +// cal.add( Calendar.DAY_OF_MONTH, -14 ); +// dataAviso = cal.getTime(); +// aviso.set( AvisoData.DATA_AVISO, dataAviso ); +// aviso.set( AvisoData.DATA_EVENTO, dataEvento ); +// String descricao = "Visita "; +// aviso.set( AvisoData.DESCRICAO, descricao ); +// cal = Calendar.getInstance(); +// cal.setTime( dataEvento ); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// dataEvento = cal.getTime(); +// +// cal = Calendar.getInstance(); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// Date hoje = cal.getTime(); +// if( hoje.before( dataEvento ) ) +// { +// aviso.save(); +// } +// } +// if( object instanceof MarcacaoTrabalhadorData ) +// { +// AvisoData aviso = (AvisoData) load( AvisoData.class, new Object[]{ object.get( MarcacaoTrabalhadorData.ID ), new Integer( AvisoData.TIPO_TRABALHADOR ) }, new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); +// if( aviso == null ) +// { +// aviso = new AvisoData(); +// } +// aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_TRABALHADOR ) ); +// TrabalhadorData trab = ( TrabalhadorData ) object.get( MarcacaoTrabalhadorData.TRABALHADOR ); +// aviso.set( AvisoData.TRABALHADOR, trab ); +// EstabelecimentoData estabelecimento = ( EstabelecimentoData ) trab.get( TrabalhadorData.ESTABELECIMENTO ); +// aviso.set( AvisoData.ESTABELECIMENTO, estabelecimento ); +// EmpresaData empresa = ( EmpresaData ) estabelecimento.get( EstabelecimentoData.EMPRESA ); +// aviso.set( AvisoData.EMPRESA, empresa ); +// aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoTrabalhadorData.ID ) ); +// Date dataEvento = (Date) object.get( DATA ); +// Date dataAviso = new Date( dataEvento.getTime() ); +// Calendar cal = Calendar.getInstance(); +// cal.setTime( dataAviso ); +// cal.add( Calendar.DAY_OF_MONTH, -14 ); +// dataAviso = cal.getTime(); +// aviso.set( AvisoData.DATA_AVISO, dataAviso ); +// aviso.set( AvisoData.DATA_EVENTO, dataEvento ); +// String descricao = ""; +// switch( ( ( Integer ) object.get( MarcacaoTrabalhadorData.TIPO ) ).intValue() ) +// { +// case MarcacaoTrabalhadorData.TIPO_EXAMES: +// descricao = "Exames "; +// break; +// +// case MarcacaoTrabalhadorData.TIPO_CONSULTA: +// descricao = "Consulta "; +// break; +// } +// aviso.set( AvisoData.DESCRICAO, descricao ); +// cal = Calendar.getInstance(); +// cal.setTime( dataEvento ); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// dataEvento = cal.getTime(); +// +// cal = Calendar.getInstance(); +// cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 ); +// cal.set( Calendar.MILLISECOND, 0 ); +// Date hoje = cal.getTime(); +// if( hoje.before( dataEvento ) ) +// { +// aviso.save(); +// } +// } +// else +// { +// return false; +// } +// return true; +// } +// +// protected boolean preDelete( Marcacao object ) +// throws Exception +// { +// return false; +// } +// +// protected boolean postDelete( Marcacao object ) +// throws Exception +// { +// Integer tipo; +// if( object instanceof MarcacaoEmpresaData ) +// { +// tipo = new Integer( AvisoData.TIPO_EMPRESA ); +// } +// else if( object instanceof MarcacaoEstabelecimentoData ) +// { +// tipo = new Integer( AvisoData.TIPO_ESTABELECIMENTO ); +// } +// if( object instanceof MarcacaoTrabalhadorData ) +// { +// tipo = new Integer( AvisoData.TIPO_TRABALHADOR ); +// } +// else +// { +// return false; +// } +// AvisoData aviso = (AvisoData) load( AvisoData.class, new Object[]{ object.get( "id" ), tipo }, new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); +// if( aviso != null ) +// { +// aviso.delete(); +// } +// +// return true; +// } +} diff --git a/trunk/siprp/data/MarcacaoEmpresa.java b/trunk/siprp/data/MarcacaoEmpresa.java new file mode 100644 index 00000000..1f32cac8 --- /dev/null +++ b/trunk/siprp/data/MarcacaoEmpresa.java @@ -0,0 +1,118 @@ +/* +* MarcacaoEmpresa.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class MarcacaoEmpresa implements JDOInnerObject +{ + private Integer id; + private Date data; + private String texto; + private String realizada; + private Empresa empresa; + + public MarcacaoEmpresa() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == MarcacaoEmpresaData.ID ) + { + return id; + } + else if( fieldName == MarcacaoEmpresaData.DATA ) + { + return data; + } + else if( fieldName == MarcacaoEmpresaData.TEXTO ) + { + return texto; + } + else if( fieldName == MarcacaoEmpresaData.REALIZADA ) + { + return realizada; + } + else if( fieldName == MarcacaoEmpresaData.EMPRESA ) + { + return empresa; + } + else if( fieldName.equals( MarcacaoEmpresaData.ID ) ) + { + return id; + } + else if( fieldName.equals( MarcacaoEmpresaData.DATA ) ) + { + return data; + } + else if( fieldName.equals( MarcacaoEmpresaData.TEXTO ) ) + { + return texto; + } + else if( fieldName.equals( MarcacaoEmpresaData.REALIZADA ) ) + { + return realizada; + } + else if( fieldName.equals( MarcacaoEmpresaData.EMPRESA ) ) + { + return empresa; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == MarcacaoEmpresaData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == MarcacaoEmpresaData.DATA ) + { + data = ( Date ) value; + } + else if( fieldName == MarcacaoEmpresaData.TEXTO ) + { + texto = ( String ) value; + } + else if( fieldName == MarcacaoEmpresaData.REALIZADA ) + { + realizada = ( String ) value; + } + else if( fieldName == MarcacaoEmpresaData.EMPRESA ) + { + empresa = ( Empresa ) value; + } + else if( fieldName.equals( MarcacaoEmpresaData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoEmpresaData.DATA ) ) + { + data = ( Date ) value; + } + else if( fieldName.equals( MarcacaoEmpresaData.TEXTO ) ) + { + texto = ( String ) value; + } + else if( fieldName.equals( MarcacaoEmpresaData.REALIZADA ) ) + { + realizada = ( String ) value; + } + else if( fieldName.equals( MarcacaoEmpresaData.EMPRESA ) ) + { + empresa = ( Empresa ) value; + } + } + + public Class getOuterClass() + { + return MarcacaoEmpresaData.class; + } +} diff --git a/trunk/siprp/data/MarcacaoEmpresaData.java b/trunk/siprp/data/MarcacaoEmpresaData.java new file mode 100644 index 00000000..54921f1f --- /dev/null +++ b/trunk/siprp/data/MarcacaoEmpresaData.java @@ -0,0 +1,61 @@ +/* +* MarcacaoEmpresaData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class MarcacaoEmpresaData extends Marcacao +{ + public static final String ID = "id"; + public static final String DATA = "data"; + public static final String TEXTO = "texto"; + public static final String REALIZADA = "realizada"; + public static final String EMPRESA = "empresa"; + + public static final String FIELD_NAMES[] = new String[]{ + DATA, TEXTO, REALIZADA, EMPRESA, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DATA, TEXTO, REALIZADA, EMPRESA, }; + + private HashMap dataHash; + + public MarcacaoEmpresaData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return MarcacaoEmpresa.class; + } +} diff --git a/trunk/siprp/data/MarcacaoEmpresaID.java b/trunk/siprp/data/MarcacaoEmpresaID.java new file mode 100644 index 00000000..8b074d13 --- /dev/null +++ b/trunk/siprp/data/MarcacaoEmpresaID.java @@ -0,0 +1,22 @@ +/* +* MarcacaoEmpresaID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 7/Dez/2004 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class MarcacaoEmpresaID extends IntegerID +{ + public MarcacaoEmpresaID() + { + } + + public MarcacaoEmpresaID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/MarcacaoEstabelecimento.java b/trunk/siprp/data/MarcacaoEstabelecimento.java new file mode 100644 index 00000000..16f5fca4 --- /dev/null +++ b/trunk/siprp/data/MarcacaoEstabelecimento.java @@ -0,0 +1,186 @@ +/* +* MarcacaoEstabelecimento.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class MarcacaoEstabelecimento implements JDOInnerObject +{ + private Integer id; + private Date data; + private String realizada; + private Integer estado; + private Integer tecnico_hst; + private Date data_email; + private Date data_relatorio; + private Estabelecimento estabelecimento; + private String observacoes; + + public MarcacaoEstabelecimento() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == MarcacaoEstabelecimentoData.ID ) + { + return id; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA ) + { + return data; + } + else if( fieldName == MarcacaoEstabelecimentoData.REALIZADA ) + { + return realizada; + } + else if( fieldName == MarcacaoEstabelecimentoData.ESTADO ) + { + return estado; + } + else if( fieldName == MarcacaoEstabelecimentoData.TECNICO_HST ) + { + return tecnico_hst; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA_EMAIL ) + { + return data_email; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA_RELATORIO ) + { + return data_relatorio; + } + else if( fieldName == MarcacaoEstabelecimentoData.ESTABELECIMENTO ) + { + return estabelecimento; + } + else if( fieldName == MarcacaoEstabelecimentoData.OBSERVACOES ) + { + return observacoes; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ID ) ) + { + return id; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA ) ) + { + return data; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.REALIZADA ) ) + { + return realizada; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ESTADO ) ) + { + return estado; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.TECNICO_HST ) ) + { + return tecnico_hst; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA_EMAIL ) ) + { + return data_email; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA_RELATORIO ) ) + { + return data_relatorio; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ESTABELECIMENTO ) ) + { + return estabelecimento; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.OBSERVACOES ) ) + { + return observacoes; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == MarcacaoEstabelecimentoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA ) + { + data = ( Date ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.REALIZADA ) + { + realizada = ( String ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.ESTADO ) + { + estado = ( Integer ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.TECNICO_HST ) + { + tecnico_hst = ( Integer ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA_EMAIL ) + { + data_email = ( Date ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.DATA_RELATORIO ) + { + data_relatorio = ( Date ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.ESTABELECIMENTO ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName == MarcacaoEstabelecimentoData.OBSERVACOES ) + { + observacoes = ( String ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA ) ) + { + data = ( Date ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.REALIZADA ) ) + { + realizada = ( String ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ESTADO ) ) + { + estado = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.TECNICO_HST ) ) + { + tecnico_hst = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA_EMAIL ) ) + { + data_email = ( Date ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.DATA_RELATORIO ) ) + { + data_relatorio = ( Date ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.ESTABELECIMENTO ) ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName.equals( MarcacaoEstabelecimentoData.OBSERVACOES ) ) + { + observacoes = ( String ) value; + } + } + + public Class getOuterClass() + { + return MarcacaoEstabelecimentoData.class; + } +} diff --git a/trunk/siprp/data/MarcacaoEstabelecimentoData.java b/trunk/siprp/data/MarcacaoEstabelecimentoData.java new file mode 100644 index 00000000..4c8551ca --- /dev/null +++ b/trunk/siprp/data/MarcacaoEstabelecimentoData.java @@ -0,0 +1,67 @@ +/* +* MarcacaoEstabelecimentoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class MarcacaoEstabelecimentoData extends Marcacao +{ + public static final String ID = "id"; + public static final String DATA = "data"; + public static final String REALIZADA = "realizada"; + public static final String ESTADO = "estado"; + public static final String TECNICO_HST = "tecnico_hst"; + public static final String DATA_EMAIL = "data_email"; + public static final String DATA_RELATORIO = "data_relatorio"; + public static final String ESTABELECIMENTO = "estabelecimento"; + public static final String OBSERVACOES = "observacoes"; + + public static final String FIELD_NAMES[] = new String[]{ + DATA, REALIZADA, ESTADO, TECNICO_HST, DATA_EMAIL, DATA_RELATORIO, ESTABELECIMENTO, + OBSERVACOES, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DATA, REALIZADA, ESTADO, TECNICO_HST, DATA_EMAIL, DATA_RELATORIO, + ESTABELECIMENTO, OBSERVACOES, }; + + private HashMap dataHash; + + public MarcacaoEstabelecimentoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return MarcacaoEstabelecimento.class; + } +} diff --git a/trunk/siprp/data/MarcacaoEstabelecimentoID.java b/trunk/siprp/data/MarcacaoEstabelecimentoID.java new file mode 100644 index 00000000..36240581 --- /dev/null +++ b/trunk/siprp/data/MarcacaoEstabelecimentoID.java @@ -0,0 +1,25 @@ +/* +* MarcacaoEstabelecimentoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class MarcacaoEstabelecimentoID extends IntegerID + implements Serializable +{ + public MarcacaoEstabelecimentoID() + { + } + + public MarcacaoEstabelecimentoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/MarcacaoListLoader.java b/trunk/siprp/data/MarcacaoListLoader.java new file mode 100644 index 00000000..c966c222 --- /dev/null +++ b/trunk/siprp/data/MarcacaoListLoader.java @@ -0,0 +1,80 @@ +/* + * MarcacaoListLoader.java + * + * Created on 27 de Maio de 2004, 16:18 + */ + +package siprp.data; + +import javax.jdo.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.jdo.*; + +import siprp.*; +/** + * + * @author fpalma + */ +public class MarcacaoListLoader +{ +// private static PersistenceManager MANAGER = null; + private JDOProvider JDO; + + /** Creates a new instance of MarcacaoListLoader */ + public MarcacaoListLoader() + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + + public Marcacao[] load( int tipo, Integer targetID ) + throws Exception + { + Class theClass; + String filterString; + switch( tipo ) + { + case Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES: case Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA: + theClass = MarcacaoTrabalhador.class; + filterString = "(trabalhador.id == " + targetID + ") && (tipo == " + tipo + ")"; + break; + + case Marcacao.TIPO_MARCACAO_ESTABELECIMENTO: + theClass = MarcacaoEstabelecimento.class; + filterString = "estabelecimento.id == " + targetID; + break; + + default: + return new Marcacao[ 0 ]; + } +// if( MANAGER == null ) +// { +// MANAGER = (PersistenceManager) Singleton.getInstance( SingletonConstants.PERSISTENCE_MANAGER ); +// } +// Transaction tx = MANAGER.currentTransaction(); + Object sessionID = null; + try + { + sessionID = JDO.begin(); + Query q = JDO.getManager().newQuery( theClass, filterString ); + q.setOrdering( Marcacao.DATA + " descending" ); + Collection c = ( Collection )q.execute(); + JDOInnerObject innerObjects[] = ( JDOInnerObject [] ) c.toArray( new JDOInnerObject[0] ); + JDO.commit( sessionID ); + Marcacao marcacoes[] = new Marcacao[ innerObjects.length ]; + for( int n = 0; n < marcacoes.length; n++ ) + { + marcacoes[ n ] = ( Marcacao ) innerObjects[ n ].getOuterClass().newInstance(); + marcacoes[ n ].setInnerObject( innerObjects[ n ] ); + } + return marcacoes; + } + catch( RuntimeException ex ) + { + JDO.rollback( sessionID ); +// Main.reconnectJDO(); + throw ex; + } + } +} diff --git a/trunk/siprp/data/MarcacaoSaveAndDeleteHandler.java b/trunk/siprp/data/MarcacaoSaveAndDeleteHandler.java new file mode 100644 index 00000000..52ce02e5 --- /dev/null +++ b/trunk/siprp/data/MarcacaoSaveAndDeleteHandler.java @@ -0,0 +1,258 @@ +/* +* MarcacaoSaveAndDeleteHandler.java + * + * Created on 13 de Outubro de 2004, 18:31 + */ + +package siprp.data; + +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.jdo.*; + +import siprp.medicina.*; + +/** + * + * @author fpalma + */ +public class MarcacaoSaveAndDeleteHandler + implements JDOOperationHandlerInterface +{ + public static final MarcacaoSaveAndDeleteHandler INSTANCE = new MarcacaoSaveAndDeleteHandler(); + + public JDOProvider JDO; + protected MedicinaDataProvider medicinaProvider; + + /** Creates a new instance of MarcacaoSaveAndDeleteHandler */ + public MarcacaoSaveAndDeleteHandler() + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + + public boolean handle( JDOObject object, int operation, int moment ) + throws Exception + { + if( JDO == null ) + { + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + } + switch( operation ) + { + case JDOOperationHandlerInterface.OP_SAVE: + switch( moment ) + { + case JDOOperationHandlerInterface.MOMENT_BEFORE: + return preSave( (Marcacao) object ); + + case JDOOperationHandlerInterface.MOMENT_AFTER: + return postSave( (Marcacao) object ); + } + return false; + + case JDOOperationHandlerInterface.OP_DELETE: + switch( moment ) + { + case JDOOperationHandlerInterface.MOMENT_BEFORE: + return preDelete( (Marcacao) object ); + + case JDOOperationHandlerInterface.MOMENT_AFTER: + return postDelete( (Marcacao) object ); + } + return false; + } + return false; + } + + protected boolean preSave( Marcacao object ) + throws Exception + { + return false; + } + + protected boolean postSave( Marcacao object ) + throws Exception + { + if( object instanceof MarcacaoEmpresaData ) + { + AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, + new Object[]{ object.get( MarcacaoEmpresaData.ID ), new Integer( AvisoData.TIPO_EMPRESA ) }, + new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); + if( aviso == null ) + { + aviso = new AvisoData(); + } + aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_EMPRESA ) ); + EmpresaData empresa = ( EmpresaData ) object.get( MarcacaoEmpresaData.EMPRESA ); + aviso.set( AvisoData.EMPRESA, empresa ); + aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoEmpresaData.ID ) ); + Date dataEvento = (Date) object.get( Marcacao.DATA ); + aviso.set( AvisoData.DATA_EVENTO, dataEvento ); + aviso.set( AvisoData.DATA_AVISO, dataEvento ); + String descricao = "Tarefa "; + aviso.set( AvisoData.DESCRICAO, descricao ); + aviso.save(); + + empresa.save(); + } + else if( object instanceof MarcacaoEstabelecimentoData ) + { + AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, + new Object[]{ object.get( MarcacaoEstabelecimentoData.ID ), new Integer( AvisoData.TIPO_ESTABELECIMENTO ) }, + new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); + if( aviso == null ) + { + aviso = new AvisoData(); + } + aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_ESTABELECIMENTO ) ); + EstabelecimentoData estabelecimento = ( EstabelecimentoData ) object.get( MarcacaoEstabelecimentoData.ESTABELECIMENTO ); + aviso.set( AvisoData.ESTABELECIMENTO, estabelecimento ); + EmpresaData empresa = ( EmpresaData )estabelecimento.get( EstabelecimentoData.EMPRESA ); + aviso.set( AvisoData.EMPRESA, empresa ); + aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoEstabelecimentoData.ID ) ); + Date dataEvento = (Date) object.get( Marcacao.DATA ); + Date dataAviso = new Date( dataEvento.getTime() ); + Calendar cal = Calendar.getInstance(); + cal.setTime( dataAviso ); + cal.add( Calendar.DAY_OF_MONTH, -14 ); + dataAviso = cal.getTime(); + aviso.set( AvisoData.DATA_AVISO, dataAviso ); + aviso.set( AvisoData.DATA_EVENTO, dataEvento ); + String descricao = "Visita "; + aviso.set( AvisoData.DESCRICAO, descricao ); + cal = Calendar.getInstance(); + cal.setTime( dataEvento ); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + dataEvento = cal.getTime(); + + cal = Calendar.getInstance(); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + Date hoje = cal.getTime(); + if( hoje.before( dataEvento ) ) + { + aviso.save(); + } + + estabelecimento.save(); + } + if( object instanceof MarcacaoTrabalhadorData ) + { + AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, + new Object[]{ object.get( MarcacaoTrabalhadorData.ID ), new Integer( AvisoData.TIPO_TRABALHADOR ) }, + new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); + System.out.println( "AVISO LOADED: " + aviso + " id: " + ( aviso != null ? aviso.get( AvisoData.ID ) : "n/a" ) + + " MT.ID: " + object.get( MarcacaoTrabalhadorData.ID ) + + " AD.TIPO: " + new Integer( AvisoData.TIPO_TRABALHADOR ) ); + if( aviso == null ) + { + System.out.println( "novo aviso" ); + aviso = new AvisoData(); + } + aviso.set( AvisoData.TIPO, new Integer( AvisoData.TIPO_TRABALHADOR ) ); + TrabalhadorData trab = ( TrabalhadorData ) object.get( MarcacaoTrabalhadorData.TRABALHADOR ); + aviso.set( AvisoData.TRABALHADOR, trab ); + EstabelecimentoData estabelecimento = ( EstabelecimentoData ) trab.get( TrabalhadorData.ESTABELECIMENTO ); + aviso.set( AvisoData.ESTABELECIMENTO, estabelecimento ); + EmpresaData empresa = ( EmpresaData ) estabelecimento.get( EstabelecimentoData.EMPRESA ); + aviso.set( AvisoData.EMPRESA, empresa ); + aviso.set( AvisoData.EVENTO_ID, object.get( MarcacaoTrabalhadorData.ID ) ); + Date dataEvento = (Date) object.get( Marcacao.DATA ); + Date dataAviso = new Date( dataEvento.getTime() ); + Calendar cal = Calendar.getInstance(); + cal.setTime( dataAviso ); + cal.add( Calendar.DAY_OF_MONTH, -14 ); + dataAviso = cal.getTime(); + aviso.set( AvisoData.DATA_AVISO, dataAviso ); + aviso.set( AvisoData.DATA_EVENTO, dataEvento.clone() ); + String descricao = ""; + switch( ( ( Integer ) object.get( MarcacaoTrabalhadorData.TIPO ) ).intValue() ) + { + case MarcacaoTrabalhadorData.TIPO_EXAMES: + descricao = "Exames"; + break; + + case MarcacaoTrabalhadorData.TIPO_CONSULTA: + Integer motivo = ( ( Integer ) object.get( MarcacaoTrabalhadorData.MOTIVO ) ); + descricao = "Consulta " + ( motivo == null ? "" : ("(" + MedicinaDataProvider.TIPOS_CONSULTAS[ motivo.intValue() ] + ")" ) ); + break; + } + aviso.set( AvisoData.DESCRICAO, descricao ); + cal = Calendar.getInstance(); + cal.setTime( dataEvento ); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 0, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + dataEvento = cal.getTime(); + + cal = Calendar.getInstance(); + cal.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DAY_OF_MONTH ), 10, 0, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + Date hoje = cal.getTime(); + if( hoje.before( dataEvento ) ) + { + if( !hoje.before( dataAviso ) ) + { + aviso.set( AvisoData.DATA_AVISO, dataEvento.clone() ); + } + aviso.save(); + } + + trab.save(); + } + else + { + return false; + } + return true; + } + + protected boolean preDelete( Marcacao object ) + throws Exception + { + if( object instanceof MarcacaoTrabalhadorData && + ( ( Integer ) object.get( MarcacaoTrabalhadorData.TIPO ) ).intValue() == MarcacaoTrabalhadorData.TIPO_EXAMES ) + { + if( medicinaProvider == null ) + { + medicinaProvider = (MedicinaDataProvider)MedicinaDataProvider.getProvider(); + } + medicinaProvider.deleteDetalhesRealziadosForMarcacao( ( Integer ) object.get( MarcacaoTrabalhadorData.ID ) ); + return true; + } + return false; + } + + protected boolean postDelete( Marcacao object ) + throws Exception + { +System.out.println( "!delete!" ); + Integer tipo; + if( object instanceof MarcacaoEmpresaData ) + { + tipo = new Integer( AvisoData.TIPO_EMPRESA ); + } + else if( object instanceof MarcacaoEstabelecimentoData ) + { + tipo = new Integer( AvisoData.TIPO_ESTABELECIMENTO ); + } + if( object instanceof MarcacaoTrabalhadorData ) + { + tipo = new Integer( AvisoData.TIPO_TRABALHADOR ); + } + else + { + return false; + } + AvisoData aviso = (AvisoData) JDO.load( AvisoData.class, + new Object[]{ object.get( "id" ), tipo }, + new String[]{ AvisoData.EVENTO_ID, AvisoData.TIPO } ); + if( aviso != null ) + { + aviso.delete(); + } + + return true; + } +} diff --git a/trunk/siprp/data/MarcacaoTrabalhador.java b/trunk/siprp/data/MarcacaoTrabalhador.java new file mode 100644 index 00000000..a4af4d07 --- /dev/null +++ b/trunk/siprp/data/MarcacaoTrabalhador.java @@ -0,0 +1,203 @@ +/* +* MarcacaoTrabalhador.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Jan 28, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class MarcacaoTrabalhador implements JDOInnerObject +{ + private Integer id; + private Date data; + private String realizada; + private Integer estado; + private Integer motivo; + private Date data_email; + private Date data_relatorio; + private Integer tipo; + private Trabalhador trabalhador; + private String observacoes; + + public MarcacaoTrabalhador() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == MarcacaoTrabalhadorData.ID ) + { + return id; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA ) + { + return data; + } + else if( fieldName == MarcacaoTrabalhadorData.REALIZADA ) + { + return realizada; + } + else if( fieldName == MarcacaoTrabalhadorData.ESTADO ) + { + return estado; + } + else if( fieldName == MarcacaoTrabalhadorData.MOTIVO ) + { + return motivo; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA_EMAIL ) + { + return data_email; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA_RELATORIO ) + { + return data_relatorio; + } + else if( fieldName == MarcacaoTrabalhadorData.TIPO ) + { + return tipo; + } + else if( fieldName == MarcacaoTrabalhadorData.TRABALHADOR ) + { + return trabalhador; + } + else if( fieldName == MarcacaoTrabalhadorData.OBSERVACOES ) + { + return observacoes; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.ID ) ) + { + return id; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA ) ) + { + return data; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.REALIZADA ) ) + { + return realizada; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.ESTADO ) ) + { + return estado; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.MOTIVO ) ) + { + return motivo; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA_EMAIL ) ) + { + return data_email; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA_RELATORIO ) ) + { + return data_relatorio; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.TIPO ) ) + { + return tipo; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.TRABALHADOR ) ) + { + return trabalhador; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.OBSERVACOES ) ) + { + return observacoes; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == MarcacaoTrabalhadorData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA ) + { + data = ( Date ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.REALIZADA ) + { + realizada = ( String ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.ESTADO ) + { + estado = ( Integer ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.MOTIVO ) + { + motivo = ( Integer ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA_EMAIL ) + { + data_email = ( Date ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.DATA_RELATORIO ) + { + data_relatorio = ( Date ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.TIPO ) + { + tipo = ( Integer ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.TRABALHADOR ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName == MarcacaoTrabalhadorData.OBSERVACOES ) + { + observacoes = ( String ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA ) ) + { + data = ( Date ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.REALIZADA ) ) + { + realizada = ( String ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.ESTADO ) ) + { + estado = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.MOTIVO ) ) + { + motivo = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA_EMAIL ) ) + { + data_email = ( Date ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.DATA_RELATORIO ) ) + { + data_relatorio = ( Date ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.TIPO ) ) + { + tipo = ( Integer ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.TRABALHADOR ) ) + { + trabalhador = ( Trabalhador ) value; + } + else if( fieldName.equals( MarcacaoTrabalhadorData.OBSERVACOES ) ) + { + observacoes = ( String ) value; + } + } + + public Class getOuterClass() + { + return MarcacaoTrabalhadorData.class; + } +} diff --git a/trunk/siprp/data/MarcacaoTrabalhadorConstants.java b/trunk/siprp/data/MarcacaoTrabalhadorConstants.java new file mode 100644 index 00000000..e0096a87 --- /dev/null +++ b/trunk/siprp/data/MarcacaoTrabalhadorConstants.java @@ -0,0 +1,17 @@ +/* + * MarcacaoTrabalhadorConstants.java + * + * Created on 11 de Outubro de 2004, 13:18 + */ + +package siprp.data; + +/** + * + * @author fpalma + */ +public interface MarcacaoTrabalhadorConstants +{ + public static final int TIPO_EXAMES = 0; + public static final int TIPO_CONSULTA = 1; +} diff --git a/trunk/siprp/data/MarcacaoTrabalhadorData.java b/trunk/siprp/data/MarcacaoTrabalhadorData.java new file mode 100644 index 00000000..67273b67 --- /dev/null +++ b/trunk/siprp/data/MarcacaoTrabalhadorData.java @@ -0,0 +1,69 @@ +/* +* MarcacaoTrabalhadorData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Jan 28, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class MarcacaoTrabalhadorData extends Marcacao + implements MarcacaoTrabalhadorConstants +{ + public static final String ID = "id"; + public static final String DATA = "data"; + public static final String REALIZADA = "realizada"; + public static final String ESTADO = "estado"; + public static final String MOTIVO = "motivo"; + public static final String DATA_EMAIL = "data_email"; + public static final String DATA_RELATORIO = "data_relatorio"; + public static final String TIPO = "tipo"; + public static final String TRABALHADOR = "trabalhador"; + public static final String OBSERVACOES = "observacoes"; + + public static final String FIELD_NAMES[] = new String[]{ + DATA, REALIZADA, ESTADO, MOTIVO, DATA_EMAIL, DATA_RELATORIO, TIPO, TRABALHADOR, + OBSERVACOES, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, DATA, REALIZADA, ESTADO, MOTIVO, DATA_EMAIL, DATA_RELATORIO, TIPO, TRABALHADOR, + OBSERVACOES, }; + + private HashMap dataHash; + + public MarcacaoTrabalhadorData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return MarcacaoTrabalhador.class; + } +} diff --git a/trunk/siprp/data/MarcacaoTrabalhadorID.java b/trunk/siprp/data/MarcacaoTrabalhadorID.java new file mode 100644 index 00000000..7dc15955 --- /dev/null +++ b/trunk/siprp/data/MarcacaoTrabalhadorID.java @@ -0,0 +1,25 @@ +/* +* MarcacaoTrabalhadorID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on Jan 28, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class MarcacaoTrabalhadorID extends IntegerID + implements Serializable +{ + public MarcacaoTrabalhadorID() + { + } + + public MarcacaoTrabalhadorID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Medico.java b/trunk/siprp/data/Medico.java new file mode 100644 index 00000000..a9c4785e --- /dev/null +++ b/trunk/siprp/data/Medico.java @@ -0,0 +1,100 @@ +/* +* Medico.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 27/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.*; + +public final class Medico implements JDOInnerObject +{ + private Integer id; + private String nome; + private String numero_cedula; + private String inactivo; + + public Medico() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == MedicoData.ID ) + { + return id; + } + else if( fieldName == MedicoData.NOME ) + { + return nome; + } + else if( fieldName == MedicoData.NUMERO_CEDULA ) + { + return numero_cedula; + } + else if( fieldName == MedicoData.INACTIVO ) + { + return inactivo; + } + else if( fieldName.equals( MedicoData.ID ) ) + { + return id; + } + else if( fieldName.equals( MedicoData.NOME ) ) + { + return nome; + } + else if( fieldName.equals( MedicoData.NUMERO_CEDULA ) ) + { + return numero_cedula; + } + else if( fieldName.equals( MedicoData.INACTIVO ) ) + { + return inactivo; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == MedicoData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == MedicoData.NOME ) + { + nome = ( String ) value; + } + else if( fieldName == MedicoData.NUMERO_CEDULA ) + { + numero_cedula = ( String ) value; + } + else if( fieldName == MedicoData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( MedicoData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( MedicoData.NOME ) ) + { + nome = ( String ) value; + } + else if( fieldName.equals( MedicoData.NUMERO_CEDULA ) ) + { + numero_cedula = ( String ) value; + } + else if( fieldName.equals( MedicoData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + } + + public Class getOuterClass() + { + return MedicoData.class; + } +} diff --git a/trunk/siprp/data/MedicoData.java b/trunk/siprp/data/MedicoData.java new file mode 100644 index 00000000..6e385ce8 --- /dev/null +++ b/trunk/siprp/data/MedicoData.java @@ -0,0 +1,61 @@ +/* +* MedicoData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 27/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class MedicoData extends JDOObject + implements DisableDeleteable +{ + public static final String ID = "id"; + public static final String NOME = "nome"; + public static final String NUMERO_CEDULA = "numero_cedula"; + public static final String INACTIVO = "inactivo"; + + public static final String FIELD_NAMES[] = new String[]{ + NOME, NUMERO_CEDULA, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, NOME, NUMERO_CEDULA, INACTIVO, }; + + private HashMap dataHash; + + public MedicoData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Medico.class; + } +} diff --git a/trunk/siprp/data/MedicoID.java b/trunk/siprp/data/MedicoID.java new file mode 100644 index 00000000..8c13efb7 --- /dev/null +++ b/trunk/siprp/data/MedicoID.java @@ -0,0 +1,22 @@ +/* +* MedicoID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 27/Jan/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.jpox.*; + +public final class MedicoID extends IntegerID +{ + public MedicoID() + { + } + + public MedicoID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/SearchExecuterFactory.java b/trunk/siprp/data/SearchExecuterFactory.java new file mode 100644 index 00000000..e011144d --- /dev/null +++ b/trunk/siprp/data/SearchExecuterFactory.java @@ -0,0 +1,180 @@ +/* + * SearchExecuterFactory.java + * + * Created on 24 de Maio de 2004, 19:30 + */ + +package siprp.data; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.db.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.ui.search.*; + +/** + * + * @author fpalma + */ +public class SearchExecuterFactory +{ + private static SearchExecuter empresaExecuter; + private static SearchExecuter estabelecimentoExecuter; + private static SearchExecuter trabalhadorExecuter; + + + + /** Creates a new instance of SearchExecuterFactory */ + private SearchExecuterFactory() + { + } + + public static SearchExecuter getSearchExecuter( Class objectClass ) + { + if( objectClass.equals( EmpresaData.class ) ) + { +System.out.println( "Empresa" ); + return getEmpresaSearchExecuter(); + } + else if( objectClass == EstabelecimentoData.class ) + { + return getEstabelecimentoSearchExecuter(); + } + else if( objectClass == TrabalhadorData.class ) + { + return getTrabalhadorSearchExecuter(); + } + return null; + } + + private static SearchExecuter getEmpresaSearchExecuter() + { + if( empresaExecuter == null ) + { + empresaExecuter = new SearchExecuter(){ + + private final DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + + public Virtual2DArray search( String pattern ) + throws Exception + { + + Executer executer = dbm.getSharedExecuter( this ); + Select select = new Select( new String[]{ "empresas" }, + new String[]{ EmpresaData.ID, EmpresaData.DESIGNACAO_SOCIAL, EmpresaData.DESIGNACAO_SOCIAL_PLAIN }, + new Field( EmpresaData.DESIGNACAO_SOCIAL_PLAIN ).isLike( "%" + com.evolute.utils.strings.StringPlainer.convertString( pattern, false, false ) + "%" ).and( + new Field( EmpresaData.INACTIVO ).isDifferent( "y" ) ), + new String[]{ EmpresaData.DESIGNACAO_SOCIAL_PLAIN }, null ); +System.out.println( "SELECT : " + select ); + return executer.executeQuery( select ); + } + + public boolean hasDetails() + { + return false; + } + + public void showDetails( SearchDialog dialog, Object o ) + throws Exception + { + } + + public String getSearchTitle() + { + return "Procurar Empresa"; + } + + public String[] getColumnNames() + { + return new String[]{ "Designa\u00e7\u00e3o Social" }; + } + }; + } + return empresaExecuter; + } + + private static SearchExecuter getEstabelecimentoSearchExecuter() + { + if( estabelecimentoExecuter == null ) + { + estabelecimentoExecuter = new SearchExecuter(){ + private final DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + + public Virtual2DArray search( String pattern ) + throws Exception + { + Executer executer = dbm.getSharedExecuter( this ); + Select select = new Select( new String[]{ "estabelecimentos" }, + new String[]{ EstabelecimentoData.ID, EstabelecimentoData.NOME, EstabelecimentoData.NOME_PLAIN }, + new Field( EstabelecimentoData.NOME_PLAIN ).isLike( "%" + com.evolute.utils.strings.StringPlainer.convertString( pattern, false, false ) + "%" ), + new String[]{ EstabelecimentoData.NOME_PLAIN }, null ); + return executer.executeQuery( select ); + } + + public boolean hasDetails() + { + return false; + } + + public void showDetails( SearchDialog dialog, Object o ) + throws Exception + { + } + + public String getSearchTitle() + { + return "Procurar Estabelecimento"; + } + + public String[] getColumnNames() + { + return new String[]{ "Designa\u00e7\u00e3o" }; + } + }; + } + return estabelecimentoExecuter; + } + + + private static SearchExecuter getTrabalhadorSearchExecuter() + { + if( trabalhadorExecuter == null ) + { + trabalhadorExecuter = new SearchExecuter(){ + private final DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + + public Virtual2DArray search( String pattern ) + throws Exception + { + Executer executer = dbm.getSharedExecuter( this ); + Select select = new Select( new String[]{ "trabalhadores" }, + new String[]{ TrabalhadorData.ID, TrabalhadorData.NOME, TrabalhadorData.NOME_PLAIN }, + new Field( TrabalhadorData.NOME_PLAIN ).isLike( "%" + com.evolute.utils.strings.StringPlainer.convertString( pattern, false, false ) + "%" ), + new String[]{ TrabalhadorData.NOME_PLAIN }, null ); + return executer.executeQuery( select ); + } + + public boolean hasDetails() + { + return false; + } + + public void showDetails( SearchDialog dialog, Object o ) + throws Exception + { + } + + public String getSearchTitle() + { + return "Procurar Trablhador"; + } + + public String[] getColumnNames() + { + return new String[]{ "Nome" }; + } + }; + } + return trabalhadorExecuter; + } +} diff --git a/trunk/siprp/data/TecnicoHST.java b/trunk/siprp/data/TecnicoHST.java new file mode 100644 index 00000000..352d6096 --- /dev/null +++ b/trunk/siprp/data/TecnicoHST.java @@ -0,0 +1,134 @@ +/* +* TecnicoHST.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import com.evolute.utils.jdo.*; + +public final class TecnicoHST implements JDOInnerObject +{ + private Integer id; + private String nome; + private String nome_plain; + private String iniciais; + private Integer identificador; + private String inactivo; + + public TecnicoHST() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == TecnicoHSTData.ID ) + { + return id; + } + else if( fieldName == TecnicoHSTData.NOME ) + { + return nome; + } + else if( fieldName == TecnicoHSTData.NOME_PLAIN ) + { + return nome_plain; + } + else if( fieldName == TecnicoHSTData.INICIAIS ) + { + return iniciais; + } + else if( fieldName == TecnicoHSTData.IDENTIFICADOR ) + { + return identificador; + } + else if( fieldName == TecnicoHSTData.INACTIVO ) + { + return inactivo; + } + else if( fieldName.equals( TecnicoHSTData.ID ) ) + { + return id; + } + else if( fieldName.equals( TecnicoHSTData.NOME ) ) + { + return nome; + } + else if( fieldName.equals( TecnicoHSTData.NOME_PLAIN ) ) + { + return nome_plain; + } + else if( fieldName.equals( TecnicoHSTData.INICIAIS ) ) + { + return iniciais; + } + else if( fieldName.equals( TecnicoHSTData.IDENTIFICADOR ) ) + { + return identificador; + } + else if( fieldName.equals( TecnicoHSTData.INACTIVO ) ) + { + return inactivo; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == TecnicoHSTData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == TecnicoHSTData.NOME ) + { + nome = ( String ) value; + } + else if( fieldName == TecnicoHSTData.NOME_PLAIN ) + { + nome_plain = ( String ) value; + } + else if( fieldName == TecnicoHSTData.INICIAIS ) + { + iniciais = ( String ) value; + } + else if( fieldName == TecnicoHSTData.IDENTIFICADOR ) + { + identificador = ( Integer ) value; + } + else if( fieldName == TecnicoHSTData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( TecnicoHSTData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( TecnicoHSTData.NOME ) ) + { + nome = ( String ) value; + } + else if( fieldName.equals( TecnicoHSTData.NOME_PLAIN ) ) + { + nome_plain = ( String ) value; + } + else if( fieldName.equals( TecnicoHSTData.INICIAIS ) ) + { + iniciais = ( String ) value; + } + else if( fieldName.equals( TecnicoHSTData.IDENTIFICADOR ) ) + { + identificador = ( Integer ) value; + } + else if( fieldName.equals( TecnicoHSTData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + } + + public Class getOuterClass() + { + return TecnicoHSTData.class; + } +} diff --git a/trunk/siprp/data/TecnicoHSTData.java b/trunk/siprp/data/TecnicoHSTData.java new file mode 100644 index 00000000..1d70e935 --- /dev/null +++ b/trunk/siprp/data/TecnicoHSTData.java @@ -0,0 +1,63 @@ +/* +* TecnicoHSTData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class TecnicoHSTData extends JDOObject + implements DisableDeleteable +{ + public static final String ID = "id"; + public static final String NOME = "nome"; + public static final String NOME_PLAIN = "nome_plain"; + public static final String INICIAIS = "iniciais"; + public static final String IDENTIFICADOR = "identificador"; + public static final String INACTIVO = "inactivo"; + + public static final String FIELD_NAMES[] = new String[]{ + NOME, NOME_PLAIN, INICIAIS, IDENTIFICADOR, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, NOME, NOME_PLAIN, INICIAIS, IDENTIFICADOR, INACTIVO, }; + + private HashMap dataHash; + + public TecnicoHSTData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return TecnicoHST.class; + } +} diff --git a/trunk/siprp/data/TecnicoHSTID.java b/trunk/siprp/data/TecnicoHSTID.java new file mode 100644 index 00000000..f7f90bd4 --- /dev/null +++ b/trunk/siprp/data/TecnicoHSTID.java @@ -0,0 +1,25 @@ +/* +* TecnicoHSTID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on Feb 1, 2006 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class TecnicoHSTID extends IntegerID + implements Serializable +{ + public TecnicoHSTID() + { + } + + public TecnicoHSTID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/Trabalhador.java b/trunk/siprp/data/Trabalhador.java new file mode 100644 index 00000000..e7da2172 --- /dev/null +++ b/trunk/siprp/data/Trabalhador.java @@ -0,0 +1,356 @@ +/* +* Trabalhador.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.Date; +import com.evolute.utils.jdo.*; + +public final class Trabalhador implements JDOInnerObject +{ + private Integer id; + private String nome; + private String nome_plain; + private String sexo; + private Date data_nascimento; + private String nacionalidade; + private String numero_mecanografico; + private Date data_admissao; + private String categoria; + private String local_trabalho; + private String funcao_proposta; + private Date data_admissao_funcao; + private String observacoes; + private Estabelecimento estabelecimento; + private Date data_demissao; + private String observacoes_gestao; + private Integer perfil; + private String inactivo; + private Date actualizacao; + + public Trabalhador() + { + } + + public Object getField( String fieldName ) + { + if( fieldName == TrabalhadorData.ID ) + { + return id; + } + else if( fieldName == TrabalhadorData.NOME ) + { + return nome; + } + else if( fieldName == TrabalhadorData.NOME_PLAIN ) + { + return nome_plain; + } + else if( fieldName == TrabalhadorData.SEXO ) + { + return sexo; + } + else if( fieldName == TrabalhadorData.DATA_NASCIMENTO ) + { + return data_nascimento; + } + else if( fieldName == TrabalhadorData.NACIONALIDADE ) + { + return nacionalidade; + } + else if( fieldName == TrabalhadorData.NUMERO_MECANOGRAFICO ) + { + return numero_mecanografico; + } + else if( fieldName == TrabalhadorData.DATA_ADMISSAO ) + { + return data_admissao; + } + else if( fieldName == TrabalhadorData.CATEGORIA ) + { + return categoria; + } + else if( fieldName == TrabalhadorData.LOCAL_TRABALHO ) + { + return local_trabalho; + } + else if( fieldName == TrabalhadorData.FUNCAO_PROPOSTA ) + { + return funcao_proposta; + } + else if( fieldName == TrabalhadorData.DATA_ADMISSAO_FUNCAO ) + { + return data_admissao_funcao; + } + else if( fieldName == TrabalhadorData.OBSERVACOES ) + { + return observacoes; + } + else if( fieldName == TrabalhadorData.ESTABELECIMENTO ) + { + return estabelecimento; + } + else if( fieldName == TrabalhadorData.DATA_DEMISSAO ) + { + return data_demissao; + } + else if( fieldName == TrabalhadorData.OBSERVACOES_GESTAO ) + { + return observacoes_gestao; + } + else if( fieldName == TrabalhadorData.PERFIL ) + { + return perfil; + } + else if( fieldName == TrabalhadorData.INACTIVO ) + { + return inactivo; + } + else if( fieldName == TrabalhadorData.ACTUALIZACAO ) + { + return actualizacao; + } + else if( fieldName.equals( TrabalhadorData.ID ) ) + { + return id; + } + else if( fieldName.equals( TrabalhadorData.NOME ) ) + { + return nome; + } + else if( fieldName.equals( TrabalhadorData.NOME_PLAIN ) ) + { + return nome_plain; + } + else if( fieldName.equals( TrabalhadorData.SEXO ) ) + { + return sexo; + } + else if( fieldName.equals( TrabalhadorData.DATA_NASCIMENTO ) ) + { + return data_nascimento; + } + else if( fieldName.equals( TrabalhadorData.NACIONALIDADE ) ) + { + return nacionalidade; + } + else if( fieldName.equals( TrabalhadorData.NUMERO_MECANOGRAFICO ) ) + { + return numero_mecanografico; + } + else if( fieldName.equals( TrabalhadorData.DATA_ADMISSAO ) ) + { + return data_admissao; + } + else if( fieldName.equals( TrabalhadorData.CATEGORIA ) ) + { + return categoria; + } + else if( fieldName.equals( TrabalhadorData.LOCAL_TRABALHO ) ) + { + return local_trabalho; + } + else if( fieldName.equals( TrabalhadorData.FUNCAO_PROPOSTA ) ) + { + return funcao_proposta; + } + else if( fieldName.equals( TrabalhadorData.DATA_ADMISSAO_FUNCAO ) ) + { + return data_admissao_funcao; + } + else if( fieldName.equals( TrabalhadorData.OBSERVACOES ) ) + { + return observacoes; + } + else if( fieldName.equals( TrabalhadorData.ESTABELECIMENTO ) ) + { + return estabelecimento; + } + else if( fieldName.equals( TrabalhadorData.DATA_DEMISSAO ) ) + { + return data_demissao; + } + else if( fieldName.equals( TrabalhadorData.OBSERVACOES_GESTAO ) ) + { + return observacoes_gestao; + } + else if( fieldName.equals( TrabalhadorData.PERFIL ) ) + { + return perfil; + } + else if( fieldName.equals( TrabalhadorData.INACTIVO ) ) + { + return inactivo; + } + else if( fieldName.equals( TrabalhadorData.ACTUALIZACAO ) ) + { + return actualizacao; + } + return null; + } + + public void setField( String fieldName, Object value ) + { + if( fieldName == TrabalhadorData.ID ) + { + id = ( Integer ) value; + } + else if( fieldName == TrabalhadorData.NOME ) + { + nome = ( String ) value; + } + else if( fieldName == TrabalhadorData.NOME_PLAIN ) + { + nome_plain = ( String ) value; + } + else if( fieldName == TrabalhadorData.SEXO ) + { + sexo = ( String ) value; + } + else if( fieldName == TrabalhadorData.DATA_NASCIMENTO ) + { + data_nascimento = ( Date ) value; + } + else if( fieldName == TrabalhadorData.NACIONALIDADE ) + { + nacionalidade = ( String ) value; + } + else if( fieldName == TrabalhadorData.NUMERO_MECANOGRAFICO ) + { + numero_mecanografico = ( String ) value; + } + else if( fieldName == TrabalhadorData.DATA_ADMISSAO ) + { + data_admissao = ( Date ) value; + } + else if( fieldName == TrabalhadorData.CATEGORIA ) + { + categoria = ( String ) value; + } + else if( fieldName == TrabalhadorData.LOCAL_TRABALHO ) + { + local_trabalho = ( String ) value; + } + else if( fieldName == TrabalhadorData.FUNCAO_PROPOSTA ) + { + funcao_proposta = ( String ) value; + } + else if( fieldName == TrabalhadorData.DATA_ADMISSAO_FUNCAO ) + { + data_admissao_funcao = ( Date ) value; + } + else if( fieldName == TrabalhadorData.OBSERVACOES ) + { + observacoes = ( String ) value; + } + else if( fieldName == TrabalhadorData.ESTABELECIMENTO ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName == TrabalhadorData.DATA_DEMISSAO ) + { + data_demissao = ( Date ) value; + } + else if( fieldName == TrabalhadorData.OBSERVACOES_GESTAO ) + { + observacoes_gestao = ( String ) value; + } + else if( fieldName == TrabalhadorData.PERFIL ) + { + perfil = ( Integer ) value; + } + else if( fieldName == TrabalhadorData.INACTIVO ) + { + inactivo = ( String ) value; + } + else if( fieldName == TrabalhadorData.ACTUALIZACAO ) + { + actualizacao = ( Date ) value; + } + else if( fieldName.equals( TrabalhadorData.ID ) ) + { + id = ( Integer ) value; + } + else if( fieldName.equals( TrabalhadorData.NOME ) ) + { + nome = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.NOME_PLAIN ) ) + { + nome_plain = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.SEXO ) ) + { + sexo = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.DATA_NASCIMENTO ) ) + { + data_nascimento = ( Date ) value; + } + else if( fieldName.equals( TrabalhadorData.NACIONALIDADE ) ) + { + nacionalidade = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.NUMERO_MECANOGRAFICO ) ) + { + numero_mecanografico = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.DATA_ADMISSAO ) ) + { + data_admissao = ( Date ) value; + } + else if( fieldName.equals( TrabalhadorData.CATEGORIA ) ) + { + categoria = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.LOCAL_TRABALHO ) ) + { + local_trabalho = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.FUNCAO_PROPOSTA ) ) + { + funcao_proposta = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.DATA_ADMISSAO_FUNCAO ) ) + { + data_admissao_funcao = ( Date ) value; + } + else if( fieldName.equals( TrabalhadorData.OBSERVACOES ) ) + { + observacoes = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.ESTABELECIMENTO ) ) + { + estabelecimento = ( Estabelecimento ) value; + } + else if( fieldName.equals( TrabalhadorData.DATA_DEMISSAO ) ) + { + data_demissao = ( Date ) value; + } + else if( fieldName.equals( TrabalhadorData.OBSERVACOES_GESTAO ) ) + { + observacoes_gestao = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.PERFIL ) ) + { + perfil = ( Integer ) value; + } + else if( fieldName.equals( TrabalhadorData.INACTIVO ) ) + { + inactivo = ( String ) value; + } + else if( fieldName.equals( TrabalhadorData.ACTUALIZACAO ) ) + { + actualizacao = ( Date ) value; + } + } + + public Class getOuterClass() + { + return TrabalhadorData.class; + } +} diff --git a/trunk/siprp/data/TrabalhadorData.java b/trunk/siprp/data/TrabalhadorData.java new file mode 100644 index 00000000..396b512f --- /dev/null +++ b/trunk/siprp/data/TrabalhadorData.java @@ -0,0 +1,82 @@ +/* +* TrabalhadorData.java +* +* Generated by com.evutils.codegen.JDOObjectGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.util.HashMap; +import com.evolute.utils.jdo.*; + +public final class TrabalhadorData extends JDOObject + implements DisableDeleteable, ActualizacaoSaveable +{ + public static final String ID = "id"; + public static final String NOME = "nome"; + public static final String NOME_PLAIN = "nome_plain"; + public static final String SEXO = "sexo"; + public static final String DATA_NASCIMENTO = "data_nascimento"; + public static final String NACIONALIDADE = "nacionalidade"; + public static final String NUMERO_MECANOGRAFICO = "numero_mecanografico"; + public static final String DATA_ADMISSAO = "data_admissao"; + public static final String CATEGORIA = "categoria"; + public static final String LOCAL_TRABALHO = "local_trabalho"; + public static final String FUNCAO_PROPOSTA = "funcao_proposta"; + public static final String DATA_ADMISSAO_FUNCAO = "data_admissao_funcao"; + public static final String OBSERVACOES = "observacoes"; + public static final String ESTABELECIMENTO = "estabelecimento"; + public static final String DATA_DEMISSAO = "data_demissao"; + public static final String OBSERVACOES_GESTAO = "observacoes_gestao"; + public static final String PERFIL = "perfil"; + public static final String INACTIVO = "inactivo"; + public static final String ACTUALIZACAO = "actualizacao"; + + public static final String FIELD_NAMES[] = new String[]{ + NOME, NOME_PLAIN, SEXO, DATA_NASCIMENTO, NACIONALIDADE, NUMERO_MECANOGRAFICO, + DATA_ADMISSAO, CATEGORIA, LOCAL_TRABALHO, FUNCAO_PROPOSTA, + DATA_ADMISSAO_FUNCAO, OBSERVACOES, ESTABELECIMENTO, DATA_DEMISSAO, + OBSERVACOES_GESTAO, PERFIL, }; + + + protected static final String ALL_FIELD_NAMES[] = new String[]{ + ID, NOME, NOME_PLAIN, SEXO, DATA_NASCIMENTO, NACIONALIDADE, NUMERO_MECANOGRAFICO, + DATA_ADMISSAO, CATEGORIA, LOCAL_TRABALHO, FUNCAO_PROPOSTA, + DATA_ADMISSAO_FUNCAO, OBSERVACOES, ESTABELECIMENTO, DATA_DEMISSAO, + OBSERVACOES_GESTAO, PERFIL, INACTIVO, ACTUALIZACAO, }; + + private HashMap dataHash; + + public TrabalhadorData() + { + dataHash = new HashMap(); + } + + protected Object innerGet( String fieldName ) + throws Exception + { + return dataHash.get( fieldName ); + } + + protected void innerSet( String fieldName, Object value ) + throws Exception + { + dataHash.put( fieldName, value ); + } + + public String []getFieldNames() + { + return FIELD_NAMES; + } + + protected String []getAllFieldNames() + { + return ALL_FIELD_NAMES; + } + + public Class getInnerClass() + { + return Trabalhador.class; + } +} diff --git a/trunk/siprp/data/TrabalhadorID.java b/trunk/siprp/data/TrabalhadorID.java new file mode 100644 index 00000000..6f37784d --- /dev/null +++ b/trunk/siprp/data/TrabalhadorID.java @@ -0,0 +1,25 @@ +/* +* TrabalhadorID.java +* +* Generated by com.evolute.codegen.jdo.idclassgenerators.JPOXIDClassGenerator on 24/Nov/2005 +* +* Use but DON'T TOUCH +*/ +package siprp.data; + +import java.io.*; + +import com.evolute.utils.jdo.jpox.*; + +public final class TrabalhadorID extends IntegerID + implements Serializable +{ + public TrabalhadorID() + { + } + + public TrabalhadorID( String str ) + { + super( str ); + } +} diff --git a/trunk/siprp/data/package.jdo b/trunk/siprp/data/package.jdo new file mode 100644 index 00000000..477f0586 --- /dev/null +++ b/trunk/siprp/data/package.jdo @@ -0,0 +1,1104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/siprp/estatistica/EstatisticaDataProvider.java b/trunk/siprp/estatistica/EstatisticaDataProvider.java new file mode 100644 index 00000000..935afc49 --- /dev/null +++ b/trunk/siprp/estatistica/EstatisticaDataProvider.java @@ -0,0 +1,777 @@ +/* + * EstatisticaDataProvider.java + * + * Created on 16 de Dezembro de 2004, 12:50 + */ + +package siprp.estatistica; + +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.db.keyretrievers.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.sql.expression.*; + +import siprp.data.*; +/** + * + * @author fpalma + */ +public class EstatisticaDataProvider extends MetaProvider +{ + private static final Object LOCK = new Object(); + private static EstatisticaDataProvider instance = null; + private final Executer executer; + + public static final DateFormat DF = DateFormat.getDateInstance( DateFormat.SHORT ); + + /** Creates a new instance of EstatisticaDataProvider */ + public EstatisticaDataProvider() + throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + executer = dbm.getSharedExecuter( this ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new EstatisticaDataProvider(); + } + } + return instance; + } + + public String[][] getMarcacoesPeriodo( Date dataInicio, Date dataFim ) + throws Exception + { + String [][]result = null; + Select select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ MarcacaoTrabalhadorData.DATA, + "trabalhador_id", + MarcacaoTrabalhadorData.REALIZADA, + MarcacaoTrabalhadorData.TIPO }, + new Field( "data" ).isGreaterOrEqual( dataInicio ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ), + new String[]{ "data" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + result = new String[ array.columnLength() ][ 5 ]; + for( int n = 0; n < result.length; n++ ) + { + Date data = ( Date ) array.get( n, 0 ); + int trabalhadorID = ( ( Number ) array.get( n, 1 ) ).intValue(); + boolean realizada = "y".equals( array.get( n, 2 ) ); + int tipo = ( ( Number ) array.get( n, 3 ) ).intValue(); + String nomeEstabEmp[] = getNomeEstabelecimentoEmpresaForTrabalhador( trabalhadorID ); + result[ n ][ 0 ] = nomeEstabEmp[ 2 ]; + result[ n ][ 1 ] = nomeEstabEmp[ 0 ]; + result[ n ][ 2 ] = nomeEstabEmp[ 1 ]; + result[ n ][ 3 ] = DF.format( data ); + result[ n ][ 4 ] = ( tipo == Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ? "(Exame)" : "(Consulta)" ); + + } + return result; + } + + public String[] getNomeEstabelecimentoEmpresaForTrabalhador( int trabalhadorID ) + throws Exception + { + String data[] = new String[ 3 ]; + Select select = + new Select( new String[]{ "trabalhadores", "estabelecimentos", "empresas"}, + new String[]{ "trabalhadores.nome", "estabelecimentos.nome", "empresas.designacao_social" }, + new Field( "trabalhadores.id" ).isEqual( new Integer( trabalhadorID ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 1 ) + { + data[ 0 ] = ( String ) array.get( 0, 0 ); + data[ 1 ] = ( String ) array.get( 0, 1 ); + data[ 2 ] = ( String ) array.get( 0, 2 ); + } + return data; + } + + public int countExamesPeriodo( Date dataInicio, Date dataFim ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ "count(*)" }, + new Field( "data" ).isGreaterOrEqual( dataInicio ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public int countConsultasPeriodo( Date dataInicio, Date dataFim ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ "count(*)" }, + new Field( "data" ).isGreaterOrEqual( dataInicio ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public int countExamesPeriodoForEmpresa( Date dataInicio, Date dataFim, Integer empresaID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" }, + new String[]{ "count(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public int countConsultasPeriodoForEmpresa( Date dataInicio, Date dataFim, Integer empresaID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" }, + new String[]{ "count(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public String[][] getMarcacoesPeriodoForEstabelecimento( Date dataInicio, Date dataFim, Integer estabelecimentoID ) + throws Exception + { + String [][]result = null; + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new String[]{ MarcacaoTrabalhadorData.DATA, + "trabalhador_id", + MarcacaoTrabalhadorData.REALIZADA, + MarcacaoTrabalhadorData.TIPO }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ), + new String[]{ "data" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + result = new String[ array.columnLength() ][ 5 ]; + for( int n = 0; n < result.length; n++ ) + { + Date data = ( Date ) array.get( n, 0 ); + int trabalhadorID = ( ( Number ) array.get( n, 1 ) ).intValue(); + boolean realizada = "y".equals( array.get( n, 2 ) ); + int tipo = ( ( Number ) array.get( n, 3 ) ).intValue(); + String nomeEstabEmp[] = getNomeEstabelecimentoEmpresaForTrabalhador( trabalhadorID ); + result[ n ][ 0 ] = nomeEstabEmp[ 2 ]; + result[ n ][ 1 ] = nomeEstabEmp[ 0 ]; + result[ n ][ 2 ] = nomeEstabEmp[ 1 ]; + result[ n ][ 3 ] = DF.format( data ); + result[ n ][ 4 ] = ( tipo == Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ? "(Exame)" : "(Consulta)" ); + + } + return result; + } + + public int countExamesPeriodoForEstabelecimento( Date dataInicio, Date dataFim, Integer estabelecimentoID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new String[]{ "count(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public int countConsultasPeriodoForEstabelecimento( Date dataInicio, Date dataFim, Integer estabelecimentoID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new String[]{ "count(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return 0; + } + return ( ( Number ) array.get( 0, 0 ) ).intValue(); + } + + public String[][] getTrabalhadoresSemExamesOuConsultas( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { +// Select subSelect = +// new Select( new String[]{ "marcacoes_trabalhador" }, +// new String[]{ "trabalhador_id" }, +// new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ).and( +// new Field( "realizada" ).isEqual( "y" ) ) ); + Select select = + new Select( new String[]{ "empresas", "estabelecimentos", + "trabalhadores LEFT OUTER JOIN marcacoes_trabalhador ON " + + "( trabalhadores.id = marcacoes_trabalhador.trabalhador_id AND marcacoes_trabalhador.tipo = " + + (exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA) + " AND marcacoes_trabalhador.realizada = 'y' )" }, + new String[]{ "empresas.designacao_social", "estabelecimentos.nome", "trabalhadores.nome", + "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( null ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ).or( + new Field( "marcacoes_trabalhador.realizada" ).isDifferent( "y" ) ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ), + new String[]{ "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 3 ]; + for( int r = 0; r < array.columnLength(); r++ ) + { + for( int c = 0; c < 3; c++ ) + { + data[ r ][ c ] = (String) array.get( r, c ); + } + } + return data; + } + + + + public int countTrabalhadoresSemExamesOuConsultas( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "trabalhadores" }, new String[]{ "COUNT(*)" }, + new Field( "inactivo" ).isDifferent( "y" ) ); + int totalCount = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + totalCount = n.intValue(); + } + } + +// select = +// new Select( new String[]{ "marcacoes_trabalhador" }, +// new String[]{ "COUNT(*)" }, +// new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ).and( +// new Field( "realizada" ).isEqual( "y" ) ).and( +// new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); +// int subCount = 0; +// array = executer.executeQuery( select ); +// if( array.columnLength() > 0 && array.rowLength() > 0 ) +// { +// Number n = (Number) array.get( 0, 0 ); +// if( n != null ) +// { +// subCount = n.intValue(); +// } +// } + + return totalCount - countTrabalhadoresComExamesOuConsultasPeriodo( dataInicio, dataFim, exames ); + } + + public String[][] getTrabalhadoresSemExamesOuConsultasEstabelecimento( Integer estabelecimentoID, Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ "trabalhador_id" }, + new Field( "tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ).and( + new Field( "realizada" ).isEqual( "y" ) ) ); + 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 ); + } + if( ids.length == 0 ) + { + ids = new Integer[]{ new Integer( -1 ) }; + } + select = + new Select( new String[]{ "estabelecimentos", + "trabalhadores" }, + new String[]{ "estabelecimentos.nome", "trabalhadores.nome" }, + new Field( "estabelecimentos.id" ).isEqual( estabelecimentoID ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.id" ).notIn( ids ) ), + new String[]{ "trabalhadores.nome" }, null ); +// Select select = +// new Select( new String[]{ "estabelecimentos", +// "trabalhadores LEFT OUTER JOIN marcacoes_trabalhador ON " +// + "( trabalhadores.id = marcacoes_trabalhador.trabalhador_id AND marcacoes_trabalhador.tipo = " +// + (exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA) + " AND marcacoes_trabalhador.realizada = 'y' )" }, +// new String[]{ "estabelecimentos.nome", "trabalhadores.nome" }, +// new Field( "estabelecimentos.id" ).isEqual( estabelecimentoID ).and( +// new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( +// new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( +// new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( null ).or( +// new Field( "marcacoes_trabalhador.realizada" ).isDifferent( "y" ) ) ).and( +// new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( +// new Field( "data" ).isLessOrEqual( dataFim ) ).and( +// new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ), +// new String[]{ "trabalhadores.nome" }, null ); + array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 2 ]; + for( int r = 0; r < array.columnLength(); r++ ) + { + for( int c = 0; c < 2; c++ ) + { + data[ r ][ c ] = (String) array.get( r, c ); + } + } + return data; + } + + public Object[][] getCountTrabalhadoresSemExamesOuConsultasPeriodoForAllEmpresas( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "empresas" }, + new String[]{ "id", "designacao_social", "designacao_social_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "designacao_social_plain" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + Object data[][] = new Object[ array.columnLength() ][ 3 ]; + for( int n = 0; n < data.length; n++ ) + { + data[ n ][ 0 ] = array.get( n, 1 ); + Integer empresaID = (Integer)array.get( n, 0 ); + data[ n ][ 1 ] = new Integer( countTrabalhadoresSemExamesOuConsultasEmpresa( empresaID, dataInicio, dataFim, exames ) ); + data[ n ][ 2 ] = empresaID; + } + return data; + } + + public int countTrabalhadoresSemExamesOuConsultasEmpresa( Integer empresaID, Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "trabalhadores", "estabelecimentos" }, new String[]{ "COUNT(*)" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); + int totalCount = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + totalCount = n.intValue(); + } + } + +// select = +// new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" }, +// new String[]{ "COUNT(*)" }, +// new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( +// new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( +// new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ).and( +// new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ).and( +// new Field( "realizada" ).isEqual( "y" ) ).and( +// new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); +// int subCount = 0; +// array = executer.executeQuery( select ); +// if( array.columnLength() > 0 && array.rowLength() > 0 ) +// { +// Number n = (Number) array.get( 0, 0 ); +// if( n != null ) +// { +// subCount = n.intValue(); +// } +// } + return totalCount - countTrabalhadoresComExamesOuConsultasPeriodoForEmpresa( dataInicio, dataFim, empresaID, exames ); + } + + public int countTrabalhadoresSemExamesOuConsultasEstabelecimento( Integer estabelecimentoID, Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "trabalhadores" }, new String[]{ "COUNT(*)" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); + int totalCount = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + totalCount = n.intValue(); + } + } + +// select = +// new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, +// new String[]{ "COUNT(*)" }, +// new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( +// new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( +// new Field( "tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ).and( +// new Field( "realizada" ).isEqual( "y" ) ).and( +// new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); +// int subCount = 0; +// array = executer.executeQuery( select ); +// if( array.columnLength() > 0 && array.rowLength() > 0 ) +// { +// Number n = (Number) array.get( 0, 0 ); +// if( n != null ) +// { +// subCount = n.intValue(); +// } +// } + return totalCount - countTrabalhadoresComExamesOuConsultasPeriodoForEstabelecimento( dataInicio, dataFim, estabelecimentoID, exames ); + } + + public String[][]getTrabalhadoresComExamesOuConsultasPeriodo( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "empresas", "estabelecimentos", + "trabalhadores", "marcacoes_trabalhador" }, + new String[]{ "empresas.designacao_social", "estabelecimentos.nome", "trabalhadores.nome", + "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ).and( + new Field( "marcacoes_trabalhador.realizada" ).isEqual( "y" ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ), + new String[]{ "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 3 ]; + for( int r = 0; r < array.columnLength(); r++ ) + { + for( int c = 0; c < 3; c++ ) + { + data[ r ][ c ] = (String) array.get( r, c ); + } + } + return data; + } + + public int countTrabalhadoresComExamesOuConsultasPeriodo( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new String[]{ "COUNT(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ).and( + new Field( "realizada" ).isEqual( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ) ); + int count = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + count = n.intValue(); + } + } + return count; + } + + public String[][]getTrabalhadoresComExamesOuConsultasPeriodoForEstabelecimento( Date dataInicio, Date dataFim, Integer estabelecimentoID, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "estabelecimentos", + "trabalhadores", "marcacoes_trabalhador" }, + new String[]{ "estabelecimentos.nome", "trabalhadores.nome" }, + new Field( "estabelecimentos.id" ).isEqual( estabelecimentoID ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ).and( + new Field( "marcacoes_trabalhador.realizada" ).isEqual( "y" ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ), + new String[]{ "estabelecimentos.nome", "trabalhadores.nome" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 2 ]; + for( int r = 0; r < array.columnLength(); r++ ) + { + for( int c = 0; c < 2; c++ ) + { + data[ r ][ c ] = (String) array.get( r, c ); + } + } + return data; + } + + public Object[][] getCountTrabalhadoresComExamesOuConsultasPeriodoForAllEmpresas( Date dataInicio, Date dataFim, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "empresas" }, + new String[]{ "id", "designacao_social", "designacao_social_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "designacao_social_plain" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + Object data[][] = new Object[ array.columnLength() ][ 3 ]; + for( int n = 0; n < data.length; n++ ) + { + data[ n ][ 0 ] = array.get( n, 1 ); + Integer empresaID = (Integer)array.get( n, 0 ); + data[ n ][ 1 ] = new Integer( countTrabalhadoresComExamesOuConsultasPeriodoForEmpresa( dataInicio, dataFim, empresaID, exames ) ); + data[ n ][ 2 ] = empresaID; + } + return data; + } + + public int countTrabalhadoresComExamesOuConsultasPeriodoForEmpresa( Date dataInicio, Date dataFim, Integer empresaID, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" }, + new String[]{ "COUNT(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ).and( + new Field( "tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ).and( + new Field( "realizada" ).isEqual( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ) ); + int count = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + count = n.intValue(); + } + } + return count; + } + + public int countTrabalhadoresComExamesOuConsultasPeriodoForEstabelecimento( Date dataInicio, Date dataFim, Integer estabelecimentoID, boolean exames ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador", "trabalhadores" }, + new String[]{ "COUNT(*)" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( "tipo" ).isEqual( new Integer( exames ? Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES : Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ).and( + new Field( "realizada" ).isEqual( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ).and( + new Field( "data" ).isGreaterOrEqual( dataInicio ) ).and( + new Field( "data" ).isLessOrEqual( dataFim ) ) ); + int count = 0; + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() > 0 && array.rowLength() > 0 ) + { + Number n = (Number) array.get( 0, 0 ); + if( n != null ) + { + count = n.intValue(); + } + } + return count; + } + + public String [][]getDadosTrabalhadoresPeriodo( Date dataInicio, Date dataFim ) + throws Exception + { + Select select = + new Select( new String[]{ "empresas", "estabelecimentos", "trabalhadores" }, + new String[]{ "empresas.designacao_social", "estabelecimentos.nome", "trabalhadores.nome", "trabalhadores.id", + "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ), + new String[]{ "empresas.designacao_social_plain", "estabelecimentos.nome_plain", "trabalhadores.nome_plain" }, null ); + + Virtual2DArray array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 7 ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + data[ n ][ 0 ] = ( String ) array.get( n, 0 ); + data[ n ][ 1 ] = ( String ) array.get( n, 1 ); + data[ n ][ 2 ] = ( String ) array.get( n, 2 ); + Integer id = new Integer( ( (Number) array.get( n, 3 ) ).intValue() ); + Select exameSelect = + new Select( new String[]{ "trabalhadores", "marcacoes_trabalhador" }, + new String[]{ "data", "realizada" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.id" ).isEqual( id ) ).and( + new Field( "marcacoes_trabalhador.data" ).isLessOrEqual( dataFim ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES ) ) ), + new String[]{ "data desc" }, null ); + Virtual2DArray exameArray = executer.executeQuery( exameSelect ); + if( exameArray.columnLength() > 0 ) + { + Date dataExame = ( Date ) exameArray.get( 0, 0 ); + String estado = ( String ) exameArray.get( 0, 1 ); + data[ n ][ 3 ] = DF.format( dataExame ); + data[ n ][ 4 ] = "y".equals( estado ) ? "Realizado" : "Faltou"; + } + else + { + data[ n ][ 3 ] = "--"; + data[ n ][ 4 ] = "--"; + } + + Select consultaSelect = + new Select( new String[]{ "trabalhadores", "marcacoes_trabalhador" }, + new String[]{ "data", "realizada" }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.id" ).isEqual( id ) ).and( + new Field( "marcacoes_trabalhador.data" ).isLessOrEqual( dataFim ) ).and( + new Field( "marcacoes_trabalhador.tipo" ).isEqual( new Integer( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ) ), + new String[]{ "data desc" }, null ); + Virtual2DArray consultaArray = executer.executeQuery( consultaSelect ); + if( consultaArray.columnLength() > 0 ) + { + Date dataConsulta = ( Date ) consultaArray.get( 0, 0 ); + String estado = ( String ) consultaArray.get( 0, 1 ); + data[ n ][ 5 ] = DF.format( dataConsulta ); + data[ n ][ 6 ] = "y".equals( estado ) ? "Realizada" : "Faltou"; + } + else + { + data[ n ][ 5 ] = "--"; + data[ n ][ 6 ] = "--"; + } + } + return data; + } + + public String[][]getDadosHigieneSeguranca() + throws Exception + { + Select select = + new Select( new String[]{ "empresas", "estabelecimentos" }, + new String[]{ "empresas.designacao_social", "estabelecimentos.nome", "estabelecimentos.id", + "empresas.designacao_social_plain", "estabelecimentos.nome_plain" }, + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ).and( + new Field( "empresas.inactivo" ).isDifferent( "y" ) ).and( + new Field( "estabelecimentos.inactivo" ).isDifferent( "y" ) ), + new String[]{ "empresas.designacao_social_plain", "estabelecimentos.nome_plain" }, null ); + + Virtual2DArray array = executer.executeQuery( select ); + String data[][] = new String[ array.columnLength() ][ 6 ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + data[ n ][ 0 ] = ( String ) array.get( n, 0 ); + data[ n ][ 1 ] = ( String ) array.get( n, 1 ); + Integer id = new Integer( ( (Number) array.get( n, 2 ) ).intValue() ); + Select ultimaSelect = + new Select( new String[]{ "marcacoes_estabelecimento" }, + new String[]{ "data", "realizada", "data_relatorio" }, + new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( id ).and( + new Field( "marcacoes_estabelecimento.data" ).isLessOrEqual( new Date() ) ), + new String[]{ "data desc" }, null ); + Virtual2DArray ultimaArray = executer.executeQuery( ultimaSelect ); + if( ultimaArray.columnLength() > 0 ) + { + Date dataAud = ( Date ) ultimaArray.get( 0, 0 ); + String estado = ( String ) ultimaArray.get( 0, 1 ); + Date dataRel = ( Date ) ultimaArray.get( 0, 2 ); + data[ n ][ 2 ] = DF.format( dataAud ); + data[ n ][ 3 ] = "y".equals( estado ) ? "Realizada" : "Não Realizada"; + data[ n ][ 4 ] = dataRel != null ? DF.format( dataRel ) : "--"; + } + else + { + data[ n ][ 2 ] = "--"; + data[ n ][ 3 ] = "--"; + data[ n ][ 4 ] = "--"; + } + + Select proximaSelect = + new Select( new String[]{ "marcacoes_estabelecimento" }, + new String[]{ "data" }, + new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( id ).and( + new Field( "marcacoes_estabelecimento.data" ).isGreaterOrEqual( new Date() ) ), + new String[]{ "data desc" }, null ); + Virtual2DArray proximaArray = executer.executeQuery( proximaSelect ); + if( proximaArray.columnLength() > 0 ) + { + Date dataProx = ( Date ) proximaArray.get( 0, 0 ); + data[ n ][ 5 ] = DF.format( dataProx ); + } + else + { + data[ n ][ 5 ] = "--"; + } + } + return data; + } + + + +} + diff --git a/trunk/siprp/estatistica/EstatisticaWindow.java b/trunk/siprp/estatistica/EstatisticaWindow.java new file mode 100644 index 00000000..7bdbd736 --- /dev/null +++ b/trunk/siprp/estatistica/EstatisticaWindow.java @@ -0,0 +1,1323 @@ +/* + * EstatisticaWindow.java + * + * Created on 16 de Dezembro de 2004, 13:50 + */ + +package siprp.estatistica; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; +import javax.swing.event.*; +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.data.*; +import com.evolute.utils.documents.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.tracker.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.data.*; +import siprp.pesquisas.*; +/** + * + * @author fpalma + */ +public class EstatisticaWindow extends JFrame + implements TrackableWindow, ListSelectionListener, ActionListener, ItemListener +{ + public static final DateFormat DF = DateFormat.getDateInstance( DateFormat.SHORT ); + + public static final int NONE = 0; + public static final int LISTAGEM_GERAL_MARCACOES_PERIODO = 1; + public static final int LISTAGEM_MARCACOES_PERIODO_EMPRESA_ESTABELECIMENTO = 2; + public static final int LISTAGEM_GLOBAL_TRABALHADORES_SEM_EXAMES = 3; + public static final int LISTAGEM_TRABALHADORES_SEM_EXAMES_EMPRESA_ESTABELECIMENTO = 4; + public static final int LISTAGEM_GLOBAL_TRABALHADORES_COM_EXAMES_PERIODO = 5; + public static final int LISTAGEM_TRABALHADORES_COM_EXAMES_PERIODO_EMPRESA_ESTABELECIMENTO = 6; + public static final int LISTAGEM_GLOBAL_TRABALHADORES_SEM_CONSULTA = 7; + public static final int LISTAGEM_TRABALHADORES_SEM_CONSULTA_EMPRESA_ESTABELECIMENTO = 8; + public static final int LISTAGEM_GLOBAL_TRABALHADORES_COM_CONSULTA_PERIODO = 9; + public static final int LISTAGEM_TRABALHADORES_COM_CONSULTA_PERIODO_EMPRESA_ESTABELECIMENTO = 10; + public static final int LISTAGEM_GLOBAL_TRABALHADORES_PERIODO = -1; + public static final int LISTAGEM_GLOBAL_HIGIENE_SEGURANCA = 11; + + public static final String ESTATISTICAS[] = + new String[]{ "", + "Marca\u00e7\u00f5es efectuadas e pendentes (geral)", + "Marca\u00e7\u00f5es efectuadas e pendentes (por Empresa e Estabelecimento)", + "Contagem global de trabalhadores que ainda n\u00e3o realizaram exames (por per\u00edodo)", + "Listagem de trabalhadores que ainda n\u00e3o realizaram exames (por per\u00edodo, Empresa e Estabelecimento)", + "Contagem global de trabalhadores que j\u00e1 realizaram exames (por per\u00edodo)", + "Listagem de trabalhadores que j\u00e1 realizaram exames (por per\u00edodo, Empresa e Estabelecimento)", + "Contagem global de trabalhadores que ainda n\u00e3o realizaram consultas (por per\u00edodo)", + "Listagem de trabalhadores que ainda n\u00e3o realizaram consultas (por per\u00edodo, Empresa e Estabelecimento)", + "Contagem global de trabalhadores que j\u00e1 realizaram consultas (por per\u00edodo)", + "Listagem de trabalhadores que j\u00e1 realizaram consultas (por per\u00edodo, Empresa e Estabelecimento)", + //"Listagem global de trabalhadores (por per\u00edodo)", + "Listagem global com os dados de higiene e seguran\u00e7a" }; + + + public static final int OPTION_INTERVALO = 0; + public static final int OPTION_ANO = 1; + public static final int OPTION_EMPRESA = 2; + public static final int OPTION_ESTABELECIMENTO = 0; + + public static final boolean ESTATISTICAS_OPTIONS[][] = + // intervalo, ano, empresa, estabelecimento + new boolean[][]{ { false, false, false, false }, + { true, false, false, false }, + { true, false, true, true }, + { true, false, false, false }, + { true, false, true, true }, + { true, false, false, false }, + { true, false, true, true }, + { true, false, false, false }, + { true, false, true, true }, + { true, false, false, false }, + { true, false, true, true }, +// { true, false, false, false }, + { false, false, false, false } }; + + private JDOProvider JDO; + private EstatisticaDataProvider provider; + private PesquisasProvider pesquisasProvider; + + private JComboBox estatisticaCombo; + private JCalendarPanel dataInicioPanel; + private JCalendarPanel dataFimPanel; + private JTextField anoText; + private BaseTable empresasTable; + private VectorTableModel empresasModel; + private BaseTable estabelecimentosTable; + private VectorTableModel estabelecimentosModel; + private JButton pesquisarButton; + private JButton excelButton; + private JEditorPane resultadoText; + + /** Creates a new instance of EstatisticaWindow */ + public EstatisticaWindow() + throws Exception + { + provider = (EstatisticaDataProvider)EstatisticaDataProvider.getProvider(); + pesquisasProvider = (PesquisasProvider)PesquisasProvider.getProvider(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + } + + private void setupComponents() + { + setSize( 1000, 700 ); + setTitle( "Listagens" ); + + JLabel estatisticaLabel = new JLabel( "Listagem" ); + estatisticaCombo = new JComboBox(); + for( int n = 0; n < ESTATISTICAS.length; n++ ) + { + estatisticaCombo.addItem( ESTATISTICAS[ n ] ); + } + estatisticaCombo.setSelectedIndex( 0 ); + estatisticaCombo.addItemListener( this ); + estatisticaCombo.setPreferredSize( new Dimension( 700, 20 ) ); + JLabel intervalo1Label = new JLabel( "De" ); + JLabel intervalo2Label = new JLabel( "a" ); + dataInicioPanel = new JCalendarPanel( null ); + dataInicioPanel.setPreferredSize( new Dimension( 200, 20 ) ); + dataFimPanel = new JCalendarPanel( null ); + dataFimPanel.setPreferredSize( new Dimension( 200, 20 ) ); + + JLabel anoLabel = new JLabel( "Ano" ); + anoText = new JTextField(); + anoText.setDocument( new YearDocument() ); + anoText.setPreferredSize( new Dimension( 50, 20 ) ); + new CopyPasteHandler( anoText ); + + empresasModel = new VectorTableModel( new String[]{ "Designa\u00e7\u00e3o Social" } ); + empresasTable = new BaseTable( empresasModel ); + empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + empresasTable.setNonResizableNorReordable(); + empresasTable.getSelectionModel().addListSelectionListener( this ); + JScrollPane empresasScroll = new JScrollPane(); + empresasScroll.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Empresa" ) ); + empresasScroll.setViewportView( empresasTable ); + empresasScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + empresasScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + empresasScroll.getVerticalScrollBar().setBlockIncrement(20); + + estabelecimentosModel = new VectorTableModel( new String[]{ "Nome" } ); + estabelecimentosTable = new BaseTable( estabelecimentosModel ); + estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + estabelecimentosTable.setNonResizableNorReordable(); + estabelecimentosTable.getSelectionModel().addListSelectionListener( this ); + JScrollPane estabelecimentosScroll = new JScrollPane(); + estabelecimentosScroll.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Estabelecimento" ) ); + estabelecimentosScroll.setViewportView( estabelecimentosTable ); + estabelecimentosScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + estabelecimentosScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + + pesquisarButton = new JButton( "Pesquisar" ); + pesquisarButton.addActionListener( this ); + excelButton = new JButton( "Exportar" ); + excelButton.addActionListener( this ); + + resultadoText = new JEditorPane( "text/html", "" ); + resultadoText.setEditable( false ); +// resultadoText.setLineWrap( true ); +// resultadoText.setWrapStyleWord( true ); + new CopyPasteHandler( resultadoText ); + JScrollPane resultadoScroll = new JScrollPane(); + resultadoScroll.setViewportView( resultadoText ); + resultadoScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ); + resultadoScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + + JPanel pad; + + GridBagLayout gridbag = new GridBagLayout(); + getContentPane().setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 5, 5, 5, 5 ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + + JPanel escolhaEstatisticaPanel = new JPanel(); + escolhaEstatisticaPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); + escolhaEstatisticaPanel.add( estatisticaLabel ); + escolhaEstatisticaPanel.add( estatisticaCombo ); + gridbag.setConstraints( escolhaEstatisticaPanel, constraints ); + getContentPane().add( escolhaEstatisticaPanel ); + + JPanel periodoPanel = new JPanel(); + periodoPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); + periodoPanel.add( intervalo1Label ); + periodoPanel.add( dataInicioPanel ); + periodoPanel.add( intervalo2Label ); + periodoPanel.add( dataFimPanel ); + gridbag.setConstraints( periodoPanel, constraints ); + getContentPane().add( periodoPanel ); + + JPanel anoPanel = new JPanel(); + anoPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); + anoPanel.add( anoLabel ); + anoPanel.add( anoText ); + gridbag.setConstraints( anoPanel, constraints ); + getContentPane().add( anoPanel ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0.2; + constraints.gridheight = 2; + constraints.weightx = 0.3; + constraints.gridwidth = 3; + gridbag.setConstraints( empresasScroll, constraints ); + getContentPane().add( empresasScroll ); + + gridbag.setConstraints( estabelecimentosScroll, constraints ); + getContentPane().add( estabelecimentosScroll ); + + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + getContentPane().add( pad ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0; + constraints.gridwidth = 1; + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout( new GridLayout( 1, 1 ) ); + buttonPanel.add( pesquisarButton ); + buttonPanel.add( excelButton ); + gridbag.setConstraints( buttonPanel, constraints ); + getContentPane().add( buttonPanel ); + + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + getContentPane().add( pad ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0.8; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( resultadoScroll, constraints ); + getContentPane().add( resultadoScroll ); + + processarEscolha(); + } + + public void actionPerformed(java.awt.event.ActionEvent e) + { + Object source = e.getSource(); + if( source.equals( pesquisarButton ) ) + { + int index = estatisticaCombo.getSelectedIndex(); + switch( index ) + { + case LISTAGEM_GERAL_MARCACOES_PERIODO: + listagemGeralMarcacoesPeriodo(); + break; + + case LISTAGEM_MARCACOES_PERIODO_EMPRESA_ESTABELECIMENTO: + listagemMarcacoesPeriodoEmpresaEstabelecimento(); + break; + + case LISTAGEM_GLOBAL_TRABALHADORES_SEM_EXAMES: + listagemGeralTrabalhadoresSemExamesOuConsultas( true ); + break; + + case LISTAGEM_TRABALHADORES_SEM_EXAMES_EMPRESA_ESTABELECIMENTO: + listagemTrabalhadoresSemExamesOuConsultasEmpresaEstabelecimento( true ); + break; + + case LISTAGEM_GLOBAL_TRABALHADORES_COM_EXAMES_PERIODO: + listagemGeralTrabalhadoresComExamesOuConsultasPeriodo( true ); + break; + + case LISTAGEM_TRABALHADORES_COM_EXAMES_PERIODO_EMPRESA_ESTABELECIMENTO: + listagemGeralTrabalhadoresComExamesOuConsultasPeriodoEmpresaEstabelecimento( true ); + break; + + case LISTAGEM_GLOBAL_TRABALHADORES_SEM_CONSULTA: + listagemGeralTrabalhadoresSemExamesOuConsultas( false ); + break; + + case LISTAGEM_TRABALHADORES_SEM_CONSULTA_EMPRESA_ESTABELECIMENTO: + listagemTrabalhadoresSemExamesOuConsultasEmpresaEstabelecimento( false ); + break; + + case LISTAGEM_GLOBAL_TRABALHADORES_COM_CONSULTA_PERIODO: + listagemGeralTrabalhadoresComExamesOuConsultasPeriodo( false ); + break; + + case LISTAGEM_TRABALHADORES_COM_CONSULTA_PERIODO_EMPRESA_ESTABELECIMENTO: + listagemGeralTrabalhadoresComExamesOuConsultasPeriodoEmpresaEstabelecimento( false ); + break; + + case LISTAGEM_GLOBAL_TRABALHADORES_PERIODO: + listagemGeralTrabalhadoresPeriodo(); + break; + + case LISTAGEM_GLOBAL_HIGIENE_SEGURANCA: + listagemGlobalHigieneSeguranca(); + break; + } + } + else if( source.equals( excelButton ) ) + { + exportar(); + } + } + + private boolean close() + { + setVisible( false ); + dispose(); + return true; + } + + public boolean closeIfPossible() + { + return close(); + } + + public void open() + { + empresasTable.clearSelection(); + estatisticaCombo.setSelectedIndex( 0 ); + try + { + IDObject empresas[] = pesquisasProvider.getAllEmpresas(); + empresasModel.setValues( new Vector( Arrays.asList( empresas ) ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados", true ); + } + setVisible( true ); + } + + public void refresh() + { + setVisible( true ); + } + + public void valueChanged(javax.swing.event.ListSelectionEvent e) + { + Object source = e.getSource(); + if( source.equals( empresasTable.getSelectionModel() ) ) + { + estabelecimentosTable.clearSelection(); + int selected = empresasTable.getSelectedRow(); + if( selected == -1 ) + { + return; + } + IDObject empresa = (IDObject) empresasModel.getRowAt( selected ); + estabelecimentosModel.clearAll(); + IDObject estabelecimentos[]; + try + { + estabelecimentos = pesquisasProvider.getAllEstabelecimentosForEmpresa( empresa.getID() ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os estabelecimentos", true ); + return; + } + Vector v = new Vector( Arrays.asList( estabelecimentos ) ); + v.add( new MappableObject( new Integer( -1 ), "TODOS" ) ); + estabelecimentosModel.setValues( v ); + } + } + + public void itemStateChanged(java.awt.event.ItemEvent itemEvent) + { + processarEscolha(); + } + + protected void processarEscolha() + { + int index = estatisticaCombo.getSelectedIndex(); + boolean optionLine[] = ESTATISTICAS_OPTIONS[ index ]; + dataInicioPanel.setEnabled( optionLine[ OPTION_INTERVALO ] ); + dataFimPanel.setEnabled( optionLine[ OPTION_INTERVALO ] ); + anoText.setEnabled( optionLine[ OPTION_ANO ] ); + empresasTable.setEnabled( optionLine[ OPTION_EMPRESA ] ); + estabelecimentosTable.setEnabled( optionLine[ OPTION_ESTABELECIMENTO ] ); + pesquisarButton.setEnabled( index != NONE ); + } + + protected void listagemGeralMarcacoesPeriodo() + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + if( inicio == null || fim == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher o intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + StringBuffer buffer = new StringBuffer(); + int exames = provider.countExamesPeriodo( inicio, fim ); + int consultas = provider.countConsultasPeriodo( inicio, fim ); + int total = exames + consultas; + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ LISTAGEM_GERAL_MARCACOES_PERIODO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + buffer.append( "EXAMES:" ); + buffer.append( "" ); + buffer.append( "" + exames + "" ); + buffer.append( "
" ); + buffer.append( "CONSULTAS:" ); + buffer.append( "" ); + buffer.append( "" + consultas + "" ); + buffer.append( "
" ); + buffer.append( "TOTAL:" ); + buffer.append( "" ); + buffer.append( "" + ( exames + consultas ) + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getMarcacoesPeriodo( inicio, fim ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 0; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "EMPRESA" ); + buffer.append( "" ); + buffer.append( "NOME" ); + buffer.append( "" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "DATA" ); + buffer.append( "" ); + buffer.append( " " ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemMarcacoesPeriodoEmpresaEstabelecimento() + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + int sEmpresa = empresasTable.getSelectedRow(); + int sEstabelecimento = estabelecimentosTable.getSelectedRow(); + if( inicio == null || fim == null || sEmpresa == -1 ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher Empresa e intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + StringBuffer buffer = new StringBuffer(); + Integer idEmpresa = ( (IDObject)empresasModel.getRowAt( sEmpresa ) ).getID(); + EmpresaData empresa = (EmpresaData)JDO.load( EmpresaData.class, idEmpresa ); + String designacao = (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ); + IDObject estabelecimentos[]; + if( sEstabelecimento == -1 || ( ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ) ).getID().equals( new Integer( -1 ) ) ) + { + estabelecimentos = pesquisasProvider.getAllEstabelecimentosForEmpresa( idEmpresa ); + } + else + { + estabelecimentos = new IDObject[ 1 ]; + estabelecimentos[ 0 ] = ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ); + } + int examesEmpresa = provider.countExamesPeriodoForEmpresa( inicio, fim, idEmpresa ); + int consultasEmpresa = provider.countConsultasPeriodoForEmpresa( inicio, fim, idEmpresa ); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ LISTAGEM_MARCACOES_PERIODO_EMPRESA_ESTABELECIMENTO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "EMPRESA:" ); + buffer.append( "" ); + buffer.append( "" + designacao + "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + buffer.append( "EXAMES:" ); + buffer.append( "" ); + buffer.append( "" + examesEmpresa + "" ); + buffer.append( "
" ); + buffer.append( "CONSULTAS:" ); + buffer.append( "" ); + buffer.append( "" + consultasEmpresa + "" ); + buffer.append( "
" ); + buffer.append( "TOTAL:" ); + buffer.append( "" ); + buffer.append( "" + ( examesEmpresa + consultasEmpresa ) + "" ); + buffer.append( "
" ); + for( int e = 0; e < estabelecimentos.length; e++ ) + { + EstabelecimentoData estabelecimento = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, estabelecimentos[ e ].getID() ); + String nome = (String)estabelecimento.get( EstabelecimentoData.NOME ); + int exames = provider.countExamesPeriodoForEstabelecimento( inicio, fim, estabelecimentos[ e ].getID() ); + int consultas = provider.countConsultasPeriodoForEstabelecimento( inicio, fim, estabelecimentos[ e ].getID() ); + int total = exames + consultas; + buffer.append( "



" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "ESTABELECIMENTO:" ); + buffer.append( "" ); + buffer.append( "" + nome + "" ); + buffer.append( "
" ); + buffer.append( "EXAMES:" ); + buffer.append( "" ); + buffer.append( "" + exames + "" ); + buffer.append( "
" ); + buffer.append( "CONSULTAS:" ); + buffer.append( "" ); + buffer.append( "" + consultas + "" ); + buffer.append( "
" ); + buffer.append( "TOTAL:" ); + buffer.append( "" ); + buffer.append( "" + ( exames + consultas ) + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getMarcacoesPeriodoForEstabelecimento( inicio, fim, estabelecimentos[ e ].getID() ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 1; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "NOME" ); + buffer.append( "" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "DATA" ); + buffer.append( "" ); + buffer.append( " " ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + } + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemGeralTrabalhadoresSemExamesOuConsultas( boolean exames ) + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + if( inicio == null || fim == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher o intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + int count = provider.countTrabalhadoresSemExamesOuConsultas( inicio, fim, exames ); + //String data[][] = provider.getTrabalhadoresComExamesOuConsultasPeriodo( inicio, fim, exames ); + Object data[][] = provider.getCountTrabalhadoresSemExamesOuConsultasPeriodoForAllEmpresas( inicio, fim, exames ); + StringBuffer buffer = new StringBuffer(); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ exames ? LISTAGEM_GLOBAL_TRABALHADORES_SEM_EXAMES : LISTAGEM_GLOBAL_TRABALHADORES_SEM_CONSULTA ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + buffer.append( "TOTAL:" ); + buffer.append( "" ); + buffer.append( "" + count + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "EMPRESA" ); + buffer.append( "" ); + buffer.append( "N\u00ba" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ 0 ] + "" ); + buffer.append( "" ); + buffer.append( "" + data[ l ][ 1 ] + "" ); + buffer.append( "
" ); + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemTrabalhadoresSemExamesOuConsultasEmpresaEstabelecimento( boolean exames ) + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + if( inicio == null || fim == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher o intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + int sEmpresa = empresasTable.getSelectedRow(); + int sEstabelecimento = estabelecimentosTable.getSelectedRow(); + if( sEmpresa == -1 ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher Empresa.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + StringBuffer buffer = new StringBuffer(); + Integer idEmpresa = ( (IDObject)empresasModel.getRowAt( sEmpresa ) ).getID(); + EmpresaData empresa = (EmpresaData)JDO.load( EmpresaData.class, idEmpresa ); + String designacao = (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ); + IDObject estabelecimentos[]; + if( sEstabelecimento == -1 || ( ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ) ).getID().equals( new Integer( -1 ) ) ) + { + estabelecimentos = pesquisasProvider.getAllEstabelecimentosForEmpresa( idEmpresa ); + } + else + { + estabelecimentos = new IDObject[ 1 ]; + estabelecimentos[ 0 ] = ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ); + } + int countEmpresa = provider.countTrabalhadoresSemExamesOuConsultasEmpresa( idEmpresa, inicio, fim, exames ); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ exames ? LISTAGEM_TRABALHADORES_SEM_EXAMES_EMPRESA_ESTABELECIMENTO : LISTAGEM_TRABALHADORES_SEM_CONSULTA_EMPRESA_ESTABELECIMENTO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "EMPRESA:" ); + buffer.append( "" ); + buffer.append( "" + designacao + "" ); + buffer.append( "
" ); + buffer.append( "Nº DE TRABALHADORES:" ); + buffer.append( "" ); + buffer.append( "" + countEmpresa + "" ); + buffer.append( "
" ); + for( int e = 0; e < estabelecimentos.length; e++ ) + { + EstabelecimentoData estabelecimento = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, estabelecimentos[ e ].getID() ); + String nome = (String)estabelecimento.get( EstabelecimentoData.NOME ); + int countEstabelecimento = provider.countTrabalhadoresSemExamesOuConsultasEstabelecimento( estabelecimentos[ e ].getID(), inicio, fim, exames ); + buffer.append( "



" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "ESTABELECIMENTO:" ); + buffer.append( "" ); + buffer.append( "" + nome + "" ); + buffer.append( "
" ); + buffer.append( "Nº DE TRABALHADORES:" ); + buffer.append( "" ); + buffer.append( "" + countEstabelecimento + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getTrabalhadoresSemExamesOuConsultasEstabelecimento( estabelecimentos[ e ].getID(), inicio, fim, exames ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 0; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "NOME" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + } + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemGeralTrabalhadoresComExamesOuConsultasPeriodo( boolean exames ) + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + if( inicio == null || fim == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher o intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + int count = provider.countTrabalhadoresComExamesOuConsultasPeriodo( inicio, fim, exames ); + //String data[][] = provider.getTrabalhadoresComExamesOuConsultasPeriodo( inicio, fim, exames ); + Object data[][] = provider.getCountTrabalhadoresComExamesOuConsultasPeriodoForAllEmpresas( inicio, fim, exames ); + StringBuffer buffer = new StringBuffer(); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ exames ? LISTAGEM_GLOBAL_TRABALHADORES_COM_EXAMES_PERIODO : LISTAGEM_GLOBAL_TRABALHADORES_COM_CONSULTA_PERIODO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + buffer.append( "TOTAL:" ); + buffer.append( "" ); + buffer.append( "" + count + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "EMPRESA" ); + buffer.append( "" ); + buffer.append( "N\u00ba" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ 0 ] + "" ); + buffer.append( "" ); + buffer.append( "" + data[ l ][ 1 ] + "" ); + buffer.append( "
" ); + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemGeralTrabalhadoresComExamesOuConsultasPeriodoEmpresaEstabelecimento( boolean exames ) + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + int sEmpresa = empresasTable.getSelectedRow(); + int sEstabelecimento = estabelecimentosTable.getSelectedRow(); + if( inicio == null || fim == null || sEmpresa == -1 ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher Empresa e intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + StringBuffer buffer = new StringBuffer(); + Integer idEmpresa = ( (IDObject)empresasModel.getRowAt( sEmpresa ) ).getID(); + EmpresaData empresa = (EmpresaData)JDO.load( EmpresaData.class, idEmpresa ); + String designacao = (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ); + IDObject estabelecimentos[]; + if( sEstabelecimento == -1 || ( ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ) ).getID().equals( new Integer( -1 ) ) ) + { + estabelecimentos = pesquisasProvider.getAllEstabelecimentosForEmpresa( idEmpresa ); + } + else + { + estabelecimentos = new IDObject[ 1 ]; + estabelecimentos[ 0 ] = ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ); + } + int countEmpresa = provider.countTrabalhadoresComExamesOuConsultasPeriodoForEmpresa( inicio, fim, idEmpresa, exames ); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ exames ? LISTAGEM_TRABALHADORES_COM_EXAMES_PERIODO_EMPRESA_ESTABELECIMENTO : LISTAGEM_TRABALHADORES_COM_CONSULTA_PERIODO_EMPRESA_ESTABELECIMENTO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "
" ); + buffer.append( "EMPRESA:" ); + buffer.append( "" ); + buffer.append( "" + designacao + "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + buffer.append( "Nº:" ); + buffer.append( "" ); + buffer.append( "" + countEmpresa + "" ); + buffer.append( "
" ); + for( int e = 0; e < estabelecimentos.length; e++ ) + { + EstabelecimentoData estabelecimento = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, estabelecimentos[ e ].getID() ); + String nome = (String)estabelecimento.get( EstabelecimentoData.NOME ); + int countEstabelecimento = provider.countTrabalhadoresComExamesOuConsultasPeriodoForEstabelecimento( inicio, fim, estabelecimentos[ e ].getID(), exames ); + buffer.append( "



" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "ESTABELECIMENTO:" ); + buffer.append( "" ); + buffer.append( "" + nome + "" ); + buffer.append( "
" ); + buffer.append( "Nº:" ); + buffer.append( "" ); + buffer.append( "" + countEstabelecimento + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getTrabalhadoresComExamesOuConsultasPeriodoForEstabelecimento( inicio, fim, estabelecimentos[ e ].getID(), exames ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 0; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "NOME" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + } + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemGeralTrabalhadoresPeriodo() + { + try + { + Date inicio = dataInicioPanel.getDate(); + Date fim = dataFimPanel.getDate(); + if( inicio == null || fim == null ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher o intervalo de datas.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + if( inicio.after( fim ) ) + { + JOptionPane.showMessageDialog( this, "A data de in\u00edcio tem de ser inferior \u00e0 de fim..", "Erro...", + JOptionPane.ERROR_MESSAGE ); + resultadoText.setText( "ERRO!" ); + return; + } + StringBuffer buffer = new StringBuffer(); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ LISTAGEM_GLOBAL_TRABALHADORES_PERIODO ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "
" ); + buffer.append( "PER\u00cdODO:" ); + buffer.append( "" ); + buffer.append( "" + DF.format( dataInicioPanel.getDate() ) + " a " + + DF.format( dataFimPanel.getDate() ) + "" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getDadosTrabalhadoresPeriodo( inicio, fim ); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 0; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "EMPRESA" ); + buffer.append( "" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "NOME" ); + buffer.append( "" ); + buffer.append( "ÚLTIMO EXAME" ); + buffer.append( "" ); + buffer.append( "ESTADO" ); + buffer.append( "" ); + buffer.append( "ÚLTIMA CONSULTA" ); + buffer.append( "" ); + buffer.append( "ESTADO" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + protected void listagemGlobalHigieneSeguranca() + { + try + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "

" ); + buffer.append( "" + ESTATISTICAS[ LISTAGEM_GLOBAL_HIGIENE_SEGURANCA ] + "" ); + buffer.append( "

" ); + buffer.append( "
" ); + + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + buffer.append( "" ); + String data[][] = provider.getDadosHigieneSeguranca(); + for( int l = 0; l < data.length; l++ ) + { + buffer.append( "" ); + for( int c = 0; c < data[ l ].length; c++ ) + { + buffer.append( "" ); + buffer.append( "" ); + } + buffer.append( "" ); + } + buffer.append( "
" ); + buffer.append( "EMPRESA" ); + buffer.append( "" ); + buffer.append( "ESTABELECIMENTO" ); + buffer.append( "" ); + buffer.append( "ÚLTIMA AUDITORIA" ); + buffer.append( "" ); + buffer.append( "ESTADO" ); + buffer.append( "" ); + buffer.append( "RELATÓRIO" ); + buffer.append( "" ); + buffer.append( "PRÓXIMA AUDITORIA" ); + buffer.append( "
" ); + buffer.append( "" + data[ l ][ c ] + "" ); + buffer.append( "
" ); + resultadoText.setText( buffer.toString() ); + } + catch( Exception ex ) + { + resultadoText.setText( "ERRO a carregar dados!" ); + ex.printStackTrace(); + } + } + + public void exportar() + { + FileDialog dialog = new FileDialog( this, "Ficheiro de destino", FileDialog.SAVE ); + dialog.setDirectory( System.getProperty( "user.home" ) ); + dialog.setVisible( true ); + String fileName; + String dirName; + fileName = dialog.getFile(); + dirName = dialog.getDirectory(); + if( fileName != null ) + { + int index = fileName.indexOf( '.' ); + if( index == -1 ) + { + fileName += ".html"; + } + if( index == fileName.length() - 1 ) + { + fileName += "html"; + } + String fullName = dirName + fileName; + String text = resultadoText.getText(); + String title = "S.I.P.R.P. - Sociedade Ibérica de Prevenção de Riscos Profissionais"; + String style = ""; + text = text.replace( "", "\n\t\t" + title + "\n" + style ); + text = text.replace( "", "
" ); + text = text.replace( "", "
" ); +// System.out.println( text ); + try + { + FileWriter writer = new FileWriter( new File( fullName ) ); + writer.write( text ); + writer.close(); + } + catch( IOException ex ) + { + DialogException.showException( ex ); + return; + } + } + } +} \ No newline at end of file diff --git a/trunk/siprp/higiene/HigieneDataProvider.java b/trunk/siprp/higiene/HigieneDataProvider.java new file mode 100644 index 00000000..60b2074b --- /dev/null +++ b/trunk/siprp/higiene/HigieneDataProvider.java @@ -0,0 +1,255 @@ +/* + * HigieneDataProvider.java + * + * Created on February 1, 2006, 10:49 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene; + +import java.awt.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.strings.*; +import com.evolute.utils.tables.*; + +import siprp.*; +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class HigieneDataProvider extends MetaProvider +{ + public static final int ESTADO_POR_REALIZAR = 0; + public static final int ESTADO_REALIZADO = 2; + public static final int ESTADO_DESMARCADO_TRABALHADOR = 3; + public static final int ESTADO_DESMARCADO_EMPRESA = 4; + public static final int ESTADO_FALTOU = 5; + + public static final String ESTADOS_STR[] = + new String[]{ "Por realizar", "", "Realizada", + "Desmarcada empresa", + "Desmarcada " + Singleton.getInstance( SingletonConstants.COMPANY_ACRONYM ), + "Faltou" }; + + public static final Color CORES_TECNICOS[] = + new Color[]{ Color.white, Color.red.darker(), Color.blue, + Color.green.darker(), Color.yellow.darker(), + Color.gray, Color.pink.darker() }; + + private static final Object LOCK = new Object(); + private static HigieneDataProvider instance = null; + private final Executer executer; + + /** Creates a new instance of HigieneDataProvider */ + public HigieneDataProvider() + throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + executer = dbm.getSharedExecuter( this ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new HigieneDataProvider(); + } + } + return instance; + } + + public Object[][] getAllTecnicosHST() + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_tecnicos_hst" }, + new String[]{ "id", "nome", "iniciais", "identificador", "nome_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "nome_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + return array.getObjects(); + } + + public ColumnizedMappable[] getAllEmpresas() + throws Exception + { + Select select = + new Select( new String[]{ "empresas" }, + new String[]{ "id", "designacao_social", "designacao_social_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "designacao_social_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + ColumnizedMappable empresas[] = new ColumnizedMappable[ array.columnLength() ]; + for( int n = 0; n < empresas.length; n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String designacao = ( String ) array.get( n, 1 ); + empresas[ n ] = new ColumnizedMappable( id, designacao ); + } + return empresas; + } + + public ColumnizedMappable[] getAllEstabelecimentosForEmpresa( Integer empresaID ) + throws Exception + { + Select select = + new Select( new String[]{ "estabelecimentos" }, + new String[]{ "id", "nome", "nome_plain" }, + new Field( "empresa_id" ).isEqual( empresaID ).and( + new Field( "inactivo" ).isDifferent( "y" ) ), + new String[]{ "nome_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + ColumnizedMappable estabelecimentos[] = new ColumnizedMappable[ array.columnLength() ]; + for( int n = 0; n < estabelecimentos.length; n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String nome = ( String ) array.get( n, 1 ); + estabelecimentos[ n ] = new ColumnizedMappable( id, nome ); + } + return estabelecimentos; + } + + public String getEmpresa( Integer empresaID ) + throws Exception + { + String nomes[] = new String[ 2 ]; + Select select = new Select( new String[]{ "empresas" }, + new String[]{ "designacao_social" }, + new Field( "id" ).isEqual( empresaID ) ); + Virtual2DArray array = executer.executeQuery( select ); + return ( String ) array.get( 0, 0 ); + } + + public Object[][] getVisitasEstabelecimento( Integer estabelecimentoID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_estabelecimento" }, + new String[]{ "id", "data", "estado" }, + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ), + new String[]{ "data desc" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + Object data[][] = array.getObjects(); + for( int n = 0; n < data.length; n++ ) + { + int estado = ( ( Integer ) data[ n ][ 2 ] ).intValue(); + data[ n ][ 2 ] = ESTADOS_STR[ estado ]; + } + return data; + } + + public Vector[][] getMapaAnual( Integer ano ) + throws Exception + { + String deleted = "__DELETED__"; + Select select = + new Select( new String[]{ "marcacoes_tecnicos_hst" }, + new String[]{ "id", "nome", "iniciais", "identificador", "nome_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "nome_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + Object tecnicosArr[][] = array.getObjects(); + Hashtable tecnicos = new Hashtable(); + for( int n = 0; n < tecnicosArr.length; n++ ) + { + tecnicos.put( tecnicosArr[ n ][ 0 ], tecnicosArr[ n ] ); + } + Hashtable empresas = new Hashtable(); + Hashtable estabelecimentos = new Hashtable(); + Hashtable empresasEstabelecimentos = new Hashtable(); + Vector data[][] = new Vector[ 31 ][ 12 ]; + select = new Select( new String[]{ "marcacoes_estabelecimento" }, + new String[]{ "data", "estabelecimento_id", "tecnico_hst" }, + new Field( "data" ).between( new Object[]{ ano + "-01-01", ano + "-12-31" } ).and( + new Field( "estado" ).in( new Integer[]{ new Integer( 0 ), new Integer( 2 ) } ) ) ); + array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Date dataVisita = ( Date ) array.get( n, 0 ); + Integer estabelecimentoID = ( Integer ) array.get( n, 1 ); + Integer tecnicoID = ( Integer ) array.get( n, 2 ); + Integer empresaID = null; + if( !estabelecimentos.containsKey( estabelecimentoID ) ) + { + Select estabelecimentoSelect = + new Select( new String[]{ "estabelecimentos" }, + new String[]{ "nome", "empresa_id", "inactivo" }, + new Field( "id" ).isEqual( estabelecimentoID ) ); + Virtual2DArray estabelecimentoArray = executer.executeQuery( estabelecimentoSelect ); + if( "y".equals( estabelecimentoArray.get( 0, 2 ) ) ) + { + estabelecimentos.put( estabelecimentoID, deleted ); + } + else + { + estabelecimentos.put( estabelecimentoID, estabelecimentoArray.get( 0, 0 ) ); + } + empresaID = ( Integer ) estabelecimentoArray.get( 0, 1 ); + empresasEstabelecimentos.put( estabelecimentoID, empresaID ); + if( !empresas.containsKey( empresaID ) ) + { + Select empresaSelect = + new Select( new String[]{ "empresas" }, + new String[]{ "designacao_social", "inactivo" }, + new Field( "id" ).isEqual( empresaID ) ); + Virtual2DArray empresaArray = executer.executeQuery( empresaSelect ); + if( "y".equals( empresaArray.get( 0, 1 ) ) ) + { + empresas.put( empresaID, deleted ); + } + else + { + empresas.put( empresaID, empresaArray.get( 0, 0 ) ); + } + } + } + String nomeEstabelecimento = ( String ) estabelecimentos.get( estabelecimentoID ); + empresaID = ( Integer ) empresasEstabelecimentos.get( estabelecimentoID ); + String nomeEmpresa = ( String ) empresas.get( empresaID ); + String nomeTecnico = " "; + Integer indiceCor = null; + Color cor = null; + if( tecnicoID != null ) + { + Object tecnico[] = ( Object[] ) tecnicos.get( tecnicoID ); + nomeTecnico = ( String ) tecnico[ 1 ]; + indiceCor = ( Integer ) tecnico[ 3 ]; + cor = CORES_TECNICOS[ indiceCor.intValue() ]; + } + Calendar cal = Calendar.getInstance(); + cal.setTime( dataVisita ); + int dia = cal.get( Calendar.DAY_OF_MONTH ) - 1; + int mes = cal.get( Calendar.MONTH ); + if( data[ dia ][ mes ] == null ) + { + data[ dia ][ mes ] = new Vector(); + data[ dia ][ mes ].add( new Object[]{ new Integer( dia + 1 ) } ); + } + if( nomeEmpresa != deleted && nomeEstabelecimento != deleted ) + { + data[ dia ][ mes ].add( new Object[]{ nomeEmpresa, nomeEstabelecimento, nomeTecnico, cor } ); + } + } + + return data; + } +} diff --git a/trunk/siprp/higiene/alter2.sql b/trunk/siprp/higiene/alter2.sql new file mode 100644 index 00000000..6166400d --- /dev/null +++ b/trunk/siprp/higiene/alter2.sql @@ -0,0 +1,18 @@ + +CREATE TABLE marcacoes_tecnicos_hst +( + id int4 NOT NULL, + nome varchar(255) NOT NULL, + nome_plain varchar(255) NOT NULL, + iniciais varchar(10) NOT NULL, + identificador int4, + inactivo char(1) DEFAULT 'n' NOT NULL, + CONSTRAINT marcacoes_tecnicos_hst_pkey PRIMARY KEY (id) +) +WITHOUT OIDS; +ALTER TABLE marcacoes_tecnicos_hst OWNER TO postgres; + +ALTER TABLE marcacoes_estabelecimento ADD estado INT; +ALTER TABLE marcacoes_estabelecimento ADD tecnico_hst INT REFERENCES marcacoes_tecnicos_hst(id); +ALTER TABLE marcacoes_estabelecimento ADD observacoes VARCHAR( 2048 ); +UPDATE marcacoes_estabelecimento SET estado = 2 WHERE realizada = 'y'; \ No newline at end of file diff --git a/trunk/siprp/higiene/mapa/DiaLine.java b/trunk/siprp/higiene/mapa/DiaLine.java new file mode 100644 index 00000000..7eb4a647 --- /dev/null +++ b/trunk/siprp/higiene/mapa/DiaLine.java @@ -0,0 +1,62 @@ +/* + * DiaLine.java + * + * Created on 8 de Fevereiro de 2006, 22:43 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.util.*; + +import com.evolute.utils.tables.*; + +/** + * + * @author Frederico + */ +public class DiaLine implements ColumnizedObjectForUpdate +{ + protected Integer day; + protected Vector data[]; + + /** Creates a new instance of DiaLine */ + public DiaLine( int day, Vector data[] ) + { + this.day = new Integer( day ); + this.data = data; + } + + public Object getValue( int col ) + { + switch( col ) + { + case 0: + return day; + + default: + return data[ col - 1 ].toArray( new Object[ 0 ][] ); + } + } + + public int[] getUpdateableColumns() + { + return new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + } + + public void setValueAt( Object value, int col ) + { +// data[ col - 1 ].clear(); + if( value != null && value instanceof Vector ) + { + data[ col - 1 ].addAll( ( Vector ) value ); + } + } + + public void clear( int col ) + { + data[ col - 1 ].clear(); + } +} diff --git a/trunk/siprp/higiene/mapa/DiaPanel.java b/trunk/siprp/higiene/mapa/DiaPanel.java new file mode 100644 index 00000000..05c508b4 --- /dev/null +++ b/trunk/siprp/higiene/mapa/DiaPanel.java @@ -0,0 +1,101 @@ +/* + * DiaPanel.java + * + * Created on February 1, 2006, 6:42 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import com.evolute.utils.dataui.*; +/** + * + * @author fpalma + */ +public class DiaPanel extends JPanel + implements ControllableComponent, ActionListener +{ + protected Object data[][]; + protected JButton buttons[]; + + /** Creates a new instance of DiaPanel */ + public DiaPanel() + { + } + + private void setupComponents() + { + } + + public void setEnabled( boolean enable ) + { + } + + public void fill( Object value ) + { + removeAll(); + Object arr[][] = ( Object[][] ) value; + data = arr; + buttons = new JButton[ arr.length ]; + if( arr.length > 0 ) + { + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 0, 0, 0, 0 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weighty = 0; + constraints.gridheight = 1; + Integer dia = ( Integer ) arr[ 0 ][ 0 ]; + JLabel diaLabel = new JLabel( dia.toString(), JLabel.LEFT ); + gridbag.setConstraints( diaLabel, constraints ); + add( diaLabel ); + for( int n = 1; n < arr.length; n++ ) + { + String empresa = ( String ) arr[ n ][ 0 ]; + String estabelecimento = ( String ) arr[ n ][ 1 ]; + String tecnico = ( String ) arr[ n ][ 2 ]; + Color cor = ( Color ) arr[ n ][ 3 ]; + String empresaR = empresa.length() > 10 ? empresa.substring( 0, 10 ) : empresa; + String estabelecimentoR = estabelecimento.length() > 10 ? estabelecimento.substring( 0, 10 ) : estabelecimento; + buttons[ n ] = new JButton( "" + empresaR + "
" + estabelecimentoR + "
" ); + buttons[ n ].setMargin( new Insets( 2, 1, 2, 1 ) ); + buttons[ n ].setBackground( cor ); + buttons[ n ].setToolTipText( "T\u00e9cnico: " + ( tecnico != null ? tecnico : "n.d." ) + + " \nEmpresa: " + empresa + " \nEstabelecimento: " + estabelecimento ); + gridbag.setConstraints( buttons[ n ], constraints ); + add( buttons[ n ] ); + buttons[ n ].addActionListener( this ); + } + JPanel pad = new JPanel(); + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints( pad, constraints ); + add( pad ); + } + + } + + public Object save() + { + return data; + } + + public void clear() + { + } + + public void actionPerformed( ActionEvent e ) + { + JButton source = ( JButton ) e.getSource(); + JOptionPane.showMessageDialog( source, source.getToolTipText(), "", JOptionPane.PLAIN_MESSAGE ); + } +} diff --git a/trunk/siprp/higiene/mapa/DiaRenderer.java b/trunk/siprp/higiene/mapa/DiaRenderer.java new file mode 100644 index 00000000..40dc967e --- /dev/null +++ b/trunk/siprp/higiene/mapa/DiaRenderer.java @@ -0,0 +1,65 @@ +/* + * DiaRenderer.java + * + * Created on 8 de Fevereiro de 2006, 21:45 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.awt.*; +import javax.swing.*; +import javax.swing.table.*; +import java.util.*; +/** + * + * @author Frederico + */ +public class DiaRenderer extends DefaultCellEditor + implements TableCellRenderer +{ + protected JLabel diaLabel; + protected DiaPanel diaPanel; + + /** Creates a new instance of DiaRenderer */ + public DiaRenderer() + { + super( new JCheckBox() ); + diaLabel = new JLabel(); + diaPanel = new DiaPanel(); + } + + public Component getTableCellRendererComponent( JTable table, Object value, + boolean isSelected, + boolean hasFocus, + int row, int column ) + { + if( column == 0 ) + { + diaLabel.setText( "" + value ); + return diaLabel; + } + diaPanel.fill( value ); + return diaPanel; + } + + public Component getTableCellEditorComponent( JTable table, Object value, + boolean isSelected, + int row, int column ) + { + if( column == 0 ) + { + diaLabel.setText( "" + value ); + return diaLabel; + } + diaPanel.fill( value ); + return diaPanel; + } + + public Object getCellEditorValue() + { + return diaPanel.save(); + } +} diff --git a/trunk/siprp/higiene/mapa/MapaHigienePanel.java b/trunk/siprp/higiene/mapa/MapaHigienePanel.java new file mode 100644 index 00000000..05c6d67e --- /dev/null +++ b/trunk/siprp/higiene/mapa/MapaHigienePanel.java @@ -0,0 +1,112 @@ +/* + * MapaHigienePanel.java + * + * Created on 9 de Fevereiro de 2006, 0:11 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.awt.*; +import javax.swing.*; +import java.util.*; + +import com.evolute.utils.dataui.*; +import com.evolute.utils.date.*; +import com.evolute.utils.tables.*; +/** + * + * @author Frederico + */ +public class MapaHigienePanel extends JPanel + implements ControllableComponent +{ + protected BaseTable yearTable; + protected VectorTableModel yearModel; + protected JScrollPane yearScroll; + + /** Creates a new instance of MapaHigienePanel */ + public MapaHigienePanel() + throws Exception + { + setupComponents(); + } + + private void setupComponents() + throws Exception + { + String headers[] = new String[ 13 ]; + headers[ 0 ] = " "; + for( int n = 0; n < DateUtils.MONTHS_FULL_PT.length; n++ ) + { + headers[ n + 1 ] = DateUtils.MONTHS_FULL_PT[ n ]; + } + yearModel = new VectorTableModel( headers ); + yearTable = new BaseTable( yearModel ); + yearTable.fixColumnWidth( 0, 20 ); + yearTable.setNonResizableNorReordable(); +// yearTable.setEnabled( true ); + yearModel.setEditable( true ); + yearTable.setTableCellRenderer( new DiaRenderer() ); + yearTable.setTableCellEditor( new DiaRenderer() ); + yearScroll = new JScrollPane( yearTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + Vector values = yearModel.getValues(); + for( int n = 0; n < 31; n++ ) + { + Vector data[] = new Vector[ 12 ]; + for( int m = 0; m < 12; m++ ) + { + data[ m ] = new Vector(); + } + values.add( new DiaLine( n + 1, data ) ); + } + yearModel.setValues( values ); + + setLayout( new GridLayout( 1, 1 ) ); + add( yearScroll ); + } + + public void clear() + { + } + + public void setEnabled( boolean enable ) + { + yearTable.setEnabled( enable ); + } + + public void fill( Object value ) + { +// if( true ) return; + Vector arr[][] = ( Vector[][] )value; + int maxs[] = new int[ arr.length ]; + for( int r = 0; r < arr.length; r++ ) + { + maxs[ r ] = 1; + for( int c = 0; c < arr[ r ].length; c++ ) + { + if( arr[ r ][ c ] != null && arr[ r ][ c ].size() > maxs[ r ] ) + { + maxs[ r ] = arr[ r ][ c ].size(); + } + DiaLine line = ( DiaLine ) yearModel.getRowAt( r ); + line.clear( c + 1 ); + line.setValueAt( arr[ r ][ c ], c + 1 ); + yearModel.removeRowAt( r ); + yearModel.insertRowAt( line, r ); + } + } + for( int r = 0; r < arr.length; r++ ) + { + yearTable.setRowHeight( r, 20 + ( maxs[ r ] - 1 ) * 40 ); + } + } + + public Object save() + { + return null; + } +} diff --git a/trunk/siprp/higiene/mapa/MapaHigieneWindow.java b/trunk/siprp/higiene/mapa/MapaHigieneWindow.java new file mode 100644 index 00000000..26612fc7 --- /dev/null +++ b/trunk/siprp/higiene/mapa/MapaHigieneWindow.java @@ -0,0 +1,139 @@ +/* + * MarcacoesHigieneWindow.java + * + * Created on January 31, 2006, 11:32 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.documents.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.window.*; + +import siprp.higiene.*; + +/** + * + * @author fpalma + */ +public class MapaHigieneWindow extends EditorWindow + implements ActionListener +{ + public final static String TITLE = "Mapa de Higiene e Seguran\u00e7a"; + + private final static int iPermissionArray[][] = + new int[][]{ { } }; + + protected MapaHigienePanel mainPanel; + protected JTextField anoText; + protected JButton actualizarButton; + + protected HigieneDataProvider provider; + + public static void main( String args[] ) + throws Exception + { + + JFrame frm = new MapaHigieneWindow(); + frm.setVisible( true ); + } + + /** Creates a new instance of MarcacoesHigieneWindow */ + public MapaHigieneWindow() + throws Exception + { + super( iPermissionArray ); + provider = ( HigieneDataProvider ) HigieneDataProvider.getProvider(); + setupComponents(); + setExtendedState(getExtendedState() | MAXIMIZED_BOTH); + } + + private void setupComponents() + throws Exception + { + setTitle( TITLE ); + JPanel upperPanel = new JPanel(); + mainPanel = new MapaHigienePanel(); + getContentPane().setLayout( new BorderLayout() ); + getContentPane().add( upperPanel, BorderLayout.NORTH ); + getContentPane().add( mainPanel, BorderLayout.CENTER ); + + upperPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); + upperPanel.add( new TecnicosPanel() ); + JLabel anoLabel = new JLabel( "Ano" ); + anoText = new JTextField(); + anoText.setPreferredSize( new Dimension( 50, 20 ) ); + anoText.setDocument( new YearDocument() ); + anoText.addActionListener( this ); + actualizarButton = new JButton( "Actualizar" ); + actualizarButton.addActionListener( this ); + + Calendar cal = Calendar.getInstance(); + anoText.setText( "" + cal.get( Calendar.YEAR ) ); + + JPanel pesquisaPanel = new JPanel(); + upperPanel.add( pesquisaPanel ); + pesquisaPanel.setLayout( new FlowLayout( FlowLayout.CENTER ) ); + pesquisaPanel.add( anoLabel ); + pesquisaPanel.add( anoText ); + pesquisaPanel.add( actualizarButton ); + +// Vector data[][] = new Vector[ 31 ][ 12 ]; +// for( int r = 0; r < 31; r++ ) +// { +// for( int c = 0; c < 12; c++ ) +// { +// data[ r ][ c ] = new Vector(); +// } +// } +//// Vector example = new Vector(); +//// example.add( new Object[]{ "Empresa1", "Estabelecimento1", "Pai Natal", "9:30", Color.red } ); +// data[ 20 ][ 10 ].add( new Object[]{ new Integer( 21 ) } ); +// data[ 20 ][ 10 ].add( new Object[]{ "Empresa1", "Estabelecimento1", "Pai Natal", Color.red } ); +// data[ 20 ][ 10 ].add( new Object[]{ "Empresa1", "Estabelecimento1", "Pai Natal", Color.green } ); +// data[ 20 ][ 10 ].add( new Object[]{ "Empresa1", "Estabelecimento1", "Pai Natal", Color.yellow } ); +// data[ 20 ][ 10 ].add( new Object[]{ "Empresa1", "Estabelecimento1", "Pai Natal", Color.white } ); +// mainPanel.fill( data ); + } + + public void actualizar() + { + String anoStr = anoText.getText(); + if( anoStr.length() == 0 ) + { + mainPanel.clear(); + } + else + { + Integer ano = new Integer( anoStr ); + try + { + mainPanel.fill( provider.getMapaAnual( ano ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados", true ); + mainPanel.clear(); + } + } + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( actualizarButton ) || source.equals( anoText ) ) + { + actualizar(); + } + } +} diff --git a/trunk/siprp/higiene/mapa/TecnicosPanel.java b/trunk/siprp/higiene/mapa/TecnicosPanel.java new file mode 100644 index 00000000..2cf77ab2 --- /dev/null +++ b/trunk/siprp/higiene/mapa/TecnicosPanel.java @@ -0,0 +1,63 @@ +/* + * TecnicosPanel.java + * + * Created on 12 de Fevereiro de 2006, 17:48 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.mapa; + +import java.awt.*; +import javax.swing.*; + +import siprp.higiene.*; + +/** + * + * @author Frederico + */ +public class TecnicosPanel extends JPanel +{ + protected HigieneDataProvider provider; + + /** Creates a new instance of TecnicosPanel */ + public TecnicosPanel() + throws Exception + { + provider = ( HigieneDataProvider ) HigieneDataProvider.getProvider(); + setupComponents(); + } + + private void setupComponents() + throws Exception + { + Object tecnicos[][] = provider.getAllTecnicosHST(); + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridheight = 1; + constraints.weighty = 0; + + for( int n = 0; n < tecnicos.length; n++ ) + { + constraints.weightx = 0; + constraints.gridwidth = 1; + JLabel corLabel = new JLabel( " " ); + corLabel.setBackground( HigieneDataProvider.CORES_TECNICOS[ ( ( Integer ) tecnicos[ n ][ 3 ] ).intValue() ] ); + corLabel.setOpaque( true ); + gridbag.setConstraints( corLabel, constraints ); + add( corLabel ); + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + JLabel nomeLabel = new JLabel( (String)tecnicos[ n ][ 1 ] ); + gridbag.setConstraints( nomeLabel, constraints ); + add( nomeLabel ); + + } + + } +} diff --git a/trunk/siprp/higiene/marcacoes/CorTecnicoCellRenderer.java b/trunk/siprp/higiene/marcacoes/CorTecnicoCellRenderer.java new file mode 100644 index 00000000..13d07aff --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/CorTecnicoCellRenderer.java @@ -0,0 +1,41 @@ +/* + * CorTecnicoCellRenderer.java + * + * Created on February 1, 2006, 11:13 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.marcacoes; + +import java.awt.*; +import javax.swing.*; + +import siprp.higiene.*; + +/** + * + * @author fpalma + */ +public class CorTecnicoCellRenderer extends JLabel implements ListCellRenderer +{ + + public CorTecnicoCellRenderer() + { + setOpaque(true); + } + + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) + { + setText( " " ); + Color color = HigieneDataProvider.CORES_TECNICOS[ ( ( Integer ) value ).intValue() ]; + if( cellHasFocus ) + { + color = color.darker().darker(); + } + setBackground( color ); + + return this; + } +} diff --git a/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java b/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java new file mode 100644 index 00000000..13d30081 --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.java @@ -0,0 +1,306 @@ +package siprp.higiene.marcacoes; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.db.*; +import com.evolute.utils.documents.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.panel.*; +import com.evolute.utils.ui.text.*; +import java.awt.*; +import java.util.*; +import javax.swing.*; +import siprp.data.*; + +public class MarcacaoVisitaHSTPanel + extends JPanel + implements ControllableComponent, DataClassAware +{ + private siprp.data.MarcacaoEstabelecimentoData marcacaoEstabelecimentoData; + private final ComponentsHashtable components = new ComponentsHashtable(); + + protected final SQLExecuter EXECUTER; + + private final JLabel dataLabel = new JLabel( "Data da visita", JLabel.RIGHT ); + private final JCalendarPanel dataPanel = new JCalendarPanel( null ); + private final JButton emailButton = new JButton( "Enviar Email" ); + private final JLabel dataFichaLabel = new JLabel( "Data do Relat\u00f3rio", JLabel.RIGHT ); + private final JCalendarPanel dataFichaPanel = new JCalendarPanel( null ); + private final JLabel tecnicoLabel = new JLabel( "T\u00e9cnico", JLabel.RIGHT ); + private final JComboBox tecnicoList = new JComboBox(); + private RadioButtonFixedPanel estadoList; + private final JScrollPane observacoesTextScroll = new JScrollPane(); + private final StateTextArea observacoesText = new StateTextArea(); + + public MarcacaoVisitaHSTPanel() + throws Exception + { + DBManager dbm = ( DBManager )Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); + if( dbm != null ) + { + EXECUTER = ( SQLExecuter )dbm.getSharedExecuter( this ); + } + else + { + EXECUTER = null; + } + setupComponents(); + setupComponentsHashtable(); + place(); + } + + public void setupComponents() + throws Exception + { + JComponent MarcacaoVisitaHSTPanel = this; + emailButton.setMinimumSize( new Dimension( 300, 20 ) ); + emailButton.setPreferredSize( new Dimension( 200, 20 ) ); + + tecnicoList.addItem( new MappableObject( new Integer( -1 ), "" ) ); + tecnicoList.setSelectedIndex( 0 ); + + IDObject estadoListOptions[] = new IDObject[]{ + new MappableObject( new Integer( 0 ), "Por realizar" ), + new MappableObject( new Integer( 2 ), "Realizada" ), + new MappableObject( new Integer( 3 ), "Desmarcada pela empresa" ), + new MappableObject( new Integer( 4 ), "Desmarcada pela SIPRP" ), + }; + estadoList = new RadioButtonFixedPanel( estadoListOptions, 6, 1, RadioButtonFixedPanel.ORIENTATION_VERTICAL, false, null ); + estadoList.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Estado" ) ); + + observacoesTextScroll.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Observa\u00e7\u00f5es" ) ); + observacoesText.setLineWrap( true ); + observacoesText.setWrapStyleWord( true ); + observacoesText.setRows( 5 ); + + } + + public void place() + { + JPanel MarcacaoVisitaHSTPanel = this; + GridBagConstraints MarcacaoVisitaHSTPanelGBC = new GridBagConstraints(); + MarcacaoVisitaHSTPanelGBC.insets = new Insets( 1, 1, 1, 1 ); + GridBagLayout MarcacaoVisitaHSTPanelLayout = new GridBagLayout(); + MarcacaoVisitaHSTPanel.setLayout( MarcacaoVisitaHSTPanelLayout ); + MarcacaoVisitaHSTPanelGBC.gridx = 0; + MarcacaoVisitaHSTPanelGBC.gridy = 0; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.0; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( dataLabel, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( dataLabel ); + + MarcacaoVisitaHSTPanelGBC.gridx = 1; + MarcacaoVisitaHSTPanelGBC.gridy = 0; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.5; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( dataPanel, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( dataPanel ); + + MarcacaoVisitaHSTPanelGBC.gridx = 2; + MarcacaoVisitaHSTPanelGBC.gridy = 0; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.5; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.NONE; + MarcacaoVisitaHSTPanelLayout.setConstraints( emailButton, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( emailButton ); + + MarcacaoVisitaHSTPanelGBC.gridx = 0; + MarcacaoVisitaHSTPanelGBC.gridy = 1; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.0; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( dataFichaLabel, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( dataFichaLabel ); + + MarcacaoVisitaHSTPanelGBC.gridx = 1; + MarcacaoVisitaHSTPanelGBC.gridy = 1; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.5; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( dataFichaPanel, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( dataFichaPanel ); + + MarcacaoVisitaHSTPanelGBC.gridx = 0; + MarcacaoVisitaHSTPanelGBC.gridy = 2; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.0; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( tecnicoLabel, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( tecnicoLabel ); + + MarcacaoVisitaHSTPanelGBC.gridx = 1; + MarcacaoVisitaHSTPanelGBC.gridy = 2; + MarcacaoVisitaHSTPanelGBC.gridwidth = 1; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 0.5; + MarcacaoVisitaHSTPanelGBC.weighty = 0.0; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.HORIZONTAL; + MarcacaoVisitaHSTPanelLayout.setConstraints( tecnicoList, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( tecnicoList ); + + MarcacaoVisitaHSTPanelGBC.gridx = 0; + MarcacaoVisitaHSTPanelGBC.gridy = 3; + MarcacaoVisitaHSTPanelGBC.gridwidth = 3; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 1.0; + MarcacaoVisitaHSTPanelGBC.weighty = 0.5; + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.BOTH; + MarcacaoVisitaHSTPanelLayout.setConstraints( estadoList, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( estadoList ); + + MarcacaoVisitaHSTPanelGBC.gridx = 0; + MarcacaoVisitaHSTPanelGBC.gridy = 4; + MarcacaoVisitaHSTPanelGBC.gridwidth = 3; + MarcacaoVisitaHSTPanelGBC.gridheight = 1; + MarcacaoVisitaHSTPanelGBC.weightx = 1.0; + MarcacaoVisitaHSTPanelGBC.weighty = 0.5; + observacoesTextScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + observacoesTextScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED ); + observacoesTextScroll.setViewportView( observacoesText ); + MarcacaoVisitaHSTPanelGBC.fill = GridBagConstraints.BOTH; + MarcacaoVisitaHSTPanelLayout.setConstraints( observacoesTextScroll, MarcacaoVisitaHSTPanelGBC ); + MarcacaoVisitaHSTPanel.add( observacoesTextScroll ); + + } + + private void setupComponentsHashtable() + { + components.putComponent( siprp.data.MarcacaoEstabelecimentoData.DATA, dataPanel ); + components.putComponent( siprp.data.MarcacaoEstabelecimentoData.DATA_RELATORIO, dataFichaPanel ); + components.putComponent( siprp.data.MarcacaoEstabelecimentoData.TECNICO_HST, tecnicoList ); + components.putComponent( siprp.data.MarcacaoEstabelecimentoData.ESTADO, estadoList ); + components.putComponent( siprp.data.MarcacaoEstabelecimentoData.OBSERVACOES, observacoesText ); + } + + public void fill( Object toFill ) + { + clear(); + if( toFill == null || !( toFill instanceof PropertyObject ) ) + { + return; + } + Hashtable data = null; + if( toFill instanceof PropertyObject ) + { + data = ( (PropertyObject) toFill ).getHashData(); + if( toFill instanceof siprp.data.MarcacaoEstabelecimentoData ) + { + marcacaoEstabelecimentoData = (siprp.data.MarcacaoEstabelecimentoData) toFill; + } + } + else if( toFill instanceof Hashtable ) + { + data = (Hashtable) toFill; + } + else + { + return; + } + if( marcacaoEstabelecimentoData == null ) + { + marcacaoEstabelecimentoData = new siprp.data.MarcacaoEstabelecimentoData(); + marcacaoEstabelecimentoData.setHashData( data ); + } + PropertyObject po = (PropertyObject) toFill; + String properties[] = (String[]) components.keySet().toArray( new String[ 0 ] ); + ComponentController.fill( properties, po.getHashData(), components ); + } + + public Object save() + { + if( marcacaoEstabelecimentoData == null ) + { + marcacaoEstabelecimentoData = new siprp.data.MarcacaoEstabelecimentoData(); + } + Hashtable data = marcacaoEstabelecimentoData.getHashData(); + String properties[] = (String[]) components.keySet().toArray( new String[ 0 ] ); + ComponentController.save( properties, data, components ); + if( !( marcacaoEstabelecimentoData instanceof PropertyObject ) ) + { + return data; + } + marcacaoEstabelecimentoData.setHashData( data ); + return marcacaoEstabelecimentoData; + } + + public void clear() + { + marcacaoEstabelecimentoData = null; + String properties[] = (String[]) components.keySet().toArray( new String[ 0 ] ); + ComponentController.clear( properties, components ); + } + + public void setEnabled( boolean enable ) + { + String properties[] = (String[]) components.keySet().toArray( new String[ 0 ] ); + ComponentController.setEnabled( properties, enable, components ); + } + + public Class getDataClass() + { + return siprp.data.MarcacaoEstabelecimentoData.class; + } + + public JLabel getDataFichaLabel() + { + return dataFichaLabel; + } + + public JCalendarPanel getDataFichaPanel() + { + return dataFichaPanel; + } + + public JLabel getDataLabel() + { + return dataLabel; + } + + public JCalendarPanel getDataPanel() + { + return dataPanel; + } + + public JButton getEmailButton() + { + return emailButton; + } + + public RadioButtonFixedPanel getEstadoList() + { + return estadoList; + } + + public StateTextArea getObservacoesText() + { + return observacoesText; + } + + public JLabel getTecnicoLabel() + { + return tecnicoLabel; + } + + public JComboBox getTecnicoList() + { + return tecnicoList; + } + +} diff --git a/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.xml b/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.xml new file mode 100644 index 00000000..04a78a45 --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/MarcacaoVisitaHSTPanel.xml @@ -0,0 +1,93 @@ + + + + + + + siprp.data.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + Estado + + 6 + + + Por realizar + Realizada + Desmarcada pela empresa + Desmarcada pela SIPRP + + + + + + Observa\u00e7\u00f5es + + + 5 + + + + diff --git a/trunk/siprp/higiene/marcacoes/MarcacoesHigieneUpperPanel.java b/trunk/siprp/higiene/marcacoes/MarcacoesHigieneUpperPanel.java new file mode 100644 index 00000000..1efa12af --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/MarcacoesHigieneUpperPanel.java @@ -0,0 +1,199 @@ +/* + * MarcacoesHigieneUpperPanel.java + * + * Created on February 2, 2006, 12:40 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.marcacoes; + +import java.awt.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.dataui.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; + +import siprp.higiene.*; + +/** + * + * @author fpalma + */ +public class MarcacoesHigieneUpperPanel extends JPanel + implements ListSelectionListener, ControllableComponent +{ + protected BaseTable empresasTable; + protected VectorTableModel empresasModel; + protected BaseTable estabelecimentosTable; + protected VectorTableModel estabelecimentosModel; + + protected HigieneDataProvider provider; + + protected final Vector listeners; + + /** Creates a new instance of MedicinaUpperPanel */ + public MarcacoesHigieneUpperPanel() + throws Exception + { + provider = ( HigieneDataProvider ) HigieneDataProvider.getProvider(); + listeners = new Vector(); + setupComponents(); + } + + private void setupComponents() + throws Exception + { + empresasModel = new VectorTableModel( new String[]{ "empresas" } ); + empresasTable = new BaseTable( empresasModel ); + empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + empresasTable.setNonResizableNorReordable(); + JScrollPane empresasScroll = + new JScrollPane( empresasTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + empresasTable.getSelectionModel().addListSelectionListener( this ); + estabelecimentosModel = new VectorTableModel( new String[]{ "estabelecimentos" } ); + estabelecimentosTable = new BaseTable( estabelecimentosModel ); + estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + estabelecimentosTable.setNonResizableNorReordable(); + JScrollPane estabelecimentosScroll = + new JScrollPane( estabelecimentosTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + estabelecimentosTable.getSelectionModel().addListSelectionListener( this ); + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.gridwidth = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.weightx = 0.5; + constraints.weighty = 1; + + gridbag.setConstraints( empresasScroll, constraints ); + + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( estabelecimentosScroll, constraints ); + + add( empresasScroll ); + add( estabelecimentosScroll ); + + ColumnizedMappable empresas[] = provider.getAllEmpresas(); + Vector values = empresasModel.getValues(); + values.addAll( Arrays.asList( empresas ) ); + empresasModel.setValues( values ); + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( e.getValueIsAdjusting() ) + { + return; + } + if( source.equals( empresasTable.getSelectionModel() ) ) + { + carregarEstabelecimentos(); + } + else if( source.equals( estabelecimentosTable.getSelectionModel() ) ) + { + notifyListeners( e ); + } + } + + protected void carregarEstabelecimentos() + { + estabelecimentosTable.clearSelection(); + int selected = empresasTable.getSelectedRow(); + estabelecimentosModel.clearAll(); + if( selected > -1 ) + { + try + { + Integer empresaID = ( ( ColumnizedMappable ) empresasModel.getRowAt( selected ) ).getID(); + ColumnizedMappable estabelecimentos[] = provider.getAllEstabelecimentosForEmpresa( empresaID); + Vector values = estabelecimentosModel.getValues(); + values.addAll( Arrays.asList( estabelecimentos ) ); + estabelecimentosModel.setValues( values ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os estabelecimentos.", true ); + estabelecimentosModel.clearAll(); + } + } + } + + protected void notifyListeners( ListSelectionEvent e ) + { + for( int n = 0; n < listeners.size(); n++ ) + { + ListSelectionEvent event = + new ListSelectionEvent( this, e.getFirstIndex(), e.getLastIndex(), e.getValueIsAdjusting() ); + ( ( ListSelectionListener ) listeners.elementAt( n ) ).valueChanged( event ); + } + } + + public void addListSelectionListener( ListSelectionListener listener ) + { + listeners.add( listener ); + } + + public void removeSelectionListener( ListSelectionListener listener ) + { + listeners.remove( listener ); + } + + public void clear() + { +// empresasTable.clearSelection(); + } + + public void fill( Object value ) + { + if( value == null ) + { + clear(); + } + Integer ids[] = ( Integer [] ) value; + for( int n = 0; n < empresasTable.getRowCount(); n++ ) + { + if( ( ( ColumnizedMappable ) empresasModel.getRowAt( n ) ).getID().equals( ids[ 0 ] ) ) + { + empresasTable.setRowSelectionInterval( n, n ); + break; + } + } + + for( int n = 0; n < estabelecimentosTable.getRowCount(); n++ ) + { + if( ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( n ) ).getID().equals( ids[ 1 ] ) ) + { + estabelecimentosTable.setRowSelectionInterval( n, n ); + break; + } + } + } + + public Object save() + { + int empresaSelected = empresasTable.getSelectedRow(); + int estabelecimentoSelected = estabelecimentosTable.getSelectedRow(); + return new Integer[]{ + empresaSelected == -1 ? null : ( ( ColumnizedMappable ) empresasModel.getRowAt( empresaSelected ) ).getID(), + estabelecimentoSelected == -1 ? null : ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( estabelecimentoSelected ) ).getID() + }; + } + + public void setEnabled( boolean enable ) + { + empresasTable.setEnabled( enable ); + estabelecimentosTable.setEnabled( enable ); + } +} diff --git a/trunk/siprp/higiene/marcacoes/MarcacoesHigieneWindow.java b/trunk/siprp/higiene/marcacoes/MarcacoesHigieneWindow.java new file mode 100644 index 00000000..b8643956 --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/MarcacoesHigieneWindow.java @@ -0,0 +1,519 @@ +/* + * MarcacoesHigieneWindow.java + * + * Created on January 31, 2006, 11:32 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.marcacoes; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.panel.*; +import com.evolute.utils.ui.search.*; +import com.evolute.utils.ui.text.*; +import com.evolute.utils.ui.window.*; + +import siprp.*; +import siprp.data.*; +import siprp.higiene.*; + +/** + * + * @author fpalma + */ +public class MarcacoesHigieneWindow extends EditorWindow + implements ItemListener, ActionListener, ListSelectionListener +{ + public final static String TITLE = "Marca\u00e7\u00f5es de Higiene e Seguran\u00e7a"; + + private final static int iPermissionArray[][] = + new int[][]{ {}, { NEW_INDEX, EDIT_INDEX, CANCEL_INDEX, SAVE_INDEX, DELETE_INDEX } }; + + private static final int INDEX_MAIN = 0; + private static final int INDEX_VISITA = 1; + + private static final DateFormat DATE_FORMAT = + DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "PT", "pt" ) ); + + protected MarcacoesHigieneUpperPanel upperPanel; + protected MarcacaoVisitaHSTPanel marcacaoPanel; + protected TableEditorPanel marcacaoEditorPanel; + + protected HigieneDataProvider provider; + protected JDOProvider JDO; + protected SIPRPTracker tracker; + + private Hashtable tecnicosHash; + + protected Integer empresaID; + protected String empresa; + protected Integer estabelecimentoID; + protected EstabelecimentoData estabelecimento; + + protected boolean editing = false; + + /** Creates a new instance of MarcacoesHigieneWindow */ + public MarcacoesHigieneWindow() + throws Exception + { + super( iPermissionArray ); + provider = ( HigieneDataProvider ) HigieneDataProvider.getProvider(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + tecnicosHash = new Hashtable(); + setupComponents(); + setExtendedState(getExtendedState() | MAXIMIZED_BOTH); + } + + private void setupComponents() + throws Exception + { + setTitle( TITLE ); + upperPanel = new MarcacoesHigieneUpperPanel(); + JPanel panel = new JPanel(); + + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + getContentPane().setLayout( gridbag ); + constraints.insets = new Insets( 2, 2, 2, 2 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1; + constraints.gridheight = 1; + + constraints.weighty = 0.2; + gridbag.setConstraints( upperPanel, constraints ); + + constraints.weighty = 0.8; + gridbag.setConstraints( panel, constraints ); + + getContentPane().add( upperPanel ); + getContentPane().add( panel ); + + changeGroupName( INDEX_VISITA, "Visitas" ); + setActionName( INDEX_VISITA, NEW_INDEX, "Nova" ); + setActionTooltip( INDEX_VISITA, NEW_INDEX, "Nova" ); + JPanel toolbar = getToolbarPanel( INDEX_VISITA ); + + gridbag = new GridBagLayout(); +// GridBagConstraints constraints = new GridBagConstraints(); + panel.setLayout( gridbag ); + constraints.insets = new Insets( 2, 2, 2, 2 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1.0; + constraints.weighty = 0; + + gridbag.setConstraints( toolbar, constraints ); + panel.add( toolbar ); + + constraints.gridheight = 1; + constraints.weighty = 1.0; + try + { + marcacaoEditorPanel = + new TableEditorPanel( new String[]{ "Data", + "Estado" }, + new int[]{0,2}, new int[]{0,0}, + 0.0, 1.0, new Dimension( 350, 100 ) ); + marcacaoPanel = new MarcacaoVisitaHSTPanel(); + new CopyPasteHandler( marcacaoPanel.getObservacoesText() ); + marcacaoEditorPanel.addComponent( marcacaoPanel, + new int[]{0,2}, new int[]{1,2}, + 1.0, 1.0 ); + marcacaoEditorPanel.addListSelectionListener( new ListSelectionListener(){ + public void valueChanged(javax.swing.event.ListSelectionEvent listSelectionEvent) + { + if( marcacaoEditorPanel.getID() != null ) + { + reload(INDEX_VISITA); + select(INDEX_VISITA); + } + else + { + clear( INDEX_VISITA ); + } + } + }); + }catch( Exception ex ) + { + DialogException.showException( ex ); + return; + } + gridbag.setConstraints( marcacaoEditorPanel, constraints ); + panel.add( marcacaoEditorPanel ); + marcacaoPanel.getEmailButton().addActionListener( this ); + + fillCombo(); + upperPanel.addListSelectionListener( this ); + } + + public void fillCombo() + throws Exception + { + marcacaoPanel.getTecnicoList().removeItemListener( this ); + marcacaoPanel.getTecnicoList().removeAllItems(); + tecnicosHash.clear(); + Object tecnicos[][] = provider.getAllTecnicosHST(); + marcacaoPanel.getTecnicoList().addItem( new MappableObject( new Integer( -2 ), " " ) ); + for( int n = 0; n < tecnicos.length; n++ ) + { + Object tecnico[] = new Object[ 4 ]; + tecnico[ 0 ] = new Integer( ( (Number)tecnicos[n][0] ).intValue() ); + tecnico[ 1 ] = tecnicos[ n ][ 1 ]; + tecnico[ 2 ] = tecnicos[ n ][ 2 ]; + tecnico[ 3 ] = new Integer( n ); + tecnicosHash.put( tecnicos[ n ][ 0 ], tecnico ); + marcacaoPanel.getTecnicoList().addItem( new MappableObject( (Integer) tecnico[ 0 ], tecnico[ 1 ] ) ); + } + marcacaoPanel.getTecnicoList().setSelectedIndex( 0 ); + + marcacaoPanel.getTecnicoList().addItem( new MappableObject( new Integer( -1 ), "Novo/Editar" ) ); + marcacaoPanel.getTecnicoList().addItemListener( this ); + } + + public void itemStateChanged(java.awt.event.ItemEvent itemEvent) + { + int index = marcacaoPanel.getTecnicoList().getSelectedIndex(); + if( index == marcacaoPanel.getTecnicoList().getItemCount() - 1 ) + { + try + { +// marcacaoPanel.getTecnicoList().removeItemListener( this ); + TecnicoEditor te = new TecnicoEditor( this ); + te.setVisible( true ); +// boolean isNew = me.getIsNew(); + Integer id = te.getID(); + if( id == null ) + { + marcacaoPanel.getTecnicoList().setSelectedIndex( 0 ); + } + else + { + fillCombo(); + if( id != null ) + { + Object[] tecnico = (Object[])tecnicosHash.get( id ); + marcacaoPanel.getTecnicoList().setSelectedIndex( ((Integer)tecnico[ 3 ] ).intValue() ); + } + } + + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro na janela de edi\u00e7\u00e3o...", true ); + ex.printStackTrace(); + marcacaoPanel.getTecnicoList().setSelectedIndex( 0 ); + return; + } +// finally +// { +// marcacaoPanel.getTecnicoList().addItemListener( this ); +// } + } + else + { + IDObject selected = (IDObject)marcacaoPanel.getTecnicoList().getItemAt( index ); + Integer id = selected.getID(); + } + } + + public boolean save(int index) + { + switch( index ) + { + case INDEX_VISITA: + MarcacaoEstabelecimentoData visita = ( MarcacaoEstabelecimentoData ) marcacaoPanel.save(); + Date data = ( Date ) visita.get( MarcacaoEstabelecimentoData.DATA ); + if( data == null ) + { + JOptionPane.showMessageDialog( this, "Tem de preencher uma data para a visita.", + "Erro", JOptionPane.ERROR_MESSAGE ); + return false; + } + visita.set( MarcacaoEstabelecimentoData.ESTABELECIMENTO, estabelecimento ); + try + { + visita.set( MarcacaoEstabelecimentoData.REALIZADA, + ( ( Integer )visita.get( MarcacaoEstabelecimentoData.ESTADO ) ).intValue() == + provider.ESTADO_REALIZADO ? "y" : "n" ); + System.out.println( "DATA " + visita.get( MarcacaoEstabelecimentoData.DATA ) ); + Integer tecnico = ( Integer ) visita.get( MarcacaoEstabelecimentoData.TECNICO_HST ); + if( tecnico != null && tecnico.intValue() < 0 ) + { + visita.set( MarcacaoEstabelecimentoData.TECNICO_HST, null ); + } + visita.save(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar", true ); + return false; + } + + break; + } + reload( INDEX_MAIN ); + editing = false; + return true; + } + + public boolean delete(int index) + { + int option = JOptionPane.showConfirmDialog( this, "Tem a certeza que quer apagar a marca\u00e7\u00e3o?", + "Apagar", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE ); + if( option == 0 ) + { + switch( index ) + { + case INDEX_VISITA: + MarcacaoEstabelecimentoData visita = ( MarcacaoEstabelecimentoData ) marcacaoPanel.save(); + try + { + visita.delete(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a apagar.", true ); + return false; + } + break; + } + reload( INDEX_MAIN ); + return true; + } + return false; + } + + public void clear(int index) + { + switch( index ) + { + case INDEX_MAIN: + empresaID = null; + empresa = null; + estabelecimentoID = null; + estabelecimento = null; + upperPanel.clear(); + marcacaoEditorPanel.clear(); + break; + + case INDEX_VISITA: + marcacaoPanel.clear(); + marcacaoPanel.getEmailButton().setText( "Enviar email" ); + break; + } + } + + public void enableComponents(int index, boolean enable) + { + switch( index ) + { + case INDEX_MAIN: + + break; + + case INDEX_VISITA: + marcacaoPanel.setEnabled( enable ); + marcacaoPanel.getEmailButton().setEnabled( enable ); + upperPanel.setEnabled( !enable ); + editing = enable; + break; + } + if( tracker != null ) + { + tracker.getAvisosPanel().setEnabled( !editing, + AvisoConstants.TIPO_ESTABELECIMENTO ); + } + } + + protected void enableSelect( int index, boolean select ) + { + switch( index ) + { + case INDEX_VISITA: + marcacaoEditorPanel.setEnabled( select ); + break; + } + } + + public void reload( int index ) + { + switch( index ) + { + case INDEX_MAIN: + try + { + empresa = provider.getEmpresa( empresaID ); + estabelecimento = ( EstabelecimentoData ) JDO.load( EstabelecimentoData.class, estabelecimentoID ); +// upperPanel.getEmpresaText().setText( empresa ); +// upperPanel.getEstabelecimentoText().setText( estabelecimento ); +// upperPanel.getTrabalhadorText().setText( ( String ) trabalhador.get( TrabalhadorData.NOME ) ); + Object visitas[][] = provider.getVisitasEstabelecimento( estabelecimentoID ); + if( visitas.length > 0 ) + { + marcacaoEditorPanel.setData( new Object2DArray( visitas ) ); + } + else + { + marcacaoEditorPanel.clear(); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os dados.", true ); + } + break; + + case INDEX_VISITA: + Integer visitaID = marcacaoEditorPanel.getID(); + if( visitaID == null ) + { + return; + } + try + { + MarcacaoEstabelecimentoData visita = + ( MarcacaoEstabelecimentoData ) JDO.load( MarcacaoEstabelecimentoData.class, visitaID ); + marcacaoPanel.fill( visita ); + Date dataEmailVisita = ( Date ) visita.get( MarcacaoEstabelecimentoData.DATA_EMAIL ); + if( dataEmailVisita != null ) + { + marcacaoPanel.getEmailButton().setText( "Enviar email (" + DATE_FORMAT.format( dataEmailVisita ) + ")" ); + } + else + { + marcacaoPanel.getEmailButton().setText( "Enviar email" ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os dados da visita.", true ); + } + break; + } + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( marcacaoPanel.getEmailButton() ) ) + { + enviarEmailVisita(); + } + } + + protected void enviarEmailVisita() + { + MarcacaoEstabelecimentoData visita = ( MarcacaoEstabelecimentoData ) marcacaoPanel.save(); + + String subject = ( String ) Singleton.getInstance( SingletonConstants.SUBJECT_VISITA ); + String texto = ( String ) Singleton.getInstance( SingletonConstants.LETTER_VISITA ); + + Date today = new Date(); + marcacaoPanel.getEmailButton().setText( "Enviar email (" + DATE_FORMAT.format( today ) + ")" ); + + try + { + enviarEmail( subject, texto, ( Date )visita.get( MarcacaoEstabelecimentoData.DATA ) ); + visita.set( Marcacao.DATA_EMAIL, today ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a enviar mail", true ); + } + } + + protected void enviarEmail( String subject, String texto, Date data ) + throws Exception + { + String sede = ( String )estabelecimento.get( EstabelecimentoData.NOME ); + String dataStr = DATE_FORMAT.format( data ); + subject = subject.replaceAll( CompanyDataLoader.NOME, sede ); + String morada = ( String )estabelecimento.get( EstabelecimentoData.MORADA ); + + texto = texto.replaceAll( CompanyDataLoader.DATA, dataStr ); + texto = texto.replaceAll( CompanyDataLoader.NOME, sede ); + texto = texto.replaceAll( CompanyDataLoader.MORADA, morada ); + + ContactoData contacto = ( ContactoData )estabelecimento.get( EstabelecimentoData.CONTACTO ); + String mail = ""; + if( contacto != null ) + { + mail = ( String )contacto.get( ContactoData.EMAIL ); + } + + if( System.getProperty( "os.name" ).startsWith( "Windows" ) ) + { + mail = mail.replaceAll( " ", "%20" ); + subject = subject.replaceAll( " ", "%20" ); + texto = texto.replaceAll( " ", "%20" ); + Process proc = Runtime.getRuntime().exec( "cmd.exe /c start mailto:\"" + mail + + "?subject=" + subject + "&body=" + + + texto + ); + } + else + { + mail = mail.replaceAll( " ", "%20" ); + subject = subject.replaceAll( " ", "%20" ); + texto = texto.replaceAll( " ", "%20" ); + + Process proc = Runtime.getRuntime().exec( new String[]{ "/usr/bin/open", "/Applications/Mail.app", "mailto:" + mail + + "?subject=" + subject + "&body=" + + texto } ); + } + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( source.equals( upperPanel ) ) + { + Integer ids[] = ( Integer [] ) upperPanel.save(); + empresaID = ids[ 0 ]; + estabelecimentoID = ids[ 1 ]; + if( ids[ 1 ] == null ) + { + clear( INDEX_MAIN ); + unselect( INDEX_MAIN ); + } + else + { + reload( INDEX_MAIN ); + select( INDEX_MAIN ); + } + } + } + + public void setEmpresaAndEstabelecimento( Integer empresaID, Integer estabelecimentoID ) + { + if( editing ) + { + JOptionPane.showMessageDialog( this, "Esta janela est\u00e1 em edi\u00e7\u00e3o.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + } + else + { + upperPanel.fill( new Integer[]{ empresaID, estabelecimentoID } ); + } + } + + public void setTracker( SIPRPTracker tracker ) + { + this.tracker = tracker; + } +} diff --git a/trunk/siprp/higiene/marcacoes/TecnicoEditor.java b/trunk/siprp/higiene/marcacoes/TecnicoEditor.java new file mode 100644 index 00000000..007c119d --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/TecnicoEditor.java @@ -0,0 +1,317 @@ +/* + * TecnicoEditor.java + * + * Created on February 1, 2006, 10:55 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.marcacoes; + + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.button.*; +import com.evolute.utils.ui.text.*; + +import siprp.*; +import siprp.data.*; +import siprp.higiene.*; + +/** + * + * @author fpalma + */ +public class TecnicoEditor extends CustomJDialog + implements ActionListener, ListSelectionListener +// , ItemListener +{ + static + { + TecnicoHSTData.registerOperationHandlerForClass( DisableDeleteHandler.INSTANCE, TecnicoHSTData.class ); + } + + private JDOProvider JDO; + private HigieneDataProvider provider; + private BaseTable table; + private VectorTableModel model; + private JButton okButton; + private JButton cancelarButton; + private JButton novoButton; + private JTextField nomeText; + private JTextField iniciaisText; +// private JComboBox corCombo; + private Integer id; + private boolean isNew = false; + private BetterButtonGroup corGroup; + private JRadioButton cores[]; + + /** Creates a new instance of MedicoEditor */ + public TecnicoEditor( JFrame owner ) + throws Exception + { + super( owner, true ); + provider = (HigieneDataProvider)HigieneDataProvider.getProvider(); + JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + } + + private void setupComponents() + throws Exception + { + setSize( 600, 300 ); + setResizable( false ); + setTitle( "Criar/Editar T\u00e9cnico" ); + centerSuper(); + + model = new VectorTableModel( new String[]{ "Nome", "Iniciais", "Cor" } ); + table = new BaseTable( model ); + table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + table.setTableCellRenderer( new TecnicoRenderer() ); + JScrollPane scp = new JScrollPane(); + scp.setMinimumSize( new Dimension( 300, 200 ) ); + scp.setMaximumSize( new Dimension( 300, 200 ) ); + scp.setPreferredSize( new Dimension( 300, 200 ) ); + scp.setSize( new Dimension( 300, 200 ) ); + scp.setViewportView( table ); + scp.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + scp.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + table.fixColumnWidth( 0, 200 ); + table.setNonResizableNorReordable(); + table.getSelectionModel().addListSelectionListener( this ); + Object obj[][] = provider.getAllTecnicosHST(); + Vector tecnicosHST = new Vector(); + for( int n = 0; n < obj.length; n++ ) + { + tecnicosHST.add( new ColumnizedObjectArray( obj[ n ], true ) ); + } + model.setValues( tecnicosHST ); + + okButton = new JButton( "OK" ); + cancelarButton = new JButton( "Cancelar" ); + novoButton = new JButton( "Novo" ); + okButton.addActionListener( this ); + cancelarButton.addActionListener( this ); + novoButton.addActionListener( this ); + + nomeText = new JTextField(); + nomeText.setEnabled( false ); + iniciaisText = new JTextField(); + iniciaisText.setEnabled( false ); + JPanel corPanel = new JPanel(); + corPanel.setLayout( new BoxLayout( corPanel, BoxLayout.Y_AXIS ) ); +// corCombo = new JComboBox(); + corGroup = new BetterButtonGroup( false ); + cores = new JRadioButton[ HigieneDataProvider.CORES_TECNICOS.length ]; + for( int n = 0; n < HigieneDataProvider.CORES_TECNICOS.length; n++ ) + { + cores[ n ] = new JRadioButton( " " ); + cores[ n ].setBackground( HigieneDataProvider.CORES_TECNICOS[ n ] ); + corPanel.add( cores[ n ] ); + corGroup.add( cores[ n ] ); +// corCombo.addItem( new Integer( n ) ); + } + JScrollPane corScroll = + new JScrollPane( corPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); +// corCombo.setRenderer( new CorTecnicoCellRenderer() ); +// corCombo.setEnabled( false ); + + GridBagLayout gridbag = new GridBagLayout(); + getContentPane().setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 1; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.gridheight = 1; + + JPanel upperPanel = new JPanel(); + upperPanel.setLayout( new GridLayout( 1, 2 ) ); + upperPanel.add( scp ); + JPanel textPanel = new JPanel(); + upperPanel.add( textPanel ); + gridbag.setConstraints( upperPanel, constraints ); + getContentPane().add( upperPanel ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.weightx = 0.3; + constraints.gridwidth = 1; + constraints.gridheight = GridBagConstraints.REMAINDER;; + + gridbag.setConstraints( novoButton, constraints ); + getContentPane().add( novoButton ); + + gridbag.setConstraints( okButton, constraints ); + getContentPane().add( okButton ); + + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( cancelarButton, constraints ); + getContentPane().add( cancelarButton ); + + gridbag = new GridBagLayout(); + textPanel.setLayout( gridbag ); + constraints.weighty = 0; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.gridheight = 1; + + JLabel nomeLabel = new JLabel( "Nome" ); + gridbag.setConstraints( nomeLabel, constraints ); + textPanel.add( nomeLabel ); + + gridbag.setConstraints( nomeText, constraints ); + textPanel.add( nomeText ); + + JLabel iniciaisLabel = new JLabel( "Iniciais" ); + gridbag.setConstraints( iniciaisLabel, constraints ); + textPanel.add( iniciaisLabel ); + + gridbag.setConstraints( iniciaisText, constraints ); + textPanel.add( iniciaisText ); + + JLabel corLabel = new JLabel( "Cor" ); + gridbag.setConstraints( corLabel, constraints ); + textPanel.add( corLabel ); + +// gridbag.setConstraints( corCombo, constraints ); +// textPanel.add( corCombo ); +// + constraints.weighty = 1; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.fill = GridBagConstraints.BOTH; +// JPanel pad = new JPanel(); +// gridbag.setConstraints( pad, constraints ); +// textPanel.add( pad ); + gridbag.setConstraints( corScroll, constraints ); + textPanel.add( corScroll ); + + new CopyPasteHandler( nomeText ); + new CopyPasteHandler( iniciaisText ); +// corCombo.addItemListener( this ); + } + + public void actionPerformed( ActionEvent e ) + { + if( e.getSource().equals( okButton ) ) + { + if( save() ) + { + close(); + } + } + else if( e.getSource().equals( cancelarButton ) ) + { + close(); + } + if( e.getSource().equals( novoButton ) ) + { + table.getSelectionModel().removeListSelectionListener( this ); + nomeText.setText( "" ); + iniciaisText.setText( "" ); +// corCombo.setSelectedIndex( 0 ); + corGroup.setIntSelected( 0 ); + nomeText.setEnabled( true ); + iniciaisText.setEnabled( true ); + corGroup.setEnabled( true ); + id = null; + isNew = true; + } + } + + public void valueChanged(javax.swing.event.ListSelectionEvent listSelectionEvent) + { + int selected = table.getSelectedRow(); + if( selected == -1 ) + { + return; + } + ColumnizedObjectArray row = (ColumnizedObjectArray)model.getRowAt( selected ); + id = row.getID(); + String nome = (String) row.getValue( 0 ); + String iniciais = (String) row.getValue( 1 ); + Integer cor = ( Integer ) row.getValue( 2 ); + nomeText.setText( nome ); + iniciaisText.setText( iniciais ); +// corCombo.setSelectedIndex( cor.intValue() ); + corGroup.setIntSelected( cor.intValue() ); + nomeText.setEnabled( true ); + iniciaisText.setEnabled( true ); +// corCombo.setEnabled( true ); + corGroup.setEnabled( true ); + } + + private void close() + { + setVisible( false ); + dispose(); + } + + public boolean getIsNew() + { + return isNew; + } + + public Integer getID() + { + return id; + } + + private boolean save() + { + String nome = nomeText.getText().trim(); + String nomePlain = com.evolute.utils.strings.StringPlainer.convertString( nome ); + String iniciais = iniciaisText.getText().trim(); + Integer cor = new Integer( corGroup.getIntSelected() ); + if( nome.length() == 0 || iniciais.length() == 0 ) + { + JOptionPane.showMessageDialog( this, "O Nome e as iniciais n\u00e3o podem ser vazios.", "Erro...", + JOptionPane.ERROR_MESSAGE ); + return false; + } + try + { + TecnicoHSTData tecnico; + if( id != null ) + { + tecnico = ( TecnicoHSTData ) JDO.load( TecnicoHSTData.class, id ); + } + else + { + tecnico = new TecnicoHSTData(); + } + tecnico.set( TecnicoHSTData.NOME, nome ); + tecnico.set( TecnicoHSTData.NOME_PLAIN, nomePlain ); + tecnico.set( TecnicoHSTData.INICIAIS, iniciais ); + tecnico.set( TecnicoHSTData.IDENTIFICADOR, cor ); + tecnico.save(); + if( id == null ) + { + id = (Integer)tecnico.get( TecnicoHSTData.ID ); + } + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a gravar...", false ); + return false; + } + + return true; + } + +// public void itemStateChanged( ItemEvent e ) +// { +// corCombo.getEditor().getEditorComponent().setBackground( HigieneDataProvider.CORES_TECNICOS[ corCombo.getSelectedIndex() ] ); +// } +} diff --git a/trunk/siprp/higiene/marcacoes/TecnicoRenderer.java b/trunk/siprp/higiene/marcacoes/TecnicoRenderer.java new file mode 100644 index 00000000..7ad36ac8 --- /dev/null +++ b/trunk/siprp/higiene/marcacoes/TecnicoRenderer.java @@ -0,0 +1,58 @@ +/* + * DiaRenderer.java + * + * Created on 8 de Fevereiro de 2006, 21:45 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.higiene.marcacoes; + +import java.awt.*; +import javax.swing.*; +import javax.swing.table.*; + +import siprp.higiene.*; + +/** + * + * @author Frederico + */ +public class TecnicoRenderer + implements TableCellRenderer +{ + protected JLabel labels[]; + protected Color defaultColor; + + /** Creates a new instance of DiaRenderer */ + public TecnicoRenderer() + { + labels = new JLabel[ 3 ]; + for( int n = 0; n < 3; n++ ) + { + labels[ n ] = new JLabel(); + } + defaultColor = labels[ 0 ].getBackground(); + labels[ 2 ].setOpaque( true ); + } + + public Component getTableCellRendererComponent( JTable table, Object value, + boolean isSelected, + boolean hasFocus, + int row, int column ) + { + switch( column ) + { + case 2: + labels[ 2 ].setText( " " ); + labels[ 2 ].setBackground( value == null ? defaultColor : + HigieneDataProvider.CORES_TECNICOS[ ( ( Integer ) value ).intValue() ] ); + break; + default: + labels[ column ].setText( ( String ) value ); + break; + } + return labels[ column ]; + } +} diff --git a/trunk/siprp/impressaofichas/FichasPrinter.java b/trunk/siprp/impressaofichas/FichasPrinter.java new file mode 100644 index 00000000..5f7c5e22 --- /dev/null +++ b/trunk/siprp/impressaofichas/FichasPrinter.java @@ -0,0 +1,146 @@ +/* + * FichasPrinter.java + * + * Created on 20 de Fevereiro de 2006, 0:43 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.impressaofichas; + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.xml.transform.*; + +import com.evolute.utils.*; +import com.evolute.utils.date.*; +import com.evolute.utils.fop.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.strings.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.xml.*; + +import siprp.data.*; +import siprp.ficha.*; + +/** + * + * @author Frederico + */ +public class FichasPrinter extends Thread +{ + protected static final DateFormat D_F = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) ); + protected static final DateFormat D_F_L = DateFormat.getDateInstance( DateFormat.LONG, new Locale( "pt", "PT" ) ); + + private ImpressaoFichasDataProvider provider; + + protected Integer ids[]; + protected String printerName; + protected String listPath; + protected String nomeEmpresa; + protected String nomeEstabelecimento; + + /** Creates a new instance of FichasPrinter */ + public FichasPrinter( Integer ids[], String printerName, String listPath, + String nomeEmpresa, String nomeEstabelecimento ) + { + this.ids = ids; + this.printerName = printerName; + this.listPath = listPath; + this.nomeEmpresa = nomeEmpresa; + this.nomeEstabelecimento = nomeEstabelecimento; + } + + public void run() + { + try + { + SimpleXMLElement root = new SimpleXMLElement( "LISTA_FICHAS" ); + for( int n = 0; n < ids.length; n++ ) + { + print( ids[ n ] ); + Object dados[] = provider.getDadosForExameID( ids[ n ] ); + SimpleXMLElement linha = new SimpleXMLElement( "FICHA" ); + linha.addElement( new SimpleXMLElement( "NOME", ( String ) dados[ 0 ] ) ); + linha.addElement( new SimpleXMLElement( "DATA_EXAME", D_F.format( ( Date ) dados[ 1 ] ) ) ); + linha.addElement( new SimpleXMLElement( "DATA_PROXIMO_EXAME", dados[ 2 ] != null ? D_F.format( ( Date ) dados[ 2 ] ) : "n/d" ) ); + root.addElement( linha ); + + try + { + sleep( (n % 5 == 0 && n > 0) ? 3000 : 2000 ); + } + catch( InterruptedException iex ) + { + } + } + Date today = ( Date ) Singleton.getInstance( Singleton.TODAY ); + Calendar cal = Calendar.getInstance(); + cal.setTime( today ); + SimpleXMLElement data = new SimpleXMLElement( "DATA_EXTENSO", DateUtils.WEEKDAYS_FULL_PT[ cal.get( Calendar.DAY_OF_WEEK ) - Calendar.MONDAY ] + + ", " + D_F_L.format( today ) ); + root.addElement( data ); + TransformerFactory tFactory = TransformerFactory.newInstance(); + String xml = root.toString(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + FOPCreator creator = new FOPCreator(); + InputStream xmlIn = new ByteArrayInputStream( xml.getBytes() ); + creator.createFOfromXML( xmlIn, + FichasPrinter.class.getClassLoader().getResourceAsStream( + "siprp/impressaofichas/lista_fichas.xsl" ), + out ); + byte toPrint[] = out.toByteArray(); + ByteArrayInputStream in = new ByteArrayInputStream( toPrint ); + Hashtable printOptions = new Hashtable(); +//System.out.println( "OUT: " + out.toString() ); + new FOPPrinter().printFO( in, false, true, printOptions ); + byte []pdfData = new PDFCreator().createPdfFromFo( toPrint ); + File dir = new File( new File( listPath ), StringPlainer.convertString( nomeEmpresa ).replace( ' ', '_' ) ); + if( !dir.exists() ) + { + dir.mkdir(); + } + String fileName = StringPlainer.convertString( nomeEstabelecimento ).replace( ' ', '_' ) + + "_" + DateUtils.plainFormatDate( today ) + ".pdf"; + FileOutputStream fos = new FileOutputStream( new File( dir, fileName ) ); + fos.write( pdfData ); + fos.close(); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a imprimir", true ); + } + ids = null; + } + + private void print( Integer exameID ) + throws Exception + { + if( provider == null ) + { + provider = ( ImpressaoFichasDataProvider ) ImpressaoFichasDataProvider.getProvider(); + } +// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); +// ExameData exame = (ExameData) JDO.load( ExameData.class, exameID ); +// byte pdf[] = (byte []) exame.get( ExameData.PDF ); + byte pdf[] = provider.getPDF( exameID ); + if( pdf == null ) + { + throw new Exception( "N\u00e3o existe exame" ); + } +// TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR ); +// String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) ); + String nomeFicheiro = StringPlainer.convertString( provider.getNomeTrabalhadorForExameID( exameID ) ); +// nomeFicheiro.replaceAll( " ", "_" ); + String split[] = nomeFicheiro.split( " " ); + nomeFicheiro = ""; + for( int n = 0; n < split.length; n++ ) + { + nomeFicheiro += split[ n ] + "_"; + } + ExamePDF ePDF = new ExamePDF(); + ePDF.printSilent( pdf, nomeFicheiro, printerName ); + } +} diff --git a/trunk/siprp/impressaofichas/ImpressaoFichasDataProvider.java b/trunk/siprp/impressaofichas/ImpressaoFichasDataProvider.java new file mode 100644 index 00000000..11e0910d --- /dev/null +++ b/trunk/siprp/impressaofichas/ImpressaoFichasDataProvider.java @@ -0,0 +1,217 @@ +/* + * HigieneDataProvider.java + * + * Created on February 1, 2006, 10:49 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.impressaofichas; + +import java.text.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.strings.*; +import com.evolute.utils.tables.*; + +import siprp.*; +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class ImpressaoFichasDataProvider extends MetaProvider +{ + private static final DateFormat DATE_FORMAT = + DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "PT", "pt" ) ); + + private static final Object LOCK = new Object(); + private static ImpressaoFichasDataProvider instance = null; + private final Executer executer; + + /** Creates a new instance of HigieneDataProvider */ + public ImpressaoFichasDataProvider() + throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + executer = dbm.getSharedExecuter( this ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new ImpressaoFichasDataProvider(); + } + } + return instance; + } + + public ColumnizedMappable[] getAllEmpresas() + throws Exception + { + Select select = + new Select( new String[]{ "empresas" }, + new String[]{ "id", "designacao_social", "designacao_social_plain" }, + new Field( "inactivo" ).isDifferent( "y" ), + new String[]{ "designacao_social_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + ColumnizedMappable empresas[] = new ColumnizedMappable[ array.columnLength() ]; + for( int n = 0; n < empresas.length; n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String designacao = ( String ) array.get( n, 1 ); + empresas[ n ] = new ColumnizedMappable( id, designacao ); + } + return empresas; + } + + public ColumnizedMappable[] getAllEstabelecimentosForEmpresa( Integer empresaID ) + throws Exception + { + Select select = + new Select( new String[]{ "estabelecimentos" }, + new String[]{ "id", "nome", "nome_plain" }, + new Field( "empresa_id" ).isEqual( empresaID ).and( + new Field( "inactivo" ).isDifferent( "y" ) ), + new String[]{ "nome_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + ColumnizedMappable estabelecimentos[] = new ColumnizedMappable[ array.columnLength() ]; + for( int n = 0; n < estabelecimentos.length; n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String nome = ( String ) array.get( n, 1 ); + estabelecimentos[ n ] = new ColumnizedMappable( id, nome ); + } + return estabelecimentos; + } + + public Object [][]getAllFichasForEstabelecimentoAndDatas( Integer estabelecimentoID, Date dataInicio, Date dataFim ) + throws Exception + { + Vector fichas = new Vector(); + Select select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "id", "nome", "nome_plain" }, + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ), + new String[]{ "nome_plain" }, + null ); + Virtual2DArray array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String nome = ( String ) array.get( n, 1 ); + String nomePlain = ( String ) array.get( n, 2 ); + MappableObject fichasTrabalhador[] = getAllFichasForTrabalhadorAndDatas( id, dataInicio, dataFim ); + for( int f = 0; f < fichasTrabalhador.length; f++ ) + { + fichas.add( new Object[]{ fichasTrabalhador[ f ].getID(), nome, fichasTrabalhador[ f ].getValue(), nomePlain } ); + } + } + Object fichasArray[][] = ( Object[][] )fichas.toArray( new Object[ fichas.size() ][] ); + Arrays.sort( fichasArray, new Comparator(){ + public int compare( Object o1, Object o2 ) + { + Object arr1[] = ( Object[] )o1; + Object arr2[] = ( Object[] )o2; + int res = 0; + if( arr1[ 2 ] == null && arr2[ 2 ] == null ) + { + res = 0; + } + else if( arr1[ 2 ] == null ) + { + res = -1; + } + else if( arr2[ 2 ] == null ) + { + res = 1; + } + else + { + res = ( (Date)arr1[ 2 ]).compareTo( (Date)arr2[ 2 ] ); + } + + if( res == 0 ) + { + res = ( (String)arr1[ 3 ]).compareTo( (String)arr2[ 3 ] ); + } + return res; + } + } ); + for( int n = 0; n < fichasArray.length; n++ ) + { + fichasArray[ n ][ 2 ] = fichasArray[ n ][ 2 ] != null? DATE_FORMAT.format( (Date)fichasArray[ n ][ 2 ] ): ""; + } + return fichasArray; + } + + public MappableObject []getAllFichasForTrabalhadorAndDatas( Integer trabalhadorID, Date dataInicio, Date dataFim ) + throws Exception + { + Select select = + new Select( new String[]{ "exames" }, new String[]{ "MAX(id)", "data" }, + new Field( "trabalhador_id" ).isEqual( trabalhadorID ).and( + new Field( "inactivo" ).isEqual( "n" ) ).and( + new Field( "data" ).between( new Object[]{ dataInicio, dataFim } ) ), + new String[]{ "data DESC" }, new String[]{ "data" } ); + Virtual2DArray array = executer.executeQuery( select ); + MappableObject exames[] = new MappableObject[ array.columnLength() ]; + for( int n = 0; n < exames.length; n++ ) + { + Date date = (Date)array.get( n, 1 ); + Integer id = new Integer( ((Number)array.get( n, 0 )).intValue() ); + exames[ n ] = new MappableObject( id, date ); + } + return exames; + } + + public byte[] getPDF( Integer exameID ) + throws Exception + { + Select select = + new Select( new String[]{ "exames" }, + new String[]{ "pdf" }, + new Field( "id" ).isEqual( exameID ) ); + Virtual2DArray array = executer.executeQuery( select ); + byte pdf[] = ( byte[] ) array.get( 0, 0 ); + return pdf; + } + + public String getNomeTrabalhadorForExameID( Integer exameID ) + throws Exception + { + Select select = + new Select( new String[]{ "exames", "trabalhadores" }, + new String[]{ "trabalhadores.nome_plain" }, + new Field( "exames.id" ).isEqual( exameID ).and( + new Field( "exames.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + return ( String ) array.get( 0, 0 ); + } + + public Object[] getDadosForExameID( Integer exameID ) + throws Exception + { + Select select = + new Select( new String[]{ "exames", "trabalhadores" }, + new String[]{ "trabalhadores.nome", "exames.data", "exames.proximo_exame" }, + new Field( "exames.id" ).isEqual( exameID ).and( + new Field( "exames.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + return array.getObjects()[ 0 ]; + } +} diff --git a/trunk/siprp/impressaofichas/ImpressaoFichasWindow.java b/trunk/siprp/impressaofichas/ImpressaoFichasWindow.java new file mode 100644 index 00000000..65f95930 --- /dev/null +++ b/trunk/siprp/impressaofichas/ImpressaoFichasWindow.java @@ -0,0 +1,421 @@ +/* + * ImpressaoFichasUpperPanel.java + * + * Created on 19 de Fevereiro de 2006, 19:00 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.impressaofichas; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.print.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.properties.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.window.*; + +/** + * + * @author Frederico + */ +public class ImpressaoFichasWindow extends EditorWindow + implements ListSelectionListener, ActionListener +{ + public final static String TITLE = "Impress\u00e3o de Fichas de Aptid\u00e3o"; + + protected final static String PATH_PROPERTY_SUFFIX = ".path"; + + private final static int iPermissionArray[][] = + new int[][]{ {} }; + + protected JCalendarPanel dataInicioPanel; + protected JCalendarPanel dataFimPanel; + protected VectorTableModel empresasModel; + protected BaseTable empresasTable; + protected VectorTableModel estabelecimentosModel; + protected BaseTable estabelecimentosTable; + protected VectorTableModel fichasModel; + protected BaseTable fichasTable; + protected JButton procurarButton; + protected JTextField pathText; + protected JButton pathButton; + protected JComboBox impressorasCombo; + protected JButton imprimirButton; + protected JButton imprimirTodasButton; + + protected ImpressaoFichasDataProvider provider; + protected PropertyHandler propertyHandler; + + /** Creates a new instance of ImpressaoFichasUpperPanel */ + public ImpressaoFichasWindow() + throws Exception + { + super( iPermissionArray ); + provider = ( ImpressaoFichasDataProvider ) ImpressaoFichasDataProvider.getProvider(); + propertyHandler = new PropertyHandler(); + setupComponents(); + } + + private void setupComponents() + throws Exception + { + setTitle( TITLE ); + empresasModel = new VectorTableModel( new String[]{ "empresas" } ); + empresasTable = new BaseTable( empresasModel ); + empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + empresasTable.setNonResizableNorReordable(); + JScrollPane empresasScroll = + new JScrollPane( empresasTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + empresasTable.getSelectionModel().addListSelectionListener( this ); + estabelecimentosModel = new VectorTableModel( new String[]{ "estabelecimentos" } ); + estabelecimentosTable = new BaseTable( estabelecimentosModel ); + estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + estabelecimentosTable.setNonResizableNorReordable(); + JScrollPane estabelecimentosScroll = + new JScrollPane( estabelecimentosTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + estabelecimentosTable.getSelectionModel().addListSelectionListener( this ); + fichasModel = new VectorTableModel( new String[]{ "trabalhador", "data" } ); + fichasTable = new BaseTable( fichasModel ); + fichasTable.fixColumnWidth( 1, 120 ); + fichasTable.setNonResizableNorReordable(); + fichasTable.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); + fichasTable.getSelectionModel().addListSelectionListener( this ); + JScrollPane fichasScroll = new JScrollPane( fichasTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + JLabel inicioLabel = new JLabel( "In\u00edcio" ); + dataInicioPanel = new JCalendarPanel( null ); + JLabel fimLabel = new JLabel( "Fim" ); + dataFimPanel = new JCalendarPanel( null ); + procurarButton = new JButton( "Carregar" ); + procurarButton.addActionListener( this ); + procurarButton.setEnabled( false ); + pathText = new JTextField(); + pathText.setEditable( false ); + pathButton = new JButton( "Escolher Direct\u00f3rio" ); + pathButton.addActionListener( this ); + impressorasCombo = new JComboBox(); + PrintService printers[] = PrintServiceLookup.lookupPrintServices( null, null ); + for( int n = 0; n < printers.length; n++ ) + { + impressorasCombo.addItem( printers[ n ].getName() ); + } + imprimirButton = new JButton( "Imprimir escolhidas" ); + imprimirButton.addActionListener( this ); + imprimirButton.setEnabled( false ); + imprimirTodasButton = new JButton( "Imprimir Todas" ); + imprimirTodasButton.addActionListener( this ); + imprimirTodasButton.setEnabled( false ); + JPanel upperPad = new JPanel(); + JPanel lowerPad = new JPanel(); + JPanel upperPanel = new JPanel(); + + GridBagLayout gridbag = new GridBagLayout(); + setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); + constraints.fill = GridBagConstraints.BOTH; + constraints.gridheight = 1; + constraints.weighty = 0.35; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( upperPanel, constraints ); + + constraints.gridwidth = 2; + constraints.weightx = 1; + constraints.weighty = 0.65; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints( fichasScroll, constraints ); + + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( inicioLabel, constraints ); + gridbag.setConstraints( dataInicioPanel, constraints ); + gridbag.setConstraints( fimLabel, constraints ); + gridbag.setConstraints( dataFimPanel, constraints ); + gridbag.setConstraints( procurarButton, constraints ); + gridbag.setConstraints( pathText, constraints ); + gridbag.setConstraints( pathButton, constraints ); + gridbag.setConstraints( impressorasCombo, constraints ); + gridbag.setConstraints( imprimirButton, constraints ); + gridbag.setConstraints( imprimirTodasButton, constraints ); + + constraints.weighty = 0.32; + gridbag.setConstraints( upperPad, constraints ); + gridbag.setConstraints( lowerPad, constraints ); + + add( upperPanel ); + add( fichasScroll ); + add( upperPad ); + add( inicioLabel ); + add( dataInicioPanel ); + add( fimLabel ); + add( dataFimPanel ); + add( procurarButton ); + add( lowerPad ); + add( pathButton ); + add( pathText ); + add( impressorasCombo ); + add( imprimirButton ); + add( imprimirTodasButton ); + + upperPanel.setLayout( new GridLayout( 1, 2 ) ); + upperPanel.add( empresasScroll ); + upperPanel.add( estabelecimentosScroll ); + ColumnizedMappable empresas[] = provider.getAllEmpresas(); + Vector values = empresasModel.getValues(); + values.addAll( Arrays.asList( empresas ) ); + empresasModel.setValues( values ); + + Properties properties = propertyHandler.load(); +System.out.println( properties ); + String path = (String) properties.get( getClass().getName() + PATH_PROPERTY_SUFFIX ); + if( path == null ) + { + setDirectorio( System.getProperty( "user.home" ) ); + } + else + { + pathText.setText( path ); + } + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( e.getValueIsAdjusting() ) + { + return; + } + if( source.equals( empresasTable.getSelectionModel() ) ) + { + carregarEstabelecimentos(); + } + else if( source.equals( estabelecimentosTable.getSelectionModel() ) ) + { + procurarButton.setEnabled( estabelecimentosTable.getSelectedRow() != -1 ); + } + else if( source.equals( fichasTable.getSelectionModel() ) ) + { + imprimirButton.setEnabled( fichasTable.getSelectedRow() != -1 ); + } + } + + protected void carregarEstabelecimentos() + { + estabelecimentosTable.clearSelection(); + int selected = empresasTable.getSelectedRow(); + estabelecimentosModel.clearAll(); + if( selected > -1 ) + { + try + { + Integer empresaID = ( ( ColumnizedMappable ) empresasModel.getRowAt( selected ) ).getID(); + ColumnizedMappable estabelecimentos[] = provider.getAllEstabelecimentosForEmpresa( empresaID); + Vector values = estabelecimentosModel.getValues(); + values.addAll( Arrays.asList( estabelecimentos ) ); + estabelecimentosModel.setValues( values ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os estabelecimentos.", true ); + estabelecimentosModel.clearAll(); + } + } + } + + public void clear() + { + empresasTable.clearSelection(); + } + + public void fill( Object value ) + { + if( value == null ) + { + clear(); + } + Integer ids[] = ( Integer [] ) value; + for( int n = 0; n < empresasTable.getRowCount(); n++ ) + { + if( ( ( ColumnizedMappable ) empresasModel.getRowAt( n ) ).getID().equals( ids[ 0 ] ) ) + { + empresasTable.setRowSelectionInterval( n, n ); + break; + } + } + + for( int n = 0; n < estabelecimentosTable.getRowCount(); n++ ) + { + if( ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( n ) ).getID().equals( ids[ 1 ] ) ) + { + estabelecimentosTable.setRowSelectionInterval( n, n ); + break; + } + } + } + + public Object save() + { + int empresaSelected = empresasTable.getSelectedRow(); + int estabelecimentoSelected = estabelecimentosTable.getSelectedRow(); + return new Integer[]{ + empresaSelected == -1 ? null : ( ( ColumnizedMappable ) empresasModel.getRowAt( empresaSelected ) ).getID(), + estabelecimentoSelected == -1 ? null : ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( estabelecimentoSelected ) ).getID() + }; + } + + public void setEnabled( boolean enable ) + { + empresasTable.setEnabled( enable ); + estabelecimentosTable.setEnabled( enable ); + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( procurarButton ) ) + { + procurar(); + } + else if( source.equals( imprimirButton ) ) + { + imprimir(); + } + else if( source.equals( imprimirTodasButton ) ) + { + imprimirTodas(); + } + else if( source.equals( pathButton ) ) + { + escolherDirectorio(); + } + } + + public void procurar() + { + int selected = estabelecimentosTable.getSelectedRow(); + Date dataInicio = dataInicioPanel.getDate(); + Date dataFim = dataFimPanel.getDate(); + if( selected == -1 || ( dataInicio == null && dataFim == null ) ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher pelo menos uma data e um estabelecimento.", "Erro", + JOptionPane.ERROR_MESSAGE ); + return; + } + if( dataInicio == null ) + { + dataInicio = dataFim; + } + else if( dataFim == null ) + { + dataFim = dataInicio; + } + fichasModel.clearAll(); + try + { + Integer estabelecimentoID = ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( selected ) ).getID(); + Object fichas[][] = provider.getAllFichasForEstabelecimentoAndDatas( estabelecimentoID, dataInicio, dataFim ); + Vector values = fichasModel.getValues(); + for( int n = 0; n < fichas.length; n++ ) + { + values.add( new ColumnizedObjectArray( fichas[ n ], true ) ); + } + fichasModel.setValues( values ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar a lista.", true ); + estabelecimentosModel.clearAll(); + } + imprimirTodasButton.setEnabled( fichasTable.getRowCount() > 0 ); + } + + public void imprimir() + { + imprimirLinhas( fichasTable.getSelectedRows() ); + } + + public void imprimirTodas() + { + int linhas[] = new int[ fichasTable.getRowCount() ]; + for( int n = 0; n < linhas.length; n++ ) + { + linhas[ n ] = n; + } + imprimirLinhas( linhas ); + } + + protected void imprimirLinhas( int linhas[] ) + { + try + { + File file = new File( pathText.getText().trim() ); + if( !file.exists() || !file.isDirectory() ) + { + throw new IOException( "Direct\u00f3rio inexistente ou indispon\u00edvel: " + pathText.getText().trim() ); + } + } + catch( IOException ioex ) + { + JOptionPane.showMessageDialog( this, ioex.getMessage(), "Erro...", + JOptionPane.ERROR_MESSAGE ); + return; + } + String impressora = ( String ) impressorasCombo.getSelectedItem(); + Integer ids[] = new Integer[ linhas.length ]; + for( int n = 0; n < ids.length; n++ ) + { + ids[ n ] = ( ( ColumnizedObjectArray )fichasModel.getRowAt( linhas[ n ] ) ).getID(); + } + int option = JOptionPane.showConfirmDialog( this, "Imprimir as " + ids.length + " fichas para a impressora " + impressora + "?", + "Imprimir", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE ); + if( option == 0 ) + { + System.out.println( "imprimir" ); + new FichasPrinter( ids, impressora, pathText.getText().trim(), + empresasModel.getRowAt( empresasTable.getSelectedRow() ).toString(), + estabelecimentosModel.getRowAt( estabelecimentosTable.getSelectedRow() ).toString() ).start(); + } + } + + protected void escolherDirectorio() + { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); + int returnVal = chooser.showOpenDialog( this ); + if(returnVal == JFileChooser.APPROVE_OPTION) + { + setDirectorio( chooser.getSelectedFile().getAbsolutePath() ); + } + } + + protected void setDirectorio( String path ) + { + if( path != null ) + { + pathText.setText( path ); + Properties properties = propertyHandler.load(); + properties.setProperty( getClass().getName() + PATH_PROPERTY_SUFFIX, path ); + try + { + propertyHandler.save( properties ); + } + catch( IOException ioex ) + { + ioex.printStackTrace(); + } + } + } +} diff --git a/trunk/siprp/impressaofichas/lista_fichas.xsl b/trunk/siprp/impressaofichas/lista_fichas.xsl new file mode 100644 index 00000000..46096481 --- /dev/null +++ b/trunk/siprp/impressaofichas/lista_fichas.xsl @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + RELAÇÃO DE FICHAS DE APTIDÃO ENVIADAS + + + + + + + + + + + + NOME + + + + + DATA EXAME + + + + + PRÓXIMO EXAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/siprp/pesquisas/PesquisasProvider.java b/trunk/siprp/pesquisas/PesquisasProvider.java new file mode 100644 index 00000000..632d8b18 --- /dev/null +++ b/trunk/siprp/pesquisas/PesquisasProvider.java @@ -0,0 +1,751 @@ +/* + * EstatisticasProvider.java + * + * Created on 3 de Junho de 2004, 18:23 + */ + +package siprp.pesquisas; + +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.arrays.*; +import com.evolute.utils.data.*; +import com.evolute.utils.db.*; +import com.evolute.utils.db.keyretrievers.*; +import com.evolute.utils.metadb.*; +import com.evolute.utils.sql.*; +import com.evolute.utils.sql.expression.*; + +import siprp.data.*; +/** + * + * @author fpalma + */ +public class PesquisasProvider extends MetaProvider +{ + private static final Object LOCK = new Object(); + private static PesquisasProvider instance = null; + private final Executer executer; + + private static final int TIPOS_OCASIONAL[] = + new int[]{ 5, //mudanca de posto + 6, //mudancas das condicoes + -1, //apos 30 dias + 4, //iniciativa do medico + 3, //pedido do trabalhador + 2, //acidente de trabalho + 1, //Doenca subita + -1, //Cessacao do contrato + 10 //Outras razoes + }; + public static final String DESCRICAO_TIPOS_OCASIONAL[] = + new String[]{ "MUDAN\u00C7A DE POSTO DE TRABALHO", + "ALTERA\u00C7\u00D5ES NO POSTO DE TRABALHO", + "REGRESSO AO TRABALHO AP\u00D3S AUS\u00CANCIA SUPERIOR A 30 DIAS", + "INICIATIVA DO M\u00C9DICO", + "PEDIDO DO TRABALHADOR", + "ACIDENTE DE TRABALHO", + "DOEN\u00C7A S\u00DABITA", + "POR CESSA\u00C7\u00C3O DO CONTRATO DE TRABALHO", + "OUTRAS RAZ\u00D5ES" }; + + private static final int TIPOS_EXAME[] = + new int[]{ 1, //admissao + 2, //periodico + 3 //ocasional + }; + private static final int TIPO_OCASIONAL = 3; + + public static final String DESCRICAO_TIPOS_EXAME[] = + new String[]{ "TOTAL DE EXAMES DE ADMISS\u00C3O", + "TOTAL DE EXAMES PERI\u00D3DICOS", + "TOTAL DE EXAMES OCASIONAIS" }; + + public static final String PAR_ANO = "PAR_ANO"; + public static final String PAR_EMPRESA = "PAR_EMPRESA"; + public static final String PAR_ESTABELECIMENTO = "PAR_ESTABELECIMENTO"; + public static final String PAR_TIPO_EXAME = "PAR_TIPO_EXAME"; + public static final String PAR_RESULTADO = "PAR_RESULTADO"; + public static final String PAR_SEXO = "PAR_SEXO"; + public static final String PAR_GRUPO_ETARIO = "PAR_GRUPO_ETARIO"; + + /** Creates a new instance of EstatisticasProvider */ + public PesquisasProvider() throws Exception + { + DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ ); + executer = dbm.getSharedExecuter( this ); + } + + public static MetaProvider getProvider() + throws Exception + { + synchronized( LOCK ) + { + if( instance == null ) + { + instance = new PesquisasProvider(); + } + } + return instance; + } + + public IDObject[] getAllEmpresas() + throws Exception + { + Select select = new Select( new String[]{ "empresas" }, + new String[]{ EmpresaData.ID, EmpresaData.DESIGNACAO_SOCIAL, EmpresaData.DESIGNACAO_SOCIAL_PLAIN }, + new Field( EmpresaData.INACTIVO ).isDifferent( "y" ), + new String[]{ EmpresaData.DESIGNACAO_SOCIAL_PLAIN }, null ); +// Select select = new Select( "SELECT e.id, e.designacao_social FROM empresas e ORDER BY lower( e.designacao_social );" ); + Virtual2DArray array = executer.executeQuery( select ); + IDObject empresas[] = new IDObject[ array.columnLength() ]; + for( int n = 0; n < empresas.length; n++ ) + { + empresas[ n ] = new MappableObject( (Integer)array.get( n, 0 ), array.get( n, 1 ) ); + } + return empresas; + } + + public IDObject []getAllEstabelecimentosForEmpresa( Integer empresaID ) + throws Exception + { + return ( ( siprp.FichaDataProvider )siprp.FichaDataProvider.getProvider() ).getAllEstabelecimentosForEmpresa( empresaID ); + } + + public int[] countTrabalhadoresEstabelecimentoDezembro( Integer estabelecimentoID, int ano ) + throws Exception + { + Calendar cal = Calendar.getInstance(); + cal.set( Calendar.YEAR, ano ); + cal.set( Calendar.MONTH, 11 ); + cal.set( Calendar.DAY_OF_MONTH, 30 ); + Select select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "m" ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( cal.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + int contagem[] = new int[ 2 ]; + contagem[ 0 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "f" ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( cal.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 1 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + return contagem; + } + + public int[][] countTrabalhadoresEstabelecimentoDezembroPorGrupoEtario( Integer estabelecimentoID, int ano ) + throws Exception + { + Calendar eoy = Calendar.getInstance(); + eoy.set( Calendar.YEAR, ano ); + eoy.set( Calendar.MONTH, 11 ); + eoy.set( Calendar.DAY_OF_MONTH, 30 ); + + Calendar today = Calendar.getInstance(); + today.set( Calendar.YEAR, ano ); + today.set( Calendar.MONTH, 11 ); + today.set( Calendar.DAY_OF_MONTH, 31 ); + today.set( Calendar.HOUR_OF_DAY, 23 ); + Calendar age18 = (Calendar) today.clone(); + age18.add( Calendar.YEAR, -18 ); + Calendar age50 = (Calendar) today.clone(); + age50.add( Calendar.YEAR, -50 ); + //0-18 + Select select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "m" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( age18.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + int contagem[][] = new int[ 3 ][ 2 ]; + contagem[ 0 ][ 0 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "f" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( age18.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 0 ][ 1 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + //18-49 + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "m" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( age18.getTime() ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( age50.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 1 ][ 0 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "f" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( age18.getTime() ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( age50.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 1 ][ 1 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + + //50- + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "m" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( age50.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 2 ][ 0 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + select = + new Select( new String[]{ "trabalhadores" }, + new String[]{ "COUNT(" + TrabalhadorData.ID + ")" }, + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ).and( + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( "f" ) ).and( + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( age50.getTime() ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ).and( + new Par( new Field( TrabalhadorData.DATA_DEMISSAO ).isGreater( eoy.getTime() ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ) ); + array = executer.executeQuery( select ); + contagem[ 2 ][ 1 ] = ( ( Number ) array.get( 0, 0 ) ).intValue(); + + return contagem; + } + + public int[][] countExamesEstabelecimentoDezembroPorGrupoEtario( Integer estabelecimentoID, int ano ) + throws Exception + { + Calendar today = Calendar.getInstance(); + today.set( Calendar.YEAR, ano ); + today.set( Calendar.MONTH, 11 ); + today.set( Calendar.DAY_OF_MONTH, 31 ); + today.set( Calendar.HOUR_OF_DAY, 23 ); + Calendar age18 = (Calendar) today.clone(); + age18.add( Calendar.YEAR, -18 ); + Calendar age50 = (Calendar) today.clone(); + age50.add( Calendar.YEAR, -50 ); + Calendar dates[] = new Calendar[]{ null, age18, age50, null }; + String sexos[] = new String[]{ "m", "f" }; + + int contagem[][] = new int[ 4 ][ 6 ]; + for( int t = 0; t < TIPOS_EXAME.length; t++ ) + { + for( int s = 0; s < sexos.length; s++ ) + { + for( int d = 0; d < dates.length - 1; d++ ) + { + Select select = + new Select( new String[]{ "exames", "trabalhadores" }, + new String[]{ "DISTINCT trabalhadores.id, exames.data" }, + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ).and( + new Field( "exames.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[s] ) ).and( + new Field( "YEAR( exames.data )" ).isEqual( new Integer( ano ) ) ).and( + dates[ d ] == null ? new Field( "exames.id" ).isDifferent( null ) : + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( dates[ d ].getTime() ) ).and( + dates[ d + 1 ] == null ? new Field( "exames.id" ).isDifferent( null ) : + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( dates[ d + 1 ].getTime() ) ).and( + new Field( "exames.tipo" ).isEqual( new Integer( TIPOS_EXAME[ t ] ) ) ).and( + new Field( "exames.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); + try + { + Virtual2DArray array = executer.executeQuery( select ); + contagem[ t ][ s * 3 + d ] = array.columnLength(); +//System.out.println( select + ": " + contagem[ t ][ s * 3 + d ] ); + } + catch( Exception ex ) + { + contagem[ t ][ s * 3 + d ] = -1; + } + } + } + } + + return contagem; + } + + public int[][] countExamesOcasionaisEstabelecimentoDezembroPorGrupoEtario( Integer estabelecimentoID, int ano ) + throws Exception + { + Calendar today = Calendar.getInstance(); + today.set( Calendar.YEAR, ano ); + today.set( Calendar.MONTH, 11 ); + today.set( Calendar.DAY_OF_MONTH, 31 ); + today.set( Calendar.HOUR_OF_DAY, 23 ); + Calendar age18 = (Calendar) today.clone(); + age18.add( Calendar.YEAR, -18 ); + Calendar age50 = (Calendar) today.clone(); + age50.add( Calendar.YEAR, -50 ); + Calendar dates[] = new Calendar[]{ null, age18, age50, null }; + String sexos[] = new String[]{ "m", "f" }; + + int contagem[][] = new int[ TIPOS_OCASIONAL.length ][ ( dates.length - 1 ) * sexos.length ]; + for( int t = 0; t < TIPOS_OCASIONAL.length; t++ ) + { + for( int s = 0; s < sexos.length; s++ ) + { + for( int d = 0; d < dates.length - 1; d++ ) + { + if( TIPOS_OCASIONAL[t] == -1 ) + { + contagem[ t ][ s * 3 + d ] = -1; + continue; + } + + Select select = + new Select( new String[]{ "exames", "trabalhadores" }, + new String[]{ "DISTINCT trabalhadores.id, exames.data" }, + new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ).and( + new Field( "exames.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[s] ) ).and( + new Field( "YEAR( exames.data )" ).isEqual( new Integer( ano ) ) ).and( + dates[ d ] == null ? new Field( "exames.id" ).isDifferent( null ) : + new Field( TrabalhadorData.DATA_NASCIMENTO ).isLessOrEqual( dates[ d ].getTime() ) ).and( + dates[ d + 1 ] == null ? new Field( "exames.id" ).isDifferent( null ) : + new Field( TrabalhadorData.DATA_NASCIMENTO ).isGreater( dates[ d + 1 ].getTime() ) ).and( + new Field( "exames.tipo" ).isEqual( new Integer( 3 ) ) ).and( + new Field( "exames.ocasional" ).isEqual( new Integer( TIPOS_OCASIONAL[ t ] ) ) ).and( + new Field( "exames.inactivo" ).isDifferent( "y" ) ).and( + new Field( "trabalhadores.inactivo" ).isDifferent( "y" ) ) ); + try + { + Virtual2DArray array = executer.executeQuery( select ); + contagem[ t ][ s * 3 + d ] = array.columnLength(); + } + catch( Exception ex ) + { + contagem[ t ][ s * 3 + d ] = -1; + } + } + } + } + + return contagem; + } + + public double[] countNumeroMedioTrabalhadoresEmpresa( Integer empresaID, int ano ) + throws Exception + { + double contagens[] = new double[ 2 ];; + Select select; + String sexos[] = new String[]{ "m", "f" }; + + for( int n = 0; n < sexos.length; n++ ) + { + select = + new Select( new String[]{ "estabelecimentos", "trabalhadores" }, + new String[]{ "COUNT(trabalhadores.id)" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLess( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_DEMISSAO + ")" ).isGreater( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[ n ] ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + contagens[ n ] = ( ( Number ) array.get( 0, 0 ) ).doubleValue(); + } + for( int n = 0; n < sexos.length; n++ ) + { + select = + new Select( new String[]{ "estabelecimentos", "trabalhadores" }, + new String[]{ "SUM( MONTH( data_demissao ) )" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLess( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ) ).and( + new Field( "YEAR(" + TrabalhadorData.DATA_DEMISSAO + ")" ).isEqual( new Integer( ano ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[ n ] ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ) ); +System.out.println( "SELECT: " + select ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.get( 0, 0 ) != null ) + { + contagens[ n ] += ( ( Number ) array.get( 0, 0 ) ).doubleValue() / 12.0; + } + } + + for( int n = 0; n < sexos.length; n++ ) + { + select = + new Select( new String[]{ "estabelecimentos", "trabalhadores" }, + new String[]{ "SUM( ( 1 + 12 - MONTH( data_admissao ) ) )" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isEqual( new Integer( ano ) ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_DEMISSAO + ")" ).isGreater( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[ n ] ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.get( 0, 0 ) != null ) + { + contagens[ n ] += ( ( Number ) array.get( 0, 0 ) ).doubleValue() / 12.0; + } + } + + for( int n = 0; n < sexos.length; n++ ) + { + select = + new Select( new String[]{ "estabelecimentos", "trabalhadores" }, + new String[]{ "SUM( ( 1 + MONTH( data_demissao ) - MONTH( data_admissao ) ) )" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isEqual( new Integer( ano ) ) ).and( + new Field( "YEAR(" + TrabalhadorData.DATA_DEMISSAO + ")" ).isEqual( new Integer( ano ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[ n ] ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.get( 0, 0 ) != null ) + { + contagens[ n ] += ( ( Number ) array.get( 0, 0 ) ).doubleValue() / 12.0; + } + } + + return contagens; + } + + public double[] countNumeroTotalTrabalhadoresEmpresa( Integer empresaID, int ano ) + throws Exception + { + double contagens[] = new double[ 2 ];; + Select select; + String sexos[] = new String[]{ "m", "f" }; + + for( int n = 0; n < sexos.length; n++ ) + { + select = + new Select( new String[]{ "estabelecimentos", "trabalhadores" }, + new String[]{ "COUNT(trabalhadores.id)" }, + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_ADMISSAO + ")" ).isLessOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_ADMISSAO ).isEqual( null ) ) ) ).and( + new Par( new Field( "YEAR(" + TrabalhadorData.DATA_DEMISSAO + ")" ).isGreaterOrEqual( new Integer( ano ) ).or( + new Field( TrabalhadorData.DATA_DEMISSAO ).isEqual( null ) ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( TrabalhadorData.SEXO ).isEqual( sexos[ n ] ) ).and( + new Field( "trabalhadores.inactivo" ).isEqual( "n" ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + contagens[ n ] = ( ( Number ) array.get( 0, 0 ) ).doubleValue(); + } + return contagens; + } + + public String []getNomesExames() + throws Exception + { + String nomes[]; + Select select = + new Select( new String[]{ "tipos_exames_comp" }, + new String[]{ "descricao", "ordem" }, + null, + new String[]{ "ordem" }, null ); + Virtual2DArray array = executer.executeQuery( select ); + nomes = new String[ array.columnLength() ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + nomes[ n ] = ( String )array.get( n, 0 ); + } + return nomes; + } + + public int []countExamesComplementaresEmpresa( Integer empresaID, int ano ) + throws Exception + { +// Vector perfis[] = new Vector[ 2 ]; +// Hashtable contagens[] = new Hashtable[ 2 ]; +// Select select; +// Virtual2DArray array; +// +// for( int p = 0; p < 2; p++ ) +// { +// Integer pAux = new Integer( p + 1 ); +// perfis[ p ] = new Vector(); +// select = new Select( new String[]{"estabelecimentos", "trabalhadores", "marcacoes_trabalhador"}, +// new String[]{"COUNT(marcacoes_trabalhador.id)", TrabalhadorData.PERFIL }, +// new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( +// new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( +// new Field( "empresa_id" ).isEqual( empresaID ) ).and( +// new Field( MarcacaoTrabalhadorData.TIPO ).isEqual( new Integer( MarcacaoTrabalhadorData.TIPO_EXAMES ) ) ).and( +// new Field( "YEAR( marcacoes_trabalhador.data ) " ).isEqual( new Integer( ano ) ).and( +// new Field( MarcacaoTrabalhadorData.ESTADO ).in( new Integer[]{ new Integer( 1 ), new Integer( 2 ) } ) ) ).and( +// new Field( "trabalhadores.perfil" ).isEqual( pAux ) ) ); +// array = executer.executeQuery( select ); +// +// select = +// new Select( new String[]{ "prt_elementos_protocolo", "prt_tipos_elementos_protocolo" }, +// new String[]{ "DISTINCT prt_tipos_elementos_protocolo.grupo_protocolo_id" }, +// new Field( "prt_elementos_protocolo.empresa_id" ).isEqual( empresaID ).and( +// new Field( "prt_elementos_protocolo.tipo_elemento_protocolo_id" ).isEqual( new Field( "prt_elementos_protocolo.id" ) ) ).and( +// new Field( "pr_elementos_protocolo.perfil" ).isEqual( new Integer( p + 1 ) ) ) ); +// array = executer.executeQuery( select ); +// for( int ecd = 0; ecd < array.columnLength(); ecd++ ) +// { +// perfis[ p ].add( ( Integer ) array.get( 0, 0 ) ); +// } +// } +// +// +// return contagens; + + + int contagens[]; + Select select; + select = new Select( new String[]{"empresas"}, new String[]{ "perfil_1", "perfil_2" }, + new Field( "id" ).isEqual( empresaID ) ); + Virtual2DArray array = executer.executeQuery( select ); + String p1Str = (String)array.get( 0, 0 ); + String p2Str = (String)array.get( 0, 1 ); + Number perfil1 = ( p1Str != null && p1Str.length() > 0 )?new Integer( p1Str ):null; + Number perfil2 = ( p2Str != null && p2Str.length() > 0 )?new Integer( p2Str ):null; + select = + new Select( new String[]{ "tipos_exames_comp" }, + new String[]{ "id", "ordem" }, + null, + new String[]{ "ordem" }, null ); + array = executer.executeQuery( select ); + contagens = new int[ array.columnLength() ]; + Hashtable idExames = new Hashtable(); + for( int n = 0; n < array.columnLength(); n++ ) + { + idExames.put( ( Number )array.get( n, 0 ), new Integer( n ) ); + } + if( perfil1 == null && perfil2 == null ) + { + return contagens; + } + else if( perfil1 == null ) + { + perfil1 = perfil2; + } + else if( perfil2 == null ) + { + perfil2 = perfil1; + } + select = new Select( new String[]{"estabelecimentos", "trabalhadores", "marcacoes_trabalhador"}, + new String[]{"COUNT(marcacoes_trabalhador.id)", TrabalhadorData.PERFIL }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) ).and( + new Field( "empresa_id" ).isEqual( empresaID ) ).and( + new Field( MarcacaoTrabalhadorData.TIPO ).isEqual( new Integer( MarcacaoTrabalhadorData.TIPO_EXAMES ) ) ).and( + new Field( "YEAR( marcacoes_trabalhador.data ) " ).isEqual( new Integer( ano ) ).and( + new Field( Marcacao.REALIZADA ).isEqual( "y" ) ) ), + new String[]{ TrabalhadorData.PERFIL }, + new String[]{ TrabalhadorData.PERFIL } ); + array = executer.executeQuery( select ); + int numeroExames[] = new int[ 2 ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer perfil = (Integer)array.get( n, 1 ); + if( perfil == null || perfil.intValue() == 1 ) + { + numeroExames[0] += ( (Number) array.get( n, 0 ) ).intValue(); + } + else if( perfil.intValue() == 2 ) + { + numeroExames[1] += ( (Number) array.get( n, 0 ) ).intValue(); + } + } + + Hashtable hash = new Hashtable(); + select = new Select( new String[]{ "exames_perfis" }, + new String[]{ "tipo", "multiplicador" }, + new Field( "perfil" ).isEqual( perfil1 ) ); + array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Number tipo = (Number) array.get( n, 0 ); + if( tipo == null ) + { + continue; + } + Number multiplicador = (Number) array.get( n, 1 ); + if( multiplicador == null ) + { + multiplicador = new Integer( 1 ); + } + if( idExames.containsKey( tipo ) ) + { + int pos = ((Integer)idExames.get( tipo )).intValue(); + contagens[ pos ] += numeroExames[0] * multiplicador.intValue(); + } + } + select = new Select( new String[]{ "exames_perfis" }, + new String[]{ "tipo", "multiplicador" }, + new Field( "perfil" ).isEqual( perfil2 ) ); + array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Number tipo = (Number) array.get( n, 0 ); + if( tipo == null ) + { + continue; + } + Number multiplicador = (Number) array.get( n, 1 ); + if( multiplicador == null ) + { + multiplicador = new Integer( 1 ); + } + if( idExames.containsKey( tipo ) ) + { + int pos = ((Integer)idExames.get( tipo )).intValue(); + contagens[ pos ] += numeroExames[1] * multiplicador.intValue(); + } + } + return contagens; + } + + public int []countExamesComplementaresEstabelecimento( Integer estabelecimentoID, int ano ) + throws Exception + { + int contagens[]; + Select select; + select = new Select( new String[]{"estabelecimentos", "empresas"}, + new String[]{ "empresas.perfil_1", "empresas.perfil_2" }, + new Field( "estabelecimentos.id" ).isEqual( estabelecimentoID ).and( + new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + String p1Str = (String)array.get( 0, 0 ); + String p2Str = (String)array.get( 0, 1 ); + Number perfil1 = ( p1Str != null && p1Str.length() > 0 )?new Integer( p1Str ):null; + Number perfil2 = ( p2Str != null && p2Str.length() > 0 )?new Integer( p2Str ):null; + select = + new Select( new String[]{ "tipos_exames_comp" }, + new String[]{ "id", "ordem" }, + null, + new String[]{ "ordem" }, null ); + array = executer.executeQuery( select ); + contagens = new int[ array.columnLength() ]; + Hashtable idExames = new Hashtable(); + for( int n = 0; n < array.columnLength(); n++ ) + { + idExames.put( ( Number )array.get( n, 0 ), new Integer( n ) ); + } + if( perfil1 == null && perfil2 == null ) + { + return contagens; + } + else if( perfil1 == null ) + { + perfil1 = perfil2; + } + else if( perfil2 == null ) + { + perfil2 = perfil1; + } + select = new Select( new String[]{"trabalhadores", "marcacoes_trabalhador"}, + new String[]{"COUNT(marcacoes_trabalhador.id)", TrabalhadorData.PERFIL }, + new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ).and( + new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and( + new Field( MarcacaoTrabalhadorData.TIPO ).isEqual( new Integer( MarcacaoTrabalhadorData.TIPO_EXAMES ) ) ).and( + new Field( "YEAR( marcacoes_trabalhador.data ) " ).isEqual( new Integer( ano ) ).and( + new Field( Marcacao.REALIZADA ).isEqual( "y" ) ) ), + new String[]{ TrabalhadorData.PERFIL }, + new String[]{ TrabalhadorData.PERFIL } ); + array = executer.executeQuery( select ); + int numeroExames[] = new int[ 2 ]; + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer perfil = (Integer)array.get( n, 1 ); + if( perfil == null || perfil.intValue() == 1 ) + { + numeroExames[0] += ( (Number) array.get( n, 0 ) ).intValue(); + } + else if( perfil.intValue() == 2 ) + { + numeroExames[1] += ( (Number) array.get( n, 0 ) ).intValue(); + } + } + + Hashtable hash = new Hashtable(); + select = new Select( new String[]{ "exames_perfis" }, + new String[]{ "tipo", "multiplicador" }, + new Field( "perfil" ).isEqual( perfil1 ) ); + array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Number tipo = (Number) array.get( n, 0 ); + if( tipo == null ) + { + continue; + } + Number multiplicador = (Number) array.get( n, 1 ); + if( multiplicador == null ) + { + multiplicador = new Integer( 1 ); + } + if( idExames.containsKey( tipo ) ) + { + int pos = ((Integer)idExames.get( tipo )).intValue(); + contagens[ pos ] += numeroExames[0] * multiplicador.intValue(); + } + } + select = new Select( new String[]{ "exames_perfis" }, + new String[]{ "tipo", "multiplicador" }, + new Field( "perfil" ).isEqual( perfil2 ) ); + array = executer.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Number tipo = (Number) array.get( n, 0 ); + if( tipo == null ) + { + continue; + } + Number multiplicador = (Number) array.get( n, 1 ); + if( multiplicador == null ) + { + multiplicador = new Integer( 1 ); + } + if( idExames.containsKey( tipo ) ) + { + int pos = ((Integer)idExames.get( tipo )).intValue(); + contagens[ pos ] += numeroExames[1] * multiplicador.intValue(); + } + } + return contagens; + } +} diff --git a/trunk/siprp/pesquisas/PesquisasWindow.java b/trunk/siprp/pesquisas/PesquisasWindow.java new file mode 100644 index 00000000..c08d21b1 --- /dev/null +++ b/trunk/siprp/pesquisas/PesquisasWindow.java @@ -0,0 +1,578 @@ +/* + * PesquisasWindow.java + * + * Created on 3 de Junho de 2004, 18:13 + */ + +package siprp.pesquisas; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import com.evolute.utils.*; +import com.evolute.utils.data.*; +import com.evolute.utils.documents.*; +import com.evolute.utils.jdo.*; +import com.evolute.utils.tables.*; +import com.evolute.utils.tracker.*; +import com.evolute.utils.ui.*; +import com.evolute.utils.ui.text.*; + +import siprp.data.*; + +/** + * + * @author fpalma + */ +public class PesquisasWindow extends JFrame + implements TrackableWindow, ListSelectionListener, ActionListener +{ + private JDOProvider JDO; + private PesquisasProvider provider; + + private JTextField anoText; + private BaseTable empresasTable; + private VectorTableModel empresasModel; + private BaseTable estabelecimentosTable; + private VectorTableModel estabelecimentosModel; + private JButton pesquisarButton; + private JButton exportarButton; + private JEditorPane resultadoText; + +// public static void main( String args[] ) +// throws Exception +// { +// new PesquisasWindow().show(); +// } + + /** Creates a new instance of PesquisasWindow */ + public PesquisasWindow() + throws Exception + { + provider = (PesquisasProvider)PesquisasProvider.getProvider(); + JDO =( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); + setupComponents(); + } + + private void setupComponents() + { + setSize( 1000, 700 ); + setTitle( "Relat\u00f3rio Anual" ); + + JLabel anoLabel = new JLabel( "Ano" ); + anoText = new JTextField(); + anoText.setDocument( new YearDocument() ); + anoText.setPreferredSize( new Dimension( 50, 20 ) ); + new CopyPasteHandler( anoText ); + + empresasModel = new VectorTableModel( new String[]{ "Designa\u00e7\u00e3o Social" } ); + empresasTable = new BaseTable( empresasModel ); + empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + empresasTable.setNonResizableNorReordable(); + empresasTable.getSelectionModel().addListSelectionListener( this ); + JScrollPane empresasScroll = new JScrollPane(); + empresasScroll.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Empresa" ) ); + empresasScroll.setViewportView( empresasTable ); + empresasScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + empresasScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + empresasScroll.getVerticalScrollBar().setBlockIncrement(20); + + estabelecimentosModel = new VectorTableModel( new String[]{ "Nome" } ); + estabelecimentosTable = new BaseTable( estabelecimentosModel ); + estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + estabelecimentosTable.setNonResizableNorReordable(); + estabelecimentosTable.getSelectionModel().addListSelectionListener( this ); + JScrollPane estabelecimentosScroll = new JScrollPane(); + estabelecimentosScroll.setBorder( BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(), "Estabelecimento" ) ); + estabelecimentosScroll.setViewportView( estabelecimentosTable ); + estabelecimentosScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + estabelecimentosScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + + pesquisarButton = new JButton( "Pesquisar" ); + pesquisarButton.addActionListener( this ); + exportarButton = new JButton( "Exportar" ); + exportarButton.addActionListener( this ); + + resultadoText = new JEditorPane( "text/html", "" ); + resultadoText.setEditable( false ); +// resultadoText.setLineWrap( true ); +// resultadoText.setWrapStyleWord( true ); + new CopyPasteHandler( resultadoText ); + JScrollPane resultadoScroll = new JScrollPane(); + resultadoScroll.setViewportView( resultadoText ); + resultadoScroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); + resultadoScroll.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); + + JPanel pad; + + GridBagLayout gridbag = new GridBagLayout(); + getContentPane().setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 5, 5, 5, 5 ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + JPanel anoPanel = new JPanel(); + anoPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); + anoPanel.add( anoLabel ); + anoPanel.add( anoText ); + gridbag.setConstraints( anoPanel, constraints ); + getContentPane().add( anoPanel ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0.2; + constraints.gridheight = 2; + constraints.weightx = 0.3; + constraints.gridwidth = 3; + gridbag.setConstraints( empresasScroll, constraints ); + getContentPane().add( empresasScroll ); + + gridbag.setConstraints( estabelecimentosScroll, constraints ); + getContentPane().add( estabelecimentosScroll ); + + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + getContentPane().add( pad ); + + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0; + constraints.gridwidth = 1; + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout( new GridLayout( 1, 2 ) ); + buttonPanel.add( pesquisarButton ); + buttonPanel.add( exportarButton ); + gridbag.setConstraints( buttonPanel, constraints ); + getContentPane().add( buttonPanel ); + + constraints.weighty = 0; + constraints.gridheight = 1; + constraints.weightx = 0.4; + constraints.gridwidth = GridBagConstraints.REMAINDER; + pad = new JPanel(); + gridbag.setConstraints( pad, constraints ); + getContentPane().add( pad ); + + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0.8; + constraints.gridheight = GridBagConstraints.REMAINDER; + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( resultadoScroll, constraints ); + getContentPane().add( resultadoScroll ); + } + + private boolean close() + { + setVisible( false ); + dispose(); + return true; + } + + public boolean closeIfPossible() + { + return close(); + } + + public void open() + { + empresasTable.clearSelection(); + try + { + IDObject empresas[] = provider.getAllEmpresas(); + empresasModel.setValues( new Vector( Arrays.asList( empresas ) ) ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados", true ); + } + setVisible( true ); + } + + public void refresh() + { + } + + public void valueChanged( ListSelectionEvent e ) + { + Object source = e.getSource(); + if( source.equals( empresasTable.getSelectionModel() ) ) + { + estabelecimentosTable.clearSelection(); + int selected = empresasTable.getSelectedRow(); + if( selected == -1 ) + { + return; + } + IDObject empresa = (IDObject) empresasModel.getRowAt( selected ); + estabelecimentosModel.clearAll(); + IDObject estabelecimentos[]; + try + { + estabelecimentos = provider.getAllEstabelecimentosForEmpresa( empresa.getID() ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar os estabelecimentos", true ); + return; + } + Vector v = new Vector( Arrays.asList( estabelecimentos ) ); + v.add( new MappableObject( new Integer( -1 ), "TODOS" ) ); + estabelecimentosModel.setValues( v ); + } +/* else if( source.equals( estabelecimentosTable.getSelectionModel() ) ) + { + }*/ + } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source.equals( pesquisarButton ) ) + { + int sEmpresa = empresasTable.getSelectedRow(); + int sEstabelecimento = estabelecimentosTable.getSelectedRow(); + String anoStr = anoText.getText(); + int ano = ( anoStr.length() != 0 )? Integer.parseInt( anoStr ): -1; + if( sEmpresa == -1 || ano == -1 ) + { + JOptionPane.showMessageDialog( this, "Tem de escolher ano e empresa", "Erro...", + JOptionPane.ERROR_MESSAGE ); + return; + } + StringBuffer buff = new StringBuffer(); + buff.append( "ANO: " ); + buff.append( "" + ano + "
" ); + buff.append( "
EMPRESA
" ); + try + { + Integer idEmpresa = ( (IDObject)empresasModel.getRowAt( sEmpresa ) ).getID(); + EmpresaData empresa = (EmpresaData)JDO.load( EmpresaData.class, idEmpresa ); + buff.append( " DESIGNA\u00C7\u00C3O SOCIAL: " ); + String designacao = (String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL ); + buff.append( "" + ( designacao == null ? "" : designacao.trim() ) + "
" ); + buff.append( " MORADA: " ); + String morada = (String)empresa.get( EmpresaData.MORADA ); + buff.append( "" + ( morada == null ? "" : morada.trim() ) + "
" ); + buff.append( " LOCALIDADE: " ); + String localidade = ( String ) empresa.get( EmpresaData.LOCALIDADE ); + buff.append( "" + ( localidade == null ? "" : localidade.trim() ) + "
" ); + buff.append( " C\u00D3DIGO POSTAL: " ); + String codigoPostal = ( String ) empresa.get( EmpresaData.CODIGO_POSTAL ); + buff.append( "" + ( codigoPostal == null ? "" : codigoPostal.trim() ) + "
" ); + ContactoData contacto = (ContactoData)empresa.get( EmpresaData.CONTACTO_2 ); + if( contacto == null ) + { + buff.append( " TELEFONE:
" ); + buff.append( " FAX:
" ); + } + else + { + buff.append( " TELEFONE: " ); + String telefone = ( String ) contacto.get( ContactoData.TELEFONE ); + buff.append( "" + ( telefone == null ? "" : telefone.trim() ) + "
" ); + buff.append( " FAX: " ); + String fax = ( String ) contacto.get( ContactoData.TELEFONE ); + buff.append( "" + ( fax == null ? "" : fax.trim() ) + "
" ); + } + buff.append( " DISTRITO: " ); + String distrito = ( String ) empresa.get( EmpresaData.DISTRITO ); + buff.append( "" + ( distrito == null ? "" : distrito ) + "
" ); + buff.append( " CONCELHO: " ); + String concelho = ( String ) empresa.get( EmpresaData.CONCELHO ); + buff.append( "" + ( concelho == null ? "" : concelho ) + "
" ); + buff.append( " N\u00DAMERO PESSOA COLECTIVA: " ); + String contribuinte = ( String ) empresa.get( EmpresaData.CONTRIBUINTE ); + buff.append( "" + ( contribuinte == null ? "" : contribuinte ) + "
" ); + buff.append( " N\u00DAMERO SEGURAN\u00C7A SOCIAL: " ); + String segSocial = ( String ) empresa.get( EmpresaData.SEGURANCA_SOCIAL ); + buff.append( "" + ( segSocial == null ? "" : segSocial ) + "
" ); + buff.append( " CAE: " ); + String CAE = ( String ) empresa.get( EmpresaData.CAE ); + buff.append( "" + ( CAE == null ? "" : CAE ) + "
" ); + buff.append( "
 N\u00DAMERO M\u00C9DIO DE TRABALHADORES DURANTE O ANO" ); + double contagemMedia[] = provider.countNumeroMedioTrabalhadoresEmpresa( idEmpresa, ano ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( ""); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "
    TOTAL HOMENS MULHERES
  TOTAL " + (int)( Math.round( contagemMedia[0] ) + Math.round( contagemMedia[1] ) ) + " " + ( (int)Math.round( contagemMedia[0] ) ) + " " + ( (int)Math.round( contagemMedia[1] ) ) + "
" ); + buff.append( "
 N\u00DAMERO TOTAL DE TRABALHADORES DURANTE O ANO" ); + double contagemTotal[] = provider.countNumeroTotalTrabalhadoresEmpresa( idEmpresa, ano ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( ""); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "
    TOTAL HOMENS MULHERES
  TOTAL " + (int)( Math.round( contagemTotal[0] ) + Math.round( contagemTotal[1] ) ) + " " + ( (int)Math.round( contagemTotal[0] ) ) + " " + ( (int)Math.round( contagemTotal[1] ) ) + "
" ); + + IDObject estabelecimentos[]; + if( sEstabelecimento == -1 || ( ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ) ).getID().equals( new Integer( -1 ) ) ) + { + estabelecimentos = provider.getAllEstabelecimentosForEmpresa( idEmpresa ); + } + else + { + estabelecimentos = new IDObject[ 1 ]; + estabelecimentos[ 0 ] = ( IDObject )estabelecimentosModel.getRowAt( sEstabelecimento ); + } + buff.append( "
" ); + buff.append( "
 ESTABELECIMENTOS
" ); + buff.append( "
" ); + for( int n = 0; n < estabelecimentos.length; n++ ) + { + EstabelecimentoData estabelecimento = (EstabelecimentoData)JDO.load( EstabelecimentoData.class, estabelecimentos[ n ].getID() ); + buff.append( "  NOME: " ); + String nome = (String)estabelecimento.get( EstabelecimentoData.NOME ); + buff.append( "" + ( nome == null ? "" : nome.trim() ) + "
" ); + buff.append( "  MORADA: " ); + morada = (String)estabelecimento.get( EstabelecimentoData.MORADA ); + buff.append( "" + ( morada == null ? "" : morada.trim() ) + "
" ); + buff.append( "  LOCALIDADE: " ); + localidade = (String)estabelecimento.get( EstabelecimentoData.LOCALIDADE ); + buff.append( "" + ( localidade == null ? "" : localidade.trim() ) + "
" ); + buff.append( "  C\u00D3DIGO POSTAL: " ); + codigoPostal = (String)estabelecimento.get( EstabelecimentoData.CODIGO_POSTAL ); + buff.append( "" + ( codigoPostal == null ? "" : codigoPostal.trim() ) + "
" ); + contacto = (ContactoData)estabelecimento.get( EstabelecimentoData.CONTACTO ); + if( contacto == null ) + { + buff.append( "  TELEFONE:
" ); + buff.append( "  FAX:
" ); + } + else + { + buff.append( "  TELEFONE: " ); + String telefone = ( String ) contacto.get( ContactoData.TELEFONE ); + buff.append( "" + ( telefone == null ? "" : telefone.trim() ) + "
" ); + buff.append( "  FAX: " ); + String fax = ( String ) contacto.get( ContactoData.TELEFONE ); + buff.append( "" + ( fax == null ? "" : fax.trim() ) + "
" ); + } + int countTrabalhadores[] = provider.countTrabalhadoresEstabelecimentoDezembro( estabelecimentos[ n ].getID(), ano ); + buff.append( "
" ); + buff.append( "  TRABALHADORES A 31 DE DEZEMBRO DE " + ano + ": " ); + buff.append( "
" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" + + "" + + "" + + "" ); + buff.append( "" ); + int countTrabalhadoresEtario[][] = provider.countTrabalhadoresEstabelecimentoDezembroPorGrupoEtario( estabelecimentos[ n ].getID(), ano ); + buff.append( "" ); + buff.append( "" + + "" + + "" + + "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" + + "" + + "" + + "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" + + "" + + "" + + "" ); + buff.append( "" ); + buff.append( "
   TOTALHOMENSMULHERES
  TOTAL " + ( countTrabalhadores[0] + countTrabalhadores[1] ) + " " + ( countTrabalhadores[0] ) + " " + ( countTrabalhadores[1] ) + "
  MENOS DE 18 ANOS " + ( countTrabalhadoresEtario[0][0] + countTrabalhadoresEtario[0][1] ) + " " + ( countTrabalhadoresEtario[0][0] ) + " " + ( countTrabalhadoresEtario[0][1] ) + "
  18 A 49 ANOS " + ( countTrabalhadoresEtario[1][0] + countTrabalhadoresEtario[1][1] ) + " " + ( countTrabalhadoresEtario[1][0] ) + " " + ( countTrabalhadoresEtario[1][1] ) + "
  MAIS DE 50 ANOS " + ( countTrabalhadoresEtario[2][0] + countTrabalhadoresEtario[2][1] ) + " " + ( countTrabalhadoresEtario[2][0] ) + " " + ( countTrabalhadoresEtario[2][1] ) + "
" ); + buff.append( "
" ); + int countExames[][] = provider.countExamesEstabelecimentoDezembroPorGrupoEtario( estabelecimentos[ n ].getID(), ano ); + for( int cE = 0; cE < countExames[ countExames.length - 2 ].length; cE++ ) + { + countExames[ countExames.length - 2 ][ cE ] += countExames[ countExames.length - 1 ][ cE ]; + } + int totais[] = new int[ 6 ]; + for( int cE1 = 0; cE1 < totais.length; cE1++ ) + { + for( int cE2 = 0; cE2 < countExames.length; cE2++ ) + { + totais[ cE1 ] += countExames[ cE2 ][ cE1 ]; + } + } + buff.append( "
" ); + buff.append( "  N\u00DAMERO DE EXAMES DE ADMISS\u00C3O, PERI\u00D3DICOS E OCASIONAIS EFECTUADOS" ); + buff.append( "
" ); + buff.append( "" ); + buff.append( "" + + "" ); + buff.append( "" ); + buff.append( "" ); + for( int t = 0; t < 3; t++ ) + { + buff.append( "" ); + } + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + for( int t = 3; t < 6; t++ ) + { + buff.append( "" ); + } + buff.append( "" ); + String sexos[] = new String[]{ "H", "M" }; + for( int t = 0; t < provider.DESCRICAO_TIPOS_EXAME.length; t++ ) + { + buff.append( "" ); + + for( int s = 0; s < 2; s++ ) + { + buff.append( "" ); + buff.append( "" ); + for( int d = 0; d < 3; d++ ) + { + buff.append( "" ); + } + if( s == 0 ) + { + buff.append( "" ); + } + else + { + buff.append( "" ); + } + } + } + int countExamesOcasionais[][] = provider.countExamesOcasionaisEstabelecimentoDezembroPorGrupoEtario( estabelecimentos[ n ].getID(), ano ); + for( int t = 0; t < provider.DESCRICAO_TIPOS_OCASIONAL.length; t++ ) + { + buff.append( "" ); + + for( int s = 0; s < 2; s++ ) + { + buff.append( "" ); + int sum = countExamesOcasionais[t][s*3]+countExamesOcasionais[t][s*3+1]+countExamesOcasionais[t][s*3+2]; + buff.append( "" ); + for( int d = 0; d < 3; d++ ) + { + int val = countExamesOcasionais[t][s*3+d]; + if( val < 0 ) + { + countExamesOcasionais[t][s*3+d] = 0; + } + buff.append( "" ); + } + if( s == 0 ) + { + buff.append( "" ); + } + else + { + buff.append( "" ); + } + } + } + buff.append( "
      TOTAL INFERIOR A 18 ANOS 18 A 49 ANOS 50 E MAIS ANOS 
   TOTAL DE EXAMES H" + ( totais[0] + totais[1] + totais[2] ) + " " + totais[t] + " 
     M" + ( totais[3] + totais[4] + totais[5] ) + " " + totais[t] + " 
    "+provider.DESCRICAO_TIPOS_EXAME[t]+" " + sexos[ s ] + "" + (countExames[t][s*3]+countExames[t][s*3+1]+countExames[t][s*3+2]) + " " + countExames[t][s*3+d] + " 
    
       "+provider.DESCRICAO_TIPOS_OCASIONAL[t]+" " + sexos[ s ] + "" + ( sum < 0 ? "-" : "" + sum ) + " " + ( val < 0 ? "-" : "" + val ) + " 
       
" ); + buff.append( "
" ); + buff.append( "  EXAMES COMPLEMENTARES REALIZADOS" ); + buff.append( "
" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + String nomesExamesComp[] = provider.getNomesExames(); +// int countExamesComp[] = provider.countExamesComplementaresEmpresa( idEmpresa, ano ); + int countExamesComp[] = provider.countExamesComplementaresEstabelecimento( estabelecimentos[ n ].getID(), ano ); + for( int nec = 0; nec < nomesExamesComp.length; nec++ ) + { + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + buff.append( "" ); + } + buff.append( "
   TIPO DE EXAME N\u00BA TOTAL DE EXAMES
   " + nomesExamesComp[nec] + " " + countExamesComp[nec] + "
" ); + buff.append("


"); + } + + resultadoText.setText( buff.toString() ); + } + catch( Exception ex ) + { + DialogException.showExceptionMessage( ex, "Erro a carregar dados", true ); + return; + } + } + else if( source.equals( exportarButton ) ) + { + exportar(); + } + } + + public void exportar() + { + FileDialog dialog = new FileDialog( this, "Ficheiro de destino", FileDialog.SAVE ); + dialog.setDirectory( System.getProperty( "user.home" ) ); + dialog.setVisible( true ); + String fileName; + String dirName; + fileName = dialog.getFile(); + dirName = dialog.getDirectory(); + if( fileName != null ) + { + int index = fileName.indexOf( '.' ); + if( index == -1 ) + { + fileName += ".html"; + } + if( index == fileName.length() - 1 ) + { + fileName += "html"; + } + String fullName = dirName + fileName; + String text = resultadoText.getText(); + String title = "S.I.P.R.P. - Sociedade Ibérica de Prevenção de Riscos Profissionais"; + String style = ""; + text = text.replace( "", "\n\t\t" + title + "\n" + style ); + text = text.replace( "", "
" ); + text = text.replace( "", "
" ); + text = text.replace( "", "\n
Relatório Anual
" ); +// String title = "S.I.P.R.P. - Sociedade Ibérica de Prevenção de Riscos Profissionais"; +// text = text.replace( "", "\n\t\t" + title + "" ); +// System.out.println( text ); + try + { + FileWriter writer = new FileWriter( new File( fullName ) ); + writer.write( text ); + writer.close(); + } + catch( IOException ex ) + { + DialogException.showException( ex ); + return; + } + } + } +} + diff --git a/trunk/siprp/web/WebUpdater.java b/trunk/siprp/web/WebUpdater.java new file mode 100644 index 00000000..cf84448f --- /dev/null +++ b/trunk/siprp/web/WebUpdater.java @@ -0,0 +1,1210 @@ +/* + * WebUpdater.java + * + * Created on 27 de Outubro de 2004, 15:54 + */ + +package siprp.web; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.sql.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +//import siprp.*; +//import siprp.clientes.*; + +/** + * + * @author fpalma + */ +public class WebUpdater extends JFrame + implements ActionListener, Runnable, DocumentListener +{ + private Connection softwareConnection; + private Connection webConnection; + + public static final String GET_ULTIMA_ACTUALIZACAO = "SELECT stamp FROM actualizacao"; + + public static final String GET_EMPRESAS = + "SELECT id, designacao_social, perfil_1, perfil_2, codigo_1, codigo_2, " + + "codigo_3, cae, contribuinte, seguranca_social, actividade, servicos, morada, " + + "localidade, codigo_postal, distrito, concelho, inactivo, contacto_1 " + + "FROM empresas WHERE actualizacao >= "; + + public static final String GET_EMAIL = + "SELECT email FROM contactos WHERE id = "; + + public static final String GET_ESTABELECIMENTOS = + "SELECT id, empresa_id, nome, contacto, morada, localidade, codigo_postal, inactivo " + + "FROM estabelecimentos WHERE actualizacao >= "; + + public static final String GET_TRABALHADORES = + "SELECT id, nome, sexo, data_nascimento, numero_mecanografico, categoria, estabelecimento_id, data_demissao, inactivo " + + "FROM trabalhadores WHERE actualizacao >= "; + + public static final String GET_CONTACTO = + "SELECT nome, telefone, telemovel, fax, email, cargo FROM contactos WHERE id = "; + + public static final String GET_MARCACOES_ESTABELECIMENTO = + "SELECT id, data, realizada, data_relatorio FROM marcacoes_estabelecimento " + + "WHERE estabelecimento_id = "; + + public static final String GET_EXAMES_TRABALHADOR = + "SELECT id, data, realizada, data_relatorio FROM marcacoes_trabalhador " + + "WHERE tipo = 0 and trabalhador_id = ?trabalhador_id " + + "ORDER BY data"; + + public static final String GET_CONSULTAS_TRABALHADOR = + "SELECT id, data, realizada, data_relatorio FROM marcacoes_trabalhador " + + "WHERE tipo = 1 and trabalhador_id = ?trabalhador_id " + + "ORDER BY data"; + + public static final String GET_ID_FICHA_APTIDAO = + "SELECT MAX(id) FROM exames WHERE trabalhador_id = ?trabalhador_id AND inactivo <> 'y'"; + + public static final String GET_DADOS_FICHA_APTIDAO = + "SELECT data, resultado FROM exames WHERE id = ?id"; + + public static final String DELETE_TRABALHADOR = + "DELETE FROM trabalhadores WHERE id = "; + + public static final String DELETE_TRABALHADORES_BY_ESTABELECIMENTO = + "DELETE FROM trabalhadores WHERE estabelecimento_id = "; + + public static final String DELETE_ESTABELECIMENTO = + "DELETE FROM estabelecimentos WHERE id = "; + + public static final String DELETE_ESTABELECIMENTOS_BY_EMPRESA = + "DELETE FROM estabelecimentos WHERE empresa_id = "; + + public static final String DELETE_TRABALHADORES_BY_EMPRESA = + "DELETE FROM trabalhadores WHERE estabelecimento_id IN ( SELECT id FROM estabelecimentos WHERE empresa_id = ?empresa_id )"; + + public static final String DELETE_EMPRESA = + "DELETE FROM empresas WHERE id = "; + + public static final String CREATE_EMPRESA = + "INSERT INTO empresas(id) VALUES( ?id )"; + + public static final String CREATE_ESTABELECIMENTO = + "INSERT INTO estabelecimentos(id) VALUES( ?id )"; + + public static final String CREATE_TRABALHADOR = + "INSERT INTO trabalhadores(id) VALUES( ?id )"; + + public static final String UPDATE_EMPRESA = + "UPDATE empresas SET morada = ?morada, codigo_postal = ?codigo_postal, " + + "localidade = ?localidade, distrito = ?distrito, concelho = ?concelho, " + + "perfil_1 = ?perfil_1, perfil_2 = ?perfil_2, codigo = ?codigo, cae = ?cae, " + + "contribuinte = ?contribuinte, seguranca_social = ?seguranca_social, " + + "actividade = ?actividade, servicos = ?servicos, designacao_social = ?designacao_social, " + + "email = ?email " + + "WHERE id = ?id"; + + public static final String UPDATE_ESTABELECIMENTO = + "UPDATE estabelecimentos SET empresa_id = ?empresa_id, morada = ?morada, " + + "codigo_postal = ?codigo_postal, localidade = ?localidade, " + + "ultima_visita = ?ultima_visita, realizada = ?realizada, " + + "proxima_visita = ?proxima_visita, nome = ?nome " + + "WHERE id = ?id"; + + public static final String UPDATE_TRABALHADOR = + "UPDATE trabalhadores SET sexo = ?sexo, data_nascimento = ?data_nascimento, " + + "numero_mecanografico = ?numero_mecanografico, categoria = ?categoria, " + + "ultimo_exame = ?ultimo_exame, realizado = ?realizado, proximo_exame = ?proximo_exame, " + + "ultima_consulta = ?ultima_consulta, realizada = ?realizada, " + + "proxima_consulta = ?proxima_consulta, nome = ?nome, " + + "resultado = ?resultado, data_ficha = ?data_ficha, " + + "estabelecimento_id = ?estabelecimento_id " + + "WHERE id = ?id"; + + public static final String UPDATE_ACTUALIZACAO = "UPDATE actualizacao SET stamp = "; + + + public static final String PROPERTIES_FILE = "updtprop.txt"; + public static final String PROP_LOCAL = "interno"; + public static final String PROP_LOCAL_U = "iuser"; + public static final String PROP_LOCAL_P = "ipasswd"; + public static final String PROP_REMOTE = "externo"; + public static final String PROP_REMOTE_U = "euser"; + public static final String PROP_REMOTE_P = "epasswd"; + public static final String PROP_INTERVAL = "intervalo"; + + + protected Vector deletes; + protected Vector updates; + + protected Thread updateThread; + + protected JTextField servidorInternoText; + protected JTextField servidorExternoText; + protected JTextField intervaloText; + protected JTextField ultimaActualizacaoText; + protected JTextField proximaActualizacaoText; + protected JButton actionButton; + protected JButton saveButton; + protected JButton cancelButton; + protected JLabel stateLabel; + + protected boolean running; + protected String servidorInterno; + protected String servidorExterno; + protected String internalUser; + protected String internalPassword; + protected String externalUser; + protected String externalPassword; + protected long intervalo; + + /** Creates a new instance of WebUpdater */ + public WebUpdater() + { + deletes = new Vector(); + updates = new Vector(); + running = false; + servidorInterno = "ws_fpalma"; + servidorExterno = "localhost:5436"; + intervalo = 10; + setupComponents(); + } + + protected void setupComponents() + { + setSize( 500, 200 ); + setResizable( false ); + setTitle( "Actualiza\u00e7\u00e3o do Site" ); + JLabel servidorInternoLabel = new JLabel( "Servidor Interno" ); + servidorInternoText = new JTextField(); + servidorInternoText.setPreferredSize( new Dimension( 120, 20 ) ); + servidorInternoText.setForeground( Color.red ); + JLabel servidorExternoLabel = new JLabel( "Servidor Externo" ); + servidorExternoText = new JTextField(); + servidorExternoText.setPreferredSize( new Dimension( 120, 20 ) ); + servidorExternoText.setForeground( Color.red ); + JLabel intervaloLabel = new JLabel( "Intervalo de Actualiza\u00e7\u00e3o (minutos)" ); + intervaloText = new JTextField(); + intervaloText.setPreferredSize( new Dimension( 50, 20 ) ); + JLabel ultimaActualizacaoLabel = new JLabel( "\u00daltima Actualiza\u00e7\u00e3o" ); + ultimaActualizacaoText = new JTextField(); + ultimaActualizacaoText.setPreferredSize( new Dimension( 120, 20 ) ); + ultimaActualizacaoText.setEditable( false ); + JLabel proximaActualizacaoLabel = new JLabel( "Pr\u00f3xima Actualiza\u00e7\u00e3o" ); + proximaActualizacaoText = new JTextField(); + proximaActualizacaoText.setPreferredSize( new Dimension( 120, 20 ) ); + proximaActualizacaoText.setEditable( false ); + actionButton = new JButton( "Executar" ); + saveButton = new JButton( "Guardar Altera\u00e7\u00f5es" ); + saveButton.setEnabled( false ); + cancelButton = new JButton( "Cancelar Altera\u00e7\u00f5es" ); + cancelButton.setEnabled( false ); + stateLabel = new JLabel( " " ); + JPanel buttonPanel = new JPanel(); + JPanel pad = new JPanel(); + pad.setPreferredSize( new Dimension( 120, 20 ) ); + + Container container = getContentPane(); + GridBagLayout gridbag = new GridBagLayout(); + container.setLayout( gridbag ); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets( 1, 1, 1, 1 ); +// constraints.anchor = GridBagConstraints.EAST; + constraints.fill = GridBagConstraints.BOTH; + constraints.weighty = 0; + constraints.gridheight = 1; + + constraints.weightx = 0; + constraints.gridwidth = 1; + gridbag.setConstraints( servidorInternoLabel, constraints ); + gridbag.setConstraints( servidorExternoLabel, constraints ); + gridbag.setConstraints( intervaloLabel, constraints ); + gridbag.setConstraints( ultimaActualizacaoLabel, constraints ); + gridbag.setConstraints( proximaActualizacaoLabel, constraints ); + + constraints.weightx = 1; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( servidorInternoText, constraints ); + gridbag.setConstraints( servidorExternoText, constraints ); + gridbag.setConstraints( ultimaActualizacaoText, constraints ); + gridbag.setConstraints( proximaActualizacaoText, constraints ); + gridbag.setConstraints( buttonPanel, constraints ); + gridbag.setConstraints( stateLabel, constraints ); + + constraints.weightx = 0.5; + constraints.gridwidth = 1; + gridbag.setConstraints( intervaloText, constraints ); + + constraints.weightx = 0.5; + constraints.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints( pad, constraints ); + + container.add( servidorInternoLabel ); + container.add( servidorInternoText ); + container.add( servidorExternoLabel ); + container.add( servidorExternoText ); + container.add( intervaloLabel ); + container.add( intervaloText ); + container.add( pad ); + container.add( ultimaActualizacaoLabel ); + container.add( ultimaActualizacaoText ); + container.add( proximaActualizacaoLabel ); + container.add( proximaActualizacaoText ); + container.add( buttonPanel ); + container.add( stateLabel ); + + buttonPanel.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); + buttonPanel.add( saveButton ); + buttonPanel.add( cancelButton ); + buttonPanel.add( actionButton ); + + actionButton.addActionListener( this ); + stateLabel.setText( "Parado" ); + stateLabel.setForeground( Color.red ); + +// servidorInternoText.setText( servidorInterno ); +// servidorExternoText.setText( servidorExterno ); +// intervaloText.setText( "" + intervalo ); + reload(); + + servidorInternoText.getDocument().addDocumentListener( this ); + servidorExternoText.getDocument().addDocumentListener( this ); + intervaloText.getDocument().addDocumentListener( this ); + saveButton.addActionListener( this ); + cancelButton.addActionListener( this ); + } + + public void actionPerformed(java.awt.event.ActionEvent actionEvent) + { + Object source = actionEvent.getSource(); + if( actionButton.equals( source ) ) + { + if( running ) + { + running = false; + updateThread.interrupt(); + actionButton.setText( "Executar" ); + stateLabel.setText( "Parado" ); + stateLabel.setBackground( Color.red ); + } + else + { + updateThread = new Thread( this ); + updateThread.start(); + actionButton.setText( "Parar" ); + } + } + else if( saveButton.equals( source ) ) + { + save(); + saveButton.setEnabled( false ); + cancelButton.setEnabled( false ); + } + else if( cancelButton.equals( source ) ) + { + reload(); + saveButton.setEnabled( false ); + cancelButton.setEnabled( false ); + } + } + + + public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) + { + saveButton.setEnabled( true ); + cancelButton.setEnabled( true ); + } + + public void insertUpdate(javax.swing.event.DocumentEvent documentEvent) + { + saveButton.setEnabled( true ); + cancelButton.setEnabled( true ); + } + + public void removeUpdate(javax.swing.event.DocumentEvent documentEvent) + { + saveButton.setEnabled( true ); + cancelButton.setEnabled( true ); + } + + protected void save() + { + Properties props = new Properties(); + try + { + OutputStream out = new FileOutputStream( PROPERTIES_FILE ); + String auxSI = servidorInternoText.getText(); + String auxSE = servidorExternoText.getText(); + String auxI = intervaloText.getText();; + if( auxSI == null || auxSI.length() == 0 || + auxSE == null || auxSE.length() == 0 || + auxI == null || auxI.length() == 0 ) + { + throw new Exception( "" ); + } + intervalo = Long.parseLong( auxI ); + servidorInterno = auxSI; + servidorExterno = auxSE; + props.setProperty( PROP_LOCAL, servidorInterno ); + props.setProperty( PROP_LOCAL_U, internalUser ); + props.setProperty( PROP_LOCAL_P, internalPassword ); + props.setProperty( PROP_REMOTE, servidorExterno ); + props.setProperty( PROP_REMOTE_U, externalUser ); + props.setProperty( PROP_REMOTE_P, externalPassword ); + props.setProperty( PROP_INTERVAL, "" + intervalo ); + props.store( out, "Configura\u00e7\u00e3o da Ferramenta de Actualiza\u00e7\u00e3o da SIPRP" ); + out.close(); + } + catch( Exception ex ) + { + JOptionPane.showMessageDialog( this, "Erro a gravar altera\u00e7\u00f5es", "Erro", + JOptionPane.ERROR_MESSAGE ); + } + } + + protected void reload() + { + Properties props = new Properties(); + try + { + +System.out.println( new File( PROPERTIES_FILE ) ); + InputStream in = new FileInputStream( PROPERTIES_FILE ); + props.load( in ); + internalUser = props.getProperty( PROP_LOCAL_U ); + internalPassword = props.getProperty( PROP_LOCAL_P ); + externalUser = props.getProperty( PROP_REMOTE_U ); + externalPassword = props.getProperty( PROP_REMOTE_P ); + + String aux; + aux = props.getProperty( PROP_LOCAL ); + if( aux != null && aux.length() > 0 ) + { + servidorInterno = aux; + } + aux = props.getProperty( PROP_REMOTE ); + if( aux != null && aux.length() > 0 ) + { + servidorExterno = aux; + } + aux = props.getProperty( PROP_INTERVAL ); + if( aux != null && aux.length() > 0 ) + { + try + { + intervalo = Long.parseLong( aux ); + } + catch( NumberFormatException nfe ) + { + } + } + + } + catch( Exception ex ) + { + JOptionPane.showMessageDialog( this, "Erro a carregar os dados", "Erro", + JOptionPane.ERROR_MESSAGE ); + } + servidorInternoText.setText( servidorInterno ); + servidorExternoText.setText( servidorExterno ); + intervaloText.setText( "" + intervalo ); + } + + public void run() + { + running = true; + while( true ) + { + boolean erro = false; + if( !running ) + { + return; + } + proximaActualizacaoText.setText( "" ); + try + { + stateLabel.setText( "A Actualizar" ); + stateLabel.setForeground( Color.green ); + doUpdates(); + java.util.Date date = new java.util.Date(); + ultimaActualizacaoText.setText( date.toString() ); + } + catch( Exception ex ) + { + erro = true; + stateLabel.setText( "ERRO A ACTUALIZAR!!!" ); + stateLabel.setForeground( Color.red ); + } + if( !running ) + { + return; + } + try + { + if( !erro ) + { + stateLabel.setText( "Em Intervalo (" + intervalo + " minuto" + ( intervalo > 1 ? "s" : "" ) + ")" ); + stateLabel.setForeground( Color.black ); + } + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.MINUTE, (int)intervalo ); + proximaActualizacaoText.setText( "" + cal.getTime() ); + Thread.sleep( intervalo * 60000 ); + } + catch( InterruptedException iex ) + { + } + } + } + + protected void doUpdates() + throws Exception + { + try + { + connect(); + getData(); + updateData(); + } + catch( Exception ex ) + { + ex.printStackTrace(); + throw ex; + } + + } + + /** + * @param args the command line arguments + */ + public static void main( String[] args ) + throws Exception + { + WebUpdater updater = new WebUpdater(); + updater.show(); + } + + protected void connect() + throws Exception + { + Class.forName( "org.postgresql.Driver" ); + Class.forName( "com.mysql.jdbc.Driver" ); + webConnection = DriverManager.getConnection( "jdbc:postgresql://" + servidorExterno + "/siprp", externalUser, externalPassword ); + webConnection.setAutoCommit( true ); + softwareConnection = DriverManager.getConnection( "jdbc:mysql://" + servidorInterno + "/siprp", internalUser, internalPassword ); +// softwareConnection = DriverManager.getConnection( "jdbc:postgresql://" + servidorInterno + "/siprp", internalUser, internalPassword ); + softwareConnection.setAutoCommit( true ); + } + + protected void getData() + throws Exception + { + Object r[][]; + r = doQuery( webConnection, GET_ULTIMA_ACTUALIZACAO ); + String actualizacao = "'" + r[0][0] + "'"; + Calendar cal = Calendar.getInstance(); + //int hour = cal.get( Calendar.HOUR_OF_DAY ); + //if( hour < 3 && hour > 1 ) + //{ + // actualizacao = "'1970-01-01 00:00:00'"; + //} + doQuery(softwareConnection, "DELETE FROM actualizacao;", true); + doQuery(softwareConnection, "INSERT INTO actualizacao(hora) VALUES(now());", true); + readTrabalhadores( actualizacao ); + readEstabelecimentos( actualizacao ); + readEmpresas( actualizacao ); + } + + protected void updateData() + throws Exception + { + System.out.println( "DELETES" ); + for( int d = 0; d < deletes.size(); d++ ) + { + try + { + System.out.println( deletes.elementAt( d ).toString() ); + doQuery( webConnection, deletes.elementAt( d ).toString(), true ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } + System.out.println( "" ); + System.out.println( "UPDATES" ); + for( int u = 0; u < updates.size(); u++ ) + { + String queries[] = ( String[] ) updates.elementAt( u ); + System.out.println( queries[ 0 ] + "\n " + queries[ 1 ] ); + try + { + doQuery( webConnection, queries[ 0 ], true ); + } + catch( Exception ex ) + { + System.out.println( " ERRO DE INSERT" ); + } + try + { + doQuery( webConnection, queries[ 1 ], true ); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } + Object r[][] = doQuery( softwareConnection, "SELECT hora FROM actualizacao;" ); + String actualizacao = "'" + r[0][0] + "'"; + doQuery( webConnection, UPDATE_ACTUALIZACAO + actualizacao, true ); + } + + protected void readTrabalhadores( String actualizacao ) + throws Exception + { + Object trabalhadores[][] = doQuery( softwareConnection, GET_TRABALHADORES + actualizacao ); + for( int t = 0; t < trabalhadores.length; t++ ) + { + for( int c = 0; c < trabalhadores[ t ].length; c++ ) + { + if( trabalhadores[ t ][ c ] instanceof String ) + { + trabalhadores[ t ][ c ] = unicodeToHTML( (String) trabalhadores[ t ][ c ] ); + } + } + int id = ( ( Number ) trabalhadores[t][0] ).intValue(); + boolean inactivo = "y".equals( trabalhadores[ t ][ trabalhadores[ t ].length - 1 ] ) || + trabalhadores[ t ][ trabalhadores[ t ].length - 2 ] != null; + if( inactivo ) + { + deletes.add( DELETE_TRABALHADOR + id ); + continue; + } + String queries[] = new String[ 2 ]; + updates.insertElementAt( queries, 0 ); + queries[ 0 ] = CREATE_TRABALHADOR.replaceFirst( "[?]id", "" + id ); + String update = UPDATE_TRABALHADOR.replaceFirst( "[?]id", "" + id ); + + String nome = "'" + trabalhadores[ t ][ 1 ] + "'"; + update = update.replaceFirst( "[?]nome", nome ); + String sexo = "'" + trabalhadores[ t ][ 2 ] + "'"; + update = update.replaceFirst( "[?]sexo", sexo ); + String dataNasc; + if( trabalhadores[ t ][ 3 ] != null ) + { + dataNasc = "'" + trabalhadores[ t ][ 3 ] + "'"; + } + else + { + dataNasc = "''"; + } + update = update.replaceFirst( "[?]data_nascimento", dataNasc ); + String numeroMecanografico; + if( trabalhadores[ t ][ 4 ] != null ) + { + numeroMecanografico = "'" + trabalhadores[ t ][ 4 ] + "'"; + } + else + { + numeroMecanografico = "''"; + } + update = update.replaceFirst( "[?]numero_mecanografico", numeroMecanografico ); + String categoria; + if( trabalhadores[ t ][ 5 ] != null ) + { + categoria = "'" + trabalhadores[ t ][ 5 ] + "'"; + } + else + { + categoria = "''"; + } + update = update.replaceFirst( "[?]categoria", categoria ); + int estabelecimentoID = ( ( Number ) trabalhadores[t][6] ).intValue(); + update = update.replaceFirst( "[?]estabelecimento_id", "" + estabelecimentoID ); + Object exames[][] = doQuery( softwareConnection, + GET_EXAMES_TRABALHADOR.replaceFirst( "[?]trabalhador_id", ""+id ) ); + + if( exames != null && exames.length > 0 ) + { + java.util.Date dataExame2 = ( java.util.Date ) exames[ exames.length - 1 ] [ 1 ]; + String realizado2 = ( String ) exames[ exames.length - 1 ][ 2 ]; + java.util.Date dataExame1; + String realizado1; + if( exames.length >= 2 ) + { + dataExame1 = ( java.util.Date ) exames[ exames.length - 2 ] [ 1 ]; + realizado1 = ( String ) exames[ exames.length - 2 ][ 2 ]; + } + else + { + dataExame1 = dataExame2; + realizado1 = realizado2; + } + if( "y".equals( realizado2 ) ) + { + update = update.replaceFirst( "[?]ultimo_exame", "'" + dataExame2 + "'" ); + update = update.replaceFirst( "[?]realizado", "'" + realizado2 + "'" ); + update = update.replaceFirst( "[?]proximo_exame", "null" ); + } + else if( new java.util.Date().after( dataExame2 ) ) + { + update = update.replaceFirst( "[?]ultimo_exame", "'" + dataExame2 + "'" ); + update = update.replaceFirst( "[?]realizado", "'" + realizado2 + "'" ); + update = update.replaceFirst( "[?]proximo_exame", "null" ); + } + else + { + update = update.replaceFirst( "[?]proximo_exame", "'" + dataExame2 + "'" ); + if( !dataExame2.equals( dataExame1 ) ) + { + update = update.replaceFirst( "[?]ultimo_exame", "'" + dataExame1 + "'" ); + update = update.replaceFirst( "[?]realizado", "'" + realizado1 + "'" ); + } + else + { + update = update.replaceFirst( "[?]ultimo_exame", "null" ); + update = update.replaceFirst( "[?]realizado", "null" ); + } + } + } + else + { + update = update.replaceFirst( "[?]ultimo_exame", "null" ); + update = update.replaceFirst( "[?]realizado", "null" ); + update = update.replaceFirst( "[?]proximo_exame", "null" ); + } + Object consultas[][] = doQuery( softwareConnection, + GET_CONSULTAS_TRABALHADOR.replaceFirst( "[?]trabalhador_id", ""+id ) ); + + if( consultas != null && consultas.length > 0 ) + { + java.util.Date dataConsulta2 = ( java.util.Date ) consultas[ consultas.length - 1 ] [ 1 ]; + String realizada2 = ( String ) consultas[ consultas.length - 1 ][ 2 ]; + java.util.Date dataConsulta1; + java.util.Date dataRelatorio1; + java.util.Date dataRelatorio2 = (java.util.Date) consultas[ consultas.length - 1 ][ 3 ]; + String realizada1; + if( consultas.length >= 2 ) + { + dataConsulta1 = ( java.util.Date ) consultas[ consultas.length - 2 ] [ 1 ]; + realizada1 = ( String ) consultas[ consultas.length - 2 ][ 2 ]; + dataRelatorio1 = (java.util.Date) consultas[ consultas.length - 2 ][ 3 ]; + } + else + { + dataConsulta1 = dataConsulta2; + realizada1 = realizada2; + dataRelatorio1 = dataRelatorio2; + } + if( "y".equals( realizada2 ) ) + { + update = update.replaceFirst( "[?]ultima_consulta", "'" + dataConsulta2 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada2 + "'" ); + update = update.replaceFirst( "[?]proxima_consulta", "null" ); + if( dataRelatorio2 != null ) + { + update = update.replaceFirst( "[?]data_ficha", "'" + dataRelatorio2 + "'" ); + } + else + { + update = update.replaceFirst( "[?]data_ficha", "null" ); + } + } + else if( new java.util.Date().after( dataConsulta2 ) ) + { + update = update.replaceFirst( "[?]ultima_consulta", "'" + dataConsulta2 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada2 + "'" ); + update = update.replaceFirst( "[?]proxima_consulta", "null" ); + if( dataRelatorio2 != null ) + { + update = update.replaceFirst( "[?]data_ficha", "'" + dataRelatorio2 + "'" ); + } + else + { + update = update.replaceFirst( "[?]data_ficha", "null" ); + } + } + else + { + update = update.replaceFirst( "[?]proxima_consulta", "'" + dataConsulta2 + "'" ); + if( !dataConsulta2.equals( dataConsulta1 ) ) + { + update = update.replaceFirst( "[?]ultima_consulta", "'" + dataConsulta1 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada1 + "'" ); + if( dataRelatorio1 != null ) + { + update = update.replaceFirst( "[?]data_ficha", "'" + dataRelatorio1 + "'" ); + } + else + { + update = update.replaceFirst( "[?]data_ficha", "null" ); + } + } + else + { + update = update.replaceFirst( "[?]ultima_consulta", "null" ); + update = update.replaceFirst( "[?]realizada", "null" ); + update = update.replaceFirst( "[?]data_ficha", "null" ); + } + } + } + else + { + update = update.replaceFirst( "[?]ultima_consulta", "null" ); + update = update.replaceFirst( "[?]realizada", "null" ); + update = update.replaceFirst( "[?]proxima_consulta", "null" ); + update = update.replaceFirst( "[?]data_ficha", "null" ); + + } + Object fichas[][] = doQuery( softwareConnection, + GET_ID_FICHA_APTIDAO.replaceFirst( "[?]trabalhador_id", ""+id ) ); + if( fichas != null && fichas.length > 0 && fichas[0].length > 0 && fichas[0][0] != null ) + { + Integer idFicha = (Integer)fichas[0][0]; + fichas = doQuery( softwareConnection, + GET_DADOS_FICHA_APTIDAO.replaceFirst( "[?]id", "" + idFicha ) ); + java.util.Date dataFicha = ( java.util.Date ) fichas[ 0 ][ 0 ]; + /*if( dataFicha != null ) + { + update = update.replaceFirst( "[?]data_ficha", "null" ); + } + else + { + update = update.replaceFirst( "[?]data_ficha", "'" + dataFicha + "'" ); + }*/ + Integer resultadoFicha = (Integer) fichas[ 0 ][ 1 ]; + if( resultadoFicha != null ) + { + switch( resultadoFicha.intValue() ) + { + case 1: + update = update.replaceFirst( "[?]resultado", "'Apto'" ); + break; + case 2: + update = update.replaceFirst( "[?]resultado", "'Apto Condicionalmente'" ); + break; + case 3: + update = update.replaceFirst( "[?]resultado", "'Inapto Temporariamente'" ); + break; + case 4: + update = update.replaceFirst( "[?]resultado", "'Inapto Definitivamente'" ); + break; + default: + update = update.replaceFirst( "[?]resultado", "null" ); + } + } + else + { + update = update.replaceFirst( "[?]resultado", "null" ); + } + } + else + { + update = update.replaceFirst( "[?]data_ficha", "null" ); + update = update.replaceFirst( "[?]resultado", "null" ); + } + + queries[ 1 ] = update; + + } + } + + protected void readEstabelecimentos( String actualizacao ) + throws Exception + { + Object estabelecimentos[][] = doQuery( softwareConnection, GET_ESTABELECIMENTOS + actualizacao ); + //id, empresa_id, nome, contacto, inactivo + for( int t = 0; t < estabelecimentos.length; t++ ) + { + for( int c = 0; c < estabelecimentos[ t ].length; c++ ) + { + if( estabelecimentos[ t ][ c ] instanceof String ) + { + estabelecimentos[ t ][ c ] = unicodeToHTML( (String) estabelecimentos[ t ][ c ] ); + } + } + int id = ( ( Number ) estabelecimentos[t][0] ).intValue(); + boolean inactivo = "y".equals( estabelecimentos[ t ][ estabelecimentos[ t ].length - 1 ] ); + if( inactivo ) + { + deletes.add( DELETE_TRABALHADORES_BY_ESTABELECIMENTO + id ); + deletes.add( DELETE_ESTABELECIMENTO + id ); + continue; + } + String queries[] = new String[ 2 ]; + updates.insertElementAt( queries, 0 ); + queries[ 0 ] = CREATE_ESTABELECIMENTO.replaceFirst( "[?]id", "" + id ); + String update = UPDATE_ESTABELECIMENTO.replaceFirst( "[?]id", "" + id ); + + int empresaID = ( ( Number ) estabelecimentos[t][1] ).intValue(); + update = update.replaceFirst( "[?]empresa_id", "" + empresaID ); + String nome = "'" + estabelecimentos[ t ][ 2 ] + "'"; + update = update.replaceFirst( "[?]nome", nome ); + String morada; + if( estabelecimentos[ t ][ 4 ] != null ) + { + morada = "'" + estabelecimentos[ t ][ 4 ] + "'"; + } + else + { + morada = "''"; + } + update = update.replaceFirst( "[?]morada", morada ); + String localidade; + if( estabelecimentos[ t ][ 5 ] != null ) + { + localidade = "'" + estabelecimentos[ t ][ 5 ] + "'"; + } + else + { + localidade = "''"; + } + update = update.replaceFirst( "[?]localidade", localidade ); + String codigoPostal; + if( estabelecimentos[ t ][ 6 ] != null ) + { + codigoPostal = "'" + estabelecimentos[ t ][ 6 ] + "'"; + } + else + { + codigoPostal = "''"; + } + update = update.replaceFirst( "[?]codigo_postal", codigoPostal ); + + Object marcacoes[][] = doQuery( softwareConnection, + GET_MARCACOES_ESTABELECIMENTO +id ); + + if( marcacoes != null && marcacoes.length > 0 ) + { + java.util.Date dataConsulta2 = ( java.util.Date ) marcacoes[ marcacoes.length - 1 ] [ 1 ]; + String realizada2 = ( String ) marcacoes[ marcacoes.length - 1 ][ 2 ]; + java.util.Date dataConsulta1; + String realizada1; + if( marcacoes.length >= 2 ) + { + dataConsulta1 = ( java.util.Date ) marcacoes[ marcacoes.length - 2 ] [ 1 ]; + realizada1 = ( String ) marcacoes[ marcacoes.length - 2 ][ 2 ]; + } + else + { + dataConsulta1 = dataConsulta2; + realizada1 = realizada2; + } + if( "y".equals( realizada2 ) ) + { + update = update.replaceFirst( "[?]ultima_visita", "'" + dataConsulta2 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada2 + "'" ); + update = update.replaceFirst( "[?]proxima_visita", "null" ); + } + else if( new java.util.Date().after( dataConsulta2 ) ) + { + update = update.replaceFirst( "[?]ultima_visita", "'" + dataConsulta2 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada2 + "'" ); + update = update.replaceFirst( "[?]proxima_visita", "null" ); + } + else + { + update = update.replaceFirst( "[?]proxima_visita", "'" + dataConsulta2 + "'" ); + if( !dataConsulta2.equals( dataConsulta1 ) ) + { + update = update.replaceFirst( "[?]ultima_visita", "'" + dataConsulta1 + "'" ); + update = update.replaceFirst( "[?]realizada", "'" + realizada2 + "'" ); + } + else + { + update = update.replaceFirst( "[?]ultima_visita", "null" ); + update = update.replaceFirst( "[?]realizada", "null" ); + } + } + } + else + { + update = update.replaceFirst( "[?]ultima_visita", "null" ); + update = update.replaceFirst( "[?]realizada", "null" ); + update = update.replaceFirst( "[?]proxima_visita", "null" ); + } + + queries[ 1 ] = update; + } + } + + protected void readEmpresas( String actualizacao ) + throws Exception + { + Object empresas[][] = doQuery( softwareConnection, GET_EMPRESAS + actualizacao ); + //id, empresa_id, nome, contacto, inactivo + for( int t = 0; t < empresas.length; t++ ) + { + for( int c = 0; c < empresas[ t ].length; c++ ) + { + if( empresas[ t ][ c ] instanceof String ) + { + empresas[ t ][ c ] = unicodeToHTML( (String) empresas[ t ][ c ] ); + } + } + int id = ( ( Number ) empresas[t][0] ).intValue(); + boolean inactivo = "y".equals( empresas[ t ][ 17 ] ); + if( inactivo ) + { + String str = DELETE_TRABALHADORES_BY_EMPRESA.replaceFirst( "[?]empresa_id", "" + id ); + deletes.add( str ); + deletes.add( DELETE_ESTABELECIMENTOS_BY_EMPRESA + id ); + deletes.add( DELETE_EMPRESA + id ); + continue; + } + String queries[] = new String[ 2 ]; + updates.insertElementAt( queries, 0 ); + queries[ 0 ] = CREATE_EMPRESA.replaceFirst( "[?]id", "" + id ); + String update = UPDATE_EMPRESA.replaceFirst( "[?]id", "" + id ); + + String designacaoSocial = "'" + empresas[ t ][ 1 ] + "'"; + update = update.replaceFirst( "[?]designacao_social", designacaoSocial ); + String cae; + if( empresas[ t ][ 7 ] != null ) + { + cae = "'" + empresas[ t ][ 7 ] + "'"; + } + else + { + cae = "''"; + } + update = update.replaceFirst( "[?]cae", cae ); + String contribuinte; + if( empresas[ t ][ 8 ] != null ) + { + contribuinte = "'" + empresas[ t ][ 8 ] + "'"; + } + else + { + contribuinte = "''"; + } + update = update.replaceFirst( "[?]contribuinte", contribuinte ); + String segurancaSocial; + if( empresas[ t ][ 9 ] != null ) + { + segurancaSocial = "'" + empresas[ t ][ 9 ] + "'"; + } + else + { + segurancaSocial = "''"; + } + update = update.replaceFirst( "[?]seguranca_social", segurancaSocial ); + String actividade; + if( empresas[ t ][ 10 ] != null ) + { + actividade = "'" + empresas[ t ][ 10 ] + "'"; + } + else + { + actividade = "''"; + } + update = update.replaceFirst( "[?]actividade", actividade ); + String morada; + if( empresas[ t ][ 12 ] != null ) + { + morada = "'" + empresas[ t ][ 12 ] + "'"; + } + else + { + morada = "''"; + } + update = update.replaceFirst( "[?]morada", morada ); + String localidade; + if( empresas[ t ][ 13 ] != null ) + { + localidade = "'" + empresas[ t ][ 13 ] + "'"; + } + else + { + localidade = "''"; + } + update = update.replaceFirst( "[?]localidade", localidade ); + String codigoPostal; + if( empresas[ t ][ 14 ] != null ) + { + codigoPostal = "'" + empresas[ t ][ 14 ] + "'"; + } + else + { + codigoPostal = "''"; + } + update = update.replaceFirst( "[?]codigo_postal", codigoPostal ); + String distrito; + if( empresas[ t ][ 15 ] != null ) + { + distrito = "'" + empresas[ t ][ 15 ] + "'"; + } + else + { + distrito = "''"; + } + update = update.replaceFirst( "[?]distrito", distrito ); + String concelho; + if( empresas[ t ][ 16 ] != null ) + { + concelho = "'" + empresas[ t ][ 16 ] + "'"; + } + else + { + concelho = "''"; + } + update = update.replaceFirst( "[?]concelho", concelho ); + String email = null; + if( empresas[ t ][ 18 ] != null ) + { + try + { + Object em[][] = doQuery( softwareConnection, GET_EMAIL + empresas[ t ][ 18 ] ); + if( em != null && em.length > 0 && em[ 0 ][ 0 ] != null ) + { + email = "'" + (String)em[ 0 ][ 0 ] + "'"; + } + } + catch( Exception ex ) + { + } + } + if( email == null ) + { + email = "''"; + } + update = update.replaceFirst( "[?]email", email ); + + String codigo1 = (String) empresas[ t ][ 4 ]; + String codigo2 = (String) empresas[ t ][ 5 ]; + String codigo3 = (String) empresas[ t ][ 6 ]; + String codigo = "'" + ( codigo1 != null ? codigo1 : "_" ) + "/" + + ( codigo2 != null ? codigo2 : "_" ) + "/" + + ( codigo3 != null ? codigo3 : "_" ) + "'"; + update = update.replaceFirst( "[?]codigo", codigo ); + update = update.replaceFirst( "[?]perfil_1", "null" ); + update = update.replaceFirst( "[?]perfil_2", "null" ); + update = update.replaceFirst( "[?]perfil_3", "null" ); + update = update.replaceFirst( "[?]servicos", "null" ); + + queries[ 1 ] = update; + } + } + + protected Object [][]doQuery( Connection con, String query ) + throws Exception + { + return doQuery( con, query, false ); + } + + protected Object [][]doQuery( Connection con, String query, boolean isUpdate ) + throws Exception + { +// if( con == webConnection ) +// { +// System.out.println( "WEB" ); +// } +// else +// { +// System.out.println( "LOCAL" ); +// } +// if( query.indexOf( "INSERT" ) != -1 || query.indexOf( "UPDATE" ) != -1 ) +// { +//// System.out.println( "AAAAAAAAAAAAAHHHHHHH" + query ); +// return new Object[0][0]; +// } + Statement stm = null; + stm = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_READ_ONLY ); + if( isUpdate ) + { + stm.executeUpdate( query ); + return null; + } + ResultSet rs = stm.executeQuery( query ); + + if( rs == null ) + { + return null; + } + ResultSetMetaData rsmd = rs.getMetaData(); + int columns = rsmd.getColumnCount(); + rs.last(); + int rows = rs.getRow(); + Object data[][] = new Object[ rows ][ columns ]; + for( int i = 0; i < rows; ++i ) + { + rs.absolute( i + 1 ); + for( int j = 0; j < columns; j++ ) + { + data[ i ][ j ] = rs.getObject( j + 1 ); + } + } + return data; + } + + protected static String unicodeToHTML( String text ) + { + if( text == null || text.length() == 0 ) + { + return ""; + } + + String output = text; + + output = output.replaceAll( "\\\\u0009", " " ); + output = output.replaceAll( "\\\\u000a", "
" ); + + output = output.replaceAll( "\\\\u00a0", " " ); + + output = output.replaceAll( "\\\\u00c0", "À" ); + output = output.replaceAll( "\\\\u00c1", "Á" ); + output = output.replaceAll( "\\\\u00c2", "Â" ); + output = output.replaceAll( "\\\\u00c3", "Ã" ); + output = output.replaceAll( "\\\\u00c7", "Ç" ); + output = output.replaceAll( "\\\\u00c8", "È" ); + output = output.replaceAll( "\\\\u00c9", "É" ); + output = output.replaceAll( "\\\\u00ca", "Ê" ); + output = output.replaceAll( "\\\\u00cc", "Ì" ); + output = output.replaceAll( "\\\\u00cd", "Í" ); + output = output.replaceAll( "\\\\u00ce", "Î" ); + output = output.replaceAll( "\\\\u00d2", "Ò" ); + output = output.replaceAll( "\\\\u00d3", "Ó" ); + output = output.replaceAll( "\\\\u00d4", "Ô" ); + output = output.replaceAll( "\\\\u00d5", "Õ" ); + output = output.replaceAll( "\\\\u00d9", "Ù" ); + output = output.replaceAll( "\\\\u00da", "Ú" ); + output = output.replaceAll( "\\\\u00db", "Û" ); + + output = output.replaceAll( "\\\\u00e0", "à" ); + output = output.replaceAll( "\\\\u00e1", "á" ); + output = output.replaceAll( "\\\\u00e2", "â" ); + output = output.replaceAll( "\\\\u00e3", "ã" ); + output = output.replaceAll( "\\\\u00e7", "ç" ); + output = output.replaceAll( "\\\\u00e8", "è" ); + output = output.replaceAll( "\\\\u00e9", "é" ); + output = output.replaceAll( "\\\\u00ea", "ê" ); + output = output.replaceAll( "\\\\u00ec", "ì" ); + output = output.replaceAll( "\\\\u00ed", "í" ); + output = output.replaceAll( "\\\\u00ee", "î" ); + output = output.replaceAll( "\\\\u00f2", "ò" ); + output = output.replaceAll( "\\\\u00f3", "ó" ); + output = output.replaceAll( "\\\\u00f4", "ô" ); + output = output.replaceAll( "\\\\u00f5", "õ" ); + output = output.replaceAll( "\\\\u00f9", "ù" ); + output = output.replaceAll( "\\\\u00fa", "ú" ); + output = output.replaceAll( "\\\\u00fb", "û" ); + output = output.replaceAll( "\\\\u00aa", "ª" ); + output = output.replaceAll( "\\\\u00ba", "º" ); + + output = output.replaceAll( "\\\\u0153", "œ" ); + + output = output.replaceAll( "\\\\u2013", "-" ); + output = output.replaceAll( "\\\\u2014", "-" ); + output = output.replaceAll( "\\\\u2018|\\\\u2019", "'" ); + output = output.replaceAll( "\\\\u201c|\\\\u201d", "\"" ); + + output = output.replaceAll( "\\\\u2022", "*" ); + output = output.replaceAll( "\\\\u2026", "..." ); + + return output; + } + + +} diff --git a/trunk/siprp_create.sql b/trunk/siprp_create.sql new file mode 100644 index 00000000..56b89f27 --- /dev/null +++ b/trunk/siprp_create.sql @@ -0,0 +1,569 @@ +-- +-- PostgreSQL database dump +-- + +SET client_encoding = 'LATIN1'; +SET check_function_bodies = false; +SET client_min_messages = warning; + + +-- +-- Name: actualizacao; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE actualizacao ( + hora timestamp without time zone, + id serial NOT NULL +); + + +ALTER TABLE public.actualizacao OWNER TO postgres; + +-- +-- Name: avisos; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE avisos ( + id integer NOT NULL, + tipo integer DEFAULT 0 NOT NULL, + empresa_id integer, + estabelecimento_id integer, + trabalhador_id integer, + evento_id integer, + data_aviso date NOT NULL, + data_evento date, + descricao character varying(255) +); + + +ALTER TABLE public.avisos OWNER TO postgres; + +-- +-- Name: contactos; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE contactos ( + id integer NOT NULL, + nome character varying(255), + telefone character varying(255), + telemovel character varying(255), + fax character varying(255), + email character varying(255), + cargo character varying(255) +); + + +ALTER TABLE public.contactos OWNER TO postgres; + +-- +-- Name: empresas; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE empresas ( + id integer NOT NULL, + designacao_social character varying(255) DEFAULT ''::character varying NOT NULL, + servico_saude_tipo integer, + servico_saude_designacao character varying(255) DEFAULT 'Sociedade Ibu00e9rica de Prevenu00e7u00e3o de Riscos Profissionais'::character varying, + servico_higiene_tipo integer, + servico_higiene_designacao character varying(255), + inactivo character(1) DEFAULT 'n'::bpchar NOT NULL, + morada character varying(255), + codigo_postal character varying(8), + localidade character varying(255), + distrito character varying(255), + concelho character varying(255), + numero_trabalhadores integer, + data_proposta date, + data_aceitacao date, + perfil_1 character varying(255), + perfil_2 character varying(255), + data_envio_contrato date, + data_recepcao_contrato date, + data_envio_idict date, + cae character varying(255), + contribuinte character varying(255), + seguranca_social character varying(255), + codigo_1 character varying(255), + codigo_2 character varying(255), + codigo_3 character varying(255), + servicos integer, + contacto_1 integer, + contacto_2 integer, + data_relatorio_anual date, + preco_higiene double precision, + preco_medicina double precision, + periodicidade character varying(255), + actividade character varying(255), + actualizacao timestamp without time zone, + designacao_social_plain character varying(255) +); + + +ALTER TABLE public.empresas OWNER TO postgres; + +-- +-- Name: errors; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE errors ( + id integer NOT NULL, + date timestamp without time zone, + "type" character varying(20), + environment character varying(255), + description character varying(65535) +); + + +ALTER TABLE public.errors OWNER TO postgres; + +-- +-- Name: estabelecimentos; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE estabelecimentos ( + id integer NOT NULL, + nome character varying(255) DEFAULT ''::character varying NOT NULL, + localidade character varying(255), + inactivo character(1) DEFAULT 'n'::bpchar NOT NULL, + empresa_id integer DEFAULT 0 NOT NULL, + morada character varying(255), + codigo_postal character varying(255), + contacto character varying(255), + historico character varying(65535), + actualizacao timestamp without time zone, + nome_plain character varying(255) +); + + +ALTER TABLE public.estabelecimentos OWNER TO postgres; + +-- +-- Name: exames; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE exames ( + id integer NOT NULL, + data date, + tipo integer DEFAULT 0 NOT NULL, + ocasional integer, + outro_tipo character varying(255), + resultado integer, + outra_funcao_1 character varying(255), + outra_funcao_2 character varying(255), + outra_funcao_3 character varying(255), + outra_funcao_4 character varying(255), + proximo_exame date, + outras_recomendacoes character varying(65535), + inactivo character(1) DEFAULT 'n'::bpchar NOT NULL, + trabalhador_id integer DEFAULT 0 NOT NULL, + medico_id integer DEFAULT 0 NOT NULL, + pdf bytea +); + + +ALTER TABLE public.exames OWNER TO postgres; + +-- +-- Name: exames_perfis; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE exames_perfis ( + id integer NOT NULL, + perfil integer DEFAULT 0 NOT NULL, + tipo integer DEFAULT 0 NOT NULL, + multiplicador integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.exames_perfis OWNER TO postgres; + +-- +-- Name: historico_estabelecimento; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE historico_estabelecimento ( + id integer NOT NULL, + estabelecimento_id integer DEFAULT 0 NOT NULL, + data date, + texto character varying(65535) +); + + +ALTER TABLE public.historico_estabelecimento OWNER TO postgres; + +-- +-- Name: ids; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE ids ( + id integer NOT NULL +); + + +ALTER TABLE public.ids OWNER TO postgres; + +-- +-- Name: marcacoes_empresa; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE marcacoes_empresa ( + id integer NOT NULL, + data date NOT NULL, + texto character varying(65535), + empresa_id integer DEFAULT 0 NOT NULL, + realizada character(1) +); + + +ALTER TABLE public.marcacoes_empresa OWNER TO postgres; + +-- +-- Name: marcacoes_estabelecimento; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE marcacoes_estabelecimento ( + id integer NOT NULL, + data date NOT NULL, + realizada character(1) DEFAULT 'n'::bpchar NOT NULL, + data_email date, + data_relatorio date, + estabelecimento_id integer DEFAULT 0 NOT NULL +); + + +ALTER TABLE public.marcacoes_estabelecimento OWNER TO postgres; + +-- +-- Name: marcacoes_trabalhador; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE marcacoes_trabalhador ( + id integer NOT NULL, + data date, + realizada character(1) DEFAULT 'n'::bpchar NOT NULL, + data_email date, + data_relatorio date, + tipo integer, + trabalhador_id integer +); + + +ALTER TABLE public.marcacoes_trabalhador OWNER TO postgres; + +-- +-- Name: medicos; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE medicos ( + id integer NOT NULL, + nome character varying(255) DEFAULT ''::character varying NOT NULL, + numero_cedula character varying(255) DEFAULT ''::character varying NOT NULL, + inactivo character(1) DEFAULT 'n'::bpchar NOT NULL +); + + +ALTER TABLE public.medicos OWNER TO postgres; + +-- +-- Name: tipos_exames_comp; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tipos_exames_comp ( + id integer NOT NULL, + ordem integer DEFAULT 0 NOT NULL, + descricao character varying(255) DEFAULT ''::character varying NOT NULL +); + + +ALTER TABLE public.tipos_exames_comp OWNER TO postgres; + +-- +-- Name: trabalhadores; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE trabalhadores ( + id integer NOT NULL, + nome character varying(255) DEFAULT ''::character varying NOT NULL, + sexo character(1), + data_nascimento date, + nacionalidade character varying(255), + numero_mecanografico character varying(255), + data_admissao date, + categoria character varying(255), + local_trabalho character varying(255), + funcao_proposta character varying(255), + data_admissao_funcao date, + observacoes character varying(65535), + inactivo character(1) DEFAULT 'n'::bpchar NOT NULL, + estabelecimento_id integer DEFAULT 0 NOT NULL, + data_demissao date, + observacoes_gestao character varying(65535), + perfil integer, + actualizacao timestamp without time zone, + nome_plain character varying(255) +); + + +ALTER TABLE public.trabalhadores OWNER TO postgres; + +-- +-- Name: actualizacao_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY actualizacao + ADD CONSTRAINT actualizacao_pkey PRIMARY KEY (id); + + +ALTER INDEX public.actualizacao_pkey OWNER TO postgres; + +-- +-- Name: avisos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY avisos + ADD CONSTRAINT avisos_pkey PRIMARY KEY (id); + + +ALTER INDEX public.avisos_pkey OWNER TO postgres; + +-- +-- Name: contactos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY contactos + ADD CONSTRAINT contactos_pkey PRIMARY KEY (id); + + +ALTER INDEX public.contactos_pkey OWNER TO postgres; + +-- +-- Name: empresas_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY empresas + ADD CONSTRAINT empresas_pkey PRIMARY KEY (id); + + +ALTER INDEX public.empresas_pkey OWNER TO postgres; + +-- +-- Name: errors_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY errors + ADD CONSTRAINT errors_pkey PRIMARY KEY (id); + + +ALTER INDEX public.errors_pkey OWNER TO postgres; + +-- +-- Name: estabelecimentos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY estabelecimentos + ADD CONSTRAINT estabelecimentos_pkey PRIMARY KEY (id); + + +ALTER INDEX public.estabelecimentos_pkey OWNER TO postgres; + +-- +-- Name: exames_perfis_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY exames_perfis + ADD CONSTRAINT exames_perfis_pkey PRIMARY KEY (id); + + +ALTER INDEX public.exames_perfis_pkey OWNER TO postgres; + +-- +-- Name: exames_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY exames + ADD CONSTRAINT exames_pkey PRIMARY KEY (id); + + +ALTER INDEX public.exames_pkey OWNER TO postgres; + +-- +-- Name: historico_estabelecimento_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY historico_estabelecimento + ADD CONSTRAINT historico_estabelecimento_pkey PRIMARY KEY (id); + + +ALTER INDEX public.historico_estabelecimento_pkey OWNER TO postgres; + +-- +-- Name: ids_pk; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY ids + ADD CONSTRAINT ids_pk PRIMARY KEY (id); + + +ALTER INDEX public.ids_pk OWNER TO postgres; + +-- +-- Name: marcacoes_empresa_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY marcacoes_empresa + ADD CONSTRAINT marcacoes_empresa_pkey PRIMARY KEY (id); + + +ALTER INDEX public.marcacoes_empresa_pkey OWNER TO postgres; + +-- +-- Name: marcacoes_estabelecimento_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY marcacoes_estabelecimento + ADD CONSTRAINT marcacoes_estabelecimento_pkey PRIMARY KEY (id); + + +ALTER INDEX public.marcacoes_estabelecimento_pkey OWNER TO postgres; + +-- +-- Name: marcacoes_trabalhador_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY marcacoes_trabalhador + ADD CONSTRAINT marcacoes_trabalhador_pkey PRIMARY KEY (id); + + +ALTER INDEX public.marcacoes_trabalhador_pkey OWNER TO postgres; + +-- +-- Name: medicos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY medicos + ADD CONSTRAINT medicos_pkey PRIMARY KEY (id); + + +ALTER INDEX public.medicos_pkey OWNER TO postgres; + +-- +-- Name: tipos_exames_comp_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tipos_exames_comp + ADD CONSTRAINT tipos_exames_comp_pkey PRIMARY KEY (id); + + +ALTER INDEX public.tipos_exames_comp_pkey OWNER TO postgres; + +-- +-- Name: trabalhadores_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY trabalhadores + ADD CONSTRAINT trabalhadores_pkey PRIMARY KEY (id); + + +ALTER INDEX public.trabalhadores_pkey OWNER TO postgres; + + +-- +-- Name: avisos_empresa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY avisos + ADD CONSTRAINT avisos_empresa_id_fkey FOREIGN KEY (empresa_id) REFERENCES empresas(id); + + +-- +-- Name: avisos_estabelecimento_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY avisos + ADD CONSTRAINT avisos_estabelecimento_id_fkey FOREIGN KEY (estabelecimento_id) REFERENCES estabelecimentos(id); + + +-- +-- Name: empresas_contacto_1_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY empresas + ADD CONSTRAINT empresas_contacto_1_fkey FOREIGN KEY (contacto_1) REFERENCES contactos(id); + + +-- +-- Name: empresas_contacto_2_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY empresas + ADD CONSTRAINT empresas_contacto_2_fkey FOREIGN KEY (contacto_2) REFERENCES contactos(id); + + +-- +-- Name: estabelecimentos_empresa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY estabelecimentos + ADD CONSTRAINT estabelecimentos_empresa_id_fkey FOREIGN KEY (empresa_id) REFERENCES empresas(id); + + +-- +-- Name: exames_medico_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY exames + ADD CONSTRAINT exames_medico_id_fkey FOREIGN KEY (medico_id) REFERENCES medicos(id); + + +-- +-- Name: exames_perfis_tipo_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY exames_perfis + ADD CONSTRAINT exames_perfis_tipo_fkey FOREIGN KEY (tipo) REFERENCES tipos_exames_comp(id); + + +-- +-- Name: historico_estabelecimento_estabelecimento_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY historico_estabelecimento + ADD CONSTRAINT historico_estabelecimento_estabelecimento_id_fkey FOREIGN KEY (estabelecimento_id) REFERENCES estabelecimentos(id); + + +-- +-- Name: marcacoes_empresa_empresa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY marcacoes_empresa + ADD CONSTRAINT marcacoes_empresa_empresa_id_fkey FOREIGN KEY (empresa_id) REFERENCES empresas(id); + + +-- +-- Name: marcacoes_estabelecimento_estabelecimento_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY marcacoes_estabelecimento + ADD CONSTRAINT marcacoes_estabelecimento_estabelecimento_id_fkey FOREIGN KEY (estabelecimento_id) REFERENCES estabelecimentos(id); + + +-- +-- Name: trabalhadores_estabelecimento_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY trabalhadores + ADD CONSTRAINT trabalhadores_estabelecimento_id_fkey FOREIGN KEY (estabelecimento_id) REFERENCES estabelecimentos(id); + + + +-- +-- Name: public; Type: ACL; Schema: -; Owner: postgres +-- + +REVOKE ALL ON SCHEMA public FROM PUBLIC; +REVOKE ALL ON SCHEMA public FROM postgres; +GRANT ALL ON SCHEMA public TO postgres; +GRANT ALL ON SCHEMA public TO PUBLIC; + + + diff --git a/trunk/updtprop.txt b/trunk/updtprop.txt new file mode 100644 index 00000000..6153dbeb --- /dev/null +++ b/trunk/updtprop.txt @@ -0,0 +1,7 @@ +interno=localhost:5432 +iuser=postgres +ipasswd=Typein +externo=www.evolute.pt:5436 +euser=siprp +epasswd=rg2h-opksiprp +intervalo=10