using System; using System.Collections; using System.Reflection; using System.Runtime.Remoting; using System.Text.RegularExpressions; using System.Linq; using System.Data.Linq; using System.Xml; using System.IO; using ICSSoft.Base.Config.AppConfig; using System.Collections.Specialized; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.DataConnect.Action; using System.Data; using ICSSoft.Frame.DataCollect; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Helper; using System.Collections.Generic; namespace ICSSoft.Frame.DataConnect { /// /// DataCollectFacade 的摘要说明。 /// 文件名: DataCollectFacade.cs /// 描 述: /// 版 本: /// public class DataCollectFacade { public const string ISMAINROUTE_TRUE = "1"; private FramDataContext _domainDataProvider = null; public DataCollectFacade() { } public const string PID = "PID"; public const string HID = "HID"; public const string POWER = "POWER"; public DataCollectFacade(FramDataContext domainDataProvider) { this._domainDataProvider = domainDataProvider; } public FramDataContext DataProvider { get { return _domainDataProvider; } } #region 检查 /// /// 只支持线上的采集,TS、REWORK、线外站应该自己检查、填写 /// /// /// /// /// /// /// public Messages CheckID(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { return CheckID(iD, actionType, resourceCode, userCode, product, null); } // // 扩展一个带ActionCheckStatus参数的方法 public Messages CheckID(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, ActionCheckStatus actionCheckStatus) { // 检查actionCheckStatus中的MOCode是否与product中的一致 if (actionCheckStatus != null) { if (actionCheckStatus.ProductInfo != null) { //新增 判断LastSimulation为Null的情况 if (actionCheckStatus.ProductInfo.LastSimulation != null) { if (actionCheckStatus.ProductInfo.LastSimulation.MOCODE != product.LastSimulation.MOCODE) { actionCheckStatus = new ActionCheckStatus(); } } } } // Added end Messages messages = new Messages(); try { DoCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); } catch (Exception e) { messages.Add(new Message(e)); } return messages; } //,新增 检查 private void DoCheck(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { if (product.CurrentMO == null) { this.CheckMO(product.LastSimulation.MOCODE, product); } else { this.CheckMO(product.CurrentMO); } this.GetRouteOPOnline(iD, actionType, resourceCode, userCode, product); this.CheckCardStatus(product); this.CheckRepeatCollect(actionType, product); //if first op,break off carton information if (GetMORouteFirstOperation(product.NowSimulation.MOCODE, product.NowSimulation.ROUTECODE).OPCODE == product.CurrentItemRoute2OP.OPCODE) { if (product.NowSimulation.CARTONCODE != String.Empty) { //Package.PackageFacade pf = new Package.PackageFacade(DataProvider); //pf.SubtractCollected(((ExtendSimulation)product.LastSimulation).CARTONCODE); } ((ExtendSimulation)product.LastSimulation).CARTONCODE = String.Empty; product.NowSimulation.CARTONCODE = String.Empty; } } private void DoCheck(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, ActionCheckStatus actionCheckStatus) { if (actionCheckStatus == null || actionCheckStatus.CheckedID == false) { if (actionCheckStatus == null || actionCheckStatus.CheckedMO == false) { this.CheckMO(product.LastSimulation.MOCODE, product); if (actionCheckStatus != null) { actionCheckStatus.CheckedMO = true; } } this.GetRouteOPOnline(iD, actionType, resourceCode, userCode, product, actionCheckStatus); if (actionCheckStatus != null) { actionCheckStatus.CheckedID = true; } } else { this.GetRouteOPOnline(iD, actionType, resourceCode, userCode, product, actionCheckStatus); } // 是否重复采集 this.CheckCardStatus(product); this.CheckRepeatCollect(actionType, product); } //根据前一次Simulation 结果, 预先填 新的 Simulation 记录 public Messages WriteSimulation(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { Messages messages = new Messages(); try { product.NowSimulation.ID = AppConfig.GetGuid(); product.NowSimulation.MOCODE = product.LastSimulation.MOCODE; product.NowSimulation.ITEMCODE = product.LastSimulation.ITEMCODE; product.NowSimulation.MODELCODE = product.LastSimulation.MODELCODE; product.NowSimulation.IDMERGERULE = product.LastSimulation.IDMERGERULE; product.NowSimulation.RCARD = iD; product.NowSimulation.RCARDSEQ = product.LastSimulation.RCARDSEQ + 1; product.NowSimulation.TCARD = product.LastSimulation.TCARD; product.NowSimulation.TCARDSEQ = product.LastSimulation.TCARDSEQ; product.NowSimulation.SCARD = product.LastSimulation.SCARD; product.NowSimulation.SCARDSEQ = product.LastSimulation.SCARDSEQ; product.NowSimulation.FROMROUTE = ActionOnLineHelper.StringNull; product.NowSimulation.FROMOP = ActionOnLineHelper.StringNull; product.NowSimulation.ROUTECODE = product.LastSimulation.ROUTECODE; product.NowSimulation.OPCODE = product.LastSimulation.OPCODE; product.NowSimulation.RESCODE = resourceCode; product.NowSimulation.PRODUCTSTATUS = ProductStatus.GOOD; product.NowSimulation.LACTION = actionType; product.NowSimulation.ACTIONLIST = string.Format("{0}{1};", product.LastSimulation.ACTIONLIST, actionType); //检查是否完工 TODO product.NowSimulation.ISCOM = ProductComplete.NoComplete; product.NowSimulation.CARTONCODE = product.LastSimulation.CARTONCODE; product.NowSimulation.LOTNO = product.LastSimulation.LOTNO; product.NowSimulation.PALLETCODE = product.LastSimulation.PALLETCODE; product.NowSimulation.NGTIMES = product.LastSimulation.NGTIMES; // product.NowSimulation.RMABILLCODE = product.LastSimulation.RMABILLCODE; product.NowSimulation.MOSEQ = product.LastSimulation.MOSEQ; DateTime dbDateTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); product.NowSimulation.MTIME = dbDateTime; product.NowSimulation.MUSER = AppConfig.UserCode; product.NowSimulation.MUSERName = AppConfig.UserName; product.NowSimulation.WorkPoint = AppConfig.WorkPointCode; } catch (Exception e) { messages.Add(new Message(e)); } return messages; } public ICSSimulation CloneSimulation(ICSSimulation simulation) { ICSSimulation returnValue = CreateNewSimulation(); Type simulationType = typeof(ICSSimulation); FieldInfo[] fieldInfoList = simulationType.GetFields(); if (fieldInfoList != null) { foreach (FieldInfo fieldInfo in fieldInfoList) { fieldInfo.SetValue(returnValue, fieldInfo.GetValue(simulation)); } } return returnValue; } /// /// 检查ID在一个工单中是否已经被使用 /// /// 改传参SQL /// /// /// /// public ICSONWIP CheckIDIsUsed(string id, string moCode) { string sql = @"select * from ICSONWIP where RCARD='" + id + "'and MOCODE='" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIP)objs[0]; } #region 检查 //ID状态检查 public bool CheckCardStatus(ProductInfo productInfo) { if (productInfo.LastSimulation.PRODUCTSTATUS != ProductStatus.GOOD) { if (((ExtendSimulation)productInfo.LastSimulation).AdjustProductStatus != ProductStatus.GOOD) /* 允许脱离工单*/ { throw new Exception("$CS_ProductStatusError $CS_Param_ProductStatus=" + productInfo.LastSimulation.PRODUCTSTATUS + " $CS_Param_ID=" + productInfo.LastSimulation.RCARD); } } return true; } //工单状态检查 public bool CheckMO(string moCode) { ICSMO mo = (ICSMO)this.DataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode); //工单状态检查 bool moStatus = this.CheckMO(mo); if (!moStatus) { throw new Exception("$CS_MOStatus_Error $CS_Param_MOStatus=$" + mo.MOSTATUS); } return moStatus; } public bool CheckMO(string moCode, ProductInfo product) { ICSMO mo = null; if (product.CurrentMO == null) { mo = (ICSMO)this.DataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode); } else { mo = product.CurrentMO; } //工单状态检查 bool moStatus = this.CheckMO(mo); if (!moStatus) { throw new Exception("$CS_MOStatus_Error $CS_Param_MOStatus=$" + mo.MOSTATUS); } product.CurrentMO = mo; return moStatus; } //工单状态检查 public bool CheckMO(ICSMO mo) { if ((mo.MOSTATUS == MOManufactureStatus.MOSTATUS_RELEASE) || (mo.MOSTATUS == MOManufactureStatus.MOSTATUS_OPEN)) return true; else return false; } private const char isSelected = '1'; //根据工序设定检查动作可否在该工序做 public bool CheckAction(ProductInfo productInfo, object op, string actionType) { string opCode = string.Empty; string opControl = "0000000000000000000000"; if (op is ICSOP) { opCode = ((ICSOP)op).OPCODE; opControl = ((ICSOP)op).OPCONTROL; } if (op is ICSITEMROUTE2OP) { opCode = ((ICSITEMROUTE2OP)op).OPCODE; opControl = ((ICSITEMROUTE2OP)op).OPCONTROL; } return true;// this.CheckActionOnlineAndOutline(actionType, opCode, opControl); } public void CheckRepeatCollect(string actionType, ProductInfo product) { switch (product.LastSimulation.LACTION) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_OutLineReject: switch (actionType) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: //线外工序允许二次采集NG //if (product.l != null && product.LastTS.RunningCardSequence != product.LastSimulation.RunningCardSequence) //{ // this.CheckRepeatCollect(product.LastSimulation.RunningCard, product.LastSimulation.ActionList, actionType); //} product.NowSimulation.ACTIONLIST = string.Format("{0}{1};", product.LastSimulation.ACTIONLIST, actionType); break; default: product.NowSimulation.ACTIONLIST = string.Format(";{0};", actionType); break; } break; case ActionType.DataCollectAction_NG: case ActionType.DataCollectAction_SMTNG: case ActionType.DataCollectAction_OQCNG: case ActionType.DataCollectAction_Reject: product.NowSimulation.ACTIONLIST = string.Format(";{0};", actionType); break; default: switch (actionType) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: product.NowSimulation.ACTIONLIST = string.Format(";{0};", actionType); break; default: if (product.LastSimulation.OPCODE == product.NowSimulation.OPCODE) { this.CheckRepeatCollect(product.LastSimulation.RCARD, product.LastSimulation.ACTIONLIST, actionType); product.NowSimulation.ACTIONLIST = string.Format("{0}{1};", product.LastSimulation.ACTIONLIST, actionType); } else { product.NowSimulation.ACTIONLIST = string.Format(";{0};", actionType); } break; } break; } } public void CheckRepeatCollect(string rcard, string actionList, string action) { actionList = ";" + actionList + ";"; switch (action) { case ActionType.DataCollectAction_GoMO: if (actionList.IndexOf(";" + ActionType.DataCollectAction_GoMO + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; /*添加脱离工单*/ case ActionType.DataCollectAction_OffMo: { if (actionList.IndexOf(";" + ActionType.DataCollectAction_OffMo + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; } case ActionType.DataCollectAction_DropMaterial: { if (actionList.IndexOf(";" + ActionType.DataCollectAction_DropMaterial + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; } case ActionType.DataCollectAction_SMTGOOD: case ActionType.DataCollectAction_GOOD: case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OQCGood: string[] actions = actionList.Split(new char[] { ';' }); //if (actions.Length > 2) //因为上面在actionList的前后都加了分号 if (actions.Length > 3) { //string lastAction = actions[actions.Length - 2]; //因为上面在actionList的前后都加了分号 string lastAction = actions[actions.Length - 3]; if (lastAction == ActionType.DataCollectAction_GOOD || lastAction == ActionType.DataCollectAction_GOOD || lastAction == ActionType.DataCollectAction_SMTGOOD || lastAction == ActionType.DataCollectAction_OutLineGood || lastAction == ActionType.DataCollectAction_OQCGood) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } } break; case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_SMTNG: case ActionType.DataCollectAction_NG: case ActionType.DataCollectAction_OQCNG: case ActionType.DataCollectAction_OutLineReject: if (actionList.IndexOf(";" + ActionType.DataCollectAction_NG + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } if (actionList.IndexOf(";" + ActionType.DataCollectAction_SMTNG + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } if (actionList.IndexOf(";" + ActionType.DataCollectAction_OutLineNG + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCReject + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCNG + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_CollectINNO: if (actionList.IndexOf(";" + ActionType.DataCollectAction_CollectINNO + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_CollectKeyParts: if (actionList.IndexOf(";" + ActionType.DataCollectAction_CollectKeyParts + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_ECN: if (actionList.IndexOf(";" + ActionType.DataCollectAction_ECN + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_OQCLotAddID: if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCLotAddID + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_OQCLotRemoveID: if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCLotRemoveID + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_TRY: if (actionList.IndexOf(";" + ActionType.DataCollectAction_TRY + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_SoftINFO: if (actionList.IndexOf(";" + ActionType.DataCollectAction_SoftINFO + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_Split: if (actionList.IndexOf(";" + ActionType.DataCollectAction_Split + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_Reject: case ActionType.DataCollectAction_OQCReject: if (actionList.IndexOf(";" + ActionType.DataCollectAction_Reject + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCReject + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_OQCPass: if (actionList.IndexOf(";" + ActionType.DataCollectAction_OQCPass + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_BurnIn: if (actionList.IndexOf(";" + ActionType.DataCollectAction_BurnIn + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_BurnOut: if (actionList.IndexOf(";" + ActionType.DataCollectAction_BurnOut + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; case ActionType.DataCollectAction_Carton: if (actionList.IndexOf(";" + ActionType.DataCollectAction_Carton + ";") >= 0) { throw new Exception("$CS_RepeatCollect_OnOneOP $CS_Param_ID :" + rcard); } break; default: throw new Exception("$CS_Sys_Error_CheckRepeatCollect_Failed $CS_Param_Action=" + action + " $CS_Param_ID :" + rcard); } } //维修处理 public object GetCardLastTSRecordInNewStatus(string rcard) { string sql = "SELECT * FROM icsts WHERE rcard='" + rcard + "' and workpoint = '"+AppConfig.WorkPointCode+"' order by tstimes desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSTS)objs[0]; } /// /// ** 功能描述: 由产品序列号获得最新的一笔维修记录 /// ** 修 改: /// ** 日 期: /// /// /// public ICSTS GetCardLastTSRecord(string runningCard) { return GetCardLastTSRecord(runningCard, string.Empty); } public ICSTS GetCardLastTSRecord(string runningCard, string moCode) { string sql = string.Empty; sql += " SELECT * "; sql += " FROM icsts "; sql += string.Format(" WHERE rcard = '{0}' ", runningCard.Trim()); if (moCode.Trim().Length > 0) { sql += string.Format(" AND mocode = '{0}' ", moCode.Trim()); } sql += " And workpoint='"+AppConfig.WorkPointCode+"'"; sql += " ORDER BY mtime desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSTS)objs[0]; } //Online 检查途程OP是否存在 public void GetRouteOPOnline(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { GetRouteOPOnline(iD, actionType, resourceCode, userCode, product, null); } public void GetRouteOPOnline(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, Action.ActionCheckStatus actionCheckStatus) { switch (product.LastSimulation.LACTION) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_OutLineReject: switch (actionType) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_OutLineReject: throw new Exception("$CS_Route_Failed_Need_Call_CheckRouteOPOutline"); default: this.AdjustRouteOPOnline(iD, actionType, resourceCode, userCode, product); this.CheckOnlineOP(iD, actionType, resourceCode, userCode, product); break; } break; case ActionType.DataCollectAction_NG: case ActionType.DataCollectAction_SMTNG: case ActionType.DataCollectAction_Reject: case ActionType.DataCollectAction_OQCReject: case ActionType.DataCollectAction_OQCNG: switch (actionType) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_OutLineReject: throw new Exception("$CS_Route_Failed_Need_Call_CheckRouteOPOutline"); case ActionType.DataCollectAction_OQCReject: { this.AdjustRouteOPOnline(iD, actionType, resourceCode, userCode, product); this.CheckOnlineOPSingle(iD, actionType, resourceCode, userCode, product); break; } default: this.AdjustRouteOPOnline(iD, actionType, resourceCode, userCode, product); this.CheckOnlineOPSingle(iD, actionType, resourceCode, userCode, product, actionCheckStatus); break; } break; default: switch (actionType) { case ActionType.DataCollectAction_OutLineGood: case ActionType.DataCollectAction_OutLineNG: throw new Exception("$CS_Route_Failed_Need_Call_CheckRouteOPOutline"); default: this.AdjustRouteOPOnline(iD, actionType, resourceCode, userCode, product); this.CheckOnlineOP(iD, actionType, resourceCode, userCode, product, actionCheckStatus); break; } break; } } public void AdjustRouteOPOnline(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { ICSTS ts = GetCardLastTSRecord(iD, product.LastSimulation.MOCODE); if (ts != null) { #region 报废的情况 报废和拆解不能够再次进入产线 if (ts != null && ts.FRMINPUTTYPE == "tssource_onwip" && ts.TSSTATUS == TSStatus.TSStatus_Scrap) { if (ts.FRMROUTECODE == product.LastSimulation.ROUTECODE && ts.FRMOPCODE == product.LastSimulation.OPCODE && ts.MOCODE == product.LastSimulation.MOCODE && ts.RCARD == product.LastSimulation.RCARD) { throw new Exception("$CS_Error_Product_Already_Scrap"); } } #endregion #region 处理回流的情况 if (ts != null && ts.TSSTATUS == TSStatus.TSStatus_Reflow) { if (ts.RCARDSEQ == product.LastSimulation.RCARDSEQ) { ((ExtendSimulation)product.LastSimulation).AdjustProductStatus = ProductStatus.GOOD; ((ExtendSimulation)product.LastSimulation).NextRouteCode = ts.REFROUTECODE; ((ExtendSimulation)product.LastSimulation).NextOPCode = ts.REFOPCODE; if (ts.REFOPCODE.Length == 0) { ICSITEMROUTE2OP itemOP = GetMORouteFirstOperation(product.LastSimulation.MOCODE, ts.REFROUTECODE); if (itemOP != null) { if (((ExtendSimulation)product.LastSimulation).NextOPCode == null || ((ExtendSimulation)product.LastSimulation).NextOPCode.Trim().Length <= 0) { ((ExtendSimulation)product.LastSimulation).NextOPCode = itemOP.OPCODE; ((ExtendSimulation)product.LastSimulation).AdjustProductStatus = ProductStatus.GOOD; } } else { throw new Exception("$CS_Route_Lost_First_OP_Of_Route" + " : " + ts.REFROUTECODE); } } } } #endregion } if (((ExtendSimulation)product.LastSimulation).NextRouteCode == null || ((ExtendSimulation)product.LastSimulation).NextRouteCode.Trim().Length <= 0) { ((ExtendSimulation)product.LastSimulation).NextRouteCode = product.LastSimulation.ROUTECODE; } if (((ExtendSimulation)product.LastSimulation).NextOPCode == null || ((ExtendSimulation)product.LastSimulation).NextOPCode.Trim().Length <= 0) { ((ExtendSimulation)product.LastSimulation).NextOPCode = product.LastSimulation.OPCODE; } } private void CheckMaterialAndTest(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { CheckMaterialAndTest(iD, actionType, resourceCode, userCode, product, null); } private void CheckMaterialAndTest(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, Action.ActionCheckStatus actionCheckStatus) { //#region 处理测试和上料在同一道工序 ////默认会在当前站做下一个动作{hight} ////L测试和上料Action 在进入下一站前必须完成上料 ////FQC判GOOD、判Pass、判退排除在外 ///*增加逻辑检查上一个工序是否按照用户的设置完整了集成上料Action和KeyParts上料Action的检查; // * 试流料部分有客户在业务上保证。 // * 具体的逻辑将更新在数据采集模组的Spec中,由RD决定整合方式。 // * 目前没有做Rework的检查 // */ //if ( // ActionType.DataCollectAction_SMTGOOD == actionType // || ActionType.DataCollectAction_SMTNG == actionType // || ActionType.DataCollectAction_GOOD == actionType // || ActionType.DataCollectAction_NG == actionType // || ActionType.DataCollectAction_OQCGood == actionType // || ActionType.DataCollectAction_OQCNG == actionType // || ActionType.DataCollectAction_OQCPass == actionType) //{ // object currentOP = null; // if (product.CurrentItemRoute2OP != null) // { // currentOP = product.CurrentItemRoute2OP; // } // else // { // currentOP = (new ItemFacade(this._domainDataProvider)).GetItemRoute2Operation(product.NowSimulation.ITEMCODE, product.NowSimulation.ROUTECODE, product.NowSimulation.OPCODE); // product.CurrentItemRoute2OP = currentOP as ICSITEMROUTE2OP; // } // if (currentOP == null) // { // if (product.LastSimulation != null && product.LastSimulation.ISCOM == "1") // { // throw new Exception("$CS_PRODUCT_ALREADY_COMPLETE $CS_Param_OPCode =" + product.LastSimulation.OPCODE); // } // else // { // throw new Exception("$CS_Route_Failed_GetNotNextOP"); // } // } // string opControls = ((ICSITEMROUTE2OP)currentOP).OPCONTROL; // if (opControls != null && opControls.Length > 2) // { // if (opControls.Substring(0, 2).Trim() == "11" // || (FormatHelper.StringToBoolean(opControls, (int)OperationList.Testing) // && FormatHelper.StringToBoolean(opControls, (int)OperationList.ComponentDown))) // { // BenQGuru.eMES.Rework.ReworkFacade reworkFacade = new BenQGuru.eMES.Rework.ReworkFacade(this.DataProvider); // BenQGuru.eMES.Domain.Rework.ReworkSheet rSheet = (BenQGuru.eMES.Domain.Rework.ReworkSheet)reworkFacade.GetReworkSheetByReject(product.LastSimulation.RCARD, product.LastSimulation.RCARDSEQ); // //统计KeyParts的个数 // int keypartTimes = 0; // //统计Inno的个数 // int innoTimes = 0; // object[] objs = null; // ArrayList listTmp = new ArrayList(); // if (actionCheckStatus != null) // { // for (int iaction = 0; iaction < actionCheckStatus.ActionList.Count; iaction++) // { // ActionEventArgs actionEventArgs = (ActionEventArgs)actionCheckStatus.ActionList[iaction]; // if (actionEventArgs is CINNOActionEventArgs || actionEventArgs is CKeypartsActionEventArgs) // { // for (int iwip = 0; iwip < actionEventArgs.OnWIP.Count; iwip++) // { // if (actionEventArgs.OnWIP[iwip] is ICSONWIPITEM) // { // ICSONWIPITEM wipItem = (ICSONWIPITEM)actionEventArgs.OnWIP[iwip]; // ONWIPItemObject wipObj = new ONWIPItemObject(); // wipObj.MCARD = wipItem.MCARD; // wipObj.MCardType = wipItem.MCARDTYPE; // wipObj.OPCODE = wipItem.OPCODE; // wipObj.RunningCard = wipItem.RCARD; // wipObj.RunningCardSequence = wipItem.RCARDSEQ.ToString(); // listTmp.Add(wipObj); // } // } // } // } // } // if (listTmp.Count > 0) // { // objs = new object[listTmp.Count]; // listTmp.CopyTo(objs); // } // if (objs == null || objs.Length == 0) // { // objs = this.ExtraQuery(product.NowSimulation.RCARD // , product.NowSimulation.OPCODE // , product.NowSimulation.MOCODE // , product.LastSimulation.LACTION, product); // } // string opBOMType = actionCheckStatus == null ? String.Empty : actionCheckStatus.opBOMType; // if (opBOMType == string.Empty) // { // //获取OPBOM中维护的料信息 // OPBOMFacade opFac = new OPBOMFacade(this._domainDataProvider); // if (FormatHelper.StringToBoolean(opControls, (int)OperationList.ComponentDown)) // { // opBOMType = opFac.GetOPDropBOMDetailType( // product.NowSimulation.MOCODE // , product.NowSimulation.ROUTECODE // , ((ICSITEMROUTE2OP)currentOP).OPCODE // , out keypartTimes // , out innoTimes); // //考虑分板比率 // keypartTimes = Convert.ToInt32(keypartTimes * product.LastSimulation.IDMERGERULE); // } // else // { // opBOMType = opFac.GetOPBOMDetailType( // product.NowSimulation.MOCODE // , product.NowSimulation.ROUTECODE // , ((ICSITEMROUTE2OP)currentOP).OPCODE // , out keypartTimes // , out innoTimes); // //考虑分板比率 // keypartTimes = Convert.ToInt32(keypartTimes * product.LastSimulation.IDMERGERULE); // } // if (actionCheckStatus != null) // { // actionCheckStatus.opBOMType = opBOMType; // actionCheckStatus.keypartTimes = keypartTimes; // actionCheckStatus.innoTimes = innoTimes; // } // } // else // { // if (actionCheckStatus != null) // { // keypartTimes = actionCheckStatus.keypartTimes; // innoTimes = actionCheckStatus.innoTimes; // } // } // //如果当前是Rework工单的话,统计次数 // int iCount = 1; // if (rSheet != null && rSheet.ReworkType == Web.Helper.ReworkType.REWORKTYPE_ONLINE) // { // object[] objReworks = reworkFacade.QueryReworkSheet(rSheet.ReworkCode); // if (objReworks != null && objReworks.Length > 0) // { // for (int i = 0; i < objReworks.Length; i++) // { // BenQGuru.eMES.Domain.Rework.ReworkSheet rs = (BenQGuru.eMES.Domain.Rework.ReworkSheet)objReworks[i]; // if (rs.ReworkType == Web.Helper.ReworkType.REWORKTYPE_ONLINE) // { // object[] objOPS = (new MOModel.ItemFacade(this._domainDataProvider)).QueryItem2Operation(rs.ItemCode, rs.NewRouteCode); // for (int j = 0; j < objOPS.Length; j++) // { // ICSITEMROUTE2OP i2op = (ICSITEMROUTE2OP)objOPS[j]; // if (i2op.OPCODE == product.LastSimulation.OPCODE) // { // iCount += 1; // } // } // } // } // } // //product.LastSimulation.FromRoute // } // keypartTimes = keypartTimes * iCount; // innoTimes = innoTimes * iCount; // if (objs == null || (objs != null && objs.Length < 1)) // { // if (BenQGuru.eMES.Web.Helper.FormatHelper.StringToBoolean(product.CurrentItemRoute2OP.OPCONTROL, (int)OperationList.ComponentLoading)) // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // if (BenQGuru.eMES.Web.Helper.FormatHelper.StringToBoolean(product.CurrentItemRoute2OP.OPCONTROL, (int)OperationList.ComponentDown)) // { // throw new Exception("$CS_PLEASE_COMPLETE_DROPMATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_DropMaterial) // { // throw new Exception("$CS_PLEASE_COMPLETE_DROPMATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // else // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // string actionList = String.Empty; // //实际上了KeyParts个数 // int actualKeyParts = 0; // //实际上了Inno个数 // int actualInnos = 0; // string keyPartsString = ActionType.DataCollectAction_CollectKeyParts; // string INNOString = ActionType.DataCollectAction_CollectINNO; // string bomKeyPartsString = BOMItemControlType.ITEM_CONTROL_KEYPARTS; // string bomINNOString = BOMItemControlType.ITEM_CONTROL_LOT; // if (objs != null) // { // foreach (ONWIPItemObject wip in objs) // { // if (wip.MCardType == MCardType.MCardType_Keyparts) // { // actionList = actionList + keyPartsString + ";"; // actualKeyParts += 1; // } // if (wip.MCardType == MCardType.MCardType_INNO) // { // actionList = actionList + INNOString + ";"; // //修改 只允许一次集成上料 // actualInnos = 1; // } // } // } // if (actionList.IndexOf(INNOString) < 0 // && actionList.IndexOf(keyPartsString) < 0) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_DropMaterial) // { // throw new Exception("$CS_PLEASE_DROP_INNO_KEYPARTS $CS_Param_ID =" + product.LastSimulation.RCARD); // } // else // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // return; // } // //检查KeyParts上料的情况 // if (opBOMType.IndexOf(bomKeyPartsString) >= 0 // && opBOMType.IndexOf(bomINNOString) < 0) // { // if (actionList.IndexOf(keyPartsString) < 0 // || actualKeyParts < keypartTimes) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_DropMaterial) // { // throw new Exception("$CS_PLEASE_DROP_INNO_KEYPARTS $CS_Param_ID =" + product.LastSimulation.RCARD); // } // else // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // if (actionList.IndexOf(keyPartsString) >= 0 && actualKeyParts > keypartTimes && actualKeyParts != 0) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectKeyParts) // { // throw new Exception("$CS_ALREADY_COLLECTMATIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // } // //检查集成上料的情况 // if (opBOMType.IndexOf(bomKeyPartsString) < 0 // && opBOMType.IndexOf(bomINNOString) >= 0) // { // if (actionList.IndexOf(INNOString) < 0 // || actualInnos < innoTimes) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_DropMaterial) // { // throw new Exception("$CS_PLEASE_DROP_INNO_KEYPARTS $CS_Param_ID =" + product.LastSimulation.RCARD); // } // else // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // if (actionList.IndexOf(INNOString) >= 0 && actualInnos > innoTimes && actualInnos != 0) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectINNO) // { // throw new Exception("$CS_ALREADY_COLLECTMATIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // } // //两者都存在的状况 // if (opBOMType.IndexOf(bomKeyPartsString) >= 0 // && opBOMType.IndexOf(bomINNOString) >= 0) // { // if (actionList.IndexOf(INNOString) < 0 // || actionList.IndexOf(keyPartsString) < 0 // || actualInnos < innoTimes // || actualKeyParts < keypartTimes) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_DropMaterial) // { // throw new Exception("$CS_PLEASE_DROP_INNO_KEYPARTS $CS_Param_ID =" + product.LastSimulation.RCARD); // } // else // { // throw new Exception("$CS_PLEASE_COMPLETE_MATERIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // if ((actionList.IndexOf(INNOString) >= 0 && actualInnos > innoTimes && actualInnos != 0) // || (actionList.IndexOf(keyPartsString) >= 0 && actualKeyParts > keypartTimes && actualKeyParts != 0)) // { // if (product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectKeyParts // || product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectINNO) // { // throw new Exception("$CS_ALREADY_COLLECTMATIAL $CS_Param_ID =" + product.LastSimulation.RCARD); // } // } // } // } // } //} //#endregion } //OUT_Line -> OQC OUT_Line -> Normal 必须走变换后指定 Route + OP public ICSITEMROUTE2OP CheckOnlineOPSingle(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { return CheckOnlineOPSingle(iD, actionType, resourceCode, userCode, product, null); } // 扩展ActionCheckStatus public ICSITEMROUTE2OP CheckOnlineOPSingle(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, Action.ActionCheckStatus actionCheckStatus) { if (actionCheckStatus != null) { if (actionCheckStatus.CheckedNextOP == true && actionCheckStatus.OP != null) { bool bPass = false; //当前站 if (product.LastSimulation.NextOPCode == actionCheckStatus.OP.OPCODE && product.LastSimulation.NextRouteCode == actionCheckStatus.OP.ROUTECODE) { bPass = true; } if (bPass == true) { this.WriteSimulationCheckOnlineOP(iD, actionType, resourceCode, userCode, product); OtherCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); return actionCheckStatus.OP; } } } ICSBaseModel dataModel = new ICSBaseModel(this.DataProvider); //下一站必须采集 if (dataModel.GetOperation2Resource(((ExtendSimulation)product.LastSimulation).NextOPCode, resourceCode) != null) { ICSITEMROUTE2OP op = this.GetMORouteOP(product.LastSimulation.ITEMCODE, product.LastSimulation.MOCODE, ((ExtendSimulation)product.LastSimulation).NextRouteCode, ((ExtendSimulation)product.LastSimulation).NextOPCode, product); if (op == null) { /*Burn In 漏扫时,如果到了FT,提示“该产品已经完工或者被替换”这个提示要修改,以便让USER知道是在哪里完工了,并提示要从第一站投入。 建议如果报该提示的时候,即发现该产品已经完工,先不要直接报出来,在后面再加一条检查,检查其完工工序,并报出来。毕竟这种情况不是很多,所以性能方面的顾虑可以排除掉。 * */ if (product.LastSimulation != null && product.LastSimulation.ISCOM == "1") { throw new Exception("$CS_PRODUCT_ALREADY_COMPLETE $CS_Param_OPCode =" + product.LastSimulation.OPCODE); } else { throw new Exception("$CS_Route_Failed_GetNotNextOP"); } } this.WriteSimulationCheckOnlineOP(iD, actionType, resourceCode, userCode, product); OtherCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); if (actionCheckStatus != null) { actionCheckStatus.OP = op; actionCheckStatus.CheckedNextOP = true; actionCheckStatus.CheckedNextOPCode = product.LastSimulation.OPCODE; actionCheckStatus.CheckedNextRouteCode = product.LastSimulation.NextRouteCode; } return op; } else { throw new Exception("$CS_Route_Failed_GetNextOP_Online_Line $CS_Param_ID =" + product.LastSimulation.RCARD); } } public void OtherCheck(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { OtherCheck(iD, actionType, resourceCode, userCode, product, null); } public void OtherCheck(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, Action.ActionCheckStatus actionCheckStatus) { //上料和测试同时做的情况 switch (product.LastSimulation.LACTION) { case ActionType.DataCollectAction_OutLineGood: //检查上料Action和测试Action是否在同一道工序 string route = product.LastSimulation.ROUTECODE; string opcode = product.LastSimulation.OPCODE; //临时赋值 product.LastSimulation.ROUTECODE = product.LastSimulation.FROMROUTE; product.LastSimulation.OPCODE = product.LastSimulation.FROMOP; CheckMaterialAndTest(iD, actionType, resourceCode, userCode, product, actionCheckStatus); //恢复正常值 product.LastSimulation.ROUTECODE = route; product.LastSimulation.OPCODE = opcode; break; case ActionType.DataCollectAction_OutLineNG: case ActionType.DataCollectAction_NG: case ActionType.DataCollectAction_SMTNG: case ActionType.DataCollectAction_OQCNG: //检查上料Action和测试Action是否在同一道工序 CheckMaterialAndTest(iD, actionType, resourceCode, userCode, product, actionCheckStatus); break; case ActionType.DataCollectAction_Reject: break; default: //检查上料Action和测试Action是否在同一道工序 CheckMaterialAndTest(iD, actionType, resourceCode, userCode, product, actionCheckStatus); break; } } public ICSITEMROUTE2OP CheckOnlineOP(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { return CheckOnlineOP(iD, actionType, resourceCode, userCode, product, null); } public ICSITEMROUTE2OP CheckOnlineOP(string iD, string actionType, string resourceCode, string userCode, ProductInfo product, Action.ActionCheckStatus actionCheckStatus) { if (actionCheckStatus != null) { if (actionCheckStatus.CheckedNextOP == true && actionCheckStatus.OP != null) { bool bPass = false; //当前站 if (product.LastSimulation.NextOPCode == actionCheckStatus.OP.OPCODE && product.LastSimulation.NextRouteCode == actionCheckStatus.OP.ROUTECODE) { bPass = true; } else if (product.LastSimulation.NextOPCode == actionCheckStatus.CheckedNextOPCode && product.LastSimulation.NextRouteCode == actionCheckStatus.CheckedNextRouteCode) { //下一站 bPass = true; ((ExtendSimulation)product.LastSimulation).NextOPCode = actionCheckStatus.OP.OPCODE; } if (bPass == true) { this.WriteSimulationCheckOnlineOP(iD, actionType, resourceCode, userCode, product); OtherCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); return actionCheckStatus.OP; } } } //BaseModelFacade dataModel = new BaseModelFacade(this.DataProvider); ICSITEMROUTE2OP op; //下一站,当前站可以走 ICSBaseModel dataModel = new ICSBaseModel(this.DataProvider); if (dataModel.GetOperation2Resource(((ExtendSimulation)product.LastSimulation).NextOPCode, resourceCode) != null) { op = this.GetMORouteOP(product.LastSimulation.ITEMCODE, product.LastSimulation.MOCODE, ((ExtendSimulation)product.LastSimulation).NextRouteCode, ((ExtendSimulation)product.LastSimulation).NextOPCode, product); if (op == null) { /*Burn In 漏扫时,如果到了FT,提示“该产品已经完工或者被替换”这个提示要修改,以便让USER知道是在哪里完工了,并提示要从第一站投入。 建议如果报该提示的时候,即发现该产品已经完工,先不要直接报出来,在后面再加一条检查,检查其完工工序,并报出来。毕竟这种情况不是很多,所以性能方面的顾虑可以排除掉。 * */ if (product.LastSimulation != null && product.LastSimulation.ISCOM == "1") { throw new Exception("$CS_PRODUCT_ALREADY_COMPLETE $CS_Param_OPCode =" + product.LastSimulation.OPCODE); } else { throw new Exception("$CS_Route_Failed_GetNotNextOP"); } } this.WriteSimulationCheckOnlineOP(iD, actionType, resourceCode, userCode, product); OtherCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); if (actionCheckStatus != null) { actionCheckStatus.OP = op; actionCheckStatus.CheckedNextOP = true; actionCheckStatus.CheckedNextOPCode = product.LastSimulation.OPCODE; actionCheckStatus.CheckedNextRouteCode = product.LastSimulation.NextRouteCode; } return op; } else { op = this.GetMORouteNextOperation(product.LastSimulation.MOCODE, ((ExtendSimulation)product.LastSimulation).NextRouteCode, ((ExtendSimulation)product.LastSimulation).NextOPCode); if (op == null) { /*Burn In 漏扫时,如果到了FT,提示“该产品已经完工或者被替换”这个提示要修改,以便让USER知道是在哪里完工了,并提示要从第一站投入。 建议如果报该提示的时候,即发现该产品已经完工,先不要直接报出来,在后面再加一条检查,检查其完工工序,并报出来。毕竟这种情况不是很多,所以性能方面的顾虑可以排除掉。 * */ if (product.LastSimulation != null && product.LastSimulation.ISCOM == "1") { throw new Exception("产品已经完工, 工序 =" + product.LastSimulation.OPCODE); } else { throw new Exception("$CS_Route_Failed_GetNotNextOP"); } } //直接做归属工单,不允许到下一站采集 if (product.LastSimulation.LACTION == ActionType.DataCollectAction_GoMO && product.LastSimulation.OPCODE != op.OPCODE) { throw new Exception("$CS_Route_Failed_GetNotNextOP $CS_Param_OPCode =" + product.LastSimulation.OPCODE); } //判断当前登陆资源和工序是否匹配 ICSOP2RES op2Res = dataModel.GetOperationByResource(resourceCode); if (op2Res.OPCODE != op.OPCODE) { throw new Exception("产品采集工序为:" + op.OPCODE + ",当前工序为: " + op2Res.OPCODE); } // End Added if (actionCheckStatus != null) { actionCheckStatus.OP = op; actionCheckStatus.CheckedNextOP = true; actionCheckStatus.CheckedNextOPCode = product.LastSimulation.OPCODE; actionCheckStatus.CheckedNextRouteCode = product.LastSimulation.NextRouteCode; } ((ExtendSimulation)product.LastSimulation).NextOPCode = op.OPCODE; this.WriteSimulationCheckOnlineOP(iD, actionType, resourceCode, userCode, product); OtherCheck(iD, actionType, resourceCode, userCode, product, actionCheckStatus); return op; } } public void WriteSimulationCheckOnlineOP(string iD, string actionType, string resourceCode, string userCode, ProductInfo product) { this.WriteSimulation(iD, actionType, resourceCode, userCode, product); product.NowSimulation.ROUTECODE = ((ExtendSimulation)product.LastSimulation).NextRouteCode; product.NowSimulation.OPCODE = ((ExtendSimulation)product.LastSimulation).NextOPCode; } #endregion 检查 /// /// /// /// /// 只需要填写增加数 public void UpdateMOOutPut(string moCode, int outPutQty) { string sql = @"UPDATE ICSMO SET MOACTQTY=MOACTQTY+'" + outPutQty + "' where MOCODE='" + moCode + "'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } #region 工单途程信息 //工序是否为途程最后一个工序 public bool OPIsMORouteLastOP(string moCode, string routeCode, string opCode) { ICSBaseModel baseModel = new ICSBaseModel(this.DataProvider); return baseModel.OperationIsRouteLastOperation(moCode, routeCode, opCode); } //工单途程工序信息 public ICSITEMROUTE2OP GetMORouteOP(string itemCode, string moCode, string routeCode, string curOp, ProductInfo e) { if (e.CurrentItemRoute2OP == null) { e.CurrentItemRoute2OP = GetItemRoute2Operation(itemCode, routeCode, curOp); }//考虑到途程和工序变换的case else if (e.CurrentItemRoute2OP != null && (e.CurrentItemRoute2OP.OPCODE != curOp || e.CurrentItemRoute2OP.ROUTECODE != routeCode)) { e.CurrentItemRoute2OP = GetItemRoute2Operation(itemCode, routeCode, curOp); } return e.CurrentItemRoute2OP; } #region 根据生产订单号查询工单途程 public ICSMO2ROUTE GetMONormalRouteByMOCode(string moCode) { var obj = QueryMORoutes(moCode, string.Empty, ISMAINROUTE_TRUE); if (obj != null) { return (ICSMO2ROUTE)obj; } return null; } #endregion public ICSMO2ROUTE QueryMORoutes(string moCode, string routeCode) { return QueryMORoutes(moCode, routeCode, string.Empty, string.Empty); } public ICSMO2ROUTE QueryMORoutes(string moCode, string routeCode, string isMainRoute) { return QueryMORoutes(moCode, routeCode, isMainRoute, string.Empty); } public ICSMO2ROUTE QueryMORoutes(string moCode, string routeCode, string isMainRoute, string opBOMVersion) { string sql = @"select * from ICSMO2ROUTE where "; string tmpString = " 1=1 "; if ((moCode != string.Empty) && (moCode.Trim() != string.Empty)) { tmpString += " and MOCODE = '" + moCode.Trim() + "'"; } if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty)) { tmpString += " and ROUTECODE ='" + routeCode.Trim() + "'"; } //if ((isMainRoute != string.Empty) && (isMainRoute.Trim() != string.Empty)) //{ // tmpString += " and ISMROUTE ='" + isMainRoute.Trim() + "'"; //} if ((opBOMVersion != string.Empty) && (opBOMVersion.Trim() != string.Empty)) { tmpString += " and OPBOMVER ='" + opBOMVersion.Trim() + "'"; } var objs = this._domainDataProvider.ExecuteQuery(sql + tmpString).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSMO2ROUTE)objs[0]; } #region 工单途程的一道工序 public ICSITEMROUTE2OP GetMORouteFirstOperation(string moCode) { var mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode); if (mo == null) { throw new Exception("$Error_MONotExisted"); } var mo2route = GetMONormalRouteByMOCode(moCode); string sql = @" select * from ICSITEMROUTE2OP where ITEMCODE='" + mo.ITEMCODE + "' and ROUTECode='" + ((ICSMO2ROUTE)mo2route).ROUTECODE + "' and OPSEQ = (select min(OPSEQ) from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + mo2route.ROUTECODE + "' and workpoint = '" + AppConfig.WorkPointCode + "' ) and workpoint = '" + AppConfig.WorkPointCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null) { throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, ((ICSMO2ROUTE)mo2route).ROUTECODE)); } return (ICSITEMROUTE2OP)objs[0]; } public ICSITEMROUTE2OP GetMORouteFirstOperation(string moCode, string routeCode) { var mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode); if (mo == null) { throw new Exception("$Error_MONotExisted"); } string sql = @" select * from ICSITEMROUTE2OP where ITEMCODE='" + mo.ITEMCODE + "' and ROUTECode='" + routeCode + "' and OPSEQ = (select min(OPSEQ) from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and workpoint = '" + AppConfig.WorkPointCode + "' ) and workpoint = '" + AppConfig.WorkPointCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null) { throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, routeCode)); } return (ICSITEMROUTE2OP)objs[0]; } #endregion # region 查看下一道工序 public ICSITEMROUTE2OP GetMORouteNextOperation(string moCode, string routeCode, string opCode) { var mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode); if (mo == null) { throw new Exception("$Error_MONotExisted"); } string sql = @" select * from ICSITEMROUTE2OP where ITEMCODE= '" + mo.ITEMCODE + "' and ROUTECODE='" + routeCode + "' and OPSEQ > (select OPSEQ from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and opcode='" + opCode + "' and workpoint = '" + AppConfig.WorkPointCode + "') and workpoint = '" + AppConfig.WorkPointCode + "' order by opseq"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSITEMROUTE2OP)objs[0]; } #endregion #region 查询某工单的所有序列号个数 public int GetMO2RCardLinkCount(string moCode) { string sql = "SELECT COUNT(*) FROM ICSMO2RCARD WHERE MOCODE='" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return 0; else return (objs.Count); } #endregion #region 查询工单首检记录数量 public int QueryFirstCheckByMOCount(string moCode, int checkDate) { string sql = @"select count(*) from ICSFIRSTCHECKBYMO A left join ICSMO B on A.MOCODE = B.MOCODE left join ICSINVENTORY C on B.ITEMCODE = C.INVCODE where 1=1"; if (!String.IsNullOrEmpty(moCode)) { sql += " and A.MOCODE = '" + moCode + "'"; } if (checkDate > 0) { sql += " and A.CHECKDATE = '" + checkDate + "'"; } var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return 0; else return (objs.Count); } #endregion #region 根据生产订单号查询工单首检记录 public ICSFIRSTCHECKBYMO GetFirstCheckByMO(string moCode, string checkDate) { string sql = @"select * from ICSFIRSTCHECKBYMO where MOCODE='" + moCode + "' and CHECKDATE='" + checkDate + "'"; var obj = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (obj != null && obj.Count > 0) { return (ICSFIRSTCHECKBYMO)obj[0]; } return null; } #endregion public ICSITEMROUTE2OP GetItemRoute2Operation(string itemCode, string routeCode, string opCode) { string sql = @"select * from ICSITEMROUTE2OP where ITEMCODE='" + itemCode + "' and ROUTECODE='" + routeCode + "' and OPCODE ='" + opCode + "'"; var obj = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (obj == null || obj.Count < 1) { throw new Exception("$Error_ItemRoute_NotExisted"); } return (ICSITEMROUTE2OP)obj[0]; } #region 判断工序是否属于产品途程工序 public bool IsOPInItemOP(string itemCode, int orgID, string OPCode) { string sql = @"SELECT COUNT (*) FROM ICSITEMROUTE2OP WHERE ITEMCODE = '" + itemCode + "' AND OPCODE = '" + OPCode + "' "; var obj = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (obj == null || obj.Count < 1) { return false; } else { return true; } } #endregion public ICSITEMROUTE2OP QueryItemRoute2Op(string routeCode, string itemCode) { string sql = @"SELECT COUNT (*) FROM ICSITEMROUTE2OP WHERE ITEMCODE = '" + itemCode + "' AND ROUTECODE = '" + routeCode + "' "; var obj = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (obj == null || obj.Count < 1) { throw new Exception("$Error_ItemRoute_NotExisted"); } return (ICSITEMROUTE2OP)obj[0]; } #endregion 工单途程信息 #endregion #region 序列号转换采集 //ID:转换前序列号;必须 //Resrouce:当前机台资源名称;必须 //UserCode:操作用户;必须 // Language:语言开关,0 英文,1 中文,目前只提供中文 //返回值:“OK” 表示检查通过,其他为错误信息 public string CheckIDRoute(string ID, string Resrouce, string UserCode, int Language)//此方法在哪边调用??????? { ID = ID.Trim().ToUpper(); Resrouce = Resrouce.Trim().ToUpper(); UserCode = UserCode.Trim().ToUpper(); if (ID == string.Empty) return "$CS_IDisNull"; if (Resrouce == string.Empty) return "$CS_ResrouceisNull"; if (UserCode == string.Empty) return "$CS_UserCodeisNull"; ActionOnLineHelper onLine = new ActionOnLineHelper(this.DataProvider); Messages messages1 = onLine.GetIDInfo(ID); if (messages1.IsSuccess()) { //((Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection(); //try //{ // ProductInfo product = (ProductInfo)messages1.GetData().Values[0]; // messages1.AddMessages(onLine.CheckID(new ActionEventArgs(ActionType.DataCollectAction_IDTran, ID, // UserCode, Resrouce, // product // ))); // if (!messages1.IsSuccess()) // return GetErrorMessage(messages1); // return "OK"; //} //catch //{ //} //finally //{ // ((Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection(); //} return ""; } else { return GetErrorMessage(messages1); } } public string GetErrorMessage(Messages messages) { for (int i = 0; i < messages.Count(); i++) { Message message = messages.Objects(i); if (message.Type == MessageType.Error) { if (message.Body == string.Empty) return message.Exception.Message; else return (message.Body); } } // return messages.Debug(); return "$CS_System_unKnowError"; } public string GetRuningCard(string sCard, string moCode) { string sql = ""; if (string.IsNullOrEmpty(moCode.Trim())) { sql = @"SELECT top 1 * FROM icssimulation WHERE scard = '" + sCard + "' AND mocode = '" + moCode + "'" + " ORDER BY mdate DESC, mtime DESC"; } else { sql = @"SELECT top 1 * FROM icssimulation WHERE scard = '" + sCard + "'" + " ORDER BY mdate DESC, mtime DESC"; } var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return ""; else return ((ICSSimulation)objs[0]).RCARD; } #endregion #region Simulation /// /// /// public ICSSimulation CreateNewSimulation() { return new ICSSimulation(); } public void AddSimulation(ICSSimulation simulation) { this._domainDataProvider.ICSSimulation.InsertOnSubmit(simulation); this._domainDataProvider.SubmitChanges(); } public void UpdateSimulation(ICSSimulation simulation) { var line = this._domainDataProvider.ICSSimulation.SingleOrDefault(a => a.RCARD == simulation.RCARD && a.WorkPoint == AppConfig.WorkPointCode); if (line != null) { this._domainDataProvider.ICSSimulation.DeleteOnSubmit(line); } this._domainDataProvider.ICSSimulation.InsertOnSubmit(simulation); } public void UpdateSimulationReport(ICSSimulationReport simulationReport) { var line = this._domainDataProvider.ICSSimulationReport.SingleOrDefault(a => a.RCARD == simulationReport.RCARD && a.WorkPoint == AppConfig.WorkPointCode); if (line != null) { this._domainDataProvider.ICSSimulationReport.DeleteOnSubmit(line); } this._domainDataProvider.ICSSimulationReport.InsertOnSubmit(simulationReport); } public void DeleteSimulation(ICSSimulation simulation) { var line = this._domainDataProvider.ICSSimulation.Where(a => a.RCARD == simulation.RCARD && a.WorkPoint == simulation.WorkPoint); this._domainDataProvider.ICSSimulation.DeleteAllOnSubmit(line); } public void UpdateSimulationForLot(string rCard, string moCode, string lotNo) { string sql = "UPDATE ICSSimulation SET LOTNO='" + lotNo + "' WHERE RCARD='" + rCard + "' AND MOCODE='" + moCode + "'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } // End Added /// /// /// 改传参SQL /// /// /// // public object GetSimulation(string runningCard) // { // object[] simulations = this.DataProvider.CustomQuery(typeof(Simulation), // //new SQLParamCondition(string.Format("select {0} from TBLSIMULATION where RCARD = $RCARD order by MDATE desc,MTIME desc", // new SQLParamCondition(string.Format( // @"select {0} from // (select A.* // from TBLSIMULATION A // where RCARD = $RCARD // order by A.MDATE desc, A.MTIME desc) // where rownum = 1", // DomainObjectUtility.GetDomainObjectFieldsString(typeof(Simulation))), // new SQLParameter[] { new SQLParameter("RCARD", typeof(string), runningCard.ToUpper()) })); // if (simulations == null) // return null; // if (simulations.Length > 0) // return simulations[0]; // else // return null; // } public ICSSimulation GetSimulation(string runningCard) { string sql = "SELECT * FROM ICSSimulation WHERE RCARD = '" + runningCard + "' ORDER BY MTIME DESC "; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetSimulationByRCardOrTCard(string runningCard) { string sql = @"select * from ICSSimulation where RCARD = '" + runningCard + "' or TCARD='" + runningCard + "'order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } // public object GetSimulationByRCardOrTCard(string runningCard) // { // object[] simulations = this.DataProvider.CustomQuery(typeof(Simulation), // //new SQLParamCondition(string.Format("select {0} from TBLSIMULATION where RCARD = $RCARD order by MDATE desc,MTIME desc", // new SQLParamCondition(string.Format( // @"select {0} from tblsimulation where // (rcard,mocode) in ( // select rcard, mocode // from (select rcard, mocode // from TBLSIMULATION // where RCARD = $RCARD // OR TCARD=$RCARD // order by MDATE desc, MTIME desc) // where rownum = 1)", // DomainObjectUtility.GetDomainObjectFieldsString(typeof(Simulation))), // new SQLParameter[] { new SQLParameter("RCARD", typeof(string), runningCard.ToUpper()), new SQLParameter("RCARD", typeof(string), runningCard.ToUpper()) })); // if (simulations == null) // return null; // if (simulations.Length > 0) // return simulations[0]; // else // return null; // } public ICSSimulation GetSimulationByTCard(string runningCard) { string sql= @"select * from ICSSimulation where TCARD='"+runningCard+"' order by MTIME desc "; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation QuerySimulation(string runningCard) { string sql = @"select * from ICSSimulation where RCARD = '" + runningCard + "' order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulationReport QuerySimulationReport(string runningCard) { string sql = @"select * from ICSSimulationReport where RCARD = '" + runningCard + "' order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } /// /// 改传参SQL /// /// /// public ICSSimulation GetOnlineSimulationByMoCode(string moCode) { string sql = @"select * from ICSSimulation where MODE = '" + moCode + "' and ISCOM = 0 order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } /// /// 改传参SQL /// /// /// public ICSSimulation GetSimulationFromCarton(string cartonno) { string sql = @"select * from ICSSimulation CARTONCODE = '" + cartonno + "' order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulationReport GetRCardByCartonCode(string cartonCode) { string sql = @"select * from ICSSimulation CARTONCODE = '" + cartonCode + "' order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } // End Added /// /// /// 改传参SQL /// /// /// public ICSSimulation GetSimulation(string moCode, string runningCard) { string sql = @"select * from ICSSimulation WHERE RCARD='" + runningCard + "' and MOCODE='" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetSimulationByMoCodeAndRcardORTCard(string moCode, string runningCard) { string sql = @"select * from ICSSimulation where (RCARD = '" + runningCard + "' or TCARD='" + runningCard + "') and MOCODE = '" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetSimulationByTCARDAndMoCode(string moCode, string translateCard) { string sql = @"select * from ICSSimulation where TCARD = '" + translateCard + "' and MOCODE = '" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } // /// /// 根据translateCard查询转换后序列号 /// public ICSSimulation GetSimulationFromTCard(string translateCard) { string sql = @"select * from ICSSimulation where TCARD = '" + translateCard + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetLastSimulation(string rcard) { string sql = @"select * from ICSSimulation where RCARD='" + rcard + "'and MOCODE in(select MOCODE from ICSMO where MOSTATUS='生产中') ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetLastSimulation(string rcard, string moCode) { string sql = @"select * from ICSSimulation where RCARD='" + rcard + "'and MOCODE = '" + moCode + "'and MOCODE in(select MOCODE from ICSMO where MOSTATUS='生产中') ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetSimulationNotInCurretMoCode(string rcard, string moCode) { string sql = @"select * from ICSSimulation where RCARD='" + rcard + "'and MOCODE in(select MOCODE from ICSMO where MOSTATUS='生产中') and MOCODE!='" + moCode + "' "; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } public ICSSimulation GetLastSimulationOrderByDateAndTime(string rcard) { string sql = @"select * from ICSSimulation where RCARD='" + rcard + "'and MOCODE in(select MOCODE from ICSMO where MOSTATUS='生产中') and PRODUCTSTATUS in ('GOOD','OFFLINE','OFFMO','OUTLINE') ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulation)objs[0]; } #endregion #region OnWIP /// /// /// public ICSONWIP CreateNewOnWIP() { return new ICSONWIP(); } public void AddOnWIP(ICSONWIP onWIP) { this._domainDataProvider.ICSONWIP.InsertOnSubmit(onWIP); } public void UpdateOnWIP(ICSONWIP onWIP) { //this.DataProvider.Update(onWIP); var line = this._domainDataProvider.ICSONWIP.Where(a => a.ID == onWIP.ID); this._domainDataProvider.ICSONWIP.DeleteAllOnSubmit(line); this._domainDataProvider.ICSONWIP.InsertOnSubmit(onWIP); } public void DeleteOnWIP(ICSONWIP onWIP) { var line = this._domainDataProvider.ICSONWIP.Where(a => a.ID == onWIP.ID); this._domainDataProvider.ICSONWIP.DeleteAllOnSubmit(line); } public ICSONWIP QueryOnWIP(string mCard, string moCode, string opCode, string action) { string sql = @"select * from ICSONWIP where RCARD='" + mCard + "' and ACTION='" + action + "' and MOCODE='" + moCode + "'and OPCODE='" + opCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIP)objs[0]; } #endregion #region SimulationReport /// /// /// public ICSSimulationReport CreateNewSimulationReport() { return new ICSSimulationReport(); } public void AddSimulationReport(ICSSimulationReport simulationReport) { this.DataProvider.ICSSimulationReport.InsertOnSubmit(simulationReport); this._domainDataProvider.SubmitChanges(); } //更新在制品历史记录表的LOTNO public void UpdateSimulationReportForLot(string rCard, string moCode, string lotNo) { string sql = @"UPDATE ICSSimulationReport SET LOTNO='" + lotNo + "' WHERE RCARD='" + rCard + "' AND MOCODE='" + moCode + "'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } //更新Carton号 public void UpdateSimulationReportCartonNo(string rcard, string mocode, string ctnno) { string sql = @"UPDATE ICSSimulationReport SET CARTONCODE='" + ctnno + "'where RCARD='" + rcard + "' and MOCODE='" + mocode + "'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } //根据RCODE、MOCODE删除在制品历史记录表 public void DeleteSimulationReport(ICSSimulation simulation) { string sql = @"delete from ICSSimulationReport where RRCARD='" + simulation.RCARD + "' and MOCODE='" + simulation.MOCODE + "'"; sql = string.Format(sql); this._domainDataProvider.ExecuteCommand(sql); this._domainDataProvider.SubmitChanges(); } public void DeleteSimulationReport(ICSSimulationReport simulationReport) { var line = this._domainDataProvider.ICSSimulationReport.Where(a => a.ID == simulationReport.ID); this._domainDataProvider.ICSSimulationReport.DeleteOnSubmit(simulationReport); //this.DataProvider.Delete(simulationReport); } /// /// 根据产品当前序列号获取最后一个SimulationReport /// /// /// public ICSSimulationReport GetLastSimulationReport(string rcard) { string sql = @"select * from ICSSimulationReport where RCARD='" + rcard + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } /// ///根据产品当前序列号、完工状态获取最后一个SimulationReport /// /// /// /// public ICSSimulationReport GetLastSimulationReport(string rcard, bool isComp) { string sql = @"SELECT * FROM ICSSimulationReport WHERE RCARD='" + rcard + "' and ISCOM='" + isComp + "'ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } /// /// 根据包装箱号获取最后一个SimulationReport /// /// /// public ICSSimulationReport GetLastSimulationReportByCarton(string cartonCode) { string sql = @"SELECT * FROM ICSSimulationReport WHERE CARTONCODE='" + cartonCode + "' ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } //根据包装箱号查找在制品信息 public ICSSimulationReport QuerySimulationReportByCarton(string cartonno) { string sql = @"select * from ICSSimulationReport where CARTONCODE = '" + cartonno + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } //根据工单号、产品当前序列号获取在制品信息 public ICSSimulationReport GetSimulationReport(string moCode, string runningCard) { string sql = @"select * from ICSSimulationReport where RCARD = '" + runningCard + "' and MOCODE = '" + moCode + "' order by MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } //根据工单号、产品当前序列号获取状态不在‘OFFMO’的在制品信息 public ICSSimulationReport GetSimulationReportNotInCurretMoCode(string rcard, string moCode) { string sql = "SELECT * FROM ICSSimulationReport WHERE RCARD='" + rcard + "' and MOCODE!='" + moCode + "' and PRODUCTSTATUS != 'OFFMO' ORDER BY MTIME DESC"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSSimulationReport)objs[0]; } #endregion #region OnWIPItem /// /// /// public ICSONWIPITEM CreateNewOnWIPItem() { return new ICSONWIPITEM(); } public void AddOnWIPItem(ICSONWIPITEM onWIPItem) { this.DataProvider.ICSONWIPITEM.InsertOnSubmit(onWIPItem); } public void UpdateOnWIPItem(ICSONWIPITEM onWIPItem) { var line = this._domainDataProvider.ICSONWIPITEM.Where(a => a.ID == onWIPItem.ID); this._domainDataProvider.ICSONWIPITEM.DeleteAllOnSubmit(line); this._domainDataProvider.ICSONWIPITEM.InsertOnSubmit(onWIPItem); //this.DataProvider.Update(onWIPItem); } public void DeleteOnWIPItem(ICSONWIPITEM onWIPItem) { var line = this._domainDataProvider.ICSONWIPITEM.Where(a => a.ID == onWIPItem.ID); this._domainDataProvider.ICSONWIPITEM.DeleteAllOnSubmit(line); //this.DataProvider.Delete(onWIPItem); } //根据产品序列号、产品序列号流水号、生产订单号、MCARD流水号获取上料历史记录 public object GetOnWIPItem(string runningCard, decimal runningCardSequence, string mocode, decimal mSequence) { //return this.DataProvider.CustomSearch(typeof(OnWIPItem), new object[] { runningCard, runningCardSequence, mOCode, mSequence }); var line = this._domainDataProvider.ICSONWIPITEM.SingleOrDefault(a => a.RCARD == runningCard && a.RCARDSEQ == runningCardSequence && a.MOCODE == mocode && a.MSEQ == mSequence); return (ICSONWIPITEM)line; } //根据产品序列号、生产订单号获取最后一条上料历史记录 public ICSONWIPITEM GetLastOnWIPItem(string runningCard, string moCode) { string sql = @" select * from ICSONWIPITEM where RCARD='" + runningCard + "' and MOCODE = '" + moCode + "' order by MTIME desc,MOSEQ desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } //根据产品序列号、产品序列号流水号、生产订单号获取物料代码 public ICSONWIPITEM ExtraQuery(string runningCard, decimal runningCardSequence, string moCode) { string sql = @"select distinct MITEMCODE from ICSONWIPITEM where MCARDTYPE='" + MCardType.MCardType_Keyparts + "' and RCARD = '" + runningCard + "' and RCARDSEQ = '" + runningCardSequence + "' and MOCODE = '" + moCode + "'" +" union (select MITEMCODE from ICSONWIPITEM where MCARDTYPE=" + MCardType.MCardType_INNO + " and RCARD = '" + runningCard + "' and RCARDSEQ = '" + runningCardSequence + "' and MOCODE = '" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } public static ICSONWIPITEM ExtraQuery(string runningCard) { ArrayList arRcard = new ArrayList(); //BenQGuru.eMES.Material.CastDownHelper castHelper = new BenQGuru.eMES.Material.CastDownHelper(DataProvider); //castHelper.GetAllRCard(ref arRcard, runningCard); arRcard.Add(runningCard); string runningCards = "('" + String.Join("','", (string[])arRcard.ToArray(typeof(string))) + "')"; FramDataContext db = new FramDataContext(AppConfig.AppConnectString); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); ICSONWIPITEM entity = new ICSONWIPITEM(); try { var line = db.ICSONWIPITEM.Where(a => a.RCARD == runningCard && a.ACTIONTYPE ==MaterialType.CollectMaterial.ToString()); return (ICSONWIPITEM)line; } catch (Exception ex) { throw new Exception(ex.Message); } } public ICSONWIPITEM ExtraQuery(string runningCard, string opCODE, string moCode, string actionType, ProductInfo product) { string sql = ""; string selectSQL = String.Empty; // 查询上料记录和下料记录 if (actionType == ActionType.DataCollectAction_DropMaterial) { string runningCards = runningCard; if (System.Configuration.ConfigurationSettings.AppSettings["NeedMaterialModule"].Trim() == "1") { ArrayList arRcard = new ArrayList(); //BenQGuru.eMES.Material.CastDownHelper castHelper = new BenQGuru.eMES.Material.CastDownHelper(DataProvider); //castHelper.GetAllRCard(ref arRcard, runningCard); arRcard.Add(runningCard); runningCards = "('" + String.Join("','", (string[])arRcard.ToArray(typeof(string))) + "')"; sql = @" select * from ICSONWIPITEM where RCARD='" + runningCard + "' and DROPOP='" + opCODE + "' and ACTIONTYPE='" + (int)MaterialType.DropMaterial + "'"; } else { sql = " select * from ICSONWIPITEM where RCARD = RCARD='" + runningCard + "' and DROPOP='" + opCODE + "' and ACTIONTYPE='" + (int)MaterialType.DropMaterial + "'"; } var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } else { sql = @" select * from ICSONWIPITEM where RCARD = RCARD='" + runningCard + "' and DROPOP='" + opCODE + "' and MOCODE = '" + moCode + "' and ACTIONTYPE='" + (int)MaterialType.DropMaterial + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } } //根据最小包装号或半成品的产品序列号查找上料历史记录 public ICSONWIPITEM QueryOnWIPItem(string mCard) { string sql = @" select * from ICSONWIPITEM where where 1=1 and MCARD = '" + mCard + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } //根据最小包装号或半成品的产品序列号和物料代码查询上料历史记录信息 public ICSONWIPITEM QueryOnWIPItem(string mCard, string MItemCode) { string sql = @" select * from ICSONWIPITEM where where 1=1 and MCARD = '" + mCard + "'and MITEMCODE='" + MItemCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } //根据最小包装号或半成品的产品序列号、物料代码、生产订单号查询上料历史记录信息 public ICSONWIPITEM QueryOnWIPItemWithmoCode(string mCard, string MItemCode, string moCode) { string sql = @" select * from ICSONWIPITEM where where 1=1 and MCARD = '" + mCard + "'and MITEMCODE='" + MItemCode + "'and MOCODE='" + moCode + "'"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } //根据最小包装号或半成品的产品序列号、产品序列号、事件类型查找上料历史记录信息 public ICSONWIPITEM QueryOnWIPItem(string mCard, string rCardList, string actionType) { string sql = @"SELECT * FROM ICSONWIPITEM"; sql += "WHERE 1 = 1 "; if (mCard.Trim().Length > 0) { sql += "AND MCARD = '" + mCard.Trim().ToUpper() + "' "; } if (actionType.Trim().Length > 0) { sql += "AND ACTIONTYPE = '" + actionType.Trim().ToUpper() + "' "; } if (rCardList.Trim().Length > 0) { sql += "AND RCARD IN " + rCardList.Trim().ToUpper() + " "; } sql += "ORDER BY MTIME desc"; var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return null; else return (ICSONWIPITEM)objs[0]; } #endregion #region 解析方式与检查类型相关方法 public Messages ParseFromBarcode(ref ICSMINNO newMINNO, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength) { return ParseFromBarcode(ref newMINNO, barcode, opBOMDetailForItemCode, opBOMDetailSNLength, true); } public Messages ParseFromBarcode(ref ICSMINNO newMINNO, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength, bool dealSecondSource) { Messages returnValue = new Messages(); string splitter = "-"; string itemCode = string.Empty; string vendorCode = string.Empty; string lotNo = string.Empty; string productDate = string.Empty; string pattern = @"^.+-.+-.+-.+[Rr]?$"; Regex reg = new Regex(pattern, RegexOptions.IgnoreCase); Match match = reg.Match(barcode); if (!match.Success) { //returnValue.Add(new Message(MessageType.Error, "$parse_barcode: $CS_Error_Format" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } lotNo = barcode; int pos = 0; //Vendor Code pos = barcode.IndexOf(splitter); vendorCode = barcode.Substring(0, pos); barcode = barcode.Substring(pos + 1); //Item code pos = barcode.IndexOf(splitter); itemCode = barcode.Substring(0, pos); barcode = barcode.Substring(pos + 1); //Product date pos = barcode.IndexOf(splitter); productDate = barcode.Substring(0, pos); barcode = barcode.Substring(pos + 1); //Return if (itemCode == string.Empty || vendorCode == string.Empty || lotNo == string.Empty || productDate == string.Empty) { //returnValue.Add(new Message(MessageType.Error, "$parse_barcode: $CS_Error_LackOfInfo" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } if (returnValue.IsSuccess()) { //newMINNO.MItemCode = itemCode; //newMINNO.VendorCode = vendorCode; //newMINNO.LotNO = lotNo; //newMINNO.DateCode = productDate; returnValue.ClearMessages(); returnValue.Add(new Message(MessageType.Success, "$parse_barcode$CS_Error_ParseSuccess")); } return returnValue; } public Messages ParseFromPrepare(ref ICSMINNO newMINNO, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength) { return ParseFromPrepare(ref newMINNO, barcode, opBOMDetailForItemCode, opBOMDetailSNLength, true); } public Messages ParseFromPrepare(ref ICSMINNO newMINNO, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength, bool dealSecondSource) { Messages returnValue = new Messages(); /* string sql = "select " + DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(MKeyPart)) + " "; sql += "from tblmkeypart, tblmkeypartdetail "; sql += "where tblmkeypart.mitemcode = tblmkeypartdetail.mitemcode "; sql += "and tblmkeypart.seq = tblmkeypartdetail.seq "; sql += "and serialno = '" + barcode.Trim().ToUpper() + "' "; object[] mKeyParts = this.DataProvider.CustomQuery(typeof(MKeyPart), new SQLCondition(sql)); if (mKeyParts == null) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_prepare: $CS_Error_NoPrepareInfo" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } for (int i = 0; i < mKeyParts.Length; i++) { returnValue = new Messages(); string prepareMOCode = ((MKeyPart)mKeyParts[i]).MoCode == null ? "" : ((MKeyPart)mKeyParts[i]).MoCode.Trim().ToUpper(); string keyPartMOCode = newMINNO.MOCode == null ? "" : newMINNO.MOCode.Trim().ToUpper(); if (prepareMOCode.Length > 0 && prepareMOCode != keyPartMOCode) { if (i == mKeyParts.Length - 1) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_prepare: $CS_Error_MOLimited " + ((MKeyPart)mKeyParts[i]).MoCode.Trim().ToUpper() + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } else { continue; } } //比对料号和序列号长度 returnValue.AddMessages(this.CheckAfterParse(((MKeyPart)mKeyParts[i]).MItemCode, opBOMDetailForItemCode, barcode, opBOMDetailSNLength, "$parse_prepare:", dealSecondSource)); if (!returnValue.IsSuccess()) { if (i == mKeyParts.Length - 1) { return returnValue; } else { continue; } } if (returnValue.IsSuccess()) { newMINNO.MItemCode = ((MKeyPart)mKeyParts[i]).MItemCode; newMINNO.VendorCode = ((MKeyPart)mKeyParts[i]).VendorCode; newMINNO.LotNO = ((MKeyPart)mKeyParts[i]).LotNO; newMINNO.DateCode = ((MKeyPart)mKeyParts[i]).DateCode; newMINNO.VendorItemCode = ((MKeyPart)mKeyParts[i]).VendorItemCode; newMINNO.Version = ((MKeyPart)mKeyParts[i]).Version; newMINNO.PCBA = ((MKeyPart)mKeyParts[i]).PCBA; newMINNO.BIOS = ((MKeyPart)mKeyParts[i]).BIOS; returnValue.ClearMessages(); returnValue.Add(new UserControl.Message(MessageType.Success, "$parse_prepare$CS_Error_ParseSuccess")); break; } } * */ return returnValue; } public Messages ParseFromProduct(ref ICSMINNO newMINNO, bool checkComplete, string moCode, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength) { return ParseFromProduct(ref newMINNO, checkComplete, moCode, barcode, opBOMDetailForItemCode, opBOMDetailSNLength, true, false); } public Messages ParseFromProduct(ref ICSMINNO newMINNO, bool checkComplete, string moCode, string barcode, ICSOPBOMDETAIL opBOMDetailForItemCode, int opBOMDetailSNLength, bool dealSecondSource, bool isSKDCartonCheck) { Messages returnValue = new Messages(); /* SimulationReport simRpt = GetSimulationReportNotInCurretMoCode(barcode, moCode); if (simRpt == null) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_product: $CS_Error_NoSimulationReport" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } if (!isSKDCartonCheck && simRpt.IsLoadedPart.Trim().Length > 0 && simRpt.IsLoadedPart.Trim() == FormatHelper.TRUE_STRING) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_product: $CS_Error_AlreadyLoaded" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } if (checkComplete && simRpt.IsComplete == FormatHelper.FALSE_STRING) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_product: $CS_Error_NotComplete" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } if (simRpt.Status != ProductStatus.GOOD && simRpt.Status != ProductStatus.OffLine && simRpt.Status != ProductStatus.OffMo && simRpt.Status != ProductStatus.OutLine) { returnValue.Add(new UserControl.Message(MessageType.Error, "$parse_product: $CS_ProductStatusError" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); return returnValue; } //比对料号和序列号长度 returnValue.AddMessages(this.CheckAfterParse(simRpt.ItemCode, opBOMDetailForItemCode, barcode, opBOMDetailSNLength, "$parse_product:", dealSecondSource)); if (!returnValue.IsSuccess()) { return returnValue; } if (returnValue.IsSuccess()) { newMINNO.MItemCode = simRpt.ItemCode; //newMINNO.LotNO = simRpt.LOTNO; returnValue.ClearMessages(); returnValue.Add(new UserControl.Message(MessageType.Success, "$parse_product$CS_Error_ParseSuccess")); } */ return returnValue; } private Messages CheckAfterParse(string inputItemCode, ICSOPBOMDETAIL opBOMDetail, string input, int opBOMDetailSNLength, string msgPrefix, bool dealSecondSource) { Messages returnValue = new Messages(); /* //料号比对 if (opBOMDetail != null) { if (dealSecondSource) { string itemCode = opBOMDetail.ItemCode; string opID = opBOMDetail.OPID; string opBOMCode = opBOMDetail.OPBOMCode; string opBOMVersion = opBOMDetail.OPBOMVersion; string opBOMSourceItemcode = opBOMDetail.OPBOMSourceItemCode; int orgID = GlobalVariables.CurrentOrganizations.First().OrganizationID; OPBOMFacade opbomfacade = new OPBOMFacade(this.DataProvider); object[] objs = opbomfacade.QueryOPBOMDetail(opID, itemCode, opBOMCode, opBOMVersion, orgID, inputItemCode); if (objs != null) { if (((OPBOMDetail)objs[0]).OPBOMSourceItemCode.Trim().ToUpper() != opBOMSourceItemcode.Trim().ToUpper()) { returnValue.Add(new UserControl.Message(MessageType.Error, msgPrefix + " $CS_LotControlMaterial_CompareItemFailed")); return returnValue; } } else { returnValue.Add(new UserControl.Message(MessageType.Error, msgPrefix + " $CS_LotControlMaterial_CompareItemFailed")); return returnValue; } } else { if (string.Compare(inputItemCode, opBOMDetail.OPBOMItemCode, true) != 0) { returnValue.Add(new UserControl.Message(MessageType.Error, msgPrefix + "$CS_LotControlMaterial_CompareItemFailed")); return returnValue; } } } //检查序列号长度 if (opBOMDetailSNLength > 0) { if (input.Length != opBOMDetailSNLength) { returnValue.Add(new UserControl.Message(MessageType.Error, msgPrefix + " $Error_SNLength_Wrong")); return returnValue; } } * * */ return returnValue; } //必须检查供应商 public Messages CheckNeedVebdor(ICSMINNO newMINNO) { Messages returnValue = new Messages(); //if (string.IsNullOrEmpty(newMINNO.VendorCode)) //{ // returnValue.Add(new UserControl.Message(MessageType.Error, "$CS_Material_Have_No_Vendor" + "[$CS_MItemCode:" + newMINNO.MItemCode.Trim() + "]")); // return returnValue; //} return returnValue; } public bool KeyPartUsed(string keyPartRCard, string mItemCode, bool checkCache, ArrayList inputPartList) { if (checkCache) { //检查是否存在页面上的,但是还没有保存到数据库的 if (inputPartList != null) { foreach (ICSMINNO minno in inputPartList) { //if (minno.EATTRIBUTE1 == MCardType.MCardType_Keyparts // && minno.MItemPackedNo.Trim().ToUpper() == keyPartRCard.Trim().ToUpper()) //{ // return true; //} } } } //Check DB //object[] onWIPItemList = QueryOnWIPItem(keyPartRCard, mItemCode); //if (onWIPItemList != null) //{ // foreach (ICSONWIPITEM onWIPItem in onWIPItemList) // { // if (onWIPItem.MCardType == MCardType.MCardType_Keyparts // && onWIPItem.ActionType == (int)MaterialType.CollectMaterial) // { // return true; // } // } //} return false; } public Messages GetMINNOByBarcode(ICSOPBOMDETAIL opBOMDetail, string barcode, string moCode, ArrayList inputPartList, bool dealSecondSource, bool isSKDCartonCheck, string actionType, out ICSMINNO minno) { Messages returnValue = new Messages(); minno = null; /* //解析方式 bool checkStatus = opBOMDetail.CheckStatus == BenQGuru.eMES.Web.Helper.FormatHelper.TRUE_STRING; //检查类型 string checkTypeSetting = "," + opBOMDetail.OPBOMCheckType + ","; int inputLength = opBOMDetail.SerialNoLength; string checkNeedVendor = !string.IsNullOrEmpty(opBOMDetail.NeedVendor) ? checkNeedVendor = opBOMDetail.NeedVendor : string.Empty; string mItemCode = opBOMDetail.OPBOMItemCode; MaterialFacade materialFacade = new MaterialFacade(this.DataProvider); ICSMINNO newMINNO = materialFacade.CreateNewMINNO(); newMINNO.MITEMCODE = mItemCode; newMINNO.LOTNO = string.Empty; DateTime dbDateTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); object obj = GetSimulationNotInCurretMoCode(barcode, moCode); if (obj != null && ((ICSSimulation)obj).IsComplete != "1") { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("{0} $CS_ERROR_MATERIAL_NOT_COMPLETE", barcode))); return returnValue; } Material.InventoryFacade inventoryFacade = new InventoryFacade(this.DataProvider); ItemFacade itemfacade = new ItemFacade(this.DataProvider); object objItemLot = inventoryFacade.QueryLastItemLotByLotNo(barcode); if (objItemLot == null) { objItemLot = inventoryFacade.QueryItemLotByBarCode(barcode); if (objItemLot != null) { newMINNO.MITEMCODE = ((ICSITEMLot)objItemLot).MCODE.ToString(); newMINNO.LOTNO = ((ICSITEMLot)objItemLot).LotNO.ToString(); newMINNO.DATECODE = ((ICSITEMLot)objItemLot).PRODUCTDATE.ToString(); newMINNO.VENDORCODE = ((ICSITEMLot)objItemLot).VENDORCODE; newMINNO.VENDORITEMCODE = ((ICSITEMLot)objItemLot).VENDORITEMCODE; } } else { newMINNO.MITEMCODE = ((ICSITEMLot)objItemLot).MCODE.ToString(); newMINNO.LOTNO = ((ICSITEMLot)objItemLot).LotNO.ToString(); newMINNO.DATECODE = ((ICSITEMLot)objItemLot).PRODUCTDATE.ToString(); newMINNO.VENDORCODE = ((ICSITEMLot)objItemLot).VENDORCODE; newMINNO.VENDORITEMCODE = ((ICSITEMLot)objItemLot).VENDORITEMCODE; } //料号比对 if (checkTypeSetting.IndexOf(OPBOMDetailCheckType.CHECK_COMPAREITEM.ToLower()) >= 0) { Messages messsages = ParseFromProduct(ref newMINNO, true, moCode, barcode, opBOMDetail, inputLength, dealSecondSource, false); if (!messsages.IsSuccess()) { if (objItemLot == null) { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("$CS_Error_ItemLot_Dif"))); return returnValue; } else { //for岗位备料支持替代料 if (string.Compare(((ICSITEMLot)objItemLot).Mcode, ICSOPBOMDETAIL.OPBOMItemCode, true) != 0 && actionType != "LotPart0") { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("$CS_Error_Mcode_DIF"))); return returnValue; } } } //for岗位备料支持替代料 if (actionType == "LotPart" || actionType == "LotPart0") { returnValue.AddMessages(MDSManager(newMINNO.LotNO, opBOMDetail.MaintainUser)); if (!returnValue.IsSuccess()) { return returnValue; } } } newMINNO.MITEMCODE = moCode; newMINNO.OPBOMCODE = opBOMDetail.OBCODE; newMINNO.OPBOMVER = opBOMDetail.OPBOMVER; newMINNO.OPCODE = opBOMDetail.OPCODE; newMINNO.MaintainTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); if (obj != null) { newMINNO.ITEMCODE = ((ICSSimulation)obj).ITEMCODE; newMINNO.ROUTECODE = ((ICSSimulation)obj).ROUTECODE; newMINNO.RESCODE = ((ICSSimulation)obj).RESCODE; } //如果VendorCode为空,到tblmaterial中获取 if (newMINNO.VENDORCODE == null || newMINNO.VENDORCODE.Trim().Length <= 0) { object objMaterial = itemfacade.GetMaterial(newMINNO.MITEMCODE.Trim(), GlobalVariables.CurrentOrganizations.First().OrganizationID); if (objMaterial != null) { newMINNO.VENDORCODE = ((Domain.MOModel.Material)objMaterial).VendorCode; } } //Check if key part was used if (!isSKDCartonCheck && opBOMDetail.OPBOMItemControlType == BOMItemControlType.ITEM_CONTROL_KEYPARTS && KeyPartUsed(barcode, newMINNO.MItemCode, true, inputPartList)) { returnValue.Add(new UserControl.Message(MessageType.Error, "$CS_Error_ParseFailed $CS_Error_KeyPartUsed:" + barcode)); return returnValue; } //序列号长度比对 if (opBOMDetail.OBPARSETYPE.Trim().Length <= 0) { if (inputLength > 0 && barcode.Trim().Length != inputLength) { returnValue.Add(new UserControl.Message(MessageType.Error, "$CS_Error_ParseFailed $Error_SNLength_Wrong")); return returnValue; } } //check NeedVendor if (!isSKDCartonCheck && checkNeedVendor == NeedVendor.NeedVendor_Y) { Messages checkNeedVendorMsg = new Messages(); checkNeedVendorMsg = CheckNeedVebdor(newMINNO); if (!checkNeedVendorMsg.IsSuccess()) { returnValue.AddMessages(checkNeedVendorMsg); return returnValue; } } if (string.IsNullOrEmpty(newMINNO.MITEMCODE)) { newMINNO.MItemCode = mItemCode; } newMINNO.MItemPackedNo = barcode; if (opBOMDetail.OBITEMCONTYPE == BOMItemControlType.ITEM_CONTROL_KEYPARTS) { newMINNO.EAttribute1 = MCardType.MCardType_Keyparts; } else if (opBOMDetail.OBITEMCONTYPE == BOMItemControlType.ITEM_CONTROL_LOT) { newMINNO.EATTRIBUTE1 = MCardType.MCardType_INNO; newMINNO.QTY = opBOMDetail.OBITEMQTY; } minno = newMINNO; */ return returnValue; } public Messages GetMINNOByBarcode(ICSOPBOMDETAIL opBOMDetail, ICSMINNO oldminno, string moCode, ArrayList inputPartList, bool dealSecondSource, bool isSKDCartonCheck, string actionType, out ICSMINNO minno) { Messages returnValue = new Messages(); minno = null; /* //解析方式 bool checkStatus = opBOMDetail.CHECKSTATUS == BenQGuru.eMES.Web.Helper.FormatHelper.TRUE_STRING; //检查类型 string checkTypeSetting = "," + opBOMDetail.OPBOMCheckType + ","; int inputLength = opBOMDetail.SerialNoLength; string checkNeedVendor = !string.IsNullOrEmpty(opBOMDetail.NeedVendor) ? checkNeedVendor = opBOMDetail.NeedVendor : string.Empty; string mItemCode = opBOMDetail.OPBOMItemCode; MaterialFacade materialFacade = new MaterialFacade(this.DataProvider); ICSMINNO newMINNO = materialFacade.CreateNewMINNO(); newMINNO.MITEMCODE = mItemCode; newMINNO.LOTNO = string.Empty; DateTime dbDateTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); object obj = GetSimulationNotInCurretMoCode(oldminno.MItemPackedNo, moCode); if (obj != null && ((ICSSimulation)obj).IsComplete != "1") { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("{0} $CS_ERROR_MATERIAL_NOT_COMPLETE", oldminno.MItemPackedNo))); return returnValue; } Material.InventoryFacade inventoryFacade = new InventoryFacade(this.DataProvider); ItemFacade itemfacade = new ItemFacade(this.DataProvider); object objItemLot = inventoryFacade.QueryLastItemLotByLotNo(oldminno.MItemPackedNo); if (objItemLot == null) { objItemLot = inventoryFacade.QueryItemLotByBarCode(oldminno.MItemPackedNo); if (objItemLot != null) { newMINNO.LOTNO = ((ICSITEMLot)objItemLot).LotNO.ToString(); newMINNO.DATECODE = ((ICSITEMLot)objItemLot).PRODUCTDATE.ToString(); newMINNO.VENDORCODE = ((ICSITEMLot)objItemLot).VENDORCODE; newMINNO.VENDORITEMCODE = ((ICSITEMLot)objItemLot).VENDORITEMCODE; } } else { newMINNO.LOTNO = ((ICSITEMLot)objItemLot).LotNO.ToString(); newMINNO.DATECODE = ((ICSITEMLot)objItemLot).PRODUCTDATE.ToString(); newMINNO.VENDORCODE = ((ICSITEMLot)objItemLot).VENDORCODE; newMINNO.VENDORITEMCODE = ((ICSITEMLot)objItemLot).VENDORITEMCODE; } //料号比对 if (checkTypeSetting.IndexOf(OPBOMDetailCheckType.CHECK_COMPAREITEM.ToLower()) >= 0) { Messages messsages = ParseFromProduct(ref newMINNO, true, moCode, oldminno.MItemPackedNo, opBOMDetail, inputLength, dealSecondSource, false); if (!messsages.IsSuccess()) { if (objItemLot == null) { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("$CS_Error_ItemLot_Dif"))); return returnValue; } else { //for岗位备料支持替代料 if (string.Compare(((ICSITEMLot)objItemLot).Mcode, opBOMDetail.OPBOMItemCode, true) != 0 && actionType != "LotPart0") { returnValue.Add(new UserControl.Message(MessageType.Error, string.Format("$CS_Error_Mcode_DIF"))); return returnValue; } } } //岗位备料支持替代料 if (actionType == "LotPart" || actionType == "LotPart0") { if (oldminno.Nextlotno != null && oldminno.Nextlotno.Trim() != "") { returnValue.AddMessages(MDSManager(oldminno.Nextlotno, opBOMDetail.MaintainUser)); } else { returnValue.AddMessages(MDSManager(oldminno.LotNO, opBOMDetail.MaintainUser)); } if (!returnValue.IsSuccess()) { return returnValue; } } } newMINNO.MOCODE = moCode; newMINNO.OPBOMCODE = opBOMDetail.OBCODE; newMINNO.OPBOMVER = opBOMDetail.OPBOMVER; newMINNO.OPCODE = opBOMDetail.OPCODE; newMINNO.MaintainTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString()); if (obj != null) { newMINNO.ITEMCODE = ((ICSSimulation)obj).ITEMCODE; newMINNO.ROUTECODE = ((ICSSimulation)obj).ROUTECODE; newMINNO.RESCODE = ((ICSSimulation)obj).RESCODE; } //如果VendorCode为空,到tblmaterial中获取 if (newMINNO.VENDORCODE == null || newMINNO.VENDORCODE.Trim().Length <= 0) { object objMaterial = itemfacade.GetMaterial(newMINNO.MItemCode.Trim(), GlobalVariables.CurrentOrganizations.First().OrganizationID); if (objMaterial != null) { newMINNO.VENDORCODE = ((Domain.MOModel.Material)objMaterial).VendorCode; } } //Check if key part was used if (!isSKDCartonCheck && opBOMDetail.OPBOMItemControlType == BOMItemControlType.ITEM_CONTROL_KEYPARTS && KeyPartUsed(oldminno.LotNO, newMINNO.MItemCode, true, inputPartList)) { returnValue.Add(new UserControl.Message(MessageType.Error, "$CS_Error_ParseFailed $CS_Error_KeyPartUsed:" + oldminno.LotNO)); return returnValue; } //序列号长度比对 if (opBOMDetail.OPBOMParseType.Trim().Length <= 0) { if (inputLength > 0 && oldminno.LotNO.Trim().Length != inputLength) { returnValue.Add(new UserControl.Message(MessageType.Error, "$CS_Error_ParseFailed $Error_SNLength_Wrong")); return returnValue; } } //check NeedVendor if (!isSKDCartonCheck && checkNeedVendor == NeedVendor.NeedVendor_Y) { Messages checkNeedVendorMsg = new Messages(); checkNeedVendorMsg = CheckNeedVebdor(newMINNO); if (!checkNeedVendorMsg.IsSuccess()) { returnValue.AddMessages(checkNeedVendorMsg); return returnValue; } } if (string.IsNullOrEmpty(newMINNO.MItemCode)) { newMINNO.MITEMCODE = mItemCode; } newMINNO.MITEMPACKEDNO = oldminno.LOTNO; if (opBOMDetail.OPBOMItemControlType == BOMItemControlType.ITEM_CONTROL_KEYPARTS) { newMINNO.EATTRIBUTE1 = MCardType.MCardType_Keyparts; } else if (opBOMDetail.OPBOMItemControlType == BOMItemControlType.ITEM_CONTROL_LOT) { newMINNO.EATTRIBUTE1 = MCardType.MCardType_INNO; newMINNO.QTY = opBOMDetail.OBITEMQTY; } minno = newMINNO; */ return returnValue; } #endregion #region MESEntityList public ICSMESEntityList CreateNewMESEntityList() { return new ICSMESEntityList(); } public void AddMESEntityList(ICSMESEntityList mesEntityList) { this.DataProvider.ICSMESEntityList.InsertOnSubmit(mesEntityList); } public void DeleteMESEntityList(ICSMESEntityList mesEntityList) { this.DataProvider.ICSMESEntityList.DeleteOnSubmit(mesEntityList); } public object GetMESEntityList(int serial) { return this.DataProvider.ICSMESEntityList.SingleOrDefault( a => a.serial== serial ); } private int GetMESEntityListSerial(ICSMESEntityList mesEntityList) { if (mesEntityList == null) { return -1; } string sql = "SELECT * FROM ICSMESEntityList WHERE 1 = 1 "; sql += string.Format(" AND workpoint = '{0}' ", mesEntityList.WorkPoint); sql += string.Format(" AND faccode = '{0}' ", mesEntityList.FACCODE); sql += string.Format(" AND segcode = '{0}' ", mesEntityList.SEGCODE); sql += string.Format(" AND sscode = '{0}' ", mesEntityList.SSCODE); sql += string.Format(" AND rescode = '{0}' ", mesEntityList.RESCODE); sql += string.Format(" AND opcode = '{0}' ", mesEntityList.OPCODE); sql += string.Format(" AND modelcode = '{0}' ", mesEntityList.MODELCODE); sql += string.Format(" AND shifttypecode = '{0}' ", mesEntityList.SHIFTTYPECODE); sql += string.Format(" AND shiftcode = '{0}' ", mesEntityList.SHIFTCODE); sql += string.Format(" AND tpcode = '{0}' ", mesEntityList.TPCODE); var objs = this._domainDataProvider.ExecuteQuery(sql).ToList(); if (objs == null || objs.Count < 1) return -1; else return ((ICSMESEntityList)objs[0]).serial; } public int GetMESEntityListSerial(ICSSimulationReport simulationReport) { if (simulationReport == null) { return -1; } ICSBaseModel baseModelFacade = new ICSBaseModel(this.DataProvider); ICSMESEntityList mesEntityList = new ICSMESEntityList(); ICSSS stepSequence = (ICSSS)baseModelFacade.GetStepSequence(simulationReport.SSCODE); ICSSEG segment = (ICSSEG)baseModelFacade.GetSegment(simulationReport.SEGCODE); if (segment != null) { ICSFACTORY factory = this.DataProvider.ICSFACTORY.SingleOrDefault(a => a.ID == segment.FACID); mesEntityList.FACCODE = factory.FACCODE; } mesEntityList.BIGSSCODE = ""; mesEntityList.SEGCODE = simulationReport.SEGCODE; mesEntityList.SSCODE = simulationReport.SSCODE; mesEntityList.RESCODE = simulationReport.RESCODE; mesEntityList.OPCODE = simulationReport.OPCODE; mesEntityList.MODELCODE = simulationReport.MODELCODE; mesEntityList.SHIFTTYPECODE = simulationReport.SHIFTTYPECODE; mesEntityList.SHIFTCODE = simulationReport.SHIFTCODE; mesEntityList.TPCODE = simulationReport.TPCODE; mesEntityList.WorkPoint = simulationReport.WorkPoint; //现查询看是否存在,不存在的话,新增一笔 int returnValue = GetMESEntityListSerial(mesEntityList); if (returnValue <= 0) { AddMESEntityList(mesEntityList); returnValue = GetMESEntityListSerial(mesEntityList); } return returnValue; } #endregion private bool CheckIsComAndNotInStorage(string rcard, string moCode) { ICSSimulation sim = this.GetLastSimulation(rcard, moCode) as ICSSimulation; if (sim != null) { if (sim.ISCOM == "1" && sim.PRODUCTSTATUS == "GOOD") { //判断未入过库 object[] objOnWip = null;// this.QueryOnWIP(sim.RCARD, sim.MOCODE, sim.OPCODE, "GOOD"); if (objOnWip == null || objOnWip.Length <= 1) { return true; } } } return false; } public Messages CheckReworkRcardIsScarp(string rcard, string resCode) { Messages msg = new Messages(); ICSBaseModel baseModelFacade = new ICSBaseModel(this.DataProvider); ICSRES resource = (ICSRES)baseModelFacade.GetResource(resCode); ICSSimulationReport simulationReport = (ICSSimulationReport)this.GetLastSimulationReport(rcard); if (resource != null && simulationReport != null && simulationReport.PRODUCTSTATUS == ProductStatus.Scrap) { msg.Add(new Message(MessageType.Error, "$CS_Rcard_IS_Scrap_Can_Not_Rework")); } return msg; } } [Serializable] //工单状态 public class MOManufactureStatus { private ArrayList _list = new ArrayList(); public MOManufactureStatus() { this._list.Add(MOManufactureStatus.MOSTATUS_INITIAL); this._list.Add(MOManufactureStatus.MOSTATUS_RELEASE); this._list.Add(MOManufactureStatus.MOSTATUS_OPEN); this._list.Add(MOManufactureStatus.MOSTATUS_CLOSE); this._list.Add(MOManufactureStatus.MOSTATUS_PENDING); } public const string MOSTATUS_INITIAL = "mostatus_initial"; //初始 public const string MOSTATUS_RELEASE = "下发";//"mostatus_release"; //下发 public const string MOSTATUS_OPEN = "生产中";//"mostatus_open"; //生产中 public const string MOSTATUS_CLOSE = "mostatus_close"; //关单 public const string MOSTATUS_PENDING = "mostatus_pending"; //暂停 #region IInternalSystemVariable 成员 public string Group { get { return "MOManufactureStatus"; } } public ArrayList Items { get { return this._list; } } #endregion } [Serializable] public class ONWIPItemQueryObject { public string MItemCode; } [Serializable] public class ONWIPItemObject { public string RunningCard; public string RunningCardSequence; public string MCARD; public string MCardType; public string OPCODE; } }