SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
LabVIEW_Errors.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Text;
7 using System.Windows.Forms;
8 
9 namespace Sample_Environment_Control_Interface.Dialogs.Messages
10 {
11  public partial class LabView_Errors : UserControl
12  {
13  //Set up event and delegates for stopping/starting error thread while a question is asked
14  public event QuestionHandler QuestionAsked;
15  public delegate void QuestionHandler();
16 
17  public event QuestionHandler QuestionAnswered;
18 
19  public LabView_Errors()
20  {
21  InitializeComponent();
22  }
23 
24  private void LabView_Errors_Load(object sender, EventArgs e)
25  {
26  //Disable datagrid sorting
27  foreach (DataGridViewColumn i in dataGridView1.Columns)
28  {
29  i.SortMode = DataGridViewColumnSortMode.NotSortable;
30  }
31  }
32 
33  public void addMessages(Seci.SerialisableList<Seci.LabView.MessageInfo> messages)
34  {
35  //Clear messages
36  dataGridView1.Rows.Clear();
37 
38  for (int i = 0; i < messages.Count; ++i)
39  {
40 
41  //if wait for response = true then it is a question, else is an error
42  Image img;
43  Boolean question;
44 
45  //There is a hidden column called Question, which is used to check whether the row,
46  //double clicked on is a question or an error.
47 
48  //And there are two hidden columns called yes and no which contain what should be
49  //written on the question buttons
50 
51  if (messages[i].WaitForResponse)
52  {
53  //Question
54  img = Sample_Environment_Control_Interface.Properties.Resources.LabView_Question.ToBitmap();
55  question = true;
56  }
57  else
58  {
59  //Error
60  img = Sample_Environment_Control_Interface.Properties.Resources.LabView_Error.ToBitmap();
61  question = false;
62  }
63 
64  dataGridView1.Rows.Insert(0, img, question, messages[i].TimeAdded.ToShortDateString(), messages[i].TimeAdded.ToShortTimeString(), messages[i].VIName, messages[i].Message, messages[i].YesText, messages[i].NoText);
65  }
66  }
67 
68  private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
69  {
70  if (dataGridView1.CurrentRow != null)
71  {
72  //Stop Error thread
73  QuestionAsked();
74 
75  //See it user double clicked on a question
76  if (dataGridView1.CurrentRow.Cells[1].Value.ToString() == "True")
77  {
78  int rownum = dataGridView1.CurrentRow.Index;
79 
80  //It is a question, so pop up message box.
81  String question = "Source: " + dataGridView1.Rows[rownum].Cells[4].Value.ToString() + Environment.NewLine + Environment.NewLine + dataGridView1.Rows[rownum].Cells[5].Value.ToString();
82  Generic_PopUp popup = new Generic_PopUp("Question", question, dataGridView1.Rows[rownum].Cells[6].Value.ToString(), dataGridView1.Rows[rownum].Cells[7].Value.ToString());
83  if (popup.ShowDialog() == DialogResult.Yes)
84  {
85  //Answered in the positive
86  Seci.SeciInterface.LVQ_SendReply(dataGridView1.Rows[rownum].Cells[5].Value.ToString(), dataGridView1.Rows[rownum].Cells[4].Value.ToString(), true);
87  }
88  else
89  {
90  //Answered in the negative
91  Seci.SeciInterface.LVQ_SendReply(dataGridView1.Rows[rownum].Cells[5].Value.ToString(), dataGridView1.Rows[rownum].Cells[4].Value.ToString(), false);
92  }
93  }
94  else
95  {
96  int rownum = dataGridView1.CurrentRow.Index;
97 
98  //It is an error message, so pop up message box.
99  String message = "Source: " + dataGridView1.Rows[rownum].Cells[4].Value.ToString() + Environment.NewLine + Environment.NewLine + dataGridView1.Rows[rownum].Cells[5].Value.ToString();
100  Generic_PopUp popup = new Generic_PopUp("LabVIEW Message", message, "Delete", "Cancel");
101  if (popup.ShowDialog() == DialogResult.Yes)
102  {
103  //Remove the message
104  Seci.SeciInterface.LVQ_SendReply(dataGridView1.Rows[rownum].Cells[5].Value.ToString(), dataGridView1.Rows[rownum].Cells[4].Value.ToString(), true);
105  }
106  }
107 
108  //Restart Error thread
109  QuestionAnswered();
110  }
111 
112  }
113 
114 
115  }
116 }
void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
void addMessages(Seci.SerialisableList< Seci.LabView.MessageInfo > messages)