/* * frameFacture.java * * Created on 8 septembre 2007, 08:39 */ package fr.vcube.factologo.facture; import java.sql.ResultSet; import java.util.Date; import javax.swing.DefaultListModel; import javax.swing.JFrame; import fr.vcube.factologo.facture.framePointage; import fr.vcube.factologo.util.Bdd; import fr.vcube.factologo.util.Format; import fr.vcube.factologo.util.GestionFichiers; import fr.vcube.factologo.facture.Facture; /** * * @author Alex */ public class frameFacture extends javax.swing.JFrame { private JFrame parent; /** Creates new form frameFacture */ public frameFacture (JFrame pere) { this.parent = pere; initComponents (); initialiseListe(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); listFactures = new javax.swing.JList(); btnFermer = new javax.swing.JButton(); btnOuvrir = new javax.swing.JButton(); btnImprimer = new javax.swing.JButton(); btnPointage = new javax.swing.JButton(); btnAnnuler = new javax.swing.JButton(); btnReset = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Consultation des factures \u00e9dit\u00e9es"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent evt) { formWindowClosed(evt); } }); listFactures.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { listFacturesValueChanged(evt); } }); jScrollPane1.setViewportView(listFactures); btnFermer.setText("Fermer"); btnFermer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFermerActionPerformed(evt); } }); btnOuvrir.setText("Ouvrir la facture"); btnOuvrir.setEnabled(false); btnOuvrir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnOuvrirActionPerformed(evt); } }); btnImprimer.setText("Imprimer la facture"); btnImprimer.setEnabled(false); btnImprimer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnImprimerActionPerformed(evt); } }); btnPointage.setText("Pointer mon salaire"); btnPointage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPointageActionPerformed(evt); } }); btnAnnuler.setText("Supprimer la facture"); btnAnnuler.setEnabled(false); btnAnnuler.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAnnulerActionPerformed(evt); } }); btnReset.setText("Tout d\u00e9selectionner"); btnReset.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnResetActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(btnReset, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, btnFermer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, btnOuvrir, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, btnImprimer, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, btnPointage, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, btnAnnuler, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(btnOuvrir) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnImprimer) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnAnnuler) .add(9, 9, 9) .add(btnPointage) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 46, Short.MAX_VALUE) .add(btnReset) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnFermer))) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void btnResetActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed this.initialiseListe (); }//GEN-LAST:event_btnResetActionPerformed private void btnAnnulerActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnnulerActionPerformed Object selection = this.listFactures.getSelectedValue (); //Object selection = this.listeFactures.getSelectedValue (); ComposantFacture cf = (ComposantFacture) selection; int idF = cf.getIdFacture (); Facture fact = new Facture(idF); fact.supprimer (); //this.listFactures.removeAll (); this.listFactures.removeAll (); this.initialiseListe (); }//GEN-LAST:event_btnAnnulerActionPerformed private void btnPointageActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPointageActionPerformed framePointage fen = new framePointage(this); fen.setVisible (true); this.setVisible (false); }//GEN-LAST:event_btnPointageActionPerformed private void formWindowClosed (java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed this.parent.setVisible (true); }//GEN-LAST:event_formWindowClosed private void btnOuvrirActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOuvrirActionPerformed Object[] selection = this.listFactures.getSelectedValues (); //Object[] selection = this.listeFactures.getSelectedValues (); for (Object o:selection) { ComposantFacture f = (ComposantFacture) o; GestionFichiers.ouvrePdf (f.getTitreFichier ()); } //ComposantFacture f = (ComposantFacture) this.listFactures.getSelectedValue (); //GestionFichiers.ouvrePdf (f.getTitreFichier ()); this.setExtendedState (frameFacture.ICONIFIED); }//GEN-LAST:event_btnOuvrirActionPerformed private void btnImprimerActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimerActionPerformed Object[] selection = this.listFactures.getSelectedValues (); for (Object o:selection) { ComposantFacture f = (ComposantFacture) o; GestionFichiers.imprimePdf (f.getTitreFichier ()); } }//GEN-LAST:event_btnImprimerActionPerformed private void listFacturesValueChanged (javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listFacturesValueChanged Object[] selection = this.listFactures.getSelectedValues (); int nbSel = selection.length; //javax.swing.JOptionPane.showMessageDialog(this, nbSel + " facture sélectionnée", nbSel + " facture sélectionnée", javax.swing.JOptionPane.WARNING_MESSAGE); if (nbSel<1) { this.btnOuvrir.setEnabled (false); this.btnImprimer.setEnabled (false); this.btnAnnuler.setEnabled (false); } else { this.btnAnnuler.setEnabled (true); //this.btnOuvrir.setEnabled (true); //this.btnImprimer.setEnabled (true); boolean existe = true; boolean imprimable = true; for (Object o:selection) { ComposantFacture f = (ComposantFacture) o; String titre = f.getTitreFichier (); if (!GestionFichiers.existe (titre)) { existe = false; javax.swing.JOptionPane.showMessageDialog(this, "Le fichier " + titre + " n'existe pas", "Le fichier " + titre + " n'existe pas", javax.swing.JOptionPane.WARNING_MESSAGE); } if (!GestionFichiers.estImprimable (titre)) { imprimable = false; } } this.btnOuvrir.setEnabled (existe); this.btnImprimer.setEnabled (imprimable); /*ComposantFacture f = (ComposantFacture) selection; this.btnOuvrir.setEnabled (GestionFichiers.existe (f.getTitreFichier ())); this.btnImprimer.setEnabled (GestionFichiers.estImprimable (f.getTitreFichier ()));*/ } }//GEN-LAST:event_listFacturesValueChanged private void btnFermerActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFermerActionPerformed this.dispose (); }//GEN-LAST:event_btnFermerActionPerformed /** * @param args the command line arguments */ /*public static void main (String args[]) { java.awt.EventQueue.invokeLater (new Runnable () { public void run () { new frameFacture ().setVisible (true); } }); }*/ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAnnuler; private javax.swing.JButton btnFermer; private javax.swing.JButton btnImprimer; private javax.swing.JButton btnOuvrir; private javax.swing.JButton btnPointage; private javax.swing.JButton btnReset; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JList listFactures; // End of variables declaration//GEN-END:variables private void initialiseListe() { String titre = ""; int id = 0; Date d = new Date(); DefaultListModel liste = new DefaultListModel(); String rq = "SELECT id_facture, date_facture, titre FROM fl_facture ORDER BY date_facture DESC"; Bdd cnx = new Bdd(); ResultSet rs = cnx.requeteSelect (rq); try { rs.beforeFirst (); while (rs.next ()) { id = rs.getInt ("id_facture"); titre = rs.getString ("titre"); d = rs.getDate ("date_facture"); liste.addElement (new ComposantFacture(id, titre, d)); } } catch (Exception e) { e.printStackTrace (); } finally { this.listFactures.setModel (liste); //this.listeFactures.setModel (liste); } } private class ComposantFacture { private int idFacture; private String titreFichier; private Date dateFacture; private String libelle; public ComposantFacture (int id, String titre, Date date) { this.idFacture = id; this.dateFacture = date; this.titreFichier = titre; this.libelle = "Facture n°" + id + " du " +Format.date2Ch (date); } public Date getDateFacture () { return dateFacture; } public int getIdFacture () { return idFacture; } public String getTitreFichier () { return titreFichier; } public String toString() { return libelle; } } }