void BindData1()
 {
     if (!string.IsNullOrEmpty(txtSearchDistrictTH.Text))
     {
         ClassDistrict a1 = new ClassDistrict();
         DataTable dt1 = a1.GetDistrict(txtSearchDistrictTH.Text, "", "", "", "", "");
         GridView1.DataSource = dt1;
         GridView1.DataBind();
         SetViewState(dt1);
     }
     if (!string.IsNullOrEmpty(txtSearchDistrictEN.Text))
     {
         ClassDistrict a2 = new ClassDistrict();
         DataTable dt2 = a2.GetDistrict("", txtSearchDistrictEN.Text, "", "", "", "");
         GridView1.DataSource = dt2;
         GridView1.DataBind();
         SetViewState(dt2);
     }
     if (ddlSearchAmphur.SelectedIndex != 0)
     {
         ClassDistrict a3 = new ClassDistrict();
         DataTable dt3 = a3.GetDistrict("", "", ddlSearchAmphur.SelectedValue, "", "", "");
         GridView1.DataSource = dt3;
         GridView1.DataBind();
         SetViewState(dt3);
     }
     if (ddlSearchProvince.SelectedIndex != 0)
     {
         ClassDistrict a4 = new ClassDistrict();
         DataTable dt4 = a4.GetDistrict("", "", "", ddlSearchProvince.SelectedValue, "", "");
         GridView1.DataSource = dt4;
         GridView1.DataBind();
         SetViewState(dt4);
     }
     if (!string.IsNullOrEmpty(txtSearchPostCode.Text))
     {
         ClassDistrict a5 = new ClassDistrict();
         DataTable dt5 = a5.GetDistrict("", "", "", "", txtSearchPostCode.Text, "");
         GridView1.DataSource = dt5;
         GridView1.DataBind();
         SetViewState(dt5);
     }
     if (!string.IsNullOrEmpty(txtSearchNote.Text))
     {
         ClassDistrict a6 = new ClassDistrict();
         DataTable dt6 = a6.GetDistrict("", "", "", "", "", txtSearchNote.Text);
         GridView1.DataSource = dt6;
         GridView1.DataBind();
         SetViewState(dt6);
     }
 }
 protected void lbuRefresh_Click(object sender, EventArgs e)
 {
     ClearData();
     ClassDistrict d = new ClassDistrict();
     DataTable dt = d.GetDistrict("", "", "", "", "", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
 void BindData()
 {
     ClassDistrict d = new ClassDistrict();
     DataTable dt = d.GetDistrict("", "", "", "", "", "");
     GridView1.DataSource = dt;
     GridView1.DataBind();
     SetViewState(dt);
 }
        protected void modUpdateCommand(Object sender, GridViewUpdateEventArgs e)
        {
            Label lblDistrictIDEdit = (Label)GridView1.Rows[e.RowIndex].FindControl("lblDistrictIDEdit");
            TextBox txtDistrictTHEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDistrictTHEdit");
            TextBox txtDistrictENEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDistrictENEdit");
            DropDownList ddlAmphurIDEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlAmphurIDEdit");
            DropDownList ddlProvinceIDEdit = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlProvinceIDEdit");
            TextBox txtPostCodeEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtPostCodeEdit");
            TextBox txtNoteEdit = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtNoteEdit");

            ClassDistrict d = new ClassDistrict(Convert.ToInt32(lblDistrictIDEdit.Text)
                , txtDistrictTHEdit.Text
                , txtDistrictENEdit.Text
                , Convert.ToInt32(ddlAmphurIDEdit.SelectedValue)
                , Convert.ToInt32(ddlProvinceIDEdit.SelectedValue)
                , Convert.ToInt32(txtPostCodeEdit.Text)
                , txtNoteEdit.Text);

            if (d.CheckUseDistrictName())
            {
                d.UpdateDistrict();
                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);
            ClassDistrict d = new ClassDistrict();
            d.DISTRICT_ID = id;
            d.DeleteDistrict();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ลบข้อมูลเรียบร้อย')", true);

            if (txtSearchDistrictTH.Text != "" || txtSearchDistrictEN.Text != "" || ddlSearchAmphur.SelectedIndex != 0 || ddlSearchProvince.SelectedIndex != 0 || txtInsertPostCode.Text != "" || txtInsertNote.Text != "")
            {
                GridView1.EditIndex = -1;
                BindData1();
            }
            else
            {
                GridView1.EditIndex = -1;
                BindData();
            }
        }
        protected void lbuSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtInsertDistrictTH.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ ชื่อตำบลภาษาไทย')", true);
                return;
            }

            if (string.IsNullOrEmpty(txtInsertDistrictEN.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ ชื่อตำบลภาษาอังกฤษ')", true);
                return;
            }
            if (ddlInsertAmphur.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก อำเภอ')", true);
                return;
            }
            if (ddlInsertProvince.SelectedIndex == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาเลือก จังหวัด')", true);
                return;
            }
            if (string.IsNullOrEmpty(txtInsertPostCode.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณาใส่ รหัสไปรษณีย์')", true);
                return;
            }

            ClassDistrict d = new ClassDistrict();
            d.DISTRICT_TH = txtInsertDistrictTH.Text;
            d.DISTRICT_EN = txtInsertDistrictEN.Text;
            d.AMPHUR_ID = Convert.ToInt32(ddlInsertAmphur.SelectedValue);
            d.PROVINCE_ID = Convert.ToInt32(ddlInsertProvince.SelectedValue);
            d.POST_CODE = Convert.ToInt32(txtInsertPostCode.Text);
            d.NOTE = txtInsertNote.Text;

            if (d.CheckUseDistrictName())
            {
                d.InsertDistrict();
                BindData();
                ClearData();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('เพิ่มข้อมูลเรียบร้อย')", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ข้อมูลที่จะเพิ่ม มีอยู่ในระบบแล้ว !')", true);
            }
        }
        protected void lbuSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSearchDistrictTH.Text) && string.IsNullOrEmpty(txtSearchDistrictEN.Text) && ddlSearchAmphur.SelectedIndex == 0 && ddlSearchProvince.SelectedIndex == 0 && string.IsNullOrEmpty(txtSearchPostCode.Text) && string.IsNullOrEmpty(txtSearchNote.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('กรุณากรอก คำค้นหา')", true);

                return;
            }
            else
            {
                if (!string.IsNullOrEmpty(txtSearchDistrictTH.Text))
                {
                    ClassDistrict a1 = new ClassDistrict();
                    DataTable dt1 = a1.GetDistrict(txtSearchDistrictTH.Text, "", "", "", "", "");
                    GridView1.DataSource = dt1;
                    GridView1.DataBind();
                    SetViewState(dt1);
                }
                if (!string.IsNullOrEmpty(txtSearchDistrictEN.Text))
                {
                    ClassDistrict a2 = new ClassDistrict();
                    DataTable dt2 = a2.GetDistrict("", txtSearchDistrictEN.Text, "", "", "", "");
                    GridView1.DataSource = dt2;
                    GridView1.DataBind();
                    SetViewState(dt2);
                }
                if (ddlSearchAmphur.SelectedIndex != 0)
                {
                    ClassDistrict a3 = new ClassDistrict();
                    DataTable dt3 = a3.GetDistrict("", "", ddlSearchAmphur.SelectedValue, "", "", "");
                    GridView1.DataSource = dt3;
                    GridView1.DataBind();
                    SetViewState(dt3);
                }
                if (ddlSearchProvince.SelectedIndex != 0)
                {
                    ClassDistrict a4 = new ClassDistrict();
                    DataTable dt4 = a4.GetDistrict("", "", "", ddlSearchProvince.SelectedValue, "", "");
                    GridView1.DataSource = dt4;
                    GridView1.DataBind();
                    SetViewState(dt4);
                }
                if (!string.IsNullOrEmpty(txtSearchPostCode.Text))
                {
                    ClassDistrict a5 = new ClassDistrict();
                    DataTable dt5 = a5.GetDistrict("", "", "", "", txtSearchPostCode.Text, "");
                    GridView1.DataSource = dt5;
                    GridView1.DataBind();
                    SetViewState(dt5);
                }
                if (!string.IsNullOrEmpty(txtSearchNote.Text))
                {
                    ClassDistrict a6 = new ClassDistrict();
                    DataTable dt6 = a6.GetDistrict("", "", "", "", "", txtSearchNote.Text);
                    GridView1.DataSource = dt6;
                    GridView1.DataBind();
                    SetViewState(dt6);
                }
            }
        }