SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
RunControlViewer.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 
9 namespace Sample_Environment_Control_Interface.Dialogs.Blocks
10 {
11  public partial class RunControlViewer : Form
12  {
13  //Temporay dictionary to contain the configs blocks
14  private Seci.BlockDictionary tempBlocks = new Seci.BlockDictionary();
15 
17  {
18  InitializeComponent();
19  }
20 
21  private void RunControlViewer_Load(object sender, EventArgs e)
22  {
23  //Disable datagrid sorting
24  foreach (DataGridViewColumn i in dataGridView1.Columns)
25  {
26  i.SortMode = DataGridViewColumnSortMode.NotSortable;
27  }
28 
29  if (Seci.SeciInterface.SeciStatus.UseDaeMonitorVi)
30  {
31  Seci.SeciInterface.DAEMonitor_GetRunControlSettings();
32  }
33 
34  //Copy/clone current config blocks on to tempblocks
35  tempBlocks = (Seci.BlockDictionary)Seci.SeciInterface.Blocks.Clone();
36 
37  //Check if tempblocks is null, i.e. no blocks in config
38  if (tempBlocks == null)
39  {
40  //declare new instance
41  tempBlocks = new Seci.BlockDictionary();
42  }
43 
44  initialiseDataGrid();
45 
46  timer1.Start();
47  }
48 
49  private void initialiseDataGrid()
50  {
51  dataGridView1.Rows.Clear();
52 
53  //Main config blocks
54  if (tempBlocks != null)
55  {
56  for (int i = 0; i < tempBlocks.Count; ++i)
57  {
58  //See if out of range - true = out of range
59  Boolean OutofRange = Seci.SeciInterface.Blocks[i].OutOfRange();
60  String InRange = "True";
61 
62  //Need to reverse sense to get in range
63  if (OutofRange)
64  {
65  InRange = "False";
66  }
67 
68  //Check to see if block is enabled - if not don't bother about the range and current value
69  if (Seci.SeciInterface.Blocks[i].BlockEnabled)
70  {
71  dataGridView1.Rows.Add(tempBlocks[i].BlockName, tempBlocks[i].UnderRunControl,
72  tempBlocks[i].LowerLimit, tempBlocks[i].UpperLimit,
73  tempBlocks[i].CurrentValue, InRange, "N/A");
74  }
75  else
76  {
77  dataGridView1.Rows.Add(tempBlocks[i].BlockName, tempBlocks[i].UnderRunControl,
78  tempBlocks[i].LowerLimit, tempBlocks[i].UpperLimit,
79  "N/A", "N/A", "N/A");
80  }
81  }
82  }
83 
84  dataGridView1.Sort(dataGridView1.Columns["colBlock"], ListSortDirection.Ascending);
85  }
86 
87  private void updateDataGrid()
88  {
89  int rowCount = 0;
90 
91  //Main config blocks
92  if (tempBlocks != null)
93  {
94 
95  for (int i = 0; i < dataGridView1.Rows.Count; ++i)
96  {
97  //Check to see if block is enabled - if not don't bother about the range or value
98  if (Seci.SeciInterface.Blocks[dataGridView1.Rows[i].Cells["colBlock"].Value.ToString()].BlockEnabled)
99  {
100  //Update the current value
101  dataGridView1.Rows[i].Cells["colRunControl"].Value = Seci.SeciInterface.Blocks[dataGridView1.Rows[i].Cells["colBlock"].Value.ToString()].UnderRunControl;
102 
103  dataGridView1.Rows[i].Cells["colCurrent"].Value = Seci.SeciInterface.Blocks[dataGridView1.Rows[i].Cells["colBlock"].Value.ToString()].CurrentValue;
104 
105  //See if out of range - true = out of range
106  Boolean OutofRange = Seci.SeciInterface.Blocks[dataGridView1.Rows[i].Cells["colBlock"].Value.ToString()].OutOfRange();
107  String InRange = "True";
108 
109  //Need to reverse sense to get in range
110  if (OutofRange)
111  {
112  InRange = "False";
113  }
114  dataGridView1.Rows[i].Cells["colInRange"].Value = InRange;
115  }
116  else
117  {
118  dataGridView1.Rows[i].Cells["colCurrent"].Value = "N/A";
119  dataGridView1.Rows[i].Cells["colInRange"].Value = "N/A";
120  }
121 
122  rowCount++;
123  }
124  }
125 
126  }
127 
128 
129  //Values changed
130  private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
131  {
132  doChanges(tempBlocks[dataGridView1.CurrentRow.Cells["colBlock"].Value.ToString()]);
133  }
134 
135  private void doChanges(Seci.BlockInfo block)
136  {
137 
138  //make changes to run-control, visibility and enabled only
139  if (dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["colRunControl"])
140  {
141  block.UnderRunControl = (bool)dataGridView1.CurrentRow.Cells["colRunControl"].Value;
142  }
143  else if (dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["colLower"])
144  {
145  try
146  {
147  block.LowerLimit = Convert.ToDouble(dataGridView1.CurrentRow.Cells["colLower"].Value);
148  }
149  catch
150  {
151  MessageBox.Show("Invalid value enter; value rest to previous value.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
152  dataGridView1.CurrentRow.Cells["colLower"].Value = block.LowerLimit;
153  }
154  }
155  else if (dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["colUpper"])
156  {
157  try
158  {
159  block.UpperLimit = Convert.ToDouble(dataGridView1.CurrentRow.Cells["colUpper"].Value);
160  }
161  catch
162  {
163  MessageBox.Show("Invalid value enter; value rest to previous value.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
164  dataGridView1.CurrentRow.Cells["colUpper"].Value = block.UpperLimit;
165  }
166 
167  }
168  }
169 
170  private void btnOK_Click(object sender, EventArgs e)
171  {
172  //Check lower is Lower and Upper is Upper, if not then swap
173  for (int i = 0; i < tempBlocks.Count; ++i)
174  {
175  if (tempBlocks[i].LowerLimit > tempBlocks[i].UpperLimit)
176  {
177  //Swap
178  double temp = tempBlocks[i].LowerLimit;
179  tempBlocks[i].LowerLimit = tempBlocks[i].UpperLimit;
180  tempBlocks[i].UpperLimit = temp;
181  }
182  }
183 
184  //Copy tempblocks onto main config blocks
185  Seci.SeciInterface.Blocks = tempBlocks;
186 
187  timer1.Stop();
188 
189  if (Seci.SeciInterface.SeciStatus.UseDaeMonitorVi)
190  {
191  Seci.SeciInterface.DAEMonitor_SetBlocks();
192  }
193 
194  DialogResult = DialogResult.OK;
195  Close();
196  }
197 
198  private void timer1_Tick(object sender, EventArgs e)
199  {
200  updateDataGrid();
201  }
202 
203  private void btnCancel_Click(object sender, EventArgs e)
204  {
205  timer1.Stop();
206  DialogResult = DialogResult.Cancel;
207  Close();
208  }
209 
210 
211  }
212 }
void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...