/// <summary>
    /// 绑定Grid
    /// </summary>
    protected void BindGrid()
    {
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
        DataSet ds = new DataSet();

        try
        {
            string strs = this.StrWhere;

            if (!string.IsNullOrEmpty(txtCustNo.Text))
            {
                strs += " and (custNo like '%" + txtCustNo.Text.Trim().Replace("'", "''")
                    + "%' or custNm like '%" + txtCustNo.Text.Trim().Replace("'", "''") + "%')";
            }

            if (!string.IsNullOrEmpty(txtInvoke.Text))
            {
                strs += " and invoiceNo='" + txtInvoke.Text.Trim().Replace("'", "''") + "'";
            }

            if (!string.IsNullOrEmpty(txtShippingmark.Text))
            {
                strs += " and shippingMarkNo='" + txtShippingmark.Text.Trim().Replace("'", "''") + "'";
            }

            if (!string.IsNullOrEmpty(txtStockUpBill.Text))
            {
                strs += " and stockUpBillNo='" + txtStockUpBill.Text.Trim().Replace("'", "''") + "'";
            }

            if (!string.IsNullOrEmpty(ddlState.SelectedValue))
            {
                strs += " and instantState='" + ddlState.SelectedValue + "'";
            }

            ds = stockUpBillBB.GetVList(strs);
            this.grid.DataSource = ds.Tables[0];
            this.grid.DataBind();

            //赋值记录条数、页面总数
            this.Label3.Text = ds.Tables[0].Rows.Count.ToString();
            this.Label2.Text = this.grid.PageCount.ToString();
            this.currPage.Text = (this.grid.PageIndex + 1).ToString();
        }
        finally
        {
            stockUpBillBB.Dispose();
        }
    }
    /// <summary>
    /// 保存或保存并提交公用方法
    /// </summary>
    /// <param name="isSubmit"></param>
    protected void SubmitArrangeBill(bool isSubmit)
    {
        //要保存之前判断状态是否被改变
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
        string stockUpState = stockUpBillBB.GetVList("stockUpBillNo = '" + stockUpBillNo.Text.Trim() + "'").Tables[0].Rows[0]["instantState"].ToString();
        stockUpBillNo.Dispose();
        if (stockUpState != StockUpinstantState)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"拣货单已经被别人生成\");", true);
            return;
        }
        using (CPickOutPlanBC planBC = new CPickOutPlanBC())
        {
            CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB();
            LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();

            try
            {
                #region 判断是否完全拣货

                DataSet dsStockUpDetail_Temp = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + this.stockUpBillNo.Text.Trim() + "'");

                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"]);
                    }

                    //计算原物料可拣货数量
                    //7月25号修改
                    //解决拣货单下发不下去的问题
                    //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)
                        {
                            //7月25号修改
                            //解决拣货单下发不下去的问题
                            //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)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!\");", true);
                        return;
                    }
                }

                #endregion 判断是否完全拣货

                planBC.EmpID = this.currentUser.empId;
                planBC.SavePickOutPlanBill(this.DtResult, this.stockUpBillNo.Text.Trim(), isSubmit);

                this.DtResult = null;
                this.InitDtPickOutPlan();

                if (isSubmit)//保存并提交
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"拣货单维护成功!\");window.location='"
                            + Request.Params["backurl"] + "';", 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
            {
                stockUpDetailBB.Dispose();
                materialRelationBB.Dispose();
            }
        }
    }
    /// <summary>
    /// 页面实始化
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            string id = Request.Params["id"];

            if (id != null && id != "")
            {
                this.IdValue = Convert.ToInt32(id);
                this.ShowStockUpBillInfo();//显示销售备货单信息
                this.InitDtPickOutPlan();//初始化拣货计划数据源
                this.BindWareLocator(this.ddlWareLocator);//绑定工作台
            }

            CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
            StockUpinstantState = stockUpBillBB.GetVList("stockUpBillNo = '" + stockUpBillNo.Text.Trim() + "'").Tables[0].Rows[0]["instantState"].ToString();
            stockUpBillNo.Dispose();

        }
    }