Пример #1
0
        private bool DoValidate()
        {
            try
            {
                if (txtDetailQuery.Text.Trim().Length == 0)
                {
                    throw new InPutValidationException("The detail query must be specified!", txtDetailQuery);
                }
                if (!SQLTools.TSQLValid(txtDetailQuery.Text))
                {
                    throw new InPutValidationException("SQL statements may not contain certain keywords (e.g. update, delete, create etc!", txtDetailQuery);
                }



                return(true);
            }
            catch (InPutValidationException ex)
            {
                MessageBox.Show(ex.Message, "Input Validation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
        }
Пример #2
0
 private bool DoValidate()
 {
     try
     {
         if (txtName.Text.Length == 0)
         {
             throw new InPutValidationException("Name must be specified!", txtName);
         }
         if (txtServer.Text.Length == 0)
         {
             throw new InPutValidationException("The sql server name must be specified!", txtServer);
         }
         if (txtDatabase.Text.Length == 0)
         {
             throw new InPutValidationException("The database name must be specified!", txtDatabase);
         }
         if (!chkIntegratedSec.Checked && txtUserName.Text.Length == 0)
         {
             throw new InPutValidationException("The user name must be specified when not using integrated security!", txtUserName);
         }
         if (txtStateQuery.Text.Trim().Length == 0)
         {
             throw new InPutValidationException("The summary query must be specified!", txtStateQuery);
         }
         if (!SQLTools.TSQLValid(txtStateQuery.Text))
         {
             throw new InPutValidationException("SQL statements may not contain certain keywords (e.g. update, delete, create etc!", txtStateQuery);
         }
         if ((cboSuccessValue.Text == "[null]" && cboWarningValue.Text == "[null]") ||
             (cboSuccessValue.Text == "[null]" && cboErrorValue.Text == "[null]") ||
             (cboWarningValue.Text == "[null]" && cboErrorValue.Text == "[null]"))
         {
             throw new InPutValidationException("Only one value can be [null]!", cboSuccessValue);
         }
         if ((cboSuccessValue.Text == "[any]" && cboWarningValue.Text == "[any]") ||
             (cboSuccessValue.Text == "[any]" && cboErrorValue.Text == "[any]") ||
             (cboWarningValue.Text == "[any]" && cboErrorValue.Text == "[any]"))
         {
             throw new InPutValidationException("Only one value can be [any]!", cboSuccessValue);
         }
         if (cboReturnType.SelectedIndex != 0)
         {
             if (cboReturnType.SelectedIndex == 3)
             {
                 chkReturnValueNotInverted.Checked = true;
             }
             if (cboSuccessValue.Text != "[null]" && cboSuccessValue.Text != "[any]" && !cboSuccessValue.Text.IsLong())
             {
                 throw new InPutValidationException("Success value must be a valid integer!\r\n(or predefined values [any] or [null])", cboSuccessValue);
             }
             else if (cboWarningValue.Text != "[null]" && cboWarningValue.Text != "[any]" && !cboWarningValue.Text.IsLong())
             {
                 throw new InPutValidationException("Warning value must be a valid integer!\r\n(or predefined values [any] or [null])", cboWarningValue);
             }
             else if (cboErrorValue.Text != "[null]" && cboErrorValue.Text != "[any]" && !cboErrorValue.Text.IsLong())
             {
                 throw new InPutValidationException("Error value must be a valid integer!\r\n(or predefined values [any] or [null])", cboErrorValue);
             }
             else if (chkReturnValueNotInverted.Checked)
             {
                 if (cboSuccessValue.Text != "[null]" && cboSuccessValue.Text != "[any]" &&
                     cboWarningValue.Text != "[null]" && cboWarningValue.Text != "[any]" &&
                     long.Parse(cboSuccessValue.Text) >= long.Parse(cboWarningValue.Text))
                 {
                     throw new InPutValidationException("Success value must smaller than Warning value", cboSuccessValue);
                 }
                 else if (cboWarningValue.Text != "[null]" && cboWarningValue.Text != "[any]" &&
                          cboErrorValue.Text != "[null]" && cboErrorValue.Text != "[any]" &&
                          int.Parse(cboWarningValue.Text) >= long.Parse(cboErrorValue.Text))
                 {
                     throw new InPutValidationException("Warning value must smaller than Error value", cboWarningValue);
                 }
             }
             else if (!chkReturnValueNotInverted.Checked)
             {
                 if (cboSuccessValue.Text != "[null]" && cboSuccessValue.Text != "[any]" &&
                     cboWarningValue.Text != "[null]" && cboWarningValue.Text != "[any]" &&
                     long.Parse(cboSuccessValue.Text) <= long.Parse(cboWarningValue.Text))
                 {
                     throw new InPutValidationException("Success value must bigger than Warning value", cboSuccessValue);
                 }
                 else if (cboWarningValue.Text != "[null]" && cboWarningValue.Text != "[any]" &&
                          cboErrorValue.Text != "[null]" && cboErrorValue.Text != "[any]" &&
                          long.Parse(cboWarningValue.Text) <= long.Parse(cboErrorValue.Text))
                 {
                     throw new InPutValidationException("Warning value must bigger than Error value", cboWarningValue);
                 }
             }
         }
         if (txtDetailQuery.Text.Trim().Length == 0)
         {
             throw new InPutValidationException("The detail query must be specified!", txtDetailQuery);
         }
         if (!SQLTools.TSQLValid(txtDetailQuery.Text))
         {
             throw new InPutValidationException("SQL statements may not contain certain keywords (e.g. update, delete, create etc!", txtDetailQuery);
         }
         return(true);
     }
     catch (InPutValidationException ex)
     {
         MessageBox.Show(ex.Message, "Input Validation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         if (ex.ValidatedObject is Control)
         {
             Control theControl = ((Control)ex.ValidatedObject);
             if (theControl.Parent != null && theControl.Parent is TabPage)
             {
                 tabControlConfig.SelectedTab = (TabPage)theControl.Parent;
             }
             ((Control)ex.ValidatedObject).Focus();
         }
         return(false);
     }
 }