private void removeAssociated_Button_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Deletion is final, are you sure you want to remove?", "Removal confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                children_GridView.EndEdit();
                List <string> services = getSelectedServices();
                foreach (string service in services)
                {
                    using (EnterpriseTestContext context = new EnterpriseTestContext())
                    {
                        // Get service to remove from parent
                        ResourceWindowsCategory serviceToDelete = ResourceWindowsCategory.SelectByName(context, service, tabControl_Types.SelectedTab.Text);

                        //Get Parent
                        ResourceWindowsCategory parent = ResourceWindowsCategory.SelectByName(context, listBox_Resource.Text, tabControl_Types.SelectedTab.Text);

                        //Remove Parent Child relationship
                        ResourceWindowsCategory.RemoveChild(context, parent.CategoryId, serviceToDelete.CategoryId);

                        context.SaveChanges();

                        // Update Grid
                        children_GridView.DataSource = null;
                        children_GridView.DataSource = ResourceWindowsCategory.SelectByParent(context, (int)listBox_Resource.SelectedValue);
                    }
                }
            }
        }
 private void Update_GridView(int selectedId)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         children_GridView.DataSource = ResourceWindowsCategory.SelectByParent(context, selectedId);
     }
 }
        private void addAssociated_Button_Click(object sender, EventArgs e)
        {
            List <string> associatedServices         = new List <string>();
            List <ResourceWindowsCategory> services  = new List <ResourceWindowsCategory>();
            ResourceWindowsCategory        component = new ResourceWindowsCategory();

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                component = ResourceWindowsCategory.SelectById(context, (int)listBox_Resource.SelectedValue);
                services  = ResourceWindowsCategory.SelectByParent(context, (int)listBox_Resource.SelectedValue);
            }

            foreach (ResourceWindowsCategory service in services)
            {
                associatedServices.Add(service.Name);
            }

            try
            {
                if (pingServer(component.Name))
                {
                    ResourceWindowsConfigurationForm addForm = new ResourceWindowsConfigurationForm(component, associatedServices);
                    addForm.ShowDialog();
                    if (addForm.DialogResult == DialogResult.OK)
                    {
                        ResourceWindowsCategory newServer = addForm.Resource;
                        string newCategoryType            = addForm.CategoryType;
                        LoadResourceTypeTabs();
                        tabControl_Types.SelectedTab  = tabControl_Types.TabPages[newServer.CategoryType];
                        listBox_Resource.SelectedItem = newServer.Name;
                        Update_GridView((int)listBox_Resource.SelectedValue);
                    }
                }
            }
            catch
            {
                string errorMessage = "Error: No access to " + component.Name;
                MessageBox.Show(errorMessage, "Server Access Failure", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }