/// <summary> /// 批次过站作业。 /// </summary> /// <param name="obj">批次对象。</param> /// <param name="model">过站模型对象。</param> /// <returns>返回结果。</returns> private MethodReturnResult Track(Lot obj, LotTrackViewModel model) { string lotNumber = model.LotNumber.ToUpper(); MethodReturnResult result = new MethodReturnResult(); IDictionary <string, IList <TransactionParameter> > dicParams = new Dictionary <string, IList <TransactionParameter> >(); //获取工序参数列表。 IList <RouteStepParameter> lstRouteStepParameter = GetParameterList(obj.RouteName, obj.RouteStepName, obj.StateFlag); //组织批次附加参数。 if (lstRouteStepParameter != null) { foreach (RouteStepParameter item in lstRouteStepParameter) { string hashcode = string.Format("{0}{1}{2}", item.Key.RouteName, item.Key.RouteStepName, item.Key.ParameterName) .GetHashCode() .ToString() .Replace('-', '_'); string paramName = string.Format("PARAM_{0}", hashcode); string val = Request.Form[paramName]; //记录上一次值。 if (item.IsUsePreValue) { if (Request.Cookies.Get(paramName) != null) { Response.SetCookie(new HttpCookie(paramName, val)); } else if (!string.IsNullOrEmpty(val)) { Response.Cookies.Add(new HttpCookie(paramName, val)); } } if (string.IsNullOrEmpty(val)) { continue; } if (!dicParams.ContainsKey(obj.Key)) { dicParams.Add(obj.Key, new List <TransactionParameter>()); } if (item.DataType == EnumDataType.Boolean) { val = val == "on" ? "true" : "false"; } TransactionParameter tp = new TransactionParameter() { Index = item.ParamIndex, Name = item.Key.ParameterName, Value = val }; dicParams[obj.Key].Add(tp); } } //批次当前状态为等待进站。 if (obj.StateFlag == EnumLotState.WaitTrackIn) { TrackInParameter p = new TrackInParameter() { Creator = User.Identity.Name, EquipmentCode = model.EquipmentCode, LineCode = model.LineCode, LotNumbers = new List <string>(), OperateComputer = Request.UserHostAddress, Operator = User.Identity.Name, Paramters = dicParams, Remark = model.Description, RouteOperationName = model.RouteOperationName }; p.LotNumbers.Add(lotNumber); //进行批次进站。 using (LotTrackInServiceClient client = new LotTrackInServiceClient()) { result = client.TrackIn(p); if (result.Code == 0) { if (!string.IsNullOrEmpty(result.Message)) { if (!result.Message.EndsWith("\n")) { result.Message += "\n"; } result.Message = result.Message.Replace("\n", "<br/>"); } result.Message = string.Format("批次 {0} 进站成功。", lotNumber); } } } //批次当前状态为等待出站。 else if (obj.StateFlag == EnumLotState.WaitTrackOut) { TrackOutParameter p = new TrackOutParameter() { Creator = User.Identity.Name, LineCode = model.LineCode, LotNumbers = new List <string>(), OperateComputer = Request.UserHostAddress, Operator = User.Identity.Name, Paramters = dicParams, Remark = model.Description, RouteOperationName = model.RouteOperationName, EquipmentCode = model.EquipmentCode, Color = model.Color, Grade = model.Grade }; p.LotNumbers.Add(lotNumber); //进行不良数量记录 IList <ReasonCodeCategoryDetail> lstDefectReasonCodes = GetDefectReasonCodes(obj.RouteName, obj.RouteStepName); p.DefectReasonCodes = new Dictionary <string, IList <DefectReasonCodeParameter> >(); if (lstDefectReasonCodes != null && lstDefectReasonCodes.Count > 0) { foreach (ReasonCodeCategoryDetail item in lstDefectReasonCodes) { string hashcode = string.Format("{0}{1}", item.Key.ReasonCodeCategoryName, item.Key.ReasonCodeName) .GetHashCode() .ToString() .Replace('-', '_'); string inputControlName = string.Format("DefectReasonCode_{0}", hashcode); string val = Request.Form[inputControlName]; double dVal = 0; if (string.IsNullOrEmpty(val) || double.TryParse(val, out dVal) == false || dVal == 0) { continue; } if (!p.DefectReasonCodes.ContainsKey(obj.Key)) { p.DefectReasonCodes.Add(obj.Key, new List <DefectReasonCodeParameter>()); } DefectReasonCodeParameter drcp = new DefectReasonCodeParameter() { ReasonCodeCategoryName = item.Key.ReasonCodeCategoryName, ReasonCodeName = item.Key.ReasonCodeName, Quantity = dVal, Description = string.Empty, ResponsiblePerson = string.Empty, RouteOperationName = string.Empty }; p.DefectReasonCodes[obj.Key].Add(drcp); } } //进行报废数量记录 IList <ReasonCodeCategoryDetail> lstScrapReasonCodes = GetScrapReasonCodes(obj.RouteName, obj.RouteStepName); p.ScrapReasonCodes = new Dictionary <string, IList <ScrapReasonCodeParameter> >(); if (lstScrapReasonCodes != null && lstScrapReasonCodes.Count > 0) { foreach (ReasonCodeCategoryDetail item in lstScrapReasonCodes) { string hashcode = string.Format("{0}{1}", item.Key.ReasonCodeCategoryName, item.Key.ReasonCodeName) .GetHashCode() .ToString() .Replace('-', '_'); string inputControlName = string.Format("ScrapReasonCode_{0}", hashcode); string val = Request.Form[inputControlName]; double dVal = 0; if (string.IsNullOrEmpty(val) || double.TryParse(val, out dVal) == false || dVal == 0) { continue; } if (!p.ScrapReasonCodes.ContainsKey(obj.Key)) { p.ScrapReasonCodes.Add(obj.Key, new List <ScrapReasonCodeParameter>()); } ScrapReasonCodeParameter srcp = new ScrapReasonCodeParameter() { ReasonCodeCategoryName = item.Key.ReasonCodeCategoryName, ReasonCodeName = item.Key.ReasonCodeName, Quantity = dVal, Description = string.Empty, ResponsiblePerson = string.Empty, RouteOperationName = string.Empty }; p.ScrapReasonCodes[obj.Key].Add(srcp); } } //进行批次出站。 using (LotTrackOutServiceClient client = new LotTrackOutServiceClient()) { result = client.TrackOut(p); if (result.Code == 0) { if (!string.IsNullOrEmpty(result.Message)) { if (!result.Message.EndsWith("\n")) { result.Message += "\n"; } result.Message = result.Message.Replace("\n", "<br/>"); } result.Message += string.Format("批次 {0} 出站成功。", lotNumber); } } } else { result.Code = 100; result.Message = string.Format("批次 {0} 状态为({1}),不能进行工作站作业。" , lotNumber , obj.StateFlag.GetDisplayName()); } return(result); }
public void Execute(LotReaderDeviceElement lotinfo) { LotReaderFinishedArgs Args = new LotReaderFinishedArgs(); try { if (lotinfo.LotNumber.Length < 3) { Args.TransferMsg = string.Format("未扫到码,车间{0}线别{1}" , lotinfo.WorkShop , lotinfo.LineCode); Args.TransferMsg = Args.TransferMsg + "-------------"; ErrorLog(null, Args.TransferMsg); if (OnLotReaderFinished != null) { CommonFun.eventInvoket(() => { OnLotReaderFinished(this, Args); }); } } else { //根据条码获取批次信息 Lot lot = null; MethodReturnResult resultLot = new MethodReturnResult(); try { string lotNumber = lotinfo.LotNumber.ToUpper(); lot = GetLot(lotNumber); if (lot == null) { return; } } catch (Exception ex) { resultLot.Code = 1000; resultLot.Message = ex.Message; resultLot.Detail = ex.ToString(); ErrorLog(ex, resultLot.Message); } //判断进出站状态、设备及工序 TrackInParameter pIn = new TrackInParameter() { Creator = "system", RouteOperationName = "", LineCode = lotinfo.LineCode, LotNumbers = new List <string>(), OperateComputer = lotinfo.ReaderIP, Operator = "system", EquipmentCode = "" }; pIn.LotNumbers.Add(lotinfo.LotNumber); TrackOutParameter pOut = new TrackOutParameter() { Creator = "system", RouteOperationName = "", LineCode = lotinfo.LineCode, LotNumbers = new List <string>(), OperateComputer = lotinfo.ReaderIP, Operator = "system", EquipmentCode = "" }; pOut.LotNumbers.Add(lotinfo.LotNumber); //工序,状态 if (lot.RouteStepName == lotinfo.FirstStepCode) { if (lot.StateFlag == EnumLotState.WaitTrackIn) { //第一站进站赋值进站属性 pIn.RouteOperationName = lotinfo.FirstStepCode; pIn.EquipmentCode = lotinfo.FirstEquipmentCode; if (stepIn(lotinfo, lot, Args, pIn))//第一站进站 { //第一站出站赋值出站属性 pOut.RouteOperationName = lotinfo.FirstStepCode; pOut.EquipmentCode = lotinfo.FirstEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第一站出站 { //第二站进站赋值进站属性 pIn.RouteOperationName = lotinfo.SecondStepCode; pIn.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackIn; if (stepIn(lotinfo, lot, Args, pIn)) //第二站进站 { //第二站出站赋值进站属性 pOut.RouteOperationName = lotinfo.SecondStepCode; pOut.EquipmentCode = lotinfo.SecondEquipmentCode; lot.RouteStepName = lotinfo.SecondStepCode; lot.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第二站出站 { //启线 //m_retFlag = m_soap.SetLineState(m_workShopId, m_flowId, m_flowSubId, 1); //StartLine(lotinfo.WorkShopId, lotinfo.FlowId, lotinfo.FlowSubId, lotinfo.LineCode, lotinfo.SecondEquipmentCode); } } } } } else if (lot.StateFlag == EnumLotState.WaitTrackOut) { //第一站出站赋值出站属性 pOut.RouteOperationName = lotinfo.FirstStepCode; pOut.EquipmentCode = lotinfo.FirstEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第一站出站 { //第二站进站赋值进站属性 pIn.RouteOperationName = lotinfo.SecondStepCode; pIn.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackIn; if (stepIn(lotinfo, lot, Args, pIn)) //第二站进站 { //第二站出站赋值进站属性 pOut.RouteOperationName = lotinfo.SecondStepCode; pOut.EquipmentCode = lotinfo.SecondEquipmentCode; lot.RouteStepName = lotinfo.SecondStepCode; lot.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第二站出站 { //启线 //m_retFlag = m_soap.SetLineState(m_workShopId, m_flowId, m_flowSubId, 1); //StartLine(lotinfo.WorkShopId, lotinfo.FlowId, lotinfo.FlowSubId, lotinfo.LineCode, lotinfo.SecondEquipmentCode); } } } } } else if (lot.RouteStepName == lotinfo.SecondStepCode) { if (lot.StateFlag == EnumLotState.WaitTrackIn) { //第二站进站赋值进站属性 pIn.RouteOperationName = lotinfo.SecondStepCode; pIn.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackIn; if (stepIn(lotinfo, lot, Args, pIn)) //第二站进站 { //第二站出站赋值进站属性 pOut.RouteOperationName = lotinfo.SecondStepCode; pOut.EquipmentCode = lotinfo.SecondEquipmentCode; lot.RouteStepName = lotinfo.SecondStepCode; lot.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第二站出站 { //启线 //m_retFlag = m_soap.SetLineState(m_workShopId, m_flowId, m_flowSubId, 1); //StartLine(lotinfo.WorkShopId, lotinfo.FlowId, lotinfo.FlowSubId, lotinfo.LineCode, lotinfo.SecondEquipmentCode); } } } if (lot.StateFlag == EnumLotState.WaitTrackOut) { //第二站出站赋值进站属性 pOut.RouteOperationName = lotinfo.SecondStepCode; pOut.EquipmentCode = lotinfo.SecondEquipmentCode; lot.RouteStepName = lotinfo.SecondStepCode; lot.EquipmentCode = lotinfo.SecondEquipmentCode; lot.StateFlag = EnumLotState.WaitTrackOut; if (stepOut(lotinfo, lot, Args, pOut))//第二站出站 { string msg = null; //启线 //m_retFlag = m_soap.SetLineState(m_workShopId, m_flowId, m_flowSubId, 1); //StartLine(lotinfo.WorkShopId, lotinfo.FlowId, lotinfo.FlowSubId, lotinfo.LineCode, lotinfo.SecondEquipmentCode); } } } } } catch (Exception ex) { Args.TransferMsg = Args.TransferMsg + "-------------" + ex; ErrorLog(ex, Args.TransferMsg); } }
/// <summary> /// 执行批次作业。 /// </summary> private void Execute(LotJobTransferThreadWrapper wrapper) { while (wrapper.Loop) { try { //查询前10个批次定时作业。 PagingConfig cfg = new PagingConfig() { PageNo = 0, PageSize = 10, Where = string.Format(@"Status=1 AND CloseType=0 AND NextRunTime<='{0}'" , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), OrderBy = "NextRunTime" }; IList <WIPModel.LotJob> lstJob = new List <WIPModel.LotJob>(); using (LotJobServiceClient client = new LotJobServiceClient()) { MethodReturnResult <IList <WIPModel.LotJob> > rst = client.Get(ref cfg); if (rst.Data == null) { this._eventLog.WriteEntry(string.Format("MES.LotJob:{0}", rst.Message), EventLogEntryType.Error); client.Close(); continue; } lstJob = rst.Data; } //遍历JOB数据 foreach (WIPModel.LotJob job in lstJob) { job.RunCount++; job.NotifyMessage = string.Empty; #region //自动出站。 if (job.Type == EnumJobType.AutoTrackOut) { TrackOutParameter p = new TrackOutParameter() { Creator = job.Creator, LineCode = job.LineCode, LotNumbers = new List <string>(), OperateComputer = System.Net.Dns.GetHostName(), Operator = job.Creator, RouteOperationName = job.RouteStepName, EquipmentCode = job.EquipmentCode }; p.LotNumbers.Add(job.LotNumber); using (LotTrackOutServiceClient client = new LotTrackOutServiceClient()) { MethodReturnResult result = client.TrackOut(p); if (result.Code > 0) { job.NotifyMessage = result.Message; job.NextRunTime = job.NextRunTime.AddMinutes(1); this._eventLog.WriteEntry(string.Format("MES.LotJob:{0} {1}" , job.LotNumber , job.Type.GetDisplayName() , result.Message), EventLogEntryType.Error); } else { job.CloseType = EnumCloseType.Normal; } } } #endregion #region //自动进站。 else if (job.Type == EnumJobType.AutoTrackIn) { TrackInParameter p = new TrackInParameter() { Creator = job.Creator, LineCode = job.LineCode, LotNumbers = new List <string>(), OperateComputer = System.Net.Dns.GetHostName(), Operator = job.Creator, RouteOperationName = job.RouteStepName, EquipmentCode = job.EquipmentCode }; p.LotNumbers.Add(job.LotNumber); using (LotTrackInServiceClient client = new LotTrackInServiceClient()) { MethodReturnResult result = client.TrackIn(p); if (result.Code > 0) { job.NotifyMessage = result.Message; job.NextRunTime = job.NextRunTime.AddMinutes(1); this._eventLog.WriteEntry(string.Format("MES.LotJob:{0} {1}" , job.LotNumber , job.Type.GetDisplayName() , result.Message), EventLogEntryType.Error); } else { job.CloseType = EnumCloseType.Normal; } } } #endregion //超过5次没有完成,则设置为手动关闭。定时作业失败。 if (job.RunCount >= 2 && job.CloseType == EnumCloseType.None) { job.CloseType = EnumCloseType.Manual; } #region //更新批次定时作业。 using (LotJobServiceClient client = new LotJobServiceClient()) { MethodReturnResult result = client.Modify(job); if (result.Code > 0) { this._eventLog.WriteEntry(string.Format("MES.LotJob:{0} {1}" , job.LotNumber , job.Type.GetDisplayName() , result.Message), EventLogEntryType.Error); } } #endregion } } catch (Exception ex) { this._eventLog.WriteEntry(string.Format("MES.LotJob:{0}", ex.Message), EventLogEntryType.Error); } if (wrapper.Loop) { Thread.Sleep(1000); } } wrapper.AutoResetEvent.Set(); }
public bool stepOut(LotReaderDeviceElement lotinfo, Lot lot, LotReaderFinishedArgs Args, TrackOutParameter p) { bool flag = true; //出站 MethodReturnResult result = null; using (WipEngineerServiceClient client = new WipEngineerServiceClient()) { if (lot.StateFlag == EnumLotState.WaitTrackOut) { IDictionary <string, IList <TransactionParameter> > dicParams = new Dictionary <string, IList <TransactionParameter> >(); //获取工序参数列表。 IList <RouteStepParameter> lstRouteStepParameter = GetParameterList(lot.RouteName, lot.RouteStepName, EnumLotState.WaitTrackOut); if (lstRouteStepParameter != null) { #region 组织批次附加代码 foreach (RouteStepParameter item in lstRouteStepParameter) { if (!dicParams.ContainsKey(lot.Key)) { dicParams.Add(lot.Key, new List <TransactionParameter>()); } string val = null; if (item.Key.ParameterName == "电池片批号" || item.Key.ParameterName == "电池片小包装号") { val = GetCellLotList(item.MaterialType, lot.LineCode, lot.RouteStepName, lot.OrderNumber, p.EquipmentCode); } else { val = GetParameterLotList(item.MaterialType, lot.LineCode, lot.RouteStepName, lot.OrderNumber, p.EquipmentCode); } TransactionParameter tp = new TransactionParameter() { Index = item.ParamIndex, Name = item.Key.ParameterName, Value = val }; dicParams[lot.Key].Add(tp); } p.Paramters = dicParams; #endregion } MethodReturnResult resultTrackOut = client.TrackOutLot(p); if (resultTrackOut.Code == 0) { Args.TransferMsg = string.Format("批次:{0} {1}出站成功", lotinfo.LotNumber, p.RouteOperationName); flag = true; } else { flag = false; Args.TransferMsg = string.Format("批次:{0} {1}出站失败 => ", lotinfo.LotNumber, p.RouteOperationName) + resultTrackOut.Message; } //存储读头扫码结果信息 Args.TransferMsg = Args.TransferMsg + "-------------"; if (OnLotReaderFinished != null) { CommonFun.eventInvoket(() => { OnLotReaderFinished(this, Args); }); } } } ErrorLog(null, Args.TransferMsg); return(flag); }