/// <summary>
 /// 配置验证规则;
 /// </summary>
 /// <param name="validatingUnit">验证单元</param>
 /// <param name="referenceControl">参照控件</param>
 /// <returns>验证单元</returns>
 private BaseValidatingUnit <Control> ConfigSpecification(BaseValidatingUnit <Control> validatingUnit, Control referenceControl)
 {
     validatingUnit.Match = this.Match;
     validatingUnit.AddSpecification("ReferenceControl", referenceControl);
     validatingUnit.ErrorMessage = this.ErrorMessage;
     return(validatingUnit);
 }
        /// <summary>
        /// 添加(参照控件与确认控件);
        /// </summary>
        /// <param name="referenceControl">参照控件</param>
        /// <param name="confirmControl">确认控件</param>
        /// <returns>确认验证器</returns>
        public ConfirmValidator Add(Control referenceControl, Control confirmControl)
        {
            BaseValidatingUnit <Control> validatingUnit = new BaseValidatingUnit <Control>(confirmControl);

            this.ConfigSpecification(validatingUnit, referenceControl);
            this.ValidatingUnits.Add(validatingUnit);
            return(this);
        }
        /// <summary>
        /// 添加(需要验证的控件);
        /// 同时指定匹配操作、存在是否为有效;
        /// </summary>
        /// <param name="control">控件</param>
        /// <param name="match">匹配操作</param>
        /// <param name="existIsValid">存在是否为有效</param>
        /// <returns>存在验证器</returns>
        public ExistValidator Add(Control control, Func <string, bool> match, bool existIsValid)
        {
            BaseValidatingUnit <Func <string, bool> > validatingUnit = new BaseValidatingUnit <Func <string, bool> >(control);

            this.ConfigSpecification(validatingUnit, match, existIsValid);
            this.ValidatingUnits.Add(validatingUnit);
            return(this);
        }
 /// <summary>
 /// 配置验证规则;
 /// </summary>
 /// <param name="validatingUnit">验证单元</param>
 /// <param name="match">匹配操作</param>
 /// <param name="existIsValid">存在是否为有效</param>
 /// <returns></returns>
 private BaseValidatingUnit <Func <string, bool> > ConfigSpecification(BaseValidatingUnit <Func <string, bool> > validatingUnit, Func <string, bool> match, bool existIsValid)
 {
     this.ExistIsValid    = existIsValid;
     validatingUnit.Match = s => match(s.ControlText);
     //validatingUnit.AddSpecification("", existIsValid);
     validatingUnit.ErrorMessage = existIsValid ? "不存在" : "已存在";
     return(validatingUnit);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加(需要验证的控件);
 /// </summary>
 /// <param name="controls">控件</param>
 /// <returns>验证器</returns>
 public virtual BaseValidator <TSpec> Add(params Control[] controls)
 {
     foreach (var control in controls)
     {
         BaseValidatingUnit <TSpec> validatingUnit = new BaseValidatingUnit <TSpec>(control);
         this.ValidatingUnits.Add(validatingUnit);
     }
     this.GetDefaultErrorProvider();
     return(this);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 配置验证规则;
 /// </summary>
 /// <param name="validatingUnit">验证单元</param>
 /// <param name="minLength">最小长度</param>
 /// <param name="maxLength">最大长度</param>
 /// <returns>验证单元</returns>
 private BaseValidatingUnit <int> ConfigSpecification(BaseValidatingUnit <int> validatingUnit, int minLength, int maxLength)
 {
     validatingUnit.Match = this.Match;
     validatingUnit.AddSpecification("MinLength", minLength);
     validatingUnit.AddSpecification("MaxLength", maxLength);
     validatingUnit.ErrorMessage = $"长度应为{minLength}{(minLength == maxLength ? "" : $"-{maxLength}")}";