Somme des linges d'un tableau qui doit insser dans la dernier ligne de la table

Signaler
Messages postés
12
Date d'inscription
samedi 29 janvier 2011
Statut
Membre
Dernière intervention
7 mars 2020
-
Messages postés
12
Date d'inscription
samedi 29 janvier 2011
Statut
Membre
Dernière intervention
7 mars 2020
-
Bonjour,

1.Svp je n’arrive pas a calculer la somme des linge d'un tableau si vous pouvez m’aidé
2.j’ai trouvez une solution pour imprimer la table en format pdf mais le prb c’est que la table s’imprime en 2page j’ai pas pus fixer la taille de la table ?????
3.comment actualiser la table après une recherche ou suppression ?
3.comment programmer la modification d’un champs ou une ligne ?
merci
salutation
package brq1;

import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import java.awt.print.PrinterException;
import java.sql.*;

import java.sql.Statement;
import java.text.MessageFormat;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author CELLULE
 */
public class fenetre_BRQ extends javax.swing.JFrame {

    Statement stmtBRQ;
    Statement stmtCPT;
    connexionjm maConnexion = new connexionjm();
    DefaultTableModel model= new DefaultTableModel();
    DefaultTableModel model1= new DefaultTableModel();
/**
     * Creates new form fenetre_BRQ
     */
    public fenetre_BRQ() {
        initComponents();
         this.setLocationRelativeTo(null);
      
         
        model.addColumn("Date");
        model.addColumn("centre");
        model.addColumn("secteur");
        model.addColumn("Nbr-coup");
        model.addColumn("MontC");
        model.addColumn("Nbr-rem");
        model.addColumn("MontR");
        model.addColumn("Nbr-relc");
        model.addColumn("MontRlc");
        model.addColumn("Nbr-mdem");
        model.addColumn("MontM");
        model.addColumn("Nbr-br-illi");
        model.addColumn("MontBRI");
        model.addColumn("Eau");
        model.addColumn("Travaux");
        model.addColumn("Total");
        Tablebrq.setModel(model);
        Tablebrq.setAutoResizeMode(Tablebrq.AUTO_RESIZE_OFF);
        TableColumn col = Tablebrq.getColumnModel().getColumn(0);
        col.setPreferredWidth(80);
        col = Tablebrq.getColumnModel().getColumn(1);
        col.setPreferredWidth(140);
        col = Tablebrq.getColumnModel().getColumn(2);
        col.setPreferredWidth(145);
        col = Tablebrq.getColumnModel().getColumn(3);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(4);
        col.setPreferredWidth(60);
       col = Tablebrq.getColumnModel().getColumn(5);
        col.setPreferredWidth(65);
        col = Tablebrq.getColumnModel().getColumn(6);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(7);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(8);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(9);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(10);
        col.setPreferredWidth(70);
        col = Tablebrq.getColumnModel().getColumn(11);
        col.setPreferredWidth(50);
        col = Tablebrq.getColumnModel().getColumn(12);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(13);
        col.setPreferredWidth(60);
        col = Tablebrq.getColumnModel().getColumn(14);
        col.setPreferredWidth(50);
       col = Tablebrq.getColumnModel().getColumn(15);
        col.setPreferredWidth(50);
        /*col = Tablebrq.getColumnModel().getColumn(16);
        col.setPreferredWidth(50);*/
        
        DefaultTableModel model1= new DefaultTableModel();
        model1.addColumn("date");
        model1.addColumn("centre");
        model1.addColumn("secteur");
        model1.addColumn("Cum-enc");
        model1.addColumn("Obj");
        model1.addColumn("Taux");
        model1.addColumn("créance");
        model1.addColumn("dos-cont");
        model1.addColumn("Prise_nouv");
        model1.addColumn("Renov");
        model1.addColumn("Pose-cpt");
        model1.addColumn("CAT1");
        model1.addColumn("CAT2");
        model1.addColumn("CAT3");
        model1.addColumn("TRAV");
        model1.addColumn("TOTALR");
        Tablecpt.setModel(model1);
        Tablecpt.setAutoResizeMode(Tablebrq.AUTO_RESIZE_OFF);
        TableColumn colm = Tablecpt.getColumnModel().getColumn(0);
        colm.setPreferredWidth(80);
        colm = Tablecpt.getColumnModel().getColumn(1);
        colm.setPreferredWidth(140);
        colm = Tablecpt.getColumnModel().getColumn(2);
        colm.setPreferredWidth(145);
        colm = Tablecpt.getColumnModel().getColumn(3);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(4);
        colm.setPreferredWidth(60);
       colm = Tablecpt.getColumnModel().getColumn(5);
        colm.setPreferredWidth(65);
        colm = Tablecpt.getColumnModel().getColumn(6);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(7);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(8);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(9);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(10);
        colm.setPreferredWidth(70);
        colm = Tablecpt.getColumnModel().getColumn(11);
        colm.setPreferredWidth(50);
        colm = Tablecpt.getColumnModel().getColumn(12);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(13);
        colm.setPreferredWidth(60);
        colm = Tablecpt.getColumnModel().getColumn(14);
        colm.setPreferredWidth(50);
       colm = Tablecpt.getColumnModel().getColumn(15);
        colm.setPreferredWidth(50);

        String requettebrq = "select* from matable";
        String requettecpt = "select* from trait";
        try{
          stmtBRQ = maConnexion.ObtenirConnexion().createStatement();
          stmtCPT = maConnexion.ObtenirConnexion().createStatement();
            ResultSet resultat =stmtBRQ.executeQuery(requettebrq);            
            ResultSet resultat1 =stmtCPT.executeQuery(requettecpt);
            while(resultat.next()){
                  model.addRow(new Object[] {resultat.getString("Date"),resultat.getString("centre"),resultat.getString("secteur"),resultat.getString("Nbr_coup"),resultat.getString("Mont_coup"),resultat.getString("Nbr_rem"),resultat.getString("Mont_rem"),resultat.getString("Nbr_relc"),resultat.getString("Mont_relc"),resultat.getString("Nbr_mdem"),resultat.getString("Mont_mdem"),resultat.getString("Nbr_br_illi"),resultat.getString("Mont_br_illi"),resultat.getString("Eau"),resultat.getString("Travaux"),resultat.getString("Total")});
                             }
           while(resultat1.next()){
                   model1.addRow(new Object[] {resultat1.getString("Date"),resultat1.getString("centre"),resultat1.getString("secteur"),resultat1.getString("Cum_enc"),resultat1.getString("Obj"),resultat1.getString("Taux"),resultat1.getString("creance"),resultat1.getString("Nbr_dos_cont"),resultat1.getString("Nbr_dos_cont"),resultat1.getString("prise_nouv"),resultat1.getString("renov"),resultat1.getString("CAT1"),resultat1.getString("CAT2"),resultat1.getString("CAT3"),resultat1.getString("TRAV"),resultat1.getString("TOTALR")});
            } 
        }
        catch(SQLException ex){
        System.out.println("ex");
        }
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        modiffier = new javax.swing.JButton();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jComboBox1 = new javax.swing.JComboBox<>();
        jComboBox2 = new javax.swing.JComboBox<>();
        jButton1 = new javax.swing.JButton();
        Buttonsup = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        Tablecpt = new javax.swing.JTable();
        Actualiser = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tablebrq = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("TABLE BRQ");
        setSize(getMaximumSize());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Table BRQ");

        modiffier.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        modiffier.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/edit.png"))); // NOI18N
        modiffier.setText("Modiffier");
        modiffier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modiffierActionPerformed(evt);
            }
        });

        try {
            jFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Unité", "Centre Saida", "Centre AEH", "Centre Sidi Boubkeur" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jComboBox2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/binoculars.png"))); // NOI18N
        jButton1.setText("Recherche");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        Buttonsup.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        Buttonsup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/filled-trash.png"))); // NOI18N
        Buttonsup.setText("Supprimer");
        Buttonsup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonsupActionPerformed(evt);
            }
        });

        Tablecpt.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        Tablecpt.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablecptMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(Tablecpt);

        Actualiser.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        Actualiser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/folder-invoices.png"))); // NOI18N
        Actualiser.setText("Actualiser");
        Actualiser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActualiserActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icons8-couleur-48.png"))); // NOI18N
        jButton2.setText("Imprimer");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        Tablebrq.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(Tablebrq);

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButton3.setText("Calculer ");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(65, 65, 65)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(72, 72, 72))
            .addGroup(layout.createSequentialGroup()
                .addGap(370, 370, 370)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(581, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1131, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(modiffier)
                .addGap(29, 29, 29)
                .addComponent(Buttonsup)
                .addGap(18, 18, 18)
                .addComponent(Actualiser)
                .addGap(39, 39, 39)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(36, 36, 36))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(modiffier, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                            .addComponent(Buttonsup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Actualiser)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28))))
        );

        pack();
    }// </editor-fold>                        

    private void modiffierActionPerformed(java.awt.event.ActionEvent evt) {                                          

    }                                         

        



    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           

       String choisis = jComboBox1.getSelectedItem().toString();  // selectionner un choix
           if (choisis.equals("Unité")) {
                jComboBox2.removeAllItems(); 
            jComboBox2.addItem("Agence de Saida");
            jComboBox2.addItem("Agence de 5 Juuillet");
            jComboBox2.addItem("Secteur AEH");
            jComboBox2.addItem("Secteur Hssasna");
            jComboBox2.addItem("Secteur Balloul");
            jComboBox2.addItem("Secteur Sidi Boubkeur");
            jComboBox2.addItem("Secteur Youb");
            jComboBox2.addItem("Secteur Rebahia");

           }else if (choisis.equals("Centre Saida")) {
            jComboBox2.removeAllItems(); 
            jComboBox2.addItem("Agence de Saida");
            jComboBox2.addItem("Agence de 5 Juuillet");
        } else if (choisis.equals("Centre AEH")) {
             jComboBox2.removeAllItems(); 
            jComboBox2.addItem("Secteur AEH");
            jComboBox2.addItem("Secteur Hssasna");
            jComboBox2.addItem("Secteur Balloul");

        } else if (choisis.equals("Centre Sidi Boubkeur")) {
             jComboBox2.removeAllItems(); 
            jComboBox2.addItem("Secteur Sidi Boubkeur");
            jComboBox2.addItem("Secteur Youb");
            jComboBox2.addItem("Secteur Rebahia");

            // TODO add your handling code here:

        }  // TODO add your handling code here:
    }                                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   
    
        String date=jFormattedTextField1.getText().toString();
      
        String centre=jComboBox1.getSelectedItem().toString();
         
        String newDate = date.substring(6)+"-"+date.substring(3, 5)+"-"+date.substring(0, 2);
      
        String requetteselect ;
        String requetteselect1;
        
        String choisis = jComboBox1.getSelectedItem().toString(); 
        
        
         if (choisis.equals("Centre Saida")){
        requetteselect = "SELECT * FROM matable  WHERE centre='"+centre+"'and Date='"+newDate+"'"; 
        
       requetteselect1 ="SELECT * FROM trait  WHERE centre='"+centre+"'and Date='"+newDate+"'";
        try{
          stmtBRQ = maConnexion.ObtenirConnexion().createStatement();
          stmtCPT = maConnexion.ObtenirConnexion().createStatement();
            ResultSet resultat =stmtBRQ.executeQuery(requetteselect); 
            ResultSet resultat1 =stmtCPT.executeQuery(requetteselect1); 
           Tablebrq.setModel(DbUtils.resultSetToTableModel(resultat));
           Tablecpt.setModel(DbUtils.resultSetToTableModel(resultat1));
        }
        catch(SQLException ex){
        System.out.println("ex");
        }
               }else if(choisis.equals("Centre AEH")){
                   requetteselect = "SELECT * FROM matable  WHERE centre='"+centre+"'and Date='"+newDate+"'"; 
        
       requetteselect1 ="SELECT * FROM trait  WHERE centre='"+centre+"'and Date='"+newDate+"'";
        try{
          stmtBRQ = maConnexion.ObtenirConnexion().createStatement();
          stmtCPT = maConnexion.ObtenirConnexion().createStatement();
            ResultSet resultat =stmtBRQ.executeQuery(requetteselect); 
            ResultSet resultat1 =stmtCPT.executeQuery(requetteselect1); 
           Tablebrq.setModel(DbUtils.resultSetToTableModel(resultat));
           Tablecpt.setModel(DbUtils.resultSetToTableModel(resultat1));
        }
        catch(SQLException ex){
        System.out.println("ex");
        }
       }else if(choisis.equals("Centre Sidi Boubkeur")){
                
                   requetteselect = "SELECT * FROM matable  WHERE centre='"+centre+"'and Date='"+newDate+"'"; 
        
       requetteselect1 ="SELECT * FROM trait  WHERE centre='"+centre+"' and Date='"+newDate+"'";
        try{
          stmtBRQ = maConnexion.ObtenirConnexion().createStatement();
          stmtCPT = maConnexion.ObtenirConnexion().createStatement();
            ResultSet resultat =stmtBRQ.executeQuery(requetteselect); 
            ResultSet resultat1 =stmtCPT.executeQuery(requetteselect1); 
           Tablebrq.setModel(DbUtils.resultSetToTableModel(resultat));
           Tablecpt.setModel(DbUtils.resultSetToTableModel(resultat1));
        }
        catch(SQLException ex){
        System.out.println("ex");
        } 
      }else if(choisis.equals("Unité")){
                   requetteselect = "SELECT * FROM matable  WHERE  Date='"+newDate+"'"; 
        
       requetteselect1 ="SELECT * FROM trait  WHERE Date='"+newDate+"'";
        try{
          stmtBRQ = maConnexion.ObtenirConnexion().createStatement();
          stmtCPT = maConnexion.ObtenirConnexion().createStatement();
            ResultSet resultat =stmtBRQ.executeQuery(requetteselect); 
            ResultSet resultat1 =stmtCPT.executeQuery(requetteselect1); 
           Tablebrq.setModel(DbUtils.resultSetToTableModel(resultat));
           Tablecpt.setModel(DbUtils.resultSetToTableModel(resultat1));
        }
        catch(SQLException ex){
        System.out.println("ex");
        }
                     } 
          
    }                                        

    private void ButtonsupActionPerformed(java.awt.event.ActionEvent evt) {                                          
      
        try{
           int row = Tablebrq.getSelectedRow();
           int row1 = Tablecpt.getSelectedRow();
           System.out.println(Tablebrq.getValueAt(row, 0));
           System.out.println(Tablecpt.getValueAt(row1, 0));
           String requette="delete from matable where date= '"+Tablebrq.getValueAt(row, 0)+"' and centre = '"+Tablebrq.getValueAt(row, 1)+"'";
           String requette1="delete from matable where date= '"+Tablecpt.getValueAt(row1, 0)+"' and centre = '"+Tablecpt.getValueAt(row1, 1)+"'";
           stmtBRQ.executeUpdate(requette);
           stmtCPT.executeUpdate(requette1);
         
          JOptionPane.showMessageDialog(null, "Suppression avec succeé");
         
       }catch(SQLException e){
           System.out.println(e.getMessage());
       }
    }                                         

    private void TablecptMouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    private void ActualiserActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        MessageFormat header =new MessageFormat("Unité:Saida"
                
                + "          SUIVI QUOTIDIEN DE L'ACTIVITE COMMERCIALE             ");
        MessageFormat footer =new MessageFormat("C/Departement Commercial                                      Directeur de l'unité");
        try{
        Tablebrq.print (JTable.PrintMode.NORMAL, header, footer);
        
        }catch( java.awt.print.PrinterException e){
            System.err.format("can not print %s%n",e.getMessage());
               
        
        }
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 
    DefaultTableModel model1= new DefaultTableModel();
    Tablecpt.setModel(model1);
        int[] Tablecpt = new int[13]; 
         int Sum = 0; 

          for(int i = 4; i<13; i++) { 
          Sum += Tablecpt[i]; 
             } 
System.out.println(Sum); 

    }                                        
            

        
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(fenetre_BRQ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(fenetre_BRQ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(fenetre_BRQ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(fenetre_BRQ.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new fenetre_BRQ().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton Actualiser;
    private javax.swing.JButton Buttonsup;
    private javax.swing.JTable Tablebrq;
    private javax.swing.JTable Tablecpt;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox<String> jComboBox1;
    private javax.swing.JComboBox<String> jComboBox2;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton modiffier;
    // End of variables declaration                   
}

2 réponses

Messages postés
5350
Date d'inscription
dimanche 4 mai 2003
Statut
Modérateur
Dernière intervention
29 juin 2020
97
Salut,

Je n'ai pas regardé en détail le code, mais visiblement tu remplis ton jtable via ta bdd, du coup pourquoi ne pas faire cette somme directement via ta requête sql genre:
SELECT SUM(colX) sommeTotal FROM la_table;


Messages postés
12
Date d'inscription
samedi 29 janvier 2011
Statut
Membre
Dernière intervention
7 mars 2020

bonsoir
merci pour ta réponse
je veux calculer la somme de table après un filtrage par date et centre?
j'ai plusiers colnnes comment faire
selectsum('col1',col2',...'colx') somme totale From matable? ca nemarche pas?

et comment faire l'insertion de cet résultat a la dernier ligne de la table?



merci
Messages postés
12
Date d'inscription
samedi 29 janvier 2011
Statut
Membre
Dernière intervention
7 mars 2020

Bonjour,
comment faire l'insertion du résultat de somme a la dernière ligne de la table?
merci