diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 763d33f3..f010dae1 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -7,8 +7,10 @@ package siprp.ficha; import siprp.*; +import siprp.importer.*; import java.awt.*; +import java.io.*; import java.util.*; import javax.swing.*; import java.text.*; @@ -117,6 +119,22 @@ public class FichaWindow extends TabbedWindow }, "Imprimir", "Imprimir Ficha", "print", 0, true ); + + registerAction( new ActionHandler(){ + public void execute() + { + excel(); + } + + public boolean activate( boolean newAction, boolean editAction, + boolean cancelAction, boolean saveAction, + boolean deleteAction, boolean selectAction ) + { + return saveAction; + } + }, "Importar", + "Importar de Excel", "excel", + 0, true ); } public boolean save( int index ) @@ -514,4 +532,37 @@ public class FichaWindow extends TabbedWindow return ePDF.createPDF( ht ); } + 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.show(); + //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 ); + Hashtable hash = importer.getData(); + if( hash != null ) + { + trabalhadorPanel.setData( hash ); + } + } + catch( Exception ex ) + { + ex.printStackTrace(); + JOptionPane.showMessageDialog( this, "Erro a importar", "Erro...", JOptionPane.ERROR_MESSAGE ); + } + } + + } } diff --git a/trunk/siprp/ficha/TrabalhadorPanel.java b/trunk/siprp/ficha/TrabalhadorPanel.java index 7ccf5c32..17011f83 100644 --- a/trunk/siprp/ficha/TrabalhadorPanel.java +++ b/trunk/siprp/ficha/TrabalhadorPanel.java @@ -17,6 +17,7 @@ import com.evolute.utils.ui.*; import com.evolute.utils.ui.panel.*; import siprp.*; +import siprp.importer.*; /** * * @author fpalma @@ -333,4 +334,58 @@ public class TrabalhadorPanel extends JPanel String names[] = (String[])components.keySet().toArray( new String[0] ); ComponentController.setEnabled( names, enable, components ); } + + public void setData( Hashtable data ) + { + String nome = (String)data.get( Importer.NOME ); + if( nome != null && nome.trim().length() > 0 ) + { + nomeText.setText( nome ); + } + String sexo = (String)data.get( Importer.SEXO ); + if( sexo != null && sexo.trim().length() > 0 ) + { + Integer sexoInt; + if( sexo.trim().toLowerCase().charAt(0) == 'f' ) + { + sexoInt = new Integer( 2 ); + } + else + { + sexoInt = new Integer( 1 ); + } + sexoPanel.fill( sexoInt ); + } + String nacionalidade = (String)data.get( Importer.NACIONALIDADE ); + if( nacionalidade != null && nacionalidade.trim().length() > 0 ) + { + nacionalidadeText.setText( nacionalidade ); + } + String dataNascimento = (String)data.get( Importer.DATA_NASCIMENTO ); + + String numeroMecanografico = (String)data.get( Importer.NUMERO_MECANOGRAFICO ); + if( numeroMecanografico != null && numeroMecanografico.trim().length() > 0 ) + { + numeroMecanograficoText.setText( numeroMecanografico ); + } + String dataAdmissao = (String)data.get( Importer.DATA_ADMISSAO ); + + String categoria = (String)data.get( Importer.CATEGORIA ); + if( categoria != null && categoria.trim().length() > 0 ) + { + categoriaText.setText( categoria ); + } + String localTrabalho = (String)data.get( Importer.LOCAL_TRABALHO ); + if( localTrabalho != null && localTrabalho.trim().length() > 0 ) + { + localText.setText( localTrabalho ); + } + String funcao = (String)data.get( Importer.FUNCAO ); + if( funcao != null && funcao.trim().length() > 0 ) + { + funcaoText.setText( funcao ); + } + String dataAdmissaoFuncao = (String)data.get( Importer.DATA_ADMISSAO_FUNCAO ); + + } }