35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using DevExpress.XtraEditors.DXErrorProvider;
|
||
using System;
|
||
using System.Windows.Forms;
|
||
|
||
namespace HL_FristAidPlatform_Public
|
||
{
|
||
///<summary>
|
||
///验证值是否存在的验证规则
|
||
///</summary>
|
||
public class CustomValidationRule : ValidationRule
|
||
{
|
||
public CustomValidationRule(Func<object, bool> validationFunction)
|
||
{
|
||
this.ValidateFunction = validationFunction;
|
||
}
|
||
|
||
///<summary>
|
||
///获取或设置验证方法
|
||
///</summary>
|
||
private Func<object, bool> ValidateFunction { get; set; }
|
||
|
||
///<summary>
|
||
///验证待验证控件的值是否已存在
|
||
///</summary>
|
||
///<param name="control">待验证控件。</param>
|
||
///<param name="value">待验证控件的值</param>
|
||
///<returns>若是值已存在,返回false;不然返回true。</returns>
|
||
public override bool Validate(Control control, object value)
|
||
{
|
||
if (this.ValidateFunction == null)
|
||
throw new InvalidOperationException("必须设置ValidateFunction属性");
|
||
return ValidateFunction(value);
|
||
}
|
||
}
|
||
} |