XiangTan_JiaoJie_Bak/DM_Weight/Common/TemperatureRangeRule.cs

62 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 TemperatureRangeRule : ValidationRule
{
//冰箱温度设置区间为取自配置文件2~8度
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
bool flag = false;
string tips = string.Empty;
try
{
string[] rang = value.ToString().Split('-');
if (rang.Length >= 2)
{
bool bSRange = int.TryParse(rang[0], out int sRange);
bool bERange = int.TryParse(rang[1], out int eRange);
if (bSRange && bERange)
{
if ((sRange < 2 || eRange > 8||sRange>8||eRange<2))
{
tips = "温度区间设置2-8度请检查输入";
return new ValidationResult(flag, tips);
}
else
{
flag = true;
}
}
else
{
tips = "请输入正确的数值";
return new ValidationResult(flag, tips);
}
}
else
{
tips = "请输入正确的数值";
return new ValidationResult(flag, tips);
}
return new ValidationResult(flag, tips);
}
catch (Exception ex)
{
tips = $"校验异常{ex.ToString()}";
return new ValidationResult(flag, tips);
}
}
}
}