Adicionada exportacao para PDF de fichas de aptidao

git-svn-id: https://svn.coded.pt/svn/SIPRP@698 bb69d46d-e84e-40c8-a05a-06db0d633741
lxbfYeaa
Tiago Simão 18 years ago
parent f841e5eb0f
commit f675de0c5f

@ -3,7 +3,9 @@ package siprp.ficha;
import java.awt.Color; import java.awt.Color;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import siprp.SingletonConstants; import siprp.SingletonConstants;
@ -179,8 +181,8 @@ public class ExamePDF implements FichaAptidaoConstants
} }
} }
public void printSilent( byte []pdf, String nome, String printerName ) public void printSilent( byte []pdf, String nome, String printerName ) throws InterruptedException, IOException
throws Exception // throws Exception
{ {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
// FileOutputStream fos = new FileOutputStream( System.getProperty( "user.home" ) + System.getProperty( "file.separator" ) + "report_ficha" + time + ".pdf" ); // FileOutputStream fos = new FileOutputStream( System.getProperty( "user.home" ) + System.getProperty( "file.separator" ) + "report_ficha" + time + ".pdf" );

@ -14,12 +14,14 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -35,6 +37,7 @@ import siprp.data.MedicoData;
import siprp.data.TrabalhadorData; import siprp.data.TrabalhadorData;
import siprp.importer.Importer; import siprp.importer.Importer;
import siprp.medicina.MarcacoesMedicinaHandler; import siprp.medicina.MarcacoesMedicinaHandler;
import siprp.printer.Printer;
import com.evolute.utils.Singleton; import com.evolute.utils.Singleton;
import com.evolute.utils.data.IDObject; import com.evolute.utils.data.IDObject;
@ -220,6 +223,20 @@ public class FichaWindow extends TabbedWindow
}, "Apagar Fichas Anteriores", }, "Apagar Fichas Anteriores",
"Apagar Fichas Anteriores", null, "Apagar Fichas Anteriores", null,
0, false ); 0, false );
registerAction( new ActionHandler(){
public void execute()
{
printToFile();
}
public boolean activate( boolean newAction, boolean editAction,
boolean cancelAction, boolean saveAction,
boolean deleteAction, boolean selectAction )
{
return saveAction || editAction;
}
}, "Exportar", "Exportar para PDF", null, 0, true );
// registerAction( new ActionHandler(){ // registerAction( new ActionHandler(){
// public void execute() // public void execute()
@ -560,15 +577,15 @@ public class FichaWindow extends TabbedWindow
System.out.println( "no id" ); System.out.println( "no id" );
return; return;
} }
print( id ); print( id, false );
} }
catch( Exception ex ) catch( Exception ex )
{ {
DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel imprimir", true ); DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel imprimir", true );
} }
} }
private void print( Integer exameID ) private void print( Integer exameID, boolean toFile )
throws Exception throws Exception
{ {
// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); // MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) );
@ -578,43 +595,101 @@ public class FichaWindow extends TabbedWindow
throw new Exception( "N\u00e3o existe exame" ); throw new Exception( "N\u00e3o existe exame" );
} }
// lflores - ignore FO (for now) byte fo[] = (byte []) exame.get( ExameData.FO );
byte fo[] = null; //(byte []) exame.get( ExameData.FO );
byte pdf[] = (byte []) exame.get( ExameData.PDF ); byte pdf[] = (byte []) exame.get( ExameData.PDF );
if( fo != null ) if( toFile )
{ {
FichaAptidaoCreator.getCreator().print( fo ); TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR );
String fileName = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) );
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
fileName = fileName + sdf.format( date );
fileName = fileName.replace( ' ', '_' );
JFileChooser dialog = new JFileChooser();
dialog.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
int result = dialog.showSaveDialog( this );
if( result == JFileChooser.APPROVE_OPTION )
{
File selectedFile = dialog.getSelectedFile();
if( selectedFile != null )
{
String absolutePath = selectedFile.getAbsolutePath();
if( absolutePath != null )
{
if(absolutePath.charAt( absolutePath.length() - 1) != File.separatorChar )
{
absolutePath = absolutePath + File.separatorChar;
}
fileName = absolutePath + fileName + ".pdf";
}
if( fo != null )
{
Printer.printFoToFile( fo, fileName, true );
}
else
{
Printer.printPDFToFile( pdf, fileName, true );
}
}
}
} }
else else
{ {
TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR ); if( fo != null )
String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) ); {
nomeFicheiro = nomeFicheiro.replaceAll( " ", "_" ); FichaAptidaoCreator.getCreator().print( fo );
ePDF.print( pdf, nomeFicheiro ); }
} else
{
TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR );
String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) );
nomeFicheiro = nomeFicheiro.replaceAll( " ", "_" );
ePDF.print( pdf, nomeFicheiro );
}
}
} }
private void printFO( Integer exameID ) private void printToFile()
throws Exception
{ {
// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); try
ExameData exame = (ExameData) JDO.load( ExameData.class, exameID );
if( exame == null )
{ {
throw new Exception( "N\u00e3o existe exame" ); if( trabalhadorID != null )
{
Integer id = fdpProvider.getLastExameIDForTrabalhador( trabalhadorID );
if( id != null )
{
print(id, true);
}
}
} }
catch( Exception ex )
// lflores - ignore FO (for now)
byte fo[] = (byte []) exame.get( ExameData.FO );
if( fo != null )
{ {
byte pdf[] = FichaAptidaoCreator.getCreator().createPDF( fo ); DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel exportar", true );
new PDFFilePrinter( pdf, true );
} }
} }
// private void printFO( Integer exameID )
// throws Exception
//{
//// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) );
// ExameData exame = (ExameData) JDO.load( ExameData.class, exameID );
// if( exame == null )
// {
// throw new Exception( "N\u00e3o existe exame" );
// }
//
// // lflores - ignore FO (for now)
// byte fo[] = (byte []) exame.get( ExameData.FO );
//
// if( fo != null )
// {
// byte pdf[] = FichaAptidaoCreator.getCreator().createPDF( fo );
// new PDFFilePrinter( pdf, true );
// }
//}
public byte[] createFO( ExameData exame ) public byte[] createFO( ExameData exame )
throws Exception throws Exception
{ {
@ -1117,11 +1192,17 @@ public class FichaWindow extends TabbedWindow
{ {
if( useFO ) if( useFO )
{ {
printFO( ( ( IDObject )value ).getID() ); ExameData exame = (ExameData) JDO.load( ExameData.class, ( ( IDObject )value ).getID() );
if( exame == null )
{
throw new Exception( "N\u00e3o existe exame" );
}
byte fo[] = (byte[]) exame.get( ExameData.FO );
Printer.printFO( fo );
} }
else else
{ {
print( ( ( IDObject )value ).getID() ); print( ( ( IDObject )value ).getID(), false );
} }
} }
catch( Exception ex ) catch( Exception ex )

@ -320,9 +320,6 @@ public class TrabalhadorPanel extends JPanel
{ {
trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID ); trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID );
String names[] = trabalhador.getFieldNames(); String names[] = trabalhador.getFieldNames();
System.out.println(names.length);
System.out.println(trabalhador.getHashData().size());
System.out.println(components.size());
ComponentController.fill( names, trabalhador.getHashData(), components ); ComponentController.fill( names, trabalhador.getHashData(), components );
// trabalhador = provider.load( FichaDataProvider.TRABALHADORES, new DBKey( trabalhadorID ) ); // trabalhador = provider.load( FichaDataProvider.TRABALHADORES, new DBKey( trabalhadorID ) );
// DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields(); // DBField fields[] = FichaDataProvider.TRABALHADORES.getInsertFields();

@ -24,6 +24,7 @@ import com.evolute.utils.xml.*;
import siprp.data.*; import siprp.data.*;
import siprp.ficha.*; import siprp.ficha.*;
import siprp.printer.Printer;
/** /**
* *
@ -125,22 +126,41 @@ public class FichasPrinter extends Thread
// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); // MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) );
// ExameData exame = (ExameData) JDO.load( ExameData.class, exameID ); // ExameData exame = (ExameData) JDO.load( ExameData.class, exameID );
// byte pdf[] = (byte []) exame.get( ExameData.PDF ); // byte pdf[] = (byte []) exame.get( ExameData.PDF );
byte pdf[] = provider.getPDF( exameID );
if( pdf == null ) if( !printFO( exameID ) && !printPDF( exameID ) )
{ {
throw new Exception( "N\u00e3o existe exame" ); 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 ) ); private boolean printFO(int exameID) throws Exception
// nomeFicheiro.replaceAll( " ", "_" ); {
String split[] = nomeFicheiro.split( " " ); boolean result = false;
nomeFicheiro = ""; byte[] fo = provider.getFO( exameID );
for( int n = 0; n < split.length; n++ ) if(fo != null)
{ {
nomeFicheiro += split[ n ] + "_"; Printer.printFO( fo );
result = true;
} }
ExamePDF ePDF = new ExamePDF(); return result;
ePDF.printSilent( pdf, nomeFicheiro, printerName ); }
}
private boolean printPDF(int exameID) throws Exception
{
boolean result = false;
byte pdf[] = provider.getPDF( exameID );
if( pdf != null )
{
String nomeFicheiro = StringPlainer.convertString( provider.getNomeTrabalhadorForExameID( exameID ) );
String split[] = nomeFicheiro.split( " " );
nomeFicheiro = "";
for( int n = 0; n < split.length; n++ )
{
nomeFicheiro += split[n] + "_";
}
Printer.printPDF( pdf, nomeFicheiro, printerName );
result = true;
}
return result;
}
} }

Loading…
Cancel
Save