Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientManagement/HeuristicLab.Services.Authentication/UserInterface/UserInterface.cs @ 4695

Last change on this file since 4695 was 4695, checked in by fruehrli, 14 years ago

#1197
commit completed

File size: 14.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Collections;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.Linq;
8using System.Text;
9using System.Windows.Forms;
10using AM = HeuristicLab.Services.Authentication.AdminMethods;
11
12namespace HeuristicLab.Services.Authentication.UserInterface {
13  public partial class Form1 : Form {
14    public AM.ClientAdmin clientAdmin = null;
15    public AM.GroupAdmin groupAdmin = null;
16
17    public Form1() {
18      InitializeComponent();
19      clientAdmin = new AM.ClientAdmin();
20      groupAdmin = new AM.GroupAdmin();
21    }
22
23//******************************************************************************
24//    tab client
25//******************************************************************************
26    // copies values of textboxes into hashtable
27    private Hashtable GetResourceCollection() {
28      Hashtable ht = new Hashtable();
29      ht.Add(AM.eResource.ResourceID, (string)tbResourceID.Text);
30      ht.Add(AM.eResource.Name, (string)tbName.Text);
31      ht.Add(AM.eResource.Description, (string)tbDescription.Text);
32      ht.Add(AM.eResource.ResourceType, (string)tbResourceType.Text);
33      ht.Add(AM.eResource.ProcessorType, (string)tbProcessorType.Text);
34      ht.Add(AM.eResource.NumberOfProcessors, (string)tbNumberOfProcessors.Text);
35      ht.Add(AM.eResource.NumberOfThreads, (string)tbNumberOfThreads.Text);
36      ht.Add(AM.eResource.IPAdress, (string)tbIPAdress.Text);
37      ht.Add(AM.eResource.MemorySize, (string)tbMemorySize.Text);
38      ht.Add(AM.eResource.OperatingSystem, (string)tbOperatingSystem.Text);
39      ht.Add(AM.eResource.ResourceIDGroup, (string)tbResourceGroupID.Text);
40      ht.Add(AM.eResource.ResourceNameGroup, (string)tbResourceGroupName.Text);
41      return ht;
42    }
43
44    private void FillForm(Hashtable ht) {
45      tbResourceID.Text = (string)ht[AM.eResource.ResourceID];
46      tbName.Text = (string)ht[AM.eResource.Name];
47      tbDescription.Text = (string)ht[AM.eResource.Description];
48      tbResourceID.Text = (string)ht[AM.eResource.ResourceType];
49      tbProcessorType.Text = (string)ht[AM.eResource.ProcessorType];
50      tbNumberOfProcessors.Text = (string)ht[AM.eResource.NumberOfProcessors];
51      tbNumberOfThreads.Text = (string)ht[AM.eResource.NumberOfThreads];
52      tbIPAdress.Text = (string)ht[AM.eResource.IPAdress];
53      tbMemorySize.Text = (string)ht[AM.eResource.MemorySize];
54      tbOperatingSystem.Text = (string)ht[AM.eResource.OperatingSystem];
55      tbResourceGroupID.Text = (string)ht[AM.eResource.ResourceIDGroup];
56      tbResourceGroupName.Text = (string)ht[AM.eResource.ResourceNameGroup];
57      cbResourceGroup.Text = "";
58    }
59
60    private void DeselectResourceListCells() {
61      foreach (DataGridViewCell c in this.ResourceList.SelectedCells) {
62        c.Selected = false;
63      }
64    }
65
66    private void ClearTextBoxes() {
67      Hashtable empty = new Hashtable();
68      FillForm(empty);
69    }
70
71    private void AddRowToResourceList(Hashtable ht, int r){     
72      ResourceList.Rows[r].Cells[0].Value = ht[AM.eResource.ResourceID];
73      ResourceList.Rows[r].Cells[1].Value = (string)ht[AM.eResource.Name];
74      ResourceList.Rows[r].Cells[2].Value = (string)ht[AM.eResource.ResourceType];
75      ResourceList.Rows[r].Cells[3].Value = (string)ht[AM.eResource.Description];
76      ResourceList.Rows[r].Cells[4].Value = (string)ht[AM.eResource.IPAdress];
77      ResourceList.Rows[r].Cells[5].Value = (string)ht[AM.eResource.NumberOfProcessors];
78      ResourceList.Rows[r].Cells[6].Value = (string)ht[AM.eResource.NumberOfThreads];
79      ResourceList.Rows[r].Cells[7].Value = (string)ht[AM.eResource.MemorySize];
80      ResourceList.Rows[r].Cells[8].Value = (string)ht[AM.eResource.OperatingSystem];
81      ResourceList.Rows[r].Cells[9].Value = (string)ht[AM.eResource.ResourceNameGroup];
82      ResourceList.Rows[r].Cells[10].Value = ht[AM.eResource.ResourceIDGroup];       
83    }
84
85    // insert results of search in ResourceList
86    private void FillResultList(HashSet<Hashtable> hs) {
87      ResourceList.Rows.Clear();
88      ResourceList.ColumnCount = 11;
89      int r = 0;
90      foreach (Hashtable ht in hs) {
91        ResourceList.Rows.Add();
92        AddRowToResourceList(ht, r);
93        r++;
94      }
95      ResourceList.Refresh();
96    }
97
98    private void Search() {
99      DeselectResourceListCells();
100      Hashtable ht = GetResourceCollection();
101      HashSet<Hashtable> reshs = clientAdmin.Get(ht);
102      //HashSet<Hashtable> reshs = AM.AdminMethods.GetClient(ht);
103      // empty textboxes
104      ClearTextBoxes();
105      if (reshs != null) {
106        FillResultList(reshs);
107      }
108    }
109
110    private Hashtable GenerateClient() {
111      Hashtable ht = new Hashtable();
112      ht.Add(AM.eResource.ResourceID, "");
113      ht.Add(AM.eResource.Name, "cl Name");
114      ht.Add(AM.eResource.Description, "descr");
115      ht.Add(AM.eResource.ResourceType, "");
116      ht.Add(AM.eResource.ProcessorType, "Amd");
117      ht.Add(AM.eResource.NumberOfProcessors, "4");
118      ht.Add(AM.eResource.NumberOfThreads, "2");
119      ht.Add(AM.eResource.IPAdress, "192.168.1.2");
120      ht.Add(AM.eResource.MemorySize, "4096");
121      ht.Add(AM.eResource.OperatingSystem, "WinXP");
122      //ht.Add(AM.eResource.ResourceGroup, "");
123      return ht;
124    }
125
126    private void GetGroupIDandName(ref string id, ref string name) {
127      string selectedGroup = (string)cbResourceGroup.SelectedItem;
128      char[] seperator = {'('};
129      char []trimSpaces = {' '};
130      char []trimEntPara = {')'};
131
132      string[] splitText = selectedGroup.Split(seperator);
133      name = splitText[0].TrimEnd(trimSpaces);
134      id = splitText[1].TrimEnd(trimEntPara);
135    }
136
137    // get clients selected by textboxvalues
138    private void btSearchClient_Click(object sender, EventArgs e) {     
139      Search();
140    }
141
142    // when click on a cell the values of current row will be copied into textboxes
143    private void ResourceList_CellClick(object sender, DataGridViewCellEventArgs e) {
144      int r = e.RowIndex; //selected row
145      tbResourceID.Text = ResourceList.Rows[r].Cells[0].Value.ToString();
146      tbName.Text = ResourceList.Rows[r].Cells[1].Value.ToString();
147      tbResourceType.Text = ResourceList.Rows[r].Cells[2].Value.ToString();
148      tbDescription.Text = ResourceList.Rows[r].Cells[3].Value.ToString();
149      tbIPAdress.Text = ResourceList.Rows[r].Cells[4].Value.ToString();
150      tbNumberOfProcessors.Text = ResourceList.Rows[r].Cells[5].Value.ToString();
151      tbNumberOfThreads.Text = ResourceList.Rows[r].Cells[6].Value.ToString();
152      tbMemorySize.Text = ResourceList.Rows[r].Cells[7].Value.ToString();
153      tbOperatingSystem.Text = ResourceList.Rows[r].Cells[8].Value.ToString();
154      tbResourceGroupName.Text = ResourceList.Rows[r].Cells[9].Value.ToString();
155      tbResourceGroupID.Text = ResourceList.Rows[r].Cells[10].Value.ToString();
156    }
157
158    // get ResourceGroup
159    private void cbResourceGroup_Click(object sender, EventArgs e) {
160      cbResourceGroup.Items.Clear();
161      Hashtable ht = new Hashtable(); // GetResourceGroupCollection();
162      HashSet<Hashtable> reshs = groupAdmin.Get(ht);
163      foreach (Hashtable resht in reshs) {
164        cbResourceGroup.Items.Add((string)resht[AM.eResource.Name] + "    (" + resht[AM.eResource.ResourceID] + ")");
165      }
166    }
167   
168    private void cbResourceGroup_SelectedIndexChanged(object sender, EventArgs e) {
169      string id = "";
170      string name = "";
171      GetGroupIDandName(ref id, ref name);
172      tbResourceGroupName.Text = name;
173      tbResourceGroupID.Text = id;
174    }
175
176    // clear textboxes
177    private void btClear_Click(object sender, EventArgs e) {
178      ClearTextBoxes();
179      DeselectResourceListCells();
180    }
181
182    private void btCreateClient_Click(object sender, EventArgs e) {       
183      Hashtable newClient = GetResourceCollection();
184      if (clientAdmin.Create(newClient)) {Search();}
185    }
186
187    private void btDeleteClient_Click(object sender, EventArgs e) {
188      Hashtable ht = new Hashtable();
189      ht = GetResourceCollection();
190      bool deleted = clientAdmin.Delete(ht);
191      if (deleted) {
192        Hashtable empty = new Hashtable();
193        FillForm(empty);
194        Search();
195        //int i = ResourceList.CurrentCell.RowIndex;
196        //ResourceList.Rows.RemoveAt(i);
197        //DeselectResourceListCells();
198      }
199    }
200
201    // insert default values for new client
202    private void btGenerate_Click(object sender, EventArgs e) {
203      FillForm(GenerateClient());
204    }
205
206    private void btClientExit_Click(object sender, EventArgs e) {
207      Close();
208    }
209
210    private void btClientUpdate_Click(object sender, EventArgs e) {
211      Hashtable updateClient = GetResourceCollection();
212      if (clientAdmin.Update(updateClient)) {Search();}
213    }
214
215//******************************************************************************
216//    tab group
217//******************************************************************************
218
219    private void btClearRG_Click(object sender, EventArgs e) {
220      ClearTextBoxesGroup();
221      DeselectResourceGroupListCells();
222    }
223
224    private void btSearchRG_Click(object sender, EventArgs e) {
225      SearchGroup();
226    }
227
228    private void btCreateRG_Click(object sender, EventArgs e) {
229      Hashtable newGroup = GetResourceGroupCollection();
230      if (groupAdmin.Create(newGroup)) {SearchGroup();}
231    }
232
233    private void btUpdateRG_Click(object sender, EventArgs e) {
234      Hashtable newGroup = GetResourceGroupCollection();
235      if (groupAdmin.Update(newGroup)) {SearchGroup();}
236    }
237
238    private void btDeleteRG_Click(object sender, EventArgs e) {
239      Hashtable ht = new Hashtable();
240      ht = GetResourceGroupCollection();
241      if (groupAdmin.Delete(ht)) {
242        Hashtable empty = new Hashtable();
243        FillFormGroup(empty);
244        SearchGroup();
245        //int i = ResourceGroupList.CurrentCell.RowIndex;
246        //ResourceGroupList.Rows.RemoveAt(i);
247        //DeselectResourceGroupListCells();
248      }
249    }
250
251    private void btExitRG_Click(object sender, EventArgs e) {
252      Close();
253    }
254
255    private void GetGroupGroupIDandName(ref string id, ref string name) {
256      string selectedGroup = (string)cbResourceGroupGroup.SelectedItem;
257      char[] seperator = { ' ' };
258      string[] splitText = selectedGroup.Split(seperator);
259      name = splitText[0];
260      id = splitText[2];
261    }
262
263    private void cbResourceGroupGroup_Click(object sender, EventArgs e) {
264      cbResourceGroupGroup.Items.Clear();
265      Hashtable ht = new Hashtable(); // GetResourceGroupCollection();
266      HashSet<Hashtable> reshs = groupAdmin.Get(ht);
267      foreach (Hashtable resht in reshs) {
268        cbResourceGroupGroup.Items.Add((string)resht[AM.eResource.Name] + " : " + resht[AM.eResource.ResourceID]);
269      }
270    }
271
272    private void cbResourceGroupGroup_SelectedIndexChanged(object sender, EventArgs e) {
273      string id = "";
274      string name = "";
275      GetGroupGroupIDandName(ref id, ref name);
276      tbResourceGroupGroupName.Text = name;
277      tbResourceGroupGroupID.Text = id;
278    }
279
280    private void ResourceGroupList_CellClick(object sender, DataGridViewCellEventArgs e) {
281      int r = e.RowIndex; //selected row
282      tbResourceIDGroup.Text = ResourceGroupList.Rows[r].Cells[0].Value.ToString();
283      tbNameGroup.Text = ResourceGroupList.Rows[r].Cells[1].Value.ToString();
284      tbResourceGroupType.Text = ResourceGroupList.Rows[r].Cells[2].Value.ToString();
285      tbDescriptionGroup.Text = ResourceGroupList.Rows[r].Cells[3].Value.ToString();
286      tbResourceGroupGroupName.Text = ResourceGroupList.Rows[r].Cells[4].Value.ToString();
287      tbResourceGroupGroupID.Text = ResourceGroupList.Rows[r].Cells[5].Value.ToString();
288    }
289
290    private void FillResultGroupList(HashSet<Hashtable> hs) {
291      ResourceGroupList.Rows.Clear();
292      ResourceGroupList.ColumnCount = 6;
293      int r = 0;
294      foreach (Hashtable ht in hs) {
295        ResourceGroupList.Rows.Add();
296        AddRowToResourceGroupList(ht, r);
297        r++;
298      }
299      ResourceGroupList.Refresh();
300    }
301
302    private void AddRowToResourceGroupList(Hashtable ht, int r) {
303      ResourceGroupList.Rows[r].Cells[0].Value = ht[AM.eResource.ResourceID];
304      ResourceGroupList.Rows[r].Cells[1].Value = (string)ht[AM.eResource.Name];
305      ResourceGroupList.Rows[r].Cells[2].Value = (string)ht[AM.eResource.ResourceType];
306      ResourceGroupList.Rows[r].Cells[3].Value = (string)ht[AM.eResource.Description];
307      ResourceGroupList.Rows[r].Cells[4].Value = (string)ht[AM.eResource.ResourceNameGroup];
308      ResourceGroupList.Rows[r].Cells[5].Value = ht[AM.eResource.ResourceIDGroup];
309    }
310
311    private void SearchGroup() {
312      DeselectResourceGroupListCells();
313      Hashtable ht = GetResourceGroupCollection();
314      HashSet<Hashtable> reshs = groupAdmin.Get(ht);
315      // empty textboxes
316      ClearTextBoxesGroup();
317      if (reshs != null) {
318        FillResultGroupList(reshs);
319      }
320    }
321
322    private void DeselectResourceGroupListCells() {
323      foreach (DataGridViewCell c in this.ResourceGroupList.SelectedCells) {
324        c.Selected = false;
325      }
326    }
327
328    private void FillFormGroup(Hashtable ht) {
329      tbResourceIDGroup.Text = (string)ht[AM.eResource.ResourceID];
330      tbNameGroup.Text = (string)ht[AM.eResource.Name];
331      tbDescriptionGroup.Text = (string)ht[AM.eResource.Description];
332      tbResourceGroupType.Text = "ResourceGroup";
333      tbResourceGroupGroupID.Text = (string)ht[AM.eResource.ResourceIDGroup];
334      tbResourceGroupGroupName.Text = (string)ht[AM.eResource.ResourceNameGroup];
335      cbResourceGroupGroup.Text = "";
336    }
337
338    // copies values of textboxes into hashtable
339    private Hashtable GetResourceGroupCollection() {
340      Hashtable ht = new Hashtable();
341      ht.Add(AM.eResource.ResourceID, (string)tbResourceIDGroup.Text);
342      ht.Add(AM.eResource.Name, (string)tbNameGroup.Text);
343      ht.Add(AM.eResource.Description, (string)tbDescriptionGroup.Text);
344      ht.Add(AM.eResource.ResourceType, (string)tbResourceGroupType.Text);
345      ht.Add(AM.eResource.ResourceIDGroup, (string)tbResourceGroupGroupID.Text);
346      ht.Add(AM.eResource.ResourceNameGroup, (string)tbResourceGroupGroupName.Text);
347      return ht;
348    }
349
350    private void ClearTextBoxesGroup() {
351      Hashtable empty = new Hashtable();
352      FillFormGroup(empty);
353    }
354
355
356  }
357}
Note: See TracBrowser for help on using the repository browser.