Expand|Select|Wrap|Line Numbers
- public void loadDatabase()
- {
- try
- {
- //Load MySQL drivers
- Class.forName("org.gjt.mm.mysql.Driver");
- }
- catch( java.lang.ClassNotFoundException e )
- {
- showStatus("MySQL ORG Package Driver not found ...");
- System.err.println(e.getMessage());
- }
- try
- {
- //Connect to the database
- conBrads_mySQL = DriverManager.getConnection(dbURL);
- }
- catch(SQLException error)
- {
- System.err.println("Unable to Connect to Database");
- }
- try
- {
- Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
- //Create the ResultSet
- rsBrads_mySQL = cmdBrads_mySQL.executeQuery("Select * from Brads_mySQL.Items;");
- loadItemName(rsBrads_mySQL);
- rsBrads_mySQL = cmdBrads_mySQL.executeQuery("Select * from Brads_mySQL.Products;");
- loadProductName(rsBrads_mySQL);
- blnSuccessfulOpen = true;
- }
- catch(SQLException error)
- {
- System.err.println("Error in recordset");
- }
- }
- public void loadItemName(ResultSet rsBrads_mySQL)
- {
- //Fill item list box
- try
- {
- while(rsBrads_mySQL.next())
- {
- lstItems.add(rsBrads_mySQL.getString("ItemName"));
- }
- }
- catch (SQLException error)
- {
- System.err.println("Error in Display Record");
- }
- }
- public void loadProductName(ResultSet rsBrads_mySQL)
- {
- //Fill product list box
- try
- {
- while(rsBrads_mySQL.next())
- {
- lstProducts.add(rsBrads_mySQL.getString("ProductName"));
- }
- }
- catch (SQLException error)
- {
- System.err.println("Error in Display Record");
- }
- }
- public void actionPerformed (ActionEvent event)
- {
- Object objSource = event.getSource();
- if (objSource == btnAddItem && event.getActionCommand() == "Add")
- addItems();
- else if (objSource == btnAdd && event.getActionCommand() == "Add")
- addProducts();
- else if (objSource == btnAddItem)
- saveItems();
- else if(objSource == btnEditItem)
- editItems();
- else if(objSource == btnDeleteItem)
- deleteItems();
- else if(objSource == btnCancelItem)
- cancelItems();
- else if (objSource == btnAdd)
- saveProducts();
- else if(objSource == btnEdit)
- editProducts();
- else if(objSource == btnDelete)
- deleteProducts();
- else if(objSource == btnCancel)
- cancelProducts();
- else if(objSource == btnFirstItem)
- firstItemRecord();
- else if(objSource == btnPreviousItem)
- previousItemRecord();
- else if(objSource == btnNextItem)
- nextItemRecord();
- else if(objSource == btnLastItem)
- lastItemRecord();
- else if(objSource == btnFirst)
- firstProductRecord();
- else if(objSource == btnPrevious)
- previousProductRecord();
- else if(objSource == btnNext)
- nextProductRecord();
- else if(objSource == btnLast)
- lastProductRecord();
- else if(objSource == btnItemDisplay)
- itemResults();
- else if(objSource == btnProductDisplay)
- productResults();
- }
- public void itemStateChanged(ItemEvent event)
- {
- String strItemName = lstItems.getSelectedItem();
- String strProductName = lstProducts.getSelectedItem();
- showStatus("");
- Object objSource = event.getSource();
- if (objSource == lstItems)
- {
- try
- {
- Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
- rsBrads_mySQL = cmdBrads_mySQL.executeQuery(
- "Select * from Brads_mySQL.Items where ItemName = '" + strItemName + "';");
- txtItemName.setText(strItemName);
- displayItemRecord(rsBrads_mySQL);
- itemAlteredState();
- }
- catch(SQLException error)
- {
- showStatus("Error in recordset");
- }
- }
- else if (objSource == lstProducts)
- {
- try
- {
- Statement cmdBrads_mySQL = conBrads_mySQL.createStatement();
- rsBrads_mySQL = cmdBrads_mySQL.executeQuery(
- "Select * from Brads_mySQL.Products where ProductName = '" + strProductName + "';");
- txtProductName.setText(strProductName);
- displayProductRecord(rsBrads_mySQL);
- productAlteredState();
- }
- catch(SQLException error)
- {
- showStatus("Error in recordset");
- }
- }
- }
- public void displayItemRecord(ResultSet rsBrads_mySQL)
- {
- //Display the current record
- try
- {
- if(rsBrads_mySQL.next())
- {
- txtItems.setText(rsBrads_mySQL.getString("ItemID"));
- txtItemName.setText(rsBrads_mySQL.getString("ItemName"));
- txtItemQuantity.setText(rsBrads_mySQL.getString("ItemQuantity"));
- txtItemDescription.setText(rsBrads_mySQL.getString("ItemDescription"));
- showStatus("");
- }
- else
- {
- showStatus("Record not found");
- clearItemTextFields();
- }
- }
- catch (SQLException error)
- {
- showStatus("Error in display record");
- }
- }
- public void displayProductRecord(ResultSet rsBrads_mySQL)
- {
- //Display the current record
- try
- {
- if(rsBrads_mySQL.next())
- {
- txtProduct.setText(rsBrads_mySQL.getString("ProductID"));
- txtProductName.setText(rsBrads_mySQL.getString("ProductName"));
- txtProductQuantity.setText(rsBrads_mySQL.getString("ProductQuantity"));
- txtProductDescription.setText(rsBrads_mySQL.getString("ProductDescription"));
- showStatus("");
- }
- else
- {
- showStatus("Record not found");
- clearProductTextFields();
- }
- }
- catch (SQLException error)
- {
- showStatus("Error in display record");
- }
- }
- public void itemResults()
- {
- //Display the Report
- //try
- //{
- //if(rsBrads_mySQL.next())
- //{
- //txaItemReport.append("" + txtItems.setText(rsBrads_mySQL.getString("ItemID"))
- //+ "\n" + txtItemName.setText(rsBrads_mySQL.getString("ItemName")) + "\n" +
- //txtItemQuantity.setText(rsBrads_mySQL.getString("ItemQuantity")) + "\n" +
- //txtItemDescription.setText(rsBrads_mySQL.getString("ItemDescription")) + "\n\n\n");
- //showStatus("Report Complete");
- //}
- //else
- //{
- //showStatus("Record not found");
- //}
- //}
- //catch (SQLException error)
- //{
- //showStatus("Error trying to Report");
- //}
- }
- public void productResults()
- {
- //Display the Report
- //try
- //{
- //if(rsBrads_mySQL.next())
- //{
- //txaProductReport.append("" + txtProduct.setText(rsBrads_mySQL.getString("ItemID"))
- //+ "\t" + txtProductName.setText(rsBrads_mySQL.getString("ItemName")) + "\t" +
- //txtProductQuantity.setText(rsBrads_mySQL.getString("ItemQuantity")) + "\t" +
- //txtProductDescription.setText(rsBrads_mySQL.getString("ItemDescription")) + "\n\n");
- //showStatus("Report Complete");
- //}
- //else
- //{
- //showStatus("Record not found");
- //}
- //}
- //catch (SQLException error)
- //{
- //showStatus("Error trying to Report");
- //}
- }