SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
SetNexusInfo.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 SetNexusInfo : Form
12  {
13  //Temporary dictionary to contain the blocks
15 
17 
18  public SetNexusInfo()
19  {
20  InitializeComponent();
21  }
22 
23  private void SetNexusInfo_Load(object sender, EventArgs e)
24  {
25  //Disable datagrid sorting
26  foreach (DataGridViewColumn i in dataGridView1.Columns)
27  {
28  i.SortMode = DataGridViewColumnSortMode.NotSortable;
29  }
30 
31  //Add blocks to table
32  if (blocksNexus != null)
33  {
34  for (int i = 0; i < blocksNexus.Count; ++i)
35  {
36  dataGridView1.Rows.Add(blocksNexus[i].BlockName, blocksNexus[i].NexusName, blocksNexus[i].NexusGroup, false);
37  }
38  }
39 
40  //Add component blocks to table - these are read only.
41  if (compsBlocksNexus != null)
42  {
43  for (int i = 0; i < compsBlocksNexus.GetLength(0); ++i)
44  {
45  for (int j = 0; j < compsBlocksNexus[i].Count; ++j)
46  {
47  dataGridView1.Rows.Add(compsBlocksNexus[i][j].BlockName, compsBlocksNexus[i][j].NexusName, compsBlocksNexus[i][j].NexusGroup, true);
48  dataGridView1.Rows[dataGridView1.Rows.Count - 1].ReadOnly = true;
49  }
50  }
51  }
52 
53  //Add the NeXus group list
54  ((DataGridViewComboBoxColumn) dataGridView1.Columns["colNexusGroup"]).Items.AddRange(Seci.SeciInterface.SeciStatus.NexusGroups);
55  }
56 
57  private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
58  {
59  //check neXus name is unique
60  if ((dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["colNexusName"]) || (dataGridView1.CurrentCell == dataGridView1.CurrentRow.Cells["colNexusGroup"]))
61  {
62  if ((dataGridView1.CurrentRow.Cells["colNexusName"].Value != null)&&(dataGridView1.CurrentRow.Cells["colNexusGroup"].Value != null))
63  {
64  String name = dataGridView1.CurrentRow.Cells["colNexusName"].Value.ToString();
65  String group = dataGridView1.CurrentRow.Cells["colNexusGroup"].Value.ToString();
66 
67  for (int i = 0; i < dataGridView1.Rows.Count; ++i)
68  {
69  if ((i != dataGridView1.CurrentRow.Index)&&(dataGridView1.Rows[i].Cells["colNexusName"].Value != null)&&(dataGridView1.Rows[i].Cells["colNexusGroup"] != null))
70  {
71  if ((dataGridView1.Rows[i].Cells["colNexusName"].Value.ToString() == name) && (dataGridView1.Rows[i].Cells["colNexusGroup"].Value.ToString() == group))
72  {
73  MessageBox.Show("NeXus names must be unique within their group - please change this name!", "Not Unique", MessageBoxButtons.OK, MessageBoxIcon.Error);
74  dataGridView1.CurrentRow.Cells["colNexusName"].Value = "";
75  }
76  }
77  }
78 
79  }
80  }
81  }
82 
83  private void btnOK_Click(object sender, EventArgs e)
84  {
85  Boolean IsOkay = true;
86 
87  if (blocksNexus !=null)
88  {
89  for (int i = 0; i < blocksNexus.Count; ++i)
90  {
91  if (dataGridView1.Rows[i].Cells["colNexusName"].Value.ToString() != "")
92  {
93  if (dataGridView1.Rows[i].Cells["colNexusGroup"].Value != null)
94  {
95  blocksNexus[i].NexusName = dataGridView1.Rows[i].Cells["colNexusName"].Value.ToString();
96  blocksNexus[i].NexusGroup = dataGridView1.Rows[i].Cells["colNexusGroup"].Value.ToString();
97  }
98  else
99  {
100  MessageBox.Show("A corresponding NeXus group must be chosen for each NeXus name", "No NeXus Group Chosen!", MessageBoxButtons.OK, MessageBoxIcon.Error);
101  IsOkay = false;
102  }
103  }
104  }
105  }
106 
107  if (IsOkay)
108  {
109  DialogResult = DialogResult.OK;
110  Close();
111  }
112  }
113 
114 
115  }
116 }
void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
Definition: SetNexusInfo.cs:57
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...