/// <summary> /// 注册验证规则 /// </summary> /// <param name="control">控件</param> /// <param name="validateFunc">验证函数</param> /// <param name="errorMessage">错误消息</param> /// <param name="isFocusControl">错误时是否激活控件焦点</param> public void RegisterRule(BaseEdit control, Func <bool> validateFunc, string errorMessage, bool isFocusControl) { ValidateRule item = new ValidateRule(); item.Control = control; item.IsFocusControl = isFocusControl; item.ValidateFun = validateFunc; item.Message = errorMessage; if (ValidateRules == null) { ValidateRules = new List <ValidateRule>(); } ValidateRules.Add(item); }
/// <summary> /// 验证控件 如果控件为空验证全部规则 /// </summary> /// <param name="control">控件</param> /// <returns>验证成功返回true</returns> public bool ValidateControl(BaseEdit control) { ValidateRule rule = GetFirstValidateRule(control); if (rule != null) { if (rule.Message.IsNotEmpty()) { XtraMessageBoxHelper.ShowWarning(rule.Message); } if (rule.IsFocusControl) { rule.Control.SelectAll(); rule.Control.Select(); } return(false); } return(true); }