Program: What Time Do I Leave Friday

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:
Mian screen of my program, What Time Do I Leave Friday
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:
Lunch screen of my program, What Time Do I Leave Friday
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):
Main screen in use, after entering lunch and other information for my program, What Time Do I Leave Friday

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.

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // NOTE: This will likely change in future versions
  9. // to be in my own library set.
  10. // **********************************************
  11. // Class: ConvertTime
  12. // Class Author: Brian A. Thomas
  13. // Class webpage: http://www.brianathomas.com/
  14. // This Class Version: 0.4
  15. // This Class Copyright: 2006 by Brian A. Thomas
  16. // **********************************************
  17. /*
  18.      This file is part of What Time Do I Leave Friday.
  19.     What Time Do I Leave Friday is free software; you can redistribute it
  20.     and/or modify it under the terms of the GNU General Public License as
  21.     published by the Free Software Foundation; version 2 of the
  22.     License, or any later version.
  23.     What Time Do I Leave Friday is distributed in the hope that it will be
  24.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.     GNU General Public License for more details.
  27.     You should have received a copy of the GNU General Public License
  28.     along with What Time Do I Leave Friday; if not, write to the Free Software
  29.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  30. */
  31.  
  32. using System;
  33. using System.Collections.Generic;
  34. using System.Text;
  35. using System.Windows.Forms;
  36.  
  37. namespace WhatTimeFriday
  38. {
  39.     /// <summary>
  40.     /// ConvertTime Class has a few methods for converting time
  41.     /// currently it converts a standard format time such as 8:30 into
  42.     /// decimal time, and from military time to standard time
  43.     /// </summary>
  44.     class ConvertTime
  45.     {
  46.         /// <summary>
  47.         /// Changes time from standard format such as 8:30 into decimal time
  48.         /// (not the French version) but breaking minutes into hundreds. For
  49.         /// example 8:30 becomes 8.5.
  50.         /// </summary>
  51.         /// <param name="s">time in string format without the AM/PM</param>
  52.         /// <returns>time in double format</returns>
  53.         public static double ToDecimal(string s)
  54.         {
  55.             // had to add as canceling a lunch addition caused an error.
  56.             if (s == null)
  57.             {
  58.                 s = "0.00";
  59.             }
  60.             if (s.IndexOf(':') <0)
  61.             {
  62.                 // for some reason using a conditional or in the above didn't
  63.                 // work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
  64.                 // <0) but if a string did have a : in it, it still went
  65.                 // to CantConvert
  66.                 if (s.IndexOf('.')>= 0)
  67.                 {
  68.                     // don't worry about it.
  69.                 }
  70.                 else
  71.                 {
  72.                     s = CantConvert(s);
  73.                 }
  74.             }
  75.             if (s.IndexOf(':')> -1) // check to see if it has a : in the time
  76.             //if so we need to turn it into a decimal time for
  77.             {
  78.                 // first split hours and minutes apart
  79.                 string[] allTime = s.Split(':');
  80.                 string hoursString = allTime[0];
  81.                 string minutesString = allTime[1];
  82.                 if (minutesString == "")
  83.                 {
  84.                     minutesString = "00";
  85.                 }
  86.                 //string secondsString = allTime[2];
  87.                 // above not used currently
  88.                 double minutes = Convert.ToInt32(minutesString);
  89.                 minutes /= 60;
  90.                 if (minutes <1 && minutes> 0)
  91.                 {
  92.                     string timeString = minutes.ToString();
  93.                     string[] fullTime = timeString.Split('.');
  94.                     string wholeString = fullTime[0];
  95.                     string portionString = fullTime[1];
  96.                     minutesString = portionString;
  97.                 }
  98.                 else
  99.                 {
  100.                     minutesString = "00";
  101.                 }
  102.                 string returnTime = hoursString + "." + minutesString;
  103.                 double time = Convert.ToDouble(returnTime);
  104.                 return time;
  105.             } // end if :
  106.             else
  107.             {
  108.                 string returnTime = s;
  109.                 // in theory, shouldn't need, but testing showed otherwise...
  110.                 // actually, should be gone for sure now after adding the
  111.                 // if(s==null) above, but will leave to be safe.
  112.                 if (returnTime == "")
  113.                 {
  114.                     returnTime = "0.00";
  115.                 }
  116.                 double time = Convert.ToDouble(returnTime);
  117.                 return time;
  118.             } // end else already in decimal time
  119.         }// end ToDecimal method of ConvertTime class
  120.  
  121.         /// <summary>
  122.         /// Converts from military time to standard time in the event the user
  123.         /// entered military time (24 hour time compared to 12 hour time)
  124.         /// </summary>
  125.         /// <param name="s">time in string format without the AM/PM</param>
  126.         /// <returns>time in string format with :</returns>
  127.         public static string NonMillTime(string s)
  128.         {
  129.             if (s == null)
  130.             {
  131.                 s = "0:00";
  132.             }
  133.             if (s.IndexOf(':') <0)
  134.             {
  135.                 // for some reason using a conditional or in the above didn't
  136.                 // work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
  137.                 // <0) but if a string did have a : in it, it still went
  138.                 // to CantConvert
  139.                 if (s.IndexOf('.')>= 0)
  140.                 {
  141.                     // don't worry about it.
  142.                 }
  143.                 else
  144.                 {
  145.                     s = CantConvert(s);
  146.                 }
  147.             }
  148.             string[] allTime = s.Split(':');
  149.             string hoursString = allTime[0];
  150.             string minutesString = allTime[1];
  151.             if (minutesString == "")
  152.             {
  153.                 minutesString = "00";
  154.             }
  155.             // string secondsString = allTime[2];
  156.             // above not used currently
  157.             double hours = Convert.ToDouble(hoursString);
  158.             if (hours> 12)
  159.             {
  160.                 hours -= 12;
  161.                 WhatTimeFriday.MainWindow.PM = true;
  162.             } // end hours> 12
  163.             string returnTime = hours.ToString() + ":" + minutesString;
  164.             return returnTime;
  165.         } // end StandardTime Method of ConvertTime Class
  166.  
  167.         /// <summary>
  168.         /// Truns decimal time (not French version) to stnadard time with
  169.         /// a : as the time seperator. So 8.5 becomes 8:30.
  170.         /// </summary>
  171.         /// <param name="s">time in string format without the AM/PM</param>
  172.         /// <returns>time in string format with :</returns>
  173.         public static string StandardTime(string s)
  174.         {
  175.             // had to add as canceling adding a lunch caused an error
  176.             if (s == null)
  177.             {
  178.                 s = "0:00";
  179.             }
  180.             if (s.IndexOf(':') <0)
  181.             {
  182.                 // for some reason using a conditional or in the above didn't
  183.                 // work. It was set as (s.IndexOf(':') <0 || s.IndexOf('.')
  184.                 // <0) but if a string did have a : in it, it still went
  185.                 // to CantConvert
  186.                 if (s.IndexOf('.')>= 0)
  187.                 {
  188.                     // don't worry about it.
  189.                 }
  190.                 else
  191.                 {
  192.                     s = CantConvert(s);
  193.                 }
  194.             }
  195.             if (s.IndexOf(':')> -1)
  196.             {
  197.                 //already has a : so it is okay
  198.                 // had to add the split just in case user entered
  199.                 // :30 for lunch or something like that where the hour
  200.                 // string is empty
  201.                 string[] allTime = s.Split(':');
  202.                 string hoursString = allTime[0];
  203.                 string minutesString = allTime[1];
  204.                 if (minutesString == "")
  205.                 {
  206.                     minutesString = "00";
  207.                 }
  208.                 if (hoursString == "")
  209.                 {
  210.                     hoursString = "0";
  211.                 }
  212.                 s = hoursString + ":" + minutesString;
  213.                 return s;
  214.             } // end if s has a :
  215.             else
  216.             {
  217.                 if (s == "" || s == "0")
  218.                 {
  219.                     s = "0.00";
  220.                 }
  221.                 string[] allTime = s.Split('.');
  222.                 string hoursString = allTime[0];
  223.                 // just in case the hoursString is empty
  224.                 if (hoursString == "")
  225.                 {
  226.                     hoursString = "0";
  227.                 }
  228.                 string minutesString = allTime[1];
  229.                 if (minutesString == "")
  230.                 {
  231.                     minutesString = "00";
  232.                 }
  233.                 // string secondsString = allTime[2];
  234.                 // above not used currently
  235.                 minutesString = "." + minutesString;
  236.                 double minutes = Convert.ToDouble(minutesString);
  237.                 minutes *= 60;
  238.                 minutesString = minutes.ToString("f0"); //needs to remove the
  239.                 // decimal place if there is one, otherwise there are problems
  240.                 // probably will add to the seconds if that seconds are ever
  241.                 // calculated
  242.                 if (minutesString == "0")
  243.                 {
  244.                     minutesString = "00";
  245.                 }
  246.                 string returnTime = hoursString + ":" + minutesString;
  247.                 return returnTime;
  248.             }
  249.         } // end StandardTime method of ConvertTimeClass
  250.  
  251.         /// <summary>
  252.         /// Shouldn't actually be used as the method calling the ConvertTime
  253.         /// class should validate before sending.
  254.         /// If string coming into ConvertTiem doesn't have a : or a . in it
  255.         /// adds a :
  256.         /// </summary>
  257.         /// <param name="s">and integer in striang format</param>
  258.         /// <returns>a string with a : in it</returns>
  259.         private static string CantConvert(string s)
  260.         {
  261.             // Method calling the Convert Class should validate this before it
  262.             // sends it here, but just in case.
  263.             // presently I know of no way of knowing for sure which text box
  264.             // caused this from this class, which is why it should be validated
  265.             // by the method, class or something calling this class.
  266.             // Also, the string sent to the ConvertTime class may not be from a
  267.             // text box anyhow, so even knowing the text box may not help.
  268.             string sugestedTime;
  269.             if (s == "")
  270.             {
  271.                 s = "0";
  272.             }
  273.             int number = Convert.ToInt32(s);
  274.             if (number <0)
  275.             {
  276.                 // if the number is negative, reverse it
  277.                 number = -number;
  278.             }
  279.             if (number> 24 && number <60)
  280.             {
  281.                 // we'll guess that the user may want it in the minutes
  282.                 // spot if it is over 24 and under 60 since it can't be
  283.                 // more then 60 if it is minutes, and possibly minutes if
  284.                 // over 24 which would be the limit of the hours spot if it
  285.                 // is military time
  286.                 sugestedTime = "0:" + s;
  287.             }
  288.             else
  289.             {
  290.                 // this takes a huge range of 0 to 24 and from 60 on
  291.                 // as noted above, the calling method to the ConvertTime
  292.                 // class really needs to validate the string before sending
  293.                 // it here
  294.                 sugestedTime = s = ":00";
  295.             }
  296.             string message = "Can't convert " + s + " to a time.\n"
  297.             + "It needs a ":" either before it (hours) or after it"
  298.             + "(minutes).\n"
  299.             + "Pressing OK will return " + sugestedTime + ". If this is not "
  300.             + "correct you will need to edit the entry when you return.";
  301.             MessageBox.Show(message, "Entry Error");
  302.             return sugestedTime;
  303.         } // end CantConvert method of ConvertTime class
  304.     } // end ConvertTime class
  305. }

Here is the code for the Hours Worked Calculator:

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // **********************************************
  9. // This Class: HoursWorkedCalculator
  10. // This Class Author: Brian A. Thomas
  11. // This Class Version: 0.4
  12. // This Class Copyright: 2006 by Brian A. Thomas
  13. // **********************************************
  14. /*
  15.      This file is part of What Time Do I Leave Friday.
  16.     What Time Do I Leave Friday is free software; you can redistribute it
  17.     and/or modify it under the terms of the GNU General Public License as
  18.     published by the Free Software Foundation; version 2 of the
  19.     License, or any later version.
  20.     What Time Do I Leave Friday is distributed in the hope that it will be
  21.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.     GNU General Public License for more details.
  24.     You should have received a copy of the GNU General Public License
  25.     along with What Time Do I Leave Friday; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28.  
  29. using System;
  30. using System.Collections.Generic;
  31. using System.ComponentModel;
  32. using System.Data;
  33. using System.Drawing;
  34. using System.Text;
  35. using System.Windows.Forms;
  36.  
  37. namespace WhatTimeFriday
  38. {
  39.     /// <summary>
  40.     /// form for the Hours Worked Calculator
  41.     /// </summary>
  42.     public partial class HoursWorkedCalculator : Form
  43.     {
  44.         /// <summary>
  45.         /// Main class for the Hours Worked Calculator
  46.         /// </summary>
  47.         public HoursWorkedCalculator()
  48.         {
  49.             InitializeComponent();
  50.         }
  51.  
  52.         // global variable to track days added, user can only add up to 6 days
  53.         // since even if they were working 7 days, the main form keeps care
  54.         // of the 7th day
  55.         int dayAdded = 0;
  56.         string amPmOutBreak1 = "AM";
  57.         string amPmInBreak1 = "AM";
  58.         string amPmOutLunch = "AM";
  59.         string amPmInLunch = "AM";
  60.         string amPmOutBreak2 = "AM";
  61.         string amPmInBreak2 = "AM";
  62.         string lunchTime = "0:00";
  63.         private bool ok = true;
  64.         string amPmInForDay = "AM";
  65.         string amPMOutForDay = "PM";
  66.         string hoursWorkedWeek = "0:00";
  67.  
  68.         // user has the use clock radio button picked
  69.         private void rbnUseClock_CheckedChanged(object sender, EventArgs e)
  70.         {
  71.             grpHoursBox.Text = "Step 4";
  72.             grpSendBox.Text = "Step 5";
  73.             grpLunchClock.Enabled = true;
  74.             grpAddBox.Enabled = true;
  75.             txtDay1Hours.ReadOnly = true;
  76.             txtDay2Hours.ReadOnly = true;
  77.             txtDay3Hours.ReadOnly = true;
  78.             txtDay4Hours.ReadOnly = true;
  79.             txtDay5Hours.ReadOnly = true;
  80.             txtDay6Hours.ReadOnly = true;
  81.             txtInForDay.TabStop = true;
  82.             cboInForDayAmPm.TabStop = true;
  83.             txtOutBreak1.TabStop = true;
  84.             cboOutBreak1AmPm.TabStop = true;
  85.             txtInBreak1.TabStop = true;
  86.             cboInBreak1AmPm.TabStop = true;
  87.             txtOutToLunch.TabStop = true;
  88.             cboOutLunchAmPm.TabStop = true;
  89.             txtInFromLunch.TabStop = true;
  90.             cboInLunchAmPm.TabStop = true;
  91.             txtOutBreak2.TabStop = true;
  92.             cboOutBreak2AmPm.TabStop = true;
  93.             txtInBreak2.TabStop = true;
  94.             cboInBreak2AmPm.TabStop = true;
  95.             txtOutForDay.TabStop = true;
  96.             cboOutForDayAmPm.TabStop = true;
  97.             txtDay1Hours.TabStop = false;
  98.             txtDay2Hours.TabStop = false;
  99.             txtDay3Hours.TabStop = false;
  100.             txtDay4Hours.TabStop = false;
  101.             txtDay5Hours.TabStop = false;
  102.             txtDay6Hours.TabStop = false;
  103.             btnAdd.Enabled = false;
  104.             btnAddTogether.Enabled = false;
  105.             btnSend.Enabled = false;
  106.         }
  107.  
  108.         // user has the total hours radio button checked
  109.         private void rbtnUseHours_CheckedChanged(object sender, EventArgs e)
  110.         {
  111.             grpHoursBox.Text = "Step 2";
  112.             grpSendBox.Text = "Step 3";
  113.             grpLunchClock.Enabled = false;
  114.             grpAddBox.Enabled = false;
  115.             txtDay1Hours.ReadOnly = false;
  116.             txtDay2Hours.ReadOnly = false;
  117.             txtDay3Hours.ReadOnly = false;
  118.             txtDay4Hours.ReadOnly = false;
  119.             txtDay5Hours.ReadOnly = false;
  120.             txtDay6Hours.ReadOnly = false;
  121.             txtDay1Hours.TabStop = true;
  122.             txtDay2Hours.TabStop = true;
  123.             txtDay3Hours.TabStop = true;
  124.             txtDay4Hours.TabStop = true;
  125.             txtDay5Hours.TabStop = true;
  126.             txtDay6Hours.TabStop = true;
  127.             btnAddTogether.Enabled = true;
  128.             btnSend.Enabled = false;
  129.         }
  130.  
  131.         // user clicked the cancel button
  132.         private void btnCancel_Click(object sender, EventArgs e)
  133.         {
  134.             this.Close();
  135.         }
  136.  
  137.         // load event for the Hours Worked Calcuator form
  138.         private void HoursWorkedCalculator_Load(object sender, EventArgs e)
  139.         {
  140.             cboInForDayAmPm.Items.Add("AM");
  141.             cboInForDayAmPm.Items.Add("PM");
  142.             cboInForDayAmPm.SelectedIndex = 0;
  143.             cboOutLunchAmPm.Items.Add("AM");
  144.             cboOutLunchAmPm.Items.Add("PM");
  145.             cboOutLunchAmPm.SelectedIndex = 0;
  146.             cboInLunchAmPm.Items.Add("AM");
  147.             cboInLunchAmPm.Items.Add("PM");
  148.             cboInLunchAmPm.SelectedIndex = 0;
  149.             cboInBreak1AmPm.Items.Add("AM");
  150.             cboInBreak1AmPm.Items.Add("PM");
  151.             cboInBreak1AmPm.SelectedIndex = 0;
  152.             cboOutBreak1AmPm.Items.Add("AM");
  153.             cboOutBreak1AmPm.Items.Add("PM");
  154.             cboOutBreak1AmPm.SelectedIndex = 0;
  155.             cboInBreak2AmPm.Items.Add("AM");
  156.             cboInBreak2AmPm.Items.Add("PM");
  157.             cboInBreak2AmPm.SelectedIndex = 1;
  158.             cboOutBreak2AmPm.Items.Add("AM");
  159.             cboOutBreak2AmPm.Items.Add("PM");
  160.             cboOutBreak2AmPm.SelectedIndex = 1;
  161.             cboOutForDayAmPm.Items.Add("AM");
  162.             cboOutForDayAmPm.Items.Add("PM");
  163.             cboOutForDayAmPm.SelectedIndex = 1;
  164.             rbnUseClock_CheckedChanged(sender, e);
  165.         }
  166.  
  167.         // user clicked the Calculate button
  168.         private void btnCalculate_Click(object sender, EventArgs e)
  169.         {
  170.             // must add the if(!(Validator. stuff here
  171.             if (!(Validator.IsPresent(txtInForDay) &&
  172.                 Validator.IsPresent(txtOutBreak1) &&
  173.                 Validator.IsPresent(txtInBreak1) &&
  174.                 Validator.IsPresent(txtOutToLunch) &&
  175.                 Validator.IsPresent(txtInFromLunch) &&
  176.                 Validator.IsPresent(txtOutBreak2) &&
  177.                 Validator.IsPresent(txtInBreak2) &&
  178.                 Validator.IsPresent(txtOutForDay) &&
  179.                 Validator.IsTime(txtInForDay) &&
  180.                 Validator.IsTime(txtOutBreak1) &&
  181.                 Validator.IsTime(txtInBreak1) &&
  182.                 Validator.IsTime(txtOutToLunch) &&
  183.                 Validator.IsTime(txtInFromLunch) &&
  184.                 Validator.IsTime(txtOutBreak2) &&
  185.                 Validator.IsTime(txtInBreak2) &&
  186.                 Validator.IsTime(txtOutForDay)
  187.                 ))
  188.             {
  189.                 ok = false;
  190.             }
  191.             else
  192.             {
  193.                 // calcualte time in and out for day
  194.                 string inForDay = ConvertTime.StandardTime(txtInForDay.Text);
  195.                 inForDay = ConvertTime.NonMillTime(inForDay);
  196.                 inForDay += amPmInForDay;
  197.                 string outForDay = ConvertTime.StandardTime(txtOutForDay.Text);
  198.                 outForDay = ConvertTime.NonMillTime(outForDay);
  199.                 outForDay += amPMOutForDay;
  200.                 DateTime inDay = DateTime.Parse(inForDay);
  201.                 DateTime outDay = DateTime.Parse(outForDay);
  202.                 TimeSpan workedToday = outDay - inDay;
  203.                 hoursWorkedWeek = workedToday.ToString();
  204.  
  205.                 // calculate lunch and breaks
  206.                 // Break 1
  207.                 string outToBreak1 =
  208.                     ConvertTime.StandardTime(txtOutBreak1.Text);
  209.                 outToBreak1 = ConvertTime.NonMillTime(outToBreak1);
  210.                 outToBreak1 += amPmOutBreak1;
  211.                 string inFromBreak1 =
  212.                     ConvertTime.StandardTime(txtInBreak1.Text);
  213.                 inFromBreak1 = ConvertTime.NonMillTime(inFromBreak1);
  214.                 inFromBreak1 += amPmInBreak1;
  215.                 DateTime outBreak1 = DateTime.Parse(outToBreak1);
  216.                 DateTime inBreak1 = DateTime.Parse(inFromBreak1);
  217.                 TimeSpan break1 = inBreak1 - outBreak1;
  218.  
  219.                 // Lunch
  220.                 string outToLunch =
  221.                     ConvertTime.StandardTime(txtOutToLunch.Text);
  222.                 outToLunch = ConvertTime.NonMillTime(outToLunch);
  223.                 outToLunch += amPmOutLunch;
  224.                 string inFromLunch =
  225.                     ConvertTime.StandardTime(txtInFromLunch.Text);
  226.                 inFromLunch = ConvertTime.NonMillTime(inFromLunch);
  227.                 inFromLunch += amPmInLunch;
  228.                 DateTime outLunch = DateTime.Parse(outToLunch);
  229.                 DateTime inLunch = DateTime.Parse(inFromLunch);
  230.                 TimeSpan lunch = inLunch - outLunch;
  231.  
  232.                 //Break 2
  233.                 string outToBreak2 =
  234.                     ConvertTime.StandardTime(txtOutBreak2.Text);
  235.                 outToBreak2 = ConvertTime.NonMillTime(outToBreak2);
  236.                 outToBreak2 += amPmOutBreak2;
  237.                 string inFromBreak2 =
  238.                     ConvertTime.StandardTime(txtInBreak2.Text);
  239.                 inFromBreak2 = ConvertTime.NonMillTime(inFromBreak2);
  240.                 inFromBreak2 += amPmInBreak2;
  241.                 DateTime outBreak2 = DateTime.Parse(outToBreak2);
  242.                 DateTime inBreak2 = DateTime.Parse(inFromBreak2);
  243.                 TimeSpan break2 = inBreak2 - outBreak2;
  244.  
  245.                 TimeSpan lunchTotal = break1.Add(break2);
  246.                 lunchTotal = lunchTotal.Add(lunch);
  247.  
  248.                 string lunchTimeUsed = lunchTotal.ToString();
  249.                 //lunchTimeUsed = ConvertTime.NoAmPm(lunchTimeUsed);
  250.                 lunchTime = lunchTimeUsed;
  251.  
  252.                 // now calculate hours worked - lunch
  253.                 double worked = ConvertTime.ToDecimal(hoursWorkedWeek);
  254.                 double lunchBreaks = ConvertTime.ToDecimal(lunchTime);
  255.                 worked = worked - lunchBreaks;
  256.                 string forwardTime = worked.ToString();
  257.                 // just in case we get back a whole number, which is likely
  258.                 // othewise ConvertTime.StandardTime will have a problem.
  259.                 if (forwardTime.IndexOf('.') <0)
  260.                 {
  261.                     forwardTime += ":00";
  262.                 }
  263.                 forwardTime = ConvertTime.StandardTime(forwardTime);
  264.                 txtTotalHoursDay.Text = forwardTime;
  265.                 btnAdd.Enabled = true;
  266.                 ok = true;
  267.             }
  268.         }
  269.  
  270.         // user clicked the add button
  271.         private void btnAdd_Click(object sender, EventArgs e)
  272.         {
  273.             dayAdded++;
  274.             if (dayAdded == 6)
  275.             {
  276.                 grpLunchClock.Enabled = false;
  277.                 // MessageBox.Show("You may only enter up to 6 work days. If you"
  278.                 //+ " are working 7 days, that will be kept care of on the main"
  279.                 //+ " window.", "Entry Error");
  280.             }
  281.             switch (dayAdded)
  282.             {
  283.                 case 1:
  284.                     txtDay1Hours.Text = txtTotalHoursDay.Text;
  285.                     lblDay.Text = "second";
  286.                     lblDayCon.Text = "Day 2:";
  287.                     btnAddTogether.Enabled = true;
  288.                     break;
  289.                 case 2:
  290.                     txtDay2Hours.Text = txtTotalHoursDay.Text;
  291.                     lblDay.Text = "third";
  292.                     lblDayCon.Text = "Day 3:";
  293.                     break;
  294.                 case 3:
  295.                     txtDay3Hours.Text = txtTotalHoursDay.Text;
  296.                     lblDay.Text = "fourth";
  297.                     lblDayCon.Text = "Day 4:";
  298.                     break;
  299.                 case 4:
  300.                     txtDay4Hours.Text = txtTotalHoursDay.Text;
  301.                     lblDay.Text = "fifth";
  302.                     lblDayCon.Text = "Day 5:";
  303.                     break;
  304.                 case 5:
  305.                     txtDay5Hours.Text = txtTotalHoursDay.Text;
  306.                     lblDay.Text = "sixth";
  307.                     lblDayCon.Text = "Day 6:";
  308.                     break;
  309.                 case 6:
  310.                     txtDay6Hours.Text = txtTotalHoursDay.Text;
  311.                     break;
  312.             }
  313.         }
  314.  
  315.         // ucer is changing am/pm
  316.         private void cboInForDayAmPm_SelectedIndexChanged(object sender, EventArgs e)
  317.         {
  318.             if (cboInForDayAmPm.SelectedIndex == 1)
  319.             {
  320.                 amPmInForDay = "PM";
  321.  
  322.             }
  323.             else
  324.             {
  325.                 amPmInForDay = "AM";
  326.             }
  327.         }
  328.  
  329.         // user clicked the send button
  330.         private void btnSend_Click(object sender, EventArgs e)
  331.         {
  332.             if (ok)
  333.             {
  334.                 // allow form to close
  335.                 this.Tag = txtTotalHoursWeek.Text;
  336.                 this.DialogResult = DialogResult.OK;
  337.             }
  338.         }
  339.  
  340.         // user clicked the Add together button
  341.         private void btnAddTogether_Click(object sender, EventArgs e)
  342.         {
  343.             if(!(Validator.IsPresent(txtDay1Hours) &&
  344.                 Validator.IsPresent(txtDay2Hours) &&
  345.                 Validator.IsPresent(txtDay3Hours) &&
  346.                 Validator.IsPresent(txtDay4Hours) &&
  347.                 Validator.IsPresent(txtDay5Hours) &&
  348.                 Validator.IsPresent(txtDay6Hours) &&
  349.                 Validator.IsTime(txtDay1Hours) &&
  350.                 Validator.IsTime(txtDay2Hours) &&
  351.                 Validator.IsTime(txtDay3Hours) &&
  352.                 Validator.IsTime(txtDay4Hours) &&
  353.                 Validator.IsTime(txtDay5Hours) &&
  354.                 Validator.IsTime(txtDay6Hours)))
  355.             {
  356.                 ok = false;
  357.             }
  358.             else
  359.             {
  360.                 double day1 = ConvertTime.ToDecimal(txtDay1Hours.Text);
  361.                 double day2 = ConvertTime.ToDecimal(txtDay2Hours.Text);
  362.                 double day3 = ConvertTime.ToDecimal(txtDay3Hours.Text);
  363.                 double day4 = ConvertTime.ToDecimal(txtDay4Hours.Text);
  364.                 double day5 = ConvertTime.ToDecimal(txtDay5Hours.Text);
  365.                 double day6 = ConvertTime.ToDecimal(txtDay6Hours.Text);
  366.                 double totalHours = day1 + day2 + day3 + day4 + day5 + day6;
  367.                 string workedHours = totalHours.ToString("f2");
  368.                 if (workedHours.IndexOf('.') <0)
  369.                 {
  370.                     workedHours += ".00";
  371.                 }
  372.                 hoursWorkedWeek = ConvertTime.StandardTime(workedHours);
  373.                 if (hoursWorkedWeek == "0:00")
  374.                 {
  375.                     MessageBox.Show("All times have a zero value, so there is "
  376.                     + "nothing to add together", "Entry Error");
  377.                     txtDay1Hours.Focus();
  378.                 }
  379.                 else
  380.                 {
  381.                     ok = true;
  382.                     txtTotalHoursWeek.Text = hoursWorkedWeek;
  383.                     btnSend.Enabled = true;
  384.                 }
  385.             }
  386.            
  387.         }
  388.  
  389.         // user clicked Exit in the menu
  390.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  391.         {
  392.             this.Close();
  393.         }
  394.  
  395.         // user clicked About in the menu
  396.         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  397.         {
  398.             Form aboutForm = new AboutBox1();
  399.             aboutForm.ShowDialog();
  400.         }
  401.  
  402.         // user clicked the Contents for help the menu
  403.         private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
  404.         {
  405.             Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
  406.         }
  407.     }
  408. }

Here is the code for the Lunch window, it adds unpaid lunch/breaks to the day:

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // **********************************************
  9. // This Class: frmLunch
  10. // This Class Author: Brian A. Thomas
  11. // This Class Version: 0.4.2
  12. // This Class Copyright: 2006 by Brian A. Thomas
  13. // **********************************************
  14. /*
  15.      This file is part of What Time Do I Leave Friday.
  16.     What Time Do I Leave Friday is free software; you can redistribute it
  17.     and/or modify it under the terms of the GNU General Public License as
  18.     published by the Free Software Foundation; version 2 of the
  19.     License, or any later version.
  20.     What Time Do I Leave Friday is distributed in the hope that it will be
  21.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.     GNU General Public License for more details.
  24.     You should have received a copy of the GNU General Public License
  25.     along with What Time Do I Leave Friday; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28.  
  29. using System;
  30. using System.Collections.Generic;
  31. using System.ComponentModel;
  32. using System.Data;
  33. using System.Drawing;
  34. using System.Text;
  35. using System.Windows.Forms;
  36.  
  37. namespace WhatTimeFriday
  38. {
  39.     /// <summary>
  40.     /// Code for the Lunch form. Allows the user to add unpaid lunchs and
  41.     /// breaks to the calculation on the main window
  42.     /// </summary>
  43.     public partial class frmLunch : Form
  44.     {
  45.         /// <summary>
  46.         /// Created by Visual C# 2005
  47.         /// </summary>
  48.         public frmLunch()
  49.         {
  50.             InitializeComponent();
  51.         }
  52.  
  53.         // set global variables
  54.         string amPmOutBreak1 = "AM";
  55.         string amPmInBreak1 = "AM";
  56.         string amPmOutLunch = "AM";
  57.         string amPmInLunch = "AM";
  58.         string amPmOutBreak2 = "AM";
  59.         string amPmInBreak2 = "AM";
  60.         // lunchTime is the string returned to the main window
  61.         string lunchTime = "0:00";
  62.         // will allow the lunch window to close so long as all is valid
  63.         private bool ok = true;
  64.  
  65.         // load event, sets AM/PM in combo boxes.
  66.         private void frmLunch_Load(object sender, EventArgs e)
  67.         {
  68.             cboOutLunchAmPm.Items.Add("AM");
  69.             cboOutLunchAmPm.Items.Add("PM");
  70.             cboOutLunchAmPm.SelectedIndex = 0;
  71.             cboInLunchAmPm.Items.Add("AM");
  72.             cboInLunchAmPm.Items.Add("PM");
  73.             cboInLunchAmPm.SelectedIndex = 0;
  74.             cboInBreak1AmPm.Items.Add("AM");
  75.             cboInBreak1AmPm.Items.Add("PM");
  76.             cboInBreak1AmPm.SelectedIndex = 0;
  77.             cboOutBreak1AmPm.Items.Add("AM");
  78.             cboOutBreak1AmPm.Items.Add("PM");
  79.             cboOutBreak1AmPm.SelectedIndex = 0;
  80.             cboInBreak2AmPm.Items.Add("AM");
  81.             cboInBreak2AmPm.Items.Add("PM");
  82.             cboInBreak2AmPm.SelectedIndex = 0;
  83.             cboOutBreak2AmPm.Items.Add("AM");
  84.             cboOutBreak2AmPm.Items.Add("PM");
  85.             cboOutBreak2AmPm.SelectedIndex = 0;
  86.             // focus on ClockTime text box as that is the default entry.
  87.             txtClockTime.Focus();
  88.         }
  89.  
  90.         // user chose to enter their lunch and unpaid breaks in a clock in/out
  91.         // format
  92.         private void rbtnClock_CheckedChanged(object sender, EventArgs e)
  93.         {
  94.             grpTotalLunchTime.Enabled = false;
  95.             grpLunchClock.Enabled = true;
  96.             txtOutToLunch.Focus();
  97.         }
  98.  
  99.         // user will enter total time of lunchs and unpaid breaks
  100.         private void rbtnTime_CheckedChanged(object sender, EventArgs e)
  101.         {
  102.             grpLunchClock.Enabled = false;
  103.             grpTotalLunchTime.Enabled = true;
  104.             txtClockTime.Focus();
  105.         }
  106.  
  107.         // close this form
  108.         private void btnCancel_Click(object sender, EventArgs e)
  109.         {
  110.             this.Close();
  111.         }
  112.  
  113.         /// <summary>
  114.         /// If all information if valid, calculate total lunch and unpaid
  115.         /// break time (if the user entered time into the clock) and then send
  116.         /// the information back to the main window
  117.         /// </summary>
  118.         /// <param name="sender">standard object sender</param>
  119.         /// <param name="e">standard event handler</param>
  120.         private void btnSave_Click(object sender, EventArgs e)
  121.         {
  122.             if (rbtnTime.Checked)
  123.             {
  124.                 // user entered a total time for lunch and unpaid breaks
  125.  
  126.                 //Validator.IsPresent(txtClockTime);
  127.                 //Validator.IsTime(txtClockTime);
  128.                 // was originally like above, but, every time something wasn't
  129.                 // valid, the error box would come up, I would hit OK then
  130.                 // the lunch window would go away with the box.
  131.                 // so added this Not logical operator to allow me to set
  132.                 // an okay or not bool value to false, allowing me to stop
  133.                 // the dialog result being OK.
  134.                 if (!(Validator.IsPresent(txtClockTime) &&
  135.                     Validator.IsTime(txtClockTime)))
  136.                 {
  137.                     // isn't valid so don't allow this form to close
  138.                     ok = false;
  139.                 }
  140.                 else
  141.                 {
  142.                     // make sure it isn't in decimal format then set to allow
  143.                     // ok to true so form can close
  144.                     // lunchTime will be returned to main window
  145.                     lunchTime = ConvertTime.StandardTime(txtClockTime.Text);
  146.                     if (lunchTime == "0:00")
  147.                     {
  148.                         MessageBox.Show("Time was a zero. If you want to "
  149.                             + "Cancel entry select the cancell button",
  150.                             "Entry Error");
  151.                         txtClockTime.Focus();
  152.                         ok = false;
  153.                     }
  154.                     else
  155.                     {
  156.                         ok = true;
  157.                     }
  158.                 }
  159.             }
  160.             else
  161.             {
  162.                 // user is using the clock function to calculate total
  163.                 // lunch and unpaid break time
  164.                 if(!(Validator.IsPresent(txtOutBreak1) &&
  165.                     Validator.IsTime(txtOutBreak1) &&
  166.                     Validator.IsPresent(txtInBreak1) &&
  167.                     Validator.IsTime(txtInBreak1) &&
  168.                     Validator.IsPresent(txtOutToLunch) &&
  169.                     Validator.IsPresent(txtInFromLunch) &&
  170.                     Validator.IsTime(txtOutToLunch) &&
  171.                     Validator.IsTime(txtInFromLunch) &&
  172.                     Validator.IsPresent(txtOutBreak2) &&
  173.                     Validator.IsTime (txtOutBreak2) &&
  174.                     Validator.IsPresent(txtInBreak2) &&
  175.                     Validator.IsTime(txtInBreak2)))
  176.                 {
  177.                     // isn't valid, so don't allow this form to close
  178.                     ok = false;
  179.                 }
  180.                 else
  181.                 {
  182.                     // entries are valid, so start calculating
  183.  
  184.                     // Break 1
  185.                     string outToBreak1 =
  186.                         ConvertTime.StandardTime(txtOutBreak1.Text);
  187.                     outToBreak1 = ConvertTime.NonMillTime(outToBreak1);
  188.                     outToBreak1 += amPmOutBreak1;
  189.                     string inFromBreak1 =
  190.                         ConvertTime.StandardTime(txtInBreak1.Text);
  191.                     inFromBreak1 = ConvertTime.NonMillTime(inFromBreak1);
  192.                     inFromBreak1 += amPmInBreak1;
  193.                     DateTime outBreak1 = DateTime.Parse(outToBreak1);
  194.                     DateTime inBreak1 = DateTime.Parse(inFromBreak1);
  195.                     TimeSpan break1 = inBreak1 - outBreak1;
  196.  
  197.                     // Lunch
  198.                     string outToLunch =
  199.                         ConvertTime.StandardTime(txtOutToLunch.Text);
  200.                     outToLunch = ConvertTime.NonMillTime(outToLunch);
  201.                     outToLunch += amPmOutLunch;
  202.                     string inFromLunch =
  203.                         ConvertTime.StandardTime(txtInFromLunch.Text);
  204.                     inFromLunch = ConvertTime.NonMillTime(inFromLunch);
  205.                     inFromLunch += amPmInLunch;
  206.                     DateTime outLunch = DateTime.Parse(outToLunch);
  207.                     DateTime inLunch = DateTime.Parse(inFromLunch);
  208.                     TimeSpan lunch = inLunch - outLunch;
  209.  
  210.                     //Break 2
  211.                     string outToBreak2 =
  212.                         ConvertTime.StandardTime(txtOutBreak2.Text);
  213.                     outToBreak2 = ConvertTime.NonMillTime(outToBreak2);
  214.                     outToBreak2 += amPmOutBreak2;
  215.                     string inFromBreak2 =
  216.                         ConvertTime.StandardTime(txtInBreak2.Text);
  217.                     inFromBreak2 = ConvertTime.NonMillTime(inFromBreak2);
  218.                     inFromBreak2 += amPmInBreak2;
  219.                     DateTime outBreak2 = DateTime.Parse(outToBreak2);
  220.                     DateTime inBreak2 = DateTime.Parse(inFromBreak2);
  221.                     TimeSpan break2 = inBreak2 - outBreak2;
  222.  
  223.                     // start calcualting total lunch and unpaid breaks
  224.                     TimeSpan lunchTotal = break1.Add(break2);
  225.                     lunchTotal = lunchTotal.Add(lunch);
  226.                     string lunchTimeUsed = lunchTotal.ToString();
  227.                     // lunchTime will be returned to main window
  228.                     lunchTime = lunchTimeUsed;
  229.                     if (lunchTime == "0:00")
  230.                     {
  231.                         MessageBox.Show("Time was a zero. If you want to "
  232.                             + "Cancel entry select the cancell button",
  233.                             "Entry Error");
  234.                         ok = false;
  235.                         txtOutToLunch.Focus();
  236.                     }
  237.                     else
  238.                     {
  239.                         ok = true;
  240.                     }
  241.                 }
  242.             }
  243.  
  244.             // sets lunchTime to be value to be returned to main window
  245.             this.Tag = lunchTime;
  246.             if (ok)
  247.             {
  248.                 // allow form to close
  249.                 this.DialogResult = DialogResult.OK;
  250.             }
  251.         }
  252.  
  253.         // set the AM/PM combo boxes
  254.         private void cboOutLunchAmPm_SelectedIndexChanged(object sender, EventArgs e)
  255.         {
  256.             if (cboOutLunchAmPm.SelectedIndex == 1)
  257.             {
  258.                 amPmOutLunch = "PM";
  259.  
  260.             }
  261.             else
  262.             {
  263.                 amPmOutLunch = "AM";
  264.             }
  265.         }
  266.  
  267.         private void cboInLunchAmPm_SelectedIndexChanged(object sender, EventArgs e)
  268.         {
  269.             if (cboInLunchAmPm.SelectedIndex == 1)
  270.             {
  271.                 amPmInLunch = "PM";
  272.  
  273.             }
  274.             else
  275.             {
  276.                 amPmInLunch = "AM";
  277.             }
  278.         }
  279.  
  280.         private void cboOutBreak1AmPm_SelectedIndexChanged(object sender, EventArgs e)
  281.         {
  282.             if (cboOutBreak1AmPm.SelectedIndex == 1)
  283.             {
  284.                 amPmOutBreak1 = "PM";
  285.  
  286.             }
  287.             else
  288.             {
  289.                 amPmOutBreak1 = "AM";
  290.             }
  291.         }
  292.  
  293.         private void cboInBreak1AmPm_SelectedIndexChanged(object sender, EventArgs e)
  294.         {
  295.             if (cboInBreak1AmPm.SelectedIndex == 1)
  296.             {
  297.                 amPmInBreak1 = "PM";
  298.  
  299.             }
  300.             else
  301.             {
  302.                 amPmInBreak1 = "AM";
  303.             }
  304.         }
  305.  
  306.         private void cboOutBreak2AmPm_SelectedIndexChanged(object sender, EventArgs e)
  307.         {
  308.             if (cboOutBreak2AmPm.SelectedIndex == 1)
  309.             {
  310.                 amPmOutBreak2 = "PM";
  311.  
  312.             }
  313.             else
  314.             {
  315.                 amPmOutBreak2 = "AM";
  316.             }
  317.         }
  318.  
  319.         private void cboInBreak2AmPm_SelectedIndexChanged(object sender, EventArgs e)
  320.         {
  321.             if (cboInBreak2AmPm.SelectedIndex == 1)
  322.             {
  323.                 amPmInBreak2 = "PM";
  324.  
  325.             }
  326.             else
  327.             {
  328.                 amPmInBreak2 = "AM";
  329.             }
  330.         }
  331.  
  332.         // Menu items
  333.         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  334.         {
  335.             Form aboutForm = new AboutBox1();
  336.             aboutForm.ShowDialog();
  337.         }
  338.  
  339.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  340.         {
  341.             this.Close();
  342.         }
  343.  
  344.         private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
  345.         {
  346.             Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
  347.         }
  348.     } // end class ConvertTime
  349. }

Here is the code for Vacation time:

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // **********************************************
  9. // This Class: vacation
  10. // This Class Author: Brian A. Thomas
  11. // This Class Version: 0.4
  12. // This Class Copyright: 2006 by Brian A. Thomas
  13. // **********************************************
  14. /*
  15.      This file is part of What Time Do I Leave Friday.
  16.     What Time Do I Leave Friday is free software; you can redistribute it
  17.     and/or modify it under the terms of the GNU General Public License as
  18.     published by the Free Software Foundation; version 2 of the
  19.     License, or any later version.
  20.     What Time Do I Leave Friday is distributed in the hope that it will be
  21.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.     GNU General Public License for more details.
  24.     You should have received a copy of the GNU General Public License
  25.     along with What Time Do I Leave Friday; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.ComponentModel;
  31. using System.Data;
  32. using System.Drawing;
  33. using System.Text;
  34. using System.Windows.Forms;
  35.  
  36. namespace WhatTimeFriday
  37. {
  38.     /// <summary>
  39.     /// This window adds unpaid vacation/sick/personal time to the
  40.     /// calculations used by the main window
  41.     /// </summary>
  42.     public partial class vacation : Form
  43.     {
  44.         /// <summary>
  45.         /// This window adds unpaid vacation/sick/personal time to the
  46.         /// calculations used by the main window this is the actual start
  47.         /// of this window
  48.         /// </summary>
  49.         public vacation()
  50.         {
  51.             InitializeComponent();
  52.         }
  53.        
  54.         // set global variables
  55.         private bool ok = true;
  56.         string hoursWorkedWeek = "0:00";
  57.        
  58.         // user clicked add together to get total hours
  59.         private void btnAddTogether_Click(object sender, EventArgs e)
  60.         {
  61.             if (!(Validator.IsPresent(txtDay1Hours) &&
  62.                 Validator.IsPresent(txtDay2Hours) &&
  63.                 Validator.IsPresent(txtDay3Hours) &&
  64.                 Validator.IsPresent(txtDay4Hours) &&
  65.                 Validator.IsPresent(txtDay5Hours) &&
  66.                 Validator.IsPresent(txtDay6Hours) &&
  67.                 Validator.IsTime(txtDay1Hours) &&
  68.                 Validator.IsTime(txtDay2Hours) &&
  69.                 Validator.IsTime(txtDay3Hours) &&
  70.                 Validator.IsTime(txtDay4Hours) &&
  71.                 Validator.IsTime(txtDay5Hours) &&
  72.                 Validator.IsTime(txtDay6Hours)))
  73.             {
  74.                 // not valid, don't let window close
  75.                 ok = false;
  76.             }
  77.             else
  78.             {
  79.                 double day1 = ConvertTime.ToDecimal(txtDay1Hours.Text);
  80.                 double day2 = ConvertTime.ToDecimal(txtDay2Hours.Text);
  81.                 double day3 = ConvertTime.ToDecimal(txtDay3Hours.Text);
  82.                 double day4 = ConvertTime.ToDecimal(txtDay4Hours.Text);
  83.                 double day5 = ConvertTime.ToDecimal(txtDay5Hours.Text);
  84.                 double day6 = ConvertTime.ToDecimal(txtDay6Hours.Text);
  85.                 double totalHours = day1 + day2 + day3 + day4 + day5 + day6;
  86.                 string workedHours = totalHours.ToString("f2");
  87.                 if (workedHours.IndexOf('.') <0)
  88.                 {
  89.                     workedHours += ".00";
  90.                 }
  91.                 hoursWorkedWeek = ConvertTime.StandardTime(workedHours);
  92.                 if (hoursWorkedWeek == "0:00")
  93.                 {
  94.                     MessageBox.Show("All times have a zero value, so there is "
  95.                     + "nothing to add together", "Entry Error");
  96.                     txtDay1Hours.Focus();
  97.                 }
  98.                 else
  99.                 {
  100.                     ok = true;
  101.                     txtTotalHoursWeek.Text = hoursWorkedWeek;
  102.                     btnSend.Enabled = true;
  103.                 }
  104.             }
  105.         }
  106.  
  107.         // user chose to send results back
  108.         private void btnSend_Click(object sender, EventArgs e)
  109.         {
  110.             if (ok)
  111.             {
  112.                 // allow form to close
  113.                 this.Tag = txtTotalHoursWeek.Text;
  114.                 this.DialogResult = DialogResult.OK;
  115.             }
  116.         }
  117.  
  118.         // user chose to cancel entry
  119.         private void btnCancel_Click(object sender, EventArgs e)
  120.         {
  121.             this.Close();
  122.         }
  123.  
  124.         // user chose Exit from the menu
  125.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  126.         {
  127.             Form aboutForm = new AboutBox1();
  128.             aboutForm.ShowDialog();
  129.         }
  130.  
  131.         // user chose About from the menu
  132.         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  133.         {
  134.             Form aboutForm = new AboutBox1();
  135.             aboutForm.ShowDialog();
  136.         }
  137.  
  138.         // user chose Help from the menu
  139.         private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
  140.         {
  141.             Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
  142.         }
  143.     }
  144. }

Here is the code for the Vailidator class:

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // NOTE: This will likely change in future versions
  9. // to be in my own library set.
  10. // **********************************************
  11. // Class: MainWindow
  12. // Class Author: Brian A. Thomas
  13. // Class Version: 0.6
  14. // Based off of the Validator Class presented in Murach's C# 2005 book
  15. // by Joel Murach
  16. // Published by: Mike Murach and Associates, Inc.
  17. // ISBN-10: 1-890774-37-5, ISBN-13: 978-1-890774-37-0
  18. // Available at www.murach.com, Amazon.com and other quality book stores
  19. // **********************************************
  20. /*
  21.      This file is part of What Time Do I Leave Friday.
  22.     What Time Do I Leave Friday is free software; you can redistribute it
  23.     and/or modify it under the terms of the GNU General Public License as
  24.     published by the Free Software Foundation; version 2 of the
  25.     License, or any later version.
  26.     What Time Do I Leave Friday is distributed in the hope that it will be
  27.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.     GNU General Public License for more details.
  30.     You should have received a copy of the GNU General Public License
  31.     along with What Time Do I Leave Friday; if not, write to the Free Software
  32.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  33. */
  34. // Portions from Murach's book might fall outside the bounds from the GNU GPL.
  35.  
  36. using System;
  37. using System.Collections.Generic;
  38. using System.Text;
  39. using System.Windows.Forms;
  40.  
  41. namespace WhatTimeFriday
  42. {
  43.     /// <summary>
  44.     /// Validator claass is used to validate that data entered into text boxes
  45.     /// are valid.  Presently covers that the text boxes that are required are
  46.     /// not empty, that it containes a decimal and that it is in a proper
  47.     /// time format.
  48.     /// See comments at top for original source information.
  49.     /// </summary>
  50.     class Validator
  51.     {
  52.         /// <summary>
  53.         /// Determains if a text box has an entry
  54.         /// </summary>
  55.         /// <param name="textBox">The name of the text box's Tag property</param>
  56.         /// <returns>true or false value</returns>
  57.         //  NOTE: This is the part that came from Murach's book and as such
  58.         //  may fall outside the bounds of the GNU GPL.
  59.         public static bool IsPresent(TextBox textBox)
  60.         {
  61.             if (textBox.Text == "")
  62.             {
  63.                 MessageBox.Show(textBox.Tag + " is a requried field.", "Entry Error");
  64.                 textBox.Focus();
  65.                 return false;
  66.             } // end box is empty Message Box
  67.             return true;
  68.         } // end IsPresent
  69.  
  70.         /// <summary>
  71.         /// Makes sure that the entry into the text box is in a valid time
  72.         /// format such as 8:30 or 8.5.
  73.         /// It does NOT insure it is in standard time over military time as
  74.         /// some times entered into boxes will be more then 12, so that part
  75.         /// is handled by the StandardTime method of the ConvertTime class.
  76.         /// This one was not in the book.
  77.         /// </summary>
  78.         /// <param name="textBox">The name of the text box's Tag property</param>
  79.         /// <returns>true or false value</returns>
  80.         public static bool IsTime(TextBox textBox)
  81.         {
  82.             string s = textBox.Text;
  83.             int seperatorCount = 0;
  84.             bool validTime = true;
  85.             foreach (char c in s)
  86.             {
  87.                 if (!(c == '0' || c == '1' || c == '2' || c == '3' || c == '4'
  88.                     || c == '5' || c == '6' || c == '7' || c == '8' || c == '9'
  89.                     || c == ':' || c == '.'))
  90.                 {
  91.                     validTime = false;
  92.                     break;
  93.                 } // end Time isn't valid
  94.                 if (c == ':' || c == '.')
  95.                 {
  96.                     seperatorCount++;
  97.                 } // end if seperator
  98.             } // end foreach
  99.             if (validTime && seperatorCount == 1) // presently doesn't allow
  100.             // for seconds. May be modified at a later date to allow for
  101.             // them by changing it to>0 && <=2 so it forces it to be over
  102.             // over 0 but still under 2.
  103.             {
  104.                 return true;
  105.             } // end if time is valid and seperator count isn't too high
  106.             else
  107.             {
  108.                 MessageBox.Show(textBox.Tag + " must be in a time format. "
  109.                 + "Such as 8:30.\nDo NOT enter seconds or AM/PM.\nAM/PM is"
  110.                 + " selected by using the AM/PM buttons.\nAlso be sure to "
  111.                 + "include the ":" seperator.\n"
  112.                 + "If the time is 0 enter 0:00.", "Entry Error");
  113.                 textBox.Focus();
  114.                 return false;
  115.             } // end time isn't valid message box display
  116.         } // end IsTime
  117.     }// end Validator class
  118. }

Finally, here is the code for the main window itself:

C#:
  1. // **********************************************
  2. // Program Name: What Time Do I Leave Friday
  3. // Program Author: Brian A. Thomas
  4. // Program Homepage: http://www.brianathomas.com/
  5. // Author Homepage: http://www.brianathomas.com/
  6. // **********************************************
  7. // This Namespace: WhatTimeFriday
  8. // **********************************************
  9. // This Class: MainWindow
  10. // This Class Author: Brian A. Thomas
  11. // This Class Version: 0.8
  12. // This Class Copyright: 2006 by Brian A. Thomas
  13. // **********************************************
  14. /*
  15.      This file is part of What Time Do I Leave Friday.
  16.     What Time Do I Leave Friday is free software; you can redistribute it
  17.     and/or modify it under the terms of the GNU General Public License as
  18.     published by the Free Software Foundation; version 2 of the
  19.     License, or any later version.
  20.     What Time Do I Leave Friday is distributed in the hope that it will be
  21.     useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.     GNU General Public License for more details.
  24.     You should have received a copy of the GNU General Public License
  25.     along with What Time Do I Leave Friday; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28.  
  29. using System;
  30. using System.Collections.Generic;
  31. using System.ComponentModel;
  32. using System.Data;
  33. using System.Drawing;
  34. using System.Text;
  35. using System.Windows.Forms;
  36. //using ystem.Windows.Forms.ToolTip;
  37.  
  38. namespace WhatTimeFriday
  39. {
  40.     /// <summary>
  41.     /// This program will take the hours worked so far in a week, the time
  42.     /// in Friday and lets you know what time to leave Friday
  43.     /// Future versions will allow for less then 40 hours for a standard work
  44.     /// week and allow for lunches on Friday
  45.     /// </summary>
  46.     public partial class MainWindow : Form
  47.     {
  48.         /// <summary>
  49.         /// Created by Visual C# 2005
  50.         /// </summary>
  51.         public MainWindow()
  52.         {
  53.             InitializeComponent();
  54.            
  55.         }
  56.  
  57.         // set global variable
  58.         double standardWorkWeek = 40;
  59.         string lunchTime = "0:00";
  60.         bool standWeekOpen = false;
  61.         double vacationTime = 0;
  62.         // Global variable moved from below so it can be used by a
  63.         // few methods, most noteably so I could display the lunch time
  64.         double lunch;
  65.         bool valid = true;
  66.        
  67.         /// <summary>
  68.         /// This Field controls if the time in is AM or PM
  69.         /// </summary>
  70.         private static bool pm = false;
  71.  
  72.         /// <summary>
  73.         /// PM Property for other classes to access the pm field and set
  74.         /// AM/PM as needed. Most notably at this time the ConvertTime class
  75.         /// uses it if the user uses military time in the Friday in box.
  76.         /// </summary>
  77.         public static bool PM
  78.         {
  79.             get
  80.             {
  81.                 return pm;
  82.             }
  83.             set
  84.             {
  85.                 pm = value;
  86.             }
  87.         }
  88.        
  89.         /// <summary>
  90.         /// User clicked the Calculate button.
  91.         /// If everything is valid, then calculate the time out and hours
  92.         /// for the day.
  93.         /// </summary>
  94.         /// <param name="sender">Standard object sender for event</param>
  95.         /// <param name="e">Standard event handler</param>
  96.         private void btnCalculate_Click(object sender, EventArgs e)
  97.         {
  98.             if (standWeekOpen)
  99.             {
  100.                 // if the user was editing the standard work week
  101.  
  102.                 // first check the text box
  103.                 if (Validator.IsPresent(txtWorkWeek))
  104.                 {
  105.                     if (txtWorkWeek.Text.IndexOf(':') <0
  106.                         && txtWorkWeek.Text.IndexOf('.') <0)
  107.                     {
  108.                         txtWorkWeek.Text += ":00";
  109.                     }
  110.                     else if (txtWorkWeek.Text.IndexOf('.')> -1)
  111.                     {
  112.                         string tempTime =
  113.                             ConvertTime.StandardTime(txtWorkWeek.Text);
  114.                         txtWorkWeek.Text = tempTime;
  115.                     }
  116.                     // check to be sure there are minutes even if they are 0
  117.                     string checkMinutes =
  118.                         ConvertTime.StandardTime(txtWorkWeek.Text);
  119.                     txtWorkWeek.Text = checkMinutes;
  120.                 }
  121.                 // next change standarWorkWeek into a time value
  122.                 string changeStandardWorkWeek = standardWorkWeek.ToString();
  123.                 if (changeStandardWorkWeek.IndexOf('.') <0)
  124.                 {
  125.                     changeStandardWorkWeek += ":00";
  126.                 }
  127.                 else
  128.                 {
  129.                     changeStandardWorkWeek =
  130.                     ConvertTime.StandardTime(changeStandardWorkWeek);
  131.                 }
  132.                
  133.                 // okay one more thing to check before we go on
  134.                 // check to see if the time in the text box is differant
  135.                 // from the standerWorkWeek (changeStandarWorkWeek)
  136.                 if (!(changeStandardWorkWeek == txtWorkWeek.Text))
  137.                 {
  138.                     // the standardWorkWeek and the time in the box are differant
  139.                     DialogResult button = MessageBox.Show("You are still editing "
  140.                     + "the Standard Work Week.\n"
  141.                     + "Press OK to save work week as " + txtWorkWeek.Text + "\n"
  142.                     + "Or press CANCEL to save work week as "
  143.                     + changeStandardWorkWeek, "Work Week Open",
  144.                     MessageBoxButtons.OKCancel);
  145.                     if (button == DialogResult.OK)
  146.                     {
  147.                         btnSaveWorkWeek_Click(sender, e);
  148.                     }
  149.                     else
  150.                     {
  151.                         txtWorkWeek.Text = changeStandardWorkWeek;
  152.                         btnSaveWorkWeek_Click(sender, e);
  153.                     }
  154.                 }
  155.                 else
  156.                 {
  157.                     // they were equal hit the save button so we are sure
  158.                     // to hit the time in. This also makes sure the save
  159.                     // button goes away and the text box becomes read only
  160.                     btnSaveWorkWeek_Click(sender, e);
  161.                 }
  162.  
  163.                
  164.             }
  165.  
  166.             // Check to see if they entered decimal time in a box
  167.             string totalTime = txtTotalHours.Text;
  168.             string inTime = txtTimeInFriday.Text;
  169.             if (totalTime.IndexOf('.')>= 0)
  170.             {
  171.                 DialogResult button = MessageBox.Show("You entered a decimal "
  172.                     + "value into the Total Hours text box.\nIt normally "
  173.                     + "expects a standard time with a colon seperating\nhours "
  174.                     + "from minutes.\nIf you are sure you want to use the "
  175.                     + "decimal entry click OK\notherwise click Cancel to return"
  176.                     + "and edit your entry.","Notice",
  177.                 MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  178.                 if (button == DialogResult.OK)
  179.                 {
  180.                     valid = true;
  181.                 }
  182.                 else
  183.                 {
  184.                     valid = false;
  185.                     txtTotalHours.Focus();
  186.                     txtTimeToLeave.Text = "";
  187.                     txtHourForFriday.Text = "";
  188.                 }
  189.             }
  190.             if (inTime.IndexOf('.')>= 0)
  191.             {
  192.                 DialogResult button = MessageBox.Show("You entered a decimal "
  193.                     + "value into the Time in Friday text box.\nIt normally "
  194.                     + "expects a standard time with a colon seperating\nhours "
  195.                     + "from minutes.\nIf you are sure you want to use the "
  196.                     + "decimal entry click OK\notherwise click Cancel to return"
  197.                     + "and edit your entry.", "Notice",
  198.                 MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  199.                 if (button == DialogResult.OK)
  200.                 {
  201.                     valid = true;
  202.                 }
  203.                 else
  204.                 {
  205.                     valid = false;
  206.                     txtTimeInFriday.Focus();
  207.                     txtTimeToLeave.Text = "";
  208.                     txtHourForFriday.Text = "";
  209.                 }