Beispiel #1
0
 /// <summary>
 /// 添加产品读码数据
 /// </summary>
 /// <param name="data"></param>
 public void Add(CamData data)
 {
     if (!Datas.ContainsKey(data.CamNo))
     {
         Datas.Add(data.CamNo, data);
     }
     else if (!Datas[data.CamNo].Success)
     {
         data.ReadTimes    = Datas[data.CamNo].ReadTimes;
         Datas[data.CamNo] = data;
     }
     Datas[data.CamNo].ReadTimes++;
     UpdateUI();
 }
Beispiel #2
0
        public Product Add(int camNo, int stageId, List <string> data)
        {
            Product product = GetProduct(camNo, stageId);

            var    config    = App.Config.DataMapping.FirstOrDefault(p => p.CAMNO.Contains(camNo));
            bool   isSn      = config?.Mapping.Any(p => p.Name.IndexOf("fgcode", StringComparison.Ordinal) > -1) ?? false;
            double codeCount = data.Count - (isSn ? 8 : 7); //读码个数

            codeCount = codeCount < 0 ? 0 : codeCount;
            int needCount = isSn ? 1 : Config.Station.Count;//期望读码个数

            double  state      = data.Count > 5 ? Convert.ToDouble(data[5]) : -2;
            CamData camOneData = new CamData
            {
                CamNo   = camNo,
                Data    = data,
                Success = Convert.ToBoolean(data[3]) && codeCount == needCount,
                State   = state
            };

            product.Add(camOneData);
            if (state != 1)
            {
                return(product);
            }

            if (!isSn)
            {
                List <string> msg   = new List <string>();
                List <Users>  users = App.Users.Where(p => p.UserClasses == App.Settings.ShiftCode || string.IsNullOrEmpty(p.UserClasses)).ToList();
                //检测工站码数量
                if (codeCount < needCount)
                {
                    msg.Add($"工站条码缺失!期望{needCount}个,读到{codeCount}个");
                }
                if (codeCount > needCount)
                {
                    msg.Add($"工站条码多贴!期望{needCount}个,读到{codeCount}个");
                }

                var code_data = data.Skip(7);
                //检测工站码重复
                int stationIndex = 0;
                foreach (var station in Config.Station)
                {
                    stationIndex++;
                    var uList = users.Where(p => p.UserType == stationIndex.ToString() && code_data.Contains(p.UserCode)).ToList();
                    if (uList.Count > 1)
                    {
                        msg.Add($"{station} 工站码重复[{string.Join(",", uList.Select(p => p.UserCode))}]");
                    }
                }
                //检测工站码配置
                for (int i = 0; i < code_data.Count(); i++)
                {
                    string code = code_data.ElementAt(i);
#if CD
                    //替换工站码班别
                    if (code.IndexOf("A") > -1 || code.IndexOf("B") > -1)
                    {
                        code = App.Settings.ShiftCode + code.Replace("A", "").Replace("B", "");
                    }
#endif
                    var user = users.Where(p => p.UserCode == code).ToList();
                    if (user.Count == 0)
                    {
                        msg.Add($"工站码[{code}]未配置人员");
                    }
                }

                //检测工站缺失
                List <string> ts = users.Where(p => code_data.Contains(p.UserCode)).Select(p => p.UserType).ToList();
                List <string> ls = Config.Station.Where(p => !ts.Contains((Config.Station.IndexOf(p) + 1).ToString())).Select(p => p).ToList();
                if (ls.Count > 0)
                {
                    msg.Add($"[{string.Join(",", ls)}] 工站码缺失");
                }
                if (msg.Count > 0)
                {
                    camOneData.Success = false;
                }
                product.AddNgMsg(msg);
                product.UpdateUI();
            }
            else
            {
                if (codeCount < needCount)
                {
                    product.AddNgMsg($"SN条码缺失!");
                }
                if (codeCount > needCount)
                {
                    product.AddNgMsg($"SN条码多贴!");
                }
                if (camOneData.Success && Config.POSTData.CheckRepeat)
                {
                    string fg = data[config.Mapping[0].Index];
                    //检测重复
                    product.IsRepeat = new DbContext().Db.Queryable <Datas>().Any(p => p.FGCode == fg && p.TracePost == true);
                }
            }
            return(product);
        }