/// <summary>
        /// 添加历史批次信息
        /// </summary>
        private void Insert()
        {
            try
            {
                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);
                string CreateTime   = context.Request.Params["CreateTime"].ToString();
                if (string.IsNullOrEmpty(MaterialCode) || string.IsNullOrEmpty(BatchNo))
                {
                    ReturnData.Msg = "参数错误";
                }
                else
                {
                    BatchNoHisMDL Model = new BatchNoHisMDL();
                    Model.MaterialCode = MaterialCode;
                    Model.BatchNo      = BatchNo;
                    Model.Supplier     = Supplier;

                    if (b)
                    {
                        Model.BatchNum = BatchNum;
                    }

                    if (!string.IsNullOrEmpty(CreateTime))
                    {
                        Model.CreateTime = DateTime.Parse(CreateTime);
                    }
                    else
                    {
                        Model.CreateTime = DateTime.Now;
                    }
                    bool flag = DataDAL.Add(Model);
                    if (flag)
                    {
                        ReturnData.Code = "1";
                        ReturnData.Msg  = "OK";
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(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 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);
            }
        }