Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.table.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.event.ActionListener;
- import java.sql.*;
- import java.util.Vector;
- public class Project_SalesDatabase extends JPanel {
- JTabbedPane tabbedPane = new JTabbedPane();
- ImageIcon icon = createImageIcon("images/middle.gif");
- JButton view = new JButton(" View ");
- JButton save = new JButton(" Save ");
- JButton addNew = new JButton(" Add New ");
- JButton exit = new JButton(" Exit Application ");
- JPanel displayBiscuitsPanel = new JPanel();
- JPanel displayCookingPanel = new JPanel();
- JPanel displayCustomersPanel = new JPanel();
- JPanel displayEmployeesPanel = new JPanel();
- JPanel displayProvisionsPanel = new JPanel();
- JPanel displayButton = new JPanel();
- JPanel displayContent = new JPanel(new GridLayout(0, 2));
- JPanel displayTable = new JPanel(new GridLayout(1, 1));
- JTextField biscuitName = new JTextField();
- JTextField biscuitPrice = new JTextField();
- JTextField biscuitCompany = new JTextField();
- JTextField quantityOfBiscuitsBought = new JTextField();
- JTextField quantityOfBiscuitsSold = new JTextField();
- JTextField quantityInStock = new JTextField();
- JTextField itemName = new JTextField();
- JTextField itemPrice = new JTextField();
- JTextField itemType = new JTextField();
- JTextField quantityOfitemsBought = new JTextField();
- JTextField quantityOfitemsSold = new JTextField();
- JTextField firstName = new JTextField();
- JTextField lastName = new JTextField();
- JTextField customerAttendant = new JTextField();
- JTextField customerAttendantPosition = new JTextField();
- JTextField isCustomerADebtor = new JTextField();
- JTextField orderNumber = new JTextField();
- JTextField debtAmount = new JTextField();
- JTextField address = new JTextField();
- JTextField phoneNumber = new JTextField();
- JTextField position = new JTextField();
- JTextField age = new JTextField();
- JTextField salary = new JTextField();
- JTextField nextOfKin = new JTextField();
- JTextField relationshipWithNextOfKin = new JTextField();
- JTextField nextOfKinPhoneNumber = new JTextField();
- JTextField itemCompany = new JTextField();
- public static void main(String[] args) {
- //Schedule a job for the event dispatch thread:
- //creating and showing this application's GUI.
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- //Turn off metal's use of bold fonts
- UIManager.put("swing.boldMetal", Boolean.FALSE);
- //Create and set up the window.
- JFrame frame = new JFrame("The Royal Ventures International®");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Add content to the window.
- frame.add(new Project_SalesDatabase(), BorderLayout.CENTER);
- //Display the window.
- frame.setSize(1000, 500);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
- public Project_SalesDatabase() {
- super(new GridLayout(1, 1));
- // Create the tab pages
- biscuitsTable();
- cookingIngredientsTable();
- customersTable();
- employeesTable();
- provisionsTable();
- // Create tabs in tabbedPane
- int index = tabbedPane.getTabCount();
- System.out.println(index);
- tabbedPane.addTab("Biscuits Database", icon, displayBiscuitsPanel,
- "Allows you to view or Enter Data into the Biscuits Database");
- tabbedPane.addTab("Cooking Ingredients Database", icon, displayCookingPanel,
- "Allows you to view or Enter Data into the Cooking Ingredients Database");
- tabbedPane.addTab("Customers Database", icon, displayCustomersPanel,
- "Allows you to view or Enter Data into the Customers Database");
- tabbedPane.addTab("Employees Database", icon, displayEmployeesPanel,
- "Allows you to view or Enter Data into the Employees Database");
- tabbedPane.addTab("Provisions Database", icon, displayProvisionsPanel,
- "Allows you to view or Enter Data into the Provisions Database");
- add(tabbedPane);
- //Enable scrolling in tabs.
- tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
- }
- public static ImageIcon createImageIcon(String path) {
- java.net.URL imgURL = Project_SalesDatabase.class.getResource(path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- System.err.println("Couldn't find file: " + path);
- return null;
- }
- }
- public final void biscuitsTable() {
- displayBiscuitsPanel.setLayout(new BorderLayout());
- displayBiscuitsPanel.add(displayContent, BorderLayout.CENTER);
- displayBiscuitsPanel.add(displayButton, BorderLayout.SOUTH);
- displayBiscuitsPanel.add(displayTable, BorderLayout.NORTH);
- displayContent.add(new JLabel("Biscuit Name"));
- displayContent.add(biscuitName);
- displayContent.add(new JLabel("Biscuit Price"));
- displayContent.add(biscuitPrice);
- displayContent.add(new JLabel("Biscuit Company"));
- displayContent.add(biscuitCompany);
- displayContent.add(new JLabel("Quantity Of Biscuits Bought"));
- displayContent.add(quantityOfBiscuitsBought);
- displayContent.add(new JLabel("Quantity Of Biscuits Sold"));
- displayContent.add(quantityOfBiscuitsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- displayButton.add(addNew);
- displayButton.add(save);
- displayButton.add(view);
- displayButton.add(exit);
- view.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = null;
- ResultSet set = null;
- try {
- String Query = "SELECT * FROM Biscuits";
- state = con.createStatement();
- set = state.executeQuery(Query);
- boolean nextrec = set.next();
- if (!nextrec) {
- JOptionPane.showMessageDialog(null, "No Record");
- } else {
- Vector col = new Vector();
- Vector row = new Vector();
- ResultSetMetaData rsm = set.getMetaData();
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- col.addElement(rsm.getColumnName(x));
- }
- do {
- row.addElement(getNextRow(set, rsm));
- } while (set.next());
- JTable tab = new JTable(row, col);
- displayContent.removeAll();
- displayTable.removeAll();
- displayTable.add(new JScrollPane(tab), BorderLayout.CENTER);
- validate();
- }
- state.close();
- } catch (SQLException sql) {
- JOptionPane.showMessageDialog(null, sql.getMessage());
- }
- }
- });
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- String Query = "INSERT INTO Biscuits VALUES ('" + biscuitName.getText() + "',"
- + " '" + biscuitPrice.getText() + "',"
- + " '" + biscuitCompany.getText() + "',"
- + " '" + quantityOfBiscuitsBought.getText() + "',"
- + " '" + quantityOfBiscuitsSold.getText() + "',"
- + " '" + quantityInStock.getText() + "')";
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = con.createStatement();
- int rep = state.executeUpdate(Query);
- if (rep == 0) {
- JOptionPane.showMessageDialog(null, "No Data Saved");
- } else {
- JOptionPane.showMessageDialog(null, "Data Saved");
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- }
- });
- addNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- biscuitName.setText("");
- biscuitPrice.setText("");
- biscuitCompany.setText("");
- quantityOfBiscuitsBought.setText("");
- quantityOfBiscuitsSold.setText("");
- quantityInStock.setText("");
- displayTable.removeAll();
- displayContent.removeAll();
- displayContent.add(new JLabel("Biscuit Name"));
- displayContent.add(biscuitName);
- displayContent.add(new JLabel("Biscuit Price"));
- displayContent.add(biscuitPrice);
- displayContent.add(new JLabel("Biscuit Company"));
- displayContent.add(biscuitCompany);
- displayContent.add(new JLabel("Quantity Of Biscuits Bought"));
- displayContent.add(quantityOfBiscuitsBought);
- displayContent.add(new JLabel("Quantity Of Biscuits Sold"));
- displayContent.add(quantityOfBiscuitsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- validate();
- } catch (Exception f) {
- f.getMessage();
- }
- }
- });
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- public final void cookingIngredientsTable() {
- displayCookingPanel.setLayout(new BorderLayout());
- displayCookingPanel.add(displayContent, BorderLayout.CENTER);
- displayCookingPanel.add(displayButton, BorderLayout.SOUTH);
- displayCookingPanel.add(displayTable, BorderLayout.NORTH);
- displayContent.add(new JLabel("Item Name"));
- displayContent.add(itemName);
- displayContent.add(new JLabel("Item Price"));
- displayContent.add(itemPrice);
- displayContent.add(new JLabel("Item Type"));
- displayContent.add(itemType);
- displayContent.add(new JLabel("Quantity Of Items Bought"));
- displayContent.add(quantityOfitemsBought);
- displayContent.add(new JLabel("Quantity Of Items Sold"));
- displayContent.add(quantityOfitemsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- displayButton.add(addNew);
- displayButton.add(save);
- displayButton.add(view);
- displayButton.add(exit);
- view.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = null;
- ResultSet set = null;
- try {
- String Query = "SELECT * FROM CookingIngredients";
- state = con.createStatement();
- set = state.executeQuery(Query);
- boolean nextrec = set.next();
- if (!nextrec) {
- JOptionPane.showMessageDialog(null, "No Record");
- } else {
- Vector col = new Vector();
- Vector row = new Vector();
- ResultSetMetaData rsm = set.getMetaData();
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- col.addElement(rsm.getColumnName(x));
- }
- do {
- row.addElement(getNextRow(set, rsm));
- } while (set.next());
- JTable tab = new JTable(row, col);
- displayContent.removeAll();
- displayTable.removeAll();
- displayTable.add(new JScrollPane(tab), BorderLayout.CENTER);
- validate();
- }
- state.close();
- } catch (SQLException sql) {
- JOptionPane.showMessageDialog(null, sql.getMessage());
- }
- }
- });
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- String Query = "INSERT INTO CookingIngredients VALUES ('" + itemName.getText() + "',"
- + " '" + itemPrice.getText() + "',"
- + " '" + itemType.getText() + "',"
- + " '" + quantityOfitemsBought.getText() + "',"
- + " '" + quantityOfitemsSold.getText() + "',"
- + " '" + quantityInStock.getText() + "')";
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = con.createStatement();
- int rep = state.executeUpdate(Query);
- if (rep == 0) {
- JOptionPane.showMessageDialog(null, "No Data Saved");
- } else {
- JOptionPane.showMessageDialog(null, "Data Saved");
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- }
- });
- addNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- itemName.setText("");
- itemPrice.setText("");
- itemType.setText("");
- quantityOfitemsBought.setText("");
- quantityOfBiscuitsSold.setText("");
- quantityOfitemsSold.setText("");
- quantityInStock.setText("");
- displayTable.removeAll();
- displayContent.removeAll();
- displayContent.add(new JLabel("Item Name"));
- displayContent.add(itemName);
- displayContent.add(new JLabel("Item Price"));
- displayContent.add(itemPrice);
- displayContent.add(new JLabel("Item Type"));
- displayContent.add(itemType);
- displayContent.add(new JLabel("Quantity Of Items Bought"));
- displayContent.add(quantityOfitemsBought);
- displayContent.add(new JLabel("Quantity Of Items Sold"));
- displayContent.add(quantityOfitemsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- validate();
- } catch (Exception f) {
- f.getMessage();
- }
- }
- });
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- public final void customersTable() {
- displayCustomersPanel.setLayout(new BorderLayout());
- displayCustomersPanel.add(displayContent, BorderLayout.CENTER);
- displayCustomersPanel.add(displayButton, BorderLayout.SOUTH);
- displayCustomersPanel.add(displayTable, BorderLayout.NORTH);
- displayContent.add(new JLabel("First Name"));
- displayContent.add(firstName);
- displayContent.add(new JLabel("Last Name"));
- displayContent.add(lastName);
- displayContent.add(new JLabel("Customer Attendant"));
- displayContent.add(customerAttendant);
- displayContent.add(new JLabel("Customer Attendant's Position"));
- displayContent.add(customerAttendantPosition);
- displayContent.add(new JLabel("Is This Customer A Debtor?"));
- displayContent.add(isCustomerADebtor);
- displayContent.add(new JLabel("Order Number"));
- displayContent.add(orderNumber);
- displayContent.add(new JLabel("Debt Amount"));
- displayContent.add(debtAmount);
- displayContent.add(new JLabel("Customer's Address"));
- displayContent.add(address);
- displayContent.add(new JLabel("Customer's Phone Number"));
- displayContent.add(phoneNumber);
- displayButton.add(addNew);
- displayButton.add(save);
- displayButton.add(view);
- displayButton.add(exit);
- view.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = null;
- ResultSet set = null;
- try {
- String Query = "SELECT * FROM CustomersNames";
- state = con.createStatement();
- set = state.executeQuery(Query);
- boolean nextrec = set.next();
- if (!nextrec) {
- JOptionPane.showMessageDialog(null, "No Record");
- } else {
- Vector col = new Vector();
- Vector row = new Vector();
- ResultSetMetaData rsm = set.getMetaData();
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- col.addElement(rsm.getColumnName(x));
- }
- do {
- row.addElement(getNextRow(set, rsm));
- } while (set.next());
- JTable tab = new JTable(row, col);
- displayContent.removeAll();
- displayTable.removeAll();
- displayTable.add(new JScrollPane(tab), BorderLayout.CENTER);
- validate();
- }
- state.close();
- } catch (SQLException sql) {
- JOptionPane.showMessageDialog(null, sql.getMessage());
- }
- }
- });
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- String Query = "INSERT INTO CustomersNames VALUES ('" + firstName.getText() + "',"
- + " '" + lastName.getText() + "',"
- + " '" + customerAttendant.getText() + "')"
- + " '" + customerAttendantPosition.getText() + "')"
- + " '" + isCustomerADebtor.getText() + "')"
- + " '" + orderNumber.getText() + "')"
- + " '" + debtAmount.getText() + "')"
- + " '" + address.getText() + "')"
- + " '" + phoneNumber.getText() + "')";
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = con.createStatement();
- int rep = state.executeUpdate(Query);
- if (rep == 0) {
- JOptionPane.showMessageDialog(null, "No Data Saved");
- } else {
- JOptionPane.showMessageDialog(null, "Data Saved");
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- }
- });
- addNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- firstName.setText("");
- lastName.setText("");
- customerAttendant.setText("");
- customerAttendantPosition.setText("");
- isCustomerADebtor.setText("");
- orderNumber.setText("");
- debtAmount.setText("");
- address.setText("");
- phoneNumber.setText("");
- displayTable.removeAll();
- displayContent.removeAll();
- displayContent.add(new JLabel("First Name"));
- displayContent.add(firstName);
- displayContent.add(new JLabel("Last Name"));
- displayContent.add(lastName);
- displayContent.add(new JLabel("Customer Attendant"));
- displayContent.add(customerAttendant);
- displayContent.add(new JLabel("Customer Attendant's Position"));
- displayContent.add(customerAttendantPosition);
- displayContent.add(new JLabel("Is This Customer A Debtor?"));
- displayContent.add(isCustomerADebtor);
- displayContent.add(new JLabel("Order Number"));
- displayContent.add(orderNumber);
- displayContent.add(new JLabel("Debt Amount"));
- displayContent.add(debtAmount);
- displayContent.add(new JLabel("Customer's Address"));
- displayContent.add(address);
- displayContent.add(new JLabel("Customer's Phone Number"));
- displayContent.add(phoneNumber);
- validate();
- } catch (Exception f) {
- f.getMessage();
- }
- }
- });
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- public final void employeesTable() {
- displayEmployeesPanel.setLayout(new BorderLayout());
- displayEmployeesPanel.add(displayContent, BorderLayout.CENTER);
- displayEmployeesPanel.add(displayButton, BorderLayout.SOUTH);
- displayEmployeesPanel.add(displayTable, BorderLayout.NORTH);
- displayContent.add(new JLabel("First Name"));
- displayContent.add(firstName);
- displayContent.add(new JLabel("Last Name"));
- displayContent.add(lastName);
- displayContent.add(new JLabel("Position"));
- displayContent.add(position);
- displayContent.add(new JLabel("Age"));
- displayContent.add(age);
- displayContent.add(new JLabel("Salary"));
- displayContent.add(salary);
- displayContent.add(new JLabel("Employees's Address"));
- displayContent.add(address);
- displayContent.add(new JLabel("Employees's Phone Number(s)"));
- displayContent.add(phoneNumber);
- displayContent.add(new JLabel("Next of Kin"));
- displayContent.add(nextOfKin);
- displayContent.add(new JLabel("Relationship With Next of Kin"));
- displayContent.add(relationshipWithNextOfKin);
- displayContent.add(new JLabel("Next of Kin's Phone Number(s)"));
- displayContent.add(nextOfKinPhoneNumber);
- displayButton.add(addNew);
- displayButton.add(save);
- displayButton.add(view);
- displayButton.add(exit);
- view.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "Employer";
- String password = "employer";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = null;
- ResultSet set = null;
- try {
- String Query = "SELECT * FROM Employees";
- state = con.createStatement();
- set = state.executeQuery(Query);
- boolean nextrec = set.next();
- if (!nextrec) {
- JOptionPane.showMessageDialog(null, "No Record");
- } else {
- Vector col = new Vector();
- Vector row = new Vector();
- ResultSetMetaData rsm = set.getMetaData();
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- col.addElement(rsm.getColumnName(x));
- }
- do {
- row.addElement(getNextRow(set, rsm));
- } while (set.next());
- JTable tab = new JTable(row, col);
- displayContent.removeAll();
- displayTable.removeAll();
- displayTable.add(new JScrollPane(tab), BorderLayout.CENTER);
- for (int i = 0; i < 10; i++) {
- TableColumn column = null;
- column = tab.getColumnModel().getColumn(i);
- if (i == 5) {
- column.setPreferredWidth(300); //third column is bigger
- } else {
- column.setPreferredWidth(50);
- }
- }
- validate();
- }
- state.close();
- } catch (SQLException sql) {
- JOptionPane.showMessageDialog(null, sql.getMessage());
- }
- }
- });
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- String Query = "INSERT INTO Employees VALUES ('" + firstName.getText() + "',"
- + " '" + lastName.getText() + "',"
- + " '" + position.getText() + "',"
- + " '" + age.getText() + "',"
- + " '" + salary.getText() + "',"
- + " '" + address.getText() + "',"
- + " '" + phoneNumber.getText() + "',"
- + " '" + nextOfKin.getText() + "',"
- + " '" + relationshipWithNextOfKin.getText() + "',"
- + " '" + nextOfKinPhoneNumber.getText() + "')";
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = con.createStatement();
- int rep = state.executeUpdate(Query);
- if (rep == 0) {
- JOptionPane.showMessageDialog(null, "No Data Saved");
- } else {
- JOptionPane.showMessageDialog(null, "Data Saved");
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- }
- });
- addNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- firstName.setText("");
- lastName.setText("");
- position.setText("");
- age.setText("");
- salary.setText("");
- address.setText("");
- phoneNumber.setText("");
- nextOfKin.setText("");
- relationshipWithNextOfKin.setText("");
- nextOfKinPhoneNumber.setText("");
- displayTable.removeAll();
- displayContent.removeAll();
- displayContent.add(new JLabel("First Name"));
- displayContent.add(firstName);
- displayContent.add(new JLabel("Last Name"));
- displayContent.add(lastName);
- displayContent.add(new JLabel("Position"));
- displayContent.add(position);
- displayContent.add(new JLabel("Age"));
- displayContent.add(age);
- displayContent.add(new JLabel("Salary"));
- displayContent.add(salary);
- displayContent.add(new JLabel("Employees's Address"));
- displayContent.add(address);
- displayContent.add(new JLabel("Employees's Phone Number(s)"));
- displayContent.add(phoneNumber);
- displayContent.add(new JLabel("Next of Kin"));
- displayContent.add(nextOfKin);
- displayContent.add(new JLabel("Relationship With Next of Kin"));
- displayContent.add(relationshipWithNextOfKin);
- displayContent.add(new JLabel("Next of Kin's Phone Number(s)"));
- displayContent.add(nextOfKinPhoneNumber);
- validate();
- } catch (Exception f) {
- f.getMessage();
- }
- }
- });
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- public final void provisionsTable() {
- displayProvisionsPanel.setLayout(new BorderLayout());
- displayProvisionsPanel.add(displayContent, BorderLayout.CENTER);
- displayProvisionsPanel.add(displayButton, BorderLayout.SOUTH);
- displayProvisionsPanel.add(displayTable, BorderLayout.NORTH);
- displayContent.add(new JLabel("Item Name"));
- displayContent.add(itemName);
- displayContent.add(new JLabel("Item Price"));
- displayContent.add(itemPrice);
- displayContent.add(new JLabel("Item Company"));
- displayContent.add(itemCompany);
- displayContent.add(new JLabel("Quantity Of Items Bought"));
- displayContent.add(quantityOfitemsBought);
- displayContent.add(new JLabel("Quantity Of Items Sold"));
- displayContent.add(quantityOfitemsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- displayButton.add(addNew);
- displayButton.add(save);
- displayButton.add(view);
- displayButton.add(exit);
- view.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = null;
- ResultSet set = null;
- try {
- String Query = "SELECT * FROM Provisions";
- state = con.createStatement();
- set = state.executeQuery(Query);
- boolean nextrec = set.next();
- if (!nextrec) {
- JOptionPane.showMessageDialog(null, "No Record");
- } else {
- Vector col = new Vector();
- Vector row = new Vector();
- ResultSetMetaData rsm = set.getMetaData();
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- col.addElement(rsm.getColumnName(x));
- }
- do {
- row.addElement(getNextRow(set, rsm));
- } while (set.next());
- JTable tab = new JTable(row, col);
- displayContent.removeAll();
- displayTable.removeAll();
- displayTable.add(new JScrollPane(tab), BorderLayout.CENTER);
- validate();
- }
- state.close();
- } catch (SQLException sql) {
- JOptionPane.showMessageDialog(null, sql.getMessage());
- }
- }
- });
- save.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- String Query = "INSERT INTO Provisions VALUES ('" + itemName.getText() + "',"
- + " '" + itemPrice.getText() + "',"
- + " '" + itemCompany.getText() + "',"
- + " '" + quantityOfitemsBought.getText() + "',"
- + " '" + quantityOfitemsSold.getText() + "',"
- + " '" + quantityInStock.getText() + "')";
- String db_url = "jdbc:odbc:ProjectSalesDatabase";
- String username = "";
- String password = "";
- Connection con = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- con = DriverManager.getConnection(db_url, username, password);
- } catch (ClassNotFoundException | SQLException f) {
- JOptionPane.showMessageDialog(null, f.getMessage());
- }
- Statement state = con.createStatement();
- int rep = state.executeUpdate(Query);
- if (rep == 0) {
- JOptionPane.showMessageDialog(null, "No Data Saved");
- } else {
- JOptionPane.showMessageDialog(null, "Data Saved");
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- }
- });
- addNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- itemName.setText("");
- itemPrice.setText("");
- itemCompany.setText("");
- quantityOfitemsBought.setText("");
- quantityOfitemsSold.setText("");
- quantityInStock.setText("");
- displayTable.removeAll();
- displayContent.removeAll();
- displayContent.add(new JLabel("Item Name"));
- displayContent.add(itemName);
- displayContent.add(new JLabel("Item Price"));
- displayContent.add(itemPrice);
- displayContent.add(new JLabel("Item Company"));
- displayContent.add(itemCompany);
- displayContent.add(new JLabel("Quantity Of Items Bought"));
- displayContent.add(quantityOfitemsBought);
- displayContent.add(new JLabel("Quantity Of Items Sold"));
- displayContent.add(quantityOfitemsSold);
- displayContent.add(new JLabel("Quantity In Stock"));
- displayContent.add(quantityInStock);
- validate();
- } catch (Exception f) {
- f.getMessage();
- }
- }
- });
- exit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- }
- Vector getNextRow(ResultSet set, ResultSetMetaData rsm) {
- Vector currentRow = new Vector();
- try {
- for (int x = 1; x <= rsm.getColumnCount(); x++) {
- switch (rsm.getColumnType(x)) {
- case Types.VARCHAR:
- currentRow.addElement(set.getString(x));
- break;
- case Types.INTEGER:
- currentRow.addElement(new Long(set.getLong(x)));
- break;
- default:
- System.out.println("No column type known");
- break;
- }
- }
- } catch (SQLException sqle) {
- sqle.getMessage();
- }
- return currentRow;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement