-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.cs
184 lines (160 loc) · 6.16 KB
/
countdown.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace AlarmClockSystemTray
{
public partial class countdown : Form
{
public int seconds;
public int minutes;
public int hours;
public bool paused;
[DllImport("user32")]
public static extern void LockWorkStation();
public countdown()
{
InitializeComponent();
}
private void btstart_Click(object sender, EventArgs e)
{
if (paused != true)
{
if ((tbhrs.Text != string.Empty) && (tbmin.Text != string.Empty) && (tbsec.Text != string.Empty))
{
timer1.Enabled = true;
btpause.Enabled = true;
btstart.Enabled = false;
btstop.Enabled = true;
tbhrs.Enabled = false;
tbmin.Enabled = false;
tbsec.Enabled = false;
tbmsg.Enabled = false;
try
{
minutes = System.Convert.ToInt32(tbmin.Text);
seconds = System.Convert.ToInt32(tbsec.Text);
hours = System.Convert.ToInt32(tbhrs.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("Incomplete settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
timer1.Enabled = true;
paused = false;
btstart.Enabled = false;
btpause.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if ((minutes == 0) && (hours == 0) && (seconds == 0))
{
timer1.Enabled = false;
Console.Beep();
MessageBox.Show(tbmsg.Text, "Warnning");
btpause.Enabled = false;
btstop.Enabled = false;
btstart.Enabled = true;
tbmsg.Clear();
tbhrs.Text = Convert.ToString(0);
tbmin.Text = Convert.ToString(0);
tbsec.Text = Convert.ToString(0);
LockWorkStation();
tbhrs.Enabled = true;
tbmsg.Enabled = true;
tbsec.Enabled = true;
tbmin.Enabled = true;
tbhrs.Enabled = true;
lblHr.Text = "00";
lblMin.Text = "00";
lblSec.Text = "00";
}
else
{
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0)
hours -= 1;
}
else
{
minutes -= 1;
}
}
else
seconds -= 1;
lblHr.Text = hours.ToString();
lblMin.Text = minutes.ToString();
lblSec.Text = seconds.ToString();
}
if ((minutes == 5) && (hours == 0) && (seconds == 0))
{
MessageBox.Show("Five minutes left.\n Please make sure that you save your work so that you won't loss it. ", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
if ((minutes == 10) && (hours == 0) && (seconds == 0))
{
MessageBox.Show("Ten minutes left.\n Please make sure that you save your work so that you won't loss it. ", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btpause_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to pause the time?\n Be are ware that if you click Yes the computer will be locked.\n I advice you to click No if you not sure what you are doing.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
timer1.Enabled = false;
paused = true;
btpause.Enabled = false;
btstart.Enabled = true;
LockWorkStation();
}
}
private void btstop_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to stop the time?\n Be are ware that if you click Yes the computer will be locked.\n I advice you to click No if you not sure what you are doing.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
paused = false;
timer1.Enabled = false;
btpause.Enabled = false;
btstop.Enabled = false;
btstart.Enabled = true;
tbmsg.Clear();
tbhrs.Text = Convert.ToString(0);
tbmin.Text = Convert.ToString(0);
tbsec.Text = Convert.ToString(0);
tbhrs.Enabled = true;
tbmin.Enabled = true;
tbsec.Enabled = true;
tbmin.Enabled = true;
tbhrs.Enabled = true;
lblHr.Text = "00";
lblMin.Text = "00";
lblSec.Text = "00";
LockWorkStation();
}
}
private void countdown_Load(object sender, EventArgs e)
{
tbhrs.Focus();
tbhrs.Text = Convert.ToString(0);
tbmin.Text = Convert.ToString(0);
tbsec.Text = Convert.ToString(0);
}
}
}