ETAT D'impression sous JAVA / ACCESS ??

Résolu
amine1234Z Messages postés 134 Date d'inscription samedi 26 mai 2007 Statut Membre Dernière intervention 31 mai 2010 - 19 mai 2008 à 01:21
hafedhaouni Messages postés 62 Date d'inscription jeudi 18 février 2010 Statut Membre Dernière intervention 16 février 2012 - 7 déc. 2008 à 22:47
Salut a tous

voila j'ai 2 table dans ma base de donnée ACCESS qui sont en relation:
Table Projet et Jury.
Je veux s'avoir s'il ya une possibilité de les afficher dans un etat sous JAVA bien sur
parcque je travail avec les Jtable et je l'ai imprime lorsqu'il sagit d'un seul Table mais dans ce cas j'ai les deux
je veux afficher dans un etat d'impression un projet par jury ou bien tous les projet avec les jury qui appartien a chaque projet
je me damande comment
quelq'un a une idée ?
MERCI

% Mauvais Sens %

1 réponse

hafedhaouni Messages postés 62 Date d'inscription jeudi 18 février 2010 Statut Membre Dernière intervention 16 février 2012 1
7 déc. 2008 à 22:47
etape 1:
package rapport;


import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


import org.apache.poi.poifs.property.Parent;


import constant.Constant;


import main.JFGestionFacture;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.xml.JasperPrintFactory;
import net.sf.jasperreports.view.JasperViewer;


public class Rapport {
 public static final String LOGIN = "";


 public static final String PASSWORD = "";


 public static final String MODEL_PATH = "";


 public static final String FILE_PATH = "";


 public static void generer(String dns, String pdfExe, String login,


 String password, String modelPath, String modelName, String filePath,
   String fileName) throws ClassNotFoundException, SQLException,
   JRException, IOException {


  fileName = fileName;
  String url = "jdbc:odbc:" + dns;


  // - Connexion à la base
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection connection = DriverManager.getConnection(url, login,password);


  // - Chargement et compilation du rapport
  JasperDesign jasperDesign = JRXmlLoader.load(modelName);
  JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);


  // - Paramètres à envoyer au rapport
  Map parameters = new HashMap();
  parameters.put("Titre", "Titre");
  // parameters.put("NFacture", Facture.champs[0]);


  // - Execution du rapport
  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
    parameters, connection);
  JasperExportManager.exportReportToPdfFile(jasperPrint, fileName);


  ouvrir(pdfExe, filePath, fileName);
 }


 public static void ouvrir(String pdfExe, String filePath, String fileName)
   throws IOException {
  Runtime r = Runtime.getRuntime();
  String[] tabCmd;
  tabCmd = new String[2];
  tabCmd[0] = pdfExe;
  tabCmd[1] = fileName;


  Process p = r.exec(tabCmd);
 }


 public static void generer(String modelName, String fileName)
   throws ClassNotFoundException, SQLException, JRException,
   IOException {
  generer(Constant.DNS, Constant.PDF_EXE, LOGIN, PASSWORD, MODEL_PATH,
    modelName, FILE_PATH, fileName);
 }


/* public static void genererWord(String dns, String wordExe, String login,


 String password, String modelPath, String modelName, String filePath,
   String fileName) throws ClassNotFoundException, SQLException,
   JRException, IOException {
  fileName = fileName + ".doc";
  String url = "jdbc:odbc:" + dns;


  // - Connexion à la base
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection connection = DriverManager.getConnection(url, login,
    password);


  // - Chargement et compilation du rapport
  JasperDesign jasperDesign = JRXmlLoader.load(modelName);
  JasperReport jasperReport = JasperCompileManager
    .compileReport(jasperDesign);


  // - Paramètres à envoyer au rapport
  Map parameters = new HashMap();
  parameters.put("Titre", "Titre");
  // parameters.put("NFacture", parent        parentFacture.champs[0]);


  // - Execution du rapport
  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
    parameters, connection);
  JasperExportManager.exportReportToPdfFile(jasperPrint, fileName);


  ouvrirWord(wordExe, filePath, fileName);
 }


 public static void ouvrirWord(String wordExe, String filePath,
   String fileName) throws IOException {
  Runtime r = Runtime.getRuntime();
  String[] tabCmd;
  tabCmd = new String[2];
  tabCmd[0] = wordExe;
  tabCmd[1] = filePath + "\" + fileName;


  Process p = r.exec(tabCmd);
 }


 public static void genererWord(String modelName, String fileName)
   throws ClassNotFoundException, SQLException, JRException,
   IOException {
   genererWord(DNS,WORD_EXE,LOGIN,PASSWORD,MODEL_PATH,modelName,FILE_PATH,fileName);
 }


 public static void generer(String dns, String pdfExe, String login,


 String password, String modelPath, String modelName, String filePath,
   String fileName, ReportParameter[] tParam)
   throws ClassNotFoundException, SQLException, JRException,
   IOException {


  fileName = fileName;
  String url = "jdbc:odbc:" + dns;


  // - Connexion à la base
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection connection = DriverManager.getConnection(url, login,
    password);


  // - Chargement et compilation du rapport
  JasperDesign jasperDesign = JRXmlLoader.load(modelName);
  JasperReport jasperReport = JasperCompileManager
    .compileReport(jasperDesign);


  // - Paramètres à envoyer au rapport
  Map parameters = new HashMap();
  parameters.put("Titre", "Titre");
  for (int i = 0; i < tParam.length; i++)
   parameters.put(tParam[i].getName(), tParam[i].getValue());


  // - Execution du rapport
  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
    parameters, connection);
  JasperExportManager.exportReportToPdfFile(jasperPrint, fileName);


  ouvrir(pdfExe, filePath, fileName);
 }


 public static void generer(String modelName, String fileName,
   ReportParameter[] tParam) throws ClassNotFoundException,
   SQLException, JRException, IOException {
  generer(Constant.DNS, Constant.PDF_EXE, LOGIN, PASSWORD, MODEL_PATH,
    modelName, FILE_PATH, fileName, tParam);
 }*/


}
etape 2
package etat;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.sql.SQLException;


import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;


import main.JFGestionFacture;
import net.sf.jasperreports.engine.JRException;
import rapport.Rapport;
import constant.Constant;
import data.gen.Record;
import data.gen.Table;
import erreur.Erreur;


public class JIFEtat extends JInternalFrame {


 private JPanel jContentPane = null;


 private JPanel jPanel = null;


 private JPanel jPanel1 = null;


 private JButton jButtonValider = null;


 private JButton jButtonAnnuler = null;


 private JLabel jLabel = null;


 private DefaultListModel lModel;


 private JScrollPane jScrollPane = null;


 private JList jListEtat = null;


 private void init() {
  this.setTitle(Constant.TABLE_ETAT);
  lModel = new DefaultListModel();
  Table tab = new Table(Constant.TABLE_ETAT, Constant.TABLE_ETAT_KEY_NB,
    0);
  tab.remplirModel(lModel);
  jListEtat.setModel(lModel);
 }


 private void quitter() {
  this.dispose();
 }


 /**
  * This is the xxx default constructor
  */
 public JIFEtat() {
  super();
  initialize();
 }


 /**
  * This method initializes this
  *
  * @return void
  */
 protected void initialize() {
  // super.initialize();
  this.setSize(383, 576);
  this.setMaximizable(true);
  this.setIconifiable(true);
  this.setResizable(true);
  this.setBackground(SystemColor.controlLtHighlight);
  this.setContentPane(getJContentPane());
  init();
 }


 public void valider() throws SQLException, ClassNotFoundException, JRException, IOException {
  if (jListEtat.getSelectedIndex() >= 0) {
   String name;
   String model;
   model = (String) ((Record) jListEtat.getSelectedValue())
     .getValue(1);
   name = (String) ((Record) jListEtat.getSelectedValue()).getValue(2);
   Rapport.generer(model, name);
  }
 }


 /**
  * This method initializes jContentPane
  *
  * @return javax.swing.JPanel
  */
 private JPanel getJContentPane() {
  if (jContentPane == null) {
   jContentPane = new JPanel();
   jContentPane.setLayout(new BorderLayout());
   jContentPane.setBackground(SystemColor.controlLtHighlight);
   jContentPane.add(getJPanel(), BorderLayout.SOUTH);
   jContentPane.add(getJPanel1(), BorderLayout.NORTH);
   jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
  }
  return jContentPane;
 }


 /**
  * This method initializes jPanel
  *
  * @return javax.swing.JPanel
  */
 private JPanel getJPanel() {
  if (jPanel == null) {
   jPanel = new JPanel();
   jPanel.setLayout(new FlowLayout());
   jPanel.setBackground(SystemColor.controlLtHighlight);
   jPanel.setBorder(BorderFactory.createTitledBorder(null, "",
     TitledBorder.DEFAULT_JUSTIFICATION,
     TitledBorder.DEFAULT_POSITION, new Font("Dialog",
       Font.BOLD, 12), new Color(51, 51, 51)));
   jPanel.add(getJButtonValider(), null);
   jPanel.add(getJButtonAnnuler(), null);
  }
  return jPanel;
 }


 /**
  * This method initializes jPanel1
  *
  * @return javax.swing.JPanel
  */
 private JPanel getJPanel1() {
  if (jPanel1 == null) {
   jLabel = new JLabel();
   jLabel.setText("Sélectionnez un état");
   jLabel.setFont(new Font("Times New Roman", Font.BOLD, 14));
   jPanel1 = new JPanel();
   jPanel1.setLayout(new BorderLayout());
   jPanel1.setBackground(SystemColor.controlLtHighlight);
   jPanel1.add(jLabel, BorderLayout.WEST);


  }
  return jPanel1;
 }


 /**
  * This method initializes jButtonValider
  *
  * @return javax.swing.JButton
  */
 private JButton getJButtonValider() {
  if (jButtonValider == null) {
   jButtonValider = new JButton();
   jButtonValider.setText("Imprimer");
   jButtonValider.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent e) {
     try {
      valider();
     } catch (SQLException e1) {
      // TODO Auto-generated catch block
      Erreur.print(e1.toString());
     } catch (ClassNotFoundException e1) {
      // TODO Auto-generated catch block
      Erreur.print(e1.toString());
     } catch (JRException e1) {
      // TODO Auto-generated catch block
      Erreur.print(e1.toString());
     } catch (IOException e1) {
      // TODO Auto-generated catch block
      Erreur.print(e1.toString());
     }
    }
   });
  }
  return jButtonValider;
 }


 /**
  * This method initializes jButtonAnnuler
  *
  * @return javax.swing.JButton
  */
 private JButton getJButtonAnnuler() {
  if (jButtonAnnuler == null) {
   jButtonAnnuler = new JButton();
   jButtonAnnuler.setText("Fermer");
   jButtonAnnuler.setMnemonic(KeyEvent.VK_X);
   jButtonAnnuler
     .addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent e) {
       quitter();
       JFGestionFacture.jMenu.setEnabled(true);
       JFGestionFacture.jMenuAide.setEnabled(true);
       JFGestionFacture.jMenuConsultation.setEnabled(true);
       JFGestionFacture.jMenuFichier.setEnabled(true);
       JFGestionFacture.jMenuGestion.setEnabled(true);
      }
     });
  }
  return jButtonAnnuler;
 }


 /**
  * This method initializes jScrollPane
  *
  * @return javax.swing.JScrollPane
  */
 private JScrollPane getJScrollPane() {
  if (jScrollPane == null) {
   jScrollPane = new JScrollPane();
   jScrollPane.setViewportView(getJListEtat());
  }
  return jScrollPane;
 }


 /**
  * This method initializes jListEtat
  *
  * @return javax.swing.JList
  */
 private JList getJListEtat() {
  if (jListEtat == null) {
   jListEtat = new JList();
   jListEtat.setForeground(SystemColor.activeCaption);
   jListEtat.setFont(new Font("Engravers MT", Font.BOLD, 14));
   jListEtat.setFont(new Font("Copperplate Gothic Light", Font.PLAIN, 18));
   jListEtat.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent e) {
     if (e.getClickCount() == 2)
      try {
       valider();
      } catch (Exception e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
      }
    }
   });
  }
  return jListEtat;
 }


} //  @jve:decl-index=0:visual-constraint="10,10"
etape 3
crée une table etat dans l'access etat(code, XMLFile, PdfFile)
XMLFile et PdfFile: porte l@ ou enregistrer les table.
remarque: en java il faut creé l'intrface sous iReport puis suivis les etape 1, 2,3
il est bien testé
3
Rejoignez-nous