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.
86 lines
3.1 KiB
86 lines
3.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.TRACING.DAInterface;
|
|
using QMAPP.FJC.Entity.InterfaceData;
|
|
using System.Text.RegularExpressions;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
|
|
namespace QMAPP.FJC.TRACING.DataValidators
|
|
{
|
|
public class ParamRecordValidator : IDataValidator
|
|
{
|
|
public ValidateResult Validate(DAObject data, Entity.QT.DAIValidation validOption)
|
|
{
|
|
if (!string.Equals(data.DAI.DATA_TYPE, "SN")) //采集点类型为SN
|
|
{
|
|
return new ValidateResult(true, "");
|
|
}
|
|
if (validOption == null || string.IsNullOrEmpty(validOption.ITEM_CODE))
|
|
{
|
|
return new ValidateResult(true, "");
|
|
}
|
|
|
|
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);
|
|
}
|
|
List<string> productCodes = new List<string>();
|
|
if (!string.IsNullOrEmpty(validOption.STD_VALUE) //用正则表达式匹配是否是需要检验的条码
|
|
&& System.Text.RegularExpressions.Regex.IsMatch(product.PRODUCTCODE, validOption.STD_VALUE))
|
|
{
|
|
productCodes.Add(product.PRODUCTCODE);
|
|
}
|
|
else
|
|
{
|
|
var parts = new DAL.Operation.ProductDAL().GetPartList(product.PRODUCTCODE);
|
|
parts.Add(product);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(validOption.STD_VALUE))
|
|
{
|
|
var codes = (from p in parts
|
|
orderby p.PRODUCTCODE
|
|
where Regex.IsMatch(p.PRODUCTCODE, validOption.STD_VALUE)
|
|
select p.PRODUCTCODE).Distinct().ToList();
|
|
productCodes.AddRange(codes);
|
|
}
|
|
else
|
|
{
|
|
var codes = (from p in parts
|
|
orderby p.PRODUCTCODE
|
|
select p.PRODUCTCODE).Distinct().ToList();
|
|
productCodes.AddRange(codes);
|
|
}
|
|
}
|
|
|
|
var parmDAL = new DAL.Basic.ProcessParameterDAL();
|
|
bool record = false;
|
|
foreach (var barcode in productCodes)
|
|
{
|
|
record = parmDAL.HasParameterRecord(product.PRODUCTCODE, validOption.ITEM_CODE);
|
|
if (record)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (record)
|
|
{
|
|
return new ValidateResult(true, "");
|
|
}
|
|
else
|
|
{
|
|
return new ValidateResult(false, string.Format("零件“{0}”无{1}加工记录!", product.PRODUCTCODE,validOption.REMARK));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|