Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package view.gestion;
- import java.awt.EventQueue;
- import javax.swing.JInternalFrame;
- import java.awt.GridLayout;
- import java.awt.GridBagLayout;
- import java.awt.FlowLayout;
- import javax.swing.BoxLayout;
- import java.awt.BorderLayout;
- import javax.swing.JPanel;
- import javax.swing.JLabel;
- import DAO.CommandeDAO;
- import DAO.GestionCommandeDAO;
- import com.jgoodies.forms.layout.FormLayout;
- import com.jgoodies.forms.layout.ColumnSpec;
- import com.jgoodies.forms.factories.FormFactory;
- import com.jgoodies.forms.layout.RowSpec;
- import javax.swing.SpringLayout;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import model.Client;
- import model.Commande;
- import model.Produit;
- import net.miginfocom.swing.MigLayout;
- import javax.swing.border.TitledBorder;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import javax.swing.JComboBox;
- import javax.swing.UIManager;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.GregorianCalendar;
- public class Devis extends JInternalFrame {
- private JTextField txt_id;
- private JTextField txt_nom;
- private JTextField txt_proID;
- private JTextField txt_adresse;
- private JTextField txt_ville;
- private JTextField txt_prix;
- private JTextField txt_qte;
- private JInternalFrame m_JFrameDevis;
- private JComboBox cbx_nomProduit;
- private JComboBox cbx_categorie;
- private Produit m_oProduit = new Produit();
- private Commande m_oCommande = new Commande();
- private Client m_oClient = new Client();
- private GestionCommandeDAO m_oCommandeDAO = new GestionCommandeDAO();
- private ArrayList<Produit> m_listProduit = new ArrayList<Produit>();
- private int m_CommandeRef = CommandeDAO.getLastRef() + 1;
- /**
- * Create the frame.
- */
- public Devis() {
- super("Gestion Facture", true, true, true, true);
- m_JFrameDevis = new JInternalFrame();
- m_JFrameDevis = this;
- setSize(880, 350);
- getContentPane().setLayout(
- new MigLayout("", "[:64.00:200px,left][309.00,grow][]", "[][][98.00]"));
- JPanel panel_client = new JPanel();
- panel_client.setBorder(new TitledBorder(null, "Client",
- TitledBorder.LEADING, TitledBorder.TOP, null, null));
- getContentPane().add(panel_client, "cell 0 0,grow");
- panel_client
- .setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(59dlu;default):grow"), },
- new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC, }));
- JLabel lblRf = new JLabel("R\u00E9f ");
- panel_client.add(lblRf, "2, 2, left, default");
- txt_id = new JTextField();
- panel_client.add(txt_id, "4, 2, fill, default");
- txt_id.setColumns(10);
- JLabel lblNom = new JLabel("Nom ");
- panel_client.add(lblNom, "2, 4, left, default");
- txt_nom = new JTextField();
- panel_client.add(txt_nom, "4, 4, fill, default");
- txt_nom.setColumns(10);
- JLabel lblAdresse = new JLabel("Adresse ");
- panel_client.add(lblAdresse, "2, 6, right, default");
- txt_adresse = new JTextField();
- panel_client.add(txt_adresse, "4, 6, fill, default");
- txt_adresse.setColumns(10);
- JLabel lblVille = new JLabel("Ville ");
- panel_client.add(lblVille, "2, 8, left, default");
- txt_ville = new JTextField();
- panel_client.add(txt_ville, "4, 8, fill, default");
- txt_ville.setColumns(10);
- JPanel panel_produit = new JPanel();
- panel_produit.setBorder(new TitledBorder(null, "Produit",
- TitledBorder.LEADING, TitledBorder.TOP, null, null));
- getContentPane().add(panel_produit, "cell 1 0,grow");
- panel_produit
- .setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(43dlu;default)"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(79dlu;default):grow"), },
- new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC, }));
- JLabel lblRf_1 = new JLabel("R\u00E9f : ");
- panel_produit.add(lblRf_1, "2, 2, left, default");
- txt_proID = new JTextField();
- txt_proID.setEditable(false);
- panel_produit.add(txt_proID, "4, 2, fill, default");
- txt_proID.setColumns(10);
- JLabel lblCatgorie = new JLabel("Cat\u00E9gorie");
- panel_produit.add(lblCatgorie, "2, 4, left, default");
- cbx_categorie = new JComboBox(m_oProduit.lister_categories());
- cbx_categorie.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Produit p = new Produit();
- cbx_nomProduit.removeAllItems();
- for (int i = 0; i < p.list_nomProduit(cbx_categorie
- .getSelectedItem().toString()).length; i++) {
- cbx_nomProduit.addItem(p.list_nomProduit(cbx_categorie
- .getSelectedItem().toString())[i]);
- }
- }
- });
- panel_produit.add(cbx_categorie, "4, 4, fill, default");
- JLabel lblNom_1 = new JLabel("Nom :");
- panel_produit.add(lblNom_1, "2, 6, left, default");
- cbx_nomProduit = new JComboBox();
- cbx_nomProduit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- txt_proID.setText(String.valueOf(Produit.recherche(
- cbx_nomProduit.getSelectedItem().toString(),
- cbx_categorie.getSelectedItem().toString())
- .getProduitID()));
- txt_qte.setText(String.valueOf(Produit.recherche(
- cbx_nomProduit.getSelectedItem().toString(),
- cbx_categorie.getSelectedItem().toString()).getQte()));
- txt_prix.setText(String.valueOf(Produit.recherche(
- cbx_nomProduit.getSelectedItem().toString(),
- cbx_categorie.getSelectedItem().toString()).getPrix()));
- }
- });
- panel_produit.add(cbx_nomProduit, "4, 6, fill, default");
- JLabel lblPrix = new JLabel("Prix");
- panel_produit.add(lblPrix, "2, 8, left, default");
- txt_prix = new JTextField();
- panel_produit.add(txt_prix, "4, 8, fill, default");
- txt_prix.setColumns(10);
- JLabel lblQuantitEnStock = new JLabel("Quantit\u00E9");
- panel_produit.add(lblQuantitEnStock, "2, 10, left, default");
- txt_qte = new JTextField();
- panel_produit.add(txt_qte, "4, 10, fill, default");
- txt_qte.setColumns(10);
- JPanel panel_btn = new JPanel();
- getContentPane().add(panel_btn, "cell 1 1,alignx left,aligny bottom");
- GridBagLayout gbl_panel_btn = new GridBagLayout();
- gbl_panel_btn.columnWidths = new int[] { 0, 0, 0, 0, 0 };
- gbl_panel_btn.rowHeights = new int[] { 0, 0, 39, 0 };
- gbl_panel_btn.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
- Double.MIN_VALUE };
- gbl_panel_btn.rowWeights = new double[] { 0.0, 0.0, 0.0,
- Double.MIN_VALUE };
- panel_btn.setLayout(gbl_panel_btn);
- JButton btnValider = new JButton("Valider");
- btnValider.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- m_oCommandeDAO.setM_listProduit(m_listProduit);
- m_oCommandeDAO.setClient(m_oClient);
- // calculer le prix total
- CommandeDAO cmdDAO = new CommandeDAO();
- cmdDAO.setM_listProduit(m_listProduit);
- m_oCommande.setRef(m_CommandeRef);
- GregorianCalendar gc = new GregorianCalendar();
- m_oCommande.setDate(String.valueOf(gc.get(Calendar.YEAR)) + "-" + String.valueOf(gc.get(Calendar.MONTH)) +
- "-" + String.valueOf(gc.get(Calendar.DAY_OF_MONTH)));
- m_oCommande.setPrixTotal(cmdDAO.prixTotal());
- m_oCommandeDAO.setM_oCommande(m_oCommande);
- m_oCommandeDAO.Ajouter();
- }
- });
- GridBagConstraints gbc_btnValider = new GridBagConstraints();
- gbc_btnValider.fill = GridBagConstraints.HORIZONTAL;
- gbc_btnValider.insets = new Insets(0, 0, 5, 5);
- gbc_btnValider.gridx = 0;
- gbc_btnValider.gridy = 1;
- panel_btn.add(btnValider, gbc_btnValider);
- JButton btnChoisirClient = new JButton("Choisir Client");
- btnChoisirClient.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Client cl = Client.recherche(
- Integer.parseInt(txt_id.getText()), txt_nom.getText());
- if (cl.getNom().isEmpty()) {
- return;
- }
- m_oClient = cl;
- txt_ville.setText(cl.getVille());
- txt_adresse.setText(cl.getAdresse());
- txt_id.setText(String.valueOf(cl.getClientID()));
- txt_nom.setText(cl.getNom());
- }
- });
- GridBagConstraints gbc_btnChoisirClient = new GridBagConstraints();
- gbc_btnChoisirClient.insets = new Insets(0, 0, 5, 5);
- gbc_btnChoisirClient.gridx = 1;
- gbc_btnChoisirClient.gridy = 1;
- panel_btn.add(btnChoisirClient, gbc_btnChoisirClient);
- JButton btnAjouterProduit = new JButton("Ajouter Produit");
- btnAjouterProduit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- Produit p = Produit
- .recherche(cbx_nomProduit.getSelectedItem().toString(),
- cbx_categorie.getSelectedItem().toString());
- m_listProduit.add(p);
- txt_proID.setText("");
- txt_qte.setText("");
- txt_prix.setText("");
- cbx_nomProduit.removeAllItems();
- }
- });
- GridBagConstraints gbc_btnAjouterProduit = new GridBagConstraints();
- gbc_btnAjouterProduit.insets = new Insets(0, 0, 5, 5);
- gbc_btnAjouterProduit.gridx = 2;
- gbc_btnAjouterProduit.gridy = 1;
- panel_btn.add(btnAjouterProduit, gbc_btnAjouterProduit);
- JButton btnAjouterService = new JButton("Ajouter Service");
- btnAjouterService.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- GridBagConstraints gbc_btnAjouterService = new GridBagConstraints();
- gbc_btnAjouterService.insets = new Insets(0, 0, 0, 5);
- gbc_btnAjouterService.gridx = 0;
- gbc_btnAjouterService.gridy = 2;
- panel_btn.add(btnAjouterService, gbc_btnAjouterService);
- JButton btnQuitter = new JButton("Quitter");
- btnQuitter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- m_JFrameDevis.setVisible(false);
- }
- });
- GridBagConstraints gbc_btnQuitter = new GridBagConstraints();
- gbc_btnQuitter.fill = GridBagConstraints.HORIZONTAL;
- gbc_btnQuitter.insets = new Insets(0, 0, 0, 5);
- gbc_btnQuitter.gridx = 1;
- gbc_btnQuitter.gridy = 2;
- panel_btn.add(btnQuitter, gbc_btnQuitter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement