SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
AddEditGroup.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace Sample_Environment_Control_Interface.Dialogs.Layout.Groups
11 {
12  public partial class AddEditGroup : Form
13  {
14  public Group myGroup;
15 
16  private List<String> _fullVINames = new List<String>(); //Keeps list of all VI names
17  private List<String> _fullProgNames; //Keeps list of all programme names
18 
19  public AddEditGroup()
20  {
21  InitializeComponent();
22  }
23 
24  public AddEditGroup(Group grp)
25  {
26  InitializeComponent();
27 
28  myGroup = grp;
29  }
30 
31  private void AddEditGroup_Load(object sender, EventArgs e)
32  {
33  //Get list of config VIs + beamlogger
34  _fullVINames.AddRange(Seci.SeciInterface.LV_GetListOfVIs());
35  _fullVINames.Add(Seci.SeciInterface.BeamLogger_GetLocation());
36 
37  //Get list of programmes
38  _fullProgNames = Seci.SeciInterface.Exe_GetListOfAllExes();
39  _fullProgNames.Add("Open Genie");
40 
41  PopulateLists();
42 
43  if (myGroup != null)
44  {
45  txtName.Text = myGroup.GroupName;
46 
47  //Get members of group
48  for (int i = 0; i < myGroup.VIMembers.GetLength(0); ++i)
49  {
50  String vi = myGroup.VIMembers[i].Substring(myGroup.VIMembers[i].LastIndexOf("\\") + 1);
51  lstVIMembers.Items.Add(vi);
52  lstVIs.Items.Remove(vi);
53  }
54 
55  for (int i = 0; i < myGroup.ProgMembers.GetLength(0); ++i)
56  {
57  String prog = myGroup.ProgMembers[i].Substring(myGroup.ProgMembers[i].LastIndexOf("\\") + 1);
58  lstProgMembers.Items.Add(prog);
59  lstProgs.Items.Remove(prog);
60  }
61  }
62  }
63 
64  private void PopulateLists()
65  {
66 
67  for (int i = 0; i < _fullVINames.Count; ++i)
68  {
69  lstVIs.Items.Add(_fullVINames[i].Substring(_fullVINames[i].LastIndexOf("\\") + 1));
70  }
71 
72  for (int i = 0; i < _fullProgNames.Count; ++i)
73  {
74  lstProgs.Items.Add(_fullProgNames[i].Substring(_fullProgNames[i].LastIndexOf("\\") + 1));
75  }
76  }
77 
78  private void btnAddVI_Click(object sender, EventArgs e)
79  {
80  if (lstVIs.SelectedIndex != -1)
81  {
82  lstVIMembers.Items.Add(lstVIs.SelectedItem);
83  lstVIs.Items.RemoveAt(lstVIs.SelectedIndex);
84  }
85  }
86 
87  private void btnAddProg_Click(object sender, EventArgs e)
88  {
89  if (lstProgs.SelectedIndex != -1)
90  {
91  lstProgMembers.Items.Add(lstProgs.SelectedItem);
92  lstProgs.Items.RemoveAt(lstProgs.SelectedIndex);
93  }
94  }
95 
96  private void btnRemoveVI_Click(object sender, EventArgs e)
97  {
98  if (lstVIMembers.SelectedIndex != -1)
99  {
100  lstVIs.Items.Add(lstVIMembers.SelectedItem);
101  lstVIMembers.Items.RemoveAt(lstVIMembers.SelectedIndex);
102  }
103  }
104 
105  private void btnRemoveProg_Click(object sender, EventArgs e)
106  {
107  if (lstProgMembers.SelectedIndex != -1)
108  {
109  lstProgs.Items.Add(lstProgMembers.SelectedItem);
110  lstProgMembers.Items.RemoveAt(lstProgMembers.SelectedIndex);
111  }
112  }
113 
114 
115  private void btnOK_Click(object sender, EventArgs e)
116  {
117  if (txtName.Text.Trim() != "")
118  {
119  if (!SECI_GUI.CurrentLayout.GroupExists(txtName.Text.Trim()) || txtName.Text.Trim().ToUpper() == myGroup.GroupName.ToUpper())
120  {
121 
122  Group newgrp = new Group(txtName.Text.Trim());
123 
124  for (int i = 0; i < lstVIMembers.Items.Count; ++i)
125  {
126  String fullname = GetVIFullname(lstVIMembers.Items[i].ToString());
127 
128  if (fullname != null)
129  {
130  newgrp.AddVIMember(fullname);
131  }
132  }
133 
134  for (int i = 0; i < lstProgMembers.Items.Count; ++i)
135  {
136  String fullname = GetProgFullname(lstProgMembers.Items[i].ToString());
137 
138  if (fullname != null)
139  {
140  newgrp.AddProgMember(fullname);
141  }
142  }
143 
144  myGroup = newgrp;
145 
146  DialogResult = DialogResult.OK;
147  Close();
148  }
149  else
150  {
151  MessageBox.Show("Page name is not unique! Please change it to something else.", "Name Not Unique!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
152  }
153  }
154  else
155  {
156  MessageBox.Show("Please enter a page name.", "No Name Given!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
157  }
158  }
159 
160  private String GetVIFullname(String shortname)
161  {
162  for (int i = 0; i < _fullVINames.Count; ++i)
163  {
164  if (_fullVINames[i].EndsWith(shortname))
165  {
166  return _fullVINames[i];
167  }
168  }
169 
170  return null;
171  }
172 
173  private String GetProgFullname(String shortname)
174  {
175  for (int i = 0; i < _fullProgNames.Count; ++i)
176  {
177  if (_fullProgNames[i].EndsWith(shortname))
178  {
179  return _fullProgNames[i];
180  }
181  }
182 
183  return null;
184  }
185 
186 
187  }
188 }