Program: What Time Do I Leave Friday
Aug 14th, 2006 by Brian A. Thomas
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";