SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
ConfigureAlertSystem.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Shapes;
13 using System.Collections.ObjectModel;
14 
15 namespace SeciUserInterface.Dialogs.Alerts
16 {
20  public partial class ConfigureAlertSystem : Window
21  {
24 
25  ObservableCollection<BlockEntry> blockCollection = new ObservableCollection<BlockEntry>();
26  ObservableCollection<UserEntry> userCollection = new ObservableCollection<UserEntry>();
27 
29  {
30  InitializeComponent();
31  }
32 
33  private void Window_Loaded(object sender, RoutedEventArgs e)
34  {
35  if (Alerts != null)
36  {
37  if (Alerts.WaitingStateAlert != null && Alerts.WaitingStateAlert.DelayBeforeSms != null)
38  {
39  chkWaiting.IsChecked = true;
40  txtTime.Text = Alerts.WaitingStateAlert.DelayBeforeSms.TotalMinutes.ToString();
41  }
42 
43  if (Alerts.BlockLimitsAlerts != null)
44  {
45  foreach (var alert in Alerts.BlockLimitsAlerts)
46  {
47  BlockEntry block = new BlockEntry(alert.Value.Blockname, alert.Value.BlockType, alert.Value.LowLimit.ToString(), alert.Value.HighLimit.ToString(), true, alert.Value.OwningConfiguration);
48  blockCollection.Add(block);
49  }
50  }
51 
52  if (PhoneNumbers != null)
53  {
54  for (int i = 0; i < PhoneNumbers.Numbers.Count; ++i)
55  {
56  userCollection.Add(new UserEntry(PhoneNumbers.Numbers[i].Name, PhoneNumbers.Numbers[i].Number));
57  }
58  }
59  }
60 
61  dgBlocks.ItemsSource = blockCollection;
62  dgReceivers.ItemsSource = userCollection;
63  }
64 
65  private void btnAddRule_Click(object sender, RoutedEventArgs e)
66  {
67  AddAlert add = new AddAlert();
68  if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
69  {
70  blockCollection.Add(new BlockEntry(add.Block, add.BlockType, add.Low, add.High, true, ""));
71  }
72  }
73 
74  private void btnEditRule_Click(object sender, RoutedEventArgs e)
75  {
76  if (dgBlocks.SelectedIndex != -1)
77  {
78  BlockEntry temp = blockCollection[dgBlocks.SelectedIndex];
79  AddAlert edit = new AddAlert();
80  edit.Block = temp.Name;
81  edit.OldLow = temp.LowLimit;
82  edit.OldHigh = temp.HighLimit;
83 
84  if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
85  {
86  blockCollection[dgBlocks.SelectedIndex].Name = edit.Block;
87  blockCollection[dgBlocks.SelectedIndex].Type = edit.BlockType.ToString();
88  blockCollection[dgBlocks.SelectedIndex].LowLimit = edit.Low.ToString();
89  blockCollection[dgBlocks.SelectedIndex].HighLimit = edit.High.ToString();
90 
91  dgBlocks.ItemsSource = blockCollection;
92  }
93  }
94  }
95 
96  private void btnDeleteRule_Click(object sender, RoutedEventArgs e)
97  {
98  if (dgBlocks.SelectedIndex != -1)
99  {
100  blockCollection.RemoveAt(dgBlocks.SelectedIndex);
101  }
102  }
103 
104  private void btnOk_Click(object sender, RoutedEventArgs e)
105  {
106  Seci.Tools.AlertsBox newAlerts = new Seci.Tools.AlertsBox();
107 
108  if (chkWaiting.IsChecked == true)
109  {
110  Int32 limit;
111  if (Int32.TryParse(txtTime.Text, out limit))
112  {
113  newAlerts.SetWaitingStateAlert(new TimeSpan(0, limit, 0));
114  }
115  else
116  {
117  MessageBox.Show("The time to wait must be an integer");
118  return;
119  }
120 
121  if (Alerts.WaitingStateAlert != null && Alerts.WaitingStateAlert.DelayBeforeSms != null && !String.IsNullOrEmpty(Alerts.WaitingStateAlert.OwningConfiguration))
122  {
123  if (Alerts.WaitingStateAlert.DelayBeforeSms != newAlerts.WaitingStateAlert.DelayBeforeSms)
124  {
125  newAlerts.WaitingStateAlert.OwningConfiguration = null;
126  MessageBox.Show("The waiting time was originally set in a sub-configuration - the change will not be overwritten in the sub-configuration");
127  }
128  }
129  }
130  else
131  {
132  newAlerts.WaitingStateAlert = null;
133  }
134 
135  foreach (BlockEntry row in blockCollection)
136  {
137  String block = row.Name;
138  String config = row.Configuration.ToLower();
139  Double low;
140  Double high;
141 
142  if (newAlerts.BlockLimitsAlerts.ContainsKey(block))
143  {
144  MessageBox.Show("Blocks can only have one entry - the block " + block + " has more than one entry.");
145  return;
146  }
147 
148  if (!Double.TryParse(row.LowLimit.ToString(), out low))
149  {
150  MessageBox.Show("The low limit for " + block + " must be numeric");
151  return;
152  }
153 
154  if (!Double.TryParse(row.HighLimit.ToString(), out high))
155  {
156  MessageBox.Show("The high limit for " + block + " must be numeric");
157  return;
158  }
159 
160  newAlerts.AddBlockAlert(block, row.Type, low, high, row.Enabled);
161  newAlerts.BlockLimitsAlerts[block.ToLower()].OwningConfiguration = config;
162  }
163 
164  PhoneNumbers = new Seci.Tools.PhoneNumbersList();
165 
166  foreach (UserEntry user in userCollection)
167  {
168  PhoneNumbers.Add(user.Name, user.Number);
169  }
170 
171  Alerts = newAlerts;
172 
173  DialogResult = true;
174  Close();
175  }
176 
177  private void btnCancel_Click(object sender, RoutedEventArgs e)
178  {
179  DialogResult = false;
180  Close();
181  }
182 
183  private void btnAddUser_Click(object sender, RoutedEventArgs e)
184  {
185  AddUser add = new AddUser();
186  add.Owner = Window.GetWindow(this);
187 
188  if (add.ShowDialog() == true)
189  {
190  userCollection.Add(new UserEntry(add.Name, add.Number));
191  }
192  }
193 
194  private void btnDeleteUser_Click(object sender, RoutedEventArgs e)
195  {
196  if (dgReceivers.SelectedIndex != -1)
197  {
198  userCollection.RemoveAt(dgReceivers.SelectedIndex);
199  }
200  }
201  }
202 }
void btnDeleteUser_Click(object sender, RoutedEventArgs e)
void btnDeleteRule_Click(object sender, RoutedEventArgs e)
Interaction logic for ConfigureAlertSystem.xaml
void btnEditRule_Click(object sender, RoutedEventArgs e)
Interaction logic for AddUser.xaml
Definition: AddUser.xaml.cs:20