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 / EXPENSEVIEW.JAVA < prev    next >
Encoding:
Java Source  |  1997-02-21  |  14.4 KB  |  389 lines

  1. /**************************************************************************************************
  2. *                                                                                                 *
  3. *  Class name:   expenseView                                                                      *
  4. *                                                                                                 *
  5. *     Purpose:   Extends Panel to allow users to view expense report stored in the database.      *
  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 class expenseView extends Panel                                        *
  16. *                   public expenseView(Applet parent, String empID)                               *
  17. *                   public synchronized void show()                                               *
  18. *                   public void clearAllControls ()                                               *
  19. *                   public void clickedMainMenubutton()                                           *
  20. *                   public void disableControls ()                                                *
  21. *                   public void getEmployeeInfo(String empID)                                     *
  22. *                   public void selectedFind()                                                    *
  23. *                   public void setIDFunct (String empID)                                         *
  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 expenseView extends Panel {
  50.  
  51.     expenseApplet exp;
  52.     public expenseView(Applet parent, String empID) {
  53.  
  54.         exp = (expenseApplet)parent;
  55.  
  56.         //{{INIT_CONTROLS
  57.         setLayout(null);
  58.         resize(insets().left + insets().right + 741, insets().top + insets().bottom + 494);
  59.  
  60.         label9=new Label("Employee #");
  61.         add(label9);
  62.         label9.reshape(insets().left + 16,insets().top + 43,100,15);
  63.  
  64.         employeenum=new TextField(14);
  65.         add(employeenum);
  66.         employeenum.reshape(insets().left + 119,insets().top + 43,189,25);
  67.  
  68.         find=new Button("Find");
  69.         add(find);
  70.         find.reshape(insets().left + 308,insets().top + 43,35,25);
  71.  
  72.         firstname=new TextField(22);
  73.         add(firstname);
  74.         firstname.reshape(insets().left + 119,insets().top + 84,224,25);
  75.  
  76.         label2=new Label("First Name");
  77.         add(label2);
  78.         label2.reshape(insets().left + 16,insets().top + 84,100,15);
  79.  
  80.         label3=new Label("Last Name");
  81.         add(label3);
  82.         label3.reshape(insets().left + 395,insets().top + 84,100,15);
  83.  
  84.         lastname=new TextField(22);
  85.         add(lastname);
  86.         lastname.reshape(insets().left + 497,insets().top + 84,224,25);
  87.  
  88.         label4=new Label("Address");
  89.         add(label4);
  90.         label4.reshape(insets().left + 16,insets().top + 124,70,15);
  91.  
  92.         address=new TextField(31);
  93.         add(address);
  94.         address.reshape(insets().left + 119,insets().top + 124,224,25);
  95.  
  96.         city=new TextField(22);
  97.         add(city);
  98.         city.reshape(insets().left + 119,insets().top + 159,224,25);
  99.  
  100.         label5=new Label("City");
  101.         add(label5);
  102.         label5.reshape(insets().left + 16,insets().top + 159,70,15);
  103.  
  104.         label6=new Label("State");
  105.         add(label6);
  106.         label6.reshape(insets().left + 16,insets().top + 199,100,15);
  107.  
  108.         state=new TextField(9);
  109.         add(state);
  110.         state.reshape(insets().left + 119,insets().top + 199,224,25);
  111.  
  112.         label7=new Label("Postal Code");
  113.         add(label7);
  114.         label7.reshape(insets().left + 16,insets().top + 234,100,15);
  115.  
  116.         postalcode=new TextField(9);
  117.         add(postalcode);
  118.         postalcode.reshape(insets().left + 119,insets().top + 234,224,25);
  119.  
  120.         title=new TextField(21);
  121.         add(title);
  122.         title.reshape(insets().left + 497,insets().top + 43,224,26);
  123.  
  124.         label8=new Label("Title");
  125.         add(label8);
  126.         label8.reshape(insets().left + 395,insets().top + 43,70,15);
  127.  
  128.         label10=new Label("Social Security #");
  129.         add(label10);
  130.         label10.reshape(insets().left + 395,insets().top + 124,94,15);
  131.  
  132.         socialsecurity=new TextField(13);
  133.         add(socialsecurity);
  134.         socialsecurity.reshape(insets().left + 497,insets().top + 124,224,26);
  135.  
  136.         email=new TextField(20);
  137.         add(email);
  138.         email.reshape(insets().left + 497,insets().top + 159,224,26);
  139.  
  140.         label11=new Label("Email");
  141.         add(label11);
  142.         label11.reshape(insets().left + 395,insets().top + 159,70,15);
  143.  
  144.         label12=new Label("Dept Name");
  145.         add(label12);
  146.         label12.reshape(insets().left + 395,insets().top + 199,100,15);
  147.  
  148.         deptname=new TextField(20);
  149.         add(deptname);
  150.         deptname.reshape(insets().left + 497,insets().top + 199,224,26);
  151.  
  152.         label13=new Label("Home Phone");
  153.         add(label13);
  154.         label13.reshape(insets().left + 395,insets().top + 234,100,15);
  155.  
  156.         homephone=new TextField(13);
  157.         add(homephone);
  158.         homephone.reshape(insets().left + 497,insets().top + 234,224,25);
  159.  
  160.         label14=new Label("Country");
  161.         add(label14);
  162.         label14.reshape(insets().left + 16,insets().top + 274,70,15);
  163.  
  164.         country=new TextField(21);
  165.         add(country);
  166.         country.reshape(insets().left + 119,insets().top + 274,224,25);
  167.  
  168.         label15=new Label("Work Phone");
  169.         add(label15);
  170.         label15.reshape(insets().left + 395,insets().top + 274,100,15);
  171.  
  172.         workphone=new TextField(13);
  173.         add(workphone);
  174.         workphone.reshape(insets().left + 497,insets().top + 274,224,25);
  175.  
  176.         //list1=new List();
  177.         //list1.setFont(new Font("Courier",Font.PLAIN,8));
  178.         //add(list1);
  179.         //list1.reshape(insets().left + 48,insets().top + 353,681,75);
  180.  
  181.         exprptbutton=new Button("Expense Report Name");
  182.         add(exprptbutton);
  183.         exprptbutton.reshape(insets().left + 46,insets().top + 317,156,30);
  184.  
  185.         datebutton=new Button("Date Submitted");
  186.         add(datebutton);
  187.         datebutton.reshape(insets().left + 202,insets().top + 317,105,30);
  188.  
  189.         advancebutton=new Button("Advance");
  190.         add(advancebutton);
  191.         advancebutton.reshape(insets().left + 305,insets().top + 317,108,30);
  192.  
  193.         totalepensebutton=new Button("Total Expenses");
  194.         add(totalepensebutton);
  195.         totalepensebutton.reshape(insets().left + 410,insets().top + 317,140,30);
  196.  
  197.         amountbutton=new Button("Amount due");
  198.         add(amountbutton);
  199.         amountbutton.reshape(insets().left + 546,insets().top + 317,125,30);
  200.  
  201.         paidbutton=new Button("Paid");
  202.         add(paidbutton);
  203.         paidbutton.reshape(insets().left + 670,insets().top + 317,61,30);
  204.  
  205.         MainMenubutton=new Button("Main Menu");
  206.         add(MainMenubutton);
  207.         MainMenubutton.reshape(insets().left + 370,insets().top + 430,70,30);
  208.  
  209.         titlelabel=new Label("Employee Expense View");
  210.         titlelabel.setFont(new Font("Dialog",Font.BOLD,14));
  211.         add(titlelabel);
  212.         titlelabel.reshape(insets().left + 307,insets().top + 10,210,15);
  213.         //}}
  214.  
  215.         disableControls ();
  216.         if (empID != null) setIDFunct (empID);
  217.  
  218.     }
  219.  
  220.     public synchronized void show() {
  221.            super.show();
  222.     }
  223.  
  224.     public boolean handleEvent(Event event) {
  225.         if (event.id == Event.ACTION_EVENT && event.target == find) {
  226.             clearAllControls ();
  227.               selectedFind();
  228.                return true;
  229.         }
  230.         else
  231.         if (event.id == Event.ACTION_EVENT && event.target == employeenum) {
  232.             clearAllControls ();
  233.                getEmployeeInfo(employeenum.getText());
  234.                exp.getExpenseInfo(employeenum.getText());
  235.                return true;
  236.         }
  237.         else
  238.         if (event.id == Event.ACTION_EVENT && event.target == MainMenubutton) {
  239.             clearAllControls ();
  240.             clickedMainMenubutton();
  241.                return true;
  242.         }
  243.  
  244.         return super.handleEvent(event);
  245.     }
  246.  
  247.  
  248.     //{{DECLARE_CONTROLS
  249.     TextField firstname;
  250.     Label label2;
  251.     Label label3;
  252.     TextField lastname;
  253.     Label label4;
  254.     TextField address;
  255.     TextField city;
  256.     Label label5;
  257.     Label label6;
  258.     TextField state;
  259.     Label label7;
  260.     TextField postalcode;
  261.     TextField title;
  262.     Label label8;
  263.     Label label9;
  264.     TextField employeenum;
  265.     Label label10;
  266.     TextField socialsecurity;
  267.     TextField email;
  268.     Label label11;
  269.     Label label12;
  270.     TextField deptname;
  271.     Label label13;
  272.     TextField homephone;
  273.     Label label14;
  274.     TextField country;
  275.     Label label15;
  276.     TextField workphone;
  277.     List list1;
  278.     Button exprptbutton;
  279.     Button datebutton;
  280.     Button advancebutton;
  281.     Button totalepensebutton;
  282.     Button amountbutton;
  283.     Button paidbutton;
  284.     Button find;
  285.     Button MainMenubutton;
  286.     Label titlelabel;
  287.     //}}
  288.  
  289.     public void selectedFind() {
  290.         this.hide();
  291.         exp.clickedFind();
  292.     }
  293.  
  294.     public void disableControls () {
  295.         firstname.setEditable(false);
  296.         lastname.setEditable(false);
  297.         address.setEditable(false);
  298.         city.setEditable(false);
  299.         state.setEditable(false);
  300.         postalcode.setEditable(false);
  301.         title.setEditable(false);
  302.         socialsecurity.setEditable(false);
  303.         email.setEditable(false);
  304.         deptname.setEditable(false);
  305.         homephone.setEditable(false);
  306.         country.setEditable(false);
  307.         workphone.setEditable(false);
  308.     }
  309.  
  310.  
  311.     public void clickedMainMenubutton() {
  312.        hide();
  313.  
  314.     }
  315.  
  316.  
  317. //****  get employee information from database  *******
  318.  
  319.     public void getEmployeeInfo(String empID) {
  320.         Statement  s;
  321.         ResultSet rs;
  322.  
  323.         /**********************  Query the Employees Table  ******************************/
  324.         try
  325.         {
  326.             s = (Statement)exp.connection.createStatement();
  327.             rs = (ResultSet)s.executeQuery("select DepartmentName, SocialSecurityNumber, FirstName, LastName, Title, EmailName, Address, City, StateOrProvince, PostalCode, Country, HomePhone, WorkPhone from Employees where EmployeeID = '" + employeenum.getText() + "'");
  328.  
  329.             deptname.setText(rs.getString(1));
  330.             socialsecurity.setText(rs.getString(2));
  331.             firstname.setText(rs.getString(3));
  332.             lastname.setText(rs.getString(4));
  333.             title.setText(rs.getString(5));
  334.             email.setText(rs.getString(6));
  335.             address.setText(rs.getString(7));
  336.             city.setText(rs.getString(8));
  337.             state.setText(rs.getString(9));
  338.             postalcode.setText(rs.getString(10));
  339.             country.setText(rs.getString(11));
  340.             homephone.setText(rs.getString(12));
  341.             workphone.setText(rs.getString(13));
  342.  
  343.             s.close();
  344.         }
  345.         catch (SQLException e)
  346.         {
  347.             System.out.println(e.getMessage());
  348.             clearAllControls();
  349.             return;
  350.         }
  351.         /**********************************************************************************/
  352.     }
  353.  
  354. //**** clear control fields ******
  355.  
  356.     public void clearAllControls () {
  357.         firstname.setText(null);
  358.         lastname.setText(null);
  359.         address.setText(null);
  360.         city.setText(null);
  361.         state.setText(null);
  362.         postalcode.setText(null);
  363.         title.setText(null);
  364.         socialsecurity.setText(null);
  365.         email.setText(null);
  366.         deptname.setText(null);
  367.         homephone.setText(null);
  368.         country.setText(null);
  369.         workphone.setText(null);
  370.        /* if (list1.countItems() > 0)
  371.             list1.delItems(0, list1.countItems()-1);*/
  372.     }
  373.  
  374.  
  375.  
  376.  
  377.     public void setIDFunct (String empID) {
  378.         employeenum.setText(empID);
  379.         getEmployeeInfo(empID);
  380.         exp.getExpenseInfo(empID);
  381.     }
  382. }
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.