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

125 lines
5.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.MD.DAL;
namespace QMAPP.FJC.TRACING.DataValidators
{
/// <summary>
/// 采集点输入顺序校验
/// </summary>
public class DASequenceValidator:IDataValidator
{
public ValidateResult Validate1(DAObject data, DAIValidation validOption)
{
if (data.DAI.DA_SEQ <= 1) //第一个采集点无需验证
{
return new ValidateResult(true, "");
}
else
{
//查询前置采集点采集值为空的项
var preDa = (from dai in data.WorkLocState.DataCache
where dai.DA_SEQ < data.DAI.DA_SEQ //采集顺序小于当前采集点
&& string.IsNullOrWhiteSpace(dai.DA_VALUE) //采集值为空
&& !string.Equals(dai.DA_MODE,"2") //采集模式不是可忽略的
orderby dai.DA_SEQ descending
select dai).FirstOrDefault();
if (preDa == null)
{
return new ValidateResult(true, "");
}
else
{
return new ValidateResult(
false,
string.Format("在输入“{0}”前应先输入“{1}”!",data.DAI.DA_NAME,preDa.DA_NAME));
}
}
}
public ValidateResult Validate(DAObject data, DAIValidation validOption)
{
if (data.DAI.DA_SEQ <= 1) //第一个采集点无需验证
{
return new ValidateResult(true, "");
}
else
{
//查询前置采集点采集值为空的项
var preDa = (from dai in data.WorkLocState.DataCache
where dai.DA_SEQ < data.DAI.DA_SEQ //采集顺序小于当前采集点
&& string.IsNullOrWhiteSpace(dai.DA_VALUE) //采集值为空
//&& !string.Equals(dai.DA_MODE, "2") //采集模式不是可忽略的
//&& !string.Equals(dai.DA_MODE, "5") //采集模式不是可忽略的
orderby dai.DA_SEQ descending
select dai).ToList();
if (preDa.Count < 1)
{
return new ValidateResult(true, "");
}
else
{
if (preDa.Exists(p => p.DA_MODE != "5"&&p.DA_MODE != "2"))
{
var req_da = preDa.FirstOrDefault(p => p.DA_MODE != "5" && p.DA_MODE != "2");
return new ValidateResult(
false,
string.Format("在输入“{0}”前应先输入“{1}”!", data.DAI.DA_NAME, req_da.DA_NAME));
}
//提取采集数据中的物料号信息
var materials = (from da in data.WorkLocState.DataCache
where !string.IsNullOrWhiteSpace(da.MATERIAL_CODE)
&& !string.Equals(da.DA_MODE, "2") //过滤掉可省略的采集点
//&& !string.Equals(da.DA_MODE, "3") //过滤掉自适应采集点
&& !string.Equals(da.DA_MODE, "5") //过滤掉自适应采集点
&& !string.Equals(da.DA_CODE, data.DAI.DA_CODE) //过滤掉当前输入的采集点
select da.MATERIAL_CODE).ToList();
PbomDAL dal = new PbomDAL();
materials.Add(data.MaterialCode + "");
MD.Entity.View.BomLocation bomloc = null;
if (string.IsNullOrWhiteSpace(data.WorkLocState.CurrentState.MATERIAL_CODE))
{
var bomlocates = dal.LocateBom(materials.Distinct().ToArray()); //匹配物料BOM
if (bomlocates.Count > 0)
{
if (data.OrderPlan != null)
{
bomloc = bomlocates.FirstOrDefault(p => p.BOMCode == data.OrderPlan.PBOM_CODE);
}
else if (bomlocates.GroupBy(p => p.UP_MATERIAL_CODE).ToList().Count == 1)
{
bomloc = bomlocates[0];
}
}
}
else
{
var bomlocates = dal.LocateBomByUpMaterial(data.WorkLocState.CurrentState.MATERIAL_CODE);
if (bomlocates.Count > 0)
{
bomloc = bomlocates[0];
}
}
if (bomloc != null)
{
var bomitems = dal.GetBomItemsByLocateWithType(bomloc); //查找组成物料列表
foreach (var da in preDa.Where(p => p.DA_MODE == "5" || p.DA_MODE == "2"))
{
if (bomitems.Exists(p => p.MATERIAL_TYPE_CODE == da.MATERIAL_TYPE || p.UP_MATERIAL_TYPE_CODE == da.MATERIAL_TYPE))
{
return new ValidateResult(
false,
string.Format("请先输入“{1}”,当前生产产品“{1}”为必须项!", data.DAI.DA_NAME, da.DA_NAME));
}
}
}
return new ValidateResult(true, "");
}
}
}
}
}