Example #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BatchNoMDL model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BatchNo set ");
            strSql.Append("MaterialCode=@MaterialCode,");
            strSql.Append("MaterialName=@MaterialName,");
            strSql.Append("BatchNo=@BatchNo,");
            strSql.Append("BatchNum=@BatchNum,");
            strSql.Append("StockNum=@StockNum,");
            strSql.Append("Supplier=@Supplier");
            strSql.Append(" where TID=@TID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MaterialCode", model.MaterialCode),
                new SqlParameter("@MaterialName", model.MaterialName),
                new SqlParameter("@BatchNo",      model.BatchNo),
                new SqlParameter("@BatchNum",     model.BatchNum),
                new SqlParameter("@StockNum",     model.StockNum),
                new SqlParameter("@Supplier",     model.Supplier),
                new SqlParameter("@TID",          model.TID)
            };

            int rows = helper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 新增批次信息
        /// </summary>
        /// <param name="ProductType">产品类型</param>
        /// <param name="model">批次信息</param>
        /// <returns></returns>
        public bool Insert(BatchNoMDL model)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict.Add("do", "add");
            dict.Add("ProductType", model.ProductType);
            dict.Add("BarCode", model.BarCode);
            dict.Add("MaterialCode", model.MaterialCode);
            dict.Add("MaterialName", model.MaterialName);
            dict.Add("BatchNo", model.BatchNo);
            dict.Add("BatchNum", model.BatchNum);
            dict.Add("Supplier", model.Supplier);
            string     str        = Http.POST(requestUrl, dict);
            var        obj        = JsonHelper.JsonDeSerializer <ReturnInfo>(str);
            ReturnInfo ReturnData = (ReturnInfo)obj;

            if (ReturnData != null && ReturnData.Code == "1")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(BatchNoMDL model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BatchNo(");
            strSql.Append("MaterialCode,MaterialName,BatchNo,BatchNum,StockNum,Supplier)");
            strSql.Append(" values (");
            strSql.Append("@MaterialCode,@MaterialName,@BatchNo,@BatchNum,@StockNum,@Supplier)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MaterialCode", model.MaterialCode),
                new SqlParameter("@MaterialName", model.MaterialName),
                new SqlParameter("@BatchNo",      model.BatchNo),
                new SqlParameter("@BatchNum",     model.BatchNum),
                new SqlParameter("@StockNum",     model.StockNum),
                new SqlParameter("@Supplier",     model.Supplier)
            };

            int rows = helper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        private void SetQrCode(string code)
        {
            string pcode    = code.Substring(0, 10);
            string bnumstr  = code.Substring(10, 5);  //包装量
            string supplier = code.Substring(15, 10); //供应商代码
            string bno      = code.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;

            this.lblTip.Text = "请录入合件条码";
            this.tbBarCode.Focus();
        }
Example #5
0
        /// <summary>
        /// 加载数据
        /// </summary>
        public void LoadData()
        {
            try
            {
                string    sql   = string.Format("SELECT DISTINCT(materialcode),materialname,CASE WHEN batchnum > 0 then batchnum ELSE 0 END batchnum FROM ProductBomInfo WHERE TraceType='{0}' AND ProductType = '{1}' ORDER BY materialcode ASC", "批次追溯", BaseVariable.DeviceEntity.ProductType);
                DataTable table = LocalDbDAL.GetDataTable(sql);

                if (table == null || table.Rows.Count < 1)
                {
                    MaterialInfoList = null;
                    return;
                }
                this.cmbMaterialCode.Items.Add("--- 请选择 ---");
                foreach (DataRow row in table.Rows)
                {
                    BatchNoMDL model = new BatchNoMDL()
                    {
                        MaterialCode = row["MaterialCode"].ToString(),
                        MaterialName = row["MaterialName"].ToString(),
                        BatchNum     = int.Parse(row["BatchNum"].ToString())
                    };
                    if (!MaterialInfoList.ContainsKey(model.MaterialCode))
                    {
                        this.cmbMaterialCode.Items.Add(model.MaterialCode);
                        MaterialInfoList.Add(model.MaterialCode, model);
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[Frmbatch.LoadInfo]" + ex.Message);
            }
        }
        /// <summary>
        /// 更新批次信息
        /// </summary>
        private void Update(BatchNoMDL model = null)
        {
            try
            {
                if (model == null)//Insert 方法传过来的
                {
                    this.Insert();
                    return;
                }
                else
                {
                    bool flag = DataDAL.Update(model);
                    if (flag)
                    {
                        ReturnData.Code = "1";
                        ReturnData.Msg  = "OK";
                    }

                    BatchNoHisDAL HisDAL   = new BatchNoHisDAL();
                    BatchNoHisMDL HisModel = new BatchNoHisMDL();
                    HisModel.MaterialCode = model.MaterialCode;
                    HisModel.BatchNo      = model.BatchNo;
                    HisModel.BatchNum     = model.BatchNum;
                    HisModel.Supplier     = model.Supplier;
                    HisModel.CreateTime   = DateTime.Now;
                    flag = HisDAL.Add(HisModel);
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message + ex.StackTrace);
            }
        }
        /// <summary>
        /// 添加批量追溯信息
        /// </summary>
        private void GetBatchInfoToModel()
        {
            #region 添加批量追溯信息
            if (RemoteMaterialHT != null && RemoteMaterialHT.Count > 0)
            {
                LocalMaterialHT.Clear();
                foreach (DictionaryEntry item in RemoteMaterialHT)        // 遍历哈希表
                {
                    //从数据库获取当前批次材料信息
                    BatchNoMDL model = batchDAL.GetModel(string.Format("MaterialCode='{0}'", item.Key.ToString()));
                    LocalMaterialHT.Add(item.Key.ToString(), model);
                    //获取更新的字段
                    materialFieldModel = materialFieldDAL.GetModel(string.Format("materialcode='{0}'", item.Key.ToString()));
                    //更新对应字段
                    #region 更新对应字段
                    if (materialFieldModel != null)
                    {
                        switch (materialFieldModel.FieldName)
                        {
                        //制动泵编码
                        case "brakepumpcode":
                            resultModel.brakepumpcode = model.BatchNo;
                            break;

                        //密封垫批次号
                        case "gasketbatchno":
                            resultModel.gasketbatchno = model.BatchNo;
                            break;

                        //六角(法兰面)螺母
                        case "hexagonalnutbatchno":
                            resultModel.hexagonalnutbatchno = model.BatchNo;
                            break;

                        //压力传感器批次号
                        case "pressuresensorbatchno":
                            resultModel.pressuresensorbatchno = model.BatchNo;
                            break;

                        //消音器(制动泵隔音垫)
                        case "silencerbatchno":
                            resultModel.silencerbatchno = model.BatchNo;
                            break;

                        //结合管(制动连接管)
                        case "connectingpipe":
                            resultModel.connectingpipe = model.BatchNo;
                            break;

                        //助力器制动泵支架
                        case "boosterbrakepumpbracket":
                            resultModel.boosterbrakepumpbracket = model.BatchNo;
                            break;
                        }
                    }
                    #endregion
                }
            }
            #endregion
        }
        /// <summary>
        /// 添加批量追溯信息
        /// </summary>
        private void GetBatchInfoToModel()
        {
            #region 添加批量追溯信息
            if (RemoteMaterialHT != null && RemoteMaterialHT.Count > 0)
            {
                LocalMaterialHT.Clear();
                foreach (DictionaryEntry item in RemoteMaterialHT)        // 遍历哈希表
                {
                    //从数据库获取当前批次材料信息
                    BatchNoMDL model = batchDAL.GetModel(string.Format("MaterialCode='{0}'", item.Key.ToString()));
                    LocalMaterialHT.Add(item.Key.ToString(), model);
                    //获取更新的字段
                    materialFieldModel = materialFieldDAL.GetModel(string.Format("materialcode='{0}'", item.Key.ToString()));
                    //更新对应字段
                    #region 更新对应字段
                    if (materialFieldModel != null)
                    {
                        switch (materialFieldModel.FieldName)
                        {
                        //踏板总成
                        case "pedalassycode":
                            resultModel.pedalassycode = model.BatchNo;
                            break;

                        //油门踏板
                        case "accelpedalcode":
                            resultModel.accelpedalcode = model.BatchNo;
                            break;

                        //离合器把手批次号
                        case "cluthhandlebatchno":
                            resultModel.cluthhandlebatchno = model.BatchNo;
                            break;

                        //螺栓批次号
                        case "boltbatchno":
                            resultModel.boltbatchno = model.BatchNo;
                            break;

                        //螺母批次号
                        case "nutbatchno":
                            resultModel.nutbatchno = model.BatchNo;
                            break;
                        }
                    }
                    #endregion
                }
            }
            #endregion
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BatchNoMDL DataRowToModel(DataRow row)
        {
            BatchNoMDL model = new BatchNoMDL();

            if (row != null)
            {
                if (row["TID"] != null && row["TID"].ToString() != "")
                {
                    model.TID = long.Parse(row["TID"].ToString());
                }
                if (row["BarCode"] != null)
                {
                    model.BarCode = row["BarCode"].ToString();
                }
                if (row["ProductType"] != null)
                {
                    model.ProductType = row["ProductType"].ToString();
                }
                if (row["MaterialCode"] != null)
                {
                    model.MaterialCode = row["MaterialCode"].ToString();
                }
                if (row["MaterialName"] != null)
                {
                    model.MaterialName = row["MaterialName"].ToString();
                }
                if (row["BatchNo"] != null)
                {
                    model.BatchNo = row["BatchNo"].ToString();
                }
                if (row["BatchNum"] != null && row["BatchNum"].ToString() != "")
                {
                    model.BatchNum = int.Parse(row["BatchNum"].ToString());
                }
                if (row["StockNum"] != null && row["StockNum"].ToString() != "")
                {
                    model.StockNum = int.Parse(row["StockNum"].ToString());
                }
                if (row["Supplier"] != null)
                {
                    model.Supplier = row["Supplier"].ToString();
                }
                if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
                }
            }
            return(model);
        }
 /// <summary>
 /// 获取历史批次信息
 /// </summary>
 private void Select()
 {
     try
     {
         string method = context.Request.Params["method"].ToString();
         if (method == "model")
         {
             string TID = context.Request.Params["TID"].ToString();
             // string MaterialCode = context.Request.Params["MaterialCode"].ToString();
             string sql = " 1=1 ";
             if (!string.IsNullOrEmpty(TID))
             {
                 sql += string.Format(" AND TID = {0}", TID);
             }
             //if (!string.IsNullOrEmpty(MaterialCode))
             //{
             //    sql += string.Format(" AND MaterialCode = '{0}'", MaterialCode);
             //}
             //sql = " LIMIT 1 ";
             BatchNoMDL model = DataDAL.GetModel(sql);
             if (model != null)
             {
                 ReturnData.Code = "1";
                 ReturnData.Msg  = "OK";
                 ReturnData.Data = model;
             }
         }
         else if (method == "search")
         {
             string    ProductCode = context.Request.Params["ProductCode"].ToString();
             string    ProductType = context.Request.Params["ProductType"].ToString();
             string    TableName   = context.Request.Params["TableName"].ToString();
             string    sql         = string.Format("SELECT CASE WHEN n.tid > 0 then n.tid ELSE 0 END TID,t.materialcode MaterialCode,t.materialname MaterialName,n.batchno BatchNo,t.batchnum BatchNum,CASE WHEN n.stocknum > -1 then n.stocknum ELSE 0 END Stocknum FROM (SELECT b.producttype,b.productcode,b.tracetype,b.batchnum,f.materialcode,f.materialname,f.tablename FROM materialfield f INNER JOIN productbominfo b ON f.materialcode=b.materialcode) t LEFT JOIN batchno n ON t.materialcode=n.materialcode WHERE t.producttype='{0}' AND t.productcode='{1}' AND t.tablename='{2}' AND t.tracetype in({3});", ProductType, ProductCode, TableName, "'批次追溯'");
             DataTable table       = CommonDAL.GetDataTable(sql);
             if (table != null && table.Rows.Count > 0)
             {
                 object obj = TableHelper.TableToObj(table);
                 ReturnData.Code = "1";
                 ReturnData.Msg  = "OK";
                 ReturnData.Data = obj;
             }
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Example #11
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BatchNoMDL GetModel(string where)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select TOP 1 TID,MaterialCode,MaterialName,BatchNo,BatchNum,StockNum,Supplier from BatchNo ");
            if (!string.IsNullOrEmpty(where))
            {
                strSql.Append(" where " + where);
            }

            BatchNoMDL model = new BatchNoMDL();
            DataSet    ds    = helper.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Example #12
0
 /// <summary>
 /// 产品编码下拉框选择事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmbMaterialCode_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (this.cmbMaterialCode.Items != null && this.cmbMaterialCode.SelectedIndex > 0)
         {
             string code = this.cmbMaterialCode.Text;
             if (MaterialInfoList.ContainsKey(code))
             {
                 BatchNoMDL model = MaterialInfoList[code] as BatchNoMDL;
                 this.cmbMaterialCode.Text    = model.MaterialCode;
                 this.lblMaterialName.Text    = model.MaterialName;
                 this.tbMaterialBatchNum.Text = model.BatchNum.ToString();
                 this.scantype = ScanType.MATERIALCODE;
                 this.IsOK     = false;
             }
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.StackTrace);
     }
 }
Example #13
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BatchNoMDL GetModel(long TID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select TID,MaterialCode,MaterialName,BatchNo,BatchNum,StockNum,Supplier from BatchNo ");
            strSql.Append(" where TID=@TID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TID", TID)
            };

            BatchNoMDL model = new BatchNoMDL();
            DataSet    ds    = helper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Example #14
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);
            }
        }
Example #15
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);
            }
        }
        /// <summary>
        /// 添加批次信息
        /// </summary>
        private void Insert()
        {
            try
            {
                //string ProductCode = context.Request.Params["ProductCode"].ToString();
                string ProductType  = context.Request.Params["ProductType"].ToString();
                string MaterialCode = context.Request.Params["MaterialCode"].ToString();
                string BatchNo      = context.Request.Params["BatchNo"].ToString();
                string BatchNumStr  = context.Request.Params["BatchNum"].ToString();
                string Supplier     = context.Request.Params["Supplier"].ToString();
                int    BatchNum     = 0;
                bool   b            = int.TryParse(BatchNumStr, out BatchNum);

                BatchNoMDL Model = null;
                string     sql   = string.Format("materialcode='{0}'", MaterialCode);
                Model = DataDAL.GetModel(sql);
                if (Model != null)
                {
                    Model.BatchNo  = BatchNo;
                    Model.BatchNum = (b && BatchNum > 0) ? BatchNum : Model.BatchNum;
                    Model.StockNum = Model.BatchNum;
                    Model.Supplier = Supplier;

                    this.Update(Model);
                    return;
                }
                else
                {
                    Model = new BatchNoMDL();
                    sql   = string.Format("producttype='{0}' AND materialcode='{1}'", ProductType, MaterialCode);
                    ProductBomInfoDAL pb   = new ProductBomInfoDAL();
                    ProductBomInfoMDL info = pb.GetModel(sql);

                    if (b && BatchNum > 0)
                    {
                        Model.BatchNum = BatchNum;
                    }
                    else
                    {
                        if (info != null || info.BatchNum.ToString().Trim() != "")
                        {
                            Model.BatchNum = int.Parse(info.BatchNum.ToString());
                        }
                        else
                        {
                            Model.BatchNum = 1;
                        }
                    }
                    Model.StockNum     = Model.BatchNum;
                    Model.MaterialCode = MaterialCode;
                    Model.MaterialName = info.MaterialName;
                    Model.BatchNo      = BatchNo;
                    Model.Supplier     = Supplier;

                    bool flag = DataDAL.Add(Model);
                    if (flag)
                    {
                        ReturnData.Code = "1";
                        ReturnData.Msg  = "OK";
                    }

                    BatchNoHisDAL HisDAL   = new BatchNoHisDAL();
                    BatchNoHisMDL HisModel = new BatchNoHisMDL();
                    HisModel.MaterialCode = Model.MaterialCode;
                    HisModel.BatchNo      = BatchNo;
                    HisModel.BatchNum     = Model.BatchNum;
                    HisModel.Supplier     = Model.Supplier;
                    HisModel.CreateTime   = DateTime.Now;
                    flag = HisDAL.Add(HisModel);
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message + ex.StackTrace);
            }
        }
        /// <summary>
        /// 防错追溯,将信息添加到数据库
        /// </summary>
        private void ScanResultToDb()
        {
            try
            {
                if (resultModel != null)
                {
                    bool rst = false;
                    if (!BaseVariable.NetworkStatus || !BaseVariable.ServerStatus)        //离线状态
                    {
                        resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                        if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0"))
                        {
                            resultModel.tid = IsExistLocal.tid;
                            string sql = DataExistToDb(false);
                            rst = LocalDbDAL.ExecuteSql(sql);        //存到本地数据库
                        }
                        else
                        {
                            rst = lResultDAL.Add(resultModel);        //添加到本地数据库
                        }
                    }
                    else        //在线状态
                    {
                        //添加批量追溯信息
                        GetBatchInfoToModel();

                        //同步到数据库:在没有同步到远程数据库时记录到本地数据库
                        #region  步到数据库
                        resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        rst = false;        //更新到远程服务器数据库是否成功
                        PedalResultMDL IsExistRomote = resultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                        //更新到远程服务器数据库
                        if (IsExistRomote != null && !IsExistRomote.tid.ToString().Equals("0"))
                        {
                            resultModel.tid        = IsExistRomote.tid;
                            resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            //封装更新字段
                            string sql = DataExistToDb(true);
                            //sql += string.Format("CreateTime='{0}',", resultModel.CreateTime);
                            rst = CommonDAL.ExecuteSql(sql, null);        //存到远程服务器数据库
                        }
                        else
                        {
                            rst = resultDAL.Add(resultModel);        //添加到远程服务器数据库
                        }
                        //更新到本地数据库
                        //rst = false;
                        if (!rst)
                        {
                            PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                            if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0"))
                            {
                                resultModel.tid = IsExistLocal.tid;
                                string sql = DataExistToDb(true);
                                rst = LocalDbDAL.ExecuteSql(sql);        //存到本地数据库
                            }
                            else
                            {
                                rst = lResultDAL.Add(resultModel);        //添加到本地数据库
                            }
                        }
                        //批次材料数量更新
                        foreach (DictionaryEntry item in RemoteMaterialHT)        // 遍历哈希表
                        {
                            string            code = item.Key.ToString();
                            ProductBomInfoMDL obj  = item.Value as ProductBomInfoMDL;
                            //var obj = item.Value;
                            BatchNoMDL model = LocalMaterialHT[code] as BatchNoMDL;
                            model.StockNum -= obj.MaterialNum;
                            batchDAL.Update(model);        //更新数据
                        }
                        #endregion
                        if (rst)
                        {
                            this.lblOK.Text      = "OK";
                            this.lblOK.ForeColor = Color.Green;
                        }
                        else
                        {
                            this.lblOK.Text      = "NG";
                            this.lblOK.ForeColor = Color.Red;
                        }
                        BatchChangeTip();        //批次数量提示
                    }
                }
                else
                {
                    this.Tip("记录错误");
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[FrmScan.ScanResultToDB]" + ex.Message);
            }
        }