protected void showDelete()
        {
            if (m_server == null)
            {
                if (Sql.Policy.IsPolicyRegistered(m_policy.PolicyId))
                {
                    Sql.Policy policy = Program.gController.Repository.Policies.Find(m_policy.PolicyId);
                    if (policy != null && policy.HasAssessment(m_policy.AssessmentId))
                    {
                        // Display confirmation, if user confirms remove the policy.
                        string caption = Utility.ErrorMsgs.RemoveAssessmentCaption;
                        if (DialogResult.Yes == Utility.MsgBox.ShowWarningConfirm(caption, string.Format(Utility.ErrorMsgs.RemoveAssessmentConfirmMsg, m_policy.PolicyAssessmentName)))
                        {
                            try
                            {
                                Sql.Policy.RemoveAssessment(m_policy.PolicyId, m_policy.AssessmentId);
                            }
                            catch (Exception ex)
                            {
                                Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemoveAssessmentCaption, string.Format(Utility.ErrorMsgs.CantRemoveAssessmentMsg, m_policy.PolicyAssessmentName), ex);
                            }

                            Program.gController.SignalRefreshPoliciesEvent(0);
                        }
                    }
                    else
                    {
                        Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemoveAssessmentCaption, Utility.ErrorMsgs.AssessmentNotFound);
                        Program.gController.SignalRefreshPoliciesEvent(0);
                    }
                }
                else
                {
                    Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemoveAssessmentCaption, Utility.ErrorMsgs.PolicyNotRegistered);
                    Program.gController.SignalRefreshPoliciesEvent(0);
                }
            }
            else
            {
                if (!m_policy.IsDynamic)
                {
                    if (DialogResult.Yes == Utility.MsgBox.ShowWarningConfirm(Utility.ErrorMsgs.RemoveServerFromAssessmentCaption,
                                                                              string.Format(Utility.ErrorMsgs.RemoveServerFromAssessmentConfirmMsg, m_server.ConnectionName, m_policy.PolicyAssessmentName)))
                    {
                        Sql.RegisteredServer.RemoveRegisteredServerFromPolicy(m_server.RegisteredServerId, m_policy.PolicyId, m_policy.AssessmentId);

                        Program.gController.SignalRefreshPoliciesEvent(0);
                    }
                }
                else
                {
                    Utility.MsgBox.ShowError(Utility.ErrorMsgs.PolicyCaption, Utility.ErrorMsgs.RemoveDynamicAssessmentServerMsg);
                }
            }
        }
Ejemplo n.º 2
0
        private void DeletePolicy(Sql.Policy policy)
        {
            Cursor = Cursors.WaitCursor;

            if (Sql.Policy.IsPolicyRegistered(policy.PolicyId))
            {
                if (policy.IsPolicy)
                {
                    if (!policy.IsSystemPolicy)
                    {
                        // Display confirmation, if user confirms remove the policy.
                        string caption = Utility.ErrorMsgs.RemovePolicyCaption + " - " +
                                         policy.PolicyName;
                        if (Utility.MsgBox.ShowConfirm(caption, Utility.ErrorMsgs.RemovePolicyConfirmMsg) ==
                            DialogResult.Yes)
                        {
                            try
                            {
                                Sql.Policy.RemovePolicy(policy.PolicyId);
                            }
                            catch (Exception ex)
                            {
                                Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemovePolicyCaption,
                                                         string.Format(Utility.ErrorMsgs.CantRemovePolicyMsg,
                                                                       policy.PolicyName),
                                                         ex);
                            }

                            Program.gController.SignalRefreshPoliciesEvent(0);
                        }
                    }
                    else
                    {
                        Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemovePolicyCaption,
                                                 Utility.ErrorMsgs.RemoveSystemPolicyMsg);
                    }
                    loadPolicyDataSource(true);
                }
                else if (policy.IsAssessment)
                {
                    if (!policy.IsApprovedAssessment)
                    {
                        // Display confirmation, if user confirms remove the policy.
                        string caption = Utility.ErrorMsgs.RemoveAssessmentCaption + " - " +
                                         policy.PolicyAssessmentName;
                        if (Utility.MsgBox.ShowConfirm(caption, Utility.ErrorMsgs.RemoveAssessmentConfirmMsg) ==
                            DialogResult.Yes)
                        {
                            try
                            {
                                Sql.Policy.RemoveAssessment(policy.PolicyId, policy.AssessmentId);
                            }
                            catch (Exception ex)
                            {
                                Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemoveAssessmentCaption,
                                                         string.Format(Utility.ErrorMsgs.CantRemoveAssessmentMsg,
                                                                       policy.PolicyAssessmentName),
                                                         ex);
                            }

                            Program.gController.SignalRefreshPoliciesEvent(0);
                        }
                    }
                    else
                    {
                        Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemoveAssessmentCaption,
                                                 Utility.ErrorMsgs.RemoveApprovedAssessmentMsg);
                    }
                    loadAssessmentsDataSource(policy.PolicyId, true);
                }
            }
            else
            {
                Utility.MsgBox.ShowError(Utility.ErrorMsgs.RemovePolicyCaption,
                                         Utility.ErrorMsgs.RemoveSystemPolicyMsg);
                Program.gController.SignalRefreshPoliciesEvent(0);
            }


            Cursor = Cursors.Default;
        }