SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
MessagesControl.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.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciControls
11 {
12  public partial class MessagesControl : UserControl
13  {
14  //Set up event and delegates for stopping/starting error thread while a question is asked
16  public delegate void QuestionHandler();
17 
19 
20 
21  public MessagesControl()
22  {
24  }
25 
26  private void MessagesControl_Load(object sender, EventArgs e)
27  {
28  //Disable datagrid sorting
29  foreach (DataGridViewColumn column in dgv1.Columns)
30  {
31  column.SortMode = DataGridViewColumnSortMode.NotSortable;
32  }
33  }
34 
35  public void ClearMessages()
36  {
37  dgv1.Rows.Clear();
38  }
39 
40  public void RemoveAllErrorMessages()
41  {
42  //Only remove error messages, not questions!
43 
44  for (int i = 0; i < dgv1.RowCount; ++i)
45  {
46  //Check it is not a question
47  if (dgv1.Rows[i].Cells[0].Value.ToString() != "True")
48  {
49  //Reply with acknowledged
50  Seci.Standard.MessageQueue.SendReply(dgv1.Rows[i].Cells["colMessage"].Value.ToString(), dgv1.Rows[i].Cells["colSource"].Value.ToString(), true);
51  }
52  }
53  }
54 
55  public void AddMessages(Seci.SerialisableList<Seci.Standard.MessageInfo> messages)
56  {
57  //Clear messages
58  dgv1.Rows.Clear();
59 
60  for (int i = 0; i < messages.Count; ++i)
61  {
62 
63  //if wait for response = true then it is a question, else is an error
64  Boolean question;
65  String type = "";
66 
67  //There is a hidden column called Question, which is used to check whether the row,
68  //double clicked on is a question or an error.
69 
70  //And there are two hidden columns called yes and no which contain what should be
71  //written on the question buttons
72 
73  if (messages[i].WaitForResponse)
74  {
75  //Question
76  question = true;
77  type = "Question";
78  }
79  else
80  {
81  //Error
82  question = false;
83  type = "Error";
84  }
85 
86  dgv1.Rows.Insert(0, question, type, messages[i].TimeAdded.ToShortDateString(), messages[i].TimeAdded.ToShortTimeString(), messages[i].Count ,messages[i].VIName, messages[i].Message, messages[i].YesText, messages[i].NoText);
87  }
88  }
89 
90  public void ShowSelectedMessage()
91  {
92  if (dgv1.CurrentRow != null)
93  {
94  dgv1_CellDoubleClick(null, null);
95  }
96  }
97 
98  private void dgv1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
99  {
100  if (dgv1.CurrentRow != null)
101  {
102  //Stop Error thread
103  if (OnQuestionAsked != null)
104  {
105  OnQuestionAsked();
106  }
107 
108  //See if user double clicked on a question
109  if (dgv1.CurrentRow.Cells[0].Value.ToString() == "True")
110  {
111  int rownum = dgv1.CurrentRow.Index;
112 
113  //It is a question, so pop up message box.
114  String question = "Source: " + dgv1.Rows[rownum].Cells["colSource"].Value.ToString() + Environment.NewLine + Environment.NewLine + dgv1.Rows[rownum].Cells["colMessage"].Value.ToString();
115  Generic_PopUp popup = new Generic_PopUp("Question", question, dgv1.Rows[rownum].Cells["colYes"].Value.ToString(), dgv1.Rows[rownum].Cells["colNo"].Value.ToString());
116  if (popup.ShowDialog() == DialogResult.Yes)
117  {
118  //Answered in the positive
119  Seci.Standard.MessageQueue.SendReply(dgv1.Rows[rownum].Cells["colMessage"].Value.ToString(), dgv1.Rows[rownum].Cells["colSource"].Value.ToString(), true);
120  }
121  else
122  {
123  //Answered in the negative
124  Seci.Standard.MessageQueue.SendReply(dgv1.Rows[rownum].Cells["colMessage"].Value.ToString(), dgv1.Rows[rownum].Cells["colSource"].Value.ToString(), false);
125  }
126  }
127  else
128  {
129  int rownum = dgv1.CurrentRow.Index;
130 
131  //It is an error message, so pop up message box.
132  String message = "Source: " + dgv1.Rows[rownum].Cells["colSource"].Value.ToString() + Environment.NewLine + Environment.NewLine + dgv1.Rows[rownum].Cells["colMessage"].Value.ToString();
133  Generic_PopUp popup = new Generic_PopUp("LabVIEW Message", message, "Delete", "Cancel");
134  if (popup.ShowDialog() == DialogResult.Yes)
135  {
136  //Remove the message
137  Seci.Standard.MessageQueue.SendReply(dgv1.Rows[rownum].Cells["colMessage"].Value.ToString(), dgv1.Rows[rownum].Cells["colSource"].Value.ToString(), true);
138  }
139  }
140 
141  //Restart Error thread
142  if (OnQuestionAnswered != null)
143  {
145  }
146  }
147  }
148 
149 
150  }
151 }
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...
delegate void QuestionHandler()
void MessagesControl_Load(object sender, EventArgs e)
System.Windows.Forms.DataGridView dgv1
QuestionHandler OnQuestionAnswered
void dgv1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
void AddMessages(Seci.SerialisableList< Seci.Standard.MessageInfo > messages)