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;
using QMAPP.FJC.Entity.ProductionPlan;
using QMAPP.FJC.Entity;
namespace QMAPP.FJC.TRACING.StateActions
{
///
/// 线边包装数量
///
public class PackageConsume : IStateAction
{
///
/// 执行
///
///
public void Execute(DAObject data)
{
WorkCellRunStateDAL wcrsdal = new WorkCellRunStateDAL();
var state = wcrsdal.GetNextState(data.WorkLocState.WORKCELL_CODE, data.WorkLocState.CurrentState.STATE_SEQ);
bool workcellend = state == null; //如果当前为工序最终状态
//List unsavedDai = new List();
foreach (var dai in data.WorkLocState.DataCache)
{
if (workcellend && !string.IsNullOrWhiteSpace(dai.MATERIAL_CODE) && !dai.MATERIAL_CODE.Equals(data.WorkLocState.CurrentState.MATERIAL_CODE)) //如果采集的物料号于产品物料号一直则不保存产品组成
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("UPDATE T_AW_PACKAGE ");
sql.AppendLine("SET USINGCOUNT=USINGCOUNT+1 ");
sql.AppendLine(",USINGSTATE=CASE WHEN CAPACITY>USINGCOUNT+1 THEN 1 ELSE 2 END ");
sql.AppendLine("WHERE PID IN (SELECT TOP 1 PID ");
sql.AppendLine(" FROM T_AW_PACKAGE ");
sql.AppendLine(" WHERE MATERIAL_CODE=@materialcode ");
sql.AppendLine(" AND USINGSTATE<2 ");
sql.AppendLine(" AND USINGCOUNT