Пример #1
0
        /// <summary>
        /// 应用更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsOK)
                {
                    this.lblTip.Text = "未录入数据!!!";
                    Audio.SoundTip(0);//失败提示音
                    return;
                }
                if (!string.IsNullOrEmpty(this.cmbMaterialCode.Text) &&
                    this.cmbMaterialCode.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbMaterialBatchNo.Text) &&
                    this.tbMaterialBatchNo.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbMaterialBatchNum.Text) &&
                    this.tbMaterialBatchNum.Text.Trim() != "" &&
                    !string.IsNullOrEmpty(this.tbBarCode.Text) &&
                    this.tbBarCode.Text.Trim() != "")
                {
                    if (IsEdit)
                    {
                        #region //添加合件验证
                        if (!Opt.ValidatePartCode(this.cmbMaterialCode.Text, this.tbBarCode.Text.Trim()))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "扫描的合件不匹配,请重新录入";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbBarCode.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入合件条码";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNo.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入批次流水号";
                            return;
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNum.Text))
                        {
                            Audio.SoundTip(0);
                            this.lblTip.Text = "请录入包装数量";
                            return;
                        }
                        else
                        {
                            int num = 0;
                            try
                            {
                                num = int.Parse(this.tbMaterialBatchNum.Text);
                            }
                            catch (Exception)
                            {
                                num      = 0;
                                scantype = ScanType.PacketNumber;
                            }

                            if (num == 0)
                            {
                                this.lblTip.Text = "扫描包装数量不是数字或=0";
                                return;
                            }
                        }
                        //if (string.IsNullOrEmpty(this.tbSupplier.Text))
                        //{
                        //    Audio.SoundTip(0);
                        //    this.lblTip.Text = "请录入供应商编码";
                        //    return;
                        //}
                        #endregion
                    }

                    BatchNoMDL model = MaterialInfoList[this.cmbMaterialCode.Text.Trim()] as BatchNoMDL;
                    if (model == null)
                    {
                        return;
                    }

                    string barcode  = this.tbBarCode.Text.Trim();
                    string batchno  = this.tbMaterialBatchNo.Text.Trim();
                    string supplier = this.tbSupplier.Text.Trim();
                    int    batchnum = model.BatchNum;
                    if (!string.IsNullOrEmpty(this.tbMaterialBatchNum.Text.Trim()))
                    {
                        try
                        {
                            int num = int.Parse(this.tbMaterialBatchNum.Text.Trim());
                            batchnum = num;
                        }
                        catch (Exception)
                        {
                        }
                    }

                    model.BarCode     = barcode;
                    model.BatchNo     = batchno;
                    model.Supplier    = supplier;
                    model.BatchNum    = batchnum;
                    model.ProductType = BaseVariable.DeviceEntity.ProductType;

                    bool flag = false;         //结果标识
                    if (Opt.GlobalNetStatus()) //存储到服务器
                    {
                        flag = batchDAL.Insert(model);
                    }
                    else//存储到服务器
                    {
                        flag = lBatchDAL.Add(model);
                    }

                    if (flag)
                    {
                        IsOK             = true;
                        scantype         = ScanType.MATERIALCODE;
                        this.lblTip.Text = "更新成功,请扫描批次条码";
                        Audio.SoundTip(2);//正确提示音
                    }
                    else
                    {
                        this.lblTip.Text = "更新失败,请重试";
                        Audio.SoundTip(0);//失败提示音
                    }
                }
                else
                {
                    this.lblTip.Text = "批次相关信息不能为空";
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[Frmbatch.Apply]" + ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 扫描执行操作的方法
        /// </summary>
        /// <param name="obj"></param>
        private void ScanOptFun(string barcode, SymbologyOptions.SymbologyType t)
        {
            try
            {
                if (!IsEdit)
                {
                    #region 扫描录入
                    this.lblTip.Text = "";

                    switch (scantype)
                    {
                    case ScanType.MATERIALCODE: //材料编码扫描
                    {
                        #region                 //材料编码扫描
                        this.cmbMaterialCode.SelectedIndex = -1;
                        this.lblMaterialName.Text          = "";
                        this.tbMaterialBatchNum.Text       = "";
                        this.tbMaterialBatchNo.Text        = "";
                        this.tbSupplier.Text = "";
                        this.tbBarCode.Text  = "";
                        string pcode = "";

                        //判断是否为二维码
                        #region         // 二维码
                        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)
                        {
                            pcode = barcode.Substring(0, 10);
                            if (MaterialInfoList.ContainsKey(pcode))
                            {
                                //能够匹配
                                Audio.SoundTip(1);                           //扫描提示音
                                string bnumstr  = barcode.Substring(10, 5);  //包装量
                                string supplier = barcode.Substring(15, 10); //供应商代码
                                string bno      = barcode.Substring(25, 13); //批次号

                                BatchNoMDL model = MaterialInfoList[pcode] as BatchNoMDL;

                                int batchnum = model.BatchNum;
                                try
                                {
                                    int bnum = int.Parse(bnumstr);
                                    batchnum = bnum;
                                }
                                catch (Exception)
                                {
                                }

                                this.cmbMaterialCode.Text    = model.MaterialCode;
                                this.lblMaterialName.Text    = model.MaterialName;
                                this.tbMaterialBatchNum.Text = batchnum.ToString();
                                this.tbSupplier.Text         = supplier;
                                this.tbMaterialBatchNo.Text  = bno;
                                IsOK     = false;
                                scantype = ScanType.HJBARCODE;

                                this.tbBarCode.Focus();
                                this.lblTip.Text = "请扫描合件条码";
                            }
                            else
                            {
                                //不能够匹配
                                Audio.SoundTip(0);        //错误提示音
                                scantype                    = ScanType.MATERIALCODE;
                                this.lblTip.Text            = "扫描的条码的零件不符当前产品";
                                this.tbMaterialBatchNo.Text = barcode;
                                IsOK = true;
                            }
                            return;
                        }
                        #endregion

                        string code = barcode.Substring(1);
                        this.cmbMaterialCode.Text = code;        //扫描的条码
                        if (MaterialInfoList.ContainsKey(code))
                        {
                            Audio.SoundTip(1);                //扫描提示音
                            scantype = ScanType.PacketNumber; //修改扫描类型为供应商条码
                            BatchNoMDL model = MaterialInfoList[code] as BatchNoMDL;
                            this.cmbMaterialCode.Text = model.MaterialCode;
                            this.lblMaterialName.Text = model.MaterialName;
                            //this.tbMaterialBatchNum.Text = model.BatchNum.ToString();

                            this.tbMaterialBatchNum.Focus();

                            this.lblTip.Text = "请扫描包装数量";
                            //this.lblTip.Text = "请扫描供应商编码";
                        }
                        else
                        {
                            Audio.SoundTip(0);        //错误提示音
                            scantype         = ScanType.MATERIALCODE;
                            this.lblTip.Text = "扫描的条码的零件不符当前产品";
                        }
                        #endregion
                    }
                    break;

                    case ScanType.Supplier:    //供应商编码
                    {
                        Audio.SoundTip(1);     //扫描提示音
                        this.tbSupplier.Text = barcode;
                        scantype             = ScanType.PacketNumber;
                        this.tbMaterialBatchNum.Focus();

                        this.lblTip.Text = "请扫描包装数量";
                    }
                    break;

                    case ScanType.PacketNumber:    //包装数量
                    {
                        this.tbMaterialBatchNum.Text = barcode.ToUpper().Replace("Q", "");
                        int num = 0;
                        try
                        {
                            num = int.Parse(this.tbMaterialBatchNum.Text);
                        }
                        catch (Exception)
                        {
                            num      = 0;
                            scantype = ScanType.PacketNumber;
                        }

                        if (num == 0)
                        {
                            this.lblTip.Text = "扫描包装数量不是数字或=0";
                            return;
                        }

                        scantype = ScanType.BARCODE;
                        this.tbMaterialBatchNo.Focus();

                        this.lblTip.Text = "请扫描批次条码";
                    }
                    break;

                    case ScanType.BARCODE:    //批次条码
                    {
                        string code = barcode.Substring(1);
                        if (barcode.Substring(0, 1).Equals("P") && code == this.cmbMaterialCode.Text)
                        {
                            Audio.SoundTip(0);        //错误提示音
                            this.lblTip.Text = "重复扫描零件条码";
                            scantype         = ScanType.BARCODE;
                        }
                        else
                        {
                            Audio.SoundTip(1);                     //扫描提示音
                            this.tbMaterialBatchNo.Text = barcode; //扫描的条码
                            this.lblTip.Text            = "请扫描合件条码";
                            scantype = ScanType.HJBARCODE;
                            this.tbBarCode.Focus();
                        }
                    }
                    break;

                    case ScanType.HJBARCODE:    //合件条码扫描
                    {
                        this.tbBarCode.Text = barcode;

                        #region         //添加合件验证
                        if (Opt.ValidatePartCode(this.cmbMaterialCode.Text, barcode))
                        {
                            Audio.SoundTip(1);
                            scantype         = ScanType.MATERIALCODE;
                            this.lblTip.Text = "更新信息或者是重新录入";
                            return;
                        }
                        #endregion

                        Audio.SoundTip(0);
                        scantype         = ScanType.HJBARCODE;
                        this.lblTip.Text = "扫描的合件不匹配,请重新录入";
                    }
                    break;
                    }
                    #endregion
                }
                else
                {
                    #region 手动录入
                    if (this.MaterialInfoList != null && this.cmbMaterialCode.SelectedIndex > 0)
                    {
                        //判断是否为二维码
                        if (barcode.Trim().Length >= 38)
                        {
                            var pcode = barcode.Substring(0, 10);
                            if (MaterialInfoList.ContainsKey(pcode))
                            {
                                //能够匹配
                                Audio.SoundTip(1);//扫描提示音
                                SetQrCode(barcode);
                            }
                            return;
                        }

                        if (this.tbBarCode.Focused)
                        {
                            this.tbBarCode.Text = barcode;
                            Audio.SoundTip(1);
                        }
                        else if (this.tbSupplier.Focused)
                        {
                            this.tbSupplier.Text = barcode;
                            Audio.SoundTip(1);
                            this.tbMaterialBatchNum.Focus();
                        }
                        else if (this.tbMaterialBatchNum.Focused)
                        {
                            this.tbMaterialBatchNum.Text = barcode.ToUpper().Replace("Q", "");
                            int num = 0;
                            try
                            {
                                num = int.Parse(this.tbMaterialBatchNum.Text);
                            }
                            catch (Exception)
                            {
                                num = 0;
                            }

                            if (num == 0)
                            {
                                this.lblTip.Text = "扫描包装数量不是数字或=0";
                                Audio.SoundTip(0);
                                return;
                            }

                            Audio.SoundTip(1);
                            this.tbMaterialBatchNo.Focus();
                        }
                        else if (this.tbMaterialBatchNo.Focused)
                        {
                            this.tbMaterialBatchNo.Text = barcode;
                            Audio.SoundTip(1);
                            this.tbBarCode.Focus();
                        }
                        else
                        {
                            return;
                        }

                        int ret = 0;

                        if (string.IsNullOrEmpty(this.tbBarCode.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入合件条码";
                            this.tbBarCode.Focus();
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNo.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入批次流水号";
                            this.tbMaterialBatchNo.Focus();
                        }
                        if (string.IsNullOrEmpty(this.tbMaterialBatchNum.Text))
                        {
                            ret += 1;
                            this.lblTip.Text = "请录入包装数量";
                            this.tbMaterialBatchNum.Focus();
                        }
                        //if (string.IsNullOrEmpty(this.tbSupplier.Text))
                        //{
                        //    ret += 1;
                        //    this.lblTip.Text = "请录入供应商编码";
                        //    this.tbSupplier.Focus();
                        //}

                        if (ret == 0)
                        {
                            this.lblTip.Text = "更新信息或者是重新录入";
                        }
                    }
                    else
                    {
                        Audio.SoundTip(0);//错误提示音
                        this.lblTip.Text = "请选择零件编码";
                        this.cmbMaterialCode.Focus();
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
        }