60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Configuration;
|
|||
|
using System.Globalization;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Controls;
|
|||
|
using System.Windows.Data;
|
|||
|
|
|||
|
namespace DM_Weight.Common
|
|||
|
{
|
|||
|
//设置冰箱温度规则
|
|||
|
public class TemperatureRule : ValidationRule
|
|||
|
{
|
|||
|
//冰箱温度设置区间为取自配置文件(2~8度)
|
|||
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|||
|
{
|
|||
|
bool flag = false;
|
|||
|
string tips = string.Empty;
|
|||
|
try
|
|||
|
{
|
|||
|
bool bValue = decimal.TryParse(value.ToString(), out decimal mValue);
|
|||
|
if (!bValue)
|
|||
|
{
|
|||
|
tips = "请输入正确的数值";
|
|||
|
return new ValidationResult(flag, tips);
|
|||
|
}
|
|||
|
|
|||
|
decimal f = Math.Abs(mValue - (int)mValue);
|
|||
|
if (f.ToString().Length > 3)
|
|||
|
{
|
|||
|
tips = "温度区间设置保留小数点后一位,请检查输入";
|
|||
|
return new ValidationResult(flag, tips);
|
|||
|
}
|
|||
|
string[] temperatureRange = CommonClass.ReadAppSetting("temperatureRange").Split('-');
|
|||
|
if (temperatureRange.Length > 0)
|
|||
|
{
|
|||
|
int iMin = int.Parse(temperatureRange[0]);
|
|||
|
int iMax = int.Parse(temperatureRange[1]);
|
|||
|
if (mValue < iMin || mValue > iMax)
|
|||
|
{
|
|||
|
tips = $"温度区间设置为{iMin}~{iMax}度,保留小数点后一位,请检查输入";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
flag = true;
|
|||
|
}
|
|||
|
}
|
|||
|
return new ValidationResult(flag, tips);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
tips = $"校验异常{ex.ToString()}";
|
|||
|
return new ValidationResult(flag, tips);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|