-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStoreSelectionForm.cs
157 lines (134 loc) · 5.06 KB
/
StoreSelectionForm.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
namespace X509CertificateTool
{
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Security.Cryptography.X509Certificates;
public partial class StoreSelectionForm : Form
{
public StoreSelectionForm()
{
InitializeComponent();
}
bool clicked_OK;
IList<StoreLocation> _availableStoreLocations;
IList<StoreName> _availableStoreNames;
List<StoreLocation> _selectedStoreLocations = new List<StoreLocation>();
List<StoreName> _selectedStoreNames = new List<StoreName>();
public StoreSelectionForm(
IList<StoreLocation> availableStoreLocations,
IList<StoreName> availableStoreNames,
ICollection<StoreLocation> selectedStoreLocations,
ICollection<StoreName> selectedStoreNames,
bool regexMatchCase)
: this()
{
this.storeNamesCheckedListBox.Items.Clear();
for (int i=0; i<availableStoreNames.Count; i++)
{
StoreName sn = availableStoreNames[i];
this.storeNamesCheckedListBox.Items.Add(sn);
this.storeNamesCheckedListBox.SetItemChecked(i,
selectedStoreNames.Contains(sn));
}
this._availableStoreNames = availableStoreNames;
this._selectedStoreNames.AddRange(selectedStoreNames);
this.storeLocationCheckedListBox.Items.Clear();
for (int i = 0; i < availableStoreLocations.Count; i++)
{
StoreLocation sl = availableStoreLocations[i];
this.storeLocationCheckedListBox.Items.Add(sl);
this.storeLocationCheckedListBox.SetItemChecked(i,
selectedStoreLocations.Contains(sl));
}
this._availableStoreLocations = availableStoreLocations;
this._selectedStoreLocations.AddRange(selectedStoreLocations);
this.checkBoxRegexMatchCase.Checked = regexMatchCase;
}
private void setAllSelected(bool selection)
{
for (int i = 0; i < this.storeNamesCheckedListBox.Items.Count; i++)
{
this.storeNamesCheckedListBox.SetItemChecked(i, selection);
}
for (int i = 0; i < this.storeLocationCheckedListBox.Items.Count; i++)
{
this.storeLocationCheckedListBox.SetItemChecked(i, selection);
}
}
private void buttonSelectAll_Click(object sender, EventArgs e)
{
setAllSelected(true);
}
private void buttonOK_Click(object sender, EventArgs e)
{
this.Visible = false;
this.clicked_OK = true;
}
private void button2_Click(object sender, EventArgs e)
{
this.Visible = false;
this.clicked_OK = false;
}
public IList<StoreLocation> StoreLocations
{
get
{
if (clicked_OK)
{
List<StoreLocation> result = new List<StoreLocation>();
foreach (int sli in storeLocationCheckedListBox.CheckedIndices)
{
StoreLocation location = (StoreLocation)storeLocationCheckedListBox.Items[sli];
result.Add(location);
}
return result;
}
else
{
List<StoreLocation> result = new List<StoreLocation>();
foreach (StoreLocation storeLocation in _availableStoreLocations)
{
if (this._selectedStoreLocations.Contains(storeLocation))
{
result.Add(storeLocation);
}
}
return result;
}
}
}
public IList<StoreName> StoreNames
{
get
{
if (clicked_OK)
{
List<StoreName> result = new List<StoreName>();
foreach (int sli in storeNamesCheckedListBox.CheckedIndices)
{
StoreName storeName = (StoreName)storeNamesCheckedListBox.Items[sli];
result.Add(storeName);
}
return result;
}
else
{
List<StoreName> result = new List<StoreName>();
foreach (StoreName storeName in _availableStoreNames)
{
if (this._selectedStoreNames.Contains(storeName))
{
result.Add(storeName);
}
}
return result;
}
}
}
public bool RegexMatchCase
{
get { return this.checkBoxRegexMatchCase.Checked; }
}
}
}