/// <summary> /// Sets the IsValid property to false, and marks the first control to validate /// as invalid. /// </summary> public void MarkInvalid() { IsValid = false; ArrayList ControlsToValidate = new ArrayList(); ControlsToValidate.Reverse(); ControlsToValidate.AddRange(ControlToValidate.Split(',')); Control C = null; foreach (string st in ControlsToValidate) { C = FindControl(st); if (IsMarkedInvalid(C)) { return; } } ControlsToValidate.Reverse(); foreach (string st in ControlsToValidate) { C = FindControl(st); if (MarkInvalid(C)) { return; } } }
/// <summary> /// Returns true if the validation event is true for all the controls listed /// in ControlToValidate. Sets Validated to true when finished. /// </summary> /// <exception cref="ValidatorCircularException"> /// Thrown if method is called recursively on the same object. Means that /// one of the controls being validated is dependant on itself. Could be /// through multiple levels. /// </exception> /// <exception cref="ValidatorNotDefinedException"> /// Thrown if neither OnServerValidate property or ControlToValidate property /// is set. At least one of the two must be set. Default value will be used /// for OnServerValidate if only ControlToValidate is set. This control will /// be supplied to OnServerValidate delegate if on OnServerValidate is set. /// </exception> protected override bool EvaluateIsValid() { if (Validated) { return(base.IsValid); } if (Validating) { throw new ValidatorCircularException(ID); } Validating = true; if (ControlToValidate.Length == 0) { if (ServerValidate == null) { throw new ValidatorNotDefinedException(ID); } return(CompleteValidation(EvaluateIsValid(ID))); } else if (ServerValidate == null) { ServerValidate = new ValidatorEventHandler(DefaultOnServerValidate); } ArrayList ControlsToValidate = new ArrayList(); ControlsToValidate.AddRange(ControlToValidate.Split(',')); foreach (string st in ControlsToValidate) { if (Any == EvaluateIsValid(st)) { return(CompleteValidation(Any)); } } return(CompleteValidation(!Any)); }
public override bool Validate() { OnValidating();//Call anyone who is listening Validated event if (!Enabled) { return(UpdateResult(true)); } try { string value = ControlToValidate.GetType().GetProperty(PropertyToValidate).GetValue(ControlToValidate, null).ToString().Trim(); string compareValue = ControlToCompare.GetType().GetProperty(PropertyToValidate).GetValue(ControlToCompare, null).ToString().Trim(); if (value == compareValue) { return(UpdateResult(true)); } return(UpdateResult(false)); } catch (Exception ex) { if (ShowExceptions) { MessageBox.Show(ex.Message.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(UpdateResult(false)); } }
public override bool Validate() { OnValidating();//Call anyone who is listening Validated event if (!Enabled) { return(UpdateResult(true)); } try { String value = ControlToValidate.GetType().GetProperty(PropertyToValidate).GetValue(ControlToValidate, null).ToString().Trim(); System.Text.RegularExpressions.Regex evaluator = new System.Text.RegularExpressions.Regex(ExpressionPattern); if (evaluator.IsMatch(value)) { return(UpdateResult(true)); } return(UpdateResult(false)); } catch (Exception ex) { if (ShowExceptions) { MessageBox.Show(ex.Message.ToString(), "Exception occured!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(UpdateResult(false)); } }
/// <summary> /// Performs data validation. /// </summary> /// <param name="ARecordChangeVerification">Set to true if the data validation happens when the user is changing /// to another record, otherwise set it to false.</param> /// <param name="AValidateSpecificControl">Pass in a Control to restrict Data Validation error checking to a /// specific Control for which Data Validation errors might have been recorded. (Default=this.ActiveControl). /// <para> /// This is useful for restricting Data Validation error checking to the current TabPage of a TabControl in order /// to only display Data Validation errors that pertain to the current TabPage. To do this, pass in a TabControl in /// this Argument. /// </para> /// </param> /// <returns>True if data validation succeeded or if there is no current row, otherwise false.</returns> private bool ValidateAllData(bool ARecordChangeVerification, Control AValidateSpecificControl = null) { bool ReturnValue = false; Control ControlToValidate = null; // Record a new Data Validation Run. (All TVerificationResults/TScreenVerificationResults that are created during this 'run' are associated with this 'run' through that.) FPetraUtilsObject.VerificationResultCollection.RecordNewDataValidationRun(); if (AValidateSpecificControl != null) { ControlToValidate = AValidateSpecificControl; } else { ControlToValidate = this.ActiveControl; } // Only process the Data Validations here if ControlToValidate is not null. // It can be null if this.ActiveControl yields null - this would happen if no Control // on this Form has got the Focus. if (ControlToValidate != null) { if (ControlToValidate.FindUserControlOrForm(true) == this) { ReturnValue = TDataValidation.ProcessAnyDataValidationErrors(false, FPetraUtilsObject.VerificationResultCollection, this.GetType(), ControlToValidate.FindUserControlOrForm(true).GetType()); } else { ReturnValue = true; } } if (ReturnValue) { // Remove a possibly shown Validation ToolTip as the data validation succeeded FPetraUtilsObject.ValidationToolTip.RemoveAll(); } return(ReturnValue); }