コード例 #1
0
        private void ValidateHj(string barcode)
        {
            this.lblHJCode.Text = barcode;

            bool isNew = false;//新产品标识

            #region 判断合件条码长度
            bool CheckBitRST = Opt.HJValidate(barcode);
            //校验位判断
            if (!CheckBitRST)
            {
                this.lblTip.Text = "合件条码长度不符合!";
                Audio.SoundTip(0);//错误提示音
                return;
            }
            #endregion

            #region 判断校验位
            //判断校验位
            string CheckCode      = barcode.Substring(0, 13); //校验合件条码
            string CheckBitOrigin = barcode.Substring(13, 1); //校验位
            string CheckBit       = Opt.CheckBit(CheckCode);  //获取校验位
            if (!CheckBit.ToLower().Equals(CheckBitOrigin.ToLower()))
            {
                this.lblTip.Text = "合件条码校验位错误!";
                Audio.SoundTip(0);//错误提示音
                return;
            }
            #endregion

            #region //判断特征码
            string fc = barcode.Substring(0, 6);
            //前一个特征码与现在扫描相同
            if (this.productModel != null && this.productModel.FeatureCode == fc)
            {
                //清除前一次信息
                foreach (ListViewItem item in lvMaterial.Items)
                {
                    item.SubItems[2].Text = "";          //初始化状态为空
                    item.ForeColor        = Color.Black; //初始化字体颜色为黑色
                }
            }
            else
            {
                isNew = this.productModel == null;
                if (Opt.FeatureCodeList.ContainsKey(fc))
                {
                    //扫描合件的特征码存在
                    this.productModel = Opt.FeatureCodeList[fc];
                    isNew             = true;
                }
                else
                {
                    //扫描合件的特征码不存在
                    IsHjScan         = true;
                    this.lblTip.Text = "合件条码不符,请重新扫描合件";
                    Audio.SoundTip(0);//错误提示音
                    return;
                }
            }
            #endregion

            #region 加载ListView数据
            if (isNew)
            {
                InitListView();
            }
            #endregion

            Audio.SoundTip(1); //扫描提示音
            RecordScanInfo();  //记录扫描信息
            IsHjScan         = false;
            this.lblTip.Text = "请扫描零件条码或批次条码";
        }
コード例 #2
0
        //方法
        #region 方法

        #region 通用扫描方法
        /// <summary>
        /// 通用扫描方法
        /// </summary>
        /// <param name="obj"></param>
        private void doCommonScan(string barcode)
        {
            try
            {
                this.lblScanCode.Text      = "";//清空提示信息
                this.lblScanCode.ForeColor = Color.Navy;

                //判断是合件条码还是材料条码
                if (IsHjScan)             //当为合件时
                {
                    RequestParam.Clear(); //清除数据

                    this.lblScanCode.Text = barcode;
                    #region 合件

                    bool isNew = false;//新产品标识

                    #region 判断合件条码长度
                    bool CheckBitRST = Opt.HJValidate(barcode);
                    //校验位判断
                    if (!CheckBitRST)
                    {
                        this.Tip("合件条码长度不符合!");
                        Audio.SoundTip(0);//错误提示音
                        return;
                    }
                    #endregion

                    #region 判断校验位
                    //判断校验位
                    string CheckCode      = barcode.Substring(0, 13); //校验合件条码
                    string CheckBitOrigin = barcode.Substring(13, 1); //校验位
                    string CheckBit       = Opt.CheckBit(CheckCode);  //获取校验位
                    if (!CheckBit.ToLower().Equals(CheckBitOrigin.ToLower()))
                    {
                        this.Tip("合件条码校验位错误!");
                        Audio.SoundTip(0);//错误提示音
                        return;
                    }
                    #endregion

                    #region //判断特征码
                    string fc = barcode.Substring(0, 6);
                    //前一个特征码与现在扫描相同
                    if (this.productModel != null && this.productModel.FeatureCode == fc)
                    {
                        //清除前一次信息
                        foreach (ListViewItem item in lvMaterial.Items)
                        {
                            item.SubItems[1].Text = "";          //初始化状态为空
                            item.SubItems[3].Text = "0";         //初始化状态为空
                            item.ForeColor        = Color.Black; //初始化字体颜色为黑色
                        }
                    }
                    else
                    {
                        isNew = this.productModel == null;
                        if (Opt.FeatureCodeList.ContainsKey(fc))
                        {
                            //扫描合件的特征码存在
                            this.productModel = Opt.FeatureCodeList[fc];
                            isNew             = true;

                            this.lblTitle.Text       = "扫描-" + this.productModel.ProductName;
                            this.lblProductCode.Text = this.productModel.ProductCode;
                        }
                        else
                        {
                            //扫描合件的特征码不存在
                            IsHjScan = true;
                            this.Tip("合件条码不符,请重新扫描合件");
                            Audio.SoundTip(0);//错误提示音
                            return;
                        }
                    }
                    #endregion

                    #region                //判断合件是否存在
                    if (IsValidateBarcode) //if (IsValidateBarcode && CurrnetScanType==1)
                    {
                        if (ValidateScanIsExist(1, barcode, ""))
                        {
                            Tip("当前合件已存在");
                            Audio.SoundTip(0);//错误提示音
                            return;
                        }
                    }
                    #endregion

                    this.lblHJCode.Text = barcode;
                    this.lblOK.Text     = "";

                    #region //判断是否有子零件
                    if (CurrnetScanType == 0)
                    {
                        #region //判断是否为新的产品
                        if (isNew || this.lvMaterial.Items == null || this.lvMaterial.Items.Count == 0)
                        {
                            InitListView();//加载子零件编码列表
                        }
                        #endregion
                    }
                    else
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        //更新到数据库
                        bool ret = ScanResultToDb();
                        if (ret)
                        {
                            Audio.SoundTip(2);
                        }
                        else
                        {
                            Audio.SoundTip(0);//错误提示音
                        }
                        return;
                    }
                    #endregion

                    if (!this.productModel.HaveSub)
                    {
                        IsOK     = true;
                        IsHjScan = true;
                        Audio.SoundTip(0);//错误提示音
                        this.Tip("当前合件没有子零件");
                        return;
                    }

                    //记录扫描信息
                    RecordScanInfo();
                    IsOK     = false;
                    IsHjScan = false;
                    this.Tip("请扫描子零件条码");
                    #endregion

                    //BatchTip();//批次信息提醒
                }
                else
                {
                    //当为子零件时
                    barcode = barcode.Replace("<cr><lf>", "").Replace("\r", "").Replace("\n", "").Replace("]C1", ""); //获取条码/二维码,过滤回车换行
                    this.lblScanCode.Text = barcode;
                    ValidateMaterialInfo(barcode);                                                                    //材料防错,对比特征码
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("扫描条码," + ex.Message);
            }
        }