/// <summary>
    /// 数据保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        BTallyBillData model = new BTallyBillData();
        BTallyBillBB tallyBillBB = new BTallyBillBB();
        try
        {
            if (this.State == "1")
            {
                this.SetModel(ref model);
                model.isrtDt = DateTime.Now.ToString();
                model.isrtEmpId = this.currentUser.empId;
                this.IdValue = tallyBillBB.AddRecord(model);
            }
            else if (this.State == "2")
            {
                model = tallyBillBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                model.updtDt = DateTime.Now.ToString();
                model.updtEmpId = this.currentUser.empId;
                tallyBillBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            tallyBillBB.Dispose();
        }

        Response.Redirect("BTallyBillList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false);
    }
    /// <summary>
    /// 指定入库
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnInput_Click(object sender, EventArgs e)
    {
        bool retChecked = false;//是否选择

        foreach (GridViewRow gvrow in this.grid.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
            if (chkId.Checked == true)
            {
                UStockBB stockBB = new UStockBB();
                BTallyBillBB tallyBillBB = new BTallyBillBB();
                UStockBC stockBC = new UStockBC();

                try
                {
                    BTallyBillData tallyBillModel = tallyBillBB.GetModel(this.IdValue);

                    if (tallyBillModel.instantState != "02")//状态不是“已理货完成”
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前托盘已经指定了库位!\");", true);
                        return;
                    }
                    else
                    {
                        string strwhere = "wareLocatorNo='" + chkId.ValidationGroup + "'";
                        DataSet ds = stockBB.GetList(strwhere);

                        if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前库位已经被占用!\");", true);
                            return;
                        }
                        else
                        {
                            tallyBillModel.instantState = "03";//指定状态为“已入库”
                            tallyBillModel.isInStock = true;// 入库状态
                            tallyBillModel.wareLocatorNo = chkId.ValidationGroup;//库位

                            retChecked = stockBC.SetPalletWarelocator(tallyBillModel,this.ddlWare.SelectedValue);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
                    return;
                }
                finally
                {
                    tallyBillBB.Dispose();
                    stockBB.Dispose();
                    stockBC.Dispose();
                }
            }
        }

        if (retChecked)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"库位指定成功!\"); location.replace('UStockList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main');", true);
            return;
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择一个库位!\");", true);
        return;
    }
    public int SaveTallyBill(string strPalletNo, int isrtEmpId, string strInstantState)
    {
        BTallyBillBB tallyBillBB = new BTallyBillBB();

        try
        {
            int mainId = 0;
            DataSet ds = new DataSet();
            BTallyBillData tallyBillModel = new BTallyBillData();

            //判断当前托盘是否已经理货
            ds = tallyBillBB.GetList("palletNo='" + strPalletNo + "' and isInStock=0");
            if (ds.Tables[0].Rows.Count == 0)
            {
                tallyBillModel.palletNo = strPalletNo;//托盘条码号
                tallyBillModel.isInStock = false;//是否入库
                tallyBillModel.isrtDt = System.DateTime.Now.ToString();//添加时间
                tallyBillModel.isrtEmpId = isrtEmpId;//添加人
                tallyBillModel.instantState = "01";//理货中

                mainId = tallyBillBB.AddRecord(tallyBillModel);//称重理货单ID赋值
            }
            else
            {
                mainId = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);//称重理货单ID赋值

                if (strInstantState == "02")//理货已完成
                {
                    tallyBillModel = tallyBillBB.GetModel(mainId);

                    tallyBillModel.instantState = "02";//理货已完成

                    tallyBillBB.ModifyRecord(tallyBillModel);
                }
            }

            return mainId;
        }
        finally
        {
            tallyBillBB.Dispose();
        }
    }