Advertisement
Sungper

Ifacture

Jun 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.85 KB | None | 0 0
  1. package view.gestion;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JInternalFrame;
  6. import java.awt.GridLayout;
  7. import java.awt.GridBagLayout;
  8. import java.awt.FlowLayout;
  9. import javax.swing.BoxLayout;
  10. import java.awt.BorderLayout;
  11. import javax.swing.JPanel;
  12. import javax.swing.JLabel;
  13.  
  14. import DAO.CommandeDAO;
  15. import DAO.GestionCommandeDAO;
  16.  
  17. import com.jgoodies.forms.layout.FormLayout;
  18. import com.jgoodies.forms.layout.ColumnSpec;
  19. import com.jgoodies.forms.factories.FormFactory;
  20. import com.jgoodies.forms.layout.RowSpec;
  21. import javax.swing.SpringLayout;
  22. import javax.swing.GroupLayout;
  23. import javax.swing.GroupLayout.Alignment;
  24.  
  25. import model.Client;
  26. import model.Commande;
  27. import model.Produit;
  28. import net.miginfocom.swing.MigLayout;
  29. import javax.swing.border.TitledBorder;
  30. import javax.swing.JTextField;
  31. import javax.swing.JButton;
  32. import java.awt.GridBagConstraints;
  33. import java.awt.Insets;
  34. import javax.swing.JComboBox;
  35. import javax.swing.UIManager;
  36. import java.awt.event.ActionListener;
  37. import java.awt.event.ActionEvent;
  38. import java.util.ArrayList;
  39. import java.util.Calendar;
  40. import java.util.Date;
  41. import java.util.GregorianCalendar;
  42.  
  43. public class Devis extends JInternalFrame {
  44.     private JTextField txt_id;
  45.     private JTextField txt_nom;
  46.     private JTextField txt_proID;
  47.     private JTextField txt_adresse;
  48.     private JTextField txt_ville;
  49.     private JTextField txt_prix;
  50.     private JTextField txt_qte;
  51.     private JInternalFrame m_JFrameDevis;
  52.     private JComboBox cbx_nomProduit;
  53.     private JComboBox cbx_categorie;
  54.  
  55.     private Produit m_oProduit = new Produit();
  56.     private Commande m_oCommande = new Commande();
  57.     private Client m_oClient = new Client();
  58.     private GestionCommandeDAO m_oCommandeDAO = new GestionCommandeDAO();
  59.     private ArrayList<Produit> m_listProduit = new ArrayList<Produit>();
  60.  
  61.     private int m_CommandeRef = CommandeDAO.getLastRef() + 1;
  62.  
  63.     /**
  64.      * Create the frame.
  65.      */
  66.     public Devis() {
  67.         super("Gestion Facture", true, true, true, true);
  68.         m_JFrameDevis = new JInternalFrame();
  69.         m_JFrameDevis = this;
  70.  
  71.         setSize(880, 350);
  72.         getContentPane().setLayout(
  73.                 new MigLayout("", "[:64.00:200px,left][309.00,grow][]", "[][][98.00]"));
  74.  
  75.         JPanel panel_client = new JPanel();
  76.         panel_client.setBorder(new TitledBorder(null, "Client",
  77.                 TitledBorder.LEADING, TitledBorder.TOP, null, null));
  78.         getContentPane().add(panel_client, "cell 0 0,grow");
  79.         panel_client
  80.                 .setLayout(new FormLayout(new ColumnSpec[] {
  81.                         FormFactory.RELATED_GAP_COLSPEC,
  82.                         FormFactory.DEFAULT_COLSPEC,
  83.                         FormFactory.RELATED_GAP_COLSPEC,
  84.                         ColumnSpec.decode("max(59dlu;default):grow"), },
  85.                         new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
  86.                                 FormFactory.DEFAULT_ROWSPEC,
  87.                                 FormFactory.RELATED_GAP_ROWSPEC,
  88.                                 FormFactory.DEFAULT_ROWSPEC,
  89.                                 FormFactory.RELATED_GAP_ROWSPEC,
  90.                                 FormFactory.DEFAULT_ROWSPEC,
  91.                                 FormFactory.RELATED_GAP_ROWSPEC,
  92.                                 FormFactory.DEFAULT_ROWSPEC,
  93.                                 FormFactory.RELATED_GAP_ROWSPEC,
  94.                                 FormFactory.DEFAULT_ROWSPEC, }));
  95.  
  96.         JLabel lblRf = new JLabel("R\u00E9f ");
  97.         panel_client.add(lblRf, "2, 2, left, default");
  98.  
  99.         txt_id = new JTextField();
  100.         panel_client.add(txt_id, "4, 2, fill, default");
  101.         txt_id.setColumns(10);
  102.  
  103.         JLabel lblNom = new JLabel("Nom ");
  104.         panel_client.add(lblNom, "2, 4, left, default");
  105.  
  106.         txt_nom = new JTextField();
  107.         panel_client.add(txt_nom, "4, 4, fill, default");
  108.         txt_nom.setColumns(10);
  109.  
  110.         JLabel lblAdresse = new JLabel("Adresse ");
  111.         panel_client.add(lblAdresse, "2, 6, right, default");
  112.  
  113.         txt_adresse = new JTextField();
  114.         panel_client.add(txt_adresse, "4, 6, fill, default");
  115.         txt_adresse.setColumns(10);
  116.  
  117.         JLabel lblVille = new JLabel("Ville ");
  118.         panel_client.add(lblVille, "2, 8, left, default");
  119.  
  120.         txt_ville = new JTextField();
  121.         panel_client.add(txt_ville, "4, 8, fill, default");
  122.         txt_ville.setColumns(10);
  123.         JPanel panel_produit = new JPanel();
  124.         panel_produit.setBorder(new TitledBorder(null, "Produit",
  125.                 TitledBorder.LEADING, TitledBorder.TOP, null, null));
  126.         getContentPane().add(panel_produit, "cell 1 0,grow");
  127.         panel_produit
  128.                 .setLayout(new FormLayout(new ColumnSpec[] {
  129.                         FormFactory.RELATED_GAP_COLSPEC,
  130.                         ColumnSpec.decode("max(43dlu;default)"),
  131.                         FormFactory.RELATED_GAP_COLSPEC,
  132.                         ColumnSpec.decode("max(79dlu;default):grow"), },
  133.                         new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
  134.                                 FormFactory.DEFAULT_ROWSPEC,
  135.                                 FormFactory.RELATED_GAP_ROWSPEC,
  136.                                 FormFactory.DEFAULT_ROWSPEC,
  137.                                 FormFactory.RELATED_GAP_ROWSPEC,
  138.                                 FormFactory.DEFAULT_ROWSPEC,
  139.                                 FormFactory.RELATED_GAP_ROWSPEC,
  140.                                 FormFactory.DEFAULT_ROWSPEC,
  141.                                 FormFactory.RELATED_GAP_ROWSPEC,
  142.                                 FormFactory.DEFAULT_ROWSPEC, }));
  143.  
  144.         JLabel lblRf_1 = new JLabel("R\u00E9f : ");
  145.         panel_produit.add(lblRf_1, "2, 2, left, default");
  146.  
  147.         txt_proID = new JTextField();
  148.         txt_proID.setEditable(false);
  149.         panel_produit.add(txt_proID, "4, 2, fill, default");
  150.         txt_proID.setColumns(10);
  151.  
  152.         JLabel lblCatgorie = new JLabel("Cat\u00E9gorie");
  153.         panel_produit.add(lblCatgorie, "2, 4, left, default");
  154.  
  155.         cbx_categorie = new JComboBox(m_oProduit.lister_categories());
  156.         cbx_categorie.addActionListener(new ActionListener() {
  157.             public void actionPerformed(ActionEvent e) {
  158.                 Produit p = new Produit();
  159.                 cbx_nomProduit.removeAllItems();
  160.                 for (int i = 0; i < p.list_nomProduit(cbx_categorie
  161.                         .getSelectedItem().toString()).length; i++) {
  162.                     cbx_nomProduit.addItem(p.list_nomProduit(cbx_categorie
  163.                             .getSelectedItem().toString())[i]);
  164.                 }
  165.             }
  166.         });
  167.         panel_produit.add(cbx_categorie, "4, 4, fill, default");
  168.  
  169.         JLabel lblNom_1 = new JLabel("Nom :");
  170.         panel_produit.add(lblNom_1, "2, 6, left, default");
  171.  
  172.         cbx_nomProduit = new JComboBox();
  173.         cbx_nomProduit.addActionListener(new ActionListener() {
  174.             public void actionPerformed(ActionEvent e) {
  175.                 txt_proID.setText(String.valueOf(Produit.recherche(
  176.                         cbx_nomProduit.getSelectedItem().toString(),
  177.                         cbx_categorie.getSelectedItem().toString())
  178.                         .getProduitID()));
  179.                 txt_qte.setText(String.valueOf(Produit.recherche(
  180.                         cbx_nomProduit.getSelectedItem().toString(),
  181.                         cbx_categorie.getSelectedItem().toString()).getQte()));
  182.                 txt_prix.setText(String.valueOf(Produit.recherche(
  183.                         cbx_nomProduit.getSelectedItem().toString(),
  184.                         cbx_categorie.getSelectedItem().toString()).getPrix()));
  185.             }
  186.         });
  187.         panel_produit.add(cbx_nomProduit, "4, 6, fill, default");
  188.  
  189.         JLabel lblPrix = new JLabel("Prix");
  190.         panel_produit.add(lblPrix, "2, 8, left, default");
  191.  
  192.         txt_prix = new JTextField();
  193.         panel_produit.add(txt_prix, "4, 8, fill, default");
  194.         txt_prix.setColumns(10);
  195.  
  196.         JLabel lblQuantitEnStock = new JLabel("Quantit\u00E9");
  197.         panel_produit.add(lblQuantitEnStock, "2, 10, left, default");
  198.  
  199.         txt_qte = new JTextField();
  200.         panel_produit.add(txt_qte, "4, 10, fill, default");
  201.         txt_qte.setColumns(10);
  202.  
  203.         JPanel panel_btn = new JPanel();
  204.         getContentPane().add(panel_btn, "cell 1 1,alignx left,aligny bottom");
  205.         GridBagLayout gbl_panel_btn = new GridBagLayout();
  206.         gbl_panel_btn.columnWidths = new int[] { 0, 0, 0, 0, 0 };
  207.         gbl_panel_btn.rowHeights = new int[] { 0, 0, 39, 0 };
  208.         gbl_panel_btn.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
  209.                 Double.MIN_VALUE };
  210.         gbl_panel_btn.rowWeights = new double[] { 0.0, 0.0, 0.0,
  211.                 Double.MIN_VALUE };
  212.         panel_btn.setLayout(gbl_panel_btn);
  213.  
  214.         JButton btnValider = new JButton("Valider");
  215.         btnValider.addActionListener(new ActionListener() {
  216.             public void actionPerformed(ActionEvent arg0) {
  217.                 m_oCommandeDAO.setM_listProduit(m_listProduit);
  218.                 m_oCommandeDAO.setClient(m_oClient);
  219.  
  220.                 // calculer le prix total
  221.                 CommandeDAO cmdDAO = new CommandeDAO();
  222.                 cmdDAO.setM_listProduit(m_listProduit);
  223.                
  224.                 m_oCommande.setRef(m_CommandeRef);
  225.                 GregorianCalendar gc = new  GregorianCalendar();
  226.                 m_oCommande.setDate(String.valueOf(gc.get(Calendar.YEAR)) + "-" + String.valueOf(gc.get(Calendar.MONTH)) +
  227.                                     "-" + String.valueOf(gc.get(Calendar.DAY_OF_MONTH)));
  228.                 m_oCommande.setPrixTotal(cmdDAO.prixTotal());
  229.                
  230.                 m_oCommandeDAO.setM_oCommande(m_oCommande);
  231.                 m_oCommandeDAO.Ajouter();
  232.  
  233.             }
  234.         });
  235.         GridBagConstraints gbc_btnValider = new GridBagConstraints();
  236.         gbc_btnValider.fill = GridBagConstraints.HORIZONTAL;
  237.         gbc_btnValider.insets = new Insets(0, 0, 5, 5);
  238.         gbc_btnValider.gridx = 0;
  239.         gbc_btnValider.gridy = 1;
  240.         panel_btn.add(btnValider, gbc_btnValider);
  241.  
  242.         JButton btnChoisirClient = new JButton("Choisir Client");
  243.         btnChoisirClient.addActionListener(new ActionListener() {
  244.             public void actionPerformed(ActionEvent e) {
  245.                 Client cl = Client.recherche(
  246.                         Integer.parseInt(txt_id.getText()), txt_nom.getText());
  247.                 if (cl.getNom().isEmpty()) {
  248.                     return;
  249.                 }
  250.                 m_oClient = cl;
  251.                 txt_ville.setText(cl.getVille());
  252.                 txt_adresse.setText(cl.getAdresse());
  253.                 txt_id.setText(String.valueOf(cl.getClientID()));
  254.                 txt_nom.setText(cl.getNom());
  255.  
  256.             }
  257.         });
  258.         GridBagConstraints gbc_btnChoisirClient = new GridBagConstraints();
  259.         gbc_btnChoisirClient.insets = new Insets(0, 0, 5, 5);
  260.         gbc_btnChoisirClient.gridx = 1;
  261.         gbc_btnChoisirClient.gridy = 1;
  262.         panel_btn.add(btnChoisirClient, gbc_btnChoisirClient);
  263.  
  264.         JButton btnAjouterProduit = new JButton("Ajouter Produit");
  265.         btnAjouterProduit.addActionListener(new ActionListener() {
  266.             public void actionPerformed(ActionEvent arg0) {
  267.                 Produit p = Produit
  268.                         .recherche(cbx_nomProduit.getSelectedItem().toString(),
  269.                                 cbx_categorie.getSelectedItem().toString());
  270.                 m_listProduit.add(p);
  271.                
  272.                 txt_proID.setText("");
  273.                 txt_qte.setText("");
  274.                 txt_prix.setText("");
  275.                 cbx_nomProduit.removeAllItems();
  276.  
  277.             }
  278.         });
  279.         GridBagConstraints gbc_btnAjouterProduit = new GridBagConstraints();
  280.         gbc_btnAjouterProduit.insets = new Insets(0, 0, 5, 5);
  281.         gbc_btnAjouterProduit.gridx = 2;
  282.         gbc_btnAjouterProduit.gridy = 1;
  283.         panel_btn.add(btnAjouterProduit, gbc_btnAjouterProduit);
  284.  
  285.         JButton btnAjouterService = new JButton("Ajouter Service");
  286.         btnAjouterService.addActionListener(new ActionListener() {
  287.             public void actionPerformed(ActionEvent arg0) {
  288.                 }
  289.         });
  290.         GridBagConstraints gbc_btnAjouterService = new GridBagConstraints();
  291.         gbc_btnAjouterService.insets = new Insets(0, 0, 0, 5);
  292.         gbc_btnAjouterService.gridx = 0;
  293.         gbc_btnAjouterService.gridy = 2;
  294.         panel_btn.add(btnAjouterService, gbc_btnAjouterService);
  295.  
  296.         JButton btnQuitter = new JButton("Quitter");
  297.         btnQuitter.addActionListener(new ActionListener() {
  298.             public void actionPerformed(ActionEvent arg0) {
  299.                 m_JFrameDevis.setVisible(false);
  300.             }
  301.         });
  302.         GridBagConstraints gbc_btnQuitter = new GridBagConstraints();
  303.         gbc_btnQuitter.fill = GridBagConstraints.HORIZONTAL;
  304.         gbc_btnQuitter.insets = new Insets(0, 0, 0, 5);
  305.         gbc_btnQuitter.gridx = 1;
  306.         gbc_btnQuitter.gridy = 2;
  307.         panel_btn.add(btnQuitter, gbc_btnQuitter);
  308.  
  309.     }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement