2 using System.Collections.Generic;
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;
15 namespace SeciUserInterface.Dialogs.Alerts
25 ObservableCollection<BlockEntry> blockCollection =
new ObservableCollection<BlockEntry>();
26 ObservableCollection<UserEntry> userCollection =
new ObservableCollection<UserEntry>();
30 InitializeComponent();
37 if (Alerts.WaitingStateAlert != null && Alerts.WaitingStateAlert.DelayBeforeSms != null)
39 chkWaiting.IsChecked =
true;
40 txtTime.Text = Alerts.WaitingStateAlert.DelayBeforeSms.TotalMinutes.ToString();
43 if (Alerts.BlockLimitsAlerts != null)
45 foreach (var alert
in Alerts.BlockLimitsAlerts)
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);
52 if (PhoneNumbers != null)
54 for (
int i = 0; i < PhoneNumbers.Numbers.Count; ++i)
56 userCollection.Add(
new UserEntry(PhoneNumbers.Numbers[i].Name, PhoneNumbers.Numbers[i].Number));
61 dgBlocks.ItemsSource = blockCollection;
62 dgReceivers.ItemsSource = userCollection;
68 if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
76 if (dgBlocks.SelectedIndex != -1)
78 BlockEntry temp = blockCollection[dgBlocks.SelectedIndex];
80 edit.Block = temp.Name;
81 edit.OldLow = temp.LowLimit;
82 edit.OldHigh = temp.HighLimit;
84 if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
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();
91 dgBlocks.ItemsSource = blockCollection;
98 if (dgBlocks.SelectedIndex != -1)
100 blockCollection.RemoveAt(dgBlocks.SelectedIndex);
108 if (chkWaiting.IsChecked ==
true)
111 if (Int32.TryParse(txtTime.Text, out limit))
113 newAlerts.SetWaitingStateAlert(
new TimeSpan(0, limit, 0));
117 MessageBox.Show(
"The time to wait must be an integer");
121 if (Alerts.WaitingStateAlert != null && Alerts.WaitingStateAlert.DelayBeforeSms != null && !String.IsNullOrEmpty(Alerts.WaitingStateAlert.OwningConfiguration))
123 if (Alerts.WaitingStateAlert.DelayBeforeSms != newAlerts.WaitingStateAlert.DelayBeforeSms)
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");
132 newAlerts.WaitingStateAlert = null;
137 String block = row.Name;
138 String config = row.Configuration.ToLower();
142 if (newAlerts.BlockLimitsAlerts.ContainsKey(block))
144 MessageBox.Show(
"Blocks can only have one entry - the block " + block +
" has more than one entry.");
148 if (!Double.TryParse(row.
LowLimit.ToString(), out low))
150 MessageBox.Show(
"The low limit for " + block +
" must be numeric");
154 if (!Double.TryParse(row.
HighLimit.ToString(), out high))
156 MessageBox.Show(
"The high limit for " + block +
" must be numeric");
160 newAlerts.AddBlockAlert(block, row.Type, low, high, row.Enabled);
161 newAlerts.BlockLimitsAlerts[block.ToLower()].OwningConfiguration = config;
166 foreach (
UserEntry user
in userCollection)
168 PhoneNumbers.Add(user.Name, user.Number);
179 DialogResult =
false;
186 add.Owner = Window.GetWindow(
this);
188 if (add.ShowDialog() ==
true)
196 if (dgReceivers.SelectedIndex != -1)
198 userCollection.RemoveAt(dgReceivers.SelectedIndex);
Interaction logic for AddUser.xaml