forked from Ken98045/On-Guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailAddressesDialog.cs
85 lines (76 loc) · 2.25 KB
/
EmailAddressesDialog.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace SAAI
{
public partial class EmailAddressesDialog : Form
{
List<EmailOptions> Options { get; }
public EmailAddressesDialog(List<EmailOptions> options)
{
InitializeComponent();
Options = options;
foreach (EmailOptions option in Options)
{
ListViewItem item = emailAddressList.Items.Add(option.EmailAddress);
item.Tag = option;
}
}
private void OKButton_Click(object sender, EventArgs e)
{
Options.Clear();
foreach (ListViewItem item in emailAddressList.Items)
{
Options.Add((EmailOptions)item.Tag);
}
DialogResult = DialogResult.OK;
}
private void CancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void AddButton_Click(object sender, EventArgs e)
{
using (CreateEmailAddressDialog dlg = new CreateEmailAddressDialog())
{
DialogResult result = dlg.ShowDialog();
if (result == DialogResult.OK)
{
ListViewItem item = new ListViewItem(dlg.Email.EmailAddress)
{
Tag = dlg.Email
};
emailAddressList.Items.Add(item);
}
}
}
private void EditButton_Click(object sender, EventArgs e)
{
using (CreateEmailAddressDialog dlg = new CreateEmailAddressDialog((EmailOptions)emailAddressList.Items[emailAddressList.SelectedIndices[0]].Tag))
{
DialogResult result = dlg.ShowDialog();
if (result == DialogResult.OK)
{
emailAddressList.Items[emailAddressList.SelectedIndices[0]].Tag = dlg.Email;
}
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
emailAddressList.Items.RemoveAt(emailAddressList.SelectedIndices[0]);
}
private void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (emailAddressList.SelectedIndices.Count > 0)
{
EditButton.Enabled = true;
DeleteButton.Enabled = true;
}
else
{
EditButton.Enabled = false;
DeleteButton.Enabled = false;
}
}
}
}