using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using AM = HeuristicLab.Services.Authentication.AdminMethods; namespace HeuristicLab.Services.Authentication.UserInterface { public partial class Form1 : Form { public AM.ClientAdmin clientAdmin = null; public AM.GroupAdmin groupAdmin = null; public Form1() { InitializeComponent(); clientAdmin = new AM.ClientAdmin(); groupAdmin = new AM.GroupAdmin(); } //****************************************************************************** // tab client //****************************************************************************** // copies values of textboxes into hashtable private Hashtable GetResourceCollection() { Hashtable ht = new Hashtable(); ht.Add(AM.eResource.ResourceID, (string)tbResourceID.Text); ht.Add(AM.eResource.Name, (string)tbName.Text); ht.Add(AM.eResource.Description, (string)tbDescription.Text); ht.Add(AM.eResource.ResourceType, (string)tbResourceType.Text); ht.Add(AM.eResource.ProcessorType, (string)tbProcessorType.Text); ht.Add(AM.eResource.NumberOfProcessors, (string)tbNumberOfProcessors.Text); ht.Add(AM.eResource.NumberOfThreads, (string)tbNumberOfThreads.Text); ht.Add(AM.eResource.IPAdress, (string)tbIPAdress.Text); ht.Add(AM.eResource.MemorySize, (string)tbMemorySize.Text); ht.Add(AM.eResource.OperatingSystem, (string)tbOperatingSystem.Text); ht.Add(AM.eResource.ResourceIDGroup, (string)tbResourceGroupID.Text); ht.Add(AM.eResource.ResourceNameGroup, (string)tbResourceGroupName.Text); return ht; } private void FillForm(Hashtable ht) { tbResourceID.Text = (string)ht[AM.eResource.ResourceID]; tbName.Text = (string)ht[AM.eResource.Name]; tbDescription.Text = (string)ht[AM.eResource.Description]; tbResourceID.Text = (string)ht[AM.eResource.ResourceType]; tbProcessorType.Text = (string)ht[AM.eResource.ProcessorType]; tbNumberOfProcessors.Text = (string)ht[AM.eResource.NumberOfProcessors]; tbNumberOfThreads.Text = (string)ht[AM.eResource.NumberOfThreads]; tbIPAdress.Text = (string)ht[AM.eResource.IPAdress]; tbMemorySize.Text = (string)ht[AM.eResource.MemorySize]; tbOperatingSystem.Text = (string)ht[AM.eResource.OperatingSystem]; tbResourceGroupID.Text = (string)ht[AM.eResource.ResourceIDGroup]; tbResourceGroupName.Text = (string)ht[AM.eResource.ResourceNameGroup]; cbResourceGroup.Text = ""; } private void DeselectResourceListCells() { foreach (DataGridViewCell c in this.ResourceList.SelectedCells) { c.Selected = false; } } private void ClearTextBoxes() { Hashtable empty = new Hashtable(); FillForm(empty); } private void AddRowToResourceList(Hashtable ht, int r){ ResourceList.Rows[r].Cells[0].Value = ht[AM.eResource.ResourceID]; ResourceList.Rows[r].Cells[1].Value = (string)ht[AM.eResource.Name]; ResourceList.Rows[r].Cells[2].Value = (string)ht[AM.eResource.ResourceType]; ResourceList.Rows[r].Cells[3].Value = (string)ht[AM.eResource.Description]; ResourceList.Rows[r].Cells[4].Value = (string)ht[AM.eResource.IPAdress]; ResourceList.Rows[r].Cells[5].Value = (string)ht[AM.eResource.NumberOfProcessors]; ResourceList.Rows[r].Cells[6].Value = (string)ht[AM.eResource.NumberOfThreads]; ResourceList.Rows[r].Cells[7].Value = (string)ht[AM.eResource.MemorySize]; ResourceList.Rows[r].Cells[8].Value = (string)ht[AM.eResource.OperatingSystem]; ResourceList.Rows[r].Cells[9].Value = (string)ht[AM.eResource.ResourceNameGroup]; ResourceList.Rows[r].Cells[10].Value = ht[AM.eResource.ResourceIDGroup]; } // insert results of search in ResourceList private void FillResultList(HashSet hs) { ResourceList.Rows.Clear(); ResourceList.ColumnCount = 11; int r = 0; foreach (Hashtable ht in hs) { ResourceList.Rows.Add(); AddRowToResourceList(ht, r); r++; } ResourceList.Refresh(); } private void Search() { DeselectResourceListCells(); Hashtable ht = GetResourceCollection(); HashSet reshs = clientAdmin.Get(ht); //HashSet reshs = AM.AdminMethods.GetClient(ht); // empty textboxes ClearTextBoxes(); if (reshs != null) { FillResultList(reshs); } } private Hashtable GenerateClient() { Hashtable ht = new Hashtable(); ht.Add(AM.eResource.ResourceID, ""); ht.Add(AM.eResource.Name, "cl Name"); ht.Add(AM.eResource.Description, "descr"); ht.Add(AM.eResource.ResourceType, ""); ht.Add(AM.eResource.ProcessorType, "Amd"); ht.Add(AM.eResource.NumberOfProcessors, "4"); ht.Add(AM.eResource.NumberOfThreads, "2"); ht.Add(AM.eResource.IPAdress, "192.168.1.2"); ht.Add(AM.eResource.MemorySize, "4096"); ht.Add(AM.eResource.OperatingSystem, "WinXP"); //ht.Add(AM.eResource.ResourceGroup, ""); return ht; } private void GetGroupIDandName(ref string id, ref string name) { string selectedGroup = (string)cbResourceGroup.SelectedItem; char[] seperator = {'('}; char []trimSpaces = {' '}; char []trimEntPara = {')'}; string[] splitText = selectedGroup.Split(seperator); name = splitText[0].TrimEnd(trimSpaces); id = splitText[1].TrimEnd(trimEntPara); } // get clients selected by textboxvalues private void btSearchClient_Click(object sender, EventArgs e) { Search(); } // when click on a cell the values of current row will be copied into textboxes private void ResourceList_CellClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; //selected row tbResourceID.Text = ResourceList.Rows[r].Cells[0].Value.ToString(); tbName.Text = ResourceList.Rows[r].Cells[1].Value.ToString(); tbResourceType.Text = ResourceList.Rows[r].Cells[2].Value.ToString(); tbDescription.Text = ResourceList.Rows[r].Cells[3].Value.ToString(); tbIPAdress.Text = ResourceList.Rows[r].Cells[4].Value.ToString(); tbNumberOfProcessors.Text = ResourceList.Rows[r].Cells[5].Value.ToString(); tbNumberOfThreads.Text = ResourceList.Rows[r].Cells[6].Value.ToString(); tbMemorySize.Text = ResourceList.Rows[r].Cells[7].Value.ToString(); tbOperatingSystem.Text = ResourceList.Rows[r].Cells[8].Value.ToString(); tbResourceGroupName.Text = ResourceList.Rows[r].Cells[9].Value.ToString(); tbResourceGroupID.Text = ResourceList.Rows[r].Cells[10].Value.ToString(); } // get ResourceGroup private void cbResourceGroup_Click(object sender, EventArgs e) { cbResourceGroup.Items.Clear(); Hashtable ht = new Hashtable(); // GetResourceGroupCollection(); HashSet reshs = groupAdmin.Get(ht); foreach (Hashtable resht in reshs) { cbResourceGroup.Items.Add((string)resht[AM.eResource.Name] + " (" + resht[AM.eResource.ResourceID] + ")"); } } private void cbResourceGroup_SelectedIndexChanged(object sender, EventArgs e) { string id = ""; string name = ""; GetGroupIDandName(ref id, ref name); tbResourceGroupName.Text = name; tbResourceGroupID.Text = id; } // clear textboxes private void btClear_Click(object sender, EventArgs e) { ClearTextBoxes(); DeselectResourceListCells(); } private void btCreateClient_Click(object sender, EventArgs e) { Hashtable newClient = GetResourceCollection(); if (clientAdmin.Create(newClient)) {Search();} } private void btDeleteClient_Click(object sender, EventArgs e) { Hashtable ht = new Hashtable(); ht = GetResourceCollection(); bool deleted = clientAdmin.Delete(ht); if (deleted) { Hashtable empty = new Hashtable(); FillForm(empty); Search(); //int i = ResourceList.CurrentCell.RowIndex; //ResourceList.Rows.RemoveAt(i); //DeselectResourceListCells(); } } // insert default values for new client private void btGenerate_Click(object sender, EventArgs e) { FillForm(GenerateClient()); } private void btClientExit_Click(object sender, EventArgs e) { Close(); } private void btClientUpdate_Click(object sender, EventArgs e) { Hashtable updateClient = GetResourceCollection(); if (clientAdmin.Update(updateClient)) {Search();} } //****************************************************************************** // tab group //****************************************************************************** private void btClearRG_Click(object sender, EventArgs e) { ClearTextBoxesGroup(); DeselectResourceGroupListCells(); } private void btSearchRG_Click(object sender, EventArgs e) { SearchGroup(); } private void btCreateRG_Click(object sender, EventArgs e) { Hashtable newGroup = GetResourceGroupCollection(); if (groupAdmin.Create(newGroup)) {SearchGroup();} } private void btUpdateRG_Click(object sender, EventArgs e) { Hashtable newGroup = GetResourceGroupCollection(); if (groupAdmin.Update(newGroup)) {SearchGroup();} } private void btDeleteRG_Click(object sender, EventArgs e) { Hashtable ht = new Hashtable(); ht = GetResourceGroupCollection(); if (groupAdmin.Delete(ht)) { Hashtable empty = new Hashtable(); FillFormGroup(empty); SearchGroup(); //int i = ResourceGroupList.CurrentCell.RowIndex; //ResourceGroupList.Rows.RemoveAt(i); //DeselectResourceGroupListCells(); } } private void btExitRG_Click(object sender, EventArgs e) { Close(); } private void GetGroupGroupIDandName(ref string id, ref string name) { string selectedGroup = (string)cbResourceGroupGroup.SelectedItem; char[] seperator = { ' ' }; string[] splitText = selectedGroup.Split(seperator); name = splitText[0]; id = splitText[2]; } private void cbResourceGroupGroup_Click(object sender, EventArgs e) { cbResourceGroupGroup.Items.Clear(); Hashtable ht = new Hashtable(); // GetResourceGroupCollection(); HashSet reshs = groupAdmin.Get(ht); foreach (Hashtable resht in reshs) { cbResourceGroupGroup.Items.Add((string)resht[AM.eResource.Name] + " : " + resht[AM.eResource.ResourceID]); } } private void cbResourceGroupGroup_SelectedIndexChanged(object sender, EventArgs e) { string id = ""; string name = ""; GetGroupGroupIDandName(ref id, ref name); tbResourceGroupGroupName.Text = name; tbResourceGroupGroupID.Text = id; } private void ResourceGroupList_CellClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; //selected row tbResourceIDGroup.Text = ResourceGroupList.Rows[r].Cells[0].Value.ToString(); tbNameGroup.Text = ResourceGroupList.Rows[r].Cells[1].Value.ToString(); tbResourceGroupType.Text = ResourceGroupList.Rows[r].Cells[2].Value.ToString(); tbDescriptionGroup.Text = ResourceGroupList.Rows[r].Cells[3].Value.ToString(); tbResourceGroupGroupName.Text = ResourceGroupList.Rows[r].Cells[4].Value.ToString(); tbResourceGroupGroupID.Text = ResourceGroupList.Rows[r].Cells[5].Value.ToString(); } private void FillResultGroupList(HashSet hs) { ResourceGroupList.Rows.Clear(); ResourceGroupList.ColumnCount = 6; int r = 0; foreach (Hashtable ht in hs) { ResourceGroupList.Rows.Add(); AddRowToResourceGroupList(ht, r); r++; } ResourceGroupList.Refresh(); } private void AddRowToResourceGroupList(Hashtable ht, int r) { ResourceGroupList.Rows[r].Cells[0].Value = ht[AM.eResource.ResourceID]; ResourceGroupList.Rows[r].Cells[1].Value = (string)ht[AM.eResource.Name]; ResourceGroupList.Rows[r].Cells[2].Value = (string)ht[AM.eResource.ResourceType]; ResourceGroupList.Rows[r].Cells[3].Value = (string)ht[AM.eResource.Description]; ResourceGroupList.Rows[r].Cells[4].Value = (string)ht[AM.eResource.ResourceNameGroup]; ResourceGroupList.Rows[r].Cells[5].Value = ht[AM.eResource.ResourceIDGroup]; } private void SearchGroup() { DeselectResourceGroupListCells(); Hashtable ht = GetResourceGroupCollection(); HashSet reshs = groupAdmin.Get(ht); // empty textboxes ClearTextBoxesGroup(); if (reshs != null) { FillResultGroupList(reshs); } } private void DeselectResourceGroupListCells() { foreach (DataGridViewCell c in this.ResourceGroupList.SelectedCells) { c.Selected = false; } } private void FillFormGroup(Hashtable ht) { tbResourceIDGroup.Text = (string)ht[AM.eResource.ResourceID]; tbNameGroup.Text = (string)ht[AM.eResource.Name]; tbDescriptionGroup.Text = (string)ht[AM.eResource.Description]; tbResourceGroupType.Text = "ResourceGroup"; tbResourceGroupGroupID.Text = (string)ht[AM.eResource.ResourceIDGroup]; tbResourceGroupGroupName.Text = (string)ht[AM.eResource.ResourceNameGroup]; cbResourceGroupGroup.Text = ""; } // copies values of textboxes into hashtable private Hashtable GetResourceGroupCollection() { Hashtable ht = new Hashtable(); ht.Add(AM.eResource.ResourceID, (string)tbResourceIDGroup.Text); ht.Add(AM.eResource.Name, (string)tbNameGroup.Text); ht.Add(AM.eResource.Description, (string)tbDescriptionGroup.Text); ht.Add(AM.eResource.ResourceType, (string)tbResourceGroupType.Text); ht.Add(AM.eResource.ResourceIDGroup, (string)tbResourceGroupGroupID.Text); ht.Add(AM.eResource.ResourceNameGroup, (string)tbResourceGroupGroupName.Text); return ht; } private void ClearTextBoxesGroup() { Hashtable empty = new Hashtable(); FillFormGroup(empty); } } }