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

238 lines
10 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.DAL.QT;
using QMAPP.FJC.Entity.QT;
using QMAPP.FJC.TRACING.DAInterface;
using QMAPP.FJC.DAL.Produce;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.DAL.Operation;
using QMAPP.FJC.Entity.Basic;
using QMAPP.MD.Entity;
using QMAPP.MD.DAL;
using QMAPP.MD.Entity.View;
namespace QMAPP.FJC.TRACING.StateActions
{
/// <summary>
/// 回滚数据
/// </summary>
public class RollbackData_4UF:IStateAction
{
/// <summary>
/// 执行
/// </summary>
/// <param name="data"></param>
public void Execute(DAObject data)
{
foreach (var processcodeda in data.WorkLocState.DataCache.Where(p => p.ISPROCESSCODE == "1" && !string.IsNullOrEmpty(p.DA_VALUE)))
{
List<DAICache> dagroup = new List<DAICache>();
dagroup.Add(processcodeda);
dagroup.AddRange(data.WorkLocState.DataCache.Where(p => p.ISPROCESSCODE != "1"));
//搜索确认产品物料号
SearchMaterial(data, dagroup);
var product = GetProduct(data,dagroup);
if (product != null) //如果存在产品信息
{
if (data.WorkLocState.DataCache.FirstOrDefault(p => p.MATERIAL_CODE == product.MATERIAL_CODE) == null) //产品为新生成的物料
{
product.IsDelete = true;
}
else
{
product.WORKLOC_CODE = "";
}
data.AddToPersistentList(product, product.PID);
DeleteProcessRecord(product, data);
foreach (var dai in dagroup)
{
if (dai.SAVED.Contains(data.MouldCode) && !string.IsNullOrWhiteSpace(dai.DA_VALUE)) //过滤已保存过的和采集值为空值的
{
switch (dai.DATA_TYPE)
{
case "SN": //零件序列号
case "BN": //零件批次号
{
DeleteProductStructure(product, dai, data);
break;
}
case "MN": //模具编号
{
DeleteProcessParam(product, dai, data);
break;
}
case "PARM": //加工参数
{
DeleteProcessParam(product, dai, data);
break;
}
}
dai.SAVED = dai.SAVED.Replace(data.MouldCode, "");
}
}
//删除参数的指令
var cmdDelParm = new SQLCommand("DELETE T_QT_PROCESSPARAMETERS WHERE PRODUCT_PID=@productid AND WORKCELL_CODE=@workcell"
, new DataParameter("productid", product.PID)
, new DataParameter("workcell", data.WorkLocState.WORKCELL_CODE));
data.SQLCommands.Add(cmdDelParm);
//删除产品组成的指令
//var cmdDelStruct = new SQLCommand("DELETE T_QT_PRODUCT_STRUCTURE WHERE PRODUCT_PID=@productid"
// , new DataParameter("productid", product.PID));
//data.SQLCommands.Add(cmdDelStruct);
}
}
}
/// <summary>
/// 删除产品组成信息
/// </summary>
/// <param name="product">产品</param>
/// <param name="dai"></param>
/// <param name="data"></param>
private void DeleteProductStructure(Product product, DAICache dai, DAObject data)
{
if (!dai.MATERIAL_CODE.Equals(product.MATERIAL_CODE)) //如果采集的物料号于产品物料号一直则不修改产品组成
{
QMAPP.FJC.DAL.Produce.ProductDAL proddal = new QMAPP.FJC.DAL.Produce.ProductDAL();
Product part = null;
part= data.GetPersistentEntity<Product>(dai.OBJ_PID);
if (part == null)
{
part = proddal.GetByPID(dai.OBJ_PID, data.DataSession);
}
part.USINGCOUNT = part.USINGCOUNT - 1;
part.USINGSTATE = part.USINGCOUNT == 0 ? "0" : "1";
//part.UPDATEDATE = DateTime.Now;
part.UPDATEUSER=data.UserID;
data.AddToPersistentList(part, dai.OBJ_PID);
ProductStructureDAL psdal = new ProductStructureDAL();
var structure= psdal.GetStructure(product.PID,part.PID);
if (structure != null)
{
structure.IsDelete = true;
data.AddToPersistentList(structure, structure.PID);
}
}
}
/// <summary>
/// 删除加工参数
/// </summary>
/// <param name="product"></param>
/// <param name="dai"></param>
private void DeleteProcessParam(Product product, DAICache dai,DAObject data)
{
}
/// <summary>
/// 删除加工记录
/// </summary>
private void DeleteProcessRecord(Product product, DAObject data)
{
ProcessRecordDAL prdal = new ProcessRecordDAL();
ProcessRecord record = null;
record = data.GetPersistentEntity<ProcessRecord>(product.PID);//加工记录的ID使用PRODUCT的ID代替
if (record == null)
{
record = prdal.Get(product.PID, data.WorkLocState.WORKCELL_CODE, data.DataSession);
}
if (record != null)
{
record.IsDelete = true;
data.AddToPersistentList(record, product.PID);//加工记录的ID使用PRODUCT的ID代替
//prdal.Update(record, data.DataSession);
}
}
/// <summary>
/// 获取产品信息
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private Product GetProduct(DAObject data,List<DAICache> dagroup)
{
QMAPP.FJC.DAL.Produce.ProductDAL dal = new QMAPP.FJC.DAL.Produce.ProductDAL();
Product product=null;
string sn = (from da in dagroup
where string.Equals(da.ISPROCESSCODE, "1")
select da.DA_VALUE).FirstOrDefault();
product = dal.GetByCode(sn, data.WorkLocState.CurrentState.MATERIAL_CODE, data.DataSession);
return product;
}
/// <summary>
/// 搜索确定加工后的产品物料号及加工消耗的物料号
/// </summary>
/// <param name="data"></param>
/// <returns>返回加工消耗物料</returns>
private string[] SearchMaterial(DAObject data, List<DAICache> dagroup)
{
var materials = (from da in dagroup
where !string.IsNullOrWhiteSpace(da.MATERIAL_CODE)
select da.MATERIAL_CODE).ToArray();
if (materials.Length == 1) //单一物料加工
{
data.WorkLocState.CurrentState.MATERIAL_CODE = materials[0];
var dai = dagroup.FirstOrDefault(p => p.MATERIAL_CODE == materials[0]);
data.WorkLocState.CurrentState.PROCESS_CODE = dai.DA_VALUE;
//data.WorkLocState.CurrentState.PRODUCT_PID = dai.OBJ_PID;
}
else //多物料组成
{
var bomlocation = GetBomLocation(materials.Distinct().ToArray());
if (bomlocation == null) //未定位到
{
materials = (from da in dagroup
where !string.IsNullOrWhiteSpace(da.MATERIAL_CODE)
&& !string.Equals(da.DA_MODE, "2") //过滤掉可省略的采集点
select da.MATERIAL_CODE).ToArray();
bomlocation = GetBomLocation(materials.Distinct().ToArray());
if (bomlocation == null) //仍未定位到BOM信息 抛出异常
{
throw new Exception("采集数据有误,无法确定生产BOM,请检查采集点配置和BOM配置!");
}
}
string upperlevelmaterial = "";
if (bomlocation.ItemNo > 0) //如果Bom定位为明细项
{
PbomDAL pbidal = new PbomDAL();
var bomitem = pbidal.GetByLocate(bomlocation);
if (bomitem != null)
{
upperlevelmaterial = bomitem.MATERIAL_CODE;
}
}
else //如果Bom定位为Bom头
{
var bom = new PbomDAL().GetByCode(bomlocation.BOMCode);
if (bom != null)
{
upperlevelmaterial = bom.MATERIAL_CODE;
}
}
data.WorkLocState.CurrentState.MATERIAL_CODE = upperlevelmaterial; //取得产品物料号
}
return materials.Distinct().ToArray();
}
/// <summary>
/// 根据物料组获取上层物料号
/// </summary>
/// <param name="materials"></param>
/// <returns></returns>
private BomLocation GetBomLocation(params string[] materials)
{
PbomDAL pbidal = new PbomDAL();
var bomlocations = pbidal.LocateBom(materials);
//确定物料组成数量一致
var bomlocation = bomlocations.FirstOrDefault(p => p.SubCount == materials.Length);
return bomlocation;
}
}
}