Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SearchForThingsDialog.xaml.cs
1using System;
2using System.Collections.Generic;
3using System.Windows;
4using System.Windows.Controls;
5
7{
8 public enum Operator
9 {
10 Equality = 0,
11 NonEquality = 1,
12 GreaterThan = 2,
13 GreaterThanOrEqualTo = 3,
14 LesserThan = 4,
15 LesserThanOrEqualTo = 5,
16 InRange = 6,
17 NotInRange = 7,
18 Wildcard = 8,
19 RegularExpression = 9
20 }
21
22 public class Rule
23 {
24 public string Tag;
25 public Operator Operator;
26 public string Value1;
27 public string Value2;
28 }
29
33 public partial class SearchForThingsDialog : Window
34 {
35 private int nrRules = 1;
36 private int ruleNr = 1;
37
42 {
44
45 this.Field1.Focus();
46 }
47
48 private void OkButton_Click(object Sender, RoutedEventArgs e)
49 {
50 this.DialogResult = true;
51 }
52
53 private void CancelButton_Click(object Sender, RoutedEventArgs e)
54 {
55 this.DialogResult = false;
56 }
57
58 private void AddButton_Click(object Sender, RoutedEventArgs e)
59 {
60 string Suffix = (++this.ruleNr).ToString();
61
62 StackPanel Panel = new StackPanel()
63 {
64 Orientation = Orientation.Horizontal,
65 Margin = new Thickness(0, 0, 0, 8)
66 };
67
68 ComboBox Field = new ComboBox()
69 {
70 Name = "Field" + Suffix,
71 Width = 150,
72 IsEditable = true,
73 ToolTip = "Select field to searh on."
74 };
75
76 Field.Items.Add(new ComboBoxItem() { Tag = "ALT", Content = "Altitude (ALT)" });
77 Field.Items.Add(new ComboBoxItem() { Tag = "APT", Content = "Apartment (APT)" });
78 Field.Items.Add(new ComboBoxItem() { Tag = "AREA", Content = "Area (AREA)" });
79 Field.Items.Add(new ComboBoxItem() { Tag = "BLD", Content = "Building (BLD)" });
80 Field.Items.Add(new ComboBoxItem() { Tag = "CITY", Content = "City (CITY)" });
81 Field.Items.Add(new ComboBoxItem() { Tag = "CLASS", Content = "Class (CLASS)" });
82 Field.Items.Add(new ComboBoxItem() { Tag = "COUNTRY", Content = "Country (COUNTRY)" });
83 Field.Items.Add(new ComboBoxItem() { Tag = "LAT", Content = "Latitude (LAT)" });
84 Field.Items.Add(new ComboBoxItem() { Tag = "LONG", Content = "Longitude (LONG)" });
85 Field.Items.Add(new ComboBoxItem() { Tag = "MAN", Content = "Manufacturer (MAN)" });
86 Field.Items.Add(new ComboBoxItem() { Tag = "MLOC", Content = "Meter Location (MLOC)" });
87 Field.Items.Add(new ComboBoxItem() { Tag = "MNR", Content = "Meter Number (MNR)" });
88 Field.Items.Add(new ComboBoxItem() { Tag = "MODEL", Content = "Model (MODEL)" });
89 Field.Items.Add(new ComboBoxItem() { Tag = "NAME", Content = "Name (NAME)" });
90 Field.Items.Add(new ComboBoxItem() { Tag = "PURL", Content = "Product URL (PURL)" });
91 Field.Items.Add(new ComboBoxItem() { Tag = "REGION", Content = "Region (REGION)" });
92 Field.Items.Add(new ComboBoxItem() { Tag = "ROOM", Content = "Room (ROOM)" });
93 Field.Items.Add(new ComboBoxItem() { Tag = "SN", Content = "Serial Number (SN)" });
94 Field.Items.Add(new ComboBoxItem() { Tag = "STREET", Content = "Street (STREET)" });
95 Field.Items.Add(new ComboBoxItem() { Tag = "STREETNR", Content = "Street Number (STREETNR)" });
96 Field.Items.Add(new ComboBoxItem() { Tag = "V", Content = "Version (V)" });
97
98 StackPanel Panel2 = new StackPanel()
99 {
100 Orientation = Orientation.Vertical
101 };
102
103 Panel2.Children.Add(new Label() { Content = "Tag:" });
104 Panel2.Children.Add(Field);
105 Panel.Children.Add(Panel2);
106
107 ComboBox Operator = new ComboBox()
108 {
109 Name = "Operator" + Suffix,
110 Width = 184,
111 ToolTip = "Select search operator.",
112 SelectedIndex = 0
113 };
114
115 Operator.Items.Add(new ComboBoxItem() { Tag = "=", Content = "Equality (=)" });
116 Operator.Items.Add(new ComboBoxItem() { Tag = "<>", Content = "Non-equality (<>)" });
117 Operator.Items.Add(new ComboBoxItem() { Tag = ">", Content = "Greater than (>)" });
118 Operator.Items.Add(new ComboBoxItem() { Tag = ">=", Content = "Greater than or equal to (>=)" });
119 Operator.Items.Add(new ComboBoxItem() { Tag = "<", Content = "Lesser than (<)" });
120 Operator.Items.Add(new ComboBoxItem() { Tag = "<=", Content = "Lesser than or equal to (<=)" });
121 Operator.Items.Add(new ComboBoxItem() { Tag = "InRange", Content = "In range" });
122 Operator.Items.Add(new ComboBoxItem() { Tag = "NotInRange", Content = "Not in range" });
123 Operator.Items.Add(new ComboBoxItem() { Tag = "Wildcard", Content = "Wildcard" });
124 Operator.Items.Add(new ComboBoxItem() { Tag = "RegularExpression", Content = "Regular Expression" });
125
126 Operator.SelectionChanged += this.Operator_SelectionChanged;
127
128 Panel2 = new StackPanel()
129 {
130 Orientation = Orientation.Vertical,
131 Margin = new Thickness(16, 0, 0, 0)
132 };
133
134 Panel2.Children.Add(new Label() { Content = "Operator:" });
135 Panel2.Children.Add(Operator);
136 Panel.Children.Add(Panel2);
137
138 TextBox Value1 = new TextBox()
139 {
140 Name = "Value" + Suffix + "_1",
141 Width = 184,
142 ToolTip = "Select value to search on.",
143 Height = this.Operator1.ActualHeight
144 };
145
146 TextBox Value2 = new TextBox()
147 {
148 Name = "Value" + Suffix + "_2",
149 Width = 84,
150 ToolTip = "Select value to search to.",
151 Height = this.Operator1.ActualHeight
152 };
153
154 Panel2 = new StackPanel()
155 {
156 Orientation = Orientation.Vertical,
157 Margin = new Thickness(16, 0, 0, 0)
158 };
159
160 Panel.Children.Add(Panel2);
161
162 StackPanel Panel3 = new StackPanel()
163 {
164 Orientation = Orientation.Horizontal,
165 Width = 184
166 };
167
168 Panel2.Children.Add(Panel3);
169
170 StackPanel Panel4 = new StackPanel()
171 {
172 Orientation = Orientation.Vertical
173 };
174
175 Panel3.Children.Add(Panel4);
176
177 Panel4.Children.Add(new Label() { Content = "Value:" });
178 Panel4.Children.Add(Value1);
179
180 Panel4 = new StackPanel()
181 {
182 Orientation = Orientation.Vertical,
183 Visibility = Visibility.Hidden,
184 Margin = new Thickness(16, 0, 0, 0)
185 };
186
187 Panel3.Children.Add(Panel4);
188
189 Panel4.Children.Add(new Label() { Content = "To:" });
190 Panel4.Children.Add(Value2);
191
192 Panel2 = new StackPanel()
193 {
194 Orientation = Orientation.Vertical,
195 Margin = new Thickness(16, 0, 0, 0),
196 VerticalAlignment = VerticalAlignment.Bottom
197 };
198
199 Button Delete = new Button()
200 {
201 Name = "Delete" + Suffix,
202 Width = 80,
203 Height = this.Operator1.ActualHeight,
204 Padding = new Thickness(-10),
205 Content = "Delete",
206 Tag = this.ruleNr
207 };
208
209 Delete.Click += this.Delete_Click;
210
211 Panel2.Children.Add(Delete);
212 Panel.Children.Add(Panel2);
213
214 this.SearchFields.Children.Add(Panel);
215 this.nrRules++;
216 }
217
218 private void Delete_Click(object Sender, RoutedEventArgs e)
219 {
220 if (this.nrRules <= 1)
221 {
222 MessageBox.Show(this, "At least one rule must exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
223 return;
224 }
225
226 Button Button = (Button)Sender;
227 StackPanel Rule = (StackPanel)(((StackPanel)Button.Parent).Parent);
228 ((StackPanel)Rule.Parent).Children.Remove(Rule);
229
230 this.nrRules--;
231 }
232
233 public Rule[] GetRules()
234 {
235 List<Rule> Result = new List<Rule>();
236
237 foreach (StackPanel Rule in this.SearchFields.Children)
238 {
239 StackPanel Panel1 = (StackPanel)Rule.Children[0];
240 StackPanel Panel2 = (StackPanel)Rule.Children[1];
241 StackPanel Panel3 = (StackPanel)Rule.Children[2];
242 StackPanel Panel3_1 = (StackPanel)Panel3.Children[0];
243 StackPanel Panel3_1_1 = (StackPanel)Panel3_1.Children[0];
244 StackPanel Panel3_1_2 = (StackPanel)Panel3_1.Children[1];
245 ComboBox Field = (ComboBox)Panel1.Children[1];
246 ComboBox Operator = (ComboBox)Panel2.Children[1];
247 TextBox Value1 = (TextBox)Panel3_1_1.Children[1];
248 TextBox Value2 = (TextBox)Panel3_1_2.Children[1];
249 string TagName;
250
251 TagName = Field.Text;
252 foreach (ComboBoxItem Item in Field.Items)
253 {
254 if (TagName == Item.Content.ToString())
255 {
256 TagName = Item.Tag.ToString();
257 break;
258 }
259 }
260
261 Result.Add(new Dialogs.IoT.Rule()
262 {
263 Tag = TagName,
264 Operator = (Operator)Operator.SelectedIndex,
265 Value1 = Value1.Text,
266 Value2 = Value2.Text
267 });
268 }
269
270 return Result.ToArray();
271 }
272
273 private void Operator_SelectionChanged(object Sender, SelectionChangedEventArgs e)
274 {
275 ComboBox Op = (ComboBox)Sender;
276 Operator Op2 = (Operator)Op.SelectedIndex;
277 StackPanel Panel = (StackPanel)(Op.Parent);
278 StackPanel Rule = (StackPanel)(Panel.Parent);
279 if (Rule.Children.Count < 3)
280 return; // Building form.
281
282 StackPanel Value = (StackPanel)(Rule.Children[2]);
283 StackPanel Values = (StackPanel)(Value.Children[0]);
284 StackPanel Value1Panel = (StackPanel)(Values.Children[0]);
285 StackPanel Value2Panel = (StackPanel)(Values.Children[1]);
286 Label Value1Label = (Label)(Value1Panel.Children[0]);
287 TextBox Value1 = (TextBox)(Value1Panel.Children[1]);
288
289 if (Op2 == Operator.InRange || Op2 == Operator.NotInRange)
290 {
291 Value1Label.Content = "From:";
292 Value1.Width = 84;
293 Value1.ToolTip = "Select value to search from.";
294 Value2Panel.Visibility = Visibility.Visible;
295 }
296 else
297 {
298 Value1Label.Content = "Value:";
299 Value1.Width = 184;
300 Value2Panel.Visibility = Visibility.Hidden;
301
302 switch (Op2)
303 {
304 case Operator.Wildcard:
305 Value1.ToolTip = "Select value to search on. Use asterisks (*) as wildcards.";
306 break;
307
308 case Operator.RegularExpression:
309 Value1.ToolTip = "Select regular expression to search on.";
310 break;
311
312 default:
313 Value1.ToolTip = "Select value to search on.";
314 break;
315 }
316 }
317 }
318 }
319}
Interaction logic for SearchForThingsDialog.xaml
SearchForThingsDialog()
Interaction logic for SearchForThingsDialog.xaml
VerticalAlignment
Vertical alignment
Definition: Cell.cs:35