Пример #1
0
        private void add_Button_Click(object sender, EventArgs e)
        {
            // End grid edit mode
            services_GridView.EndEdit();

            // Validate resource name is not blank
            if (!ValidateResourceTypeName())
            {
                MessageBox.Show("Pleae enter valid resource name", "Invalid resource name", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            // Get checkbox services and custom service
            List <string> servicesToAdd = getSelectedServices();

            if (getCustomService() != null)
            {
                servicesToAdd.Add(getCustomService());
            }

            // Add and link services to server and resource type
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                // Get resource type and server name
                string categoryType        = resourceType_TextBox.Text;
                string validatedServerName = serverName_TextBox.Text;

                int serverId = ResourceWindowsCategory.AddResource(context, validatedServerName, categoryType);
                ResourceWindowsCategory serverResource = ResourceWindowsCategory.SelectById(context, serverId);

                foreach (string service in servicesToAdd)
                {
                    int tempId = ResourceWindowsCategory.AddResource(context, service, categoryType);
                    ResourceWindowsCategory tempService = ResourceWindowsCategory.SelectById(context, tempId);
                    tempService.Parents.Add(serverResource);
                }

                context.SaveChanges();
                Resource = serverResource;
                resourceType_TextBox.Text = categoryType;
                this.DialogResult         = DialogResult.OK;
                this.Close();
            }
        }
        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);
            }
        }