天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.4 KiB

using System;
using QMAPP.FJC.TRACING.DAInterface;
using QMAPP.FJC.Entity.QT;
using QMAPP.FJC.DAL.CheckTime;
using QMAPP.FJC.Entity.CheckTime;
namespace QMAPP.FJC.TRACING.DataValidators
{
/// <summary>
/// 外购件时间验证
/// </summary>
public class ProductTimeValidator : IDataValidator
{
public ValidateResult Validate(DAObject data,DAIValidation validOption)
{
if (!string.IsNullOrEmpty(data.DAI.DA_CODE) && !string.IsNullOrEmpty(data.WorkLocState.WORKLOC_CODE) && !string.IsNullOrEmpty(data.DAValue.ToString()))
{
CHECKTIMEDAL dal = new CHECKTIMEDAL();
var listCheck = dal.SelectCheck(data.WorkLocState.WORKLOC_CODE, data.DAI.DA_CODE);
if (listCheck.Count > 0)
{
var checktime = new CHECKTIME();
checktime = listCheck[0];
if (string.IsNullOrEmpty(checktime.CodeTimeNumber) && string.IsNullOrEmpty(checktime.CodeTimeStart)) return new ValidateResult(true, "");
else
{
var pCheckColumnValue = data.DAValue.ToString().Substring(Convert.ToInt32(checktime.CodeTimeStart), Convert.ToInt32(checktime.CodeTimeNumber));
pCheckColumnValue = datetime(pCheckColumnValue);
var IsCheck = TimeOutCompare(pCheckColumnValue, checktime.Operator, checktime.Check_Value, checktime.Check_ValueTo, checktime.Check_Type);
if(IsCheck) return new ValidateResult(true, "");
else return new ValidateResult(false, "未达到时间验证标准!");
}
}
else
return new ValidateResult(true, "");
}
else
{
return new ValidateResult(true, "");
}
}
/// <summary>
/// 比较时间是否满足条码
/// </summary>
/// <param name="pCheckColumnValue">校验字段配置的值</param>
/// <param name="pOperator">操作符</param>
/// <param name="pCheck_Value">验证值</param>
/// <param name="pCheck_ValueTo">验证值2</param>
/// <param name="pCheck_Type">状态</param>
/// <returns></returns>
public static bool TimeOutCompare(string pCheckColumnValue, string pOperator, string pCheck_Value,string pCheck_ValueTo,string pCheck_Type)
{
CHECKTIMEDAL dal = new CHECKTIMEDAL();
var preStatTime = DateTime.Now;
if (!DateTime.TryParse(pCheckColumnValue, out preStatTime))
{
throw new Exception("检测值CheckColumnValue必须是DateTime类型");
}
int len = 0;
if (!int.TryParse(pCheck_Value, out len))
{
throw new Exception("验证值Check_Value必须是int类型");
}
int len2 = 0;
if (!string.IsNullOrEmpty(pCheck_ValueTo))
{
if (!int.TryParse(pCheck_ValueTo, out len2))
{
throw new Exception("验证值pCheck_ValueTo必须是int类型");
}
}
DateTime serviceTime = dal.GetServiceDateTime();
TimeSpan ts = serviceTime.Subtract(preStatTime);
if (pCheck_Type == "1")
{
switch (pOperator)
{
case ">": return ts.TotalSeconds > len;
case "<": return ts.TotalSeconds < len;
case "=": return ts.TotalSeconds == len;
case ">=": return ts.TotalSeconds >= len;
case "<=": return ts.TotalSeconds <= len;
}
}
else
{
if (ts.TotalSeconds > len && ts.TotalSeconds < len2) return true;
else return false;
}
return true;
}
public string datetime(string CodeTimeNumber)
{
if (CodeTimeNumber.Length == 12)
CodeTimeNumber = "20" + CodeTimeNumber;
return CodeTimeNumber.Substring(0, 4) + "-" + CodeTimeNumber.Substring(4, 2) + "-" + CodeTimeNumber.Substring(6, 2) + " " + CodeTimeNumber.Substring(8, 2) + ":" + CodeTimeNumber.Substring(10, 2) + ":" + CodeTimeNumber.Substring(12, 2);
}
}
}