using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Controls; namespace Muchinfo.MTPClient.Infrastructure.ValidationRules { /// /// 数据范围验证 /// public class DataRangeValidationRules:ValidationRule { private decimal _minValue =0; public decimal MinValue { get { return _minValue; } set { _minValue = value; } } private decimal _maxValue=decimal.MaxValue; public decimal MaxValue { get { return _maxValue; } set { _maxValue = value; } } public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { if (value == null) { return new ValidationResult(false,null); } if (string.IsNullOrEmpty(value.ToString())) { return new ValidationResult(false, null); } if (decimal.Parse(value.ToString()) < MinValue || decimal.Parse(value.ToString()) > MaxValue) { return new ValidationResult(false, "数字范围错误!"); } return new ValidationResult(true, null); } } }