From e27f01cb7e40c3f503bea422fb1b868926ad3e5d Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Thu, 27 Jan 2005 18:20:00 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@158 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/ficha/EmpresaPanel.java | 232 ++++++++++++++++-------- trunk/siprp/ficha/FichaWindow.java | 145 ++++++++------- trunk/siprp/ficha/TrabalhadorPanel.java | 148 ++++++++++----- trunk/siprp/ficha/UpperPanel.java | 21 ++- 4 files changed, 346 insertions(+), 200 deletions(-) diff --git a/trunk/siprp/ficha/EmpresaPanel.java b/trunk/siprp/ficha/EmpresaPanel.java index 1f38e9c4..e183ecd4 100644 --- a/trunk/siprp/ficha/EmpresaPanel.java +++ b/trunk/siprp/ficha/EmpresaPanel.java @@ -20,6 +20,7 @@ import com.evolute.utils.ui.button.*; import com.evolute.utils.ui.panel.*; import siprp.*; +import siprp.data.*; /** * @@ -39,10 +40,11 @@ public class EmpresaPanel extends JPanel private JButton defaultServicoHigieneButton; private FichaDataProvider provider; - private ComponentsHashtable components; + private ComponentsHashtable empresaComponents; + private ComponentsHashtable estabelecimentoComponents; - private MetaObject estabelecimento; - private MetaObject empresa; + private EstabelecimentoData estabelecimento; + private EmpresaData empresa; /** Creates a new instance of EmpresaPanel */ @@ -221,19 +223,61 @@ public class EmpresaPanel extends JPanel private void setupComponentsHashtable() { - components = new ComponentsHashtable(); - components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.DESIGNACAO_SOCIAL, designacaoSocialText ); - components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_TIPO, servicoSaudeTipoPanel ); - components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_DESIGNACAO, designacaoServicoSaudeText ); - components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_TIPO, servicoHigieneTipoPanel ); - components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_DESIGNACAO, designacaoText ); + empresaComponents = new ComponentsHashtable(); + empresaComponents.putComponent( EmpresaData.DESIGNACAO_SOCIAL, designacaoSocialText ); + empresaComponents.putComponent( EmpresaData.SERVICO_SAUDE_TIPO, servicoSaudeTipoPanel ); + empresaComponents.putComponent( EmpresaData.SERVICO_SAUDE_DESIGNACAO, designacaoServicoSaudeText ); + empresaComponents.putComponent( EmpresaData.SERVICO_HIGIENE_TIPO, servicoHigieneTipoPanel ); + empresaComponents.putComponent( EmpresaData.SERVICO_HIGIENE_DESIGNACAO, designacaoText ); - components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.NOME, estabelecimentoText ); - components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.LOCALIDADE, localidadeText ); + empresaComponents.putDummy( EmpresaData.MORADA ); + empresaComponents.putDummy( EmpresaData.CODIGO_POSTAL ); + empresaComponents.putDummy( EmpresaData.LOCALIDADE ); + empresaComponents.putDummy( EmpresaData.DISTRITO ); + empresaComponents.putDummy( EmpresaData.CONCELHO ); + empresaComponents.putDummy( EmpresaData.DATA_PROPOSTA ); + empresaComponents.putDummy( EmpresaData.DATA_ACEITACAO ); + empresaComponents.putDummy( EmpresaData.PERFIL_1 ); + empresaComponents.putDummy( EmpresaData.PERFIL_2 ); + empresaComponents.putDummy( EmpresaData.DATA_ENVIO_CONTRATO ); + empresaComponents.putDummy( EmpresaData.DATA_RECEPCAO_CONTRATO ); + empresaComponents.putDummy( EmpresaData.DATA_ENVIO_IDICT ); + empresaComponents.putDummy( EmpresaData.DATA_RELATORIO_ANUAL ); + empresaComponents.putDummy( EmpresaData.CODIGO_1 ); + empresaComponents.putDummy( EmpresaData.CODIGO_2 ); + empresaComponents.putDummy( EmpresaData.CODIGO_3 ); + empresaComponents.putDummy( EmpresaData.CAE ); + empresaComponents.putDummy( EmpresaData.ACTIVIDADE ); + empresaComponents.putDummy( EmpresaData.CONTRIBUINTE ); + empresaComponents.putDummy( EmpresaData.SEGURANCA_SOCIAL ); + empresaComponents.putDummy( EmpresaData.CONTACTO_1 ); + empresaComponents.putDummy( EmpresaData.CONTACTO_2 ); + empresaComponents.putDummy( EmpresaData.SERVICOS ); + empresaComponents.putDummy( EmpresaData.PRECO_HIGIENE ); + empresaComponents.putDummy( EmpresaData.PRECO_MEDICINA ); + empresaComponents.putDummy( EmpresaData.PERIODICIDADE ); - components.putDummy( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.INACTIVO ); - components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.EMPRESA_ID ); - components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.INACTIVO ); + estabelecimentoComponents = new ComponentsHashtable(); + estabelecimentoComponents.putComponent( EstabelecimentoData.NOME, estabelecimentoText ); + estabelecimentoComponents.putComponent( EstabelecimentoData.LOCALIDADE, localidadeText ); + estabelecimentoComponents.putDummy( EstabelecimentoData.MORADA ); + estabelecimentoComponents.putDummy( EstabelecimentoData.CODIGO_POSTAL ); + estabelecimentoComponents.putDummy( EstabelecimentoData.CONTACTO ); + estabelecimentoComponents.putDummy( EstabelecimentoData.HISTORICO ); + estabelecimentoComponents.putDummy( EstabelecimentoData.EMPRESA ); + +// components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.DESIGNACAO_SOCIAL, designacaoSocialText ); +// components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_TIPO, servicoSaudeTipoPanel ); +// components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_SAUDE_DESIGNACAO, designacaoServicoSaudeText ); +// components.put( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_TIPO, servicoHigieneTipoPanel ); +// components.putComponent( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.SERVICO_HIGIENE_DESIGNACAO, designacaoText ); +// +// components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.NOME, estabelecimentoText ); +// components.putComponent( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.LOCALIDADE, localidadeText ); +// +// components.putDummy( FichaDataProvider.T_EMPRESAS + "." + FichaDataProvider.INACTIVO ); +// components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.EMPRESA_ID ); +// components.putDummy( FichaDataProvider.T_ESTABELECIMENTOS + "." + FichaDataProvider.INACTIVO ); } public void fill(Object value) @@ -249,36 +293,46 @@ public class EmpresaPanel extends JPanel { try { - empresa = provider.load( provider.EMPRESAS, new DBKey( empresaID ) ); - DBField fields[] = provider.EMPRESAS.getInsertFields(); - String empresaFields[] = new String[ fields.length ]; - Hashtable data = new Hashtable(); - for( int i = 0; i < empresaFields.length; ++i ) - { - empresaFields[ i ] = fields[ i ].FULL_NAME; - Object fieldValue = empresa.getProperty( empresaFields[ i ] ); - if( fieldValue != null ) - { - data.put( empresaFields[ i ], fieldValue ); - } - } - ComponentController.fill( empresaFields, data, components ); + empresa = (EmpresaData)EmpresaData.load( EmpresaData.class, empresaID ); + String names[] = empresa.getFieldNames(); + ComponentController.fill( names, estabelecimento.getHashData(), empresaComponents ); + if( estabelecimentoID != null ) { - estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); - fields = provider.ESTABELECIMENTOS.getInsertFields(); - String estabelecimentoFields[] = new String[ fields.length ]; - for( int i = 0; i < estabelecimentoFields.length; ++i ) - { - estabelecimentoFields[ i ] = fields[ i ].FULL_NAME; - Object fieldValue = estabelecimento.getProperty( estabelecimentoFields[ i ] ); - if( fieldValue != null ) - { - data.put( estabelecimentoFields[ i ], fieldValue ); - } - } - ComponentController.fill( estabelecimentoFields, data, components ); + estabelecimento = (EstabelecimentoData)EstabelecimentoData.load( EstabelecimentoData.class, estabelecimentoID ); + names = estabelecimento.getFieldNames(); + ComponentController.fill( names, estabelecimento.getHashData(), estabelecimentoComponents ); } + +// DBField fields[] = provider.EMPRESAS.getInsertFields(); +// String empresaFields[] = new String[ fields.length ]; +// Hashtable data = new Hashtable(); +// for( int i = 0; i < empresaFields.length; ++i ) +// { +// empresaFields[ i ] = fields[ i ].FULL_NAME; +// Object fieldValue = empresa.getProperty( empresaFields[ i ] ); +// if( fieldValue != null ) +// { +// data.put( empresaFields[ i ], fieldValue ); +// } +// } +// ComponentController.fill( empresaFields, data, components ); +// if( estabelecimentoID != null ) +// { +// estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); +// fields = provider.ESTABELECIMENTOS.getInsertFields(); +// String estabelecimentoFields[] = new String[ fields.length ]; +// for( int i = 0; i < estabelecimentoFields.length; ++i ) +// { +// estabelecimentoFields[ i ] = fields[ i ].FULL_NAME; +// Object fieldValue = estabelecimento.getProperty( estabelecimentoFields[ i ] ); +// if( fieldValue != null ) +// { +// data.put( estabelecimentoFields[ i ], fieldValue ); +// } +// } +// ComponentController.fill( estabelecimentoFields, data, components ); +// } } catch( Exception ex ) { @@ -300,58 +354,76 @@ public class EmpresaPanel extends JPanel { if( estabelecimento == null ) { - estabelecimento = provider.createObject( provider.ESTABELECIMENTOS ); +// estabelecimento = provider.createObject( provider.ESTABELECIMENTOS ); + estabelecimento = new EstabelecimentoData(); } if( empresa == null ) { - empresa = provider.createObject( provider.EMPRESAS ); - } - DBField fields[] = provider.EMPRESAS.getInsertFields(); - String empresaFields[] = new String[ fields.length ]; - for( int i = 0; i < empresaFields.length; ++i ) - { - empresaFields[ i ] = fields[ i ].FULL_NAME; +// empresa = provider.createObject( provider.EMPRESAS ); + empresa = new EmpresaData(); } +// DBField fields[] = provider.EMPRESAS.getInsertFields(); +// String empresaFields[] = new String[ fields.length ]; +// for( int i = 0; i < empresaFields.length; ++i ) +// { +// empresaFields[ i ] = fields[ i ].FULL_NAME; +// } +// Hashtable hash = new Hashtable(); +// ComponentController.save( empresaFields, hash, components ); +// Enumeration enum = hash.keys(); +// while( enum.hasMoreElements() ) +// { +// String name = ( String )enum.nextElement(); +// empresa.setProperty( name, hash.get( name ) ); +// } +// fields = provider.ESTABELECIMENTOS.getInsertFields(); +// String estabelecimentoFields[] = new String[ fields.length ]; +// for( int i = 0; i < estabelecimentoFields.length; ++i ) +// { +// estabelecimentoFields[ i ] = fields[ i ].FULL_NAME; +// } +// hash = new Hashtable(); +// ComponentController.save( estabelecimentoFields, hash, components ); +// enum = hash.keys(); +// while( enum.hasMoreElements() ) +// { +// String name = ( String )enum.nextElement(); +// estabelecimento.setProperty( name, hash.get( name ) ); +// } + + String names[] = empresa.getFieldNames(); Hashtable hash = new Hashtable(); - ComponentController.save( empresaFields, hash, components ); - Enumeration enum = hash.keys(); - while( enum.hasMoreElements() ) - { - String name = ( String )enum.nextElement(); - empresa.setProperty( name, hash.get( name ) ); - } - fields = provider.ESTABELECIMENTOS.getInsertFields(); - String estabelecimentoFields[] = new String[ fields.length ]; - for( int i = 0; i < estabelecimentoFields.length; ++i ) - { - estabelecimentoFields[ i ] = fields[ i ].FULL_NAME; - } + ComponentController.save( names, hash, empresaComponents ); + empresa.setHashData( hash ); + + names = estabelecimento.getFieldNames(); hash = new Hashtable(); - ComponentController.save( estabelecimentoFields, hash, components ); - enum = hash.keys(); - while( enum.hasMoreElements() ) - { - String name = ( String )enum.nextElement(); - estabelecimento.setProperty( name, hash.get( name ) ); - } - estabelecimento.setProperty( provider.R_ESTABELECIMENTO_EMPRESA, empresa ); + ComponentController.save( names, hash, estabelecimentoComponents ); + estabelecimento.setHashData( hash ); + estabelecimento.set( EstabelecimentoData.EMPRESA, empresa ); + +// estabelecimento.setProperty( provider.R_ESTABELECIMENTO_EMPRESA, empresa ); - if( ((String)empresa.getProperty( provider.DESIGNACAO_SOCIAL )).trim().length() == 0 ) +// if( ((String)empresa.getProperty( provider.DESIGNACAO_SOCIAL )).trim().length() == 0 ) + if( ((String)empresa.get( EmpresaData.DESIGNACAO_SOCIAL )).trim().length() == 0 ) { msg.append( "A empresa tem de ter uma design\u00e7\u00e3o social\n" ); hasMsg = true; } - if( empresa.getProperty( provider.SERVICO_SAUDE_TIPO ) == null ) +// if( empresa.getProperty( provider.SERVICO_SAUDE_TIPO ) == null ) + if( empresa.get( EmpresaData.SERVICO_SAUDE_TIPO ) == null ) { msg.append( "A empresa tem de ter um tipo de seri\00e7o de sa\u00fade\n" ); hasMsg = true; } - if( empresa.getProperty( provider.SERVICO_HIGIENE_TIPO ) == null ) +// if( empresa.getProperty( provider.SERVICO_HIGIENE_TIPO ) == null ) + if( empresa.get( EmpresaData.SERVICO_HIGIENE_TIPO ) == null ) { msg.append( "A empresa tem de ter um tipo de seri\00e7o de higiene\n" ); hasMsg = true; } - if( ((String)estabelecimento.getProperty( provider.NOME )).trim().length() == 0 ) +// if( ((String)estabelecimento.getProperty( provider.NOME )).trim().length() == 0 ) + if( ((String)estabelecimento.get( EstabelecimentoData.NOME )).trim().length() == 0 ) { msg.append( "O estabelecimento tem de ter nome\n" ); hasMsg = true; @@ -373,8 +445,10 @@ public class EmpresaPanel extends JPanel public void clear() { - String names[] = (String[])components.keySet().toArray( new String[0] ); - ComponentController.clear( names, components ); + String names[] = (String[])empresaComponents.keySet().toArray( new String[0] ); + ComponentController.clear( names, empresaComponents ); + names = (String[])estabelecimentoComponents.keySet().toArray( new String[0] ); + ComponentController.clear( names, estabelecimentoComponents ); estabelecimentoText.setText( "Sede" ); empresa = null; estabelecimento = null; @@ -382,7 +456,9 @@ public class EmpresaPanel extends JPanel public void setEnabled( boolean enable ) { - String names[] = (String[])components.keySet().toArray( new String[0] ); - ComponentController.setEnabled( names, enable, components ); + String names[] = (String[])empresaComponents.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, empresaComponents ); + names = (String[])estabelecimentoComponents.keySet().toArray( new String[0] ); + ComponentController.setEnabled( names, enable, estabelecimentoComponents ); } } diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 73fc158c..1a840a75 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -7,6 +7,7 @@ package siprp.ficha; import siprp.*; +import siprp.data.*; import siprp.importer.*; import java.awt.*; @@ -183,40 +184,40 @@ public class FichaWindow extends TabbedWindow } }); StringBuffer msg = new StringBuffer(); - MetaObject medico; + MedicoData medico; try { - medico = (MetaObject)upperPanel.save(); + medico = (MedicoData)upperPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); medico = null; } - MetaObject estabelecimento; + EstabelecimentoData estabelecimento; try { - estabelecimento = (MetaObject)empresaPanel.save(); + estabelecimento = (EstabelecimentoData)empresaPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); estabelecimento = null; } - MetaObject trabalhador; + TrabalhadorData trabalhador; try { - trabalhador = (MetaObject)trabalhadorPanel.save(); + trabalhador = (TrabalhadorData)trabalhadorPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); trabalhador = null; } - MetaObject exame; + ExameData exame; try { - exame = (MetaObject)examePanel.save(); + exame = (ExameData)examePanel.save(); } catch( ValuesException vex ) { @@ -228,22 +229,28 @@ public class FichaWindow extends TabbedWindow JOptionPane.showMessageDialog( this, msg.toString(), "Erro...", JOptionPane.ERROR_MESSAGE ); return false; } - trabalhador.setProperty( FichaDataProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento ); - trabalhador.setProperty( FichaDataProvider.OBSERVACOES, observacoesPanel.save() ); +// trabalhador.setProperty( FichaDataProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento ); +// trabalhador.setProperty( FichaDataProvider.OBSERVACOES, observacoesPanel.save() ); + trabalhador.set( TrabalhadorData.ESTABELECIMENTO, estabelecimento ); + trabalhador.set( TrabalhadorData.OBSERVACOES, observacoesPanel.save() ); - exame.setProperty( FichaDataProvider.R_EXAME_MEDICO, medico ); - exame.setProperty( FichaDataProvider.R_EXAME_TRABALHADOR, trabalhador ); +// exame.setProperty( FichaDataProvider.R_EXAME_MEDICO, medico ); +// exame.setProperty( FichaDataProvider.R_EXAME_TRABALHADOR, trabalhador ); + exame.set( ExameData.MEDICO, medico ); + exame.set( ExameData.TRABALHADOR, trabalhador ); try { exame.save(); - exame.setProperty( FichaDataProvider.PDF, createPDF( exame ) ); - fdpProvider.savePDF( exame ); - DBKey key = trabalhador.getPrimaryKeyValue(); - DBField fields[] = FichaDataProvider.TRABALHADORES.getPrimaryKey(); - trabalhadorID = new Integer( ((Number)key.getFieldValue( fields[ 0 ] )).intValue() ); +// exame.setProperty( FichaDataProvider.PDF, createPDF( exame ) ); +// fdpProvider.savePDF( exame ); + +// DBKey key = trabalhador.getPrimaryKeyValue(); +// DBField fields[] = FichaDataProvider.TRABALHADORES.getPrimaryKey(); +// trabalhadorID = new Integer( ((Number)key.getFieldValue( fields[ 0 ] )).intValue() ); + trabalhadorID = ( Integer ) trabalhador.get( TrabalhadorData.ID ); try { - siprp.data.Marcacao.saveMarcacaoExameForTrabalhadorID( trabalhadorID, (Date)exame.getProperty( FichaDataProvider.PROXIMO_EXAME ) ); + Marcacao.saveMarcacaoExameForTrabalhadorID( trabalhadorID, (Date)exame.get( ExameData.PROXIMO_EXAME ) ); } catch( Exception iex ) { @@ -466,30 +473,30 @@ public class FichaWindow extends TabbedWindow private void print( Integer exameID ) throws Exception { - MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); - byte pdf[] = (byte []) exame.getProperty( fdpProvider.PDF ); - if( exame == null ) - { - throw new Exception( "N\u00e3o existe exame" ); - } - ExamePDF ePDF = new ExamePDF(); - ePDF.print( pdf ); +// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); +// byte pdf[] = (byte []) exame.get( ExameData.PDF ); +// if( exame == null ) +// { +// throw new Exception( "N\u00e3o existe exame" ); +// } +// ExamePDF ePDF = new ExamePDF(); +// ePDF.print( pdf ); } - public byte[] createPDF( MetaObject exame ) + public byte[] createPDF( ExameData exame ) throws Exception { - MetaObject medico = ( (MetaObject []) exame.getProperty( fdpProvider.R_EXAME_MEDICO ) )[0]; - MetaObject trabalhador = ( (MetaObject []) exame.getProperty( fdpProvider.R_EXAME_TRABALHADOR ) )[0]; - MetaObject estabelecimento = ( (MetaObject []) trabalhador.getProperty( fdpProvider.R_TRABALHADOR_ESTABELECIMENTO ) )[0]; - MetaObject empresa = ( (MetaObject []) estabelecimento.getProperty( fdpProvider.R_ESTABELECIMENTO_EMPRESA ) )[0]; - empresa.load( empresa.getPrimaryKeyValue() ); + MedicoData medico = (MedicoData)exame.get( ExameData.MEDICO ); + TrabalhadorData trabalhador = (TrabalhadorData) exame.get( ExameData.TRABALHADOR ); + EstabelecimentoData estabelecimento = (EstabelecimentoData) trabalhador.get( TrabalhadorData.ESTABELECIMENTO ); + EmpresaData empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA ); +// empresa.load( empresa.getPrimaryKeyValue() ); Hashtable ht = new Hashtable(); - ht.put( "designacao_social", empresa.getProperty( fdpProvider.DESIGNACAO_SOCIAL ) ); - ht.put( "estabelecimentos.nome", estabelecimento.getProperty( fdpProvider.NOME ) ); - String aux = (String)estabelecimento.getProperty( fdpProvider.LOCALIDADE ); + ht.put( "designacao_social", empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) ); + ht.put( "estabelecimentos.nome", estabelecimento.get( EstabelecimentoData.NOME ) ); + String aux = (String)estabelecimento.get( EstabelecimentoData.LOCALIDADE ); ht.put( "estabelecimentos.localidade", aux != null ? aux : "" ); - Integer tipo = (Integer)empresa.getProperty( fdpProvider.SERVICO_SAUDE_TIPO ); + Integer tipo = (Integer)empresa.get( EmpresaData.SERVICO_SAUDE_TIPO ); switch( tipo.intValue() ) { case 1: @@ -505,8 +512,8 @@ public class FichaWindow extends TabbedWindow ht.put( "servico_saude_tipo_sns", "" ); break; } - ht.put( "servico_saude_designacao", empresa.getProperty( fdpProvider.SERVICO_SAUDE_DESIGNACAO ) ); - tipo = (Integer)empresa.getProperty( fdpProvider.SERVICO_HIGIENE_TIPO ); + ht.put( "servico_saude_designacao", empresa.get( EmpresaData.SERVICO_SAUDE_DESIGNACAO ) ); + tipo = (Integer)empresa.get( EmpresaData.SERVICO_HIGIENE_TIPO ); switch( tipo.intValue() ) { case 1: @@ -522,9 +529,9 @@ public class FichaWindow extends TabbedWindow ht.put( "servico_higiene_outro", "" ); break; } - ht.put( "servico_higiene_designacao", empresa.getProperty( fdpProvider.SERVICO_HIGIENE_DESIGNACAO ) ); - ht.put( "trabalhadores.nome", trabalhador.getProperty( fdpProvider.NOME ) ); - aux = (String)trabalhador.getProperty( fdpProvider.SEXO ); + ht.put( "servico_higiene_designacao", empresa.get( EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) ); + ht.put( "trabalhadores.nome", trabalhador.get( TrabalhadorData.NOME ) ); + aux = (String)trabalhador.get( TrabalhadorData.SEXO ); switch( aux.charAt( 0 ) ) { case 'm': @@ -535,27 +542,27 @@ public class FichaWindow extends TabbedWindow break; } DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT ); - Date data = ( Date )trabalhador.getProperty( fdpProvider.DATA_NASCIMENTO ); + Date data = ( Date )trabalhador.get( TrabalhadorData.DATA_NASCIMENTO ); ht.put( "data_nascimento", data != null ? df.format( data ) : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.NACIONALIDADE ); + aux = (String)trabalhador.get( TrabalhadorData.NACIONALIDADE ); ht.put( "nacionalidade", aux != null ? aux : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.NUMERO_MECANOGRAFICO ); + aux = (String)trabalhador.get( TrabalhadorData.NUMERO_MECANOGRAFICO ); ht.put( "numero_mecanografico", aux != null ? aux : "" ); - data = ( Date )trabalhador.getProperty( fdpProvider.DATA_ADMISSAO ); + data = ( Date )trabalhador.get( TrabalhadorData.DATA_ADMISSAO ); ht.put( "data_admissao", data != null ? df.format( data ) : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.CATEGORIA ); + aux = (String)trabalhador.get( TrabalhadorData.CATEGORIA ); ht.put( "categoria", aux != null ? aux : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.LOCAL_TRABALHO ); + aux = (String)trabalhador.get( TrabalhadorData.LOCAL_TRABALHO ); ht.put( "local_trabalho", aux != null ? aux : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.FUNCAO_PROPOSTA ); + aux = (String)trabalhador.get( TrabalhadorData.FUNCAO_PROPOSTA ); ht.put( "funcao_proposta", aux != null ? aux : "" ); - data = ( Date )trabalhador.getProperty( fdpProvider.DATA_ADMISSAO_FUNCAO ); + data = ( Date )trabalhador.get( TrabalhadorData.DATA_ADMISSAO_FUNCAO ); ht.put( "data_admissao_funcao", data != null ? df.format( data ) : "" ); - aux = (String)trabalhador.getProperty( fdpProvider.OBSERVACOES ); + aux = (String)trabalhador.get( TrabalhadorData.OBSERVACOES ); ht.put( "observacoes", aux != null ? aux : "" ); - data = ( Date )exame.getProperty( fdpProvider.DATA ); + data = ( Date )exame.get( ExameData.DATA ); ht.put( "exames.data", data != null ? df.format( data ) : "" ); - tipo = (Integer)exame.getProperty( fdpProvider.TIPO ); + tipo = (Integer)exame.get( ExameData.TIPO ); switch( tipo.intValue() ) { case 1: @@ -566,7 +573,7 @@ public class FichaWindow extends TabbedWindow break; case 3: ht.put( "tipo_ocasional", "" ); - tipo = (Integer)exame.getProperty( fdpProvider.OCASIONAL ); + tipo = (Integer)exame.get( ExameData.OCASIONAL ); switch( tipo.intValue() ) { case 1: @@ -588,17 +595,17 @@ public class FichaWindow extends TabbedWindow ht.put( "tipo_trabalho", "" ); break; case 10: - aux = (String)exame.getProperty( fdpProvider.OUTRO_TIPO ); + aux = (String)exame.get( ExameData.OUTRO_TIPO ); ht.put( "tipo_outro", aux != null ? aux : "" ); break; } break; // case 4: -// aux = (String)exame.getProperty( fdpProvider.OUTRO_TIPO ); +// aux = (String)exame.get( ExameData.OUTRO_TIPO ); // ht.put( "tipo_outro", aux != null ? aux : "" ); // break; } - tipo = (Integer)exame.getProperty( fdpProvider.RESULTADO ); + tipo = (Integer)exame.get( ExameData.RESULTADO ); switch( tipo.intValue() ) { case 1: @@ -614,21 +621,21 @@ public class FichaWindow extends TabbedWindow ht.put( "resultado_inapto_def", "" ); break; } - aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_1 ); + aux = (String)exame.get( ExameData.OUTRA_FUNCAO_1 ); ht.put( "outra_funcao_1", aux != null ? aux : "" ); - aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_2 ); + aux = (String)exame.get( ExameData.OUTRA_FUNCAO_2 ); ht.put( "outra_funcao_2", aux != null ? aux : "" ); - aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_3 ); + aux = (String)exame.get( ExameData.OUTRA_FUNCAO_3 ); ht.put( "outra_funcao_3", aux != null ? aux : "" ); - aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_4 ); + aux = (String)exame.get( ExameData.OUTRA_FUNCAO_4 ); ht.put( "outra_funcao_4", aux != null ? aux : "" ); - aux = (String)exame.getProperty( fdpProvider.OUTRAS_RECOMENDACOES ); + aux = (String)exame.get( ExameData.OUTRAS_RECOMENDACOES ); ht.put( "outras_recomendacoes", aux != null ? aux : "" ); - data = ( Date )exame.getProperty( fdpProvider.PROXIMO_EXAME ); + data = ( Date )exame.get( ExameData.PROXIMO_EXAME ); ht.put( "proximo_exame", data != null ? df.format( data ) : "n/d" ); - aux = (String)medico.getProperty( fdpProvider.NOME ); + aux = (String)medico.get( MedicoData.NOME ); ht.put( "medicos.nome", aux != null ? aux : "" ); - aux = (String)medico.getProperty( fdpProvider.NUMERO_CEDULA ); + aux = (String)medico.get( MedicoData.NUMERO_CEDULA ); ht.put( "numero_cedula", aux != null ? aux : "" ); ExamePDF ePDF = new ExamePDF(); return ePDF.createPDF( ht ); @@ -717,17 +724,19 @@ public class FichaWindow extends TabbedWindow private void delete( Integer exameID ) throws Exception { - MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); +// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); + ExameData exame = (ExameData) ExameData.load( ExameData.class, exameID ); if( exame == null ) { throw new Exception( "N\u00e3o existe exame" ); } if( JOptionPane.showConfirmDialog( this, - "Tem a certeza que quer apagar o exame de " + exame.getProperty( fdpProvider.DATA ) + "?", + "Tem a certeza que quer apagar o exame de " + exame.get( ExameData.DATA ) + "?", "...", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null ) == 0 ) { - exame.setProperty( fdpProvider.INACTIVO, "y" ); - exame.save(); +// exame.set( ExameData.INACTIVO, "y" ); +// exame.save(); + exame.delete(); } } } diff --git a/trunk/siprp/ficha/TrabalhadorPanel.java b/trunk/siprp/ficha/TrabalhadorPanel.java index f324ed7e..d8023e30 100644 --- a/trunk/siprp/ficha/TrabalhadorPanel.java +++ b/trunk/siprp/ficha/TrabalhadorPanel.java @@ -18,6 +18,7 @@ import com.evolute.utils.ui.*; import com.evolute.utils.ui.panel.*; import siprp.*; +import siprp.data.*; import siprp.importer.*; /** * @@ -39,7 +40,7 @@ public class TrabalhadorPanel extends JPanel private ComponentsHashtable components; private FichaDataProvider provider; - private MetaObject trabalhador; + private TrabalhadorData trabalhador; /** Creates a new instance of TrabalhadorPanel */ @@ -194,19 +195,8 @@ public class TrabalhadorPanel extends JPanel private void setupComponentsHashtable() { components = new ComponentsHashtable(); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NOME, nomeText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_NASCIMENTO, dataNascimentoPanel ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NACIONALIDADE, nacionalidadeText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NUMERO_MECANOGRAFICO, numeroMecanograficoText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO, dataAdmissaoPanel ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.CATEGORIA, categoriaText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.LOCAL_TRABALHO, localText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.FUNCAO_PROPOSTA, funcaoText ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO_FUNCAO, dataAdmissaoFuncaoPanel ); - components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.ESTABELECIMENTO_ID ); - components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.OBSERVACOES ); - components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.SEXO, - new ControllableComponent() + components.putComponent( TrabalhadorData.NOME, nomeText ); + components.putComponent( TrabalhadorData.SEXO, new ControllableComponent() { public void fill( Object value ) { @@ -240,6 +230,66 @@ public class TrabalhadorPanel extends JPanel 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.putDummy( TrabalhadorData.DATA_DEMISSAO ); + components.putDummy( TrabalhadorData.OBSERVACOES ); + components.putDummy( TrabalhadorData.OBSERVACOES_GESTAO ); + components.putDummy( TrabalhadorData.PERFIL ); + components.putDummy( TrabalhadorData.ESTABELECIMENTO ); + +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NOME, nomeText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_NASCIMENTO, dataNascimentoPanel ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NACIONALIDADE, nacionalidadeText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.NUMERO_MECANOGRAFICO, numeroMecanograficoText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO, dataAdmissaoPanel ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.CATEGORIA, categoriaText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.LOCAL_TRABALHO, localText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.FUNCAO_PROPOSTA, funcaoText ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.DATA_ADMISSAO_FUNCAO, dataAdmissaoFuncaoPanel ); +// components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.ESTABELECIMENTO_ID ); +// components.putDummy( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.OBSERVACOES ); +// components.putComponent( FichaDataProvider.T_TRABALHADORES + "." + FichaDataProvider.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 ); +// } +// } ); } public void fill(Object value) @@ -253,20 +303,23 @@ public class TrabalhadorPanel extends JPanel { try { - trabalhador = provider.load( FichaDataProvider.TRABALHADORES, new DBKey( trabalhadorID ) ); - DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields(); - String trabalhadorFields[] = new String[ fields.length ]; - Hashtable data = new Hashtable(); - for( int i = 0; i < trabalhadorFields.length; ++i ) - { - trabalhadorFields[ i ] = fields[ i ].FULL_NAME; - Object fieldValue = trabalhador.getProperty( trabalhadorFields[ i ] ); - if( fieldValue != null ) - { - data.put( trabalhadorFields[ i ], fieldValue ); - } - } - ComponentController.fill( trabalhadorFields, data, components ); + trabalhador = ( TrabalhadorData ) TrabalhadorData.load( TrabalhadorData.class, trabalhadorID ); + String names[] = trabalhador.getFieldNames(); + ComponentController.fill( names, trabalhador.getHashData(), components ); +// trabalhador = provider.load( FichaDataProvider.TRABALHADORES, new DBKey( trabalhadorID ) ); +// DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields(); +// String trabalhadorFields[] = new String[ fields.length ]; +// Hashtable data = new Hashtable(); +// for( int i = 0; i < trabalhadorFields.length; ++i ) +// { +// trabalhadorFields[ i ] = fields[ i ].FULL_NAME; +// Object fieldValue = trabalhador.getProperty( trabalhadorFields[ i ] ); +// if( fieldValue != null ) +// { +// data.put( trabalhadorFields[ i ], fieldValue ); +// } +// } +// ComponentController.fill( trabalhadorFields, data, components ); } catch( Exception ex ) { @@ -285,28 +338,35 @@ public class TrabalhadorPanel extends JPanel { if( trabalhador == null ) { - trabalhador = provider.createObject( FichaDataProvider.TRABALHADORES ); - } - DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields(); - String trabalhadorFields[] = new String[ fields.length ]; - for( int i = 0; i < trabalhadorFields.length; ++i ) - { - trabalhadorFields[ i ] = fields[ i ].FULL_NAME; +// trabalhador = provider.createObject( FichaDataProvider.TRABALHADORES ); + trabalhador = new TrabalhadorData(); } +// DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields(); +// String trabalhadorFields[] = new String[ fields.length ]; +// for( int i = 0; i < trabalhadorFields.length; ++i ) +// { +// trabalhadorFields[ i ] = fields[ i ].FULL_NAME; +// } +// Hashtable hash = new Hashtable(); +// ComponentController.save( trabalhadorFields, hash, components ); +// Enumeration enum = hash.keys(); +// while( enum.hasMoreElements() ) +// { +// String name = ( String )enum.nextElement(); +// trabalhador.setProperty( name, hash.get( name ) ); +// } + String names[] = trabalhador.getFieldNames(); Hashtable hash = new Hashtable(); - ComponentController.save( trabalhadorFields, hash, components ); - Enumeration enum = hash.keys(); - while( enum.hasMoreElements() ) - { - String name = ( String )enum.nextElement(); - trabalhador.setProperty( name, hash.get( name ) ); - } - if( ((String)trabalhador.getProperty( FichaDataProvider.NOME )).trim().length() == 0 ) + ComponentController.save( names, hash, components ); + trabalhador.setHashData( hash ); +// if( ((String)trabalhador.getProperty( FichaDataProvider.NOME )).trim().length() == 0 ) + if( ((String)trabalhador.get( TrabalhadorData.NOME )).trim().length() == 0 ) { msg.append( "O trabalhador tem de ter nome\n" ); hasMsg = true; } - if( trabalhador.getProperty( FichaDataProvider.SEXO ) == null ) +// if( trabalhador.getProperty( FichaDataProvider.SEXO ) == null ) + if( trabalhador.get( TrabalhadorData.SEXO ) == null ) { msg.append( "O trabalhador tem de ter um sexo definido\n" ); hasMsg = true; diff --git a/trunk/siprp/ficha/UpperPanel.java b/trunk/siprp/ficha/UpperPanel.java index 0986bc1f..e1e7f08e 100644 --- a/trunk/siprp/ficha/UpperPanel.java +++ b/trunk/siprp/ficha/UpperPanel.java @@ -17,6 +17,7 @@ import com.evolute.utils.metadb.*; import com.evolute.utils.ui.*; import siprp.*; +import siprp.data.*; /** * @@ -116,25 +117,25 @@ public class UpperPanel extends JPanel clear(); try { - MetaObject trabalhador; - MetaObject estabelecimento; - MetaObject empresa; + TrabalhadorData trabalhador; + EstabelecimentoData estabelecimento; + EmpresaData empresa; if( trabalhadorID != null ) { - trabalhador = provider.load( provider.TRABALHADORES, new DBKey( trabalhadorID ) ); - String nome = (String) trabalhador.getProperty( provider.NOME ); + trabalhador = ( TrabalhadorData ) TrabalhadorData.load( TrabalhadorData.class, trabalhadorID ); + String nome = (String) trabalhador.get( TrabalhadorData.NOME ); nomeText.setText( nome ); } String nomeEstabelecimento = ""; if( estabelecimentoID != null ) { - estabelecimento = provider.load( provider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) ); - nomeEstabelecimento = (String) estabelecimento.getProperty( provider.NOME ); + estabelecimento = ( EstabelecimentoData ) EstabelecimentoData.load( EstabelecimentoData.class, estabelecimentoID ); + nomeEstabelecimento = (String) estabelecimento.get( EstabelecimentoData.NOME ); } if( empresaID != null ) { - empresa = provider.load( provider.EMPRESAS, new DBKey( empresaID ) ); - String nomeEmpresa = (String) empresa.getProperty( provider.DESIGNACAO_SOCIAL ); + empresa = ( EmpresaData ) EmpresaData.load( EmpresaData.class, empresaID ); + String nomeEmpresa = (String) empresa.get( EmpresaData.DESIGNACAO_SOCIAL ); empresaText.setText( nomeEmpresa + ( nomeEstabelecimento.length() > 0?" / " + nomeEstabelecimento:"" ) ); } } @@ -151,7 +152,7 @@ public class UpperPanel extends JPanel { try { - MetaObject medico = provider.load( provider.MEDICOS, new DBKey( id ) ); + MedicoData medico = ( MedicoData )MedicoData.load( MedicoData.class, id ); return medico; } catch( Exception ex )