home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************************************************************************
- * *
- * Class name: expenseEntryForm *
- * *
- * Purpose: Extends Panel to allow the user to create a new expense report. *
- * *
- * Imports: java.awt.* *
- * java.applet.* *
- * symjava.sql.* *
- * java.io.* *
- * java.net.* *
- * java.lang.* *
- * java.util.* *
- * *
- * Methods include: public boolean getCategories() *
- * public boolean handleEvent(Event event) *
- * public expenseEntryForm(Applet parent, Choice empname, Choice cat1, Choice cat2, Choice cat3, Choice cat4, Choice cat5) *
- * public MessageBox(Frame parent, String errMessage) *
- * public ResultSet getEmployeeName() *
- * public String checkFields() *
- * public String getCategoryID(String catName) *
- * public synchronized void wakeUp() *
- * public void clickedclearbutton() *
- * public void clickedMainMenubutton() *
- * public void clickedOKButton() *
- * public void disableFields() *
- * public void findMaxRows() *
- * public void getMessageBox(String msg) *
- * *
- * *
- * Additional Notes: *
- * THIS SOFTWARE HAS BEEN COMPILED AND EXECUTED SUCCESSFULLY IN SPECIFIC SYMANTEC *
- * ENVIRONMENTS, AND IS BEING PROVIDED ONLY AS SAMPLE CODE. *
- * *
- * SYMANTEC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, *
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF *
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SYMANTEC SHALL NOT *
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING *
- * THIS SOFTWARE OR ITS DERIVATIVES. *
- * *
- * Please see the Sample Code Configuration item in the Read Me file for additional *
- * information about the sample database used in this applet. *
- * *
- * Copyright (c) 1996 Symantec. All Rights Reserved. *
- * *
- ********************************************************************************************************************************************/
-
- import java.applet.*;
- import java.net.*;
- import java.awt.*;
- import symjava.sql.*;
- import java.lang.*;
- import java.util.*;
-
- public class expenseEntryForm extends Panel {
- expenseApplet exp;
-
- String expDetails [][]= new String[50][4];
- Component allTexts [][] = new Component[5][4];
- java.util.Date theDate = new java.util.Date();
- java.util.Date theDate1 = new java.util.Date();
- java.util.Date theDate2 = new java.util.Date();
- java.util.Date theDate3 = new java.util.Date();
- java.util.Date theDate4 = new java.util.Date();
- java.util.Date theDate5 = new java.util.Date();
- boolean flag = false;
- int scrollinit = 1;
- int count = 0;
-
-
-
- public expenseEntryForm(Applet parent, Choice empname, Choice cat1, Choice cat2, Choice cat3, Choice cat4, Choice cat5) {
-
- exp = (expenseApplet)parent;
-
- //{{INIT_CONTROLS
- setLayout(null);
-
- resize(insets().left + insets().right + 690, insets().top + insets().bottom + 520);
-
- label1=new Label("Expense Report ID");
- add(label1);
- label1.reshape(insets().left + 77,insets().top + 39,130,15);
-
- reportId=new TextField(9);
- add(reportId);
- reportId.reshape(insets().left + 228,insets().top + 34,128,22);
- reportId.setEditable(false);
-
- label2=new Label("Department Charged");
- add(label2);
- label2.reshape(insets().left + 77,insets().top + 191,142,15);
-
- charged=new TextField(16);
- add(charged);
- charged.reshape(insets().left + 228,insets().top + 186,128,25);
- charged.setEditable(false);
-
- label0=new Label("Employee ID");
- add(label0);
- label0.reshape(insets().left + 411,insets().top + 191,90,15);
-
- employeeID=new TextField(20);
- add(employeeID);
- employeeID.reshape(insets().left + 509,insets().top + 186,128,25);
- employeeID.setEditable(false);
-
- label3=new Label("Expense Report Name");
- add(label3);
- label3.reshape(insets().left + 77,insets().top + 114,144,15);
-
- reportname=new TextField(9);
- add(reportname);
- reportname.reshape(insets().left + 228,insets().top + 109,128,22);
-
- label4=new Label("Description");
- add(label4);
- label4.reshape(insets().left + 75,insets().top + 221,125,15);
-
- description=new TextField(43);
- add(description);
- description.reshape(insets().left + 228,insets().top + 229,408,45);
-
- label6=new Label("Employee Name");
- add(label6);
- label6.reshape(insets().left + 77,insets().top + 154,128,15);
-
- employeename = empname;
- /* employeename=new Choice();
- add(employeename);
- employeename.reshape(insets().left + 228,insets().top + 146,128,25);
- */
-
- label7=new Label("Date Submitted");
- add(label7);
- label7.reshape(insets().left + 77,insets().top + 77,124,15);
-
- datesubmitted=new TextField(9);
- add(datesubmitted);
- datesubmitted.reshape(insets().left + 228,insets().top + 71,128,23);
- datesubmitted.setEditable(false);
-
- advanceLabel=new Label("Advance");
- add(advanceLabel);
- advanceLabel.reshape(insets().left + 411,insets().top + 36,70,15);
-
- advance=new TextField(9);
- add(advance);
- advance.reshape(insets().left + 509,insets().top + 32,128,22);
-
- label9=new Label("Total");
- add(label9);
- label9.reshape(insets().left + 411,insets().top + 75,88,20);
-
- total=new TextField(9);
- add(total);
- total.reshape(insets().left + 509,insets().top + 71,128,21);
- total.setEditable(false);
-
- label10=new Label("Balance Due");
- add(label10);
- label10.reshape(insets().left + 411,insets().top + 116,97,15);
-
- balance=new TextField(9);
- add(balance);
- balance.reshape(insets().left + 509,insets().top + 109,128,24);
- balance.setEditable(false);
-
- label11=new Label("");
- add(label11);
- label11.reshape(insets().left + 411,insets().top + 156,70,15);
-
- paid=new Checkbox(" Paid");
- add(paid);
- paid.reshape(insets().left + 509,insets().top + 150,128,24);
- paid.setBackground(Color.white);
-
- expenseDatebutton=new Button("Expense Date");
- add(expenseDatebutton);
- expenseDatebutton.reshape(insets().left + 67,insets().top + 285,106,26);
-
- expenseCategorybutton=new Button("Expense Category");
- add(expenseCategorybutton);
- expenseCategorybutton.reshape(insets().left + 172,insets().top + 285,136,26);
-
- expenseDescriptionbutton=new Button("Expense Description");
- add(expenseDescriptionbutton);
- expenseDescriptionbutton.reshape(insets().left + 308,insets().top + 285,226,26);
-
- amountbutton=new Button("Amount");
- add(amountbutton);
- amountbutton.reshape(insets().left + 534,insets().top + 285,87,26);
-
- label5=new Label("Expense Entry Form");
- label5.setFont(new Font("Dialog",Font.BOLD,14));
- add(label5);
- label5.reshape(insets().left + 247,insets().top + 8,230,15);
-
- expenseDate1=new TextField(12);
- add(expenseDate1);
- expenseDate1.reshape(insets().left + 68,insets().top + 311,104,22);
- allTexts[0][0] = expenseDate1;
-
- expenseCat1=cat1;
- /*expenseCat1=new Choice();
- add(expenseCat1);
- expenseCat1.reshape(insets().left + 172,insets().top + 311,138,22);*/
- allTexts[0][1] = expenseCat1;
-
- expenseDescr1=new TextField(26);
- add(expenseDescr1);
- expenseDescr1.reshape(insets().left + 310,insets().top + 311,222,22);
- allTexts[0][2] = expenseDescr1;
-
- expenseAmt1=new TextField(10);
- add(expenseAmt1);
- expenseAmt1.reshape(insets().left + 534,insets().top + 311,86,22);
- allTexts[0][3] = expenseAmt1;
-
- expenseDate2=new TextField(12);
- add(expenseDate2);
- expenseDate2.reshape(insets().left + 68,insets().top + 338,104,22);
- allTexts[1][0] = expenseDate2;
-
- expenseCat2=cat2;
- /*expenseCat2=new Choice();
- add(expenseCat2);
- expenseCat2.reshape(insets().left + 172,insets().top + 338,138,22);*/
- allTexts[1][1] = expenseCat2;
-
- expenseDescr2=new TextField(26);
- add(expenseDescr2);
- expenseDescr2.reshape(insets().left + 310,insets().top + 338,222,22);
- allTexts[1][2] = expenseDescr2;
-
- expenseAmt2=new TextField(10);
- add(expenseAmt2);
- expenseAmt2.reshape(insets().left + 534,insets().top + 338,86,22);
- allTexts[1][3] = expenseAmt2;
-
- expenseDate3=new TextField(12);
- add(expenseDate3);
- expenseDate3.reshape(insets().left + 68,insets().top + 366,104,22);
- allTexts[2][0] = expenseDate3;
-
- expenseCat3=cat3;
- /*expenseCat3=new Choice();
- add(expenseCat3);
- expenseCat3.reshape(insets().left + 172,insets().top + 366,138,22);*/
- allTexts[2][1] = expenseCat3;
-
- expenseDescr3=new TextField(26);
- add(expenseDescr3);
- expenseDescr3.reshape(insets().left + 310,insets().top + 366,222,22);
- allTexts[2][2] = expenseDescr3;
-
- expenseAmt3=new TextField(10);
- add(expenseAmt3);
- expenseAmt3.reshape(insets().left + 534,insets().top + 366,86,22);
- allTexts[2][3] = expenseAmt3;
-
- expenseDate4=new TextField(12);
- add(expenseDate4);
- expenseDate4.reshape(insets().left + 68,insets().top + 394,104,22);
- allTexts[3][0] = expenseDate4;
-
- expenseCat4=cat4;
- /*expenseCat4=new Choice();
- add(expenseCat4);
- expenseCat4.reshape(insets().left + 172,insets().top + 394,138,22);*/
- allTexts[3][1] = expenseCat4;
-
- expenseDescr4=new TextField(26);
- add(expenseDescr4);
- expenseDescr4.reshape(insets().left + 310,insets().top + 394,222,22);
- allTexts[3][2] = expenseDescr4;
-
- expenseAmt4=new TextField(10);
- add(expenseAmt4);
- expenseAmt4.reshape(insets().left + 534,insets().top + 394,86,22);
- allTexts[3][3] = expenseAmt4;
-
- expenseDate5=new TextField(12);
- add(expenseDate5);
- expenseDate5.reshape(insets().left + 68,insets().top + 420,104,22);
- allTexts[4][0] = expenseDate5;
-
- expenseCat5=cat5;
- /*expenseCat5=new Choice();
- add(expenseCat5);
- expenseCat5.reshape(insets().left + 172,insets().top + 420,138,22);*/
- allTexts[4][1] = expenseCat5;
-
- expenseDescr5=new TextField(26);
- add(expenseDescr5);
- expenseDescr5.reshape(insets().left + 310,insets().top + 420,222,22);
- allTexts[4][2] = expenseDescr5;
-
- expenseAmt5=new TextField(10);
- add(expenseAmt5);
- expenseAmt5.reshape(insets().left + 534,insets().top + 420,86,22);
- allTexts[4][3] = expenseAmt5;
-
-
- scrollbar1= new Scrollbar(Scrollbar.VERTICAL, 1, 0, 1, 50);
- add(scrollbar1);
- scrollbar1.reshape(insets().left + 621,insets().top + 313,28,130);
-
- button1=new Button("");
- add(button1);
- button1.reshape(insets().left + 621,insets().top + 287,28,26);
-
- savebutton=new Button("Save");
- add(savebutton);
- savebutton.reshape(insets().left + 230,insets().top + 450,88,26);
-
- clearbutton=new Button("Clear");
- add(clearbutton);
- clearbutton.reshape(insets().left + 330,insets().top + 450,88,26);
-
- MainMenubutton=new Button("Main Menu");
- add(MainMenubutton);
- MainMenubutton.reshape(insets().left + 430,insets().top + 450,88,26);
-
-
- expenseDate1.setText(null);
- expenseDescr1.setText(null);
- expenseAmt1.setText(null);
- expenseDate2.setText(null);
- expenseDescr2.setText(null);
- expenseAmt2.setText(null);
- expenseDate3.setText(null);
- expenseDescr3.setText(null);
- expenseAmt3.setText(null);
- expenseDate4.setText(null);
- expenseDescr4.setText(null);
- expenseAmt4.setText(null);
- expenseDate5.setText(null);
- expenseDescr5.setText(null);
- expenseAmt5.setText(null);
-
- datesubmitted.setText(getDate());
- /* getCategories();
- getEmployeeName();*/
- }
-
- public synchronized void show() {
- super.show();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.ACTION_EVENT && event.target == savebutton) {
- clickedSavebutton();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == clearbutton) {
- clickedclearbutton();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == expenseCat1) {
- expenseDate1.setText(getDate());
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == expenseCat2) {
- expenseDate2.setText(getDate());
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == expenseCat3) {
- expenseDate3.setText(getDate());
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == expenseCat4) {
- expenseDate4.setText(getDate());
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == expenseCat5) {
- expenseDate5.setText(getDate());
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == MainMenubutton) {
- clickedMainMenubutton();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == employeename) {
- employeeID.setText(getEmployeeID());
- charged.setText(getDepartment());
- return true;
- }
- else
- if (event.target instanceof Scrollbar) {
- clickedScrollBar();
- return true;
- }
- else
- if (event.id == Event.WINDOW_DESTROY) {
- // hide();
- return true;
- }
- return super.handleEvent(event);
- }
-
-
- //{{DECLARE_CONTROLS
- Label label1;
- TextField reportId;
- Label label2;
- Choice employeename;
- Label label3;
- TextField reportname;
- Label label4;
- TextField description;
- Label label6;
- TextField charged;
- Label label7;
- TextField datesubmitted;
- Label advanceLabel;
- TextField advance;
- Label label9;
- TextField total;
- Label label10;
- TextField balance;
- Label label11;
- TextField employeeID;
- Label label0;
- Checkbox paid;
- Button expenseDatebutton;
- Button expenseCategorybutton;
- Button expenseDescriptionbutton;
- Button amountbutton;
- Label label5;
- TextField expenseDate1;
- Choice expenseCat1;
- TextField expenseDescr1;
- TextField expenseAmt1;
- TextField expenseDate2;
- Choice expenseCat2;
- TextField expenseDescr2;
- TextField expenseAmt2;
- TextField expenseDate3;
- Choice expenseCat3;
- TextField expenseDescr3;
- TextField expenseAmt3;
- TextField expenseDate4;
- Choice expenseCat4;
- TextField expenseDescr4;
- TextField expenseAmt4;
- TextField expenseDate5;
- Choice expenseCat5;
- TextField expenseDescr5;
- TextField expenseAmt5;
- Scrollbar scrollbar1;
- Button button1;
- Button savebutton;
- Button clearbutton;
- Button MainMenubutton;
- //}}
-
-
- /*
- public void getMessageBox(String msg) {
- MessageBox theMessageBox;
- theMessageBox = new MessageBox(this, msg);
- theMessageBox.show();
- }
- */
- public void clickedMainMenubutton() {
- hide();
- }
- public void clickedSavebutton() {
- String empID;
-
- String errMessage = "";
- errMessage = checkFields();
-
- if (errMessage.equals("") ){
- empID = getEmployeeID();
- saveExpenseReport(empID);
-
- if (flag == false) {
-
- for (int i = 0; i < 5; i++) {
- for (int j = 0; j < 4; j++) {
- if (allTexts[i][j] instanceof Choice)
- expDetails[i][j] = ((Choice)allTexts[i][j]).getSelectedItem();
- else
- expDetails[i][j] = ((TextField)allTexts[i][j]).getText();
- }
- }
- findMaxRows();
- }
-
- saveExpenseDetails();
- getTotal();
- disableFields();
- }
- else {
- // getMessageBox(errMessage);
- }
- }
-
- //**** clear all entry fields *************
- public void clickedclearbutton() {
- reportId.setText(null);
- employeeID.setText(null);
- employeename.enable();
- employeename.select("<null>");
- reportname.setText(null);
- description.setText(null);
- charged.setText(null);
- advance.setText(null);
- total.setText(null);
- balance.setText(null);
- paid.setState(false);
- expenseDate1.setText(null);
- expenseDescr1.setText(null);
- expenseAmt1.setText(null);
- expenseDate2.setText(null);
- expenseDescr2.setText(null);
- expenseAmt2.setText(null);
- expenseDate3.setText(null);
- expenseDescr3.setText(null);
- expenseAmt3.setText(null);
- expenseDate4.setText(null);
- expenseDescr4.setText(null);
- expenseAmt4.setText(null);
- expenseDate5.setText(null);
- expenseDescr5.setText(null);
- expenseAmt5.setText(null);
- expenseCat1.enable();
- expenseCat2.enable();
- expenseCat3.enable();
- expenseCat4.enable();
- expenseCat5.enable();
- expenseCat1.select("<null>");
- expenseCat2.select("<null>");
- expenseCat3.select("<null>");
- expenseCat4.select("<null>");
- expenseCat5.select("<null>");
-
- reportId.setEditable(false);
- reportname.setEditable(true);
- description.setEditable(true);
- charged.setEditable(false);
- advance.setEditable(true);
- employeeID.setEditable(false);
-
- for (int i = 0; i < 5; i++) {
- for ( int j = 0; j < 4; j++) {
- if (allTexts[i][j] instanceof TextField) {
- ((TextField)allTexts[i][j]).setEditable(true);
- ((TextField)allTexts[i][j]).setText(" ");
- }
- }
- }
- }
-
- public String getDate() {
- java.util.Date theDate = new java.util.Date();
- int month = theDate.getMonth() + 1;
- String it = (month + "/" + theDate.getDate() + "/" + theDate.getYear());
- return it;
- }
-
- //**** save and update entries when scrollbar is moved *****
- public void clickedScrollBar() {
- flag = true;
- int scrollpos = scrollbar1.getValue();
-
- if (scrollpos > 0 && scrollpos < 50) {
- for (int i = scrollpos; i < scrollpos+5; i++) {
- for (int j = 0; j < 4; j++) {
- if (allTexts[i-scrollpos][j] instanceof Choice) {
- expDetails[scrollinit + (i-scrollpos)- 1][j] = ((Choice)allTexts[i-scrollpos][j]).getSelectedItem();
- }
- else
- expDetails[scrollinit + (i-scrollpos)- 1][j] = ((TextField)allTexts[i-scrollpos][j]).getText();
- }
- }
-
- for (int i = scrollpos; i < scrollpos+5; i++) {
- for (int j = 0; j < 4; j++) {
- if (allTexts[i-scrollpos][j] instanceof Choice) {
- if ((expDetails[i-1][j]) != null)
- ((Choice)allTexts[i-scrollpos][j]).select(expDetails[i-1][j]);
- else
- ((Choice)allTexts[i-scrollpos][j]).select("<null>");
- }
- else
- ((TextField)allTexts[i-scrollpos][j]).setText(expDetails[i-1][j]);
- }
- }
-
- }
- scrollinit = scrollpos;
- findMaxRows();
- }
-
- //**** populate category choice control ****
- public boolean getCategories() {
- Statement s3;
- ResultSet rs3;
-
- /********************* Query the Expense Category Table ***********************************/
- try {
- s3 = (Statement)exp.connection.createStatement();
- rs3 = (ResultSet)s3.executeQuery("select ExpenseCategory from Expense_Categories");
- String catName = "<null>";
- expenseCat1.addItem(catName);
- expenseCat2.addItem(catName);
- expenseCat3.addItem(catName);
- expenseCat4.addItem(catName);
- expenseCat5.addItem(catName);
- while (rs3.next()) {
- catName = rs3.getString(1);
- int len = catName.length();
- if (len < 23) {
- for (int i = 0; i < (23-len); i++) {
- catName = catName + " ";
- }
- }
- expenseCat1.addItem(catName);
- expenseCat2.addItem(catName);
- expenseCat3.addItem(catName);
- expenseCat4.addItem(catName);
- expenseCat5.addItem(catName);
- }
-
- s3.close();
- return true;
- }
- catch (SQLException e)
- {
- String errmsg = (e.getMessage());
- System.out.println(errmsg);
- return false;
- }
- /************************************************************************************************/
- }
-
- //**** find the last entry row for expenses ****
- public void findMaxRows() {
- int max = 0;
- for (int i = 0; i < 50; i++) {
- String tp0 = expDetails[i][0];
- String tp2 = expDetails[i][2];
- String tp3 = expDetails[i][3];
- String alltogether = tp0 + "<null>" + tp2 + tp3;
-
- if ((expDetails[i][0]==null) && (expDetails[i][2]==null) && (expDetails[i][3]==null)) {
- max = i;
- break;
- }
- else if (alltogether.equals("<null>")) {
- max = i;
- break;
- }
- }
- count = max;
- }
-
- //**** get the employee id based on the employee name ********
- public String getEmployeeID() {
- Statement s2;
- ResultSet rs2;
- String empName = employeename.getSelectedItem();
- int space = empName.indexOf(" ");
- String fName = empName.substring(0, space);
- String lName = empName.substring(space+1);
-
- /************************** Query the Employees Table ***************************************/
- try
- {
- s2 = (Statement)exp.connection.createStatement();
- rs2 = (ResultSet)s2.executeQuery("select EmployeeID from Employees where FirstName = '" + fName + "' and LastName = '" + lName + "'");
- String empID = rs2.getString(1);
- s2.close();
- return empID;
- }
- catch (SQLException e)
- {
- String errmsg = (e.getMessage());
- System.out.println(errmsg);
- return "nothing";
- }
- /**************************************************************************************************/
- }
-
- //**** get the employee's department based on the employee name ********
- public String getDepartment() {
- Statement s2;
- ResultSet rs2;
- String empName = employeename.getSelectedItem();
- int space = empName.indexOf(" ");
- String fName = empName.substring(0, space);
- String lName = empName.substring(space+1);
-
- /************************* Query Employees table *****************************/
- try
- {
- s2 = (Statement)exp.connection.createStatement();
- rs2 = (ResultSet)s2.executeQuery("select DepartmentName from Employees where FirstName = '" + fName + "' and LastName = '" + lName + "'");
- String deptName = rs2.getString(1);
- s2.close();
- return deptName;
- }
- catch (SQLException e)
- {
- System.out.println(e.getMessage());
- return null;
- }
- /**********************************************************************************/
- }
-
- //**** save to database when all fields are entered *******
- public void saveExpenseReport (String empID) {
- Statement s, s2, s1;
- ResultSet rs2;
-
- float theAdv;
-
- String thePaid;
- boolean temp = paid.getState();
-
- if (temp == true) thePaid = "1";
- else thePaid = "0";
-
- String repName = ", '" + reportname.getText() + "' ,";
- String theDescr = "'" + description.getText() + "' ,";
- String theCharge = "'" + charged.getText() + "' ,";
- String theDate = "'" + datesubmitted.getText() + "' ,";
- String theID = "'" + reportname.getText()+datesubmitted.getText()+empID + "' ,";
- if (advance.getText().equals(""))
- theAdv = 0;
- else
- if (advance.getText().indexOf(".") == -1)
- theAdv = (Float.valueOf(advance.getText()+ ".0")).floatValue();
- else
- theAdv = (Float.valueOf(advance.getText())).floatValue();
-
- int rs =0;
- String sqlStatement = "Insert into Expense_Reports (ExpenseReportID, EmployeeID, ExpenseRptName, ExpenseRptDesc, DateSubmitted, AdvanceAmount, DepartmentCharged, Paid) values (" + theID + "'" + empID + "'" + repName + theDescr + theDate + theAdv + "," + theCharge + thePaid + ")";
-
- /****************** Insert into Expense Reports Table *********************************************/
- try
- {
- s = (Statement)exp.connection.createStatement();
- rs = s.executeUpdate(sqlStatement);
- s1 = (Statement)exp.connection.createStatement();
- rs2 = (ResultSet)s1.executeQuery("select ExpenseReportID from Expense_Reports where ExpenseRptName = '" + reportname.getText() + "'");
- reportId.setText(rs2.getString(1));
-
- s.close();
- }
- catch (SQLException e)
- {
- System.out.println(e.getMessage());
- return;
- }
- /*******************************************************************************************************/
- }
-
-
- public String getCategoryID(String catName) {
-
- String catID;
-
- Statement s;
- ResultSet rs;
-
- /******************** Query the Expense Category Table ***************************/
- try {
- s = (Statement)exp.connection.createStatement();
- String sqlStatement = "Select ExpenseCategoryID from Expense_Categories where ExpenseCategory = '" + catName + "'";
- rs = (ResultSet)s.executeQuery(sqlStatement);
- catID = rs.getString(1);
- s.close();
- return catID;
- }
- catch (SQLException e)
- {
- System.out.println(e.getMessage());
- return "no cat id";
- }
- /************************************************************************************/
-
- }
-
- public void saveExpenseDetails() {
- Statement sed;
- int rs;
-
- /*************** Insert into Expense Details Table *************************************/
- try {
- sed = (Statement)exp.connection.createStatement();
- for (int i = 0; i < count; i++) {
- sed = (Statement)exp.connection.createStatement();
- String catID = getCategoryID(expDetails[i][1]);
- String expID = expDetails[i][2] + reportId.getText() + i;
- float amts;
- if (expDetails[i][3].indexOf(".") == -1)
- amts = (Float.valueOf(expDetails[i][3] + ".0")).floatValue();
- else
- amts = (Float.valueOf(expDetails[i][3])).floatValue();
-
- String sqlStatement = "Insert into Expense_Details (ExpenseDetailID, ExpenseReportID, ExpenseCategoryID, ExpenseItemAmount, ExpenseItemDescription, ExpenseDate) values ('" + expID + "','" + reportId.getText() + "','" + catID + "'," + amts + ",'" + expDetails[i][2] + "','" + expDetails[i][0] + "')";
- rs = sed.executeUpdate(sqlStatement);
- }
- sed.close();
- }
- catch (SQLException e)
- {
- String errmsg = (e.getMessage());
- System.out.println(errmsg);
- return;
- }
- /********************************************************************************************/
- }
-
-
- public void getTotal() {
- float theTotal = 0;
- float theBalance = 0;
-
- for (int i = 0; i < count; i++) {
- theTotal += (Float.valueOf(expDetails[i][3])).floatValue();
- }
-
- if (advance.getText().equals(""))
- theBalance = theTotal - 0;
- else
- theBalance = theTotal - (Float.valueOf(advance.getText())).floatValue();
-
- Float temp = new Float (theTotal);
- total.setText(temp.toString());
- Float temp2 = new Float (theBalance);
- balance.setText(temp2.toString());
- }
-
- public ResultSet getEmployeeName() {
- Statement s2;
- ResultSet rs2;
- String empName;
- employeename.addItem("<null>");
-
- /***************** Query the Employees Table *************************************************/
- try
- {
- s2 = (Statement)exp.connection.createStatement();
- rs2 = (ResultSet)s2.executeQuery("select LastName, FirstName from Employees");
- /*while (rs2.next()) {
- String lname = rs2.getVarChar(1);
- String fname = rs2.getVarChar(2);
- employeename.addItem(fname + " " + lname);
- }
- */
- s2.close();
- return rs2;
- }
- catch (SQLException e)
- {
- System.out.println(e.getMessage());
- return null;
- }
- /**************************************************************************************************/
- }
-
- //**** disable fields after data is saved ******
- public void disableFields() {
- reportId.setEditable(false);
- employeename.disable();
- reportname.setEditable(false);
- description.setEditable(false);
- charged.setEditable(false);
- datesubmitted.setEditable(false);
- advance.setEditable(false);
- total.setEditable(false);
- balance.setEditable(false);
- paid.setState(false);
-
- for (int i = 0; i < 5; i++) {
- for ( int j = 0; j < 4; j++) {
- if (allTexts[i][j] instanceof TextField) {
- ((TextField)allTexts[i][j]).setEditable(false);
- }
- }
- }
-
- expenseCat1.disable();
- expenseCat2.disable();
- expenseCat3.disable();
- expenseCat4.disable();
- expenseCat5.disable();
- }
-
-
- //**** check that all fields were entered ************
- public String checkFields() {
- String errMessage = "";
-
- if (advance.getText().equals(""))
- errMessage = "Please enter Advance amount ";
- if (description.getText().equals(""))
- errMessage = "Please enter Description ";
- if (employeename.getSelectedItem().equals("<null>"))
- errMessage = "Please enter Employee Name ";
- if (reportname.getText().equals(""))
- errMessage = "Please enter Report Name ";
-
- return errMessage;
- }
- }
-
-
- //**** dialog box that displays error messages ********
- /*class MessageBox extends Dialog {
-
- public MessageBox(Frame parent, String errMessage) {
-
- super(parent, "Error", true);
- setResizable(false);
-
- //{{INIT_CONTROLS
- setLayout(null);
- addNotify();
- resize(insets().left + insets().right + 250, insets().top + insets().bottom + 120);
-
- label1=new Label();
- label1.setFont(new Font("Dialog",Font.PLAIN,14));
- add(label1);
- label1.reshape(insets().left + 40,insets().top + 18,220,33);
-
- OKButton=new Button("OK");
- add(OKButton);
- OKButton.reshape(insets().left + 71,insets().top + 54,73,22);
- //}}
-
- label1.setText(errMessage);
-
- }
-
- public synchronized void show() {
- Rectangle bounds = getParent().bounds();
- Rectangle abounds = bounds();
-
- move(bounds.x + (bounds.width - abounds.width)/ 2,
- bounds.y + (bounds.height - abounds.height)/2);
-
- super.show();
- }
-
- public synchronized void wakeUp() {
- notify();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.ACTION_EVENT && event.target == OKButton) {
- clickedOKButton();
- return true;
- }
- else
- if (event.id == Event.WINDOW_DESTROY) {
- hide();
- return true;
- }
- return super.handleEvent(event);
- }
-
- //{{DECLARE_CONTROLS
- Button OKButton;
- Label label1;
- //}}
-
- public void clickedOKButton() {
- handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
- }
-
- }
-
- */
-
-