2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
8 using System.Windows.Forms;
11 namespace SeciUserInterface.Dialogs.Blocks
15 private Boolean _changesMade =
false;
16 private Boolean _canEditSubBlocks =
false;
18 public Boolean CanEditSubBlocks { set { _canEditSubBlocks = value; } }
19 public List<string> GroupOrder =
new List<string>();
23 InitializeComponent();
29 foreach (DataGridViewColumn i
in dgv1.Columns)
31 i.SortMode = DataGridViewColumnSortMode.NotSortable;
35 if (BlocksCopy == null)
41 GroupOrder =
new List<string>();
43 for (
int i = 0; i < Seci.Managers.BlockMgr.Groups.Count; ++i)
45 GroupOrder.Add(Seci.Managers.BlockMgr.Groups[i].Name);
55 DataGridViewComboBoxColumn groups = (DataGridViewComboBoxColumn)dgv1.Columns[
"colGroup"];
65 for (
int i = 0; i < Seci.Managers.BlockMgr.Groups.Count; ++i)
67 groups.Items.Add(Seci.Managers.BlockMgr.Groups[i].Name);
73 if (BlocksCopy != null)
75 for (
int i = 0; i < BlocksCopy.Count; ++i)
79 if (String.IsNullOrEmpty(temp.Group))
88 type = Seci.Managers.LabViewMgr.GetControlType(temp.ParentVI, temp.ReadControl);
94 type = Seci.Definitions.ControlType.NUMERIC;
97 if (type == Seci.Definitions.ControlType.BOOLEAN || type == Seci.Definitions.ControlType.STRING)
99 dgv1.Rows.Add(temp.BlockName, temp.BlockUnits, temp.OwningComponent,
100 temp.ParentVI.Substring(temp.ParentVI.LastIndexOf(
'\\') + 1),
101 temp.UnderRunControl, temp.RunControlValue,
"",
102 temp.BlockEnabled, temp.Group);
106 dgv1.Rows.Add(temp.BlockName, temp.BlockUnits, temp.OwningComponent,
107 temp.ParentVI.Substring(temp.ParentVI.LastIndexOf(
'\\') + 1),
108 temp.UnderRunControl, temp.LowerLimit, temp.UpperLimit,
109 temp.BlockEnabled, temp.Group);
118 addBlock.Dictionary = BlocksCopy;
120 if (addBlock.ShowDialog() == DialogResult.OK)
130 if (dgv1.CurrentRow != null)
135 getSelectedRow(out selectedRow, out selectedColumn, out selected);
138 editBlock.Dictionary = BlocksCopy;
143 if (dgv1.CurrentRow.Cells[2].Value == null || _canEditSubBlocks)
145 if (editBlock.ShowDialog() == DialogResult.OK)
150 setSelectedRow(selectedRow, selectedColumn, selected);
155 MessageBox.Show(
"The selected Block is part of a sub-configuration - any changes made will not be saved."
156 ,
"Editing Sub-configuration Block", MessageBoxButtons.OK, MessageBoxIcon.Warning);
157 editBlock.IsComponent =
true;
159 if (editBlock.ShowDialog() == DialogResult.OK)
163 setSelectedRow(selectedRow, selectedColumn, selected);
169 private void getSelectedRow(out
int selectedRow, out
int selectedColumn, out
bool selected)
175 if (dgv1.CurrentRow != null)
177 selected = dgv1.CurrentRow.Selected;
178 selectedRow = dgv1.CurrentRow.Index;
179 selectedColumn = dgv1.CurrentCell.ColumnIndex;
185 if (dgv1.Rows.Count > selectedRow && dgv1.Rows.Count > 0 && selectedRow >= 0)
189 dgv1.CurrentCell = dgv1.Rows[selectedRow].Cells[selectedColumn];
190 dgv1.CurrentRow.Selected = selected;
194 dgv1.CurrentCell = dgv1.Rows[selectedRow].Cells[selectedColumn];
201 if (dgv1.CurrentRow != null)
204 if (dgv1.CurrentRow.Cells[2].Value == null || _canEditSubBlocks)
207 if (dgv1.CurrentRow != null)
209 BlocksCopy.Remove(dgv1.CurrentRow.Cells[colName.Name].Value.ToString());
210 dgv1.Rows.RemoveAt(dgv1.CurrentRow.Index);
216 MessageBox.Show(
"The selected block cannot be deleted as it is part of a sub-configuration."
217 ,
"Cannot delete component block", MessageBoxButtons.OK, MessageBoxIcon.Warning);
243 DialogResult = DialogResult.OK;
247 DialogResult = DialogResult.Cancel;
257 if (dgv1.CurrentRow.Cells[2].Value != null && dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colGroup"] && !_canEditSubBlocks)
259 MessageBox.Show(
"The selected block cannot be edited as it is part of a component. However, the run-control settings can be changed via the table."
260 ,
"Cannot edit component block", MessageBoxButtons.OK, MessageBoxIcon.Warning);
261 dgv1.CurrentRow.Cells[
"colGroup"].Value = ((
Seci.Definitions.BlockInfo)BlocksCopy[dgv1.CurrentRow.Cells[colName.Name].Value.ToString()]).Group;
265 doChanges((Seci.Definitions.BlockInfo)BlocksCopy[dgv1.CurrentRow.Cells[colName.Name].Value.ToString()]);
268 private void doChanges(Seci.Definitions.BlockInfo block)
275 type = Seci.Managers.LabViewMgr.GetControlType(block.ParentVI, block.ReadControl);
279 type = Seci.Definitions.ControlType.NUMERIC;
282 if (dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colRuncontrol"])
284 block.UnderRunControl = (bool)dgv1.CurrentRow.Cells[
"colRuncontrol"].Value;
286 else if (dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colLower"])
288 if (type == Seci.Definitions.ControlType.STRING || type == Seci.Definitions.ControlType.BOOLEAN)
290 bool underRunControl = (bool)dgv1.CurrentRow.Cells[
"colRuncontrol"].Value;
291 string lowerLimit = dgv1.CurrentRow.Cells[
"colLower"].Value.ToString();
292 block.SetRunControlLimits(underRunControl, lowerLimit);
296 setLimits(block,
true);
299 else if (dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colUpper"])
301 if (type == Seci.Definitions.ControlType.STRING || type == Seci.Definitions.ControlType.BOOLEAN)
307 setLimits(block,
false);
310 else if (dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colEnabled"])
312 block.BlockEnabled = (bool)dgv1.CurrentRow.Cells[
"colEnabled"].Value;
314 else if (dgv1.CurrentCell == dgv1.CurrentRow.Cells[
"colGroup"])
316 block.Group = dgv1.CurrentRow.Cells[
"colGroup"].Value.ToString();
322 private void setLimits(Seci.Definitions.BlockInfo block, Boolean lowchanged)
326 String low = dgv1.CurrentRow.Cells[
"colLower"].Value.ToString();
327 String high = dgv1.CurrentRow.Cells[
"colUpper"].Value.ToString();
329 low = CheckForInfinity(low);
330 high = CheckForInfinity(high);
332 double lowerLimit = Convert.ToDouble(low);
333 double upperLimit = Convert.ToDouble(high);
334 bool underRunControl = (bool)dgv1.CurrentRow.Cells[
"colRuncontrol"].Value;
335 block.SetRunControlLimits(underRunControl, lowerLimit, upperLimit);
339 MessageBox.Show(
"Invalid value enter; value reset to previous value.",
"Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
342 dgv1.CurrentRow.Cells[
"colLower"].Value = block.LowerLimit;
346 dgv1.CurrentRow.Cells[
"colUpper"].Value = block.UpperLimit;
353 if (value.ToLower() ==
"inf" || value.ToLower() ==
"infinity")
355 value = Double.PositiveInfinity.ToString();
358 if (value.ToLower() ==
"-inf" || value.ToLower() ==
"-infinity")
360 value = Double.NegativeInfinity.ToString();
367 if (dgv1.CurrentRow.Index > 0)
369 int oldIndex = dgv1.CurrentRow.Index;
370 BlocksCopy.Swap(dgv1.CurrentRow.Index, dgv1.CurrentRow.Index - 1);
372 dgv1.CurrentCell = dgv1.Rows[oldIndex - 1].Cells[0];
379 if (dgv1.CurrentRow.Index < dgv1.Rows.Count - 1)
381 int oldIndex = dgv1.CurrentRow.Index;
382 BlocksCopy.Swap(dgv1.CurrentRow.Index, dgv1.CurrentRow.Index + 1);
384 dgv1.CurrentCell = dgv1.Rows[oldIndex + 1].Cells[0];
393 if (add.ShowDialog() == DialogResult.OK)
395 if (!Seci.Managers.BlockMgr.BlockGroupExists(add.
GroupName))
397 DataGridViewComboBoxColumn groups = (DataGridViewComboBoxColumn)dgv1.Columns[
"colGroup"];
399 GroupOrder.Add(add.GroupName);
407 ord.Order = GroupOrder;
409 if (ord.ShowDialog() == DialogResult.OK)
412 GroupOrder = ord.Order;
This class is used for storing the information for any blocks that are created and provides methods f...
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...