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

171 lines
7.0 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:IStateAction
{
/// <summary>
/// 执行
/// </summary>
/// <param name="data"></param>
public void Execute(DAObject data)
{
var product = GetProduct(data);
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 data.WorkLocState.DataCache)
{
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)
{
QMAPP.FJC.DAL.Produce.ProductDAL dal = new QMAPP.FJC.DAL.Produce.ProductDAL();
Product product=null;
if (!string.IsNullOrEmpty(data.WorkLocState.CurrentState.PROCESS_CODE)) //如果已存在产品条码则获取产品信息
{
if (!string.IsNullOrWhiteSpace(data.WorkLocState.CurrentState.PRODUCT_PID))//如果记录了产品ID 则通过产品ID获取产品
{
product = data.GetPersistentEntity<Product>(data.WorkLocState.CurrentState.PRODUCT_PID);
if (product == null)
{
product = dal.GetByPID(data.WorkLocState.CurrentState.PRODUCT_PID, data.DataSession);
}
}
else
{
product = dal.GetByCode(data.WorkLocState.CurrentState.PROCESS_CODE, data.WorkLocState.CurrentState.MATERIAL_CODE, data.DataSession);
}
}
return product;
}
}
}