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

                return;
            }
            else
            {
                if (!string.IsNullOrEmpty(txtSearchFacultyName.Text))
                {
                    ClassFaculty f1 = new ClassFaculty();
                    DataTable dt1 = f1.GetFaculty(txtSearchFacultyName.Text, "");
                    GridView1.DataSource = dt1;
                    GridView1.DataBind();
                    SetViewState(dt1);
                }
                if (ddlSearchCampus.SelectedIndex != 0)
                {
                    ClassFaculty f2 = new ClassFaculty();
                    DataTable dt2 = f2.GetFaculty("", ddlSearchCampus.SelectedValue);
                    GridView1.DataSource = dt2;
                    GridView1.DataBind();
                    SetViewState(dt2);
                }
            }
        }
 void BindData1()
 {
     if (!string.IsNullOrEmpty(txtSearchFacultyName.Text))
     {
         ClassFaculty f1 = new ClassFaculty();
         DataTable dt1 = f1.GetFaculty(txtSearchFacultyName.Text, "");
         GridView1.DataSource = dt1;
         GridView1.DataBind();
         SetViewState(dt1);
     }
     if (ddlSearchCampus.SelectedIndex != 0)
     {
         ClassFaculty f2 = new ClassFaculty();
         DataTable dt2 = f2.GetFaculty("", ddlSearchCampus.SelectedValue);
         GridView1.DataSource = dt2;
         GridView1.DataBind();
         SetViewState(dt2);
     }
 }
 void BindData()
 {
     ClassFaculty f = new ClassFaculty();
     DataTable dt = f.GetFaculty("", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
        protected void modUpdateCommand(Object sender, GridViewUpdateEventArgs e)
        {
            Label lblFacultyIDEdit = (Label)GridView1.Rows[e.RowIndex].FindControl("lblFacultyIDEdit");
            TextBox txtFacultyNameEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFacultyNameEdit");
            DropDownList ddlCampusIDEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlCampusIDEdit");

            ClassFaculty f = new ClassFaculty(Convert.ToInt32(lblFacultyIDEdit.Text)
                , txtFacultyNameEdit.Text
                , Convert.ToInt32(ddlCampusIDEdit.SelectedValue));

            if (f.CheckUseFacultyName())
            {
                f.UpdateFaculty();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('อัพเดทข้อมูลเรียบร้อย')", true);
                GridView1.EditIndex = -1;
                BindData1();
            }
            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);
            ClassFaculty f = new ClassFaculty();
            f.FACULTY_ID = id;
            f.DeleteFaculty();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ลบข้อมูลเรียบร้อย')", true);

            if (txtSearchFacultyName.Text != "" || ddlSearchCampus.SelectedIndex != 0)
            {
                GridView1.EditIndex = -1;
                BindData1();
            }
            else
            {
                GridView1.EditIndex = -1;
                BindData();
            }
        }
        protected void lbuSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtInsertFacultyName.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ ชื่อสำนัก / สถาบัน / คณะ')", true);
                return;
            }

            if (ddlInsertCampus.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก วิทยาเขต')", true);
                return;
            }
            ClassFaculty f = new ClassFaculty();
            f.FACULTY_NAME = txtInsertFacultyName.Text;
            f.CAMPUS_ID = Convert.ToInt32(ddlInsertCampus.SelectedValue);

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