Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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();
        }