1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Etat;
// <editor-fold defaultstate="collapsed" desc="Importations">
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
// </editor-fold>
/**
*
* @author Viranson
*/
public class CompilationExportationJT2 {
/**
*Compile le modèle de rapport généré par
* le iReport. Ce fichier au format ".jrxml"
* est compilé pour générer un autre fichier
* au format ".jasper"; ce dernier est à son
* tour traité pour obtenir un fichier au format
* ".jrprint" près pour l'exportation.
* @param <NomRapport> Chaine représentant le nom
* court du fichier modèle au format ".jrxml"
* @param <Periode> Chaine représentant la période
* sur laquelle le rapport a été généré.
* @param <IdPeriode> entier représentant l'Id de la
* période d'exercice
*/
// <editor-fold defaultstate="collapsed" desc="Compilation du Rapport">
public void CompilerRapport (String NomRapport, int numerocaisse,String tipe,String d_debut,
String d_fin, String datedebut, String datefin, String libellecaisse, int total, int solde)//,String datedebut, String datefin, String type
{
try {
String pilote = "com.mysql.jdbc.Driver";
// String url = "jdbc:mysql://localhost:3306/ges_caisse" ;
// String user = "root";
// String password = "";
String url = "jdbc:mysql://192.168.1.160:3306/ges_caisse" ;
String user = "gescaisse";
String password = "Belmars1";
Connection con ;
Class.forName(pilote);
con = DriverManager.getConnection(url, user, password);
Map parameters = new HashMap();
parameters.put("numerocaisse", numerocaisse);
parameters.put("tipe", tipe);
parameters.put("d_debut", d_debut);
parameters.put("d_fin", d_fin);
parameters.put("datedebut", datedebut);
parameters.put("datefin", datefin);
parameters.put("libellecaisse", libellecaisse);
parameters.put("total", total);
parameters.put("solde", solde);
String Chemin = "src/Etat/";
JasperCompileManager.compileReportToFile(
Chemin+NomRapport+".jrxml");
JasperFillManager.fillReportToFile(Chemin+NomRapport+".jasper",
parameters, con);
con.close();
} catch (JRException ex) {
Logger.getLogger(CompilationExportationJT.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(CompilationExportationJT.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(CompilationExportationJT.class.getName()).log(Level.SEVERE, null, ex);
}
}// </editor-fold>
public static final String DossierRapports = "C:/Soft/app/";
/**
* Exporte le fichier rapport ".jrprint" au
* format ".pdf".
* @param <NomRapport> Chaine représentant le nom
* court du fichier modèle au format ".jrxml"
*/
// <editor-fold defaultstate="collapsed" desc="Exportation du Rapport en PDF">
public void Exporter(String NomRapport) throws IOException
{
Desktop d = Desktop.getDesktop();
String Chemin = "src/Etat/";
File Fichier = new File(Chemin + NomRapport + ".jrprint");
try
{
JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(Fichier);
JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
File Dossier = new File("C:/Soft/app/");
if (!Dossier.exists())
Dossier.mkdirs();
pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
DossierRapports + NomRapport + ".pdf");
//System.out.println("Exportation en cours...");
pdfExporter.exportReport();
//System.out.println("Exportation Réussie!");
if (Fichier.exists())
Fichier.delete();
File Jasper = new File(Chemin + NomRapport + ".jasper");
if (Jasper.exists())
Jasper.delete();
File PDF = new File(DossierRapports + NomRapport +
".pdf");
if (PDF.exists())
{
d.open(PDF);
d.print(PDF);
}
}
catch (JRException e){
}
}// </editor-fold>
}
public void Impression (BilanPeriodique oBilanPeriodique)
{
try {
db=new Database();
db1 = new Database();
db.Ouverture();
db1.Ouverture();
tipe=oBilanPeriodique.getCb_typeOperation().getSelectedItem().toString();
libellecaisse=oBilanPeriodique.getLb_caisse().getText();
String d_debut = dateFormat.format(oBilanPeriodique.getDate_debut().getDate());
String d_fin = dateFormat.format(oBilanPeriodique.getDate_fin().getDate());
idcaisse=Integer.parseInt(oBilanPeriodique.getIdcaisse().getText());
String datedebut = dateFormatR.format(oBilanPeriodique.getDate_debut().getDate());
String datefin = dateFormatR.format(oBilanPeriodique.getDate_fin().getDate());
total = Integer.parseInt(oBilanPeriodique.getTxt_total().getText());
Requete="SELECT sum(montantOperation) FROM `operations` WHERE "
+ "`dateOperation`<'"+dateFormat.format(oBilanPeriodique.getDate_debut().getDate())+"'"
+ "AND `typeOperation`='ENCAISSEMENT' AND "
+ "`estEncaisser`='OUI' AND "
+ "`estSupprimer`='NON' AND "
+ "`estAutoriser`='OUI' AND "
+ "`estImprimer`='OUI' AND"
+ "`idcaisse`= '"+Integer.parseInt(oBilanPeriodique.getIdcaisse().getText())+"' ";
db.Requete(Requete);
Resultat=db.getRs();
if (Resultat.next())
{
montantEncaissement = Resultat.getInt(1);
}
Requete1="SELECT sum(montantOperation) FROM `operations` WHERE "
+ "`dateOperation`<'"+dateFormat.format(oBilanPeriodique.getDate_debut().getDate())+"' AND "
+ "`typeOperation`='DECAISSEMENT' AND "
+ "`estEncaisser`='OUI' AND "
+ "`estSupprimer`='NON' AND "
+ "`estAutoriser`='OUI' AND "
+ "`estImprimer`='OUI' AND "
+ "`idcaisse`= `idcaisse`= '"+Integer.parseInt(oBilanPeriodique.getIdcaisse().getText())+"' ";
db1.Requete(Requete1);
Resultat1=db1.getRs();
if (Resultat1.next())
{
montantDecaissement = Resultat1.getInt(1);
}
solde = montantEncaissement - montantDecaissement;
System.out.println(d_debut);
System.out.println(d_fin);
System.out.println(Integer.parseInt(oBilanPeriodique.getIdcaisse().getText()));
System.out.println(tipe);
System.out.println(solde);
System.out.println(libellecaisse);
System.out.println(montantTotale);
try {
int i =1;
comp = new CompilationExportationJT2();
comp.CompilerRapport("bilanperiodique",idcaisse,tipe,d_debut ,d_fin, datedebut, datefin, libellecaisse, total, solde);
comp.Exporter("bilanperiodique");
}
catch (IOException ex) {
Logger.getLogger(MethodeBilanPeriodique.class.getName()).log(Level.SEVERE, null, ex);
}
}
catch (SQLException ex) {
Logger.getLogger(MethodeBilanPeriodique.class.getName()).log(Level.SEVERE, null, ex);
}
} |
Partager