protected void btnAdd_Click(object sender, EventArgs e)
    {
        PManageDepartData model = new PManageDepartData();
        PManageDepartBB manageDepartBB = new PManageDepartBB();
        try
        {
            if (this.State == "1")
            {
                //�û�����һ����Ӷ��������
                manageDepartBB.AddRecord(Convert.ToInt32(this.empId.Value), Convert.ToInt32(this.roleId.SelectedValue), this.departId.Value);
            }
            else if (this.State == "2")
            {
                model = manageDepartBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                manageDepartBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            manageDepartBB.Dispose();
        }

        Response.Redirect("PManageDepartList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false);
    }
 private void ShowInfo(int id)
 {
     PManageDepartBB manageDepartBB = new PManageDepartBB();
     vPManageDepartData model = new vPManageDepartData();
     try
     {
         model = manageDepartBB.GetVModel(id);
         this.empNm.Text = model.empNm.ToString();
         this.roleName.Text = model.roleName;
         this.departNm.Text = model.departNm.ToString();
     }
     finally
     {
         manageDepartBB.Dispose();
     }
 }
    /// <summary>
    /// ��Grid
    /// </summary>
    protected void BindGrid()
    {
        PManageDepartBB manageDepartBB = new PManageDepartBB();
        DataSet ds = new DataSet();

        try
        {
            ds = manageDepartBB.GetVList(this.StrWhere);
            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
        {
            manageDepartBB.Dispose();
        }
    }
    /// <summary>
    /// ɾ��
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        bool retChecked = false;
        PManageDepartBB manageDepartBB = new PManageDepartBB();
        try
        {
            //��ȡѡ�е�����Id
            foreach (GridViewRow gvrow in this.grid.Rows)
            {
                CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
                if (chkId.Checked == true)
                {
                    retChecked = true;
                    int id = int.Parse(chkId.ValidationGroup);
                    manageDepartBB.DeleteRecord(id);
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            manageDepartBB.Dispose();
        }

        if (retChecked)
        {
            this.BindGrid();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.BindList();
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                this.IdValue = Convert.ToInt32(Request.Params["id"]);
            }
            if (Request.Params["state"] != null && Request.Params["state"].Trim() != string.Empty)
            {
                this.State = Request.Params["state"].ToString();
                switch (this.State)
                {
                    case "1":   //add
                        this.btnConsultDept.Attributes.Add("onclick", "javascript:ConsultDepartment('departId','departNm','',1,3);");
                        break;
                    case "2":   //update
                        //���ؿؼ�
                        this.btnConsultDept.Attributes.Add("onclick", "javascript:ConsultDepartment('departId','departNm','',0,3);");

                        PManageDepartBB manageDepartBB = new PManageDepartBB();
                        PManageDepartData manageDepartData = new PManageDepartData();
                        try
                        {
                            manageDepartData = manageDepartBB.GetModel(this.IdValue);

                            this.ShowInfo(this.IdValue);
                        }
                        finally
                        {
                            manageDepartBB.Dispose();
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
 private void ShowInfo(int id)
 {
     PManageDepartBB manageDepartBB = new PManageDepartBB();
     vPManageDepartData model = new vPManageDepartData();
     try
     {
         model = manageDepartBB.GetVModel(id);
         this.empId.Value = model.empId.ToString();
         this.empNm.Value = model.empNm;
         if (this.roleId.Items.FindByValue(model.roleId.ToString()) != null)
         {
             this.roleId.SelectedValue = model.roleId.ToString();
         }
         this.departId.Value = model.departId.ToString();
         this.departNm.Value = model.departNm;
     }
     finally
     {
         manageDepartBB.Dispose();
     }
 }