天津投入产出系统后端
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.
 
 
 
 
 
 

67 lines
2.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.TRACING.DAInterface;
using QMAPP.FJC.Entity.QT;
using QMAPP.FJC.Entity.Operation;
namespace QMAPP.FJC.TRACING.DataValidators
{
/// <summary>
/// 零部件加工时间校验
/// </summary>
public class PartTimeValidator:IDataValidator
{
public ValidateResult Validate(DAObject data, DAIValidation validOption)
{
DAL.Produce.ProductDAL pdal = new DAL.Produce.ProductDAL();
var product = data.GetObjectFromCache<Product>(p => p.PID == data.ObjectPID);
if (product == null)
{
product = pdal.GetByPID(data.ObjectPID);
if (product == null)
{
throw new Exception("查找零件信息失败!");
}
data.ObjectCacheList.Add(product);
}
if (product != null)
{
ProcessRecord processrecord = null;
DAL.QT.ProcessRecordDAL rdal = new DAL.QT.ProcessRecordDAL();
if (string.IsNullOrEmpty(validOption.ITEM_CODE)) //未特指工序名称默认查询最后一次加工记录
{
processrecord = rdal.GetLastRecord(product.PID);
}
else
{
processrecord = rdal.GetRecord(product.PID, product.PRODUCTCODE, validOption.ITEM_CODE);
}
if (processrecord != null)
{
var timespan=(DateTime.Now-processrecord.WORK_END_TIME).TotalHours;
if (validOption.LOWER_LMT > 0 && timespan < (double)validOption.LOWER_LMT)
{
return new ValidateResult(false, string.Format("未满足{1},设置为大于{0}小时,当前时间为{2:0.0}小时!", validOption.LOWER_LMT, validOption.REMARK, timespan));
}
if (validOption.UPPER_LMT > 0 && timespan > (double)validOption.UPPER_LMT)
{
return new ValidateResult(false, string.Format("未满足{1},设置为小于{0}小时,当前时间为{2:0.0}小时!", validOption.UPPER_LMT, validOption.REMARK, timespan));
}
return new ValidateResult(true, "");
}
else
{
throw new Exception("未找到相应的加工记录,请检查校验配置!");
}
}
else
{
throw new Exception("查找零件信息失败!");
}
}
}
}