Advertisement
Sungper

Ifacture

Jun 20th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.67 KB | None | 0 0
  1. package view.client;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JInternalFrame;
  6. import java.awt.GridBagLayout;
  7. import javax.swing.JLabel;
  8. import java.awt.GridBagConstraints;
  9. import java.awt.Insets;
  10.  
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JTextField;
  13. import javax.swing.JButton;
  14. import javax.swing.SwingConstants;
  15.  
  16. import model.Client;
  17. import model.User;
  18.  
  19. import org.hibernate.Session;
  20. import org.hibernate.SessionFactory;
  21. import org.hibernate.Transaction;
  22. import org.hibernate.cfg.Configuration;
  23.  
  24. import pattern.ConnectionDB;
  25.  
  26. import java.awt.Font;
  27. import java.awt.event.ActionListener;
  28. import java.awt.event.ActionEvent;
  29.  
  30. public class Ajouter_Client extends JInternalFrame {
  31.     private JTextField txt_nom;
  32.     private JTextField txt_adresse;
  33.     private JTextField txt_ville;
  34.     private JTextField txt_tel;
  35.     private JTextField txt_email;
  36.     private JInternalFrame jInternal;
  37.    
  38.     /**
  39.      * Create the frame.
  40.      */
  41.     public Ajouter_Client() {
  42.        
  43.         super("Ajouter un client", true, true, true, true);
  44.         //
  45.         jInternal = new JInternalFrame();
  46.         jInternal = this;
  47.        
  48.        
  49.         GridBagLayout gridBagLayout = new GridBagLayout();
  50.         gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
  51.         gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  52.         gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
  53.         gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  54.         getContentPane().setLayout(gridBagLayout);
  55.        
  56.         JLabel lblNom = new JLabel("Nom");
  57.         lblNom.setFont(new Font("Tahoma", Font.PLAIN, 11));
  58.         lblNom.setHorizontalAlignment(SwingConstants.CENTER);
  59.         GridBagConstraints gbc_lblNom = new GridBagConstraints();
  60.         gbc_lblNom.insets = new Insets(0, 0, 5, 5);
  61.         gbc_lblNom.gridx = 1;
  62.         gbc_lblNom.gridy = 1;
  63.         getContentPane().add(lblNom, gbc_lblNom);
  64.        
  65.         txt_nom = new JTextField();
  66.         GridBagConstraints gbc_txt_nom = new GridBagConstraints();
  67.         gbc_txt_nom.insets = new Insets(0, 0, 5, 0);
  68.         gbc_txt_nom.fill = GridBagConstraints.HORIZONTAL;
  69.         gbc_txt_nom.gridx = 4;
  70.         gbc_txt_nom.gridy = 1;
  71.         getContentPane().add(txt_nom, gbc_txt_nom);
  72.         txt_nom.setColumns(10);
  73.        
  74.         JLabel lblNewLabel = new JLabel("Adresse");
  75.         GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
  76.         gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
  77.         gbc_lblNewLabel.gridx = 1;
  78.         gbc_lblNewLabel.gridy = 2;
  79.         getContentPane().add(lblNewLabel, gbc_lblNewLabel);
  80.        
  81.         txt_adresse = new JTextField();
  82.         GridBagConstraints gbc_txt_adresse = new GridBagConstraints();
  83.         gbc_txt_adresse.insets = new Insets(0, 0, 5, 0);
  84.         gbc_txt_adresse.fill = GridBagConstraints.HORIZONTAL;
  85.         gbc_txt_adresse.gridx = 4;
  86.         gbc_txt_adresse.gridy = 2;
  87.         getContentPane().add(txt_adresse, gbc_txt_adresse);
  88.         txt_adresse.setColumns(10);
  89.        
  90.         JLabel lblVille = new JLabel("Ville");
  91.         GridBagConstraints gbc_lblVille = new GridBagConstraints();
  92.         gbc_lblVille.insets = new Insets(0, 0, 5, 5);
  93.         gbc_lblVille.gridx = 1;
  94.         gbc_lblVille.gridy = 3;
  95.         getContentPane().add(lblVille, gbc_lblVille);
  96.        
  97.         txt_ville = new JTextField();
  98.         GridBagConstraints gbc_txt_ville = new GridBagConstraints();
  99.         gbc_txt_ville.insets = new Insets(0, 0, 5, 0);
  100.         gbc_txt_ville.fill = GridBagConstraints.HORIZONTAL;
  101.         gbc_txt_ville.gridx = 4;
  102.         gbc_txt_ville.gridy = 3;
  103.         getContentPane().add(txt_ville, gbc_txt_ville);
  104.         txt_ville.setColumns(10);
  105.        
  106.         JLabel lblTl = new JLabel("T\u00E9l");
  107.         GridBagConstraints gbc_lblTl = new GridBagConstraints();
  108.         gbc_lblTl.insets = new Insets(0, 0, 5, 5);
  109.         gbc_lblTl.gridx = 1;
  110.         gbc_lblTl.gridy = 4;
  111.         getContentPane().add(lblTl, gbc_lblTl);
  112.        
  113.         txt_tel = new JTextField();
  114.         GridBagConstraints gbc_txt_tel = new GridBagConstraints();
  115.         gbc_txt_tel.insets = new Insets(0, 0, 5, 0);
  116.         gbc_txt_tel.fill = GridBagConstraints.HORIZONTAL;
  117.         gbc_txt_tel.gridx = 4;
  118.         gbc_txt_tel.gridy = 4;
  119.         getContentPane().add(txt_tel, gbc_txt_tel);
  120.         txt_tel.setColumns(10);
  121.        
  122.         JLabel lblEmail = new JLabel("Email");
  123.         GridBagConstraints gbc_lblEmail = new GridBagConstraints();
  124.         gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
  125.         gbc_lblEmail.gridx = 1;
  126.         gbc_lblEmail.gridy = 5;
  127.         getContentPane().add(lblEmail, gbc_lblEmail);
  128.        
  129.         txt_email = new JTextField();
  130.         GridBagConstraints gbc_txt_email = new GridBagConstraints();
  131.         gbc_txt_email.insets = new Insets(0, 0, 5, 0);
  132.         gbc_txt_email.fill = GridBagConstraints.HORIZONTAL;
  133.         gbc_txt_email.gridx = 4;
  134.         gbc_txt_email.gridy = 5;
  135.         getContentPane().add(txt_email, gbc_txt_email);
  136.         txt_email.setColumns(10);
  137.        
  138.         JButton btnAjouter = new JButton("Ajouter");
  139.         btnAjouter.addActionListener(new ActionListener() {
  140.             public void actionPerformed(ActionEvent e) {
  141.                
  142.                 Session s = ConnectionDB.getSession();
  143.                 Transaction tr = s.beginTransaction();
  144.                 User u = new User(1);
  145.                 Client cl = new Client();
  146.                 if(txt_nom.getText().isEmpty() || txt_email.getText().isEmpty() || txt_nom.getText().isEmpty() || txt_tel.getText().isEmpty() || txt_ville.getText().isEmpty())
  147.                 {
  148.                     JOptionPane.showConfirmDialog(null, "Verifier si vous avez rempli tous les champs", "Erreur", JOptionPane.CLOSED_OPTION, JOptionPane.ERROR_MESSAGE);
  149.                     return;
  150.                 }
  151.                 cl.setAdresse(txt_adresse.getText());
  152.                 cl.setNom(txt_nom.getText());
  153.                 cl.setEmail(txt_email.getText());
  154.                 cl.setVille(txt_ville.getText());
  155.                 cl.setTel(txt_tel.getText());
  156.                 cl.setUser(u);
  157.                 s.save(cl);
  158.                 tr.commit();
  159.                 JOptionPane.showConfirmDialog(null, "Ajouter avec succés", "Succés", JOptionPane.CLOSED_OPTION, JOptionPane.INFORMATION_MESSAGE);
  160.                
  161.                
  162.             }
  163.         });
  164.         GridBagConstraints gbc_btnAjouter = new GridBagConstraints();
  165.         gbc_btnAjouter.insets = new Insets(0, 0, 0, 5);
  166.         gbc_btnAjouter.gridx = 1;
  167.         gbc_btnAjouter.gridy = 7;
  168.         getContentPane().add(btnAjouter, gbc_btnAjouter);
  169.        
  170.         JButton btnVider = new JButton("Vider");
  171.         btnVider.addActionListener(new ActionListener() {
  172.             public void actionPerformed(ActionEvent arg0) {
  173.                 txt_nom.setText("");
  174.                 txt_adresse.setText("");
  175.                 txt_email.setText("");
  176.                 txt_tel.setText("");
  177.                 txt_ville.setText("");
  178.             }
  179.         });
  180.         GridBagConstraints gbc_btnVider = new GridBagConstraints();
  181.         gbc_btnVider.insets = new Insets(0, 0, 0, 5);
  182.         gbc_btnVider.gridx = 3;
  183.         gbc_btnVider.gridy = 7;
  184.         getContentPane().add(btnVider, gbc_btnVider);
  185.        
  186.         JButton btnQuitter = new JButton("Quitter");
  187.         btnQuitter.addActionListener(new ActionListener() {
  188.             public void actionPerformed(ActionEvent e) {
  189.                 jInternal.setVisible(false);
  190.             }
  191.         });
  192.         GridBagConstraints gbc_btnQuitter = new GridBagConstraints();
  193.         gbc_btnQuitter.gridx = 4;
  194.         gbc_btnQuitter.gridy = 7;
  195.         getContentPane().add(btnQuitter, gbc_btnQuitter);
  196.     }
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement