protected void lbuRefresh_Click(object sender, EventArgs e)
 {
     ClearData();
     ClassPsPosition p = new ClassPsPosition();
     DataTable dt = p.GetPsPosition("", "", "", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
        protected void lbuSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSearchDegree.Text) && ddlSearchGroup.SelectedIndex == 0 && ddlSearchNameGroup.SelectedIndex == 0 && ddlSearchTypeName.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณากรอก คำค้นหา')", true);

                return;
            }
            else
            {
                if (!string.IsNullOrEmpty(txtSearchDegree.Text))
                {
                    ClassPsPosition p = new ClassPsPosition();
                    DataTable dt = p.GetPsPosition(txtSearchDegree.Text, "", "", "");
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    SetViewState(dt);
                }
                if (ddlSearchGroup.SelectedIndex != 0)
                {
                    ClassPsPosition p = new ClassPsPosition();
                    DataTable dt = p.GetPsPosition("", ddlSearchGroup.SelectedValue, "", "");
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    SetViewState(dt);
                }
                if (ddlSearchNameGroup.SelectedIndex != 0)
                {
                    ClassPsPosition p = new ClassPsPosition();
                    DataTable dt = p.GetPsPosition("", "", ddlSearchNameGroup.SelectedValue, "");
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    SetViewState(dt);
                }
                if (ddlSearchTypeName.SelectedIndex != 0)
                {
                    ClassPsPosition p = new ClassPsPosition();
                    DataTable dt = p.GetPsPosition(txtSearchDegree.Text, "", "", ddlSearchTypeName.SelectedValue);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    SetViewState(dt);
                }
            }
        }
 void BindData1()
 {
     if (!string.IsNullOrEmpty(txtSearchDegree.Text))
     {
         ClassPsPosition p = new ClassPsPosition();
         DataTable dt = p.GetPsPosition(txtSearchDegree.Text, "", "", "");
         GridView1.DataSource = dt;
         GridView1.DataBind();
         SetViewState(dt);
     }
     if (ddlSearchGroup.SelectedIndex != 0)
     {
         ClassPsPosition p = new ClassPsPosition();
         DataTable dt = p.GetPsPosition("", ddlSearchGroup.SelectedValue, "", "");
         GridView1.DataSource = dt;
         GridView1.DataBind();
         SetViewState(dt);
     }
     if (ddlSearchNameGroup.SelectedIndex != 0)
     {
         ClassPsPosition p = new ClassPsPosition();
         DataTable dt = p.GetPsPosition("", "", ddlSearchNameGroup.SelectedValue, "");
         GridView1.DataSource = dt;
         GridView1.DataBind();
         SetViewState(dt);
     }
     if (ddlSearchTypeName.SelectedIndex != 0)
     {
         ClassPsPosition p = new ClassPsPosition();
         DataTable dt = p.GetPsPosition(txtSearchDegree.Text, "", "", ddlSearchTypeName.SelectedValue);
         GridView1.DataSource = dt;
         GridView1.DataBind();
         SetViewState(dt);
     }
 }
 void BindData()
 {
     ClassPsPosition p = new ClassPsPosition();
     DataTable dt = p.GetPsPosition("", "", "","");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
        protected void modUpdateCommand(Object sender, GridViewUpdateEventArgs e)
        {
            Label lblpsPersonIDEdit = (Label)GridView1.Rows[e.RowIndex].FindControl("lblpsPersonIDEdit");
            TextBox txtpsPersonDegreeEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpsPersonDegreeEdit");
            DropDownList ddlpsPersonGroupEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlpsPersonGroupEdit");
            DropDownList ddlpsPersonNameGroupEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlpsPersonNameGroupEdit");
            DropDownList ddlpsPersonTypeNameEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlpsPersonTypeNameEdit");

            ClassPsPosition p = new ClassPsPosition(Convert.ToInt32(lblpsPersonIDEdit.Text)
                , txtpsPersonDegreeEdit.Text
                , Convert.ToInt32(ddlpsPersonGroupEdit.SelectedValue)
                , ddlpsPersonNameGroupEdit.SelectedValue
                , ddlpsPersonTypeNameEdit.SelectedValue);

            if (p.CheckUsePsPositionNameAndGroup())
            {
                p.UpdatePsPosition();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('อัพเดทข้อมูลเรียบร้อย')", true);
                GridView1.EditIndex = -1;
                BindData();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ข้อมูลที่จะอัพเดท มีอยู่ในระบบแล้ว !')", true);
            }
        }
        protected void modDeleteCommand(Object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
            ClassPsPosition p = new ClassPsPosition();
            p.P_ID = id;
            p.DeletePsPosition();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ลบข้อมูลเรียบร้อย')", true);

            GridView1.EditIndex = -1; ;
            BindData();
        }
        protected void lbuSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtInsertDegree.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ ชื่อระดับ')", true);
                return;
            }
            if (ddlInsertGroup.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก กลุ่มระดับ')", true);
                return;
            }
            if (ddlInsertNameGroup.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก ตำแหน่งประเภท')", true);
                return;
            }
            if (ddlInsertTypeName.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก ประเภทของตำแหน่ง')", true);
                return;
            }
            ClassPsPosition p = new ClassPsPosition();
            p.P_NAME = txtInsertDegree.Text;
            p.P_GROUP = Convert.ToInt32(ddlInsertGroup.SelectedValue);
            p.P_NAMEGROUP = ddlInsertNameGroup.SelectedValue;
            p.P_TYPENAME = ddlInsertTypeName.SelectedValue;

            if (p.CheckUsePsPositionNameAndGroup())
            {
                p.InsertPsPosition();
                BindData();
                ClearData();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('เพิ่มข้อมูลเรียบร้อย')", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ข้อมูลที่จะเพิ่ม มีอยู่ในระบบแล้ว !')", true);
            }
        }