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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// **********************************************
// 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// **********************************************
// 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)
        {
            Form aboutForm = new AboutBox1();
            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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// **********************************************
// 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)
        {
            if (rbtnTime.Checked)
            {
                // 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)
        {
            Form aboutForm = new AboutBox1();
            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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// **********************************************
// 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)
        {
            Form aboutForm = new AboutBox1();
            aboutForm.ShowDialog();
        }
 
        // user chose About from the menu
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form aboutForm = new AboutBox1();
            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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// **********************************************
// 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
// **********************************************
// 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 = "";
                }
            }
 
            // if everything is okay above, then check to see if the user 
            // entered valid data
            if (valid && IsValidData())
            {
                // handle the hours this week so far
                // first call the ToDecimal method of the Convert Time class
                // to make the text entry a double value
                double totalThisWeek = 
                    ConvertTime.ToDecimal(txtTotalHours.Text);
 
                vacationTime = ConvertTime.ToDecimal(txtVacationTime.Text);
                totalThisWeek += vacationTime;
 
                if (totalThisWeek >= standardWorkWeek)
                {
                    MessageBox.Show("You are at or over the default hours.",
                        "Into Overtime");
                }
 
                // find hours needed to work Friday
                double timeToWorkFriday = standardWorkWeek - totalThisWeek;
 
                // find the time in Friday
                // need to work in call to standard time
                string fridayTimeInString = 
                    ConvertTime.StandardTime(txtTimeInFriday.Text);
                fridayTimeInString = 
                    ConvertTime.NonMillTime(fridayTimeInString);
 
                // Add AM/PM to time in text so Windows DateTime class can
                // handle the math and end up with the correct time
                if (pm)
                {
                    fridayTimeInString += " PM";
                }
                else
                {
                    fridayTimeInString += " AM";
                }
 
                DateTime timeInFriday = DateTime.Parse(fridayTimeInString);
 
                // calculate time out Friday
                DateTime timeOutFriday = 
                    timeInFriday.AddHours(timeToWorkFriday);
                //add lunch time to it
                timeOutFriday = timeOutFriday.AddHours(lunch);
                totalThisWeek = totalThisWeek + lunch;
 
                // output
                txtTimeToLeave.Text = timeOutFriday.ToShortTimeString();
                string hoursForFriday = timeToWorkFriday.ToString("f2");
                hoursForFriday = hoursForFriday + " aka " 
                    + ConvertTime.StandardTime(timeToWorkFriday.ToString("f2"));
                txtHourForFriday.Text = hoursForFriday;
            }
 
        }
 
        /// <summary>
        /// Check to see if the data is valid, calls the Valicator class
        /// to check the two input boxes.
        /// </summary>
        /// <returns>bool value</returns>
        private bool IsValidData()
        {
            return Validator.IsPresent(txtTotalHours) &&
                Validator.IsPresent(txtTimeInFriday) &&
                Validator.IsTime(txtTotalHours) &&
                Validator.IsTime(txtTimeInFriday);
        }
 
        // user selected AM
        // NOTE: I may remove the radio buttons in favor of a combo box
        // to be more consistant with other windows
        private void rbtnAM_CheckedChanged(object sender, EventArgs e)
        {
            pm = false;
        }
 
        // user selected PM
        // see note above for AM
        private void rbtnPM_CheckedChanged(object sender, EventArgs e)
        {
            pm = true;
        }
 
 
        // user has edited the standard work week and now is saving the amount
        // for the program to use to calculate time out
        private void btnSaveWorkWeek_Click(object sender, EventArgs e)
        {
            // check is valid but don't use IsValid method in case
            // user hasn't entered other times yet
            Validator.IsPresent(txtWorkWeek);
            // be sure they entered it in standard time, if they entered it
            // in decimal time, convert it
            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;
            }
            string workWeek = ConvertTime.StandardTime(txtWorkWeek.Text);
            Validator.IsTime(txtWorkWeek);
            // save it to the standardWorkWeek variable
            standardWorkWeek = ConvertTime.ToDecimal(workWeek);
 
            // reset controls
            standWeekOpen = false;
            btnSaveWorkWeek.Visible = false;
            txtWorkWeek.ReadOnly = true;
            txtWorkWeek.TabStop = false;
            txtTotalHours.Focus();
            this.toolTip1.SetToolTip(txtWorkWeek, "To change Standard Work "
            + "Week choose,"Change Standard Work Week"\n from the Action "
            + "menu");
        }
 
        // clear the two read only boxes if a change took place on one of the
        // text windows
        private void ClearReadOnlyBoxes(object sender, EventArgs e)
        {
            txtTimeToLeave.Text = "";
            txtHourForFriday.Text = "";
        }
 
        // user chose exit from the menu
        private void mnuExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        // user wants to add a lunch and/or unpaid breaks
        private void btnLunch_Click(object sender, EventArgs e)
        {
            // just in case somebody filled out stuff before hitting lunch
            // it forces them to rehit calculate
            // in theory should be no need to clear the user entered text boxes
            txtHourForFriday.Text = "";
            txtTimeToLeave.Text = "";
            txtLunchTime.Text = "";
            // reset lunchTime just to be safe
            lunchTime = "0:00";
            // launch the lunch dialog box
            Form lunchForm = new frmLunch();
            lunchForm.ShowDialog();
            lunchTime = (string)lunchForm.Tag;
 
            // get ready for output and math
            // math will be done in Calculate function
            lunch = ConvertTime.ToDecimal(lunchTime);
            string lunchText = ConvertTime.StandardTime(lunchTime);
            // Display Output on screen so user can be sure the time is there
            // before they hit calculate
            if (lunch > 0)
            {
                txtLunchTime.Text = lunchText;
            }
        }
 
        // user chose to close appication from close button
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
 
        // user changed the AM/PM combo box
        private void cboInAmPM_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboInAmPM.SelectedIndex == 1)
            {
                pm = true;
 
            }
            else
            {
                pm = false;
            }
        }
 
        // window loaded, add AM/PM to combo box, set foxus to txtTotalHours
        private void MainWindow_Load(object sender, EventArgs e)
        {
            cboInAmPM.Items.Add("AM");
            cboInAmPM.Items.Add("PM");
            cboInAmPM.SelectedIndex = 0;
            txtTotalHours.Focus();
        }
 
        // Menu items
        // Add Vacation/Personal Time was chosen in the Action menu
        private void addVacationPersonalTimeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form vacationForm = new vacation();
            vacationForm.ShowDialog();
            txtVacationTime.Text = (string)vacationForm.Tag;
        }
 
        // user chose About under menu
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form aboutForm = new AboutBox1();
            aboutForm.ShowDialog();
        }
 
        // user wants to use the hours worked calculator to find out how many 
        // hours they worked so far this week
        private void hoursWorkedCalculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form hoursWorkedCalculator = new HoursWorkedCalculator();
            hoursWorkedCalculator.ShowDialog();
            txtTotalHours.Text = (string)hoursWorkedCalculator.Tag;
            txtTimeInFriday.Focus();
        }
 
        // user wants to edit the standard work week
        private void mnuChangeWorkWeek_Click(object sender, EventArgs e)
        {
            btnSaveWorkWeek.Visible = true;
            txtWorkWeek.ReadOnly = false;
            txtWorkWeek.TabStop = true;
            txtWorkWeek.Focus();
            standWeekOpen = true;
            this.toolTip1.SetToolTip(txtWorkWeek, "Change to what your "
            + "standard work week is.");
        }
 
        // yser chose contents under help menu
        private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //HelpProvider1.HelpNamespace = Application.StartupPath & "HSTest.chm";
            Help.ShowHelp(this, this.helpProvider1.HelpNamespace);
        }
    }
}
Be Sociable, Share!

About Brian A. Thomas

I am the father of Ari and Sidd. I am the owner and administrator of this site.
General

3 responses to Program: What Time Do I Leave Friday


  1. John

    Wow … I’ve never seen so much code used to do something so simple. There is an entire class called “ConvertTime” that tries to replicate functions already built into the .NET Framework. For example, the function called “ToDecimal”, which says, “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″ can be replaced via:

    string s = “08:30″;
    DateTime date = DateTime.Parse(s);
    double result = date.Hour;
    result += (double)date.Minute / 60;

  2. Hehe. Thanks for the advice.
    It’s been a while since I looked at that code, but I recall being a bit frustrated that there seemed to be so much work involved for time/date functions that I thought would be covered. Admittedly I didn’t go beyond my couple books (actually, I may have just used the one as a reference when building this) so I didn’t do much Internet searching on the .Net framework’s time/date functions.
    I may have to revisit this one… I know some code was updated since this post, but I don’t think that class was touched.

  3. I still haven’t gotten a good reference guide yet, and still using the begginer books for everything… then again, I haven’t had much time to just learn programming. :(

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">