public void ResolveCityNameFromMap(ref string inputAddress, ref string province, ref string city) { string address = inputAddress; using (var db = new DistrictServiceContext()) { string p = province; if (!string.IsNullOrEmpty(p)) { try { var pinfo = db.ChinaAreaDatas.FirstOrDefault(c => c.levelType == 1 && (c.Name == p || p.IndexOf(c.ShortName) == 0)); var cinfo = db.ChinaAreaDatas.Where(c => c.levelType == 2 && c.ParentId == pinfo.ID).FirstOrDefault(c => address.IndexOf(c.ShortName) == 0); if (cinfo == null) { Dictionary <string, string> cityMap = DistrictMaps.CityMap; string text = cityMap.Keys.FirstOrDefault((string mapKey) => address.IndexOf(mapKey) == 0); bool flag = text != null; if (flag) { city = cityMap[text]; inputAddress = inputAddress.Replace(text, string.Empty).Trim(); DistrictInfo districtInfo = this.FindByCity(city); bool flag2 = districtInfo != null && string.IsNullOrEmpty(province); if (flag2) { province = districtInfo.Province; } } } else { inputAddress = inputAddress.Replace(cinfo.ShortName, string.Empty).Trim(); city = cinfo.Name; } } catch (Exception ex) { Util.Logs.Log.GetLog(nameof(MemoryDistrictService)).Error($"msg:{ex.Message},stacktrace:{ex.StackTrace},addr:{inputAddress}"); } } } }
public void ResolveProvinceNameFromMap(ref string inputAddress, ref string province, ref string city) { string address = inputAddress; using (var db = new DistrictServiceContext()) { var p = db.ChinaAreaDatas.Where(c => c.levelType == 1).FirstOrDefault(s => address.IndexOf(s.ShortName) == 0); if (p == null) { Dictionary <string, string> provinceMap = DistrictMaps.ProvinceMap; string text = provinceMap.Keys.FirstOrDefault((string mapKey) => address.IndexOf(mapKey) == 0); bool flag = text != null; if (flag) { province = provinceMap[text]; bool flag2 = province.EndsWith("市"); if (flag2) { city = province; } inputAddress = inputAddress.Replace(text, string.Empty).Trim(); } } else { province = p.Name; bool flag2 = province.EndsWith("市"); if (flag2) { city = province; } inputAddress = inputAddress.Replace(p.ShortName, string.Empty).Trim(); } } }
public void ResolveCountyNameFromMap(ref string inputAddress, ref string province, ref string city, ref string county) { string address = inputAddress; using (var db = new DistrictServiceContext()) { try { string sourcecity = city; if (!string.IsNullOrEmpty(sourcecity)) { var cityinfo = db.ChinaAreaDatas.FirstOrDefault(c => c.levelType == 2 && c.Name == sourcecity); OMS.Models.ChinaAreaData countyinfo = null; if (cityinfo != null) { countyinfo = db.ChinaAreaDatas.Where(c => c.levelType == 3 && c.ParentId == cityinfo.ID).FirstOrDefault(c => address.Contains(c.ShortName) == true); } else //适用于地级市降级为区,县 { Dictionary <string, string> cityMap = DistrictMaps.CityMap; string text = cityMap.Keys.FirstOrDefault((string mapKey) => sourcecity.IndexOf(mapKey) == 0); bool flag = text != null; if (flag) { city = cityMap[text]; ResolveCountyNameFromMap(ref inputAddress, ref province, ref city, ref county); return; } } if (countyinfo == null) { DistrictInfo districtInfo = null; Dictionary <string, string> countyMap = DistrictMaps.CountyMap; string text = countyMap.Keys.FirstOrDefault((string mapKey) => address.IndexOf(mapKey) == 0); bool flag = text != null; if (flag) { county = countyMap[text]; inputAddress = inputAddress.Replace(text, string.Empty).Trim(); bool flag2 = string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city); if (flag2) { districtInfo = this.FindByCounty(county); } else { bool flag3 = !string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city); if (flag3) { districtInfo = this.FindByProvinceAndCounty(province, county); } else { bool flag4 = !string.IsNullOrEmpty(city) && string.IsNullOrEmpty(province); if (flag4) { districtInfo = this.FindByCityAndCounty(city, county); } else { bool flag5 = !string.IsNullOrEmpty(province) && !string.IsNullOrEmpty(city); if (flag5) { districtInfo = this.FindByProvinceAndCityAndCounty(province, city, county); } } } } bool flag6 = districtInfo != null && string.IsNullOrEmpty(city); if (flag6) { city = districtInfo.City; } bool flag7 = districtInfo != null && string.IsNullOrEmpty(province); if (flag7) { province = districtInfo.Province; } } } else { inputAddress = inputAddress.Replace(countyinfo.ShortName, string.Empty).Trim(); county = countyinfo.Name; } } else { DistrictInfo districtInfo = null; Dictionary <string, string> countyMap = DistrictMaps.CountyMap; string text = countyMap.Keys.FirstOrDefault((string mapKey) => address.IndexOf(mapKey) == 0); bool flag = text != null; if (flag) { county = countyMap[text]; inputAddress = inputAddress.Replace(text, string.Empty).Trim(); bool flag2 = string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city); if (flag2) { districtInfo = this.FindByCounty(county); } else { bool flag3 = !string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city); if (flag3) { districtInfo = this.FindByProvinceAndCounty(province, county); } else { bool flag4 = !string.IsNullOrEmpty(city) && string.IsNullOrEmpty(province); if (flag4) { districtInfo = this.FindByCityAndCounty(city, county); } else { bool flag5 = !string.IsNullOrEmpty(province) && !string.IsNullOrEmpty(city); if (flag5) { districtInfo = this.FindByProvinceAndCityAndCounty(province, city, county); } } } } bool flag6 = districtInfo != null && string.IsNullOrEmpty(city); if (flag6) { city = districtInfo.City; } bool flag7 = districtInfo != null && string.IsNullOrEmpty(province); if (flag7) { province = districtInfo.Province; } } } } catch (Exception ex) { Util.Logs.Log.GetLog(nameof(MemoryDistrictService)).Error($"msg:{ex.Message},stacktrace:{ex.StackTrace},addr:{inputAddress}"); } } }