protected void printGrid(Infragistics.Win.UltraWinGrid.UltraGrid grid) { // Associate the print document with the grid & preview dialog here // for consistency with other forms that require it _ultraGridPrintDocument.Grid = grid; _ultraGridPrintDocument.DefaultPageSettings.Landscape = true; _ultraGridPrintDocument.DefaultPageSettings.Color = false; _ultraGridPrintDocument.DocumentName = PrintTitle; _ultraGridPrintDocument.FitWidthToPages = 1; Policy policy = Program.gController.Repository.Policies.Find(m_PolicyId); if (policy.AssessmentId != m_AssessmentId && policy.HasAssessment(m_AssessmentId)) { policy = policy.Assessments.Find(m_AssessmentId); } PolicyMetric check = null; foreach (PolicyMetric metric in policy.GetPolicyMetrics()) { if (metric.MetricId == m_MetricId) { check = metric; break; } } if (policy != null && check != null) { _ultraGridPrintDocument.Header.TextLeft = string.Format(PrintHeaderDisplay, policy.PolicyAssessmentName, check.MetricName, DateTime.Now.ToShortDateString() ); _ultraPrintPreviewDialog.Document = _ultraGridPrintDocument; // Call ShowDialog to show the print preview dialog. _ultraPrintPreviewDialog.ShowDialog(); } else { logX.loggerX.Error(string.Format(Utility.ErrorMsgs.ErrorStub, Utility.ErrorMsgs.CantGetPolicy)); MsgBox.ShowError(Utility.ErrorMsgs.PolicyCaption, Utility.ErrorMsgs.CantGetPolicy); } }
private void button_OK_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(textBox_PolicyName.Text.Trim())) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General]; textBox_PolicyName.Focus(); MsgBox.ShowError(ERRORTITLE_CREATE, ERRORMSGNAMEEMPTY); DialogResult = DialogResult.None; return; } if (m_policy.IsPolicy) { // Is Policy name already used Policy p = Program.gController.Repository.GetPolicy(textBox_PolicyName.Text); if (p != null && p.PolicyId != m_policy.PolicyId) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General]; textBox_PolicyName.Focus(); MsgBox.ShowError(ERRORTITLE_CREATE, string.Format(ERRORMSGDUP, textBox_PolicyName.Text)); DialogResult = DialogResult.None; return; } } else { if (string.IsNullOrEmpty(textBox_PolicyName.Text)) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General]; textBox_PolicyName.Focus(); MsgBox.ShowError(ERRORTITLE_CREATE, ERRORMSGNAMEEMPTY); DialogResult = DialogResult.None; return; } Policy p = Program.gController.Repository.GetPolicy(m_policy.PolicyId); if (p.HasAssessment(textBox_PolicyName.Text)) { Policy a = p.GetAssessment(textBox_PolicyName.Text); if (a.AssessmentId != m_policy.AssessmentId) { MsgBox.ShowError(ERRORTITLE_UPDATE, string.Format(ERRORMSGDUP, textBox_PolicyName.Text, p.PolicyName)); DialogResult = DialogResult.None; Cursor = Cursors.Default; return; } } } if (!controlConfigurePolicyVulnerabilities1.OKToSave()) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.SecurityChecks]; DialogResult = DialogResult.None; return; } if (controlConfigurePolicyVulnerabilities1.NumSecurityChecks == 0) { if (DialogResult.No == MsgBox.ShowWarningConfirm(WARNINGTITLE, ErrorMsgs.NoPolicyMetricsMsg)) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.SecurityChecks]; DialogResult = DialogResult.None; return; } } if (controlPolicyAddServers1.NumServers == 0) { if (DialogResult.No == MsgBox.ShowWarningConfirm(WARNINGTITLE, ErrorMsgs.NoPolicyServersMsg)) { ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.Servers]; DialogResult = DialogResult.None; return; } } List <RegisteredServer> serversToAdd = null; List <RegisteredServer> serversToRemove = null; string dynamicSelection = null; bool isDynamic; controlPolicyAddServers1.GetServers(m_isCreateNew, out serversToAdd, out serversToRemove, out dynamicSelection, out isDynamic); int policyId = -1; if (m_isCreateNew) { policyId = Policy.AddPolicy(textBox_PolicyName.Text, textBox_Description.Text, isDynamic, dynamicSelection, _policyInterview.InterviewName, _policyInterview.GetInterviewText()); if (policyId != -1) { m_policy = Policy.GetPolicy(policyId); controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy); m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString); } } else { policyId = m_policy.PolicyId; controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy); if (m_policy.IsAssessment) { m_policy.AssessmentName = textBox_PolicyName.Text; m_policy.AssessmentDescription = textBox_Description.Text; m_policy.AssessmentNotes = _textBox_Notes.Text; } else { m_policy.SetPolicyName(textBox_PolicyName.Text); m_policy.PolicyDescription = textBox_Description.Text; } m_policy.IsDynamic = isDynamic; m_policy.DynamicSelection = dynamicSelection; m_policy.InterviewName = _policyInterview.InterviewName; m_policy.InterviewText = _policyInterview.GetInterviewText(); m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString); } //list should be empty if dynamic if (!isDynamic) { foreach (RegisteredServer rServer in serversToRemove) { RegisteredServer.RemoveRegisteredServerFromPolicy(rServer.RegisteredServerId, m_policy.PolicyId, m_policy.AssessmentId); } foreach (RegisteredServer rServer in serversToAdd) { RegisteredServer.AddRegisteredServerToPolicy(rServer.RegisteredServerId, policyId, m_policy.AssessmentId); } } Program.gController.SignalRefreshPoliciesEvent(0); } catch (Exception ex) { string title = ERRORTITLE_UPDATE; string msg = string.Format(ERRORMSGFMT, textBox_PolicyName.Text, ex.Message); if (m_isCreateNew) { title = ERRORTITLE_CREATE; msg = string.Format(ERRORMSGFMT, textBox_PolicyName.Text, ex.Message); } logX.loggerX.Error(msg); MsgBox.ShowError(title, msg); } }