see if there is month end processing going on
//if so, disable the prevPeriod button
if (monthEndFlag == true) {
prevPeriod.setEnabled(false);
}
}
public void setConrolStates(boolean opt) {
if (isAdmin == true) {
opt = true;
}
prevPeriod.setEnabled(opt);
nextPeriod.setEnabled(opt);
theGrid.enableScrolls(opt);
gotoCurrMon.setEnabled(opt);
projNameOpt.setEnabled(opt);
}
public void enableUpdate(boolean opt) {
updateDb.setEnabled(opt);
addProj.setEnabled(opt);
setProjOrder.setEnabled(opt);
}
//fills the name list combo box with users
//given a sql statement
public void fillNameList(String theSql, int col) {
DataSet ds = SqlBroker.submitQuery(theSql);
//if this person is a Ptrack admin add their name to the list
if (isAdmin == true) {
empChooser.add(userName);
}
for (int i=0;i<ds.getNumRows();i++) {
empChooser.add(ds.getString(i,col));
}
}
public void drawOutline(Component c) {
Graphics g = c.getGraphics();
int h = c.size().height-5;
int w = c.size().width-5;
g.drawRect(0,0,w,h);
}
//fill the date period label, this also sets two strings:
//date1 and date2 that are used as date ranges for any sql
//selects
public void fillDatePeriod() {
Date d = this.currPeriod;
int currMonth = d.getMonth();
int currYear = d.getYear();
int currDay = d.getDate();
String theText = new String();
String tmpd1;
String tmpd2;
//check to see if the current date is before or after the 16th,
//if is is before this month is part of lay months billing cycle
if (currDay < 16)
{
//part of last month
//a the fix -- functions check to make sure that such problems as
//month, year wraps for jan-dec and year 2000 issues
tmpd1 = fixMonth(checkMonth(currMonth,-1)) + "/16/" + checkForCentury(checkYear(currYear,currMonth,-1,false));
tmpd2 = fixMonth(currMonth) + "/15/" + checkForCentury(currYear);
date1=fixMonth(checkMonth(currMonth,-1)) + "/16/" + checkYear(currYear,currMonth,-1,true);
date2=fixMonth(currMonth) + "/15/" + checkYear(currYear,currMonth,0,true);
theText = tmpd1 + " to " + tmpd2;
currYear = checkYear(currYear,currMonth,-1,false);
currMonth = checkMonth(currMonth,-1);
}
else {
//part of next month
tmpd1 = fixMonth(currMonth) + "/16/" + checkForCentury(currYear);
tmpd2 = fixMonth(checkMonth(currMonth,1)) + "/15/" + checkForCentury(checkYear(currYear,currMonth,1,false));
date1=fixMonth(currMonth) + "/16/" + checkYear(currYear,currMonth,0,true);
date2=fixMonth(checkMonth(currMonth,1)) + "/15/" + checkYear(currYear,currMonth,1,true);
theText = tmpd1 + " to " + tmpd2;
}
timePeriod.setText(theText);
theGrid.setCurrMonth(currMonth,currYear);
}
private int fixMonth(int m) {
//add 1 to the month
return ++m;
}
//check to see if the month determined by the offset
//param needs to be wrapped - jan to dec or dec to jan
private int checkMonth(int theMonth, int offset)
{
int newMonth = theMonth + offset;
int result = newMonth;
if (newMonth > 11) {
result = 0;
}
if (newMonth < 0) {
result = 11;
}
return result;
}
private String checkForCentury(int y) {
String result = "0";
int tmpy;
if (y > 99) {
tmpy = y-100;
result = result + tmpy;
int subS = result.length() - 2;
result = result.substring(subS);
}
else {
result = Integer.toString(y);
}
return result;
}
//make sure any additions to a date account for the year change and
//the year 200
private int checkYear(int theYear, int theMonth, int offset,boolean opt) {
int result =theYear;
if ((theMonth + offset) > 11) {
result++;
}
if ((theMonth + offset) < 0) {
result--;
}
if (opt == true) {
//add century info
if (result > 99) {
//subtract 100 add 2000
result = result - 99 + 2000;
}
else {
result = result + 1900;
}
}
return result;
}
//this is used to make a where clause clip that can be added to
//a sql statement to get data for a given date range
private String makeDataDateFilter(String colIndent) {
String res = new String();
res = "and " + colIndent + "start_date between to_date('" + date1;
res= res + "','MM/DD/YYYY') and to_date('" + date2 + "','MM/DD/YYYY')";
return res;
}
//move the current period either foreward or backwards
private Date moveCurrPeriod(int direction) {
Date d = currPeriod;
int newYear = checkYear(d.getYear(),d.getMonth(),direction,false);
int newDay=d.getDate();
int newMonth=checkMonth(d.getMonth(),direction);
return new Date (newYear,newMonth,newDay);
}
//this function determines if an update to the database should be allowed
public boolean allowUpdates() {
boolean result = false; //false is the def value
//first of all is the applet in the right state?
if (updateState == true) {
//now check to see if the user is either an admin or is changing thier own time
if ((userName.equals(empChooser.getSelectedItem().trim())) || (isAdmin == true)) {
result = true;
}
}
return result;
}
public boolean handleEvent(Event evt)
{
// @U002 - need to capture return results of Server update.
int updateReturnCode = 1;
if ((evt.target == prevPeriod)&& (evt.id == Event.ACTION_EVENT))
{
currPeriod = moveCurrPeriod(-1);
fillDatePeriod();
performDataLoad(); //0,0 means do not move grid position
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == nextPeriod)&& (evt.id == Event.ACTION_EVENT))
{
currPeriod = moveCurrPeriod(1);
fillDatePeriod();
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == projNameOpt)&& (evt.id == Event.ACTION_EVENT))
{
theGrid.setProjNameOpt(projNameOpt.getState());
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == empChooser)&& (evt.id == Event.ACTION_EVENT))
{
hasDataBeenLoaded = true;
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == addProj) && (evt.id == Event.ACTION_EVENT))
{
// Only create the object if it doesn't exist. Otherwise we will reuse the same object.
if (ap == null)
{
ap = new AddNewProj(empChooser.getSelectedItem().trim(), SqlBroker, theGrid, projNameOpt.getState());
}
ap.setVisible(empChooser.getSelectedItem().trim(),true);
theGrid.setVBarMax();
// @A001 - setVBarMax disables vertical scroll bar, so reenable it here.
theGrid.enableScrolls(true);
}
if ((evt.target == gotoCurrMon) && (evt.id == Event.ACTION_EVENT))
{
currPeriod = new Date();
fillDatePeriod();
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == setProjOrder) && (evt.id == Event.ACTION_EVENT))
{
//if general projects are set to be displayed first, toggle desc and
//set global boolean to false
if (genFirst == true)
{
setProjOrder.setLabel("Gen Proj 1st");
genFirst = false;
}
else
{
setProjOrder.setLabel("Spc Proj 1st");
genFirst = true;
}
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == updateDb) && (evt.id == Event.ACTION_EVENT))
{
//check to see if a save should be disallowed due to month end
if (checkForMonthEnd() == true)
{
//a save is allowed
//if we are sending deferred time , send a false, else send a
//true along with the emp_id for this employee. @U002
updateReturnCode = theGrid.saveData(empChooser.getSelectedItem().trim());
performDataLoad(theGrid.getHVal(), theGrid.getVVal());
enableUpdate(allowUpdates());
// @U002
if (updateReturnCode > 0)
{
//Data updated ok, inform user
SaveDialog sd = new SaveDialog();
sd.setVisible(true);
}
else if (updateReturnCode == 0)
{
//No rows affected, could this be a problem???
ErrorDialog ed = new ErrorDialog("WARNING - Data Update", "No data was updated! If you think this","is in error, contact the PTrack Administrator.");
ed.setVisible(true);
}
else
{
//Error returned - inform the user that their data was not saved.
ErrorDialog ed = new ErrorDialog("ERROR - Data Update", "Severe error occurred, no data was updated!","Please contact the PTrack Administrator.");
ed.setVisible(true);
}
}
else
{
//an update is not allowed, pop up a dialog to inform the user
NoUpdateDialog noUp = new NoUpdateDialog();
noUp.setVisible(true);
}
}
if ((evt.target == dayDef) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'D' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayChg) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'C' ";
updateState = false;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayApp) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'Y' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayNonChg) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'N' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayTotal) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " ";
updateState = false;
performDataLoad();
enableUpdate(allowUpdates());
}
return false;
}
private boolean checkForMonthEnd() {
//first check to see if the month end indicator is set to Y and
//that the time being changed is Approved and the month is not the
//current month
boolean result = true;
String theSql = "SELECT SYS_COLUMN_VALUE FROM PTRACK.PTRACK_SYS ";
theSql = theSql + " WHERE SYS_COLUMN_NAME = 'MONTH_END_IND'";
DataSet ds = SqlBroker.submitQuery(theSql);
if (ds.getString(0,0).equals("Y")) {
//the month end indicator is yes
//check to see if the month and year of the current period
//match today
if (timeStsCode.equals(" and pt.time_status_code = 'Y' ")) {
//it is approved, disallow changes to this time period
result = false;
}
}
return result;
}
public boolean getProjNameOpt()
{
return projNameOpt.getState();
}
private void performDataLoad()
{
//this version of performDataLoad is for the non
//dbupdate loads. It assumes a call to performDataLoad(0,0)
//unless the current period is the current month
Date now = new Date();
if ((currPeriod.getMonth() == now.getMonth()) && (currPeriod.getYear() == now.getYear())) {
//if it is the current month, then move the grid to todays date
performDataLoad(determineArrayIndex(now.getDate()),0);
}
else {
performDataLoad(0,0);
}
}
//detemines the position in the array the grid should be sent to given
//the current day as rawIndex
private int determineArrayIndex(int rawIndex)
{
int res;
// calculate the number of days in the last month
Date d = new Date();
int thisYear=checkYear(d.getYear(),d.getMonth(),-1,false);
int thisMonth=checkMonth(d.getMonth(),-1);
int numDays=theGrid.numDaysInMonth(thisMonth,thisYear);
if (rawIndex < 16) {
res = 15 + rawIndex - (31-numDays);
}
else {
res = rawIndex - 16;
}
return res;
}
//load the data from the database for the current projects
private void performDataLoad(int x, int y) {
//make sure controls are diabled
enableAllControls(false);
this.showStatus("Loading data ...");
loadProjects();
//load the data from db, and set grid to be at position x,y
loadTimeData(x,y);
//reneable controls
enableAllControls(true);
this.showStatus("Load Complete.");
}
//load all of the projects for the current user, time period and time type
private void loadProjects() {
if (hasDataBeenLoaded == true) {
DataSet ds;
if (timeStsCode.equals(" ")) {
ds = SqlBroker.sendTotalsProjListRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2,genFirst);
}
else {
ds = SqlBroker.sendProjListRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2,genFirst);
}
theGrid.bindProjectsFromDB(ds,0,1,2,3,4);
theGrid.setVBarMax();
}
}
private void loadTimeData(int x, int y) {
if (hasDataBeenLoaded == true) {
DataSet ds;
if (timeStsCode.equals(" ")) {
ds = SqlBroker.sendLoadTotalDataRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2);
}
else {
ds = SqlBroker.sendLoadDataRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2);
}
theGrid.loadTimeData(ds,0,1,2,3,4,5,x,y);
}
}
}
(Review ID: 53070)
======================================================================
Name: sh38129 Date: 01/22/99
We have a time entry applet that uses a grid layout for each day and project. If the user enters hours for a particular day, but then leaves the page (before saving) by clicking the back,home, etc buttons, we present the user with a warning that they have unsaved data. The warning is a simple frame that allows the user to click on "Save" or "Don't Save" buttons. If "Save" is clicked, a request (with the updated data) is sent to the server for insertion/update in the database. This scenario is captured by checking for changed data in the applet's stop() method.
Even though the browser exits the applet page, this frame is displayed quickly and works just fine under Netscape 3. However, under IE 4.0, the browser goes comatose. It goes into "Not Responding" mode for about 90-120 seconds and partially paints the frame. After this coma time period, the browser revives, finishes painting the frame, loads the page per the user request, and if the user clicks "Save", the data is saved in the database. Everything works, but the user has to wait 2 minutes for the browser to come back to life.
I loaded the jdk 1.2 production release to see if that would take care of the problem, however, using the 1.2 plugin causes Dr. Watson to appear when I load the applet. I get this if the applet source has been compiled under the jdk 1.1.5 or 1.2 compiler. The console displays messages regarding caching errors, which I have not seen before, so I'm assuming this is causing the crash.
However, if I load the 1.2 plugin, but tell the 1.2 Control Panel Applet to use the 1.1.6 JRE, IE 4.0 performs just fine. No hangs, etc.
I haven't tried Netscape 4, but as I said before, the plugin works fine under Netscape 3. Based on this behavior, I'm guessing that the actual plugin for IE has the bug. I'm assuming that the ActiveX control that IE is utilizing as the plugin is not communicating properly with the browser, while the Netscape plugin(which is really a plugin) doesn't have the problem. This assumption is also confirmed since the 1.2 IE plugin works ok with the JRE 1.1.6.
Now, if I could just get the JRE 1.2 working properly, I'd be set, but for now, I have to have both JRE 1.1.6 and JRE 1.2 loaded so the 1.2 plugin can access the 1.1.6 JRE. When I load the applet under JRE 1.2, the console spews out several CacheHandler errors and IE dies with a Dr. Watson.
I have been experimenting with the 1.1 plugin and have gotten the "wait" or "Not Responding" time period down to about 15 seconds (instead of 2 minutes). In the stop() method, I create the "Save" frame and then put the thread into a wait state for 5 secords so the browser doesn't call destroy()immediately. This seems to give the applet some more time to present the frame to the user, but it still delays for 15 seconds. Weird...
Below is the main class:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.applet.*;
import DataSet;
import SqlPipe;
import TimeGrid;
public class TimeEntry extends Applet {
public static final int DEF_PORT = 5025;
Socket s; //the socket connection to the pass thru server
SqlPipe SqlBroker; //a link to the database
boolean isAdmin = false; //a flag that determines when certain options should be enabled
String date1;
String date2;
boolean updateState = false; //a flag that tells if updates should be allowed
boolean genFirst = true; //a flag that says if general projects should be shown first
//all of the controls
java.awt.Panel topToolBar;
java.awt.Panel rightToolBar;
java.awt.Label lblEmpName;
java.awt.Choice empChooser;
java.awt.Label lblTimePer;
java.awt.Label timePeriod;
java.awt.Button prevPeriod;
java.awt.Button nextPeriod;
java.awt.Button updateDb;
java.awt.Button addProj;
java.awt.Button gotoCurrMon;
java.awt.Button setProjOrder;
java.awt.CheckboxGroup typeGroup;
java.awt.Checkbox dayTotal;
java.awt.Checkbox dayDef;
java.awt.Checkbox dayChg;
java.awt.Checkbox dayNonChg;
java.awt.Checkbox dayApp;
java.awt.Checkbox projNameOpt;
TimeGrid theGrid;
PreventDataLossDialog pdl;
AddNewProj ap = null;
Panel gridHolder;
Date currPeriod;
String userName; //the name of the user
String timeStsCode;
boolean hasDataBeenLoaded = false;
boolean monthEndFlag;
public void init()
{
super.init();
//get username from applet
userName = this.getParameter("UsrName").toUpperCase();
//get admin flag from applet
String adminParam = this.getParameter("UserType");
//if adminParam = ADMINISTRATOR then this user is an admin
if (adminParam.trim().equals("ADMINISTRATOR")) {
isAdmin = true;
}
else {
isAdmin = false;
}
//check to see if month end processing is in effect
String monthEnd = this.getParameter("MonthEnd");
// System.out.println("ME:" + monthEnd);
if (monthEnd.trim().equals("Y")) {
//month end is happening
monthEndFlag=true;
} else {
monthEndFlag = false;
}
//set up connection to database
try
{
//set up the socket and create a thread that
//will listen for anything coming from the server
s = new Socket(this.getCodeBase().getHost(),DEF_PORT);
SqlBroker = new SqlPipe(s);
theGrid = new TimeGrid(SqlBroker,9,5,30,2);
//{{INIT_CONTROLS
setLayout(null);
addNotify();
setSize(588,300);
topToolBar = new java.awt.Panel();
topToolBar.setLayout(null);
topToolBar.setBounds(0,0,660,25);
topToolBar.setBackground(new Color(12632256));
add(topToolBar);
rightToolBar = new java.awt.Panel();
rightToolBar.setLayout(null);
rightToolBar.setBounds(588,24,72,288);
rightToolBar.setBackground(new Color(12632256));
add(rightToolBar);
lblEmpName = new java.awt.Label("Employee");
lblEmpName.setBounds(12,0,60,24);
lblEmpName.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(lblEmpName);
empChooser = new java.awt.Choice();
topToolBar.add(empChooser);
empChooser.setBounds(72,0,144,21);
lblTimePer = new java.awt.Label("Time Period");
lblTimePer.setBounds(228,0,70,24);
lblTimePer.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(lblTimePer);
timePeriod = new java.awt.Label("");
timePeriod.setBounds(300,0,150,24);
timePeriod.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(timePeriod);
projNameOpt = new java.awt.Checkbox("True Proj Names");
projNameOpt.setState(false);
projNameOpt.setBounds(450,0,100,21);
projNameOpt.setFont(new Font("Dialog", Font.PLAIN, 10));
topToolBar.add(projNameOpt);
prevPeriod = new java.awt.Button("<<");
prevPeriod.setBounds(590,0,30,24);
topToolBar.add(prevPeriod);
nextPeriod = new java.awt.Button(">>");
nextPeriod.setBounds(625,0,30,24);
topToolBar.add(nextPeriod);
updateDb = new java.awt.Button("Update Time");
updateDb .setBounds(0,35,72,21);
rightToolBar.add(updateDb );
addProj = new java.awt.Button("Add Proj");
addProj.setBounds(0,62,72,21);
rightToolBar.add(addProj);
gotoCurrMon = new java.awt.Button("Curr Mon");
gotoCurrMon.setBounds(0,8,72,21);
rightToolBar.add(gotoCurrMon);
setProjOrder = new java.awt.Button("Spc Proj 1st");
setProjOrder.setBounds(0,89,72,21);
rightToolBar.add(setProjOrder);
theGrid.setBounds(0,24,588,287);
add(theGrid);
//load the sysdate from oracle
String datesql = "select to_char(sysdate, 'MM/DD/YYYY') from dual";
currPeriod = new Date(SqlBroker.submitQuery(datesql).getString(0,0));
//if the admin paramter is set to administrator, then show all
//of the users.
String sql = new String();
if (isAdmin == false)
{
//not an admin
sql = "select emp_id from ptrack.employees ";
sql =sql + "connect by prior emp_id = supervisor_id ";
sql =sql + "start with emp_id = '" + userName + "'";
}
else
{
// this person is an admin
sql = " select distinct emp_id from ptrack.employees ";
sql = sql + " where emp_id <> '" + userName + "'";
}
//fill in all valid ids for this employee
fillNameList(sql,0);
typeGroup = new CheckboxGroup();
dayNonChg = new java.awt.Checkbox("Non-Chg", typeGroup, false);
dayNonChg.setBounds(0,143,72,21);
dayNonChg.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayNonChg);
dayDef = new java.awt.Checkbox("Deferred", typeGroup, false);
dayDef.setBounds(0,116,72,21);
dayDef.setState(true);
dayDef.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayDef);
dayChg = new java.awt.Checkbox("Charged", typeGroup, false);
dayChg.setBounds(0,197,72,21);
dayChg.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayChg);
dayApp = new java.awt.Checkbox("Approved", typeGroup, false);
dayApp.setBounds(0,170,72,21);
dayApp.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayApp);
dayTotal = new java.awt.Checkbox("Total", typeGroup, false);
dayTotal.setBounds(0,224,72,21);
dayTotal.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayTotal);
//fill todays date period
fillDatePeriod();
//}}
//set inital value of time status code
timeStsCode = " and pt.time_status_code = 'D' ";
//disable all controls
this.setConrolStates(false);
this.enableUpdate(allowUpdates());
//now set value of updateState = true;
//because this new radio button is the default
updateState = true;
enableAllControls(true);
// Load the initial set of data for the default user and time period selected
hasDataBeenLoaded = true;
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
pdl = new PreventDataLossDialog("Save Your Data!");
pdl.init("Your time data has not been saved yet!",
" Click Save to Save your data.",
" Click Don't Save to LOSE your changes.");
}
catch (Exception e)
{
try
{
System.out.println("Error Connecting Socket:" + e);
showStatus("There is a problem Connecting to the Server!!!");
//create a link to javascript to load the error html page
Graphics g = this.getGraphics();
g.drawString("ERROR",50,50);
this.repaint();
}
catch(Exception e1)
{
this.stop();
}
}
// @A001 - this was needed in order to paint the applet completely.
// It shouldn't be needed, but under the Java 1.1 plugin, the applet does
// not get completely painted unless we have this here. Note: this is not
// needed under the MS IE 4.0 or Netscape 3 VM.
setVisible(true);
}
public synchronized void waitOnMe()
{
try
{
System.out.println("Waiting for 5 secs");
wait(5000);
}
catch (InterruptedException e)
{
System.out.println("Wait was interrupted");
}
}
public void destroy()
{
System.out.println("Yup. I'm a goner!");
// try
// {
// System.out.println("Waiting for 10 secs");
// wait(10000);
// }
// catch (InterruptedException e)
// {
// System.out.println("Wait was interrupted");
// }
// super.destroy();
}
public abstract class ActionAdapter implements ActionListener { }
public class PreventDataLossDialog extends Frame
{
Button saveBtn;
Button noSaveBtn;
Panel dlgPanelText;
Panel dlgPanelBtn;
Label label1;
Label label2;
Label label3;
PreventDataLossDialog()
{
super();
}
PreventDataLossDialog(String title)
{
this();
setTitle(title);
}
public void saveData()
{
int updateReturnCode = theGrid.saveData(empChooser.getSelectedItem().trim());
if (updateReturnCode > 0)
{
//Data updated ok, inform user
SaveDialog sd = new SaveDialog();
sd.setVisible(true);
}
else if (updateReturnCode == 0)
{
//No rows affected, could this be a problem???
ErrorDialog ed = new ErrorDialog("WARNING - Data Update", "No data was updated! If you think this","is in error, contact the PTrack Administrator.");
ed.setVisible(true);
}
else
{
//Error returned - inform the user that their data was not saved.
ErrorDialog ed = new ErrorDialog("ERROR - Data Update", "Severe error occurred, no data was updated!","Please contact the PTrack Administrator.");
ed.setVisible(true);
}
exitDlg();
}
public void exitDlg()
{
this.setVisible(false);
this.dispose();
}
public void init(String lab1, String lab2, String lab3)
{
setLayout(new BorderLayout());
setSize(275,220);
setBackground(new Color(12632256));
setResizable(false);
setLocation(100,150);
dlgPanelText = new Panel();
dlgPanelBtn = new Panel();
dlgPanelText.setLayout(new FlowLayout());
dlgPanelBtn.setLayout(new FlowLayout());
label1 = new Label(lab1);
label2 = new Label(lab2);
label3 = new Label(lab3);
dlgPanelText.add(label1);
dlgPanelText.add(label2);
dlgPanelText.add(label3);
saveBtn = new Button("Save");
dlgPanelBtn.add(saveBtn);
noSaveBtn = new Button("Don't Save");
dlgPanelBtn.add(noSaveBtn);
this.add(dlgPanelText,"Center");
this.add(dlgPanelBtn,"South");
saveBtn.addActionListener(
new ActionAdapter() {
public void actionPerformed(ActionEvent e) {
saveData();
}
}
);
noSaveBtn.addActionListener(
new ActionAdapter() {
public void actionPerformed(ActionEvent e) {
exitDlg();
}
}
);
this.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent w) {
exitDlg();
}
}
);
}
}
// @A003. Stop() is called if the user leaves the current page or the applet is destroyed.
// Before we proceed however, check for unsaved data and prompt the user if they want to
// save it or lose it.
public void stop()
{
System.out.println("Entering Stop.");
if (theGrid.checkForChangedData() == true)
{
System.out.println("Check for changed data is true");
//check to see if a save should be disallowed due to month end
if (checkForMonthEnd() == true)
{
System.out.println("Check for month end is true");
//a save is allowed
//if we are sending deferred time , send a false, else send a
//true along with the emp_id for this employee. @U002
pdl.show();
}
}
waitOnMe();
// super.stop();
}
//set the states of all controls, it is used
//to ensure the user does not get click happy
public void enableAllControls(boolean opt) {
if (isAdmin == true) {
opt = true;
}
setConrolStates(opt);
enableUpdate(opt);
dayTotal.setEnabled(opt);
dayDef.setEnabled(opt);
dayChg.setEnabled(opt);
dayNonChg.setEnabled(opt);
dayApp.setEnabled(opt);
//finally check to
//if so, disable the prevPeriod button
if (monthEndFlag == true) {
prevPeriod.setEnabled(false);
}
}
public void setConrolStates(boolean opt) {
if (isAdmin == true) {
opt = true;
}
prevPeriod.setEnabled(opt);
nextPeriod.setEnabled(opt);
theGrid.enableScrolls(opt);
gotoCurrMon.setEnabled(opt);
projNameOpt.setEnabled(opt);
}
public void enableUpdate(boolean opt) {
updateDb.setEnabled(opt);
addProj.setEnabled(opt);
setProjOrder.setEnabled(opt);
}
//fills the name list combo box with users
//given a sql statement
public void fillNameList(String theSql, int col) {
DataSet ds = SqlBroker.submitQuery(theSql);
//if this person is a Ptrack admin add their name to the list
if (isAdmin == true) {
empChooser.add(userName);
}
for (int i=0;i<ds.getNumRows();i++) {
empChooser.add(ds.getString(i,col));
}
}
public void drawOutline(Component c) {
Graphics g = c.getGraphics();
int h = c.size().height-5;
int w = c.size().width-5;
g.drawRect(0,0,w,h);
}
//fill the date period label, this also sets two strings:
//date1 and date2 that are used as date ranges for any sql
//selects
public void fillDatePeriod() {
Date d = this.currPeriod;
int currMonth = d.getMonth();
int currYear = d.getYear();
int currDay = d.getDate();
String theText = new String();
String tmpd1;
String tmpd2;
//check to see if the current date is before or after the 16th,
//if is is before this month is part of lay months billing cycle
if (currDay < 16)
{
//part of last month
//a the fix -- functions check to make sure that such problems as
//month, year wraps for jan-dec and year 2000 issues
tmpd1 = fixMonth(checkMonth(currMonth,-1)) + "/16/" + checkForCentury(checkYear(currYear,currMonth,-1,false));
tmpd2 = fixMonth(currMonth) + "/15/" + checkForCentury(currYear);
date1=fixMonth(checkMonth(currMonth,-1)) + "/16/" + checkYear(currYear,currMonth,-1,true);
date2=fixMonth(currMonth) + "/15/" + checkYear(currYear,currMonth,0,true);
theText = tmpd1 + " to " + tmpd2;
currYear = checkYear(currYear,currMonth,-1,false);
currMonth = checkMonth(currMonth,-1);
}
else {
//part of next month
tmpd1 = fixMonth(currMonth) + "/16/" + checkForCentury(currYear);
tmpd2 = fixMonth(checkMonth(currMonth,1)) + "/15/" + checkForCentury(checkYear(currYear,currMonth,1,false));
date1=fixMonth(currMonth) + "/16/" + checkYear(currYear,currMonth,0,true);
date2=fixMonth(checkMonth(currMonth,1)) + "/15/" + checkYear(currYear,currMonth,1,true);
theText = tmpd1 + " to " + tmpd2;
}
timePeriod.setText(theText);
theGrid.setCurrMonth(currMonth,currYear);
}
private int fixMonth(int m) {
//add 1 to the month
return ++m;
}
//check to see if the month determined by the offset
//param needs to be wrapped - jan to dec or dec to jan
private int checkMonth(int theMonth, int offset)
{
int newMonth = theMonth + offset;
int result = newMonth;
if (newMonth > 11) {
result = 0;
}
if (newMonth < 0) {
result = 11;
}
return result;
}
private String checkForCentury(int y) {
String result = "0";
int tmpy;
if (y > 99) {
tmpy = y-100;
result = result + tmpy;
int subS = result.length() - 2;
result = result.substring(subS);
}
else {
result = Integer.toString(y);
}
return result;
}
//make sure any additions to a date account for the year change and
//the year 200
private int checkYear(int theYear, int theMonth, int offset,boolean opt) {
int result =theYear;
if ((theMonth + offset) > 11) {
result++;
}
if ((theMonth + offset) < 0) {
result--;
}
if (opt == true) {
//add century info
if (result > 99) {
//subtract 100 add 2000
result = result - 99 + 2000;
}
else {
result = result + 1900;
}
}
return result;
}
//this is used to make a where clause clip that can be added to
//a sql statement to get data for a given date range
private String makeDataDateFilter(String colIndent) {
String res = new String();
res = "and " + colIndent + "start_date between to_date('" + date1;
res= res + "','MM/DD/YYYY') and to_date('" + date2 + "','MM/DD/YYYY')";
return res;
}
//move the current period either foreward or backwards
private Date moveCurrPeriod(int direction) {
Date d = currPeriod;
int newYear = checkYear(d.getYear(),d.getMonth(),direction,false);
int newDay=d.getDate();
int newMonth=checkMonth(d.getMonth(),direction);
return new Date (newYear,newMonth,newDay);
}
//this function determines if an update to the database should be allowed
public boolean allowUpdates() {
boolean result = false; //false is the def value
//first of all is the applet in the right state?
if (updateState == true) {
//now check to see if the user is either an admin or is changing thier own time
if ((userName.equals(empChooser.getSelectedItem().trim())) || (isAdmin == true)) {
result = true;
}
}
return result;
}
public boolean handleEvent(Event evt)
{
// @U002 - need to capture return results of Server update.
int updateReturnCode = 1;
if ((evt.target == prevPeriod)&& (evt.id == Event.ACTION_EVENT))
{
currPeriod = moveCurrPeriod(-1);
fillDatePeriod();
performDataLoad(); //0,0 means do not move grid position
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == nextPeriod)&& (evt.id == Event.ACTION_EVENT))
{
currPeriod = moveCurrPeriod(1);
fillDatePeriod();
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == projNameOpt)&& (evt.id == Event.ACTION_EVENT))
{
theGrid.setProjNameOpt(projNameOpt.getState());
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == empChooser)&& (evt.id == Event.ACTION_EVENT))
{
hasDataBeenLoaded = true;
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == addProj) && (evt.id == Event.ACTION_EVENT))
{
// Only create the object if it doesn't exist. Otherwise we will reuse the same object.
if (ap == null)
{
ap = new AddNewProj(empChooser.getSelectedItem().trim(), SqlBroker, theGrid, projNameOpt.getState());
}
ap.setVisible(empChooser.getSelectedItem().trim(),true);
theGrid.setVBarMax();
// @A001 - setVBarMax disables vertical scroll bar, so reenable it here.
theGrid.enableScrolls(true);
}
if ((evt.target == gotoCurrMon) && (evt.id == Event.ACTION_EVENT))
{
currPeriod = new Date();
fillDatePeriod();
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == setProjOrder) && (evt.id == Event.ACTION_EVENT))
{
//if general projects are set to be displayed first, toggle desc and
//set global boolean to false
if (genFirst == true)
{
setProjOrder.setLabel("Gen Proj 1st");
genFirst = false;
}
else
{
setProjOrder.setLabel("Spc Proj 1st");
genFirst = true;
}
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
}
if ((evt.target == updateDb) && (evt.id == Event.ACTION_EVENT))
{
//check to see if a save should be disallowed due to month end
if (checkForMonthEnd() == true)
{
//a save is allowed
//if we are sending deferred time , send a false, else send a
//true along with the emp_id for this employee. @U002
updateReturnCode = theGrid.saveData(empChooser.getSelectedItem().trim());
performDataLoad(theGrid.getHVal(), theGrid.getVVal());
enableUpdate(allowUpdates());
// @U002
if (updateReturnCode > 0)
{
//Data updated ok, inform user
SaveDialog sd = new SaveDialog();
sd.setVisible(true);
}
else if (updateReturnCode == 0)
{
//No rows affected, could this be a problem???
ErrorDialog ed = new ErrorDialog("WARNING - Data Update", "No data was updated! If you think this","is in error, contact the PTrack Administrator.");
ed.setVisible(true);
}
else
{
//Error returned - inform the user that their data was not saved.
ErrorDialog ed = new ErrorDialog("ERROR - Data Update", "Severe error occurred, no data was updated!","Please contact the PTrack Administrator.");
ed.setVisible(true);
}
}
else
{
//an update is not allowed, pop up a dialog to inform the user
NoUpdateDialog noUp = new NoUpdateDialog();
noUp.setVisible(true);
}
}
if ((evt.target == dayDef) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'D' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayChg) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'C' ";
updateState = false;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayApp) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'Y' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayNonChg) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " and pt.time_status_code = 'N' ";
updateState = true;
performDataLoad();
enableUpdate(allowUpdates());
}
if ((evt.target == dayTotal) && (evt.id == Event.ACTION_EVENT))
{
timeStsCode = " ";
updateState = false;
performDataLoad();
enableUpdate(allowUpdates());
}
return false;
}
private boolean checkForMonthEnd() {
//first check to see if the month end indicator is set to Y and
//that the time being changed is Approved and the month is not the
//current month
boolean result = true;
String theSql = "SELECT SYS_COLUMN_VALUE FROM PTRACK.PTRACK_SYS ";
theSql = theSql + " WHERE SYS_COLUMN_NAME = 'MONTH_END_IND'";
DataSet ds = SqlBroker.submitQuery(theSql);
if (ds.getString(0,0).equals("Y")) {
//the month end indicator is yes
//check to see if the month and year of the current period
//match today
if (timeStsCode.equals(" and pt.time_status_code = 'Y' ")) {
//it is approved, disallow changes to this time period
result = false;
}
}
return result;
}
public boolean getProjNameOpt()
{
return projNameOpt.getState();
}
private void performDataLoad()
{
//this version of performDataLoad is for the non
//dbupdate loads. It assumes a call to performDataLoad(0,0)
//unless the current period is the current month
Date now = new Date();
if ((currPeriod.getMonth() == now.getMonth()) && (currPeriod.getYear() == now.getYear())) {
//if it is the current month, then move the grid to todays date
performDataLoad(determineArrayIndex(now.getDate()),0);
}
else {
performDataLoad(0,0);
}
}
//detemines the position in the array the grid should be sent to given
//the current day as rawIndex
private int determineArrayIndex(int rawIndex)
{
int res;
// calculate the number of days in the last month
Date d = new Date();
int thisYear=checkYear(d.getYear(),d.getMonth(),-1,false);
int thisMonth=checkMonth(d.getMonth(),-1);
int numDays=theGrid.numDaysInMonth(thisMonth,thisYear);
if (rawIndex < 16) {
res = 15 + rawIndex - (31-numDays);
}
else {
res = rawIndex - 16;
}
return res;
}
//load the data from the database for the current projects
private void performDataLoad(int x, int y) {
//make sure controls are diabled
enableAllControls(false);
this.showStatus("Loading data ...");
loadProjects();
//load the data from db, and set grid to be at position x,y
loadTimeData(x,y);
//reneable controls
enableAllControls(true);
this.showStatus("Load Complete.");
}
//load all of the projects for the current user, time period and time type
private void loadProjects() {
if (hasDataBeenLoaded == true) {
DataSet ds;
if (timeStsCode.equals(" ")) {
ds = SqlBroker.sendTotalsProjListRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2,genFirst);
}
else {
ds = SqlBroker.sendProjListRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2,genFirst);
}
theGrid.bindProjectsFromDB(ds,0,1,2,3,4);
theGrid.setVBarMax();
}
}
private void loadTimeData(int x, int y) {
if (hasDataBeenLoaded == true) {
DataSet ds;
if (timeStsCode.equals(" ")) {
ds = SqlBroker.sendLoadTotalDataRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2);
}
else {
ds = SqlBroker.sendLoadDataRequest(empChooser.getSelectedItem().trim(),timeStsCode,date1,date2);
}
theGrid.loadTimeData(ds,0,1,2,3,4,5,x,y);
}
}
}
(Review ID: 53070)
======================================================================
Name: sh38129 Date: 01/22/99
We have a time entry applet that uses a grid layout for each day and project. If the user enters hours for a particular day, but then leaves the page (before saving) by clicking the back,home, etc buttons, we present the user with a warning that they have unsaved data. The warning is a simple frame that allows the user to click on "Save" or "Don't Save" buttons. If "Save" is clicked, a request (with the updated data) is sent to the server for insertion/update in the database. This scenario is captured by checking for changed data in the applet's stop() method.
Even though the browser exits the applet page, this frame is displayed quickly and works just fine under Netscape 3. However, under IE 4.0, the browser goes comatose. It goes into "Not Responding" mode for about 90-120 seconds and partially paints the frame. After this coma time period, the browser revives, finishes painting the frame, loads the page per the user request, and if the user clicks "Save", the data is saved in the database. Everything works, but the user has to wait 2 minutes for the browser to come back to life.
I loaded the jdk 1.2 production release to see if that would take care of the problem, however, using the 1.2 plugin causes Dr. Watson to appear when I load the applet. I get this if the applet source has been compiled under the jdk 1.1.5 or 1.2 compiler. The console displays messages regarding caching errors, which I have not seen before, so I'm assuming this is causing the crash.
However, if I load the 1.2 plugin, but tell the 1.2 Control Panel Applet to use the 1.1.6 JRE, IE 4.0 performs just fine. No hangs, etc.
I haven't tried Netscape 4, but as I said before, the plugin works fine under Netscape 3. Based on this behavior, I'm guessing that the actual plugin for IE has the bug. I'm assuming that the ActiveX control that IE is utilizing as the plugin is not communicating properly with the browser, while the Netscape plugin(which is really a plugin) doesn't have the problem. This assumption is also confirmed since the 1.2 IE plugin works ok with the JRE 1.1.6.
Now, if I could just get the JRE 1.2 working properly, I'd be set, but for now, I have to have both JRE 1.1.6 and JRE 1.2 loaded so the 1.2 plugin can access the 1.1.6 JRE. When I load the applet under JRE 1.2, the console spews out several CacheHandler errors and IE dies with a Dr. Watson.
I have been experimenting with the 1.1 plugin and have gotten the "wait" or "Not Responding" time period down to about 15 seconds (instead of 2 minutes). In the stop() method, I create the "Save" frame and then put the thread into a wait state for 5 secords so the browser doesn't call destroy()immediately. This seems to give the applet some more time to present the frame to the user, but it still delays for 15 seconds. Weird...
Below is the main class:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.applet.*;
import DataSet;
import SqlPipe;
import TimeGrid;
public class TimeEntry extends Applet {
public static final int DEF_PORT = 5025;
Socket s; //the socket connection to the pass thru server
SqlPipe SqlBroker; //a link to the database
boolean isAdmin = false; //a flag that determines when certain options should be enabled
String date1;
String date2;
boolean updateState = false; //a flag that tells if updates should be allowed
boolean genFirst = true; //a flag that says if general projects should be shown first
//all of the controls
java.awt.Panel topToolBar;
java.awt.Panel rightToolBar;
java.awt.Label lblEmpName;
java.awt.Choice empChooser;
java.awt.Label lblTimePer;
java.awt.Label timePeriod;
java.awt.Button prevPeriod;
java.awt.Button nextPeriod;
java.awt.Button updateDb;
java.awt.Button addProj;
java.awt.Button gotoCurrMon;
java.awt.Button setProjOrder;
java.awt.CheckboxGroup typeGroup;
java.awt.Checkbox dayTotal;
java.awt.Checkbox dayDef;
java.awt.Checkbox dayChg;
java.awt.Checkbox dayNonChg;
java.awt.Checkbox dayApp;
java.awt.Checkbox projNameOpt;
TimeGrid theGrid;
PreventDataLossDialog pdl;
AddNewProj ap = null;
Panel gridHolder;
Date currPeriod;
String userName; //the name of the user
String timeStsCode;
boolean hasDataBeenLoaded = false;
boolean monthEndFlag;
public void init()
{
super.init();
//get username from applet
userName = this.getParameter("UsrName").toUpperCase();
//get admin flag from applet
String adminParam = this.getParameter("UserType");
//if adminParam = ADMINISTRATOR then this user is an admin
if (adminParam.trim().equals("ADMINISTRATOR")) {
isAdmin = true;
}
else {
isAdmin = false;
}
//check to see if month end processing is in effect
String monthEnd = this.getParameter("MonthEnd");
// System.out.println("ME:" + monthEnd);
if (monthEnd.trim().equals("Y")) {
//month end is happening
monthEndFlag=true;
} else {
monthEndFlag = false;
}
//set up connection to database
try
{
//set up the socket and create a thread that
//will listen for anything coming from the server
s = new Socket(this.getCodeBase().getHost(),DEF_PORT);
SqlBroker = new SqlPipe(s);
theGrid = new TimeGrid(SqlBroker,9,5,30,2);
//{{INIT_CONTROLS
setLayout(null);
addNotify();
setSize(588,300);
topToolBar = new java.awt.Panel();
topToolBar.setLayout(null);
topToolBar.setBounds(0,0,660,25);
topToolBar.setBackground(new Color(12632256));
add(topToolBar);
rightToolBar = new java.awt.Panel();
rightToolBar.setLayout(null);
rightToolBar.setBounds(588,24,72,288);
rightToolBar.setBackground(new Color(12632256));
add(rightToolBar);
lblEmpName = new java.awt.Label("Employee");
lblEmpName.setBounds(12,0,60,24);
lblEmpName.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(lblEmpName);
empChooser = new java.awt.Choice();
topToolBar.add(empChooser);
empChooser.setBounds(72,0,144,21);
lblTimePer = new java.awt.Label("Time Period");
lblTimePer.setBounds(228,0,70,24);
lblTimePer.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(lblTimePer);
timePeriod = new java.awt.Label("");
timePeriod.setBounds(300,0,150,24);
timePeriod.setFont(new Font("Dialog", Font.PLAIN, 12));
topToolBar.add(timePeriod);
projNameOpt = new java.awt.Checkbox("True Proj Names");
projNameOpt.setState(false);
projNameOpt.setBounds(450,0,100,21);
projNameOpt.setFont(new Font("Dialog", Font.PLAIN, 10));
topToolBar.add(projNameOpt);
prevPeriod = new java.awt.Button("<<");
prevPeriod.setBounds(590,0,30,24);
topToolBar.add(prevPeriod);
nextPeriod = new java.awt.Button(">>");
nextPeriod.setBounds(625,0,30,24);
topToolBar.add(nextPeriod);
updateDb = new java.awt.Button("Update Time");
updateDb .setBounds(0,35,72,21);
rightToolBar.add(updateDb );
addProj = new java.awt.Button("Add Proj");
addProj.setBounds(0,62,72,21);
rightToolBar.add(addProj);
gotoCurrMon = new java.awt.Button("Curr Mon");
gotoCurrMon.setBounds(0,8,72,21);
rightToolBar.add(gotoCurrMon);
setProjOrder = new java.awt.Button("Spc Proj 1st");
setProjOrder.setBounds(0,89,72,21);
rightToolBar.add(setProjOrder);
theGrid.setBounds(0,24,588,287);
add(theGrid);
//load the sysdate from oracle
String datesql = "select to_char(sysdate, 'MM/DD/YYYY') from dual";
currPeriod = new Date(SqlBroker.submitQuery(datesql).getString(0,0));
//if the admin paramter is set to administrator, then show all
//of the users.
String sql = new String();
if (isAdmin == false)
{
//not an admin
sql = "select emp_id from ptrack.employees ";
sql =sql + "connect by prior emp_id = supervisor_id ";
sql =sql + "start with emp_id = '" + userName + "'";
}
else
{
// this person is an admin
sql = " select distinct emp_id from ptrack.employees ";
sql = sql + " where emp_id <> '" + userName + "'";
}
//fill in all valid ids for this employee
fillNameList(sql,0);
typeGroup = new CheckboxGroup();
dayNonChg = new java.awt.Checkbox("Non-Chg", typeGroup, false);
dayNonChg.setBounds(0,143,72,21);
dayNonChg.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayNonChg);
dayDef = new java.awt.Checkbox("Deferred", typeGroup, false);
dayDef.setBounds(0,116,72,21);
dayDef.setState(true);
dayDef.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayDef);
dayChg = new java.awt.Checkbox("Charged", typeGroup, false);
dayChg.setBounds(0,197,72,21);
dayChg.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayChg);
dayApp = new java.awt.Checkbox("Approved", typeGroup, false);
dayApp.setBounds(0,170,72,21);
dayApp.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayApp);
dayTotal = new java.awt.Checkbox("Total", typeGroup, false);
dayTotal.setBounds(0,224,72,21);
dayTotal.setFont(new Font("Dialog", Font.PLAIN, 12));
rightToolBar.add(dayTotal);
//fill todays date period
fillDatePeriod();
//}}
//set inital value of time status code
timeStsCode = " and pt.time_status_code = 'D' ";
//disable all controls
this.setConrolStates(false);
this.enableUpdate(allowUpdates());
//now set value of updateState = true;
//because this new radio button is the default
updateState = true;
enableAllControls(true);
// Load the initial set of data for the default user and time period selected
hasDataBeenLoaded = true;
performDataLoad();
enableUpdate(allowUpdates());
setConrolStates(true);
pdl = new PreventDataLossDialog("Save Your Data!");
pdl.init("Your time data has not been saved yet!",
" Click Save to Save your data.",
" Click Don't Save to LOSE your changes.");
}
catch (Exception e)
{
try
{
System.out.println("Error Connecting Socket:" + e);
showStatus("There is a problem Connecting to the Server!!!");
//create a link to javascript to load the error html page
Graphics g = this.getGraphics();
g.drawString("ERROR",50,50);
this.repaint();
}
catch(Exception e1)
{
this.stop();
}
}
// @A001 - this was needed in order to paint the applet completely.
// It shouldn't be needed, but under the Java 1.1 plugin, the applet does
// not get completely painted unless we have this here. Note: this is not
// needed under the MS IE 4.0 or Netscape 3 VM.
setVisible(true);
}
public synchronized void waitOnMe()
{
try
{
System.out.println("Waiting for 5 secs");
wait(5000);
}
catch (InterruptedException e)
{
System.out.println("Wait was interrupted");
}
}
public void destroy()
{
System.out.println("Yup. I'm a goner!");
// try
// {
// System.out.println("Waiting for 10 secs");
// wait(10000);
// }
// catch (InterruptedException e)
// {
// System.out.println("Wait was interrupted");
// }
// super.destroy();
}
public abstract class ActionAdapter implements ActionListener { }
public class PreventDataLossDialog extends Frame
{
Button saveBtn;
Button noSaveBtn;
Panel dlgPanelText;
Panel dlgPanelBtn;
Label label1;
Label label2;
Label label3;
PreventDataLossDialog()
{
super();
}
PreventDataLossDialog(String title)
{
this();
setTitle(title);
}
public void saveData()
{
int updateReturnCode = theGrid.saveData(empChooser.getSelectedItem().trim());
if (updateReturnCode > 0)
{
//Data updated ok, inform user
SaveDialog sd = new SaveDialog();
sd.setVisible(true);
}
else if (updateReturnCode == 0)
{
//No rows affected, could this be a problem???
ErrorDialog ed = new ErrorDialog("WARNING - Data Update", "No data was updated! If you think this","is in error, contact the PTrack Administrator.");
ed.setVisible(true);
}
else
{
//Error returned - inform the user that their data was not saved.
ErrorDialog ed = new ErrorDialog("ERROR - Data Update", "Severe error occurred, no data was updated!","Please contact the PTrack Administrator.");
ed.setVisible(true);
}
exitDlg();
}
public void exitDlg()
{
this.setVisible(false);
this.dispose();
}
public void init(String lab1, String lab2, String lab3)
{
setLayout(new BorderLayout());
setSize(275,220);
setBackground(new Color(12632256));
setResizable(false);
setLocation(100,150);
dlgPanelText = new Panel();
dlgPanelBtn = new Panel();
dlgPanelText.setLayout(new FlowLayout());
dlgPanelBtn.setLayout(new FlowLayout());
label1 = new Label(lab1);
label2 = new Label(lab2);
label3 = new Label(lab3);
dlgPanelText.add(label1);
dlgPanelText.add(label2);
dlgPanelText.add(label3);
saveBtn = new Button("Save");
dlgPanelBtn.add(saveBtn);
noSaveBtn = new Button("Don't Save");
dlgPanelBtn.add(noSaveBtn);
this.add(dlgPanelText,"Center");
this.add(dlgPanelBtn,"South");
saveBtn.addActionListener(
new ActionAdapter() {
public void actionPerformed(ActionEvent e) {
saveData();
}
}
);
noSaveBtn.addActionListener(
new ActionAdapter() {
public void actionPerformed(ActionEvent e) {
exitDlg();
}
}
);
this.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent w) {
exitDlg();
}
}
);
}
}
// @A003. Stop() is called if the user leaves the current page or the applet is destroyed.
// Before we proceed however, check for unsaved data and prompt the user if they want to
// save it or lose it.
public void stop()
{
System.out.println("Entering Stop.");
if (theGrid.checkForChangedData() == true)
{
System.out.println("Check for changed data is true");
//check to see if a save should be disallowed due to month end
if (checkForMonthEnd() == true)
{
System.out.println("Check for month end is true");
//a save is allowed
//if we are sending deferred time , send a false, else send a
//true along with the emp_id for this employee. @U002
pdl.show();
}
}
waitOnMe();
// super.stop();
}
//set the states of all controls, it is used
//to ensure the user does not get click happy
public void enableAllControls(boolean opt) {
if (isAdmin == true) {
opt = true;
}
setConrolStates(opt);
enableUpdate(opt);
dayTotal.setEnabled(opt);
dayDef.setEnabled(opt);
dayChg.setEnabled(opt);
dayNonChg.setEnabled(opt);
dayApp.setEnabled(opt);
//finally check to