home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / DBServ / SAMPLES / SAMPLES.ZIP / EXPENSES / CATEGORYENTRY.JAVA next >
Encoding:
Java Source  |  1997-02-21  |  9.2 KB  |  217 lines

  1. /**************************************************************************************************
  2. *                                                                                                 *
  3. *  Class name:   categoryEntry                                                                    *
  4. *                                                                                                 *
  5. *     Purpose:   Extends Panel to allow user to add new categories for Expenses.                  *
  6. *                                                                                                 *
  7. *     Imports:  java.awt.*                                                                        *
  8. *               java.applet.*                                                                     *
  9. *               symjava.sql.*                                                                     *
  10. *               java.net.*;                                                                       *
  11. *               java.lang.*;                                                                      *
  12. *               java.util.*;                                                                      *
  13. *                                                                                                 *
  14. * Methods include:  public boolean handleEvent(Event event)                                       *
  15. *                   public categoryEntry(Applet parent)                                           *
  16. *                   public class categoryEntry extends Panel                                      *
  17. *                   public String checkFields()                                                   *
  18. *                   public synchronized void show()                                               *
  19. *                   public void clickedclearbutton()                                              *
  20. *                   public void clickedMainMenubutton()                                           *
  21. *                   public void clickedSavebutton()                                               *
  22. *                   public void getMessageBox(String msg)                                         *
  23. *                                                                                                 *
  24. *                                                                                                 *
  25. * Additional Notes:                                                                               *
  26. * THIS SOFTWARE HAS BEEN COMPILED AND EXECUTED SUCCESSFULLY IN SPECIFIC SYMANTEC                  *
  27. * ENVIRONMENTS, AND IS BEING PROVIDED ONLY AS SAMPLE CODE.                                        *
  28. *                                                                                                 *
  29. * SYMANTEC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,          *
  30. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF               *
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SYMANTEC SHALL NOT     *
  32. * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING *
  33. * THIS SOFTWARE OR ITS DERIVATIVES.                                                               *
  34. *                                                                                                 *
  35. *  Please see the Sample Code Configuration item in the Read Me file for additional               *
  36. *  information about the sample database used in this applet.                                     *
  37. *                                                                                                 *
  38. * Copyright (c) 1996 Symantec.  All Rights Reserved.                                              *
  39. *                                                                                                 *
  40. **************************************************************************************************/
  41.  
  42. import java.applet.*;
  43. import java.net.*;
  44. import java.awt.*;
  45. import symjava.sql.*;
  46. import java.lang.*;
  47. import java.util.*;
  48.  
  49. public class categoryEntry extends Panel {
  50.  
  51.     expenseApplet exp;
  52.  
  53.     public categoryEntry(Applet parent) {
  54.  
  55.  
  56.         exp = (expenseApplet)parent;
  57.  
  58.         //{{INIT_CONTROLS
  59.         setLayout(null);
  60.         insets().left -= 60;
  61.         resize(insets().left + insets().right + 770, insets().top + insets().bottom + 390);
  62.  
  63.         label1=new Label("Category ID");
  64.         add(label1);
  65.         label1.reshape(insets().left + 25,insets().top + 47,85,15);
  66.  
  67.         categoryID=new TextField(14);
  68.         add(categoryID);
  69.         categoryID.reshape(insets().left + 165,insets().top + 39,189,25);
  70.  
  71.         label2=new Label("Category Name");
  72.         add(label2);
  73.         label2.reshape(insets().left + 25,insets().top + 126,103,15);
  74.  
  75.         categoryName=new TextField(22);
  76.         add(categoryName);
  77.         categoryName.reshape(insets().left + 165,insets().top + 120,189,26);
  78.  
  79.         label3=new Label("Category Account #");
  80.         add(label3);
  81.         label3.reshape(insets().left + 25,insets().top + 86,119,15);
  82.  
  83.         categoryAccount=new TextField(14);
  84.         add(categoryAccount);
  85.         categoryAccount.reshape(insets().left + 165,insets().top + 79,189,26);
  86.  
  87.         savebutton=new Button("Save");
  88.         add(savebutton);
  89.         savebutton.reshape(insets().left + 50,insets().top + 185,88,26);
  90.  
  91.         clearbutton=new Button("Clear");
  92.         add(clearbutton);
  93.         clearbutton.reshape(insets().left + 150,insets().top + 185,88,26);
  94.  
  95.         MainMenubutton=new Button("Main Menu");
  96.         add(MainMenubutton);
  97.         MainMenubutton.reshape(insets().left + 250,insets().top + 185,88,26);
  98.         //}}
  99.  
  100.  
  101.         categoryID.setEditable(false);
  102.     }
  103.  
  104.     public synchronized void show() {
  105.         super.show();
  106.  
  107.     }
  108.  
  109.     public boolean handleEvent(Event event) {
  110.         if (event.id == Event.ACTION_EVENT && event.target == savebutton) {
  111.                 clickedSavebutton();
  112.                 return true;
  113.         }
  114.         else
  115.         if (event.id == Event.ACTION_EVENT && event.target == clearbutton) {
  116.                 clickedclearbutton();
  117.                 return true;
  118.         }
  119.         else
  120.         if (event.id == Event.ACTION_EVENT && event.target == MainMenubutton) {
  121.                 clickedMainMenubutton();
  122.                 return true;
  123.         }
  124.  
  125.         return super.handleEvent(event);
  126.     }
  127.  
  128.  
  129.     //{{DECLARE_CONTROLS
  130.     Label label1;
  131.     TextField categoryID;
  132.     Label label2;
  133.     TextField categoryName;
  134.     Label label3;
  135.     TextField categoryAccount;
  136.     Label label5;
  137.     Button savebutton;
  138.     Button clearbutton;
  139.     Button MainMenubutton;
  140.     //}}
  141.  
  142.  
  143.  
  144.     /*
  145.     public void getMessageBox(String msg) {
  146.         MessageBox theMessageBox;
  147.         theMessageBox = new MessageBox(this, msg);
  148.         theMessageBox.show();
  149.     }
  150. */
  151.     public void clickedMainMenubutton() {
  152.        hide();
  153.     }
  154.     public void clickedSavebutton() {
  155.         Statement  s, s1;
  156.         ResultSet rs2;
  157.  
  158.         String errMessage = "";
  159.         errMessage = checkFields();
  160.  
  161.         if (errMessage.equals("")) {
  162.  
  163.             String catName = categoryName.getText();
  164.             //int catAccount = (Integer.valueOf(categoryAccount.getText())).intValue();
  165.             String catAccount = categoryAccount.getText();
  166.             int rs =0;
  167.             //String sqlStatement = "Insert into Expense_Categories (ExpenseCategory, ExpenseCategoryAccount) values ('" + catName  + "'," + catAccount + ")";
  168.             String sqlStatement = "insert into Expense_Categories (ExpenseCategory, ExpenseAccountNumber, ExpenseCategoryID) values ('" + catName  + "','" + catAccount + "','" + catAccount + "')";
  169.  
  170.             /**********************   Query the Expense Categories Table   ****************************************/
  171.             try
  172.             {
  173.                 s = (Statement)exp.connection.createStatement();
  174.                 rs = s.executeUpdate(sqlStatement);
  175.                 s1 = (Statement)exp.connection.createStatement();
  176.                 sqlStatement = "Select ExpenseCategoryID from Expense_Categories where ExpenseCategory = '" + catName + "'";
  177.                 rs2 = (ResultSet)s1.executeQuery(sqlStatement);
  178.  
  179.                 categoryID.setText(rs2.getString(1));
  180.  
  181.                 s.close();
  182.             }
  183.             catch (SQLException e)
  184.             {
  185.                 String errmsg = (e.getMessage());
  186.                 System.out.println(errmsg);
  187.                 return;
  188.             }
  189.             /**************************************************************************************************/
  190.         }
  191.         else {
  192.            // getMessageBox(errMessage);
  193.         }
  194.     }
  195.  
  196. //****  clear all entry fields  ****
  197.     public void clickedclearbutton() {
  198.         categoryName.setText(null);
  199.         categoryID.setText(null);
  200.         categoryAccount.setText(null);
  201.     }
  202.  
  203. //****  check that all fields are entered  ****
  204.     public String checkFields() {
  205.         String errMessage = "";
  206.  
  207.         if (categoryName.getText().equals(""))
  208.             errMessage =  "Please enter Category Name        ";
  209.         if (categoryAccount.getText().equals(""))
  210.             errMessage =  "Please enter Category Account         ";
  211.  
  212.         return errMessage;
  213.     }
  214.  
  215. }
  216.  
  217.