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.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciUserInterface.Forms
11 {
12  public partial class RunControlViewer : Form
13  {
14  private Seci.BlockDictionary _tempBlocks = new Seci.BlockDictionary();
15 
16  private delegate void UpdateGuiDelegate();
17 
19  {
20  InitializeComponent();
21  }
22 
23  private void RunControlViewer_Load(object sender, EventArgs e)
24  {
25  //Disable datagrid sorting
26  foreach (DataGridViewColumn i in dgv1.Columns)
27  {
28  i.SortMode = DataGridViewColumnSortMode.NotSortable;
29  }
30  updateValues();
31  timer1.Start();
32  }
33 
34  private void updateValues()
35  {
36  _tempBlocks = Seci.Managers.BlockMgr.GetBlocksClone();
37 
38  //Main config blocks
39  if (_tempBlocks != null && _tempBlocks.Count > 0)
40  {
41  while (dgv1.Rows.Count > _tempBlocks.Count)
42  {
43  //Need to delete a row
44  dgv1.Rows.RemoveAt(dgv1.Rows.Count - 1);
45  }
46 
47  while (dgv1.Rows.Count < _tempBlocks.Count)
48  {
49  //Need to delete a row
50  dgv1.Rows.Add();
51  }
52 
53  //Now update the values
54  for (int i = 0; i < _tempBlocks.Count; ++i)
55  {
56  Seci.Definitions.BlockInfo temp = _tempBlocks[i];
57 
58  String runstatus = "N/A";
59  String setpoint = "N/A";
60  Color rowColour = Color.Black;
61 
62  if (temp.UnderRunControl)
63  {
64  if (temp.InRange)
65  {
66  runstatus = "True";
67  }
68  else
69  {
70  runstatus = "False";
71  rowColour = Color.Red;
72  }
73  }
74 
75  if (temp.WriteControl != null)
76  {
77  setpoint = temp.SetPointValue;
78  }
79 
80  Seci.Definitions.ControlType type = Seci.Managers.LabViewMgr.GetControlType(temp.ParentVI, temp.ReadControl);
81 
82  if (type == Seci.Definitions.ControlType.STRING || type == Seci.Definitions.ControlType.BOOLEAN)
83  {
84  dgv1.Rows[i].Cells[0].Value = temp.BlockName;
85  dgv1.Rows[i].Cells[1].Value = temp.CurrentValue.Trim() + " " + temp.BlockUnits;
86  dgv1.Rows[i].Cells[2].Value = setpoint;
87  dgv1.Rows[i].Cells[3].Value = temp.UnderRunControl;
88  dgv1.Rows[i].Cells[4].Value = temp.RunControlValue;
89  dgv1.Rows[i].Cells[5].Value = "";
90  dgv1.Rows[i].Cells[6].Value = runstatus;
91  dgv1.Rows[i].DefaultCellStyle.ForeColor = rowColour;
92  }
93  else
94  {
95  dgv1.Rows[i].Cells[0].Value = temp.BlockName;
96  dgv1.Rows[i].Cells[1].Value = temp.CurrentValue.Trim() + " " + temp.BlockUnits;
97  dgv1.Rows[i].Cells[2].Value = setpoint;
98  dgv1.Rows[i].Cells[3].Value = temp.UnderRunControl;
99  dgv1.Rows[i].Cells[4].Value = temp.LowerLimit;
100  dgv1.Rows[i].Cells[5].Value = temp.UpperLimit;
101  dgv1.Rows[i].Cells[6].Value = runstatus;
102  dgv1.Rows[i].DefaultCellStyle.ForeColor = rowColour;
103  }
104  }
105  }
106  else
107  {
108  dgv1.Rows.Clear();
109  }
110  }
111 
112  private void btnSet_Click(object sender, EventArgs e)
113  {
114  if (dgv1.CurrentRow != null)
115  {
116  timer1.Stop();
117  EditRunControl edit = new EditRunControl((Seci.Definitions.BlockInfo)_tempBlocks[dgv1.CurrentRow.Cells[colName.Name].Value.ToString()]);
118  if (edit.ShowDialog() == DialogResult.OK)
119  {
120  _tempBlocks[dgv1.CurrentRow.Cells[colName.Name].Value.ToString()] = edit.Block;
121  Seci.Managers.SeciMgr.PauseThreads();
122  System.Threading.Thread.Sleep(1000);
123 
124  //Copy tempblocks onto main config blocks
125  Seci.Managers.BlockMgr.SetBlocks(_tempBlocks);
126 
127  if (Seci.Definitions.Status.UseDaeMonitorVI)
128  {
129  Seci.Standard.DaeMonitor.WriteBlockList();
130  }
131 
132  //Restart threads
133  Seci.Managers.SeciMgr.ResumeThreads();
134 
135  this.Invoke(new UpdateGuiDelegate(updateValues), null);
136  }
137  timer1.Start();
138  }
139  }
140 
141  private void btnClose_Click(object sender, EventArgs e)
142  {
143  this.Close();
144  }
145 
146  private void timer1_Tick(object sender, EventArgs e)
147  {
148  if (!backgroundWorker1.IsBusy)
149  {
150  backgroundWorker1.RunWorkerAsync();
151  }
152  }
153 
154  private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
155  {
156  this.Invoke(new UpdateGuiDelegate(updateValues), null);
157  }
158 
159  private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
160  {
161 
162  }
163 
164  private void dgv1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
165  {
166  btnSet_Click(sender, e);
167  }
168 
169 
170 
171  }
172 }
This class is used for storing the information for any blocks that are created and provides methods f...
Definition: BlockInfo.cs:18
Seci.Definitions.BlockInfo Block
void btnSet_Click(object sender, EventArgs e)
void dgv1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
void timer1_Tick(object sender, EventArgs e)
void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
void btnClose_Click(object sender, EventArgs e)
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
void RunControlViewer_Load(object sender, EventArgs e)