-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationForm.cs
More file actions
133 lines (116 loc) · 6.13 KB
/
ConfigurationForm.cs
File metadata and controls
133 lines (116 loc) · 6.13 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
using System;
using System.Windows.Forms;
namespace Sleeper
{
public partial class ConfigurationForm : Form
{
private Configuration FormConfiguration;
// Delegates
public delegate void SwitchTimer(bool Start = true);
public event SwitchTimer ChangeAction;
public ConfigurationForm(ref Configuration Config)
{
FormConfiguration = Config;
InitializeComponent();
}
private void LoadConfigurationForm(object sender, EventArgs e)
{
UpdateInformationLabel();
if (FormConfiguration.IsEnabled)
{
ActionButton.Text = "Reset";
ActionAfterRadioButton.Enabled = ActionAfterComboBox.Enabled = HoursAfterComboBox.Enabled = MinutesAfterComboBox.Enabled = ActionAtRadioButton.Enabled = ActionAtComboBox.Enabled = HoursAtComboBox.Enabled = MinutesAtComboBox.Enabled = WarnCheckBox.Enabled = false;
}
else
{
ActionButton.Text = "Set";
}
if (FormConfiguration.SelectedOperation == Configuration.SelectionOperation.After)
{
ActionAfterRadioButton.Checked = true;
}
else
{
ActionAtRadioButton.Checked = true;
}
ActionAfterComboBox.SelectedIndex = (int)FormConfiguration.AfterOperation;
ActionAtComboBox.SelectedIndex = (int)FormConfiguration.AtOperation;
for (byte h = 0; h < 24; ++h)
{
HoursAfterComboBox.Items.Add(String.Format("{0:D2}", h));
HoursAtComboBox.Items.Add(String.Format("{0:D2}", h));
}
for (byte h = 0; h < 60; ++h)
{
MinutesAfterComboBox.Items.Add(String.Format("{0:D2}", h));
MinutesAtComboBox.Items.Add(String.Format("{0:D2}", h));
}
TimeSpan TimeSpan = TimeSpan.FromMinutes(FormConfiguration.TimeAfterOperation);
HoursAfterComboBox.Text = TimeSpan.ToString("hh");
MinutesAfterComboBox.Text = TimeSpan.ToString("mm");
TimeSpan = TimeSpan.FromMinutes(FormConfiguration.TimeAtOperation);
HoursAtComboBox.Text = TimeSpan.ToString("hh");
MinutesAtComboBox.Text = TimeSpan.ToString("mm");
if (FormConfiguration.IsWarnEnabled)
{
WarnCheckBox.Checked = true;
}
ActionAfterRadioButton.CheckedChanged += ConfigurationChanged;
ActionAfterComboBox.SelectionChangeCommitted += ConfigurationChanged;
HoursAfterComboBox.SelectionChangeCommitted += ConfigurationChanged;
MinutesAfterComboBox.SelectionChangeCommitted += ConfigurationChanged;
ActionAtRadioButton.CheckedChanged += ConfigurationChanged;
ActionAtComboBox.SelectionChangeCommitted += ConfigurationChanged;
HoursAtComboBox.SelectionChangeCommitted += ConfigurationChanged;
MinutesAtComboBox.SelectionChangeCommitted += ConfigurationChanged;
WarnCheckBox.CheckedChanged += ConfigurationChanged;
}
private void ConfigurationChanged(object sender, EventArgs e)
{
// Lazy solution
FormConfiguration.SelectedOperation = (ActionAfterRadioButton.Checked ? Configuration.SelectionOperation.After : Configuration.SelectionOperation.At);
FormConfiguration.AfterOperation = (Configuration.OperationTypes)ActionAfterComboBox.SelectedIndex;
FormConfiguration.TimeAfterOperation = (ushort)TimeSpan.Parse(HoursAfterComboBox.GetItemText(HoursAfterComboBox.SelectedItem) + ":" + MinutesAfterComboBox.GetItemText(MinutesAfterComboBox.SelectedItem)).TotalMinutes;
FormConfiguration.AtOperation = (Configuration.OperationTypes)ActionAtComboBox.SelectedIndex;
FormConfiguration.TimeAtOperation = (ushort)TimeSpan.Parse(HoursAtComboBox.GetItemText(HoursAtComboBox.SelectedItem) + ":" + MinutesAtComboBox.GetItemText(MinutesAtComboBox.SelectedItem)).TotalMinutes;
FormConfiguration.IsWarnEnabled = WarnCheckBox.Checked;
}
private void UpdateInformationLabel()
{
if (FormConfiguration.IsEnabled)
{
string Label;
if (FormConfiguration.SelectedOperation == Configuration.SelectionOperation.After)
{
Label = Enum.GetName(typeof(Configuration.OperationTypes), FormConfiguration.AfterOperation) + " after " + TimeSpan.FromMinutes(FormConfiguration.TimeAfterOperation).ToString(@"hh\:mm");
}
else
{
Label = Enum.GetName(typeof(Configuration.OperationTypes), FormConfiguration.AtOperation) + " at " + TimeSpan.FromMinutes(FormConfiguration.TimeAtOperation).ToString(@"hh\:mm");
}
InformationLabel.Text = Label.Replace('_', ' ') + " - warning " + (FormConfiguration.IsWarnEnabled ? "enabled" : "disabled");
}
else
{
InformationLabel.Text = "Currently no action scheduled";
}
}
private void ClickActionButton(object sender, EventArgs e)
{
FormConfiguration.IsEnabled = !FormConfiguration.IsEnabled;
UpdateInformationLabel();
if (FormConfiguration.IsEnabled)
{
ChangeAction();
ActionAfterRadioButton.Enabled = ActionAfterComboBox.Enabled = HoursAfterComboBox.Enabled = MinutesAfterComboBox.Enabled = ActionAtRadioButton.Enabled = ActionAtComboBox.Enabled = HoursAtComboBox.Enabled = MinutesAtComboBox.Enabled = WarnCheckBox.Enabled = false;
ActionButton.Text = "Reset";
}
else
{
ChangeAction(false);
ActionAfterRadioButton.Enabled = ActionAfterComboBox.Enabled = HoursAfterComboBox.Enabled = MinutesAfterComboBox.Enabled = ActionAtRadioButton.Enabled = ActionAtComboBox.Enabled = HoursAtComboBox.Enabled = MinutesAtComboBox.Enabled = WarnCheckBox.Enabled = true;
ActionButton.Text = "Set";
}
}
}
}