Exemplo n.º 1
0
        /// <summary>
        /// 扫描验证
        /// </summary>
        /// <param name="barcode"></param>
        private void ScanValidate(string barcode, SymbologyOptions.SymbologyType t)
        {
            try
            {
                barcode = barcode.Replace("<cr><lf>", "").Replace("\r\n", "").Replace("]C1", ""); //获取条码/二维码,过滤回车换行
                bool IsExist = false;                                                             //标记是否存在
                foreach (ListViewItem item in this.lvMaterial.Items)
                {
                    string tmpBarcode   = barcode;
                    string ItemCode     = item.Text.ToString();  //当前的零件编码
                    string FeatureCode  = item.SubItems[3].Text; //特征码
                    string FeatureIndex = item.SubItems[4].Text; //特征位
                    string TraceType    = item.SubItems[4].Text; //追溯类型
                    bool   flag         = false;

                    if (FeatureCode == null || FeatureCode.Trim() == "")
                    {
                        if (tmpBarcode.Length < ItemCode.Length)
                        {
                            continue;
                        }
                        string tmpCode = "";

                        if ((t == SymbologyOptions.SymbologyType.QR_Code ||
                             t == SymbologyOptions.SymbologyType.DataMatrix ||
                             t == SymbologyOptions.SymbologyType.Maxicode ||
                             t == SymbologyOptions.SymbologyType.PDF417 ||
                             t == SymbologyOptions.SymbologyType.Aztec) &&
                            barcode.Trim().Length >= 38)
                        //if (t == SymbologyOptions.SymbologyType.QR_Code && barcode.Trim().Length >= 38) //if (tmpBarcode.Length >= 38)
                        {
                            tmpCode = tmpBarcode.Substring(0, 10);
                            string supplier = tmpBarcode.Substring(15, 10); //供应商代码
                            string bno      = tmpBarcode.Substring(25, 13); //批次号
                            tmpBarcode = bno + ";" + supplier;
                        }
                        //else
                        //{
                        //    tmpCode = tmpBarcode.Substring(0, ItemCode.Length);
                        //}

                        //flag = tmpCode == ItemCode;//判断特征码
                    }
                    else
                    {
                        if (tmpBarcode.Length < FeatureCode.Length)
                        {
                            continue;
                        }
                        flag = Opt.ValidateFeatureCode(tmpBarcode, FeatureIndex, FeatureCode);//判断特征码
                    }

                    if (flag)
                    {
                        materialCode              = ItemCode;
                        item.ForeColor            = Color.Green; //当防错正常时字体为绿色
                        item.SubItems[2].Text     = tmpBarcode;  //扫描条码
                        this.lblMaterialCode.Text = ItemCode;
                        this.lblBarCode.Text      = tmpBarcode;
                        item.Selected             = true;
                        RecordScanInfo();  //记录扫描信息
                        this.lblTip.Text = "扫描零件条码或零件批次条码";
                        Audio.SoundTip(1); //扫描提示音
                        IsExist = true;
                        break;
                    }
                    else
                    {
                        string code = tmpBarcode.Substring(1);
                        bool   IsOk = false;
                        switch (scantype)
                        {
                        case ScanType.MATERIALCODE:
                            if (ItemCode.Equals(code))
                            {
                                this.lblMaterialCode.Text = code;    //扫描的条码
                                this.lblBarCode.Text      = "";
                                materialCode      = ItemCode;
                                item.Selected     = true;            //选中扫描的材料
                                listViewItemIndex = item.Index;
                                Audio.SoundTip(1);                   //扫描提示音
                                scantype         = ScanType.BARCODE; //修改扫描类型为批次条码
                                this.lblTip.Text = "扫描零件批次条码";
                                IsExist          = true;
                                IsOk             = true;
                            }
                            break;

                        case ScanType.BARCODE:
                            this.lblBarCode.Text = tmpBarcode;                                       //扫描的条码
                            this.lvMaterial.Items[listViewItemIndex].ForeColor        = Color.Green; //当防错正常时字体为绿色
                            this.lvMaterial.Items[listViewItemIndex].SubItems[2].Text = tmpBarcode;  //扫描条码
                            scantype = ScanType.MATERIALCODE;
                            RecordScanInfo();                                                        //记录扫描信息
                            this.lblTip.Text = "扫描零件条码或零件批次条码";
                            Audio.SoundTip(1);                                                       //扫描提示音
                            IsExist = true;
                            IsOk    = true;
                            break;

                        default:
                            break;
                        }

                        if (IsOk)
                        {
                            break;
                        }
                    }
                }
                if (!IsExist && scantype != ScanType.BARCODE)//不存在的情况
                {
                    this.lblTip.Text = "扫描零件编码不在此产品之列";
                    Audio.SoundTip(0);//错误提示音
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 材料防错验证-有特征码
        /// </summary>
        /// <param name="code"></param>
        private void ValidateMaterialInfo(string code)
        {
            Stopwatch validateWatch = new Stopwatch();

            try
            {
                if (!IsOK)
                {
                    validateWatch.Start();

                    bool IsExist = false;//标记是否存在
                    //标记为√
                    foreach (ListViewItem item in this.lvMaterial.Items)
                    {
                        bool meterialError = true;
                        materialCode = item.Text.ToString();         //当前的零件编码
                        string FeatureCode  = item.SubItems[5].Text; //特征码
                        string FeatureIndex = item.SubItems[6].Text; //特征位
                        bool   flag         = false;

                        if (FeatureCode == null || FeatureCode.Trim() == "")
                        {
                            if (code.Length < materialCode.Length)
                            {
                                meterialError = true;
                                continue;
                            }
                            string tmpCode = code.Substring(0, materialCode.Length);
                            flag = tmpCode == materialCode;//判断特征码
                        }
                        else
                        {
                            if (code.Length < FeatureCode.Length)
                            {
                                meterialError = true;
                                continue;
                            }

                            flag = Opt.ValidateFeatureCode(code, FeatureIndex, FeatureCode);//判断特征码
                        }
                        if (flag)
                        {
                            //判断零件是否存在
                            #region 判断合件是否存在
                            if (IsValidateBarcode)
                            {
                                string FieldName = item.SubItems[7].Text;
                                if (ValidateScanIsExist(2, code, FieldName))
                                {
                                    Tip("当前零件已使用过");
                                    Audio.SoundTip(0);//错误提示音
                                    return;
                                }
                            }
                            #endregion
                            int num  = int.Parse(item.SubItems[2].Text); //产品数量
                            int scan = int.Parse(item.SubItems[3].Text); //扫描数量

                            if ((scan + 1) == num)
                            {
                                item.SubItems[3].Text = (scan + 1).ToString();
                                item.ForeColor        = Color.Green; //当防错正常时字体为绿色
                                item.SubItems[1].Text = "OK";        //扫描次数刚好和产品数量相等时
                                meterialError         = false;
                                Audio.SoundTip(1);                   //正确提示音
                            }
                            else if ((scan + 1) < num)
                            {
                                item.SubItems[3].Text = (scan + 1).ToString();
                                item.ForeColor        = Color.CornflowerBlue; //当防错正常时字体为浅蓝色
                                item.SubItems[1].Text = "√";                  //扫描次数比产品数量小时
                                meterialError         = false;
                            }
                            else if ((scan + 1) > num)
                            {
                                meterialError = true;
                                this.Tip("该条码扫描次数超出"); //提示
                                Audio.SoundTip(0);     //错误提示音
                            }
                            //记录扫描信息
                            if (!meterialError)
                            {
                                //记录扫描信息
                                RecordScanInfo();
                            }
                            IsExist = true;//标记存在为true
                            break;
                        }
                    }

                    if (!IsExist)
                    {
                        this.Tip("合件不存在该条码的零件"); //提示不存在
                        Audio.SoundTip(0);       //错误提示音
                        return;
                    }

                    this.WirteTimeSpanLog(new TimeSpan(0, 0, 0, 0, (int)validateWatch.ElapsedMilliseconds), LogType.SC);
                    validateWatch.Stop();

                    int error = 0;
                    foreach (ListViewItem item in this.lvMaterial.Items)
                    {
                        if (item.SubItems[1].Text != "OK")
                        {
                            error++;
                        }
                    }
                    if (error == 0)
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        //更新到数据库
                        bool ret = ScanResultToDb();
                        if (ret)
                        {
                            Audio.SoundTip(2);
                        }
                        else
                        {
                            Audio.SoundTip(0);//错误提示音
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[FrmScan.ValidateMaterialInfo]" + ex.Message);
            }
        }