using System; using System.Collections; using System.Collections.Generic; using ICSSoft.Frame.Data.Entity; using System.Linq; using System.Data.Linq; using System.Xml.Linq; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Frame.DataCollect; using ICSSoft.Frame.Helper; namespace ICSSoft.Frame.DataConnect.Action { /// /// 归属工单采集 /// 问题:多站同时投入同一工单时,会发生冲突 /// public class ActionGoToMO : IActionWithStatus { private FramDataContext _domainDataProvider = null; public ActionGoToMO(FramDataContext domainDataProvider) { this._domainDataProvider = domainDataProvider; } public FramDataContext DataProvider { get { return _domainDataProvider; } } public Messages CheckIn(ActionEventArgs actionEventArgs) { ((GoToMOActionEventArgs)actionEventArgs).PassCheck = true; Messages messages = new Messages(); try { DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider); //序号默认为初始,FOR 重工序列号重复 actionEventArgs.ProductInfo.NowSimulation.RCARDSEQ = ActionOnLineHelper.StartSeq; if (((GoToMOActionEventArgs)actionEventArgs).MOCode == null || ((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim() == string.Empty) { throw new Exception("$CS_Sys_GoToMO_Lost_MOParam"); } #region 检查途程 //如果ActionCheckStatus中没有检查过途程,则检查途程,并将CheckedOP设为True ICSMO mo = null; if (mo == null || mo.ISCONINPUT == "1") { if (actionEventArgs.CurrentMO != null) { mo = actionEventArgs.CurrentMO; } else { mo = (ICSMO)this.DataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == ((GoToMOActionEventArgs)actionEventArgs).MOCode && a.WorkPoint == AppConfig.WorkPointCode); actionEventArgs.CurrentMO = mo; } if (mo == null) { throw new Exception("$CS_MO_Not_Exit"); } } ICSMO2ROUTE route = null; if (route == null) { route = (ICSMO2ROUTE)dataCollectFacade.GetMONormalRouteByMOCode(mo.MOCODE); if (route == null) { throw new Exception("$CS_MOnotNormalRoute"); } } ICSITEMROUTE2OP op =null; if (op == null) { op = dataCollectFacade.GetMORouteFirstOperation(mo.MOCODE, route.ROUTECODE); } ICSBaseModel baseMode = new ICSBaseModel(this.DataProvider); if (baseMode.GetOperation2Resource(op.OPCODE, actionEventArgs.ResourceCode) == null) { throw new Exception("$CS_Route_Failed_FirstOP $Domain_MO =" + mo.MOCODE); } #endregion #region 检查是否有自动产生lot的OP维护 string itemCode = mo.ITEMCODE; object item = this.DataProvider.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == itemCode && a.WorkPoint == AppConfig.WorkPointCode); if (item == null) { throw new Exception("$Error_ItemCode_NotExist $Domain_ItemCode=" + itemCode); } #endregion #region 填写新SIMULATION actionEventArgs.ProductInfo.NowSimulation.ROUTECODE = route.ROUTECODE; actionEventArgs.ProductInfo.NowSimulation.OPCODE = op.OPCODE; actionEventArgs.ProductInfo.NowSimulation.LACTION = ActionType.DataCollectAction_GoMO; actionEventArgs.ProductInfo.NowSimulation.ACTIONLIST = ";" + ActionType.DataCollectAction_GoMO + ";"; actionEventArgs.ProductInfo.NowSimulation.RCARD = actionEventArgs.RunningCard; //序号再前面已经处理 actionEventArgs.ProductInfo.NowSimulation.TCARD = actionEventArgs.RunningCard; actionEventArgs.ProductInfo.NowSimulation.TCARDSEQ = ActionOnLineHelper.StartSeq; actionEventArgs.ProductInfo.NowSimulation.SCARD = actionEventArgs.RunningCard; actionEventArgs.ProductInfo.NowSimulation.SCARDSEQ = ActionOnLineHelper.StartSeq; actionEventArgs.ProductInfo.NowSimulation.MOCODE = mo.MOCODE; actionEventArgs.ProductInfo.NowSimulation.ITEMCODE = mo.ITEMCODE; // ICSMODEL model=null; if (model == null) { model = this.DataProvider.ICSMODEL.SingleOrDefault(a => a.MODELCODE == ((ICSINVENTORY)item).INVMODELCODE && a.WorkPoint == AppConfig.WorkPointCode); if (model == null) { throw new Exception("$CS_Model_Lost $CS_Param_ItemCode=" + mo.ITEMCODE); } } // Changed end actionEventArgs.ProductInfo.NowSimulation.MODELCODE = model.MODELCODE; actionEventArgs.ProductInfo.NowSimulation.IDMERGERULE = mo.IDMERGERULE; actionEventArgs.ProductInfo.NowSimulation.ISCOM = ProductComplete.NoComplete; actionEventArgs.ProductInfo.NowSimulation.RESCODE = actionEventArgs.ResourceCode; actionEventArgs.ProductInfo.NowSimulation.PRODUCTSTATUS = ProductStatus.GOOD; actionEventArgs.ProductInfo.NowSimulation.FROMOP = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.FROMROUTE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.CARTONCODE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.LOTNO = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.PALLETCODE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.NGTIMES = ActionOnLineHelper.StartNGTimes; actionEventArgs.ProductInfo.NowSimulation.ISHOLD = "0"; actionEventArgs.ProductInfo.NowSimulation.MOSEQ = Int32.Parse(mo.MOSEQ); actionEventArgs.ProductInfo.NowSimulation.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); actionEventArgs.ProductInfo.NowSimulation.MUSER = AppConfig.UserCode; actionEventArgs.ProductInfo.NowSimulation.MUSERName = AppConfig.UserName; actionEventArgs.ProductInfo.NowSimulation.WorkPoint = AppConfig.WorkPointCode; #endregion #region 检查工单归属 //工单归属时,如果产品别是在参数设定中的,则增加产品首检检查 object obj_SysEn = this.DataProvider.Sys_EnumValues.SingleOrDefault(a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "CHECKGOMOGROUP" && a.EnumValue == ((ICSINVENTORY)item).INVMODELCODE); if (obj_SysEn != null) { object firstCheck = dataCollectFacade.GetFirstCheckByMO(mo.MOCODE, DateTime.Now.ToString("yyyy-MM-dd")); if (firstCheck == null) { throw new Exception("$CS_MOCode_No_FirstCheck"); } else if (((ICSFIRSTCHECKBYMO)firstCheck).CHECKRESULT == "UnQualified") { throw new Exception("$CS_MOCode_FirstCheck_NotPass"); } } #endregion } catch (Exception e) { messages.Add(new Message(e)); } return messages; } public Messages CheckIn(ActionEventArgs actionEventArgs, ActionCheckStatus actionCheckStatus) { ((GoToMOActionEventArgs)actionEventArgs).PassCheck = true; Messages messages = new Messages(); try { DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider); //序号默认为初始,FOR 重工序列号重复 actionEventArgs.ProductInfo.NowSimulation.RCARDSEQ = ActionOnLineHelper.StartSeq; if (((GoToMOActionEventArgs)actionEventArgs).MOCode == null || ((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim() == string.Empty) { throw new Exception("$CS_Sys_GoToMO_Lost_MOParam"); } #region 检查途程 //如果ActionCheckStatus中没有检查过途程,则检查途程,并将CheckedOP设为True ICSMO mo = actionCheckStatus.MO; if (mo == null || mo.ISCONINPUT == "1") { if (actionEventArgs.CurrentMO != null) { mo = actionEventArgs.CurrentMO; } else { mo = (ICSMO)this.DataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == ((GoToMOActionEventArgs)actionEventArgs).MOCode && a.WorkPoint == AppConfig.WorkPointCode); actionEventArgs.CurrentMO = mo; } if (mo == null) { throw new Exception("$CS_MO_Not_Exit"); } actionCheckStatus.MO = mo; } ICSMO2ROUTE route = actionCheckStatus.Route; if (route == null) { route = (ICSMO2ROUTE)dataCollectFacade.GetMONormalRouteByMOCode(mo.MOCODE); if (route == null) { throw new Exception("$CS_MOnotNormalRoute"); } actionCheckStatus.Route = route; } ICSITEMROUTE2OP op = actionCheckStatus.OP; if (op == null) { op = dataCollectFacade.GetMORouteFirstOperation(mo.MOCODE, route.ROUTECODE); actionCheckStatus.OP = op; } if (actionCheckStatus.CheckedOP == false) { ICSBaseModel baseMode = new ICSBaseModel(this.DataProvider); if (baseMode.GetOperation2Resource(op.OPCODE, actionEventArgs.ResourceCode) == null) { throw new Exception("$CS_Route_Failed_FirstOP $Domain_MO =" + mo.MOCODE); } actionCheckStatus.CheckedOP = true; } #endregion #region 检查工单 //工单状态检查 //如果ActionCheckStatus中没有检查过工单状态,则检查,并将CheckedMO设为True if (actionCheckStatus.CheckedMO == false) { if (!dataCollectFacade.CheckMO(mo)) { throw new Exception("$CS_MO_Status_Error $CS_Param_MOStatus=$" + mo.MOSTATUS); } actionCheckStatus.CheckedMO = true; } /*1.Simulation 没有记录 * a. MO Running Card 没有重复 OK * b. MO Running Card 有重复 Exception * * 2. Simulation 有记录 * a. Simulation 工单 和 当前工单 一样 OK * b. Simulation 工单 和 当前工单 不一样 * b1. 当前工单 是重工工单 * b11. MO Running Card 没有重复 OK * b12. MO Running Card 有重复 Exception * b2. 当前工单不是重工工单 Exception * */ //如果ActionCheckStatus中没有检查过工单状态,则检查,并将CheckedMO设为True string strMOTypeParamValue = actionCheckStatus.MOTypeParamValue; if (strMOTypeParamValue == string.Empty) { actionCheckStatus.MOTypeParamValue = mo.MOTYPE; } //新增 曾经脱离过正常工单的产品序列号不允许采集 if (actionEventArgs.ProductInfo.LastSimulation != null) { //归属工单和归属工序相同也不允许 if ((mo.MOCODE == actionEventArgs.ProductInfo.LastSimulation.MOCODE)) { ((GoToMOActionEventArgs)actionEventArgs).PassCheck = false; return messages; } //建议返工工单归属采集时增加判断条件,也就是说只有没有在制记录的或者已经拆解的产品序列号才能归属返工工单 if (actionEventArgs.ProductInfo.LastSimulation.ISCOM == "0") { throw new Exception("$CS_PRODUCT_STILL_INLINE_NOT_BELONG_MO ,$CS_Param_ID " + actionEventArgs.RunningCard); } } // 投入量检查 if (mo.ISCONINPUT == "1") // 客户在工单中勾选了“限制投入量”则检查工单可投入量,否则不检查 { if (mo.MOPLANQTY - mo.MOINPUTQTY + mo.MOSCRAPQTY + mo.OFFMOQTY - mo.IDMERGERULE < 0) { throw new Exception("$CS_MOInputOut"); } } #endregion #region 检查是否有自动产生lot的OP维护 string itemCode = mo.ITEMCODE; object item = this.DataProvider.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == itemCode && a.WorkPoint == AppConfig.WorkPointCode ); if (item == null) { throw new Exception("$Error_ItemCode_NotExist $Domain_ItemCode=" + itemCode); } #endregion #region 填写新SIMULATION actionEventArgs.ProductInfo.NowSimulation.ID = AppConfig.GetGuid(); actionEventArgs.ProductInfo.NowSimulation.ROUTECODE = route.ROUTECODE; actionEventArgs.ProductInfo.NowSimulation.OPCODE = op.OPCODE; actionEventArgs.ProductInfo.NowSimulation.LACTION = ActionType.DataCollectAction_GoMO; actionEventArgs.ProductInfo.NowSimulation.ACTIONLIST = ";" + ActionType.DataCollectAction_GoMO + ";"; actionEventArgs.ProductInfo.NowSimulation.RCARD = actionEventArgs.RunningCard; //序号再前面已经处理 //actionEventArgs.ProductInfo.NowSimulation.RunningCardSequence = ActionOnLineHelper.StartSeq; //END actionEventArgs.ProductInfo.NowSimulation.TCARD = actionEventArgs.RunningCard; actionEventArgs.ProductInfo.NowSimulation.TCARDSEQ = ActionOnLineHelper.StartSeq; actionEventArgs.ProductInfo.NowSimulation.SCARD = actionEventArgs.RunningCard; actionEventArgs.ProductInfo.NowSimulation.SCARDSEQ = ActionOnLineHelper.StartSeq; actionEventArgs.ProductInfo.NowSimulation.MOCODE = mo.MOCODE; actionEventArgs.ProductInfo.NowSimulation.ITEMCODE = mo.ITEMCODE; // ICSMODEL model = actionCheckStatus.Model; if (model == null) { model = this.DataProvider.ICSMODEL.SingleOrDefault(a => a.MODELCODE == ((ICSINVENTORY)item).INVCLASS && a.WorkPoint == AppConfig.WorkPointCode); actionCheckStatus.Model = model; if (model == null) { throw new Exception("$CS_Model_Lost $CS_Param_ItemCode=" + mo.ITEMCODE); } } // Changed end actionEventArgs.ProductInfo.NowSimulation.MODELCODE = model.MODELCODE; actionEventArgs.ProductInfo.NowSimulation.IDMERGERULE = mo.IDMERGERULE; actionEventArgs.ProductInfo.NowSimulation.ISCOM = ProductComplete.NoComplete; actionEventArgs.ProductInfo.NowSimulation.RESCODE = actionEventArgs.ResourceCode; actionEventArgs.ProductInfo.NowSimulation.PRODUCTSTATUS = ProductStatus.GOOD; actionEventArgs.ProductInfo.NowSimulation.FROMOP = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.FROMROUTE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.CARTONCODE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.LOTNO = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.PALLETCODE = ActionOnLineHelper.StringNull; actionEventArgs.ProductInfo.NowSimulation.NGTIMES = ActionOnLineHelper.StartNGTimes; actionEventArgs.ProductInfo.NowSimulation.ISHOLD = "0"; actionEventArgs.ProductInfo.NowSimulation.MOSEQ = Int32.Parse(mo.MOSEQ); actionEventArgs.ProductInfo.NowSimulation.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); actionEventArgs.ProductInfo.NowSimulation.MUSER = AppConfig.UserCode; actionEventArgs.ProductInfo.NowSimulation.MUSERName = AppConfig.UserName; actionEventArgs.ProductInfo.NowSimulation.WorkPoint = AppConfig.WorkPointCode; #endregion #region 检查工单归属 //工单归属时,如果产品别是在参数设定中的,则增加产品首检检查 object obj_SysEn = this.DataProvider.Sys_EnumValues.SingleOrDefault( a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "CHECKGOMOGROUP" &&a.EnumValue==((ICSINVENTORY)item).INVMODELCODE); if (obj_SysEn != null) { object firstCheck = dataCollectFacade.GetFirstCheckByMO(mo.MOCODE, DateTime.Now.ToString("yyyy-MM-dd")); if (firstCheck == null) { throw new Exception("$CS_MOCode_No_FirstCheck"); } else if (((ICSFIRSTCHECKBYMO)firstCheck).CHECKRESULT == "UnQualified") { throw new Exception("$CS_MOCode_FirstCheck_NotPass"); } } #endregion } catch (Exception e) { messages.Add(new Message(e)); } return messages; } public Messages Execute(ActionEventArgs actionEventArgs) { ((GoToMOActionEventArgs)actionEventArgs).MOCode = ((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim().ToUpper(); actionEventArgs.RunningCard = actionEventArgs.RunningCard.Trim().ToUpper(); Messages messages = new Messages(); if (((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim() == String.Empty) { messages.Add(new Message(MessageType.Error, "$CS_Please_Input_MOCode")); } if (((GoToMOActionEventArgs)actionEventArgs).RunningCard.Trim() == String.Empty) { messages.Add(new Message(MessageType.Error, "$CS_Please_Input_RunningCard")); } DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider); try { actionEventArgs.ProductInfo.NowSimulation.EATTRIBUTE1 = (actionEventArgs as GoToMOActionEventArgs).Memo; messages.AddMessages(this.CheckIn(actionEventArgs)); if (!((GoToMOActionEventArgs)actionEventArgs).PassCheck) { throw new Exception("$序列号:" + actionEventArgs.RunningCard + "已归属工单:" + ((GoToMOActionEventArgs)actionEventArgs).MOCode + ",前往下一站采集!"); } if (messages.IsSuccess()) { ActionOnLineHelper dataCollect = new ActionOnLineHelper(this.DataProvider); // 拆箱和拆Pallet DataCollectFacade dcf = new DataCollectFacade(this.DataProvider); messages.AddMessages(dataCollect.Execute(actionEventArgs)); if (messages.IsSuccess()) { ReportHelper reportCollect = new ReportHelper(this.DataProvider); //messages.AddMessages(reportCollect.ReportLineQuanMaster(this.DataProvider, actionEventArgs.ActionType, actionEventArgs.ProductInfo)); } } } catch (Exception e) { messages.Add(new Message(e)); } return messages; } //扩展一个带ActionCheckStatus参数的方法 public Messages Execute(ActionEventArgs actionEventArgs, ActionCheckStatus actionCheckStatus) { ((GoToMOActionEventArgs)actionEventArgs).MOCode = ((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim().ToUpper(); actionEventArgs.ProductInfo.NowSimulation.EATTRIBUTE1 = (actionEventArgs as GoToMOActionEventArgs).Memo; actionEventArgs.RunningCard = actionEventArgs.RunningCard.Trim().ToUpper(); Messages messages = new Messages(); if (((GoToMOActionEventArgs)actionEventArgs).MOCode.Trim() == String.Empty) { messages.Add(new Message(MessageType.Error, "$CS_Please_Input_MOCode")); } if (((GoToMOActionEventArgs)actionEventArgs).RunningCard.Trim() == String.Empty) { messages.Add(new Message(MessageType.Error, "$CS_Please_Input_RunningCard")); } DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider); try { //调用含有ActionCheckStatus参数的CheckIn方法 messages.AddMessages(this.CheckIn(actionEventArgs, actionCheckStatus)); // add support RMA if (actionEventArgs.CurrentMO != null) { actionEventArgs.ProductInfo.NowSimulation.RMABILLCODE = actionEventArgs.CurrentMO.RMABILLCODE; } if (!((GoToMOActionEventArgs)actionEventArgs).PassCheck) { throw new Exception("$序列号:" + actionEventArgs.RunningCard + "已归属工单:" + ((GoToMOActionEventArgs)actionEventArgs).MOCode + ",前往下一站采集!"); } if (messages.IsSuccess()) { actionEventArgs.ProductInfo.NowSimulation.EATTRIBUTE1 = (actionEventArgs as GoToMOActionEventArgs).Memo; if (actionCheckStatus.NeedUpdateSimulation) { ActionOnLineHelper dataCollect = new ActionOnLineHelper(this.DataProvider); messages.AddMessages(dataCollect.Execute(actionEventArgs)); } else { ActionOnLineHelper dataCollect = new ActionOnLineHelper(this.DataProvider); messages.AddMessages(dataCollect.Execute(actionEventArgs, actionCheckStatus)); } if (messages.IsSuccess()) { if (actionCheckStatus.NeedFillReport) { ReportHelper reportCollect = new ReportHelper(this.DataProvider); //messages.AddMessages(reportCollect.ReportLineQuanMaster(this.DataProvider, actionEventArgs.ActionType, actionEventArgs.ProductInfo, actionCheckStatus)); } //将Action加入列表 actionCheckStatus.ActionList.Add(actionEventArgs); } } } catch (Exception e) { messages.Add(new Message(e)); } return messages; } private void updateItem2Route(string itemCode, string routeCode, string userCode) { DateTime mtime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); //string sql = @"UPDATE ICSITEM2ROUTE set ISREF='1',MTIME='" + mtime + "' where ITEMCODE='" + itemCode + "' and ROUTECODE='" + routeCode + "' and ISREF!='1'"; string sql = @"UPDATE ICSITEM2ROUTE set ISREF='是',MTIME='" + mtime + "' where ITEMCODE='" + itemCode + "' and ROUTECODE='" + routeCode + "' and ISREF!='是'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } public Messages AutoGoMO(ActionEventArgs actionEventArgs) { return AutoGoMO(actionEventArgs, null); } public Messages AutoGoMO(ActionEventArgs actionEventArgs, ActionCheckStatus actionCheckStatus) { Messages msg = new Messages(); // 如果当前序列号是在制品,则不会做归属工单 if (actionEventArgs.ProductInfo != null && actionEventArgs.ProductInfo.LastSimulation != null && actionEventArgs.ProductInfo.LastSimulation.ISCOM != "1") { return msg; } DateTime dbDateTime; dbDateTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); string strResCode = actionEventArgs.ResourceCode; string strRCard = actionEventArgs.RunningCard; // 解析工单 string strMOCode = ""; // 执行归属工单的操作 GoToMOActionEventArgs gomoArg = new GoToMOActionEventArgs(ActionType.DataCollectAction_GoMO, actionEventArgs.RunningCard, actionEventArgs.UserCode, actionEventArgs.ResourceCode, actionEventArgs.ProductInfo, strMOCode); IAction gomoAction = new ActionFactory(this.DataProvider).CreateAction(ActionType.DataCollectAction_GoMO); try { if (actionCheckStatus != null) { msg.AddMessages(((IActionWithStatus)gomoAction).Execute(gomoArg, actionCheckStatus)); } else { msg.AddMessages(gomoAction.Execute(gomoArg)); } } catch (Exception e) { msg.Add(new Message(e)); } if (msg.IsSuccess() == true) { if (actionCheckStatus == null || actionCheckStatus.NeedUpdateSimulation == true) { ActionOnLineHelper onLine = new ActionOnLineHelper(this.DataProvider); Messages msgProduct = onLine.GetIDInfo(actionEventArgs.RunningCard); actionEventArgs.ProductInfo = (ProductInfo)msgProduct.GetData().Values[0]; } else { actionEventArgs.ProductInfo.LastSimulation = new ExtendSimulation(gomoArg.ProductInfo.NowSimulation); actionCheckStatus.ProductInfo.LastSimulation = actionEventArgs.ProductInfo.LastSimulation; } } return msg; } public void ShowMessage() { } } }