This repository was archived by the owner on May 18, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathWindow_Main.cs
More file actions
160 lines (134 loc) · 4.17 KB
/
Copy pathWindow_Main.cs
File metadata and controls
160 lines (134 loc) · 4.17 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
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
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;
namespace Timed_Shutdown
{
public partial class Window_Main : Form
{
public decimal seconds { get; set; }
public decimal minutes { get; set; }
public decimal hours { get; set; }
public Boolean paused { get; set; }
public int selectedIndex { get; set; }
public Timed_Shutdown.Actions act = new Timed_Shutdown.Actions();
public Window_Main()
{
InitializeComponent();
timer1.Interval = (1000) * (1);
timer1.Enabled = false;
buttonStop.Visible = false;
}
private void buttonStart_Click(object sender, EventArgs e)
{
if (comboTask.SelectedIndex != -1)
{
//disable number boxes
timerSeconds.Enabled = false;
timerMinutes.Enabled = false;
timerHours.Enabled = false;
checkBoxForced.Enabled = false;
comboTask.Enabled = false;
seconds = timerSeconds.Value;
minutes = timerMinutes.Value;
hours = timerHours.Value;
updateLabels();
timer1.Enabled = true;
buttonStart.Visible = false;
buttonStop.Visible = true;
selectedIndex = comboTask.SelectedIndex;
if (checkBoxForced.Checked)
{
selectedIndex = selectedIndex + 4;
}
}
else
{
MessageBox.Show("You need to select an action!");
}
}
private void buttonStop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
seconds = 0;
minutes = 0;
hours = 0;
timerSeconds.Enabled = true;
timerMinutes.Enabled = true;
timerHours.Enabled = true;
checkBoxForced.Enabled = true;
comboTask.Enabled = true;
updateLabels();
buttonStop.Visible = false;
buttonStart.Visible = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (seconds == 0 && minutes == 0 && hours == 0)
{
doTask(selectedIndex);
//Clean and update the interface.
timer1.Enabled = false;
seconds = 0;
minutes = 0;
hours = 0;
timerSeconds.Enabled = true;
timerMinutes.Enabled = true;
timerHours.Enabled = true;
checkBoxForced.Enabled = true;
comboTask.Enabled = true;
updateLabels();
buttonStop.Visible = false;
buttonStart.Visible = true;
}
else
{
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0)
{
hours--;
}
}
else
{
minutes--;
}
}
else
{
seconds--;
}
}
updateLabels();
}
private void updateLabels()
{
labelSeconds.Text = seconds.ToString();
labelMinutes.Text = minutes.ToString();
labelHours.Text = hours.ToString();
}
private void doTask(int selectedIndex){
if (selectedIndex == 3)
{
act.Alarm();
}
else if (selectedIndex < 7)
{
act.ShutDownComputer(selectedIndex);
}
else
{
MessageBox.Show("Invalid Action!");
}
}
}
}