git-svn-id: https://svn.coded.pt/svn/SIPRP@1011 bb69d46d-e84e-40c8-a05a-06db0d633741

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Tiago Simão 17 years ago
parent 11750ccf3c
commit 57a7462c95

@ -40,14 +40,13 @@ import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.AbstractDocument.LeafElement;
import leaf.data.Validator;
import leaf.ui.LeafButton;
import leaf.ui.LeafDialog;
import leaf.ui.LeafIconButton;
import leaf.ui.LeafLogic;
import leaf.ui.LeafTextAreaEditor;
import siprp.database.cayenne.objects.Estabelecimentos;
import siprp.database.cayenne.objects.HsEmailEstabelecimento;
import siprp.database.cayenne.objects.HsRelatorio;
import siprp.database.cayenne.objects.MarcacoesEstabelecimento;
@ -65,6 +64,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
private static final long serialVersionUID = 1L;
private static final int MAX_NOME_ESTABELECIMENTO_ON_FILENAME = 10;
private static final String DEFAULT_FUNCIONARIOS_TEXT = "A empresa supracitada possui ? funcionários, sendo que ? destes exercem actividades na zona de produtos frescos.";
private static final String ICON_NAME_SAVE = "siprp/higiene/gestao/riscos/save.png";
@ -355,11 +356,13 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if( relatorio != null )
{
relatorio.setIsSubmetido( new Date() );
relatorio.save();
sendMail( relatorio );
refresh();
setRelatorio( relatorio, false );
if( sendMail( relatorio ) )
{
refresh();
relatorio.setIsSubmetido( new Date() );
relatorio.save();
setRelatorio( relatorio, false );
}
}
}
catch( Exception e )
@ -452,66 +455,96 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
return frame;
}
private void sendMail( HsRelatorio relatorio ) throws Exception
private boolean sendMail( HsRelatorio relatorio ) throws Exception
{
List<HsEmailEstabelecimento> rels = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getHsEmailEstabelecimento();
String to = "";
for( HsEmailEstabelecimento rel : rels )
{
to += rel.getToHsEmail().getEmail() + (to.length() == 0 ? "" : ", ");
}
if( to.length() > 0 && to.contains( "@" ) )
boolean result = false;
List<HsEmailEstabelecimento> rels = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getHsEmailEstabelecimento();
String to = "";
for( HsEmailEstabelecimento rel : rels )
{
to += rel.getToHsEmail().getEmail() + ",";
}
if(to.endsWith( "," ))
{
to = to.substring( 0, to.length() - 1 );
}
if( to.length() > 0 )
{
String nomeEstabelecimento = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome();
MarcacoesTecnicosHst tecnico = relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst();
String nomeTecnico = tecnico == null ? "" : tecnico.getNome();
Date dataVisita = relatorio.getToHsMarcacoesEstabelecimento().getData();
String dataVisitaString = new SimpleDateFormat("dd/MM/yyyy").format( dataVisita );
String subject = "Relatório da Avaliação de Riscos Laborais e Plano de Actuação de " + nomeEstabelecimento + " - auditoria de " + dataVisitaString;
String body = "<html>Exmos. Senhores" +
"<br>" +
"<br>" +
"<br>" +
"Junto enviamos o relatório de avaliação de riscos laborais e " +
"respectivo plano de actuação da auditoria realizada no dia " +
dataVisitaString +
" ao vosso estabelecimento de(o) " +
nomeEstabelecimento +
". Aconselhamos que tenham em conta as não conformidades indicadas " +
"nestes documentos e que preencham o plano de actuação por forma a " +
"auxiliar-vos na planificação das medidas correctivas e para poderem " +
"apresentá-los em caso de inspecção da ACT Autoridade para as Condições do Trabalho." +
"<br>" +
"<br>" +
"<br>" +
"Caso pretendam o nosso apoio ou necessitem de qualquer esclarecimento, contactem-nos, por favor, através do telefone (+351) 213 504 540." +
"<br>" +
"<br>" +
"<br>" +
"Com os melhores cumprimentos, " +
"<br>" +
"<br>" +
"<br>" +
nomeTecnico +
"<br>" +
"SIPRP - Sociedade Ibérica de Prevenção de Riscos Profissionais " +
"<br>" +
"Atrium Saldanha - Praça Duque de Saldanha, 1 - 9º G - 1050-094 Lisboa " +
"<br>" +
"Telefone: (+351) 213 504 540 " +
"<br>" +
"Fax: (+351) 213 504 549 " +
"<br>" +
"E-mail: geral@siprp.pt " +
"<br>" +
"URL: www.siprp.com " +
"<br>" +
"<br>" +
"<br>" +
"Esta é uma mensagem gerada automaticamente pelo nosso sistema, por favor não responda.</html>";
MailDialog md = new MailDialog( getFrame(), to, "", subject, body, getRelatoriosTemp(relatorio) );
result = md.wasSent();
}
return result;
}
private String getShortNameForEstabelecimento( Estabelecimentos estabelecimento )
{
String result = null;
String nome = estabelecimento.getNomePlain();
if( nome != null )
{
result = nome.trim();
if( result.length() > MAX_NOME_ESTABELECIMENTO_ON_FILENAME )
{
String nomeEstabelecimento = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome();
MarcacoesTecnicosHst tecnico = relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst();
String nomeTecnico = tecnico == null ? "" : tecnico.getNome();
Date dataVisita = relatorio.getToHsMarcacoesEstabelecimento().getData();
String dataVisitaString = new SimpleDateFormat("dd/MM/yyyy").format( dataVisita );
String subject = "Relatório da Avaliação de Riscos Laborais e Plano de Actuação de " + nomeEstabelecimento + " - auditoria de " + dataVisitaString;
String body = "<html>Exmos. Senhores" +
"<br>" +
"<br>" +
"<br>" +
"Junto enviamos o relatório de avaliação de riscos laborais e " +
"respectivo plano de actuação da auditoria realizada no dia " +
dataVisitaString +
" ao vosso estabelecimento de(o) " +
nomeEstabelecimento +
". Aconselhamos que tenham em conta as não conformidades indicadas " +
"nestes documentos e que preencham o plano de actuação por forma a " +
"auxiliar-vos na planificação das medidas correctivas e para poderem " +
"apresentá-los em caso de inspecção da ACT Autoridade para as Condições do Trabalho." +
"<br>" +
"<br>" +
"<br>" +
"Caso pretendam o nosso apoio ou necessitem de qualquer esclarecimento, contactem-nos, por favor, através do telefone (+351) 213 504 540." +
"<br>" +
"<br>" +
"<br>" +
"Com os melhores cumprimentos, " +
"<br>" +
"<br>" +
"<br>" +
nomeTecnico +
"<br>" +
"SIPRP - Sociedade Ibérica de Prevenção de Riscos Profissionais " +
"<br>" +
"Atrium Saldanha - Praça Duque de Saldanha, 1 - 9º G - 1050-094 Lisboa " +
"<br>" +
"Telefone: (+351) 213 504 540 " +
"<br>" +
"Fax: (+351) 213 504 549 " +
"<br>" +
"E-mail: geral@siprp.pt " +
"<br>" +
"URL: www.siprp.com " +
"<br>" +
"<br>" +
"<br>" +
"Esta é uma mensagem gerada automaticamente pelo nosso sistema, por favor não responda.</html>";
new MailDialog( getFrame(), to, "", subject, body, getRelatoriosTemp(relatorio) );
String [] tokens = result.split( " " );
if( tokens != null && tokens.length > 2 )
{
result = "";
for ( String token : tokens )
{
result += token == null ? "" : token;
}
}
}
}
return result;
}
private Vector<File> getRelatoriosTemp(HsRelatorio relatorio)
{
@ -522,8 +555,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
byte[] planoPDF = new PlanoActuacaoPDFCreator().createPDF( relatorio.getId(), false );
if( relatorioPDF != null )
{
String data = relatorio.getToHsMarcacoesEstabelecimento().getDataRelatorio() == null ? "" : relatorio.getData().toString();
String estabelecimento = relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNomePlain();
String data = relatorio.getToHsMarcacoesEstabelecimento().getDataRelatorio() == null ? "" : HsRelatorio.DATE_FORMAT.format( relatorio.getData().toString() );
String estabelecimento = getShortNameForEstabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos());
File relat = File.createTempFile("Relatorio - " + estabelecimento + " - " + data, ".pdf");
if( relat != null )
{

@ -13,9 +13,6 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
@ -29,7 +26,6 @@ import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
@ -47,7 +43,6 @@ import com.evolute.utils.images.ImageIconLoader;
import com.evolute.utils.tables.BaseTable;
import com.evolute.utils.tables.VectorTableModel;
import com.evolute.utils.ui.CustomJDialog;
import com.evolute.utils.ui.DialogException;
public class MailDialog extends CustomJDialog
{
@ -69,50 +64,52 @@ public class MailDialog extends CustomJDialog
protected Action removeAttachmentAction;
public static void main( String args[] )
throws Exception
{
MailDialog mailDialog = new MailDialog( null );
mailDialog.setTo( "fredPalma@netcabo.pt" );
mailDialog.setBcc( "fpalma@evolute.pt" );
mailDialog.setSubject( "SIPRP - Marca\u00E7\u00E3o de consulta de 'Frederico Palma'" );
mailDialog.setMessage(
"<p>"
+ "<font size=\"3\" face=\"Arial\">Vimos pelo presente informar que 'Frederico Palma' dever&#xe1; comparecer "
+ "nas nossas instala&#xe7;&#xf5;es para a realiza&#xe7;&#xe3;o da consulta de Medicina "
+ "do Trabalho, no dia '<b>10-01-2008</b>', pelas <b>08H30</b>. </font>"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">Solicitamos, tamb&#xe9;m, que o colaborador seja portador do <b>Boletim de Vacinas</b> e "
+ "dos <b>&#xfa;ltimos exames complementares</b> realizados.</font>"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">Caso n&#xe3;o seja poss&#xed;vel a compar&#xea;ncia deste colaborador na data "
+ "indicada, contacte-nos, por favor, atrav&#xe9;s do telefone 21 350 45 40 "
+ "ou respondendo ao remetente desta mensagem.</font>"
+ "</p><p></p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">Cumprimentos,</font>"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">SIPRP</font>"
// color=\"#497895\"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">ATRIUM SALDANHA</font>"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">Pra&#xe7;a Duque de Saldanha, 1 - 9&#xba;G</font>"
+ "</p>"
+ "<p>"
+ "<font size=\"3\" face=\"Arial\">1050-094 Lisboa"
+ "</p>" );
mailDialog.setSize( 1024, 768 );
mailDialog.setVisible( true );
System.exit( 0 );
}
public MailDialog( JFrame owner, String to, String bcc, String subject, String message, Vector<File> files )
private boolean sent = false;
//
// public static void main( String args[] )
// throws Exception
// {
// MailDialog mailDialog = new MailDialog( null );
// mailDialog.setTo( "fredPalma@netcabo.pt" );
// mailDialog.setBcc( "fpalma@evolute.pt" );
// mailDialog.setSubject( "SIPRP - Marca\u00E7\u00E3o de consulta de 'Frederico Palma'" );
// mailDialog.setMessage(
// "<p>"
// + "<font size=\"3\" face=\"Arial\">Vimos pelo presente informar que 'Frederico Palma' dever&#xe1; comparecer "
// + "nas nossas instala&#xe7;&#xf5;es para a realiza&#xe7;&#xe3;o da consulta de Medicina "
// + "do Trabalho, no dia '<b>10-01-2008</b>', pelas <b>08H30</b>. </font>"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">Solicitamos, tamb&#xe9;m, que o colaborador seja portador do <b>Boletim de Vacinas</b> e "
// + "dos <b>&#xfa;ltimos exames complementares</b> realizados.</font>"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">Caso n&#xe3;o seja poss&#xed;vel a compar&#xea;ncia deste colaborador na data "
// + "indicada, contacte-nos, por favor, atrav&#xe9;s do telefone 21 350 45 40 "
// + "ou respondendo ao remetente desta mensagem.</font>"
// + "</p><p></p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">Cumprimentos,</font>"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">SIPRP</font>"
//// color=\"#497895\"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">ATRIUM SALDANHA</font>"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">Pra&#xe7;a Duque de Saldanha, 1 - 9&#xba;G</font>"
// + "</p>"
// + "<p>"
// + "<font size=\"3\" face=\"Arial\">1050-094 Lisboa"
// + "</p>" );
// mailDialog.setSize( 1024, 768 );
// mailDialog.setVisible( true );
// System.exit( 0 );
// }
public MailDialog( JFrame owner, String to, String bcc, String subject, String message, Vector<File> files)
throws Exception
{
super( owner, true );
@ -128,16 +125,16 @@ public class MailDialog extends CustomJDialog
setVisible( true );
}
public MailDialog( JFrame owner )
throws Exception
{
super( owner, true );
this.owner = owner;
commonStartup();
setModal( true );
setSize( 1024, 768 );
setVisible( true );
}
// public MailDialog( JFrame owner )
// throws Exception
// {
// super( owner, true );
// this.owner = owner;
// commonStartup();
// setModal( true );
// setSize( 1024, 768 );
// setVisible( true );
// }
private void commonStartup()
throws Exception
@ -581,6 +578,7 @@ public class MailDialog extends CustomJDialog
try
{
sender.send( to, bcc, subject, body, attachmentList, attachments );
sent = true;
}
catch( Exception ex )
{
@ -588,6 +586,11 @@ public class MailDialog extends CustomJDialog
}
}
public boolean wasSent()
{
return sent;
}
public void close()
{
SwingUtilities.invokeLater( new Runnable(){

@ -22,7 +22,7 @@ public class BaseObject extends CayenneDataObject implements Comparable<BaseObje
protected static MainDAO dao = new MainDAO();
protected static final DateFormat sdf = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) );
public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) );
protected static final String isNewMessage = " ";

@ -10,7 +10,7 @@ public class MarcacoesEstabelecimento extends _MarcacoesEstabelecimento
@Override
public String toString()
{
return sdf.format( getData() );
return DATE_FORMAT.format( getData() );
}
@Override

@ -16,7 +16,7 @@ public class Trabalhadores extends _Trabalhadores
public String getDataNascimentoString()
{
return getDataNascimento() == null ? "" : sdf.format( getDataNascimento() );
return getDataNascimento() == null ? "" : DATE_FORMAT.format( getDataNascimento() );
}
@Override

@ -15,7 +15,7 @@ public class TrabalhadoresConsultas extends _TrabalhadoresConsultas implements M
public String getDataString()
{
return getData() == null ? "(sem data definida)" : sdf.format( getData() );
return getData() == null ? "(sem data definida)" : DATE_FORMAT.format( getData() );
}
@Override

@ -12,7 +12,7 @@ public class TrabalhadoresConsultasDatas extends _TrabalhadoresConsultasDatas im
public String getDataString()
{
return getData() == null ? "" : sdf.format( getData() );
return getData() == null ? "" : DATE_FORMAT.format( getData() );
}
public String getEstadoString()

@ -7,7 +7,7 @@ public class TrabalhadoresConsultasDatasEmails extends _TrabalhadoresConsultasDa
public String getDataString()
{
return getData() == null ? "" : sdf.format( getData() );
return getData() == null ? "" : DATE_FORMAT.format( getData() );
}
@Override

@ -14,7 +14,7 @@ public class TrabalhadoresEcds extends _TrabalhadoresEcds implements MedicinaCon
public String getDataString()
{
return getData() == null ? "(sem data definida)" : sdf.format( getData() );
return getData() == null ? "(sem data definida)" : DATE_FORMAT.format( getData() );
}
public String getEstadoString()

@ -15,7 +15,7 @@ public class TrabalhadoresEcdsDatas extends _TrabalhadoresEcdsDatas implements M
public String getDataString()
{
return getData() == null ? "" : sdf.format( getData() );
return getData() == null ? "" : DATE_FORMAT.format( getData() );
}
public String getEstadoString()

@ -7,7 +7,7 @@ public class TrabalhadoresEcdsDatasEmails extends _TrabalhadoresEcdsDatasEmails
public String getDataString()
{
return getData() == null ? "" : sdf.format( getData() );
return getData() == null ? "" : DATE_FORMAT.format( getData() );
}
@Override

@ -17,7 +17,7 @@ public class TrabalhadoresFichasAptidao extends _TrabalhadoresFichasAptidao {
Date data = exame.getProximoExame();
if( data != null )
{
result = sdf.format( data );
result = DATE_FORMAT.format( data );
}
}
return result + ": " + getEstadoString();

@ -33,7 +33,7 @@ public class TrabalhadoresProcesso extends _TrabalhadoresProcesso implements Pro
private String getDataInicioString()
{
return getDataInicio() == null ? "" : sdf.format( getDataInicio() );
return getDataInicio() == null ? "" : DATE_FORMAT.format( getDataInicio() );
}
@Override

Loading…
Cancel
Save