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

78 lines
2.9 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 PartQtyValidator:IDataValidator
{
public ValidateResult Validate(DAObject data, DAIValidation validOption)
{
DAL.Produce.ProductDAL pdal = new DAL.Produce.ProductDAL();
if (string.Equals(data.DAI.DATA_TYPE, "BN")) //如果采集数据为批量件
{
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)
{
if(product.CAPACITY>product.USINGCOUNT)
{
return new ValidateResult(true, "");
}
else
{
return new ValidateResult(false, string.Format("零件“{0}”数量不足", product.PRODUCTCODE));
}
}
else
{
throw new Exception("查找零件信息失败!");
}
}
else
{
foreach (var da in data.WorkLocState.DataCache.Where(p => p.DATA_TYPE == "BN"&& !string.IsNullOrWhiteSpace(p.DA_VALUE))) //遍历检查之前输入的批量件
{
var product = data.GetObjectFromCache<Product>(p => p.PID == da.OBJ_PID);
if (product == null)
{
product = pdal.GetByPID(da.OBJ_PID);
if (product == null)
{
throw new Exception("查找零件信息失败!");
}
data.ObjectCacheList.Add(product);
}
if (product != null)
{
if (product.CAPACITY <= product.USINGCOUNT)
{
return new ValidateResult(false, string.Format("零件{1}“{0}”数量不足,请扫描新批次条码号!", product.PRODUCTCODE, product.MATERIAL_NAME));
}
}
else
{
throw new Exception("查找零件信息失败!");
}
}
return new ValidateResult(true, "");
}
}
}
}