Last Update 9 September 2006.
What Time Do I Leave Friday is a program I created in C# using Visual C# 2005 Express Edition. It is the first "semi-practical" program I have made. (I say "semi-practical" as I don't have a way of using it at work, since I don't have a laptop.)
Simply stated, the program is designed for people who are mostly on Flex Time and want to find out when they should leave on their last day of the work week. The user enters the hours they worked so far, the time they came in that day, a lunch if they take one, and it will give them the time to leave.
You can get it from here.
I will post the code to it's own page to keep this page from getting too far out of hand.
Here are some screenshots:
The main screen:

Here the user enters the total hours they worked so far this week (using the action menu they can change the standard work week hours from 40:00), they also enter the time they got in Friday (or whatever their last day of work is) and a lunch if applicable. It will then display what time they are to leave Friday.
Here is the lunch screen:

Here the user can choose to enter their lunch time (for example 0:30 for 30 minutes) or put in their time out to and in from lunch.
Here is the main screen after being used (I typically don't take a lunch, but for this example I entered one):

Here is some of the code (I don't present the code for the designer since I figure it isn't necessary, it should be easy enough to figure it out from the screenshots, the program itself and the code below). The code is presented in alphabetical order.
Changes Log:
9 September 2006 - Minor changes to the Validator class. Semi-major change to the main window itself. The program now checks if the user entered a decimal time in one of the two main text boxes, if so, a message box comes up to be sure that is what they wanted to enter. I probably didn't handle that one the best way.
This is the Convert Time class that easily enough converts the time from one format to another for use in the program.
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// NOTE: This will likely change in future versions
-
// to be in my own library set.
-
// **********************************************
-
// Class: ConvertTime
-
// Class Author: Brian A. Thomas
-
// Class webpage: http://www.brianathomas.com/
-
// This Class Version: 0.4
-
// This Class Copyright: 2006 by Brian A. Thomas
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
-
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// ConvertTime Class has a few methods for converting time
-
/// currently it converts a standard format time such as 8:30 into
-
/// decimal time, and from military time to standard time
-
/// </summary>
-
class ConvertTime
-
{
-
/// <summary>
-
/// Changes time from standard format such as 8:30 into decimal time
-
/// (not the French version) but breaking minutes into hundreds. For
-
/// example 8:30 becomes 8.5.
-
/// </summary>
-
/// <param name="s">time in string format without the AM/PM</param>
-
/// <returns>time in double format</returns>
-
public static double ToDecimal(string s)
-
{
-
// had to add as canceling a lunch addition caused an error.
-
if (s == null)
-
{
-
s = "0.00";
-
}
-
if (s.IndexOf(':') <0)
-
{
-
// for some reason using a conditional or in the above didn't
-
// work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
-
// <0) but if a string did have a : in it, it still went
-
// to CantConvert
-
if (s.IndexOf('.')>= 0)
-
{
-
// don't worry about it.
-
}
-
else
-
{
-
s = CantConvert(s);
-
}
-
}
-
if (s.IndexOf(':')> -1) // check to see if it has a : in the time
-
//if so we need to turn it into a decimal time for
-
{
-
// first split hours and minutes apart
-
string[] allTime = s.Split(':');
-
string hoursString = allTime[0];
-
string minutesString = allTime[1];
-
if (minutesString == "")
-
{
-
minutesString = "00";
-
}
-
//string secondsString = allTime[2];
-
// above not used currently
-
double minutes = Convert.ToInt32(minutesString);
-
minutes /= 60;
-
if (minutes <1 && minutes> 0)
-
{
-
string timeString = minutes.ToString();
-
string[] fullTime = timeString.Split('.');
-
string wholeString = fullTime[0];
-
string portionString = fullTime[1];
-
minutesString = portionString;
-
}
-
else
-
{
-
minutesString = "00";
-
}
-
string returnTime = hoursString + "." + minutesString;
-
double time = Convert.ToDouble(returnTime);
-
return time;
-
} // end if :
-
else
-
{
-
string returnTime = s;
-
// in theory, shouldn't need, but testing showed otherwise...
-
// actually, should be gone for sure now after adding the
-
// if(s==null) above, but will leave to be safe.
-
if (returnTime == "")
-
{
-
returnTime = "0.00";
-
}
-
double time = Convert.ToDouble(returnTime);
-
return time;
-
} // end else already in decimal time
-
}// end ToDecimal method of ConvertTime class
-
-
/// <summary>
-
/// Converts from military time to standard time in the event the user
-
/// entered military time (24 hour time compared to 12 hour time)
-
/// </summary>
-
/// <param name="s">time in string format without the AM/PM</param>
-
/// <returns>time in string format with :</returns>
-
public static string NonMillTime(string s)
-
{
-
if (s == null)
-
{
-
s = "0:00";
-
}
-
if (s.IndexOf(':') <0)
-
{
-
// for some reason using a conditional or in the above didn't
-
// work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
-
// <0) but if a string did have a : in it, it still went
-
// to CantConvert
-
if (s.IndexOf('.')>= 0)
-
{
-
// don't worry about it.
-
}
-
else
-
{
-
s = CantConvert(s);
-
}
-
}
-
string[] allTime = s.Split(':');
-
string hoursString = allTime[0];
-
string minutesString = allTime[1];
-
if (minutesString == "")
-
{
-
minutesString = "00";
-
}
-
// string secondsString = allTime[2];
-
// above not used currently
-
double hours = Convert.ToDouble(hoursString);
-
if (hours> 12)
-
{
-
hours -= 12;
-
WhatTimeFriday.MainWindow.PM = true;
-
} // end hours> 12
-
string returnTime = hours.ToString() + ":" + minutesString;
-
return returnTime;
-
} // end StandardTime Method of ConvertTime Class
-
-
/// <summary>
-
/// Truns decimal time (not French version) to stnadard time with
-
/// a : as the time seperator. So 8.5 becomes 8:30.
-
/// </summary>
-
/// <param name="s">time in string format without the AM/PM</param>
-
/// <returns>time in string format with :</returns>
-
public static string StandardTime(string s)
-
{
-
// had to add as canceling adding a lunch caused an error
-
if (s == null)
-
{
-
s = "0:00";
-
}
-
if (s.IndexOf(':') <0)
-
{
-
// for some reason using a conditional or in the above didn't
-
// work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
-
// <0) but if a string did have a : in it, it still went
-
// to CantConvert
-
if (s.IndexOf('.')>= 0)
-
{
-
// don't worry about it.
-
}
-
else
-
{
-
s = CantConvert(s);
-
}
-
}
-
if (s.IndexOf(':')> -1)
-
{
-
//already has a : so it is okay
-
// had to add the split just in case user entered
-
// :30 for lunch or something like that where the hour
-
// string is empty
-
string[] allTime = s.Split(':');
-
string hoursString = allTime[0];
-
string minutesString = allTime[1];
-
if (minutesString == "")
-
{
-
minutesString = "00";
-
}
-
if (hoursString == "")
-
{
-
hoursString = "0";
-
}
-
s = hoursString + ":" + minutesString;
-
return s;
-
} // end if s has a :
-
else
-
{
-
if (s == "" || s == "0")
-
{
-
s = "0.00";
-
}
-
string[] allTime = s.Split('.');
-
string hoursString = allTime[0];
-
// just in case the hoursString is empty
-
if (hoursString == "")
-
{
-
hoursString = "0";
-
}
-
string minutesString = allTime[1];
-
if (minutesString == "")
-
{
-
minutesString = "00";
-
}
-
// string secondsString = allTime[2];
-
// above not used currently
-
minutesString = "." + minutesString;
-
double minutes = Convert.ToDouble(minutesString);
-
minutes *= 60;
-
minutesString = minutes.ToString("f0"); //needs to remove the
-
// decimal place if there is one, otherwise there are problems
-
// probably will add to the seconds if that seconds are ever
-
// calculated
-
if (minutesString == "0")
-
{
-
minutesString = "00";
-
}
-
string returnTime = hoursString + ":" + minutesString;
-
return returnTime;
-
}
-
} // end StandardTime method of ConvertTimeClass
-
-
/// <summary>
-
/// Shouldn't actually be used as the method calling the ConvertTime
-
/// class should validate before sending.
-
/// If string coming into ConvertTiem doesn't have a : or a . in it
-
/// adds a :
-
/// </summary>
-
/// <param name="s">and integer in striang format</param>
-
/// <returns>a string with a : in it</returns>
-
private static string CantConvert(string s)
-
{
-
// Method calling the Convert Class should validate this before it
-
// sends it here, but just in case.
-
// presently I know of no way of knowing for sure which text box
-
// caused this from this class, which is why it should be validated
-
// by the method, class or something calling this class.
-
// Also, the string sent to the ConvertTime class may not be from a
-
// text box anyhow, so even knowing the text box may not help.
-
string sugestedTime;
-
if (s == "")
-
{
-
s = "0";
-
}
-
int number = Convert.ToInt32(s);
-
if (number <0)
-
{
-
// if the number is negative, reverse it
-
number = -number;
-
}
-
if (number> 24 && number <60)
-
{
-
// we'll guess that the user may want it in the minutes
-
// spot if it is over 24 and under 60 since it can't be
-
// more then 60 if it is minutes, and possibly minutes if
-
// over 24 which would be the limit of the hours spot if it
-
// is military time
-
sugestedTime = "0:" + s;
-
}
-
else
-
{
-
// this takes a huge range of 0 to 24 and from 60 on
-
// as noted above, the calling method to the ConvertTime
-
// class really needs to validate the string before sending
-
// it here
-
sugestedTime = s = ":00";
-
}
-
string message = "Can't convert " + s + " to a time.\n"
-
+ "It needs a ":" either before it (hours) or after it"
-
+ "(minutes).\n"
-
+ "Pressing OK will return " + sugestedTime + ". If this is not "
-
+ "correct you will need to edit the entry when you return.";
-
MessageBox.Show(message, "Entry Error");
-
return sugestedTime;
-
} // end CantConvert method of ConvertTime class
-
} // end ConvertTime class
-
}
Here is the code for the Hours Worked Calculator:
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// **********************************************
-
// This Class: HoursWorkedCalculator
-
// This Class Author: Brian A. Thomas
-
// This Class Version: 0.4
-
// This Class Copyright: 2006 by Brian A. Thomas
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// form for the Hours Worked Calculator
-
/// </summary>
-
public partial class HoursWorkedCalculator : Form
-
{
-
/// <summary>
-
/// Main class for the Hours Worked Calculator
-
/// </summary>
-
public HoursWorkedCalculator()
-
{
-
InitializeComponent();
-
}
-
-
// global variable to track days added, user can only add up to 6 days
-
// since even if they were working 7 days, the main form keeps care
-
// of the 7th day
-
int dayAdded = 0;
-
string amPmOutBreak1 = "AM";
-
string amPmInBreak1 = "AM";
-
string amPmOutLunch = "AM";
-
string amPmInLunch = "AM";
-
string amPmOutBreak2 = "AM";
-
string amPmInBreak2 = "AM";
-
string lunchTime = "0:00";
-
private bool ok = true;
-
string amPmInForDay = "AM";
-
string amPMOutForDay = "PM";
-
string hoursWorkedWeek = "0:00";
-
-
// user has the use clock radio button picked
-
private void rbnUseClock_CheckedChanged(object sender, EventArgs e)
-
{
-
grpHoursBox.Text = "Step 4";
-
grpSendBox.Text = "Step 5";
-
grpLunchClock.Enabled = true;
-
grpAddBox.Enabled = true;
-
txtDay1Hours.ReadOnly = true;
-
txtDay2Hours.ReadOnly = true;
-
txtDay3Hours.ReadOnly = true;
-
txtDay4Hours.ReadOnly = true;
-
txtDay5Hours.ReadOnly = true;
-
txtDay6Hours.ReadOnly = true;
-
txtInForDay.TabStop = true;
-
cboInForDayAmPm.TabStop = true;
-
txtOutBreak1.TabStop = true;
-
cboOutBreak1AmPm.TabStop = true;
-
txtInBreak1.TabStop = true;
-
cboInBreak1AmPm.TabStop = true;
-
txtOutToLunch.TabStop = true;
-
cboOutLunchAmPm.TabStop = true;
-
txtInFromLunch.TabStop = true;
-
cboInLunchAmPm.TabStop = true;
-
txtOutBreak2.TabStop = true;
-
cboOutBreak2AmPm.TabStop = true;
-
txtInBreak2.TabStop = true;
-
cboInBreak2AmPm.TabStop = true;
-
txtOutForDay.TabStop = true;
-
cboOutForDayAmPm.TabStop = true;
-
txtDay1Hours.TabStop = false;
-
txtDay2Hours.TabStop = false;
-
txtDay3Hours.TabStop = false;
-
txtDay4Hours.TabStop = false;
-
txtDay5Hours.TabStop = false;
-
txtDay6Hours.TabStop = false;
-
btnAdd.Enabled = false;
-
btnAddTogether.Enabled = false;
-
btnSend.Enabled = false;
-
}
-
-
// user has the total hours radio button checked
-
private void rbtnUseHours_CheckedChanged(object sender, EventArgs e)
-
{
-
grpHoursBox.Text = "Step 2";
-
grpSendBox.Text = "Step 3";
-
grpLunchClock.Enabled = false;
-
grpAddBox.Enabled = false;
-
txtDay1Hours.ReadOnly = false;
-
txtDay2Hours.ReadOnly = false;
-
txtDay3Hours.ReadOnly = false;
-
txtDay4Hours.ReadOnly = false;
-
txtDay5Hours.ReadOnly = false;
-
txtDay6Hours.ReadOnly = false;
-
txtDay1Hours.TabStop = true;
-
txtDay2Hours.TabStop = true;
-
txtDay3Hours.TabStop = true;
-
txtDay4Hours.TabStop = true;
-
txtDay5Hours.TabStop = true;
-
txtDay6Hours.TabStop = true;
-
btnAddTogether.Enabled = true;
-
btnSend.Enabled = false;
-
}
-
-
// user clicked the cancel button
-
private void btnCancel_Click(object sender, EventArgs e)
-
{
-
this.Close();
-
}
-
-
// load event for the Hours Worked Calcuator form
-
private void HoursWorkedCalculator_Load(object sender, EventArgs e)
-
{
-
cboInForDayAmPm.Items.Add("AM");
-
cboInForDayAmPm.Items.Add("PM");
-
cboInForDayAmPm.SelectedIndex = 0;
-
cboOutLunchAmPm.Items.Add("AM");
-
cboOutLunchAmPm.Items.Add("PM");
-
cboOutLunchAmPm.SelectedIndex = 0;
-
cboInLunchAmPm.Items.Add("AM");
-
cboInLunchAmPm.Items.Add("PM");
-
cboInLunchAmPm.SelectedIndex = 0;
-
cboInBreak1AmPm.Items.Add("AM");
-
cboInBreak1AmPm.Items.Add("PM");
-
cboInBreak1AmPm.SelectedIndex = 0;
-
cboOutBreak1AmPm.Items.Add("AM");
-
cboOutBreak1AmPm.Items.Add("PM");
-
cboOutBreak1AmPm.SelectedIndex = 0;
-
cboInBreak2AmPm.Items.Add("AM");
-
cboInBreak2AmPm.Items.Add("PM");
-
cboInBreak2AmPm.SelectedIndex = 1;
-
cboOutBreak2AmPm.Items.Add("AM");
-
cboOutBreak2AmPm.Items.Add("PM");
-
cboOutBreak2AmPm.SelectedIndex = 1;
-
cboOutForDayAmPm.Items.Add("AM");
-
cboOutForDayAmPm.Items.Add("PM");
-
cboOutForDayAmPm.SelectedIndex = 1;
-
rbnUseClock_CheckedChanged(sender, e);
-
}
-
-
// user clicked the Calculate button
-
private void btnCalculate_Click(object sender, EventArgs e)
-
{
-
// must add the if(!(Validator. stuff here
-
if (!(Validator.IsPresent(txtInForDay) &&
-
Validator.IsPresent(txtOutBreak1) &&
-
Validator.IsPresent(txtInBreak1) &&
-
Validator.IsPresent(txtOutToLunch) &&
-
Validator.IsPresent(txtInFromLunch) &&
-
Validator.IsPresent(txtOutBreak2) &&
-
Validator.IsPresent(txtInBreak2) &&
-
Validator.IsPresent(txtOutForDay) &&
-
Validator.IsTime(txtInForDay) &&
-
Validator.IsTime(txtOutBreak1) &&
-
Validator.IsTime(txtInBreak1) &&
-
Validator.IsTime(txtOutToLunch) &&
-
Validator.IsTime(txtInFromLunch) &&
-
Validator.IsTime(txtOutBreak2) &&
-
Validator.IsTime(txtInBreak2) &&
-
Validator.IsTime(txtOutForDay)
-
))
-
{
-
ok = false;
-
}
-
else
-
{
-
// calcualte time in and out for day
-
string inForDay = ConvertTime.StandardTime(txtInForDay.Text);
-
inForDay = ConvertTime.NonMillTime(inForDay);
-
inForDay += amPmInForDay;
-
string outForDay = ConvertTime.StandardTime(txtOutForDay.Text);
-
outForDay = ConvertTime.NonMillTime(outForDay);
-
outForDay += amPMOutForDay;
-
DateTime inDay = DateTime.Parse(inForDay);
-
DateTime outDay = DateTime.Parse(outForDay);
-
TimeSpan workedToday = outDay - inDay;
-
hoursWorkedWeek = workedToday.ToString();
-
-
// calculate lunch and breaks
-
// Break 1
-
string outToBreak1 =
-
ConvertTime.StandardTime(txtOutBreak1.Text);
-
outToBreak1 = ConvertTime.NonMillTime(outToBreak1);
-
outToBreak1 += amPmOutBreak1;
-
string inFromBreak1 =
-
ConvertTime.StandardTime(txtInBreak1.Text);
-
inFromBreak1 = ConvertTime.NonMillTime(inFromBreak1);
-
inFromBreak1 += amPmInBreak1;
-
DateTime outBreak1 = DateTime.Parse(outToBreak1);
-
DateTime inBreak1 = DateTime.Parse(inFromBreak1);
-
TimeSpan break1 = inBreak1 - outBreak1;
-
-
// Lunch
-
string outToLunch =
-
ConvertTime.StandardTime(txtOutToLunch.Text);
-
outToLunch = ConvertTime.NonMillTime(outToLunch);
-
outToLunch += amPmOutLunch;
-
string inFromLunch =
-
ConvertTime.StandardTime(txtInFromLunch.Text);
-
inFromLunch = ConvertTime.NonMillTime(inFromLunch);
-
inFromLunch += amPmInLunch;
-
DateTime outLunch = DateTime.Parse(outToLunch);
-
DateTime inLunch = DateTime.Parse(inFromLunch);
-
TimeSpan lunch = inLunch - outLunch;
-
-
//Break 2
-
string outToBreak2 =
-
ConvertTime.StandardTime(txtOutBreak2.Text);
-
outToBreak2 = ConvertTime.NonMillTime(outToBreak2);
-
outToBreak2 += amPmOutBreak2;
-
string inFromBreak2 =
-
ConvertTime.StandardTime(txtInBreak2.Text);
-
inFromBreak2 = ConvertTime.NonMillTime(inFromBreak2);
-
inFromBreak2 += amPmInBreak2;
-
DateTime outBreak2 = DateTime.Parse(outToBreak2);
-
DateTime inBreak2 = DateTime.Parse(inFromBreak2);
-
TimeSpan break2 = inBreak2 - outBreak2;
-
-
TimeSpan lunchTotal = break1.Add(break2);
-
lunchTotal = lunchTotal.Add(lunch);
-
-
string lunchTimeUsed = lunchTotal.ToString();
-
//lunchTimeUsed = ConvertTime.NoAmPm(lunchTimeUsed);
-
lunchTime = lunchTimeUsed;
-
-
// now calculate hours worked - lunch
-
double worked = ConvertTime.ToDecimal(hoursWorkedWeek);
-
double lunchBreaks = ConvertTime.ToDecimal(lunchTime);
-
worked = worked - lunchBreaks;
-
string forwardTime = worked.ToString();
-
// just in case we get back a whole number, which is likely
-
// othewise ConvertTime.StandardTime will have a problem.
-
if (forwardTime.IndexOf('.') <0)
-
{
-
forwardTime += ":00";
-
}
-
forwardTime = ConvertTime.StandardTime(forwardTime);
-
txtTotalHoursDay.Text = forwardTime;
-
btnAdd.Enabled = true;
-
ok = true;
-
}
-
}
-
-
// user clicked the add button
-
private void btnAdd_Click(object sender, EventArgs e)
-
{
-
dayAdded++;
-
if (dayAdded == 6)
-
{
-
grpLunchClock.Enabled = false;
-
// MessageBox.Show("You may only enter up to 6 work days. If you"
-
//+ " are working 7 days, that will be kept care of on the main"
-
//+ " window.", "Entry Error");
-
}
-
switch (dayAdded)
-
{
-
case 1:
-
txtDay1Hours.Text = txtTotalHoursDay.Text;
-
lblDay.Text = "second";
-
lblDayCon.Text = "Day 2:";
-
btnAddTogether.Enabled = true;
-
break;
-
case 2:
-
txtDay2Hours.Text = txtTotalHoursDay.Text;
-
lblDay.Text = "third";
-
lblDayCon.Text = "Day 3:";
-
break;
-
case 3:
-
txtDay3Hours.Text = txtTotalHoursDay.Text;
-
lblDay.Text = "fourth";
-
lblDayCon.Text = "Day 4:";
-
break;
-
case 4:
-
txtDay4Hours.Text = txtTotalHoursDay.Text;
-
lblDay.Text = "fifth";
-
lblDayCon.Text = "Day 5:";
-
break;
-
case 5:
-
txtDay5Hours.Text = txtTotalHoursDay.Text;
-
lblDay.Text = "sixth";
-
lblDayCon.Text = "Day 6:";
-
break;
-
case 6:
-
txtDay6Hours.Text = txtTotalHoursDay.Text;
-
break;
-
}
-
}
-
-
// ucer is changing am/pm
-
private void cboInForDayAmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboInForDayAmPm.SelectedIndex == 1)
-
{
-
amPmInForDay = "PM";
-
-
}
-
else
-
{
-
amPmInForDay = "AM";
-
}
-
}
-
-
// user clicked the send button
-
private void btnSend_Click(object sender, EventArgs e)
-
{
-
if (ok)
-
{
-
// allow form to close
-
this.Tag = txtTotalHoursWeek.Text;
-
this.DialogResult = DialogResult.OK;
-
}
-
}
-
-
// user clicked the Add together button
-
private void btnAddTogether_Click(object sender, EventArgs e)
-
{
-
if(!(Validator.IsPresent(txtDay1Hours) &&
-
Validator.IsPresent(txtDay2Hours) &&
-
Validator.IsPresent(txtDay3Hours) &&
-
Validator.IsPresent(txtDay4Hours) &&
-
Validator.IsPresent(txtDay5Hours) &&
-
Validator.IsPresent(txtDay6Hours) &&
-
Validator.IsTime(txtDay1Hours) &&
-
Validator.IsTime(txtDay2Hours) &&
-
Validator.IsTime(txtDay3Hours) &&
-
Validator.IsTime(txtDay4Hours) &&
-
Validator.IsTime(txtDay5Hours) &&
-
Validator.IsTime(txtDay6Hours)))
-
{
-
ok = false;
-
}
-
else
-
{
-
double day1 = ConvertTime.ToDecimal(txtDay1Hours.Text);
-
double day2 = ConvertTime.ToDecimal(txtDay2Hours.Text);
-
double day3 = ConvertTime.ToDecimal(txtDay3Hours.Text);
-
double day4 = ConvertTime.ToDecimal(txtDay4Hours.Text);
-
double day5 = ConvertTime.ToDecimal(txtDay5Hours.Text);
-
double day6 = ConvertTime.ToDecimal(txtDay6Hours.Text);
-
double totalHours = day1 + day2 + day3 + day4 + day5 + day6;
-
string workedHours = totalHours.ToString("f2");
-
if (workedHours.IndexOf('.') <0)
-
{
-
workedHours += ".00";
-
}
-
hoursWorkedWeek = ConvertTime.StandardTime(workedHours);
-
if (hoursWorkedWeek == "0:00")
-
{
-
MessageBox.Show("All times have a zero value, so there is "
-
+ "nothing to add together", "Entry Error");
-
txtDay1Hours.Focus();
-
}
-
else
-
{
-
ok = true;
-
txtTotalHoursWeek.Text = hoursWorkedWeek;
-
btnSend.Enabled = true;
-
}
-
}
-
-
}
-
-
// user clicked Exit in the menu
-
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
this.Close();
-
}
-
-
// user clicked About in the menu
-
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
aboutForm.ShowDialog();
-
}
-
-
// user clicked the Contents for help the menu
-
private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
-
}
-
}
-
}
Here is the code for the Lunch window, it adds unpaid lunch/breaks to the day:
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// **********************************************
-
// This Class: frmLunch
-
// This Class Author: Brian A. Thomas
-
// This Class Version: 0.4.2
-
// This Class Copyright: 2006 by Brian A. Thomas
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// Code for the Lunch form. Allows the user to add unpaid lunchs and
-
/// breaks to the calculation on the main window
-
/// </summary>
-
public partial class frmLunch : Form
-
{
-
/// <summary>
-
/// Created by Visual C# 2005
-
/// </summary>
-
public frmLunch()
-
{
-
InitializeComponent();
-
}
-
-
// set global variables
-
string amPmOutBreak1 = "AM";
-
string amPmInBreak1 = "AM";
-
string amPmOutLunch = "AM";
-
string amPmInLunch = "AM";
-
string amPmOutBreak2 = "AM";
-
string amPmInBreak2 = "AM";
-
// lunchTime is the string returned to the main window
-
string lunchTime = "0:00";
-
// will allow the lunch window to close so long as all is valid
-
private bool ok = true;
-
-
// load event, sets AM/PM in combo boxes.
-
private void frmLunch_Load(object sender, EventArgs e)
-
{
-
cboOutLunchAmPm.Items.Add("AM");
-
cboOutLunchAmPm.Items.Add("PM");
-
cboOutLunchAmPm.SelectedIndex = 0;
-
cboInLunchAmPm.Items.Add("AM");
-
cboInLunchAmPm.Items.Add("PM");
-
cboInLunchAmPm.SelectedIndex = 0;
-
cboInBreak1AmPm.Items.Add("AM");
-
cboInBreak1AmPm.Items.Add("PM");
-
cboInBreak1AmPm.SelectedIndex = 0;
-
cboOutBreak1AmPm.Items.Add("AM");
-
cboOutBreak1AmPm.Items.Add("PM");
-
cboOutBreak1AmPm.SelectedIndex = 0;
-
cboInBreak2AmPm.Items.Add("AM");
-
cboInBreak2AmPm.Items.Add("PM");
-
cboInBreak2AmPm.SelectedIndex = 0;
-
cboOutBreak2AmPm.Items.Add("AM");
-
cboOutBreak2AmPm.Items.Add("PM");
-
cboOutBreak2AmPm.SelectedIndex = 0;
-
// focus on ClockTime text box as that is the default entry.
-
txtClockTime.Focus();
-
}
-
-
// user chose to enter their lunch and unpaid breaks in a clock in/out
-
// format
-
private void rbtnClock_CheckedChanged(object sender, EventArgs e)
-
{
-
grpTotalLunchTime.Enabled = false;
-
grpLunchClock.Enabled = true;
-
txtOutToLunch.Focus();
-
}
-
-
// user will enter total time of lunchs and unpaid breaks
-
private void rbtnTime_CheckedChanged(object sender, EventArgs e)
-
{
-
grpLunchClock.Enabled = false;
-
grpTotalLunchTime.Enabled = true;
-
txtClockTime.Focus();
-
}
-
-
// close this form
-
private void btnCancel_Click(object sender, EventArgs e)
-
{
-
this.Close();
-
}
-
-
/// <summary>
-
/// If all information if valid, calculate total lunch and unpaid
-
/// break time (if the user entered time into the clock) and then send
-
/// the information back to the main window
-
/// </summary>
-
/// <param name="sender">standard object sender</param>
-
/// <param name="e">standard event handler</param>
-
private void btnSave_Click(object sender, EventArgs e)
-
{
-
{
-
// user entered a total time for lunch and unpaid breaks
-
-
//Validator.IsPresent(txtClockTime);
-
//Validator.IsTime(txtClockTime);
-
// was originally like above, but, every time something wasn't
-
// valid, the error box would come up, I would hit OK then
-
// the lunch window would go away with the box.
-
// so added this Not logical operator to allow me to set
-
// an okay or not bool value to false, allowing me to stop
-
// the dialog result being OK.
-
if (!(Validator.IsPresent(txtClockTime) &&
-
Validator.IsTime(txtClockTime)))
-
{
-
// isn't valid so don't allow this form to close
-
ok = false;
-
}
-
else
-
{
-
// make sure it isn't in decimal format then set to allow
-
// ok to true so form can close
-
// lunchTime will be returned to main window
-
lunchTime = ConvertTime.StandardTime(txtClockTime.Text);
-
if (lunchTime == "0:00")
-
{
-
MessageBox.Show("Time was a zero. If you want to "
-
+ "Cancel entry select the cancell button",
-
"Entry Error");
-
txtClockTime.Focus();
-
ok = false;
-
}
-
else
-
{
-
ok = true;
-
}
-
}
-
}
-
else
-
{
-
// user is using the clock function to calculate total
-
// lunch and unpaid break time
-
if(!(Validator.IsPresent(txtOutBreak1) &&
-
Validator.IsTime(txtOutBreak1) &&
-
Validator.IsPresent(txtInBreak1) &&
-
Validator.IsTime(txtInBreak1) &&
-
Validator.IsPresent(txtOutToLunch) &&
-
Validator.IsPresent(txtInFromLunch) &&
-
Validator.IsTime(txtOutToLunch) &&
-
Validator.IsTime(txtInFromLunch) &&
-
Validator.IsPresent(txtOutBreak2) &&
-
Validator.IsTime (txtOutBreak2) &&
-
Validator.IsPresent(txtInBreak2) &&
-
Validator.IsTime(txtInBreak2)))
-
{
-
// isn't valid, so don't allow this form to close
-
ok = false;
-
}
-
else
-
{
-
// entries are valid, so start calculating
-
-
// Break 1
-
string outToBreak1 =
-
ConvertTime.StandardTime(txtOutBreak1.Text);
-
outToBreak1 = ConvertTime.NonMillTime(outToBreak1);
-
outToBreak1 += amPmOutBreak1;
-
string inFromBreak1 =
-
ConvertTime.StandardTime(txtInBreak1.Text);
-
inFromBreak1 = ConvertTime.NonMillTime(inFromBreak1);
-
inFromBreak1 += amPmInBreak1;
-
DateTime outBreak1 = DateTime.Parse(outToBreak1);
-
DateTime inBreak1 = DateTime.Parse(inFromBreak1);
-
TimeSpan break1 = inBreak1 - outBreak1;
-
-
// Lunch
-
string outToLunch =
-
ConvertTime.StandardTime(txtOutToLunch.Text);
-
outToLunch = ConvertTime.NonMillTime(outToLunch);
-
outToLunch += amPmOutLunch;
-
string inFromLunch =
-
ConvertTime.StandardTime(txtInFromLunch.Text);
-
inFromLunch = ConvertTime.NonMillTime(inFromLunch);
-
inFromLunch += amPmInLunch;
-
DateTime outLunch = DateTime.Parse(outToLunch);
-
DateTime inLunch = DateTime.Parse(inFromLunch);
-
TimeSpan lunch = inLunch - outLunch;
-
-
//Break 2
-
string outToBreak2 =
-
ConvertTime.StandardTime(txtOutBreak2.Text);
-
outToBreak2 = ConvertTime.NonMillTime(outToBreak2);
-
outToBreak2 += amPmOutBreak2;
-
string inFromBreak2 =
-
ConvertTime.StandardTime(txtInBreak2.Text);
-
inFromBreak2 = ConvertTime.NonMillTime(inFromBreak2);
-
inFromBreak2 += amPmInBreak2;
-
DateTime outBreak2 = DateTime.Parse(outToBreak2);
-
DateTime inBreak2 = DateTime.Parse(inFromBreak2);
-
TimeSpan break2 = inBreak2 - outBreak2;
-
-
// start calcualting total lunch and unpaid breaks
-
TimeSpan lunchTotal = break1.Add(break2);
-
lunchTotal = lunchTotal.Add(lunch);
-
string lunchTimeUsed = lunchTotal.ToString();
-
// lunchTime will be returned to main window
-
lunchTime = lunchTimeUsed;
-
if (lunchTime == "0:00")
-
{
-
MessageBox.Show("Time was a zero. If you want to "
-
+ "Cancel entry select the cancell button",
-
"Entry Error");
-
ok = false;
-
txtOutToLunch.Focus();
-
}
-
else
-
{
-
ok = true;
-
}
-
}
-
}
-
-
// sets lunchTime to be value to be returned to main window
-
this.Tag = lunchTime;
-
if (ok)
-
{
-
// allow form to close
-
this.DialogResult = DialogResult.OK;
-
}
-
}
-
-
// set the AM/PM combo boxes
-
private void cboOutLunchAmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboOutLunchAmPm.SelectedIndex == 1)
-
{
-
amPmOutLunch = "PM";
-
-
}
-
else
-
{
-
amPmOutLunch = "AM";
-
}
-
}
-
-
private void cboInLunchAmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboInLunchAmPm.SelectedIndex == 1)
-
{
-
amPmInLunch = "PM";
-
-
}
-
else
-
{
-
amPmInLunch = "AM";
-
}
-
}
-
-
private void cboOutBreak1AmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboOutBreak1AmPm.SelectedIndex == 1)
-
{
-
amPmOutBreak1 = "PM";
-
-
}
-
else
-
{
-
amPmOutBreak1 = "AM";
-
}
-
}
-
-
private void cboInBreak1AmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboInBreak1AmPm.SelectedIndex == 1)
-
{
-
amPmInBreak1 = "PM";
-
-
}
-
else
-
{
-
amPmInBreak1 = "AM";
-
}
-
}
-
-
private void cboOutBreak2AmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboOutBreak2AmPm.SelectedIndex == 1)
-
{
-
amPmOutBreak2 = "PM";
-
-
}
-
else
-
{
-
amPmOutBreak2 = "AM";
-
}
-
}
-
-
private void cboInBreak2AmPm_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (cboInBreak2AmPm.SelectedIndex == 1)
-
{
-
amPmInBreak2 = "PM";
-
-
}
-
else
-
{
-
amPmInBreak2 = "AM";
-
}
-
}
-
-
// Menu items
-
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
aboutForm.ShowDialog();
-
}
-
-
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
this.Close();
-
}
-
-
private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
-
}
-
} // end class ConvertTime
-
}
Here is the code for Vacation time:
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// **********************************************
-
// This Class: vacation
-
// This Class Author: Brian A. Thomas
-
// This Class Version: 0.4
-
// This Class Copyright: 2006 by Brian A. Thomas
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// This window adds unpaid vacation/sick/personal time to the
-
/// calculations used by the main window
-
/// </summary>
-
public partial class vacation : Form
-
{
-
/// <summary>
-
/// This window adds unpaid vacation/sick/personal time to the
-
/// calculations used by the main window this is the actual start
-
/// of this window
-
/// </summary>
-
public vacation()
-
{
-
InitializeComponent();
-
}
-
-
// set global variables
-
private bool ok = true;
-
string hoursWorkedWeek = "0:00";
-
-
// user clicked add together to get total hours
-
private void btnAddTogether_Click(object sender, EventArgs e)
-
{
-
if (!(Validator.IsPresent(txtDay1Hours) &&
-
Validator.IsPresent(txtDay2Hours) &&
-
Validator.IsPresent(txtDay3Hours) &&
-
Validator.IsPresent(txtDay4Hours) &&
-
Validator.IsPresent(txtDay5Hours) &&
-
Validator.IsPresent(txtDay6Hours) &&
-
Validator.IsTime(txtDay1Hours) &&
-
Validator.IsTime(txtDay2Hours) &&
-
Validator.IsTime(txtDay3Hours) &&
-
Validator.IsTime(txtDay4Hours) &&
-
Validator.IsTime(txtDay5Hours) &&
-
Validator.IsTime(txtDay6Hours)))
-
{
-
// not valid, don't let window close
-
ok = false;
-
}
-
else
-
{
-
double day1 = ConvertTime.ToDecimal(txtDay1Hours.Text);
-
double day2 = ConvertTime.ToDecimal(txtDay2Hours.Text);
-
double day3 = ConvertTime.ToDecimal(txtDay3Hours.Text);
-
double day4 = ConvertTime.ToDecimal(txtDay4Hours.Text);
-
double day5 = ConvertTime.ToDecimal(txtDay5Hours.Text);
-
double day6 = ConvertTime.ToDecimal(txtDay6Hours.Text);
-
double totalHours = day1 + day2 + day3 + day4 + day5 + day6;
-
string workedHours = totalHours.ToString("f2");
-
if (workedHours.IndexOf('.') <0)
-
{
-
workedHours += ".00";
-
}
-
hoursWorkedWeek = ConvertTime.StandardTime(workedHours);
-
if (hoursWorkedWeek == "0:00")
-
{
-
MessageBox.Show("All times have a zero value, so there is "
-
+ "nothing to add together", "Entry Error");
-
txtDay1Hours.Focus();
-
}
-
else
-
{
-
ok = true;
-
txtTotalHoursWeek.Text = hoursWorkedWeek;
-
btnSend.Enabled = true;
-
}
-
}
-
}
-
-
// user chose to send results back
-
private void btnSend_Click(object sender, EventArgs e)
-
{
-
if (ok)
-
{
-
// allow form to close
-
this.Tag = txtTotalHoursWeek.Text;
-
this.DialogResult = DialogResult.OK;
-
}
-
}
-
-
// user chose to cancel entry
-
private void btnCancel_Click(object sender, EventArgs e)
-
{
-
this.Close();
-
}
-
-
// user chose Exit from the menu
-
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
aboutForm.ShowDialog();
-
}
-
-
// user chose About from the menu
-
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
aboutForm.ShowDialog();
-
}
-
-
// user chose Help from the menu
-
private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
-
{
-
Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
-
}
-
}
-
}
Here is the code for the Vailidator class:
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// NOTE: This will likely change in future versions
-
// to be in my own library set.
-
// **********************************************
-
// Class: MainWindow
-
// Class Author: Brian A. Thomas
-
// Class Version: 0.6
-
// Based off of the Validator Class presented in Murach's C# 2005 book
-
// by Joel Murach
-
// Published by: Mike Murach and Associates, Inc.
-
// ISBN-10: 1-890774-37-5, ISBN-13: 978-1-890774-37-0
-
// Available at www.murach.com, Amazon.com and other quality book stores
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
// Portions from Murach's book might fall outside the bounds from the GNU GPL.
-
-
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// Validator claass is used to validate that data entered into text boxes
-
/// are valid. Presently covers that the text boxes that are required are
-
/// not empty, that it containes a decimal and that it is in a proper
-
/// time format.
-
/// See comments at top for original source information.
-
/// </summary>
-
class Validator
-
{
-
/// <summary>
-
/// Determains if a text box has an entry
-
/// </summary>
-
/// <param name="textBox">The name of the text box's Tag property</param>
-
/// <returns>true or false value</returns>
-
// NOTE: This is the part that came from Murach's book and as such
-
// may fall outside the bounds of the GNU GPL.
-
public static bool IsPresent(TextBox textBox)
-
{
-
if (textBox.Text == "")
-
{
-
MessageBox.Show(textBox.Tag + " is a requried field.", "Entry Error");
-
textBox.Focus();
-
return false;
-
} // end box is empty Message Box
-
return true;
-
} // end IsPresent
-
-
/// <summary>
-
/// Makes sure that the entry into the text box is in a valid time
-
/// format such as 8:30 or 8.5.
-
/// It does NOT insure it is in standard time over military time as
-
/// some times entered into boxes will be more then 12, so that part
-
/// is handled by the StandardTime method of the ConvertTime class.
-
/// This one was not in the book.
-
/// </summary>
-
/// <param name="textBox">The name of the text box's Tag property</param>
-
/// <returns>true or false value</returns>
-
public static bool IsTime(TextBox textBox)
-
{
-
string s = textBox.Text;
-
int seperatorCount = 0;
-
bool validTime = true;
-
foreach (char c in s)
-
{
-
if (!(c == '0' || c == '1' || c == '2' || c == '3' || c == '4'
-
|| c == '5' || c == '6' || c == '7' || c == '8' || c == '9'
-
|| c == ':' || c == '.'))
-
{
-
validTime = false;
-
break;
-
} // end Time isn't valid
-
if (c == ':' || c == '.')
-
{
-
seperatorCount++;
-
} // end if seperator
-
} // end foreach
-
if (validTime && seperatorCount == 1) // presently doesn't allow
-
// for seconds. May be modified at a later date to allow for
-
// them by changing it to>0 && <=2 so it forces it to be over
-
// over 0 but still under 2.
-
{
-
return true;
-
} // end if time is valid and seperator count isn't too high
-
else
-
{
-
MessageBox.Show(textBox.Tag + " must be in a time format. "
-
+ "Such as 8:30.\nDo NOT enter seconds or AM/PM.\nAM/PM is"
-
+ " selected by using the AM/PM buttons.\nAlso be sure to "
-
+ "include the ":" seperator.\n"
-
+ "If the time is 0 enter 0:00.", "Entry Error");
-
textBox.Focus();
-
return false;
-
} // end time isn't valid message box display
-
} // end IsTime
-
}// end Validator class
-
}
Finally, here is the code for the main window itself:
-
// **********************************************
-
// Program Name: What Time Do I Leave Friday
-
// Program Author: Brian A. Thomas
-
// Program Homepage: http://www.brianathomas.com/
-
// Author Homepage: http://www.brianathomas.com/
-
// **********************************************
-
// This Namespace: WhatTimeFriday
-
// **********************************************
-
// This Class: MainWindow
-
// This Class Author: Brian A. Thomas
-
// This Class Version: 0.8
-
// This Class Copyright: 2006 by Brian A. Thomas
-
// **********************************************
-
/*
-
This file is part of What Time Do I Leave Friday.
-
What Time Do I Leave Friday is free software; you can redistribute it
-
and/or modify it under the terms of the GNU General Public License as
-
published by the Free Software Foundation; version 2 of the
-
License, or any later version.
-
What Time Do I Leave Friday is distributed in the hope that it will be
-
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
-
along with What Time Do I Leave Friday; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
*/
-
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
//using ystem.Windows.Forms.ToolTip;
-
-
namespace WhatTimeFriday
-
{
-
/// <summary>
-
/// This program will take the hours worked so far in a week, the time
-
/// in Friday and lets you know what time to leave Friday
-
/// Future versions will allow for less then 40 hours for a standard work
-
/// week and allow for lunches on Friday
-
/// </summary>
-
public partial class MainWindow : Form
-
{
-
/// <summary>
-
/// Created by Visual C# 2005
-
/// </summary>
-
public MainWindow()
-
{
-
InitializeComponent();
-
-
}
-
-
// set global variable
-
double standardWorkWeek = 40;
-
string lunchTime = "0:00";
-
bool standWeekOpen = false;
-
double vacationTime = 0;
-
// Global variable moved from below so it can be used by a
-
// few methods, most noteably so I could display the lunch time
-
double lunch;
-
bool valid = true;
-
-
/// <summary>
-
/// This Field controls if the time in is AM or PM
-
/// </summary>
-
private static bool pm = false;
-
-
/// <summary>
-
/// PM Property for other classes to access the pm field and set
-
/// AM/PM as needed. Most notably at this time the ConvertTime class
-
/// uses it if the user uses military time in the Friday in box.
-
/// </summary>
-
public static bool PM
-
{
-
get
-
{
-
return pm;
-
}
-
set
-
{
-
pm = value;
-
}
-
}
-
-
/// <summary>
-
/// User clicked the Calculate button.
-
/// If everything is valid, then calculate the time out and hours
-
/// for the day.
-
/// </summary>
-
/// <param name="sender">Standard object sender for event</param>
-
/// <param name="e">Standard event handler</param>
-
private void btnCalculate_Click(object sender, EventArgs e)
-
{
-
if (standWeekOpen)
-
{
-
// if the user was editing the standard work week
-
-
// first check the text box
-
if (Validator.IsPresent(txtWorkWeek))
-
{
-
if (txtWorkWeek.Text.IndexOf(':') <0
-
&& txtWorkWeek.Text.IndexOf('.') <0)
-
{
-
txtWorkWeek.Text += ":00";
-
}
-
else if (txtWorkWeek.Text.IndexOf('.')> -1)
-
{
-
string tempTime =
-
ConvertTime.StandardTime(txtWorkWeek.Text);
-
txtWorkWeek.Text = tempTime;
-
}
-
// check to be sure there are minutes even if they are 0
-
string checkMinutes =
-
ConvertTime.StandardTime(txtWorkWeek.Text);
-
txtWorkWeek.Text = checkMinutes;
-
}
-
// next change standarWorkWeek into a time value
-
string changeStandardWorkWeek = standardWorkWeek.ToString();
-
if (changeStandardWorkWeek.IndexOf('.') <0)
-
{
-
changeStandardWorkWeek += ":00";
-
}
-
else
-
{
-
changeStandardWorkWeek =
-
ConvertTime.StandardTime(changeStandardWorkWeek);
-
}
-
-
// okay one more thing to check before we go on
-
// check to see if the time in the text box is differant
-
// from the standerWorkWeek (changeStandarWorkWeek)
-
if (!(changeStandardWorkWeek == txtWorkWeek.Text))
-
{
-
// the standardWorkWeek and the time in the box are differant
-
DialogResult button = MessageBox.Show("You are still editing "
-
+ "the Standard Work Week.\n"
-
+ "Press OK to save work week as " + txtWorkWeek.Text + "\n"
-
+ "Or press CANCEL to save work week as "
-
+ changeStandardWorkWeek, "Work Week Open",
-
MessageBoxButtons.OKCancel);
-
if (button == DialogResult.OK)
-
{
-
btnSaveWorkWeek_Click(sender, e);
-
}
-
else
-
{
-
txtWorkWeek.Text = changeStandardWorkWeek;
-
btnSaveWorkWeek_Click(sender, e);
-
}
-
}
-
else
-
{
-
// they were equal hit the save button so we are sure
-
// to hit the time in. This also makes sure the save
-
// button goes away and the text box becomes read only
-
btnSaveWorkWeek_Click(sender, e);
-
}
-
-
-
}
-
-
// Check to see if they entered decimal time in a box
-
string totalTime = txtTotalHours.Text;
-
string inTime = txtTimeInFriday.Text;
-
if (totalTime.IndexOf('.')>= 0)
-
{
-
DialogResult button = MessageBox.Show("You entered a decimal "
-
+ "value into the Total Hours text box.\nIt normally "
-
+ "expects a standard time with a colon seperating\nhours "
-
+ "from minutes.\nIf you are sure you want to use the "
-
+ "decimal entry click OK\notherwise click Cancel to return"
-
+ "and edit your entry.","Notice",
-
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
-
if (button == DialogResult.OK)
-
{
-
valid = true;
-
}
-
else
-
{
-
valid = false;
-
txtTotalHours.Focus();
-
txtTimeToLeave.Text = "";
-
txtHourForFriday.Text = "";
-
}
-
}
-
if (inTime.IndexOf('.')>= 0)
-
{
-
DialogResult button = MessageBox.Show("You entered a decimal "
-
+ "value into the Time in Friday text box.\nIt normally "
-
+ "expects a standard time with a colon seperating\nhours "
-
+ "from minutes.\nIf you are sure you want to use the "
-
+ "decimal entry click OK\notherwise click Cancel to return"
-
+ "and edit your entry.", "Notice",
-
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
-
if (button == DialogResult.OK)
-
{
-
valid = true;
-
}
-
else
-
{
-
valid = false;
-
txtTimeInFriday.Focus();
-
txtTimeToLeave.Text = "";
-
txtHourForFriday.Text = "";
-
}

