Advertisement
Guest User

Untitled

a guest
May 18th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.15 KB | None | 0 0
  1. package pkg;
  2.  
  3. import java.awt.Color;
  4. import java.awt.EventQueue;
  5. import java.awt.Font;
  6. import java.awt.SystemColor;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.sql.DriverManager;
  12. import java.sql.PreparedStatement;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.util.Calendar;
  16.  
  17. import javax.swing.ImageIcon;
  18. import javax.swing.JButton;
  19. import javax.swing.JFrame;
  20. import javax.swing.JLabel;
  21. import javax.swing.JList;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JPanel;
  24. import javax.swing.JSpinner;
  25. import javax.swing.JTextField;
  26. import javax.swing.SpinnerDateModel;
  27. import javax.swing.UIManager;
  28. import javax.swing.border.EmptyBorder;
  29. import javax.swing.border.TitledBorder;
  30.  
  31. import com.toedter.calendar.JDateChooser;
  32.  
  33. import javax.swing.JTextArea;
  34. import javax.swing.JTable;
  35. import javax.swing.JComboBox;
  36. import javax.swing.DefaultComboBoxModel;
  37. import javax.swing.JRadioButton;
  38.  
  39. import java.sql.*;
  40.  
  41. public class Supplier extends JFrame {
  42.  
  43.     private JPanel contentPane;
  44.     private JTextField txtSupplierId;
  45.     private JTextField txtSupplierName;
  46.     private JTextField txtSupplierSurname;
  47.     private JTextField txtPhone;
  48.     private JTextField txtCompanyName;
  49.     private JTextField txtBRN;
  50.     private JTextField txtVAT;
  51.     private JTextArea txtAddress;
  52.     private Connection con;
  53.     private ResultSet rs;
  54.     private Statement stt;
  55.     String url = "jdbc:mysql://localhost:3306/java";
  56.     String user = "root";
  57.     String pw = "";
  58.    
  59.  
  60.     public static void main(String[] args) {
  61.         EventQueue.invokeLater(new Runnable() {
  62.             public void run() {
  63.                 try {
  64.                     Supplier frame = new Supplier();
  65.                     frame.setVisible(true);
  66.                 } catch (Exception e) {
  67.                     e.printStackTrace();
  68.                 }
  69.             }
  70.         });
  71.     }
  72.    
  73.  
  74.    
  75.  
  76.    
  77.     public Supplier() {
  78.        
  79.        
  80.        
  81.         super("Supplier Details");
  82.        
  83.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  84.         setBounds(100, 100, 1100, 766);
  85.         contentPane = new JPanel();
  86.         contentPane.setBackground(SystemColor.inactiveCaptionBorder);
  87.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  88.         setContentPane(contentPane);
  89.         contentPane.setLayout(null);
  90.        
  91.         JLabel lblNewLabel = new JLabel("New label");
  92.         lblNewLabel.setIcon(new ImageIcon(Supplier.class.getResource("/Images/Main-Banner.jpg")));
  93.         lblNewLabel.setBounds(0, 0, 1084, 100);
  94.         contentPane.add(lblNewLabel);
  95.        
  96.         JLabel lblAppointmentHandling = new JLabel("SUPPLIER DETAILS");
  97.         lblAppointmentHandling.setFont(new Font("Proxima Nova", Font.BOLD, 22));
  98.         lblAppointmentHandling.setBounds(41, 111, 342, 42);
  99.         contentPane.add(lblAppointmentHandling);
  100.        
  101.         JPanel panel = new JPanel();
  102.         panel.setBackground(SystemColor.inactiveCaptionBorder);
  103.         panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Supplier ID", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  104.         panel.setBounds(41, 164, 226, 73);
  105.         contentPane.add(panel);
  106.         panel.setLayout(null);
  107.        
  108.         JLabel lblTime = new JLabel("ID");
  109.         lblTime.setBounds(30, 29, 27, 15);
  110.         panel.add(lblTime);
  111.         lblTime.setFont(new Font("Tahoma", Font.PLAIN, 12));
  112.        
  113.         txtSupplierId = new JTextField();
  114.         txtSupplierId.setEnabled(false);
  115.         txtSupplierId.setBounds(67, 27, 86, 20);
  116.         panel.add(txtSupplierId);
  117.         txtSupplierId.setColumns(10);
  118.        
  119.         JPanel panel_3 = new JPanel();
  120.         panel_3.setBackground(SystemColor.inactiveCaptionBorder);
  121.         panel_3.setLayout(null);
  122.         panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Operations", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  123.         panel_3.setBounds(295, 164, 736, 73);
  124.         contentPane.add(panel_3);
  125.        
  126.         JButton btnDelete = new JButton("Delete");
  127.         btnDelete.setIcon(new ImageIcon(Supplier.class.getResource("/Images/cross.png")));
  128.         btnDelete.setBounds(303, 26, 129, 36);
  129.         panel_3.add(btnDelete);
  130.        
  131.        
  132.         try{
  133.             Class.forName("com.mysql.jdbc.Driver");
  134.        
  135.  
  136.         con = DriverManager.getConnection(url, user, pw);
  137.        
  138.         stt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  139.         rs = stt.executeQuery("SELECT * FROM supplier");
  140.         }catch(Exception ee){
  141.             ee.printStackTrace();
  142.         }
  143.        
  144.         btnDelete.addActionListener(new ActionListener() {
  145.             public void actionPerformed(ActionEvent e) {
  146.  
  147.                 try {
  148.                    
  149.                     Class.forName("com.mysql.jdbc.Driver");
  150.                    
  151.                     Connection con = DriverManager.getConnection(url, user, pw);
  152.                                        
  153.                     String del = "DELETE FROM supplier WHERE SupplierID = ?";
  154.                    
  155.                     PreparedStatement pstmt = con.prepareStatement(del);
  156.                    
  157.                     int id =   Integer.parseInt(txtSupplierId.getText());
  158.                            
  159.                     pstmt.setInt(1, id);
  160.                    
  161.                     pstmt.execute();
  162.                    
  163.                 JOptionPane.showMessageDialog(null, "Deleted");
  164.                 } catch (Exception err) {
  165.                     JOptionPane.showMessageDialog(Supplier.this, err.getMessage());
  166.                 }
  167.  
  168.             }
  169.         });
  170.    
  171.  
  172.        
  173.         JButton btnMainMenu = new JButton("Back");
  174.         btnMainMenu.setBounds(591, 26, 129, 36);
  175.         panel_3.add(btnMainMenu);
  176.         btnMainMenu.setIcon(new ImageIcon(Supplier.class.getResource("/Images/gtk-go-back-ltr.png")));
  177.         btnMainMenu.addActionListener(new ActionListener() {
  178.  
  179.             public void actionPerformed(ActionEvent arg0) {
  180.                
  181.                 /*  frame.dispose();
  182.                     MainMenu window = new MainMenu();
  183.                     window.setVisible(true);
  184.                  *
  185.                  *
  186.                  *
  187.                  */
  188.                
  189.             }
  190.            
  191.         });
  192.        
  193.         JButton btnAdd = new JButton("Add");
  194.         btnAdd.setBounds(15, 26, 129, 36);
  195.         panel_3.add(btnAdd);
  196.         btnAdd.setIcon(new ImageIcon(Supplier.class.getResource("/Images/add.png")));
  197.        
  198.         btnAdd.addMouseListener(new MouseAdapter(){
  199.            
  200.             public void mouseClicked(MouseEvent e){
  201.                
  202.                 try{
  203.                    
  204.                         txtSupplierId.setText("");
  205.                         txtSupplierName.setText("");
  206.                         txtSupplierSurname.setText("");
  207.                         txtPhone.setText("");
  208.                         txtAddress.setText("");
  209.                         txtCompanyName.setText("");
  210.                         txtBRN.setText("");
  211.                    
  212.                 }catch(Exception q){
  213.                     JOptionPane.showMessageDialog(null, q);
  214.                 }
  215.             }
  216.            
  217.         });
  218.         JButton btnSave = new JButton("Save");
  219.         btnSave.setBounds(159, 26, 129, 36);
  220.         panel_3.add(btnSave);
  221.         btnSave.setIcon(new ImageIcon(Supplier.class.getResource("/Images/Save.png")));
  222.        
  223.        
  224.         btnSave.addMouseListener(new MouseAdapter() {@Override
  225.             public void mouseClicked(MouseEvent e) {
  226.                 try{
  227.                    
  228.                     Class.forName("com.mysql.jdbc.Driver");
  229.  
  230.                     con = DriverManager.getConnection(url, user, pw);
  231.                                        
  232.                     String fName = txtSupplierName.getText();
  233.                     String lName = txtSupplierSurname.getText();
  234.                     String comName = txtCompanyName.getText();
  235.                     String add = txtAddress.getText();
  236.                     String phone = txtPhone.getText();
  237.                     String brn = txtBRN.getText();
  238.                    
  239.                     PreparedStatement ptt = con.prepareStatement("INSERT INTO supplier (SupplierName, SupplierSurname, "
  240.                                                     + "PhoneNumber, Address, CompanyName, BRN) values (?,?,?,?,?,?)");
  241.                    
  242.                     ptt.setString(1, fName);
  243.                     ptt.setString(2, lName);
  244.                     ptt.setString(3, comName);
  245.                     ptt.setString(4, add);
  246.                     ptt.setString(5, phone);
  247.                     ptt.setString(6, brn);
  248.                    
  249.                     ptt.execute();
  250.                    
  251.                     JOptionPane.showMessageDialog(null, "Supplier Added Successfully");
  252.                 }catch(Exception e1){
  253.                    
  254.                     e1.printStackTrace();
  255.                 }
  256.             }
  257.         });
  258.        
  259.  
  260.        
  261.         JButton btnCancel = new JButton("Cancel");
  262.         btnCancel.setIcon(new ImageIcon(Supplier.class.getResource("/Images/trash_delete.png")));
  263.         btnCancel.setBounds(447, 26, 129, 36);
  264.         panel_3.add(btnCancel);
  265.        
  266.         JPanel panel_6 = new JPanel();
  267.         panel_6.setBounds(41, 261, 990, 434);
  268.         contentPane.add(panel_6);
  269.         panel_6.setLayout(null);
  270.         panel_6.setForeground(SystemColor.inactiveCaptionBorder);
  271.         panel_6.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Supplier Details", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  272.         panel_6.setBackground(SystemColor.inactiveCaptionBorder);
  273.        
  274.         JLabel lblFirstName = new JLabel("First Name");
  275.         lblFirstName.setBounds(52, 52, 74, 14);
  276.         panel_6.add(lblFirstName);
  277.        
  278.         JLabel lblLastName = new JLabel("Last Name");
  279.         lblLastName.setBounds(52, 111, 74, 14);
  280.         panel_6.add(lblLastName);
  281.        
  282.         txtSupplierName = new JTextField();
  283.         txtSupplierName.setColumns(10);
  284.         txtSupplierName.setBounds(144, 52, 161, 26);
  285.         panel_6.add(txtSupplierName);
  286.        
  287.         txtSupplierSurname = new JTextField();
  288.         txtSupplierSurname.setColumns(10);
  289.         txtSupplierSurname.setBounds(144, 105, 161, 26);
  290.         panel_6.add(txtSupplierSurname);
  291.        
  292.         JLabel lblAddress = new JLabel("Address");
  293.         lblAddress.setBounds(52, 220, 74, 14);
  294.         panel_6.add(lblAddress);
  295.        
  296.         txtAddress = new JTextArea();
  297.         txtAddress.setBounds(147, 215, 235, 65);
  298.         panel_6.add(txtAddress);
  299.        
  300.         JPanel panel_1 = new JPanel();
  301.         panel_1.setLayout(null);
  302.         panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Navigate", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  303.         panel_1.setBackground(SystemColor.inactiveCaptionBorder);
  304.         panel_1.setBounds(753, 26, 205, 93);
  305.         panel_6.add(panel_1);
  306.        
  307.         JButton btnPrevious = new JButton("");
  308.         btnPrevious.setIcon(new ImageIcon(Supplier.class.getResource("/Images/previous.png")));
  309.         btnPrevious.setBounds(42, 26, 56, 36);
  310.         panel_1.add(btnPrevious);
  311.        
  312.         btnPrevious.addMouseListener(new MouseAdapter() {
  313.            
  314.             public void mouseClicked(MouseEvent e) {
  315.                
  316.                 try{
  317.                    
  318.                     if (rs.previous()) {
  319.                        
  320.                         Integer supID = rs.getInt("SupplierID");
  321.                         String SupName = rs.getString("SupplierName");
  322.                         String supSurname = rs.getString("SupplierSurname");
  323.                         String phone = rs.getString("PhoneNumber");
  324.                         String add = rs.getString("Address");
  325.                         String comp = rs.getString("CompanyName");
  326.                         String brn = rs.getString("BRN");
  327.                        
  328.                        
  329.                         txtSupplierId.setText(supID.toString());
  330.                         txtSupplierName.setText(SupName);
  331.                         txtSupplierSurname.setText(supSurname);
  332.                         txtPhone.setText(phone);
  333.                         txtAddress.setText(add);
  334.                         txtCompanyName.setText(comp);
  335.                         txtBRN.setText(brn);
  336.                            
  337.                        
  338.                     } else {
  339.                        
  340.                         rs.next();
  341.                         JOptionPane.showMessageDialog(Supplier.this, "End of file");
  342.                     }
  343.                    
  344.                 } catch(Exception p){
  345.                    
  346.                 }
  347.             }
  348.            
  349.         });
  350.        
  351.         JButton btnNext = new JButton("");
  352.         btnNext.setIcon(new ImageIcon(Supplier.class.getResource("/Images/br_next.png")));
  353.         btnNext.setBounds(108, 26, 56, 36);
  354.         panel_1.add(btnNext);
  355.        
  356.        
  357.         btnNext.addMouseListener(new MouseAdapter() {
  358.             @Override
  359.             public void mouseClicked(MouseEvent e) {
  360.                
  361.                 try {
  362.                    
  363.                     if (rs.next()) {
  364.                        
  365.                         Integer supID = rs.getInt("SupplierID");
  366.                         String SupName = rs.getString("SupplierName");
  367.                         String supSurname = rs.getString("SupplierSurname");
  368.                         String phone = rs.getString("PhoneNumber");
  369.                         String add = rs.getString("Address");
  370.                         String comp = rs.getString("CompanyName");
  371.                         String brn = rs.getString("BRN");
  372.                        
  373.                        
  374.                         txtSupplierId.setText(supID.toString());
  375.                         txtSupplierName.setText(SupName);
  376.                         txtSupplierSurname.setText(supSurname);
  377.                         txtPhone.setText(phone);
  378.                         txtAddress.setText(add);
  379.                         txtCompanyName.setText(comp);
  380.                         txtBRN.setText(brn);
  381.                        
  382.                            
  383.                     } else {
  384.                        
  385.                         rs.previous();
  386.                         JOptionPane.showMessageDialog(Supplier.this, "End of file");
  387.                     }
  388.                    
  389.                 } catch (SQLException err) {
  390.                     JOptionPane.showMessageDialog(Supplier.this, err.getMessage());
  391.                 }
  392.                
  393.             }
  394.         });
  395.        
  396.        
  397.         txtPhone = new JTextField();
  398.         txtPhone.setColumns(10);
  399.         txtPhone.setBounds(144, 314, 161, 26);
  400.         panel_6.add(txtPhone);
  401.        
  402.         JLabel lblPhoneNum = new JLabel("Phone Num.");
  403.         lblPhoneNum.setBounds(52, 320, 74, 14);
  404.         panel_6.add(lblPhoneNum);
  405.        
  406.         JLabel lblCompanyName = new JLabel("Company Name");
  407.         lblCompanyName.setBounds(52, 166, 87, 14);
  408.         panel_6.add(lblCompanyName);
  409.        
  410.         txtCompanyName = new JTextField();
  411.         txtCompanyName.setColumns(10);
  412.         txtCompanyName.setBounds(144, 160, 161, 26);
  413.         panel_6.add(txtCompanyName);
  414.        
  415.         JLabel lblBrn = new JLabel("BRN");
  416.         lblBrn.setBounds(390, 58, 87, 14);
  417.         panel_6.add(lblBrn);
  418.        
  419.         txtBRN = new JTextField();
  420.         txtBRN.setColumns(10);
  421.         txtBRN.setBounds(482, 52, 161, 26);
  422.         panel_6.add(txtBRN);
  423.        
  424.        
  425.     }
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement