// ดึงข้อมูลจังหวัดในประเทศไทย private void _loadThaiProvinces() { List <TH_Provinces> list_data = new TH_Provinces_Manager().getProvinces(); Current_Cust_Province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); Cust_job_province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); Home_Cust_Province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); Idcard_Cust_Province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); Marry_province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); Marry_job_province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); for (int i = 0; i < list_data.Count; i++) { TH_Provinces data = list_data[i]; Current_Cust_Province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); Cust_job_province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); Home_Cust_Province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); Idcard_Cust_Province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); Marry_province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); Marry_job_province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); } Current_Cust_Province_DDL.SelectedValue = "39"; Cust_job_province_DDL.SelectedValue = "39"; Home_Cust_Province_DDL.SelectedValue = "39"; Idcard_Cust_Province_DDL.SelectedValue = "39"; Marry_province_DDL.SelectedValue = "39"; Marry_job_province_DDL.SelectedValue = "39"; }
/******************************************************************************************************************************************************************************* **************************************************** Load Default Data to Form ******************************************************** **************************************************** ******************************************************** *******************************************************************************************************************************************************************************/ // ดึงข้อมูลจังหวัดในประเทศไทย private void _loadThaiProvinces() { List <TH_Provinces> list_data = new TH_Provinces_Manager().getProvinces(); Agent_province_DDL.Items.Add(new ListItem("--------กรุณาเลือก--------", "0")); for (int i = 0; i < list_data.Count; i++) { TH_Provinces data = list_data[i]; Agent_province_DDL.Items.Add(new ListItem(data.Province_name, data.Province_id.ToString())); } Agent_province_DDL.SelectedValue = "39"; }
public List <TH_Provinces> getProvinces() { MySqlConnection con = MySQLConnection.connectionMySQL(); try { con.Open(); string sql = "SELECT * FROM th_provinces ORDER BY Province_name"; MySqlCommand cmd = new MySqlCommand(sql, con); MySqlDataReader reader = cmd.ExecuteReader(); int defaultNum = 0; string defaultString = ""; List <TH_Provinces> list_th_pv = new List <TH_Provinces>(); while (reader.Read()) { TH_Provinces th_pv = new TH_Provinces(); th_pv.Province_id = reader.IsDBNull(0) ? defaultNum : reader.GetInt32(0); th_pv.Province_code = reader.IsDBNull(1) ? defaultString : reader.GetString(1); th_pv.Province_name = reader.IsDBNull(2) ? defaultString : reader.GetString(2); th_pv.Geo_id = reader.IsDBNull(3) ? defaultNum : reader.GetInt32(3); list_th_pv.Add(th_pv); } return(list_th_pv); } catch (MySqlException ex) { error = "MysqlException ==> Managers_Base --> TH_Provinces_Manager --> getProvinces "; Log_Error._writeErrorFile(error, ex); return(null); } catch (Exception ex) { error = "Exception ==> Managers_Base --> TH_Provinces_Manager --> getProvinces "; Log_Error._writeErrorFile(error, ex); return(null); } finally { con.Close(); con.Dispose(); } }
// ดึงข้อมูลจังหวัดในประเทศไทย public static string _getThaiProvinces(string province_name) { string province_id = "0"; List <TH_Provinces> list_data = new TH_Provinces_Manager().getProvinces(); for (int i = 0; i < list_data.Count; i++) { TH_Provinces data = list_data[i]; if (data.Province_name == province_name) { province_id = data.Province_id.ToString(); } } return(province_id); }