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 / EXPENSEENTRYFORM.JAVA < prev    next >
Encoding:
Text File  |  1997-02-21  |  37.8 KB  |  989 lines

  1. /********************************************************************************************************************************************
  2. *                                                                                                                                           *
  3. *  Class name:   expenseEntryForm                                                                                                           *
  4. *                                                                                                                                           *
  5. *     Purpose:   Extends Panel to allow the user to create a new expense report.                                                            *
  6. *                                                                                                                                           *
  7. *     Imports:  java.awt.*                                                                                                                  *
  8. *               java.applet.*                                                                                                               *
  9. *               symjava.sql.*                                                                                                               *
  10. *               java.io.*                                                                                                                   *
  11. *               java.net.*                                                                                                                  *
  12. *               java.lang.*                                                                                                                 *
  13. *               java.util.*                                                                                                                 *
  14. *                                                                                                                                           *
  15. * Methods include:  public boolean getCategories()                                                                                          *
  16. *                   public boolean handleEvent(Event event)                                                                                 *
  17. *                   public expenseEntryForm(Applet parent, Choice empname, Choice cat1, Choice cat2, Choice cat3, Choice cat4, Choice cat5) *
  18. *                   public MessageBox(Frame parent, String errMessage)                                                                      *
  19. *                   public ResultSet getEmployeeName()                                                                                      *
  20. *                   public String checkFields()                                                                                             *
  21. *                   public String getCategoryID(String catName)                                                                             *
  22. *                   public synchronized void wakeUp()                                                                                       *
  23. *                   public void clickedclearbutton()                                                                                        *
  24. *                   public void clickedMainMenubutton()                                                                                     *
  25. *                   public void clickedOKButton()                                                                                           *
  26. *                   public void disableFields()                                                                                             *
  27. *                   public void findMaxRows()                                                                                               *
  28. *                   public void getMessageBox(String msg)                                                                                   *
  29. *                                                                                                                                           *
  30. *                                                                                                                                           *
  31. * Additional Notes:                                                                                                                         *
  32. * THIS SOFTWARE HAS BEEN COMPILED AND EXECUTED SUCCESSFULLY IN SPECIFIC SYMANTEC                                                            *
  33. * ENVIRONMENTS, AND IS BEING PROVIDED ONLY AS SAMPLE CODE.                                                                                  *
  34. *                                                                                                                                           *
  35. * SYMANTEC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,                                                    *
  36. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF                                                         *
  37. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SYMANTEC SHALL NOT                                               *
  38. * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING                                           *
  39. * THIS SOFTWARE OR ITS DERIVATIVES.                                                                                                         *
  40. *                                                                                                                                           *
  41. *  Please see the Sample Code Configuration item in the Read Me file for additional                                                         *
  42. *  information about the sample database used in this applet.                                                                               *
  43. *                                                                                                                                           *
  44. * Copyright (c) 1996 Symantec.  All Rights Reserved.                                                                                        *
  45. *                                                                                                                                           *
  46. ********************************************************************************************************************************************/
  47.  
  48. import java.applet.*;
  49. import java.net.*;
  50. import java.awt.*;
  51. import symjava.sql.*;
  52. import java.lang.*;
  53. import java.util.*;
  54.  
  55. public class expenseEntryForm extends Panel {
  56.     expenseApplet exp;
  57.  
  58.     String expDetails [][]= new String[50][4];
  59.     Component allTexts [][] = new Component[5][4];
  60.     java.util.Date theDate = new java.util.Date();
  61.     java.util.Date theDate1 = new java.util.Date();
  62.     java.util.Date theDate2 = new java.util.Date();
  63.     java.util.Date theDate3 = new java.util.Date();
  64.     java.util.Date theDate4 = new java.util.Date();
  65.     java.util.Date theDate5 = new java.util.Date();
  66.     boolean flag = false;
  67.     int scrollinit = 1;
  68.     int count = 0;
  69.  
  70.  
  71.  
  72.     public expenseEntryForm(Applet parent, Choice empname, Choice cat1, Choice cat2, Choice cat3, Choice cat4, Choice cat5) {
  73.  
  74.         exp = (expenseApplet)parent;
  75.  
  76.         //{{INIT_CONTROLS
  77.         setLayout(null);
  78.  
  79.         resize(insets().left + insets().right + 690, insets().top + insets().bottom + 520);
  80.  
  81.         label1=new Label("Expense Report ID");
  82.         add(label1);
  83.         label1.reshape(insets().left + 77,insets().top + 39,130,15);
  84.  
  85.         reportId=new TextField(9);
  86.         add(reportId);
  87.         reportId.reshape(insets().left + 228,insets().top + 34,128,22);
  88.         reportId.setEditable(false);
  89.  
  90.         label2=new Label("Department Charged");
  91.         add(label2);
  92.         label2.reshape(insets().left + 77,insets().top + 191,142,15);
  93.  
  94.         charged=new TextField(16);
  95.         add(charged);
  96.         charged.reshape(insets().left + 228,insets().top + 186,128,25);
  97.         charged.setEditable(false);
  98.  
  99.         label0=new Label("Employee ID");
  100.         add(label0);
  101.         label0.reshape(insets().left + 411,insets().top + 191,90,15);
  102.  
  103.         employeeID=new TextField(20);
  104.         add(employeeID);
  105.         employeeID.reshape(insets().left + 509,insets().top + 186,128,25);
  106.         employeeID.setEditable(false);
  107.  
  108.         label3=new Label("Expense Report Name");
  109.         add(label3);
  110.         label3.reshape(insets().left + 77,insets().top + 114,144,15);
  111.  
  112.         reportname=new TextField(9);
  113.         add(reportname);
  114.         reportname.reshape(insets().left + 228,insets().top + 109,128,22);
  115.  
  116.         label4=new Label("Description");
  117.         add(label4);
  118.         label4.reshape(insets().left + 75,insets().top + 221,125,15);
  119.  
  120.         description=new TextField(43);
  121.         add(description);
  122.         description.reshape(insets().left + 228,insets().top + 229,408,45);
  123.  
  124.         label6=new Label("Employee Name");
  125.         add(label6);
  126.         label6.reshape(insets().left + 77,insets().top + 154,128,15);
  127.  
  128.         employeename = empname;
  129.       /*  employeename=new Choice();
  130.         add(employeename);
  131.         employeename.reshape(insets().left + 228,insets().top + 146,128,25);
  132. */
  133.  
  134.         label7=new Label("Date Submitted");
  135.         add(label7);
  136.         label7.reshape(insets().left + 77,insets().top + 77,124,15);
  137.  
  138.         datesubmitted=new TextField(9);
  139.         add(datesubmitted);
  140.         datesubmitted.reshape(insets().left + 228,insets().top + 71,128,23);
  141.         datesubmitted.setEditable(false);
  142.  
  143.         advanceLabel=new Label("Advance");
  144.         add(advanceLabel);
  145.         advanceLabel.reshape(insets().left + 411,insets().top + 36,70,15);
  146.  
  147.         advance=new TextField(9);
  148.         add(advance);
  149.         advance.reshape(insets().left + 509,insets().top + 32,128,22);
  150.  
  151.         label9=new Label("Total");
  152.         add(label9);
  153.         label9.reshape(insets().left + 411,insets().top + 75,88,20);
  154.  
  155.         total=new TextField(9);
  156.         add(total);
  157.         total.reshape(insets().left + 509,insets().top + 71,128,21);
  158.         total.setEditable(false);
  159.  
  160.         label10=new Label("Balance Due");
  161.         add(label10);
  162.         label10.reshape(insets().left + 411,insets().top + 116,97,15);
  163.  
  164.         balance=new TextField(9);
  165.         add(balance);
  166.         balance.reshape(insets().left + 509,insets().top + 109,128,24);
  167.         balance.setEditable(false);
  168.  
  169.         label11=new Label("");
  170.         add(label11);
  171.         label11.reshape(insets().left + 411,insets().top + 156,70,15);
  172.  
  173.         paid=new Checkbox("  Paid");
  174.         add(paid);
  175.         paid.reshape(insets().left + 509,insets().top + 150,128,24);
  176.         paid.setBackground(Color.white);
  177.  
  178.         expenseDatebutton=new Button("Expense Date");
  179.         add(expenseDatebutton);
  180.         expenseDatebutton.reshape(insets().left + 67,insets().top + 285,106,26);
  181.  
  182.         expenseCategorybutton=new Button("Expense Category");
  183.         add(expenseCategorybutton);
  184.         expenseCategorybutton.reshape(insets().left + 172,insets().top + 285,136,26);
  185.  
  186.         expenseDescriptionbutton=new Button("Expense Description");
  187.         add(expenseDescriptionbutton);
  188.         expenseDescriptionbutton.reshape(insets().left + 308,insets().top + 285,226,26);
  189.  
  190.         amountbutton=new Button("Amount");
  191.         add(amountbutton);
  192.         amountbutton.reshape(insets().left + 534,insets().top + 285,87,26);
  193.  
  194.         label5=new Label("Expense Entry Form");
  195.         label5.setFont(new Font("Dialog",Font.BOLD,14));
  196.         add(label5);
  197.         label5.reshape(insets().left + 247,insets().top + 8,230,15);
  198.  
  199.         expenseDate1=new TextField(12);
  200.         add(expenseDate1);
  201.         expenseDate1.reshape(insets().left + 68,insets().top + 311,104,22);
  202.         allTexts[0][0] = expenseDate1;
  203.  
  204.         expenseCat1=cat1;
  205.         /*expenseCat1=new Choice();
  206.         add(expenseCat1);
  207.         expenseCat1.reshape(insets().left + 172,insets().top + 311,138,22);*/
  208.         allTexts[0][1] = expenseCat1;
  209.  
  210.         expenseDescr1=new TextField(26);
  211.         add(expenseDescr1);
  212.         expenseDescr1.reshape(insets().left + 310,insets().top + 311,222,22);
  213.         allTexts[0][2] = expenseDescr1;
  214.  
  215.         expenseAmt1=new TextField(10);
  216.         add(expenseAmt1);
  217.         expenseAmt1.reshape(insets().left + 534,insets().top + 311,86,22);
  218.         allTexts[0][3] = expenseAmt1;
  219.  
  220.         expenseDate2=new TextField(12);
  221.         add(expenseDate2);
  222.         expenseDate2.reshape(insets().left + 68,insets().top + 338,104,22);
  223.         allTexts[1][0] = expenseDate2;
  224.  
  225.         expenseCat2=cat2;
  226.         /*expenseCat2=new Choice();
  227.         add(expenseCat2);
  228.         expenseCat2.reshape(insets().left + 172,insets().top + 338,138,22);*/
  229.         allTexts[1][1] = expenseCat2;
  230.  
  231.         expenseDescr2=new TextField(26);
  232.         add(expenseDescr2);
  233.         expenseDescr2.reshape(insets().left + 310,insets().top + 338,222,22);
  234.         allTexts[1][2] = expenseDescr2;
  235.  
  236.         expenseAmt2=new TextField(10);
  237.         add(expenseAmt2);
  238.         expenseAmt2.reshape(insets().left + 534,insets().top + 338,86,22);
  239.         allTexts[1][3] = expenseAmt2;
  240.  
  241.         expenseDate3=new TextField(12);
  242.         add(expenseDate3);
  243.         expenseDate3.reshape(insets().left + 68,insets().top + 366,104,22);
  244.         allTexts[2][0] = expenseDate3;
  245.  
  246.         expenseCat3=cat3;
  247.         /*expenseCat3=new Choice();
  248.         add(expenseCat3);
  249.         expenseCat3.reshape(insets().left + 172,insets().top + 366,138,22);*/
  250.         allTexts[2][1] = expenseCat3;
  251.  
  252.         expenseDescr3=new TextField(26);
  253.         add(expenseDescr3);
  254.         expenseDescr3.reshape(insets().left + 310,insets().top + 366,222,22);
  255.         allTexts[2][2] = expenseDescr3;
  256.  
  257.         expenseAmt3=new TextField(10);
  258.         add(expenseAmt3);
  259.         expenseAmt3.reshape(insets().left + 534,insets().top + 366,86,22);
  260.         allTexts[2][3] = expenseAmt3;
  261.  
  262.         expenseDate4=new TextField(12);
  263.         add(expenseDate4);
  264.         expenseDate4.reshape(insets().left + 68,insets().top + 394,104,22);
  265.         allTexts[3][0] = expenseDate4;
  266.  
  267.         expenseCat4=cat4;
  268.         /*expenseCat4=new Choice();
  269.         add(expenseCat4);
  270.         expenseCat4.reshape(insets().left + 172,insets().top + 394,138,22);*/
  271.         allTexts[3][1] = expenseCat4;
  272.  
  273.         expenseDescr4=new TextField(26);
  274.         add(expenseDescr4);
  275.         expenseDescr4.reshape(insets().left + 310,insets().top + 394,222,22);
  276.         allTexts[3][2] = expenseDescr4;
  277.  
  278.         expenseAmt4=new TextField(10);
  279.         add(expenseAmt4);
  280.         expenseAmt4.reshape(insets().left + 534,insets().top + 394,86,22);
  281.         allTexts[3][3] = expenseAmt4;
  282.  
  283.         expenseDate5=new TextField(12);
  284.         add(expenseDate5);
  285.         expenseDate5.reshape(insets().left + 68,insets().top + 420,104,22);
  286.         allTexts[4][0] = expenseDate5;
  287.  
  288.         expenseCat5=cat5;
  289.         /*expenseCat5=new Choice();
  290.         add(expenseCat5);
  291.         expenseCat5.reshape(insets().left + 172,insets().top + 420,138,22);*/
  292.         allTexts[4][1] = expenseCat5;
  293.  
  294.         expenseDescr5=new TextField(26);
  295.         add(expenseDescr5);
  296.         expenseDescr5.reshape(insets().left + 310,insets().top + 420,222,22);
  297.         allTexts[4][2] = expenseDescr5;
  298.  
  299.         expenseAmt5=new TextField(10);
  300.         add(expenseAmt5);
  301.         expenseAmt5.reshape(insets().left + 534,insets().top + 420,86,22);
  302.         allTexts[4][3] = expenseAmt5;
  303.  
  304.  
  305.         scrollbar1= new Scrollbar(Scrollbar.VERTICAL, 1, 0, 1, 50);
  306.         add(scrollbar1);
  307.         scrollbar1.reshape(insets().left + 621,insets().top + 313,28,130);
  308.  
  309.         button1=new Button("");
  310.         add(button1);
  311.         button1.reshape(insets().left + 621,insets().top + 287,28,26);
  312.  
  313.         savebutton=new Button("Save");
  314.         add(savebutton);
  315.         savebutton.reshape(insets().left + 230,insets().top + 450,88,26);
  316.  
  317.         clearbutton=new Button("Clear");
  318.         add(clearbutton);
  319.         clearbutton.reshape(insets().left + 330,insets().top + 450,88,26);
  320.  
  321.         MainMenubutton=new Button("Main Menu");
  322.         add(MainMenubutton);
  323.         MainMenubutton.reshape(insets().left + 430,insets().top + 450,88,26);
  324.  
  325.  
  326.         expenseDate1.setText(null);
  327.         expenseDescr1.setText(null);
  328.         expenseAmt1.setText(null);
  329.         expenseDate2.setText(null);
  330.         expenseDescr2.setText(null);
  331.         expenseAmt2.setText(null);
  332.         expenseDate3.setText(null);
  333.         expenseDescr3.setText(null);
  334.         expenseAmt3.setText(null);
  335.         expenseDate4.setText(null);
  336.         expenseDescr4.setText(null);
  337.         expenseAmt4.setText(null);
  338.         expenseDate5.setText(null);
  339.         expenseDescr5.setText(null);
  340.         expenseAmt5.setText(null);
  341.  
  342.         datesubmitted.setText(getDate());
  343.        /* getCategories();
  344.         getEmployeeName();*/
  345.     }
  346.  
  347.     public synchronized void show() {
  348.         super.show();
  349.     }
  350.  
  351.     public boolean handleEvent(Event event) {
  352.         if (event.id == Event.ACTION_EVENT && event.target == savebutton) {
  353.             clickedSavebutton();
  354.             return true;
  355.         }
  356.         else
  357.         if (event.id == Event.ACTION_EVENT && event.target == clearbutton) {
  358.             clickedclearbutton();
  359.             return true;
  360.         }
  361.         else
  362.         if (event.id == Event.ACTION_EVENT && event.target == expenseCat1) {
  363.             expenseDate1.setText(getDate());
  364.             return true;
  365.         }
  366.         else
  367.         if (event.id == Event.ACTION_EVENT && event.target == expenseCat2) {
  368.             expenseDate2.setText(getDate());
  369.             return true;
  370.         }
  371.         else
  372.         if (event.id == Event.ACTION_EVENT && event.target == expenseCat3) {
  373.             expenseDate3.setText(getDate());
  374.             return true;
  375.         }
  376.         else
  377.         if (event.id == Event.ACTION_EVENT && event.target == expenseCat4) {
  378.             expenseDate4.setText(getDate());
  379.             return true;
  380.         }
  381.         else
  382.         if (event.id == Event.ACTION_EVENT && event.target == expenseCat5) {
  383.             expenseDate5.setText(getDate());
  384.             return true;
  385.         }
  386.         else
  387.         if (event.id == Event.ACTION_EVENT && event.target == MainMenubutton) {
  388.             clickedMainMenubutton();
  389.             return true;
  390.         }
  391.         else
  392.         if (event.id == Event.ACTION_EVENT && event.target == employeename) {
  393.             employeeID.setText(getEmployeeID());
  394.             charged.setText(getDepartment());
  395.                return true;
  396.         }
  397.         else
  398.         if (event.target instanceof Scrollbar) {
  399.             clickedScrollBar();
  400.             return true;
  401.         }
  402.         else
  403.         if (event.id == Event.WINDOW_DESTROY) {
  404. //            hide();
  405.             return true;
  406.         }
  407.         return super.handleEvent(event);
  408.     }
  409.  
  410.  
  411.     //{{DECLARE_CONTROLS
  412.     Label label1;
  413.     TextField reportId;
  414.     Label label2;
  415.     Choice employeename;
  416.     Label label3;
  417.     TextField reportname;
  418.     Label label4;
  419.     TextField description;
  420.     Label label6;
  421.     TextField charged;
  422.     Label label7;
  423.     TextField datesubmitted;
  424.     Label advanceLabel;
  425.     TextField advance;
  426.     Label label9;
  427.     TextField total;
  428.     Label label10;
  429.     TextField balance;
  430.     Label label11;
  431.     TextField employeeID;
  432.     Label label0;
  433.     Checkbox paid;
  434.     Button expenseDatebutton;
  435.     Button expenseCategorybutton;
  436.     Button expenseDescriptionbutton;
  437.     Button amountbutton;
  438.     Label label5;
  439.     TextField expenseDate1;
  440.     Choice expenseCat1;
  441.     TextField expenseDescr1;
  442.     TextField expenseAmt1;
  443.     TextField expenseDate2;
  444.     Choice expenseCat2;
  445.     TextField expenseDescr2;
  446.     TextField expenseAmt2;
  447.     TextField expenseDate3;
  448.     Choice expenseCat3;
  449.     TextField expenseDescr3;
  450.     TextField expenseAmt3;
  451.     TextField expenseDate4;
  452.     Choice expenseCat4;
  453.     TextField expenseDescr4;
  454.     TextField expenseAmt4;
  455.     TextField expenseDate5;
  456.     Choice expenseCat5;
  457.     TextField expenseDescr5;
  458.     TextField expenseAmt5;
  459.     Scrollbar scrollbar1;
  460.     Button button1;
  461.     Button savebutton;
  462.     Button clearbutton;
  463.     Button MainMenubutton;
  464.     //}}
  465.  
  466.  
  467. /*
  468.     public void getMessageBox(String msg) {
  469.         MessageBox theMessageBox;
  470.         theMessageBox = new MessageBox(this, msg);
  471.         theMessageBox.show();
  472.     }
  473. */
  474.     public void clickedMainMenubutton() {
  475.        hide();
  476.     }
  477.     public void clickedSavebutton() {
  478.         String empID;
  479.  
  480.         String errMessage = "";
  481.         errMessage = checkFields();
  482.  
  483.         if (errMessage.equals("") ){
  484.             empID = getEmployeeID();
  485.             saveExpenseReport(empID);
  486.  
  487.             if (flag == false) {
  488.  
  489.                 for (int i = 0; i < 5; i++) {
  490.                     for (int j = 0; j < 4; j++) {
  491.                         if (allTexts[i][j] instanceof Choice)
  492.                              expDetails[i][j] = ((Choice)allTexts[i][j]).getSelectedItem();
  493.                         else
  494.                              expDetails[i][j] = ((TextField)allTexts[i][j]).getText();
  495.                     }
  496.                 }
  497.                 findMaxRows();
  498.             }
  499.  
  500.             saveExpenseDetails();
  501.             getTotal();
  502.             disableFields();
  503.         }
  504.         else {
  505.          //   getMessageBox(errMessage);
  506.         }
  507.     }
  508.  
  509. //**** clear all entry fields  *************
  510.     public void clickedclearbutton() {
  511.         reportId.setText(null);
  512.         employeeID.setText(null);
  513.         employeename.enable();
  514.         employeename.select("<null>");
  515.         reportname.setText(null);
  516.         description.setText(null);
  517.         charged.setText(null);
  518.         advance.setText(null);
  519.         total.setText(null);
  520.         balance.setText(null);
  521.         paid.setState(false);
  522.         expenseDate1.setText(null);
  523.         expenseDescr1.setText(null);
  524.         expenseAmt1.setText(null);
  525.         expenseDate2.setText(null);
  526.         expenseDescr2.setText(null);
  527.         expenseAmt2.setText(null);
  528.         expenseDate3.setText(null);
  529.         expenseDescr3.setText(null);
  530.         expenseAmt3.setText(null);
  531.         expenseDate4.setText(null);
  532.         expenseDescr4.setText(null);
  533.         expenseAmt4.setText(null);
  534.         expenseDate5.setText(null);
  535.         expenseDescr5.setText(null);
  536.         expenseAmt5.setText(null);
  537.         expenseCat1.enable();
  538.         expenseCat2.enable();
  539.         expenseCat3.enable();
  540.         expenseCat4.enable();
  541.         expenseCat5.enable();
  542.         expenseCat1.select("<null>");
  543.         expenseCat2.select("<null>");
  544.         expenseCat3.select("<null>");
  545.         expenseCat4.select("<null>");
  546.         expenseCat5.select("<null>");
  547.  
  548.         reportId.setEditable(false);
  549.         reportname.setEditable(true);
  550.         description.setEditable(true);
  551.         charged.setEditable(false);
  552.         advance.setEditable(true);
  553.         employeeID.setEditable(false);
  554.  
  555.         for (int i = 0; i < 5; i++) {
  556.             for ( int j = 0; j < 4; j++) {
  557.                 if (allTexts[i][j] instanceof TextField) {
  558.                     ((TextField)allTexts[i][j]).setEditable(true);
  559.                     ((TextField)allTexts[i][j]).setText(" ");
  560.                 }
  561.             }
  562.         }
  563.     }
  564.  
  565.     public String getDate() {
  566.         java.util.Date theDate = new java.util.Date();
  567.         int month = theDate.getMonth() + 1;
  568.         String it = (month + "/" + theDate.getDate() + "/" + theDate.getYear());
  569.         return it;
  570.     }
  571.  
  572. //****  save and update entries when scrollbar is moved  *****
  573.     public void clickedScrollBar() {
  574.         flag = true;
  575.         int scrollpos = scrollbar1.getValue();
  576.  
  577.         if (scrollpos > 0 && scrollpos < 50) {
  578.             for (int i = scrollpos; i < scrollpos+5; i++) {
  579.                 for (int j = 0; j < 4; j++) {
  580.                     if (allTexts[i-scrollpos][j] instanceof Choice) {
  581.                         expDetails[scrollinit + (i-scrollpos)- 1][j] = ((Choice)allTexts[i-scrollpos][j]).getSelectedItem();
  582.                     }
  583.                     else
  584.                         expDetails[scrollinit + (i-scrollpos)- 1][j] = ((TextField)allTexts[i-scrollpos][j]).getText();
  585.                 }
  586.             }
  587.  
  588.             for (int i = scrollpos; i < scrollpos+5; i++) {
  589.                 for (int j = 0; j < 4; j++) {
  590.                     if (allTexts[i-scrollpos][j] instanceof Choice) {
  591.                         if ((expDetails[i-1][j]) != null)
  592.                             ((Choice)allTexts[i-scrollpos][j]).select(expDetails[i-1][j]);
  593.                         else
  594.                             ((Choice)allTexts[i-scrollpos][j]).select("<null>");
  595.                     }
  596.                     else
  597.                         ((TextField)allTexts[i-scrollpos][j]).setText(expDetails[i-1][j]);
  598.                 }
  599.             }
  600.  
  601.         }
  602.         scrollinit = scrollpos;
  603.         findMaxRows();
  604.     }
  605.  
  606. //****  populate category choice control  ****
  607.     public boolean getCategories() {
  608.         Statement  s3;
  609.         ResultSet rs3;
  610.  
  611.         /*********************   Query the Expense Category Table   ***********************************/
  612.         try {
  613.             s3 = (Statement)exp.connection.createStatement();
  614.             rs3 = (ResultSet)s3.executeQuery("select ExpenseCategory from Expense_Categories");
  615.             String catName = "<null>";
  616.             expenseCat1.addItem(catName);
  617.             expenseCat2.addItem(catName);
  618.             expenseCat3.addItem(catName);
  619.             expenseCat4.addItem(catName);
  620.             expenseCat5.addItem(catName);
  621.             while (rs3.next()) {
  622.                 catName = rs3.getString(1);
  623.                 int len = catName.length();
  624.                 if (len < 23) {
  625.                     for (int i = 0; i < (23-len); i++) {
  626.                         catName = catName + " ";
  627.                     }
  628.                 }
  629.                 expenseCat1.addItem(catName);
  630.                 expenseCat2.addItem(catName);
  631.                 expenseCat3.addItem(catName);
  632.                 expenseCat4.addItem(catName);
  633.                 expenseCat5.addItem(catName);
  634.             }
  635.  
  636.             s3.close();
  637.             return true;
  638.         }
  639.         catch (SQLException e)
  640.         {
  641.             String errmsg = (e.getMessage());
  642.             System.out.println(errmsg);
  643.             return false;
  644.         }
  645.         /************************************************************************************************/
  646.     }
  647.  
  648. //****  find the last entry row for expenses  ****
  649.     public void findMaxRows() {
  650.         int max = 0;
  651.         for (int i = 0; i < 50; i++) {
  652.             String tp0 = expDetails[i][0];
  653.             String tp2 = expDetails[i][2];
  654.             String tp3 = expDetails[i][3];
  655.             String alltogether = tp0 + "<null>" + tp2 + tp3;
  656.  
  657.              if ((expDetails[i][0]==null)  && (expDetails[i][2]==null) && (expDetails[i][3]==null)) {
  658.                 max = i;
  659.                 break;
  660.              }
  661.              else if (alltogether.equals("<null>")) {
  662.                 max = i;
  663.                 break;
  664.             }
  665.         }
  666.         count = max;
  667.     }
  668.  
  669. //****  get the employee id based on the employee name ********
  670.     public String getEmployeeID() {
  671.         Statement s2;
  672.         ResultSet rs2;
  673.         String empName = employeename.getSelectedItem();
  674.         int space = empName.indexOf(" ");
  675.         String fName = empName.substring(0, space);
  676.         String lName = empName.substring(space+1);
  677.  
  678.         /**************************   Query the Employees Table    ***************************************/
  679.         try
  680.         {
  681.             s2 = (Statement)exp.connection.createStatement();
  682.             rs2 = (ResultSet)s2.executeQuery("select EmployeeID from Employees where FirstName = '" + fName + "' and LastName = '" + lName + "'");
  683.             String empID = rs2.getString(1);
  684.             s2.close();
  685.             return empID;
  686.         }
  687.         catch (SQLException e)
  688.         {
  689.             String errmsg = (e.getMessage());
  690.             System.out.println(errmsg);
  691.             return "nothing";
  692.         }
  693.         /**************************************************************************************************/
  694.     }
  695.  
  696. //****  get the employee's department based on the employee name ********
  697.     public String getDepartment() {
  698.         Statement s2;
  699.         ResultSet rs2;
  700.         String empName = employeename.getSelectedItem();
  701.         int space = empName.indexOf(" ");
  702.         String fName = empName.substring(0, space);
  703.         String lName = empName.substring(space+1);
  704.  
  705.         /*************************    Query Employees table    *****************************/
  706.         try
  707.         {
  708.             s2 = (Statement)exp.connection.createStatement();
  709.             rs2 = (ResultSet)s2.executeQuery("select DepartmentName from Employees where FirstName = '" + fName + "' and LastName = '" + lName + "'");
  710.             String deptName = rs2.getString(1);
  711.             s2.close();
  712.             return deptName;
  713.         }
  714.         catch (SQLException e)
  715.         {
  716.             System.out.println(e.getMessage());
  717.             return null;
  718.         }
  719.         /**********************************************************************************/
  720.     }
  721.  
  722. //****  save to database when all fields are entered  *******
  723.     public void saveExpenseReport (String empID) {
  724.         Statement  s, s2, s1;
  725.         ResultSet rs2;
  726.  
  727.         float theAdv;
  728.  
  729.         String thePaid;
  730.         boolean temp = paid.getState();
  731.  
  732.         if (temp == true) thePaid = "1";
  733.         else thePaid = "0";
  734.  
  735.         String repName = ", '" + reportname.getText() + "' ,";
  736.         String theDescr = "'" + description.getText() + "' ,";
  737.         String theCharge = "'" + charged.getText() + "' ,";
  738.         String theDate = "'" + datesubmitted.getText() + "' ,";
  739.         String theID = "'" + reportname.getText()+datesubmitted.getText()+empID + "' ,";
  740.         if (advance.getText().equals(""))
  741.             theAdv = 0;
  742.         else
  743.             if (advance.getText().indexOf(".") == -1)
  744.                 theAdv = (Float.valueOf(advance.getText()+ ".0")).floatValue();
  745.             else
  746.                 theAdv = (Float.valueOf(advance.getText())).floatValue();
  747.  
  748.         int rs =0;
  749.         String sqlStatement = "Insert into Expense_Reports (ExpenseReportID, EmployeeID, ExpenseRptName, ExpenseRptDesc, DateSubmitted, AdvanceAmount, DepartmentCharged, Paid) values (" + theID + "'" + empID + "'" + repName + theDescr + theDate + theAdv + "," + theCharge + thePaid + ")";
  750.  
  751.         /******************    Insert into Expense Reports Table   *********************************************/
  752.         try
  753.         {
  754.             s = (Statement)exp.connection.createStatement();
  755.             rs = s.executeUpdate(sqlStatement);
  756.             s1 = (Statement)exp.connection.createStatement();
  757.             rs2 = (ResultSet)s1.executeQuery("select ExpenseReportID from Expense_Reports where ExpenseRptName = '" + reportname.getText() + "'");
  758.             reportId.setText(rs2.getString(1));
  759.  
  760.             s.close();
  761.         }
  762.         catch (SQLException e)
  763.         {
  764.             System.out.println(e.getMessage());
  765.             return;
  766.         }
  767.         /*******************************************************************************************************/
  768.     }
  769.  
  770.  
  771.     public String getCategoryID(String catName) {
  772.  
  773.          String catID;
  774.  
  775.         Statement  s;
  776.         ResultSet rs;
  777.  
  778.         /********************   Query the Expense Category Table   ***************************/
  779.         try {
  780.             s = (Statement)exp.connection.createStatement();
  781.             String sqlStatement = "Select ExpenseCategoryID from Expense_Categories where ExpenseCategory = '" + catName + "'";
  782.             rs = (ResultSet)s.executeQuery(sqlStatement);
  783.             catID = rs.getString(1);
  784.             s.close();
  785.             return catID;
  786.         }
  787.         catch (SQLException e)
  788.         {
  789.             System.out.println(e.getMessage());
  790.             return "no cat id";
  791.         }
  792.         /************************************************************************************/
  793.  
  794.     }
  795.  
  796.     public void saveExpenseDetails() {
  797.         Statement  sed;
  798.         int rs;
  799.  
  800.         /***************   Insert into Expense Details Table   *************************************/
  801.         try {
  802.             sed = (Statement)exp.connection.createStatement();
  803.             for (int i = 0; i < count; i++) {
  804.                 sed = (Statement)exp.connection.createStatement();
  805.                 String catID = getCategoryID(expDetails[i][1]);
  806.                 String expID = expDetails[i][2] + reportId.getText() + i;
  807.                 float amts;
  808.                 if (expDetails[i][3].indexOf(".") == -1)
  809.                     amts = (Float.valueOf(expDetails[i][3] + ".0")).floatValue();
  810.                 else
  811.                     amts = (Float.valueOf(expDetails[i][3])).floatValue();
  812.  
  813.                 String sqlStatement = "Insert into Expense_Details (ExpenseDetailID, ExpenseReportID, ExpenseCategoryID, ExpenseItemAmount, ExpenseItemDescription, ExpenseDate) values ('" + expID + "','" + reportId.getText() + "','" + catID + "'," + amts + ",'" + expDetails[i][2] + "','" + expDetails[i][0] + "')";
  814.                 rs = sed.executeUpdate(sqlStatement);
  815.             }
  816.             sed.close();
  817.         }
  818.         catch (SQLException e)
  819.         {
  820.             String errmsg = (e.getMessage());
  821.             System.out.println(errmsg);
  822.             return;
  823.         }
  824.         /********************************************************************************************/
  825.     }
  826.  
  827.  
  828.     public void getTotal() {
  829.         float theTotal = 0;
  830.         float theBalance = 0;
  831.  
  832.         for (int i = 0; i < count; i++) {
  833.                 theTotal += (Float.valueOf(expDetails[i][3])).floatValue();
  834.         }
  835.  
  836.         if (advance.getText().equals(""))
  837.             theBalance = theTotal - 0;
  838.         else
  839.             theBalance = theTotal - (Float.valueOf(advance.getText())).floatValue();
  840.  
  841.         Float temp  = new Float (theTotal);
  842.         total.setText(temp.toString());
  843.         Float temp2  = new Float (theBalance);
  844.         balance.setText(temp2.toString());
  845.     }
  846.  
  847.     public ResultSet getEmployeeName() {
  848.         Statement s2;
  849.         ResultSet rs2;
  850.         String empName;
  851.         employeename.addItem("<null>");
  852.  
  853.         /*****************   Query the Employees Table   *************************************************/
  854.         try
  855.         {
  856.             s2 = (Statement)exp.connection.createStatement();
  857.             rs2 = (ResultSet)s2.executeQuery("select LastName, FirstName from Employees");
  858.             /*while (rs2.next()) {
  859.                 String lname = rs2.getVarChar(1);
  860.                 String fname = rs2.getVarChar(2);
  861.                 employeename.addItem(fname + " " + lname);
  862.             }
  863.             */
  864.             s2.close();
  865.             return rs2;
  866.         }
  867.         catch (SQLException e)
  868.         {
  869.             System.out.println(e.getMessage());
  870.             return null;
  871.         }
  872.         /**************************************************************************************************/
  873.     }
  874.  
  875. //****  disable fields after data is saved  ******
  876.     public void disableFields() {
  877.         reportId.setEditable(false);
  878.         employeename.disable();
  879.         reportname.setEditable(false);
  880.         description.setEditable(false);
  881.         charged.setEditable(false);
  882.         datesubmitted.setEditable(false);
  883.         advance.setEditable(false);
  884.         total.setEditable(false);
  885.         balance.setEditable(false);
  886.         paid.setState(false);
  887.  
  888.         for (int i = 0; i < 5; i++) {
  889.             for ( int j = 0; j < 4; j++) {
  890.                 if (allTexts[i][j] instanceof TextField) {
  891.                     ((TextField)allTexts[i][j]).setEditable(false);
  892.                 }
  893.             }
  894.         }
  895.  
  896.         expenseCat1.disable();
  897.         expenseCat2.disable();
  898.         expenseCat3.disable();
  899.         expenseCat4.disable();
  900.         expenseCat5.disable();
  901.     }
  902.  
  903.  
  904. //****  check that all fields were entered  ************
  905.     public String checkFields() {
  906.         String errMessage = "";
  907.  
  908.         if (advance.getText().equals(""))
  909.             errMessage =  "Please enter Advance amount ";
  910.         if (description.getText().equals(""))
  911.             errMessage =  "Please enter Description    ";
  912.         if (employeename.getSelectedItem().equals("<null>"))
  913.             errMessage =  "Please enter Employee Name  ";
  914.         if (reportname.getText().equals(""))
  915.             errMessage =  "Please enter Report Name    ";
  916.  
  917.         return errMessage;
  918.     }
  919. }
  920.  
  921.  
  922. //****  dialog box that displays error messages ********
  923. /*class MessageBox extends Dialog {
  924.  
  925.     public MessageBox(Frame parent, String errMessage) {
  926.  
  927.         super(parent, "Error", true);
  928.         setResizable(false);
  929.  
  930.         //{{INIT_CONTROLS
  931.         setLayout(null);
  932.         addNotify();
  933.         resize(insets().left + insets().right + 250, insets().top + insets().bottom + 120);
  934.  
  935.         label1=new Label();
  936.         label1.setFont(new Font("Dialog",Font.PLAIN,14));
  937.         add(label1);
  938.         label1.reshape(insets().left + 40,insets().top + 18,220,33);
  939.  
  940.         OKButton=new Button("OK");
  941.         add(OKButton);
  942.         OKButton.reshape(insets().left + 71,insets().top + 54,73,22);
  943.         //}}
  944.  
  945.         label1.setText(errMessage);
  946.  
  947.     }
  948.  
  949.     public synchronized void show() {
  950.         Rectangle bounds = getParent().bounds();
  951.         Rectangle abounds = bounds();
  952.  
  953.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  954.              bounds.y + (bounds.height - abounds.height)/2);
  955.  
  956.         super.show();
  957.     }
  958.  
  959.     public synchronized void wakeUp() {
  960.         notify();
  961.     }
  962.  
  963.     public boolean handleEvent(Event event) {
  964.         if (event.id == Event.ACTION_EVENT && event.target == OKButton) {
  965.                 clickedOKButton();
  966.                 return true;
  967.         }
  968.         else
  969.         if (event.id == Event.WINDOW_DESTROY) {
  970.             hide();
  971.             return true;
  972.         }
  973.         return super.handleEvent(event);
  974.     }
  975.  
  976.     //{{DECLARE_CONTROLS
  977.     Button OKButton;
  978.     Label label1;
  979.     //}}
  980.  
  981.     public void clickedOKButton() {
  982.         handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
  983.     }
  984.  
  985. }
  986.  
  987. */
  988.  
  989.