Repository navigation
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
112 lines (105 loc) · 4.07 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
112 lines (105 loc) · 4.07 KB
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
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
namespace TimeClock
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
System.Windows.Threading.DispatcherTimer Timer = new System.Windows.Threading.DispatcherTimer();
public MainWindow()
{
InitializeComponent();
Timer.Tick += new EventHandler(Timer_Click);
Timer.Interval = new TimeSpan(0, 0, 1);
Timer.Start();
Time.Text = DateTime.Now.ToShortTimeString();
}
bool isClockedIn = false;
bool onBreak = false;
DateTime start;
DateTime stop;
DateTime breakStart;
DateTime breakStop;
TimeSpan elapsed = new TimeSpan(0);
List<string> lines = new List<string>();
string [] Months = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
private void Clock_In_Click(object sender, RoutedEventArgs e)
{
if(isClockedIn)
{
if(onBreak)
{
onBreak = false;
breakStop = DateTime.Now;
elapsed += breakStop.Subtract(breakStart);
lines.Add("\nEnd Break: " + breakStop.ToShortTimeString() + " : " + Note.Text);
Log.Text += lines.Last();
Break.Content = "Begin Break";
}
isClockedIn = false;
Break.IsEnabled = false;
TimeEnd.Text = DateTime.Now.ToShortTimeString();
stop = DateTime.Now;
ClockIn.Content = "Clock In";
lines.Add("\nClocked Out: " + DateTime.Now + " : " + Note.Text);
Log.Text += lines.Last();
Note.Text = "";
lines.Add("\nElapsed Time: " + (stop.Subtract(start) - elapsed) + "\n");
Log.Text += lines.Last();
Log.ScrollToEnd();
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
File.WriteAllLines(@path + "\\Time Cards\\" + start.Year + "-" + Months[start.Month] + "-" + start.Day + "_" + start.Hour + "-" + start.Minute + "-" + start.Second + ".txt", lines);
} else {
isClockedIn = true;
Break.IsEnabled = true;
TimeStart.Text = DateTime.Now.ToShortTimeString();
start = DateTime.Now;
ClockIn.Content = "Clock Out";
lines.Add("Clocked In: " + DateTime.Now + " : " + Note.Text);
Log.Text += lines.Last();
Log.ScrollToEnd();
Note.Text = "";
}
}
private void Timer_Click(object sender, EventArgs e)
{
Time.Text = DateTime.Now.ToShortTimeString();
}
private void Break_Click(object sender, RoutedEventArgs e)
{
if(onBreak)
{
onBreak = false;
Break.Content = "Begin Break";
breakStop = DateTime.Now;
elapsed += breakStop.Subtract(breakStart);
lines.Add("\nEnd Break: " + breakStop.ToShortTimeString() + " : " + Note.Text);
Log.Text += lines.Last();
Note.Text = "";
} else {
onBreak = true;
Break.Content = "End Break";
breakStart = DateTime.Now;
lines.Add("\nBegin Break: " + breakStart.ToShortTimeString() + " : " + Note.Text);
Log.Text += lines.Last();
Note.Text = "";
}
}
}
}