Пример #1
0
    /// <summary>
    /// 自动生成拣货计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPlan_click(object sender, EventArgs e)
    {
        UStockBB stockBB = new UStockBB();
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
        CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB();
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();
        LMaterialBB materialBB = new LMaterialBB();

        try
        {
            CStockUpBillData stockUpBillModel = new CStockUpBillData();
            DataSet dsStock = new DataSet();
            DataSet dsStockUpDetail = new DataSet();
            DataRow[] drsStock = null;
            string strInfo = "";

            stockUpBillModel = stockUpBillBB.GetModel(this.IdValue);//销售备货单实例

            #region 生成按单的拣货信息

            //如果是按单,则直接查找按单采购物料
            //dsStock = stockBB.GetVListByGroup("(saleBillNo in ('" + stockUpBillModel.saleBillNos.Replace(",", "','")
            //    + "') or substring(financeBillNo,1,charindex('-',financeBillNo)) like '%"
            //    + this.hidCustNo.Value + "%') and isOutStocking=0 and wareLocatorNo<>''");

            //如果是按单,则直接查找按单采购物料
            dsStock = stockBB.GetVListByGroup_ByFinanceBillNo("(stock.saleBillNo in ('" + stockUpBillModel.saleBillNos.Replace(",", "','")
                + "') or '," + stockUpBillModel.financeBillNos + ",' like '%,'+stock.financeBillNo+',%') and stock.financeBillSortNo='01' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");

            //获取定向的备货单明细
            dsStockUpDetail = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo
                + "' and financeBillSort='按单'");//and isnull(financeBillNo,'')<>''

            if (dsStock.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow drStockUpDetail in dsStockUpDetail.Tables[0].Rows)
                {
                    //备货单明细合计出来的某种物料总数量
                    int needCount = Convert.ToInt32(drStockUpDetail["num"]);
                    string strMaterialNo = drStockUpDetail["materialno"].ToString();//物料号
                    string strFinanceBillNo = drStockUpDetail["financeBillNo"].ToString();
                    //string strFinanceBillSort = drStockUpDetail["financeBillSort"].ToString();
                    string strFinanceBillSort = "按单";
                    string strDocEntry = drStockUpDetail["docEntry"].ToString();//销售订单ID
                    string strSaleBillNo = drStockUpDetail["saleBillNo"].ToString();//销售订单号
                    string strLineNum = drStockUpDetail["lineNum"].ToString();//行号
                    string strAbsEntry = drStockUpDetail["absEntry"].ToString();//提货单编号

                    #region 按单的需原物料拣货

                    while (needCount > 0)
                    {
                        //根据先进先出,尽量使用同一托盘原则
                        //找到仓库内的同种物料所在的库位以及数量
                        //首先查找不少于此需要物料数量的库位
                        drsStock = dsStock.Tables[0].Select("financeBillNo='" + strFinanceBillNo
                           + "' and materialNo='" + strMaterialNo + "' and num>=" + needCount.ToString());

                        if (drsStock.Length == 0)
                        {
                            drsStock = dsStock.Tables[0].Select("financeBillNo='" + strFinanceBillNo
                                + "' and materialNo='" + strMaterialNo + "' and num>0");
                        }

                        if (drsStock.Length > 0)
                        {
                            //当前库位所拥有该物料的数量
                            int haveCount = Convert.ToInt32(drsStock[0]["num"]);

                            //如果当前库位的物料数量大于备货单所需数量,就保存当前库位
                            DataRow drnew = this.DtResult.NewRow();

                            drnew["rowId"] = Guid.NewGuid().ToString();
                            drnew["id"] = 0;

                            if (haveCount >= needCount)
                            {
                                drnew["num"] = needCount;
                            }
                            else
                            {
                                drnew["num"] = haveCount;
                            }

                            drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量

                            needCount = needCount - Convert.ToInt32(drnew["num"]);

                            drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo;
                            drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString();
                            drnew["wareNo"] = drsStock[0]["wareNo"];
                            drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"];
                            drnew["palletNo"] = drsStock[0]["palletNo"];
                            drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号
                            drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号
                            drnew["wareNm"] = drsStock[0]["wareNm"];
                            drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"];
                            drnew["materialDesc"] = drsStock[0]["materialDesc"];
                            drnew["financeBillNo"] = strFinanceBillNo;//采购合同号
                            drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型
                            drnew["saleBillNo"] = strSaleBillNo;//销售订单号
                            drnew["docEntry"] = strDocEntry;//销售订单ID
                            drnew["lineNum"] = strLineNum;//行号
                            drnew["absEntry"] = strAbsEntry;//提货单号
                            drnew["instantState"] = "01";
                            drnew["isDel"] = false;

                            this.DtResult.Rows.Add(drnew);

                            drStockUpDetail["num"] = needCount;//重新赋值拣货数量
                        }
                        else
                        {
                            needCount = 0;
                        }
                    }

                    #endregion 按单的需原物料拣货
                }
            }

            #endregion 生成按单的拣货信息

            #region 销售订单没有按单采购

            //备货需要逐个库位查找
            dsStock = stockBB.GetVListByGroup("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");

            //获取备货的备货单明细
            dsStockUpDetail = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo
                + "' and financeBillSort='备货'");//根据采购合同类型,不根据采购合同号判断 and (isnull(financeBillNo,'')=''

            if (dsStock.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow drStockUpDetail in dsStockUpDetail.Tables[0].Rows)
                {
                    //备货单明细合计出来的某种物料总数量
                    int needCount = Convert.ToInt32(drStockUpDetail["num"]);
                    string strMaterialNo = drStockUpDetail["materialno"].ToString();//物料号
                    string strFinanceBillNo = "";
                    string strFinanceBillSort = "备货";
                    string strSaleBillNo = drStockUpDetail["saleBillNo"].ToString();//销售订单号
                    string strLineNum = drStockUpDetail["lineNum"].ToString();//行号
                    string strAbsEntry = drStockUpDetail["absEntry"].ToString();//提货单编号
                    string strDocEntry = drStockUpDetail["docEntry"].ToString();//销售订单ID

                    while (needCount > 0)
                    {
                        #region 原物料拣货

                        //找到仓库内的同种物料所在的库位以及数量
                        drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                            + "' and num>=" + needCount.ToString());

                        if (drsStock.Length == 0)
                        {
                            drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo + "' and num>0");
                        }

                        if (drsStock.Length > 0)
                        {
                            //当前库位所拥有该物料的数量
                            int haveCount = Convert.ToInt32(drsStock[0]["num"]);

                            //如果当前库位的物料数量大于备货单所需数量,就保存当前库位
                            DataRow drnew = this.DtResult.NewRow();

                            drnew["rowId"] = Guid.NewGuid().ToString();
                            drnew["id"] = 0;

                            if (haveCount >= needCount)
                            {
                                drnew["num"] = needCount;
                            }
                            else
                            {
                                drnew["num"] = haveCount;
                            }

                            drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量

                            needCount = needCount - Convert.ToInt32(drnew["num"]);

                            drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo;
                            drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString();
                            drnew["wareNo"] = drsStock[0]["wareNo"];
                            drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"];
                            drnew["palletNo"] = drsStock[0]["palletNo"];
                            drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号
                            drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号
                            drnew["wareNm"] = drsStock[0]["wareNm"];
                            drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"];
                            drnew["materialDesc"] = drsStock[0]["materialDesc"];
                            drnew["instantState"] = "01";
                            drnew["financeBillNo"] = strFinanceBillNo;//采购合同号
                            drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型
                            drnew["saleBillNo"] = strSaleBillNo;//销售订单号
                            drnew["docEntry"] = strDocEntry;//销售订单ID
                            drnew["lineNum"] = strLineNum;//行号
                            drnew["absEntry"] = strAbsEntry;//提货单号
                            drnew["isDel"] = false;

                            this.DtResult.Rows.Add(drnew);

                            drStockUpDetail["num"] = needCount;//重新赋值拣货数量
                        }
                        else
                        {
                            break;
                        }

                        #endregion 原物料拣货
                    }

                    #region 根据物料对应关系拣货

                    while (needCount > 0)
                    {
                        //需要根据物料对应关系拣其他物料
                        DataTable dtConvertMaterial = new DataTable();

                        dtConvertMaterial = materialRelationBB.GetList("oldMaterialNo='" + strMaterialNo + "'").Tables[0];

                        if (dtConvertMaterial.Rows.Count == 0)
                        {
                            break;
                        }

                        foreach (DataRow row in dtConvertMaterial.Rows)
                        {
                            //找到仓库内的有对应关系物料所在的库位以及数量
                            drsStock = dsStock.Tables[0].Select("materialno='" + row["newMaterialNo"].ToString()
                                + "' and num>=" + needCount.ToString());

                            if (drsStock.Length == 0)
                            {
                                drsStock = dsStock.Tables[0].Select("materialno='" + row["newMaterialNo"].ToString() + "' and num>0");
                            }

                            if (drsStock.Length > 0)
                            {
                                //当前库位所拥有该物料的数量
                                int haveCount = Convert.ToInt32(drsStock[0]["num"]);

                                //如果当前库位的物料数量大于备货单所需数量,就保存当前库位
                                DataRow drnew = this.DtResult.NewRow();

                                drnew["rowId"] = Guid.NewGuid().ToString();
                                drnew["id"] = 0;

                                if (haveCount >= needCount)
                                {
                                    drnew["num"] = needCount;
                                }
                                else
                                {
                                    drnew["num"] = haveCount;
                                }

                                drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量

                                needCount = needCount - Convert.ToInt32(drnew["num"]);

                                drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo;
                                drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString();
                                drnew["wareNo"] = drsStock[0]["wareNo"];
                                drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"];
                                drnew["palletNo"] = drsStock[0]["palletNo"];
                                drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号
                                drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号
                                drnew["wareNm"] = drsStock[0]["wareNm"];
                                drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"];
                                drnew["materialDesc"] = drsStock[0]["materialDesc"];
                                drnew["instantState"] = "01";
                                drnew["financeBillNo"] = strFinanceBillNo;//采购合同号
                                drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型
                                drnew["saleBillNo"] = strSaleBillNo;//销售订单号
                                drnew["docEntry"] = strDocEntry;//销售订单ID
                                drnew["lineNum"] = strLineNum;//行号
                                drnew["absEntry"] = strAbsEntry;//提货单号
                                drnew["isDel"] = false;

                                this.DtResult.Rows.Add(drnew);

                                drStockUpDetail["num"] = needCount;//重新赋值拣货数量
                            }
                            else
                            {
                                needCount = 0;
                                break;

                            }

                        }

                    }

                    #endregion 根据物料对应关系拣货
                }
            }

            #endregion 销售订单没有按单采购

            #region 判断是否完全拣货

            DataSet dsStockUpDetail_Temp = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo + "'");

            foreach (DataRow rowStockUpDetail in dsStockUpDetail_Temp.Tables[0].Rows)
            {
                int planNum = 0, factNum = 0;
                DataRow[] myDataRowArray = null;
                string strNewMaterialNo = "";
                DataTable dtConvertMaterial = new DataTable();

                //计算计划备货数量
                myDataRowArray = dsStockUpDetail_Temp.Tables[0].Select("materialNo='"
                    + rowStockUpDetail["materialNo"].ToString() + "'");
                foreach (DataRow row in myDataRowArray)
                {
                    planNum += Convert.ToInt32(row["num"]);
                }

                //计算原物料可拣货数量

                //20140725  update
                //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='"
                //    + rowStockUpDetail["materialNo"].ToString() + "'");
                myDataRowArray = this.DtResult.Select("isDel=0 and materialNo=stockupmaterialNo and materialNo='"
                 + rowStockUpDetail["materialNo"].ToString() + "'");
                foreach (DataRow row in myDataRowArray)
                {
                    factNum += Convert.ToInt32(row["num"]);
                }
                // 20140807 add
                if (planNum != factNum)
                {
                    //获取转换物料的拣货数量
                    dtConvertMaterial = materialRelationBB.GetList("oldMaterialNo='" + rowStockUpDetail["materialNo"].ToString() + "'").Tables[0];
                    if (dtConvertMaterial.Rows.Count > 0)
                    {
                        //  20140725  update
                        //strNewMaterialNo = dtConvertMaterial.Rows[0]["newMaterialNo"].ToString();

                        //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='" + strNewMaterialNo + "'");
                        strNewMaterialNo = dtConvertMaterial.Rows[0]["oldMaterialNo"].ToString();
                        myDataRowArray = this.DtResult.Select("isDel=0 and stockupmaterialNo='" + strNewMaterialNo + "' and materialNo<>stockupmaterialNo ");

                        foreach (DataRow row in myDataRowArray)
                        {
                            factNum += Convert.ToInt32(row["num"]);
                        }
                    }
                }

                //判断是否完成拣货
                if (planNum != factNum)
                {
                    strInfo += "物料【" + rowStockUpDetail["materialNo"].ToString() + "】,计划拣货【"
                        + planNum.ToString() + "】件,实际拣货【" + factNum.ToString() + "】件;";

                }
            }

            if (strInfo != "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!提示信息:" + strInfo + "\");", true);
            }

            #endregion 判断是否完全拣货

            this.BindGridPickOutPlan();//绑定拣货计划列表
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            stockBB.Dispose();
            stockUpBillBB.Dispose();
            stockUpDetailBB.Dispose();
            materialRelationBB.Dispose();
            saleDetailBB.Dispose();
            materialBB.Dispose();
        }
    }
    /// <summary>
    /// 拣货单解锁
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOpenPickOutBill_Click(object sender, EventArgs e)
    {
        //获取选中的数据Id
        foreach (GridViewRow gvrow in this.grid.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
            if (chkId.Checked == true)
            {
                string id = this.grid.DataKeys[gvrow.RowIndex].Values["id"].ToString();

                //实时获取订单状态
                using (CStockUpBillBB stockUpBillBB = new CStockUpBillBB())
                {
                    CStockUpBillData stockUpBillModel = stockUpBillBB.GetModel(Convert.ToInt32(id));

                    //备货单已提交或已生成拣货单
                    if (stockUpBillModel.instantState != "02" && stockUpBillModel.instantState != "03")
                    {
                        stockUpBillModel.instantState = "03";//状态更改为“已生成拣货单”
                        stockUpBillModel.updtDt = System.DateTime.Now.ToString();
                        stockUpBillModel.updtEmpId = this.currentUser.empId;

                        stockUpBillBB.ModifyRecord(stockUpBillModel);

                        return;
                    }
                    else
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前备货单不需要解锁拣货单!\");", true);
                        return;
                    }
                }
            }
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择一条记录!\");", true);
        return;
    }
    /// <summary>
    /// 生成拣货单
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPickBill_Click(object sender, EventArgs e)
    {
        //获取选中的数据Id
        foreach (GridViewRow gvrow in this.grid.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
            if (chkId.Checked == true)
            {
                string id = this.grid.DataKeys[gvrow.RowIndex].Values["id"].ToString();
                string stno = this.grid.DataKeys[gvrow.RowIndex].Values["stockUpBillNo"].ToString();

                //实时获取订单状态
                using (CStockUpBillBB billBB = new CStockUpBillBB())
                {
                    CStockUpBillData data = billBB.GetModel(Convert.ToInt32(id));
                    if (data.instantState == "02" || data.instantState == "03")
                    {
                        string strCurrUrl = "", strBackUrl = "";

                        strCurrUrl = HttpContext.Current.Request.Url.OriginalString;
                        strBackUrl = Server.UrlEncode(strCurrUrl);

                        Response.Redirect("~/Page/Operation/CPickOutBill/CPickOutBill.aspx?id=" + id
                            + "&itemNo=" + this.itemNo + "&pTypeNo=main&backUrl=" + strBackUrl);
                        return;
                    }
                    else
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前备货单不能生成拣货单!\");", true);
                        return;
                    }
                }
            }
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择一条记录!\");", true);
        return;
    }
Пример #4
0
    /// <summary>
    /// 删除备货单明细
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridStockUpDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();

        try
        {
            CStockUpBillData stockUpBillModel = new CStockUpBillData();
            string Id = this.gridStockUpDetail.DataKeys[e.RowIndex].Values["id"].ToString();//ID
            string rowid = this.gridStockUpDetail.DataKeys[e.RowIndex].Values["rowId"].ToString();//GUID
            string materialNo = this.gridStockUpDetail.DataKeys[e.RowIndex].Values["materialNo"].ToString();//物料编号
            DataRow[] myDataRowArray_Result = null;

            //根据rowid查找备货明细
            myDataRowArray_Result = this.DtResult.Select("rowid='" + rowid + "'");
            if (myDataRowArray_Result.Length > 0)
            {
                //更改删除标志
                myDataRowArray_Result[0]["isdel"] = "1";//删除
                myDataRowArray_Result[0]["num"] = 0;

                //判断备货单是否已经提交
                stockUpBillModel = stockUpBillBB.GetModel(this.IdValue);
                if (stockUpBillModel != null && stockUpBillModel.instantState != "01")
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('已提交数据无法删除!');", true);
                    return;
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            this.BindGridStockUpDetail();//绑定备货单明细列表
            this.SaveStencilDetailViewState();//保存备货信息
            this.BindGridSaleBill();//显示销售订单明细列表
            stockUpBillBB.Dispose();
        }
    }
Пример #5
0
    /// <summary>
    /// 保存或提交备货单公共方法
    /// </summary>
    /// <param name="isSubmit"></param>
    protected void SubmitArrangeBill(bool isSubmit)
    {
        CStockUpBillBC stockUpBillBC = new CStockUpBillBC();
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();

        try
        {
            this.SaveStencilDetailViewState();//保存备货信息
            this.BindGridStockUpDetail();//绑定备货单明细列表
            this.BindGridSaleBill();//显示销售订单明细列表

            if (this.ValidateArrangeDetail())
            {
                CStockUpBillData data = stockUpBillBB.GetModel(this.StockBillNo);

                if (data == null)
                {
                    #region 未生成备货单

                    data = new CStockUpBillData();

                    data.id = 0;
                    data.stockUpBillNo = this.StockBillNo;
                    data.invoiceNo = this.invoiceNo.Text;
                    data.stockUpEmpId = Convert.ToInt32(this.empId.Value == "" ? "0" : this.empId.Value);
                    data.mark = this.mark.Text;
                    data.custNo = this.CustomNo;
                    data.outStockDt = this.outStockDt.Text;
                    data.saleBillNos = this.lbSaleBillNos.Text;
                    data.lineNums = Request.QueryString["lineNums"];
                    data.absEntrys = Request.QueryString["absEntrys"];
                    data.financeBillNos = Request.QueryString["financeBillNos"];
                    data.shippingMarkNo = this.shippingMarkNo.Text;
                    data.isrtDt = DateTime.Now.ToString();
                    data.isrtEmpId = this.currentUser.empId;

                    if (isSubmit)
                    {
                        data.instantState = "02";
                        data.updtDt = DateTime.Now.ToString();
                        data.updtEmpId = this.currentUser.empId;
                        data.commitDt = DateTime.Now.ToString();
                        data.commitEmpId = this.currentUser.empId;
                    }
                    else
                    {
                        data.instantState = "01";
                        data.updtDt = DateTime.Now.ToString();
                        data.updtEmpId = this.currentUser.empId;
                    }

                    #endregion 未生成备货单
                }
                else
                {
                    #region 已生成备货单

                    if (data.instantState != "01")
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert9", "alert(\"当前备货单已经提交,不允许继续修改备货单信息!\");", true);
                        return;
                    }

                    data.invoiceNo = this.invoiceNo.Text;
                    data.stockUpEmpId = Convert.ToInt32(this.empId.Value == "" ? "0" : this.empId.Value);
                    data.mark = this.mark.Text;
                    data.custNo = this.CustomNo;
                    data.outStockDt = this.outStockDt.Text;
                    data.shippingMarkNo = this.shippingMarkNo.Text;
                    data.updtDt = DateTime.Now.ToString();
                    data.updtEmpId = this.currentUser.empId;

                    if (isSubmit)
                    {
                        data.instantState = "02";
                        data.updtDt = DateTime.Now.ToString();
                        data.updtEmpId = this.currentUser.empId;
                        data.commitDt = DateTime.Now.ToString();
                        data.commitEmpId = this.currentUser.empId;
                    }
                    else
                    {
                        data.instantState = "01";
                        data.updtDt = DateTime.Now.ToString();
                        data.updtEmpId = this.currentUser.empId;
                    }

                    #endregion 已生成备货单
                }

                if (stockUpBillBC.SaveBArrangeBill(data, this.DtResult, isSubmit))
                {
                    this.DtResult = null;
                    this.InitDtResult();//初始化备货单明细数据源
                    this.BindGridStockUpDetail();//绑定备货单明细列表
                    this.BindGridSaleBill();//绑定销售订单明细列表

                    if (isSubmit)//提交
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"备货单维护成功!\");window.location='"
                            + Request.Params["backurl"] + "';", true);
                    }
                    else//保存
                    {
                        this.BindGridStockUpDetail();//绑定备货单明细列表
                        this.BindGridSaleBill();//绑定销售订单明细列表
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"备货单维护成功!\");", true);
                    }
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"备货单维护失败!\");", true);
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            stockUpBillBB.Dispose();
            stockUpBillBC.Dispose();
        }
    }
    /// <summary>
    /// 删除备货单
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gvrow in this.grid.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
            if (chkId.Checked == true)
            {
                string id = this.grid.DataKeys[gvrow.RowIndex].Values["id"].ToString();

                CStockUpBillBB billBB = new CStockUpBillBB();

                CStockUpBillData data = billBB.GetModel(Convert.ToInt32(id));
                string stockUpBillNo = data.stockUpBillNo;//获取要删除的备货单号

                SCommBB commBB = new SCommBB();
                object returnValue =commBB.ExecuteScalar(@"select top 1 stockUpBillNo from CPickOutPlan where stockUpBillNo = '"+stockUpBillNo+"' and instantState<>'01'");
                if (returnValue != null)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"备货单  " + stockUpBillNo + " 不允许删除因为已经开始执行!\");", true);
                    return;
                }
                else
                {
                    try
                    {
                        commBB.ExecuteSql("Exec [DeleteStockUpBillNo] '" + stockUpBillNo + "'");
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"备货单  " + stockUpBillNo + " 删除错误删除成功!\");", true);
                    }
                    catch (Exception error)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"备货单  " + stockUpBillNo + " 删除错误" + error.Message + "!\");", true);
                    }
                    finally
                    {
                        commBB.Dispose();
                    }
                }

            }
        }
    }