private void Add_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Add_ButtonActionPerformed

        Panel_Ajouter panajout = new Panel_Ajouter();
       
        

        Deal deal = new Deal();

        int result = JOptionPane.showConfirmDialog(null, panajout, "Test",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

        if (result == JOptionPane.OK_OPTION) {
            deal.setTitreDeal_Deal(panajout.txtTitre.getText());
            Vendeur vendeur = new Vendeur();
            VendeurDAO daov = VendeurDAO.getInstance();
            
            for (Vendeur a : daov.displayvendeurByNom(String.valueOf(panajout.jList1.getSelectedValue()))) {
                vendeur = a;
            }
            if(panajout.jList1.getSelectedValue()==null){
                vendeur.setIdVendeur(0);}
                
            deal.setDescDeal_Deal(panajout.txtDesc.getText());
            deal.setPrixDeal_Deal(Double.valueOf(panajout.txtPrix.getText()));
            deal.setNbrAchatValidation(Integer.valueOf(panajout.txtValidation.getText()));
            deal.setNbrAchatActuelDeal_Deal(0);
            deal.setNbrAffichage_Deal(0);
            deal.setEtatDeal_Deal("Comming");
            deal.setCategorie_Deal(panajout.ComboCategorie.getSelectedItem().toString());
            deal.setStatutDeal_Deal(false);
            java.util.Date d1 = panajout.jdateDebut.getCalendar().getTime();
            java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
            java.util.Date d2 = panajout.jdateFin.getCalendar().getTime();
            java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime());
            if(d1.after(d2)){
                JOptionPane.showMessageDialog(null, "les Dates sont non compatibles");
            } else {
            deal.setDateDebutDeal_Deal(sqlDate);
            deal.setDateFinDeal_Deal(sqlDate2);
            deal.setIdVendeur_Deal(vendeur.getIdVendeur());
            DealDAO dealdao = DealDAO.getInstance();

            dealdao.insertDeal(deal);
            Deal dd = dealdao.displayDeal().get((dealdao.displayDeal().size()-1));
           y=dd.getIdDeal_Deal();
           System.out.println(y);
            if( panajout.fc.getSelectedFiles().length!=0){
            for (int i = 0; i < panajout.fc.getSelectedFiles().length; i++) {
              
                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(panajout.file[i]);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                }

                ImageDeal imgdeal = new ImageDeal();
                Path path = Paths.get(panajout.file[i].getAbsolutePath());
                try {
                    imgdeal.setImage(Files.readAllBytes(path));
           

                } catch (IOException ex) {
                    Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                imgdeal.setIdDeal(y);
               
                ImageDAO im = ImageDAO.getInstance();
                im.InsertImage(imgdeal);
              
            }
            }
           
            JOptionPane.showMessageDialog(null, "Ajout terminé");
            DealTableModel mymodel = new DealTableModel(list.displayDeal());
            jTable1.setModel(mymodel);
            jTable1.removeColumn(jTable1.getColumn("ID"));
            jTable1.removeColumn(jTable1.getColumn("Description"));
            jTable1.removeColumn(jTable1.getColumn("Achat Actuel"));
            jTable1.removeColumn(jTable1.getColumn("Etat"));
            jTable1.removeColumn(jTable1.getColumn("Statut"));
            jTable1.removeColumn(jTable1.getColumn("Nombre d'Affichage"));
            jTable1.removeColumn(jTable1.getColumn("Vendeur"));

            jTable1.getColumnModel().setColumnMargin(20);
            jTable1.setRowSelectionInterval(0, 0);
            y = mymodel.getRowCount();
            panajout.w = y;
            System.out.println("la valeur de y est :" + y + "et " + panajout.w);
            }
        } else {
            System.out.println("Cancelled");
        }

    }//GEN-LAST:event_Add_ButtonActionPerformed