StableVersion4.3/HL_FristAidPlatform_Public/ValidateForm.cs

35 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}