forked from Ken98045/On-Guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerAreaNotificationOptionsDialog.cs
280 lines (235 loc) · 7.99 KB
/
PerAreaNotificationOptionsDialog.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeepStackDisplay
{
public partial class NotificationOptionsDialog : Form
{
readonly AreaOfInterest _area;
public NotificationOptionsDialog(AreaOfInterest area)
{
_area = area;
InitializeComponent();
int count = 0;
foreach (var url in area.Notifications.Urls)
{
ListViewItem urlItem = new ListViewItem(new string[] { url.Url, url.CoolDown.CooldownTime.ToString() });
urlsList.Items.Add(urlItem);
urlItem.Checked = url.Active;
urlItem.Tag = url;
++count;
}
count = 0;
foreach (var option in area.Notifications.Email)
{
ListViewItem emailItem = new ListViewItem(new string[] { option.EmailAddress, option.CoolDown.CooldownTime.ToString() });
emailsList.Items.Add(emailItem);
emailItem.Tag = option;
emailItem.Checked = option.Active;
++count;
}
if (emailsList.Items.Count > 0)
{
emailsList.Items[0].Selected = true;
emailsList.Select();
}
if (urlsList.Items.Count > 0)
{
urlsList.Items[0].Selected = true;
urlsList.Select();
}
}
private void OkButton_Click(object sender, EventArgs e)
{
_area.Notifications.Email.Clear();
_area.Notifications.Urls.Clear();
foreach (ListViewItem url in urlsList.Items)
{
UrlOptions option = (UrlOptions)url.Tag;
option.Active = url.Checked;
option.Url = url.Text;
_area.Notifications.Urls.Add(option);
}
foreach (ListViewItem email in emailsList.Items)
{
EmailOptions option = (EmailOptions)email.Tag;
option.Active = email.Checked;
option.EmailAddress = email.Text;
_area.Notifications.Email.Add(option);
}
DialogResult = DialogResult.OK;
}
private void CancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void AddUrlButton_Click(object sender, EventArgs e)
{
using (AddUrlDialog dlg = new AddUrlDialog())
{
if (dlg.ShowDialog() == DialogResult.OK)
{
UrlOptions opt = new UrlOptions(dlg.Url, dlg.CoolDown);
opt.Active = true;
ListViewItem item = new ListViewItem(new string [] { dlg.Url, dlg.CoolDown.ToString()})
{
Checked = true
};
item.Tag = opt; // we don't really track changes here because there is nothing to track, but....
urlsList.Items.Add(item);
int index = item.Index;
urlsList.Items[index].Tag = new UrlOptions(opt.Url,opt.CoolDown.CooldownTime);
urlsList.Items[index].Focused = true;
urlsList.Items[index].Selected = true;
}
}
}
private void RemoveUrlButton_Click(object sender, EventArgs e)
{
if (!(urlsList.SelectedIndices.Count > 0))
{
MessageBox.Show("You must select a row in order to delete it");
}
else
{
_area.Notifications.Urls.RemoveAt(urlsList.SelectedIndices[0]);
urlsList.Items.RemoveAt(urlsList.SelectedIndices[0]);
}
}
private void AddEmailButton_Click(object sender, EventArgs e)
{
using (AddEmailDlg dlg = new AddEmailDlg())
{
if (dlg.ShowDialog() == DialogResult.OK)
{
EmailOptions options = new EmailOptions(dlg.EmailAddress, dlg.CooldownTime) // We do need to track changes here because each email has numerous properties
{
EndTime = new DateTime(2020, 1, 1, 23, 59, 59),
StartTime = new DateTime(2020, 1, 1, 0, 0, 0),
Active = true,
NumberOfImages = 1
};
_area.Notifications.Email.Add(options);
ListViewItem item = new ListViewItem(new string[] { dlg.EmailAddress, dlg.CooldownTime.ToString() });
emailsList.Items.Add(item);
int index = item.Index;
emailsList.Items[index].Tag = options;
emailsList.Items[index].Focused = true;
emailsList.Items[index].Selected = true;
SetEmailControls(options);
item.Checked = true;
emailsList.Select();
}
}
}
void SetEmailControls(EmailOptions opt)
{
numberOfImages.Value = opt.NumberOfImages;
check247.Checked = opt.AllTheTime;
fromTime.Value = opt.StartTime; ;
toTime.Value = opt.EndTime;
for (int i = 0; i < 7; i++)
{
daysOfWeekList.SetItemChecked(i, opt.DaysOfWeek[i]);
}
sizeImageToNumeric.Value = opt.SizeDownToPercent;
}
private void RemoveEmailButton_Click(object sender, EventArgs e)
{
if (!(emailsList.SelectedIndices.Count > 0))
{
MessageBox.Show("You must select a row in order to delete it");
}
else
{
_area.Notifications.Email.RemoveAt(emailsList.SelectedIndices[0]);
emailsList.Items.RemoveAt(emailsList.SelectedIndices[0]);
}
}
private void Check247_Checked(object sender, EventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
if (check247.Checked)
{
for (int i = 0; i < 7; i++)
{
daysOfWeekList.SetItemChecked(i, true);
}
}
_area.Notifications.Email[emailsList.SelectedIndices[0]].AllTheTime = check247.Checked;
}
}
private void bs_CurrentChanged(object sender, EventArgs e)
{
}
private void SelectionChanged(object sender, EventArgs e)
{
if (emailsList.SelectedItems.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.SelectedItems[0].Tag; // to avoid clutter
SetEmailControls(opt);
}
}
private void OnItemCheckChanged(object sender, ItemCheckEventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
if (emailsList.SelectedIndices.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.Items[emailsList.SelectedIndices[0]].Tag;
if (e.NewValue == CheckState.Checked)
{
opt.DaysOfWeek[e.Index] = true;
}
else
{
opt.DaysOfWeek[e.Index] = false;
check247.Checked = false; // can't be 24/7 if we aren't 7
}
}
}
}
private void FromTime_ValueChanged(object sender, EventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.Items[emailsList.SelectedIndices[0]].Tag;
opt.StartTime = fromTime.Value;
check247.Checked = false; // can't be 24/7 if we aren't 24
}
}
private void ToTime_ValueChanged(object sender, EventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.Items[emailsList.SelectedIndices[0]].Tag;
opt.EndTime = toTime.Value;
check247.Checked = false; // can't be 24/7 if we aren't 24
}
}
private void NumberOfImages_ValueChanged(object sender, EventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.Items[emailsList.SelectedIndices[0]].Tag;
opt.NumberOfImages = (int)numberOfImages.Value;
}
}
private void SizeImageToNumeric_ValueChanged(object sender, EventArgs e)
{
if (emailsList.SelectedIndices.Count > 0)
{
EmailOptions opt = (EmailOptions)emailsList.Items[emailsList.SelectedIndices[0]].Tag;
opt.SizeDownToPercent = (int)sizeImageToNumeric.Value;
}
}
}
}