/// <summary> /// 选择市 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cb_city_SelectedIndexChanged(object sender, EventArgs e) { Hat_cityModel city = (Hat_cityModel)cb_city.SelectedItem; cb_area.DataSource = GeneralHelper.GetAreasByCity(city); cb_area.DisplayMember = "area"; }
public static Hat_provinceModel GetFatherProvince(Hat_cityModel city) { int id = (int)SqlHelper.ExecuteScalar("select id from hat_province where provinceID = @provinceId", new SqlParameter("@provinceID", city.Father)); return(Hat_provinceDAL.GetById(id)); }
/// <summary> /// 通过地区Area获取包括上级市,省的字符串 /// e.g: 双流县的Hat_areaModel -> "四川省_成都市_双流县" /// </summary> /// <param name="area"></param> /// <returns></returns> public static string GetFullLocationString(Hat_areaModel area) { Hat_cityModel fatherCity = Hat_areaDAL.GetFatherCity(area); Hat_provinceModel fatherProvince = Hat_cityDAL.GetFatherProvince(fatherCity); string result = fatherProvince.Province + "_" + fatherCity.City + "_" + area.Area; return(result); }
private static Hat_cityModel ToModel(DataRow row) { Hat_cityModel hat_city = new Hat_cityModel(); hat_city.Id = (System.Int32)row["id"]; hat_city.CityID = (System.String)row["cityID"]; hat_city.City = (System.String)row["city"]; hat_city.Father = (System.String)row["father"]; return(hat_city); }
public static Hat_cityModel[] GetAll() { DataTable table = SqlHelper.ExecuteDataTable(@"select * from hat_city"); Hat_cityModel[] hat_city = new Hat_cityModel[table.Rows.Count]; for (int i = 0; i < table.Rows.Count; i++) { hat_city[i] = ToModel(table.Rows[i]); } return(hat_city); }
private static bool IfExemptCities(Hat_cityModel city) { for (int i = 0; i < _exempt_cities.Length; i++) { if (city.City.Equals(_exempt_cities[i])) { return(true); } } return(false); }
public static Hat_cityModel[] GetAllByProvinceId(int id) { DataTable table = SqlHelper.ExecuteDataTable(@"select * from hat_city where hat_city.father = (select provinceID from hat_province where hat_province.id = @id)", new SqlParameter("@id", id)); Hat_cityModel[] hat_city = new Hat_cityModel[table.Rows.Count]; for (int i = 0; i < table.Rows.Count; i++) { hat_city[i] = ToModel(table.Rows[i]); } return(hat_city); }
/// <summary> /// 通过市找到底下的区县 /// </summary> /// <param name="city"></param> /// <returns></returns> public static Hat_areaModel[] GetAreasByCity(Hat_cityModel city) { LoadLocationData(); List <Hat_areaModel> areaList = new List <Hat_areaModel>(); string cityID = city.CityID; foreach (var area in areas) { if (area.Father.Equals(cityID)) { areaList.Add(area); } } return(areaList.ToArray()); }