/// <summary> /// 验证 /// </summary> /// <param name="cet"></param> /// <returns>true 验证成功 false 验证失败</returns> private bool ValidateRun(ConErrText cet) { if (cet == null) return true;// 为空则返回正确 //如果 需要非空,首先验证非空 if (cet.ve == Interface_Enum.ValidateEnum.NotEmpty) { if (string.IsNullOrWhiteSpace(cet.con.Text)) { this.dxep.SetError(cet.con, cet.errText); return false; } else { this.dxep.SetError(cet.con, string.Empty); return true; } } if( cet.ve.ToString().Length > 4 && cet.ve.ToString().Substring(0, 4) == "NotE") { if (string.IsNullOrWhiteSpace(cet.con.Text)) { this.dxep.SetError(cet.con, cet.errText); } else { this.dxep.SetError(cet.con, string.Empty); } } switch (cet.ve) { case Interface_Enum.ValidateEnum.NotE_decimal: decimal dd = 0M; return decimal.TryParse(cet.con.Text,out dd); //return Regex_Helper.Decimal(cet.con.Text); case Interface_Enum.ValidateEnum.NotE_Number: return Regex_Helper.Number(cet.con.Text); case Interface_Enum.ValidateEnum.NotE_decimal2: return Regex_Helper.DecimalLenth(cet.con.Text,2); case Interface_Enum.ValidateEnum.NotE_decimal4: return Regex_Helper.DecimalLenth(cet.con.Text, 4); case Interface_Enum.ValidateEnum.NotE_PositiveInteger: return Regex_Helper.PositiveInteger(cet.con.Text); } return false; }
/// <summary> /// 验证控件绑定非空 /// </summary> /// <param name="con">控件</param> bool I_DXErrorProvider.ValidateControl(Control con, Interface_Enum.ValidateEnum ve , string errorText) { //判断当前对象控件是否已经存在 var cet = this.l_NEcon.Where(c => con.Equals(c.con)).SingleOrDefault(); if (cet == null) { cet = new ConErrText { con = con, ve = ve, errText = errorText }; con.Validating += con_Validating; this.l_NEcon.Add(cet); } else { if (cet.ve != ve) cet.ve = ve; else if (cet.errText != errorText) cet.errText = errorText; } return this.ValidateRun(cet); }