pi.bestdeal.gui.InterfacePrincipale.java Source code

Java tutorial

Introduction

Here is the source code for pi.bestdeal.gui.InterfacePrincipale.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pi.bestdeal.gui;

import com.jtattoo.plaf.aluminium.AluminiumLookAndFeel;
import com.jtattoo.plaf.noire.NoireLookAndFeel;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.TableModel;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeriesCollection;
import pi.bestdeal.models.ClientTableModel;
import pi.bestdeal.dao.DealDAO;
import pi.bestdeal.dao.VendeurDAO;
import pi.bestdeal.entities.Deal;
import pi.bestdeal.entities.Vendeur;
import pi.bestdeal.models.DealTableModel;
import pi.bestdeal.models.DisplayClientTableModel;
import pi.bestdeal.models.Mail;
import pi.bestdeal.dao.ClientDAO;
import pi.bestdeal.dao.ConsultationDAO;
import pi.bestdeal.dao.ImageDAO;
import pi.bestdeal.dao.MessageDAO;
import pi.bestdeal.dao.ReservationDAO;
import pi.bestdeal.entities.Client;
import pi.bestdeal.entities.ClientMail;
import pi.bestdeal.entities.ImageDeal;
import pi.bestdeal.models.Charts;
import pi.bestdeal.utils.ReportCreator;

/**
 *
 * @author Internet
 */
public class InterfacePrincipale extends javax.swing.JFrame {

    public int x;
    public int y;
    DealDAO list = DealDAO.getInstance();
    List<Deal> deals = list.displayDeal();
    TableModel tableModel = new DealTableModel(deals);
    MessageDAO listmessage = MessageDAO.getInstance();
    List<ClientMail> clientmail = listmessage.displayMessageWithSenderMail();
    TableModel mailmodel = new ClientTableModel(clientmail);
    ClientDAO clinetdao = ClientDAO.getInstance();
    List<Client> clients = clinetdao.displayClient();
    TableModel clientmodel = new DisplayClientTableModel(clients);

    /**
     * Creates new form InterfacePrincipale
     */
    public InterfacePrincipale() {

        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
        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"));
        jTable3.removeColumn(jTable3.getColumn("ID"));
        jTable3.removeColumn(jTable3.getColumn("Description"));
        jTable3.removeColumn(jTable3.getColumn("Achat Actuel"));
        jTable3.removeColumn(jTable3.getColumn("Etat"));
        jTable3.removeColumn(jTable3.getColumn("Statut"));
        jTable3.removeColumn(jTable3.getColumn("Nombre d'Affichage"));
        jTable3.removeColumn(jTable3.getColumn("Vendeur"));
        jTableMessage.removeColumn(jTableMessage.getColumn("ID"));
        if (jTable3.getModel().getRowCount() != 0) {
            jTable3.setRowSelectionInterval(0, 0);
        }
        if (jTable1.getModel().getRowCount() != 0) {
            jTable1.setRowSelectionInterval(0, 0);
        }

    }

    /**
     * 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.
     */

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        Client_Panel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        Search_TextField = new javax.swing.JTextPane();
        Add_Button = new javax.swing.JButton();
        Update_Button = new javax.swing.JButton();
        Delete_Button = new javax.swing.JButton();
        Display_Button = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        GoToClientInterface = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        DeleteClient = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        Search_TextField1 = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        StatButton = new javax.swing.JButton();
        ButtonRapport = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        Search_TextField2 = new javax.swing.JTextPane();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTableMessage = new javax.swing.JTable();
        ReplyButton = new javax.swing.JButton();
        DeleteMessageButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("BesDeal");

        jTabbedPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTabbedPane1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTabbedPane1FocusGained(evt);
            }
        });

        Search_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                Search_TextFieldKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(Search_TextField);

        Add_Button.setText("Ajouter");
        Add_Button.setToolTipText("Ajouter un Nouveau Deal");
        Add_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Add_ButtonActionPerformed(evt);
            }
        });

        Update_Button.setText("Modifier");
        Update_Button.setToolTipText("Modifier le Deal slectionn");
        Update_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Update_ButtonActionPerformed(evt);
            }
        });

        Delete_Button.setText("Supprimer");
        Delete_Button.setToolTipText("Supprimer le deal slectionn");
        Delete_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Delete_ButtonActionPerformed(evt);
            }
        });

        Display_Button.setText("Afficher");
        Display_Button.setToolTipText("Afficher le Deal");
        Display_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Display_ButtonActionPerformed(evt);
            }
        });

        jTable1.setModel(tableModel);
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE));

        GoToClientInterface.setText("Espace Client");
        GoToClientInterface.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GoToClientInterfaceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout Client_PanelLayout = new javax.swing.GroupLayout(Client_Panel);
        Client_Panel.setLayout(Client_PanelLayout);
        Client_PanelLayout.setHorizontalGroup(Client_PanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(Client_PanelLayout.createSequentialGroup().addContainerGap().addGroup(Client_PanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(Client_PanelLayout.createSequentialGroup().addGap(12, 12, 12)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                Client_PanelLayout.createSequentialGroup().addComponent(Add_Button)
                                        .addGap(18, 18, 18).addComponent(Update_Button)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(GoToClientInterface, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(30, 30, 30).addComponent(Delete_Button).addGap(18, 18, 18)
                                        .addComponent(Display_Button)))
                        .addContainerGap()));
        Client_PanelLayout.setVerticalGroup(Client_PanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Client_PanelLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
                        .addGroup(Client_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(Add_Button).addComponent(Update_Button).addComponent(Delete_Button)
                                .addComponent(Display_Button))
                        .addGap(29, 29, 29))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        Client_PanelLayout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(GoToClientInterface).addContainerGap()));

        jTabbedPane1.addTab("Gestion des Deals", Client_Panel);

        jTable2.setModel(clientmodel);
        jScrollPane3.setViewportView(jTable2);

        DeleteClient.setText("Supprimer");
        DeleteClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteClientActionPerformed(evt);
            }
        });

        Search_TextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                Search_TextField1KeyReleased(evt);
            }
        });
        jScrollPane6.setViewportView(Search_TextField1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup().addGap(18, 18, 18)
                                                .addComponent(DeleteClient))
                                        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(
                                        jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 286,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                        .addComponent(DeleteClient)));

        jTabbedPane1.addTab("Gestion des Clients", jPanel2);

        jTable3.setModel(tableModel);
        jTable3.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTable3PropertyChange(evt);
            }
        });
        jScrollPane5.setViewportView(jTable3);

        StatButton.setText("Statistique");
        StatButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        ButtonRapport.setText("Rapport");
        ButtonRapport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonRapportActionPerformed(evt);
            }
        });

        Search_TextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                Search_TextField2KeyReleased(evt);
            }
        });
        jScrollPane7.setViewportView(Search_TextField2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane5,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addGap(20, 20, 20)
                                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(
                                jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(ButtonRapport)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(StatButton)))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ButtonRapport).addComponent(StatButton))
                        .addContainerGap(136, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Gnrer les Rapports", jPanel3);

        jTableMessage.setModel(mailmodel);
        jScrollPane4.setViewportView(jTableMessage);

        ReplyButton.setText("Rpondre");
        ReplyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReplyButtonActionPerformed(evt);
            }
        });

        DeleteMessageButton.setText("Supprimer");
        DeleteMessageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteMessageButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addGroup(jPanel4Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createSequentialGroup().addComponent(ReplyButton)
                                .addGap(292, 292, 292).addComponent(DeleteMessageButton)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ReplyButton).addComponent(DeleteMessageButton))
                        .addGap(8, 8, 8)));

        jTabbedPane1.addTab("Consulter les Messages", jPanel4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    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

    private void Update_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Update_ButtonActionPerformed
        DealDAO dealdao = DealDAO.getInstance();
        Modifier_Ajouter modaj = new Modifier_Ajouter();
        Deal abc = new Deal();
        Deal deal = new Deal();
        int idd = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
        List<Deal> listdeal = dealdao
                .displayDealById((int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0));
        for (Deal a : listdeal) {
            abc = a;
        }
        modaj.txtTitre.setText(abc.getTitreDeal_Deal());
        modaj.txtDesc.setText(abc.getDescDeal_Deal());
        modaj.txtPrix.setText(abc.getPrixDeal_Deal().toString());
        modaj.txtValidation.setText(String.valueOf(abc.getNbrAchatValidation()));
        modaj.jdateDebut.setDate(abc.getDateDebutDeal_Deal());
        modaj.jdateFin.setDate(abc.getDateFinDeal_Deal());
        if (abc.isStatutDeal() == true) {
            modaj.jCheckBox1.setSelected(true);
        } else {
            modaj.jCheckBox1.setSelected(false);
        }
        if (abc.getEtatDeal_Deal().toString().equals("Pass")) {
            modaj.jComboBox1.setSelectedIndex(0);
        }
        if (abc.getEtatDeal_Deal().toString().equals("Courant")) {
            modaj.jComboBox1.setSelectedIndex(1);
        }
        if (abc.getEtatDeal_Deal().toString().equals("Comming")) {
            modaj.jComboBox1.setSelectedIndex(2);
        }

        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("High-Tech")) {
            modaj.ComboCategorie.setSelectedIndex(0);
        }
        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Bricolage")) {
            modaj.ComboCategorie.setSelectedIndex(1);
        }
        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Bijouterie")) {
            modaj.ComboCategorie.setSelectedIndex(2);
        }
        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Vacances&Sorties")) {
            modaj.ComboCategorie.setSelectedIndex(3);
        }

        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Beaut")) {
            modaj.ComboCategorie.setSelectedIndex(4);
        }
        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Accessoires&Vtements")) {
            modaj.ComboCategorie.setSelectedIndex(5);
        }
        if (abc.getCategorie_Deal().toString().equalsIgnoreCase("Divers")) {
            modaj.ComboCategorie.setSelectedIndex(6);
        }
        abc.setEtatDeal_Deal(modaj.jComboBox1.getSelectedItem().toString());
        int result = JOptionPane.showConfirmDialog(null, modaj, "Test", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {

            deal.setTitreDeal_Deal(modaj.txtTitre.getText());
            Vendeur vendeur = new Vendeur();
            VendeurDAO daov = VendeurDAO.getInstance();
            for (Vendeur a : daov.displayvendeurByNom(modaj.jList1.getSelectedValue().toString())) {
                vendeur = a;
            }
            deal.setIdDeal_Deal(idd);
            deal.setDescDeal_Deal(modaj.txtDesc.getText());
            deal.setPrixDeal_Deal(Double.valueOf(modaj.txtPrix.getText()));
            deal.setNbrAchatValidation(Integer.valueOf(modaj.txtValidation.getText()));
            deal.setNbrAchatActuelDeal_Deal(0);
            deal.setNbrAffichage_Deal(0);
            deal.setEtatDeal_Deal(modaj.jComboBox1.getSelectedItem().toString());
            java.util.Date d1 = modaj.jdateDebut.getCalendar().getTime();
            java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
            java.util.Date d2 = modaj.jdateFin.getCalendar().getTime();
            java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime());
            deal.setDateDebutDeal_Deal(sqlDate);
            deal.setDateFinDeal_Deal(sqlDate2);
            deal.setCategorie_Deal(modaj.ComboCategorie.getSelectedItem().toString());

            deal.setIdVendeur_Deal(vendeur.getIdVendeur());
            if (modaj.jCheckBox1.isSelected()) {
                deal.setStatutDeal_Deal(true);
            } else {
                deal.setStatutDeal_Deal(false);
            }
            int f = dealdao.updateDeal(deal);
            if (f == 1) {
                JOptionPane.showMessageDialog(null, "Deal modifi");

                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);
                if (!list.displayDeal().isEmpty()) {
                    jTable1.setRowSelectionInterval(0, 0);
                }
            }
        } else {
            System.out.println("Cancelled");
        }

    }//GEN-LAST:event_Update_ButtonActionPerformed

    private void jTabbedPane1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTabbedPane1FocusGained

    }//GEN-LAST:event_jTabbedPane1FocusGained

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

        int result = JOptionPane.showConfirmDialog(null,
                "Voulez Vous Supprimer" + " ( "
                        + (String) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 1) + " ) ",
                null, JOptionPane.OK_CANCEL_OPTION);
        if (result == JOptionPane.OK_OPTION) {
            int idd = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
            DealDAO dealdao = DealDAO.getInstance();
            int a = dealdao.deleteDeal(idd);
            if (a == 1) {
                JOptionPane.showMessageDialog(null, "Deal Supprim");
                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);
                if (!list.displayDeal().isEmpty()) {
                    jTable1.setRowSelectionInterval(0, 0);
                }

            }
        }

    }//GEN-LAST:event_Delete_ButtonActionPerformed

    private void ReplyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReplyButtonActionPerformed
        Interface_Mail intmail = new Interface_Mail();
        intmail.txt_to.setText(jTableMessage.getModel().getValueAt(jTableMessage.getSelectedRow(), 2).toString());
        int result = JOptionPane.showConfirmDialog(null, intmail, "Test", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {
            Mail monmail = new Mail();
            if (intmail.txt_cc.getText().equals("")) {
                monmail.sendEmail(intmail.txt_to.getText(), intmail.txt_to.getText(), intmail.jTextField4.getText(),
                        intmail.txa_content.getText());
            } else {
                monmail.sendEmail(intmail.txt_to.getText(), intmail.txt_cc.getText(), intmail.jTextField4.getText(),
                        intmail.txa_content.getText());
            }
        }

    }//GEN-LAST:event_ReplyButtonActionPerformed

    private void Search_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Search_TextFieldKeyReleased
        List<Deal> recherche = new ArrayList<>();
        for (Deal a : list.displayDeal()) {
            if (a.getTitreDeal_Deal().toLowerCase().contains(this.Search_TextField.getText().toLowerCase())) {
                recherche.add(a);
            }

        }
        DealTableModel mymodel = new DealTableModel(recherche);
        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"));

        if (jTable1.getModel().getRowCount() != 0) {
            jTable1.setRowSelectionInterval(0, 0);
        }
    }//GEN-LAST:event_Search_TextFieldKeyReleased

    private void Display_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Display_ButtonActionPerformed
        DealDAO dealdao = DealDAO.getInstance();
        PanelAffichage panneauAffichage = new PanelAffichage();
        Affichage affichage = new Affichage();
        Deal abc = new Deal();
        Deal deal = new Deal();
        int idd = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
        List<Deal> listdeal = dealdao.displayDealById(idd);
        for (Deal a : listdeal) {
            abc = a;
        }

        affichage.txtTitre.setText(abc.getTitreDeal_Deal());
        affichage.txtDesc.setText(abc.getDescDeal_Deal());
        affichage.txtPrix.setText(abc.getPrixDeal_Deal().toString());
        affichage.txtValidation.setText(String.valueOf(abc.getNbrAchatValidation()));
        affichage.jdateDebut.setDate(abc.getDateDebutDeal_Deal());
        affichage.jdateFin.setDate(abc.getDateFinDeal_Deal());
        affichage.txtVendeurAffichage.setText(null);
        if (abc.isStatutDeal() == true) {
            affichage.txtStatutAffichage.setText("Deal Confirm");
        } else {
            affichage.txtStatutAffichage.setText("Deal non Confirm");
        }
        Vendeur vendeur = new Vendeur();
        VendeurDAO daov = VendeurDAO.getInstance();
        int idv = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
        affichage.txtVendeurAffichage.setText(daov.displayvendeurByID(idv).getNomCommercial());
        affichage.txtEtat.setText(abc.getEtatDeal_Deal());
        affichage.txtCategorie.setText(abc.getCategorie_Deal());
        affichage.txtAffichage.setText(String.valueOf(abc.getNbrAffichage_Deal()));
        affichage.txtAchatActuel.setText(String.valueOf(abc.getNbrAchatActuelDeal_Deal()));
        ImageDeal img = new ImageDeal();

        ImageDAO im = new ImageDAO();
        Deal dea = new Deal();

        System.out.println(x);
        System.out.println(jTable1.getSelectedRow());
        affichage.a = idd;

        if (im.DisplayAllImage(idd).size() > 0) {
            img = im.DisplayAllImage(idd).get(0);
            ImageIcon icon = new ImageIcon(img.getImage());

            affichage.jLabel8.setIcon(icon);

        } else {
            System.out.println("aucune image trouve");
            affichage.jLabel8.setText("aucune image trouve");
        }

        JOptionPane.showMessageDialog(null, affichage, "Affichage", JOptionPane.YES_OPTION);

    }//GEN-LAST:event_Display_ButtonActionPerformed

    private void jTable3PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTable3PropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable3PropertyChange

    private void Search_TextField1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Search_TextField1KeyReleased
        List<Client> clients1 = new ArrayList<>();
        for (Client c : clinetdao.displayClient()) {
            if (c.getNom().toLowerCase().contains(this.Search_TextField1.getText().toLowerCase()))
                clients1.add(c);
        }
        DisplayClientTableModel model2 = new DisplayClientTableModel(clients1);
        jTable2.setModel(model2);
        if (jTable2.getModel().getRowCount() != 0) {
            jTable2.setRowSelectionInterval(0, 0);
        }
    }//GEN-LAST:event_Search_TextField1KeyReleased

    private void Search_TextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Search_TextField2KeyReleased
        List<Deal> recherche = new ArrayList<>();
        for (Deal a : list.displayDeal()) {
            if (a.getTitreDeal_Deal().toLowerCase().contains(this.Search_TextField2.getText().toLowerCase())) {
                recherche.add(a);
            }

        }
        DealTableModel mymodel = new DealTableModel(recherche);
        jTable3.setModel(mymodel);
        jTable3.removeColumn(jTable3.getColumn("ID"));
        jTable3.removeColumn(jTable3.getColumn("Description"));
        jTable3.removeColumn(jTable3.getColumn("Achat Actuel"));
        jTable3.removeColumn(jTable3.getColumn("Etat"));
        jTable3.removeColumn(jTable3.getColumn("Statut"));
        jTable3.removeColumn(jTable3.getColumn("Nombre d'Affichage"));
        jTable3.removeColumn(jTable3.getColumn("Vendeur"));

        if (jTable3.getModel().getRowCount() != 0) {
            jTable3.setRowSelectionInterval(0, 0);
        }
    }//GEN-LAST:event_Search_TextField2KeyReleased

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        int idd = (int) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 0);
        ChoixStat1 chStat = new ChoixStat1();
        ChoixStat2 chStat2 = new ChoixStat2();

        Object[] options = { "BACK", "NEXT" };
        int a = JOptionPane.showOptionDialog(null, chStat, "", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        int b = 0;
        if (chStat.jRadiosexe.isSelected() && chStat.jRadioconsult.isSelected()) {
            b = 0;
        }
        if (chStat.jRadiosexe.isSelected() && chStat.jRadiores.isSelected()) {
            b = 1;
        }
        if (chStat.jRadiooperation.isSelected() && chStat.jRadioconsult.isSelected()) {
            b = 2;
        }
        if (chStat.jRadiooperation.isSelected() && chStat.jRadiores.isSelected()) {
            b = 3;
        }
        if (a == 1 && b == 2) {
            chStat.setVisible(false);
            Object[] options2 = { "Annuler", "Afficher la Statistique" };
            int c = JOptionPane.showOptionDialog(null, chStat2, "", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options2, options[0]);
            if (c == 1) {
                java.util.Date d1 = chStat2.jDateDebut.getCalendar().getTime();
                java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
                java.util.Date d2 = chStat2.jDatefin.getCalendar().getTime();
                java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime());
                Charts charts = new Charts();

                XYSeriesCollection dataxy = charts.createDataset(sqlDate.toString(), sqlDate2.toString(), idd);
                final JFreeChart chart = ChartFactory.createXYLineChart(
                        "Evolution des Consultation par rapport au temps", "Jours", "Nombre des Consultations", //
                        dataxy, // Dataset
                        PlotOrientation.VERTICAL, // 

                        true, true, false);
                XYItemRenderer rend = chart.getXYPlot().getRenderer();

                ChartPanel crepart = new ChartPanel(chart);
                Plot plot = chart.getPlot();

                JPanel jpan = new JPanel();
                JButton button = new JButton("Sauvegarder");
                button.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            JFileChooser chooser = new JFileChooser();
                            chooser.showSaveDialog(jPanel3);
                            String path = chooser.getSelectedFile().getPath();
                            if ((!path.contains("jpg")) || (!path.contains("png")) || (!path.contains("jpeg"))) {
                                path = path + ".png";
                            }
                            File f = new File(path);
                            ChartUtilities.saveChartAsPNG(new File(path), chart, 800, 600);

                            if (f.exists() && !f.isDirectory()) {
                                JOptionPane.showMessageDialog(null, "Sauvegarde Effectue");
                                Desktop.getDesktop().open(f);
                            }
                        } catch (IOException ex) {
                            Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                });

                jpan.add(crepart);
                jpan.add(button);
                JOptionPane.showConfirmDialog(null, jpan, "Chart d'volution des consultations",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            }
        }
        if (a == 1 && (b == 3)) {
            Object[] options2 = { "Annuler", "Afficher la Statistique" };
            int c = JOptionPane.showOptionDialog(null, chStat2, "", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options2, options[0]);
            if (c == 1) {
                java.util.Date d1 = chStat2.jDateDebut.getCalendar().getTime();
                java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
                java.util.Date d2 = chStat2.jDatefin.getCalendar().getTime();
                java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime());
                Charts charts = new Charts();
                //     JFreeChart chrt = ChartFactory.createXYStepAreaChart(null, null, null, null, PlotOrientation.HORIZONTAL, rootPaneCheckingEnabled, rootPaneCheckingEnabled, rootPaneCheckingEnabled)
                XYSeriesCollection dataxy = charts.createDatasetRes(sqlDate.toString(), sqlDate2.toString(), idd);
                final JFreeChart chart = ChartFactory.createXYLineChart(
                        "Evolution des Consultation par rapport au temps", "Jours", "Nombre des Reservations",
                        dataxy, PlotOrientation.VERTICAL, true, true, false);
                XYItemRenderer rend = chart.getXYPlot().getRenderer();

                ChartPanel crepart = new ChartPanel(chart);
                Plot plot = chart.getPlot();

                JPanel jpan = new JPanel();
                jpan.setLayout(new FlowLayout(FlowLayout.LEADING));
                JButton button = new JButton();

                button.setText("Sauvegarder");
                button.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            JFileChooser chooser = new JFileChooser();
                            chooser.showSaveDialog(jPanel3);
                            String path = chooser.getSelectedFile().getPath();
                            if ((!path.contains("jpg")) || (!path.contains("png")) || (!path.contains("jpeg"))) {
                                path = path + ".png";
                            }
                            File f = new File(path);
                            ChartUtilities.saveChartAsPNG(new File(path), chart, 800, 600);

                            if (f.exists() && !f.isDirectory()) {
                                JOptionPane.showMessageDialog(null, "Sauvegarde Effectue");
                                Desktop.getDesktop().open(f);
                            }
                        } catch (IOException ex) {
                            Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                });

                jpan.add(crepart);
                jpan.add(button);
                JOptionPane.showConfirmDialog(null, jpan, "Test", JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.PLAIN_MESSAGE);
            }

        }
        if (a == 1 && b == 0) {
            ConsultationDAO cdao = ConsultationDAO.getInstance();
            DefaultPieDataset union = new DefaultPieDataset();
            union.setValue("Homme", cdao.consultationCounterByGender(false, idd));
            union.setValue("Femme", cdao.consultationCounterByGender(true, idd));

            final JFreeChart repart = ChartFactory.createPieChart3D("Rpartition par Sexe", union, true, true,
                    false);
            ChartPanel crepart = new ChartPanel(repart);
            Plot plot = repart.getPlot();
            JPanel jpan = new JPanel();
            JButton button = new JButton("Sauvegarder");
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        JFileChooser chooser = new JFileChooser();
                        chooser.showSaveDialog(jPanel3);
                        String path = chooser.getSelectedFile().getPath();
                        if ((!path.contains("jpg")) || (!path.contains("png")) || (!path.contains("jpeg"))) {
                            path = path + ".png";
                        }
                        File f = new File(path);
                        ChartUtilities.saveChartAsPNG(new File(path), repart, 800, 600);

                        if (f.exists() && !f.isDirectory()) {
                            JOptionPane.showMessageDialog(null, "Sauvegarde Effectue");
                            Desktop.getDesktop().open(f);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });

            jpan.add(crepart);
            jpan.add(button);
            JOptionPane.showConfirmDialog(null, jpan, "", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

        }
        if (a == 1 && b == 1) {
            DefaultPieDataset union = new DefaultPieDataset();
            ReservationDAO dAO = ReservationDAO.getInstance();
            union.setValue("Homme", dAO.reservationCounterByGender(false, idd));
            union.setValue("Femme", dAO.reservationCounterByGender(true, idd));

            final JFreeChart repart = ChartFactory.createPieChart3D("Rpartition par Sexe", union, true, true,
                    false);
            ChartPanel crepart = new ChartPanel(repart);
            Plot plot = repart.getPlot();
            JPanel jpan = new JPanel();
            JButton button = new JButton("Sauvegarder");
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        JFileChooser chooser = new JFileChooser();
                        chooser.showSaveDialog(jPanel3);
                        String path = chooser.getSelectedFile().getPath();
                        if ((!path.contains("jpg")) || (!path.contains("png")) || (!path.contains("jpeg"))) {
                            path = path + ".png";
                        }
                        File f = new File(path);
                        ChartUtilities.saveChartAsPNG(new File(path), repart, 800, 600);

                        if (f.exists() && !f.isDirectory()) {
                            JOptionPane.showMessageDialog(null, "Sauvegarde Effectue");
                            Desktop.getDesktop().open(f);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });

            jpan.add(crepart);
            jpan.add(button);
            JOptionPane.showConfirmDialog(null, jpan, "Chart de la rpartition des achat par sexe",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void DeleteClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteClientActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:

        if (jTable2.getSelectedRow() == -1) {
            // erreur.setText("Veuillez choisir un client  supprimer");

        } else {
            int result = JOptionPane.showConfirmDialog(null, "Voulez Vous Supprimer", null,
                    JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {

                int indice = (int) jTable2.getValueAt(jTable2.getSelectedRow(), jTable2.getSelectedColumn());
                int a = clinetdao.deleteClient(indice);
                if (a == 1) {
                    JOptionPane.showMessageDialog(null, "Client Supprim");

                    DisplayClientTableModel model2 = new DisplayClientTableModel(clinetdao.displayClient());
                    jTable2.setModel(model2);
                }
            }
        }
    }//GEN-LAST:event_DeleteClientActionPerformed

    private void ButtonRapportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonRapportActionPerformed
        int idd = (int) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 0);
        String pattern = null;
        String path;
        FileNameExtensionFilter filter = new FileNameExtensionFilter("JASPER files", "jasper");
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(this);
        chooser.setMultiSelectionEnabled(false);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            pattern = chooser.getSelectedFile().getPath();
        }
        FileNameExtensionFilter filterpath = new FileNameExtensionFilter("PDF files", "pdf");
        JFileChooser chooserpath = new JFileChooser();
        chooserpath.setFileFilter(filterpath);
        int returnSave = chooserpath.showSaveDialog(this);
        if (returnSave == JFileChooser.APPROVE_OPTION) {
            path = chooserpath.getSelectedFile().getPath();

            if (!path.contains("pdf")) {
                path = path + ".pdf";
                String a = "\\";
            }
            pattern = pattern.replace("\\", "\\" + "\\");
            path = path.replace("\\", "\\" + "\\");

            ReportCreator creator = new ReportCreator();
            int a = creator.CreateReportDeal(pattern, idd, path);
            if (a == 1) {
                File file = new File(path.toString());
                try {
                    Desktop.getDesktop().open(file);
                } catch (IOException ex) {
                    Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_ButtonRapportActionPerformed

    private void GoToClientInterfaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GoToClientInterfaceActionPerformed
        // TODO add your handling code here:
        this.hide();
        Espace_Client espace_client = new Espace_Client();
        espace_client.show();
    }//GEN-LAST:event_GoToClientInterfaceActionPerformed

    private void DeleteMessageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteMessageButtonActionPerformed
        int idd;
        if (jTableMessage.getRowCount() != 0) {
            idd = (int) jTableMessage.getModel().getValueAt(jTableMessage.getSelectedRow(), 4);
            System.out.println(idd);
            int a = MessageDAO.getInstance().deleteMessage(idd);
            if (a == 1) {
                JOptionPane.showMessageDialog(null, "Message Effac");
                ClientTableModel tbl = new ClientTableModel(
                        MessageDAO.getInstance().displayMessageWithSenderMail());
                jTableMessage.setModel(tbl);
                jTableMessage.removeColumn(jTableMessage.getColumn("ID"));
            }
        }
    }//GEN-LAST:event_DeleteMessageButtonActionPerformed

    /**
     * @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 {
            UIManager.setLookAndFeel(new AluminiumLookAndFeel());

        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {

                new InterfacePrincipale().setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Add_Button;
    private javax.swing.JButton ButtonRapport;
    private javax.swing.JPanel Client_Panel;
    private javax.swing.JButton DeleteClient;
    private javax.swing.JButton DeleteMessageButton;
    private javax.swing.JButton Delete_Button;
    private javax.swing.JButton Display_Button;
    private javax.swing.JButton GoToClientInterface;
    private javax.swing.JButton ReplyButton;
    private javax.swing.JTextPane Search_TextField;
    private javax.swing.JTextPane Search_TextField1;
    private javax.swing.JTextPane Search_TextField2;
    private javax.swing.JButton StatButton;
    private javax.swing.JButton Update_Button;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTabbedPane jTabbedPane1;
    public javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    public javax.swing.JTable jTable3;
    private javax.swing.JTable jTableMessage;
    // End of variables declaration//GEN-END:variables

}