public static bool ReSetRegionData() { string a = ""; string connectionString = ConfigurationManager.ConnectionStrings["HidistroSqlServer"].ConnectionString; string path = Globals.GetphysicsPath("/Installer/SqlScripts/InitRegionData.sql"); StreamReader streamReader = null; SqlConnection sqlConnection = null; using (streamReader = new StreamReader(path)) { using (sqlConnection = new SqlConnection(connectionString)) { DbCommand dbCommand = new SqlCommand { Connection = sqlConnection, CommandType = CommandType.Text, CommandTimeout = 500 }; sqlConnection.Open(); while (!streamReader.EndOfStream) { try { string text = RegionHelper.NextSqlFromStream(streamReader); if (!string.IsNullOrEmpty(text)) { dbCommand.CommandText = text; dbCommand.ExecuteNonQuery(); HiCache.Remove("FileCache-Regions"); } } catch (Exception ex) { Globals.WriteExceptionLog(ex, null, "ReSetRegionData"); a = ex.Message; } } sqlConnection.Close(); } streamReader.Close(); } if (sqlConnection != null && sqlConnection.State != 0) { sqlConnection.Close(); sqlConnection.Dispose(); } if (streamReader != null) { streamReader.Close(); streamReader.Dispose(); } if (a != "") { return(false); } return(true); }
public static bool AddRegion(Hidistro.Entities.Store.RegionInfo regionInfo) { int num = regionInfo.RegionId = new RegionDao().GetNewRegionId(); bool flag = new RegionDao().Add(regionInfo, null) > 0; if (flag) { string fullPath = RegionHelper.GetFullPath(num, true); new RegionDao().UpdateFullRegionPath(num, fullPath); HiCache.Remove("FileCache-Regions"); } return(flag); }
public static IList <Hidistro.Entities.Store.RegionInfo> GetAllProvinceLists(bool containDel = true) { IList <Hidistro.Entities.Store.RegionInfo> allRegions = RegionHelper.GetAllRegions(); if (containDel) { return((from r in allRegions where r.Depth == 1 select r).ToList()); } return((from r in allRegions where r.Depth == 1 && !r.IsDel select r).ToList()); }
public static int GetRegionId(string county, string city, string province) { try { Hidistro.Entities.Store.RegionInfo regionInfo = RegionHelper.FindNodeByRegionName(province.Replace("市", ""), 1); if (regionInfo == null) { regionInfo = RegionHelper.FindNodeByRegionName(province + "省", 1); } if (regionInfo != null) { int regionId = regionInfo.RegionId; if (string.IsNullOrEmpty(city)) { return(regionId); } IList <Hidistro.Entities.Store.RegionInfo> regionChildList = RegionHelper.GetRegionChildList(regionId, true); regionInfo = RegionHelper.FindNodeByRegionName(regionChildList, city); if (regionInfo == null) { regionInfo = RegionHelper.FindNodeByRegionName(regionChildList, city + "市"); } if (regionInfo != null) { if (string.IsNullOrEmpty(county)) { return(regionId); } regionId = regionInfo.RegionId; IList <Hidistro.Entities.Store.RegionInfo> regionChildList2 = RegionHelper.GetRegionChildList(regionId, true); regionInfo = RegionHelper.FindNodeByRegionName(regionChildList2, county); if (regionInfo != null) { regionId = regionInfo.RegionId; } } return(regionId); } } catch (Exception ex) { IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("Province", province.ToNullString()); dictionary.Add("city", city.ToNullString()); dictionary.Add("county", county.ToNullString()); Globals.WriteExceptionLog(ex, dictionary, "GetRegionId"); } return(0); }
public static Dictionary <int, string> GetRegions() { Dictionary <int, string> dictionary = new Dictionary <int, string>(); IList <Hidistro.Entities.Store.RegionInfo> allRegions = RegionHelper.GetAllRegions(); IList <Hidistro.Entities.Store.RegionInfo> list = (from r in allRegions where r.Depth == 0 select r).ToList(); foreach (Hidistro.Entities.Store.RegionInfo item in list) { int regionId = item.RegionId; dictionary.Add(item.RegionId, item.RegionName); } return(dictionary); }
public static int GetCountyId(int currentRegionId) { int result = 0; Hidistro.Entities.Store.RegionInfo region = RegionHelper.GetRegion(currentRegionId, true); if (region != null) { if (region.Depth == 4) { result = region.ParentRegionId; } if (region.Depth == 3) { result = currentRegionId; } } return(result); }
public static IDictionary <int, string> GetAllProvinces(bool containDel = true) { IDictionary <int, string> dictionary = new Dictionary <int, string>(); IList <Hidistro.Entities.Store.RegionInfo> allRegions = RegionHelper.GetAllRegions(); IList <Hidistro.Entities.Store.RegionInfo> list = (!containDel) ? (from r in allRegions where r.Depth == 1 && !r.IsDel select r).ToList() : (from r in allRegions where r.Depth == 1 select r).ToList(); foreach (Hidistro.Entities.Store.RegionInfo item in list) { int regionId = item.RegionId; if (!dictionary.ContainsKey(item.RegionId)) { dictionary.Add(item.RegionId, item.RegionName); } } return(dictionary); }
private static Dictionary <int, string> GetChildList(int parentRegionId, bool containDel = true) { Dictionary <int, string> dictionary = new Dictionary <int, string>(); IList <Hidistro.Entities.Store.RegionInfo> allRegions = RegionHelper.GetAllRegions(); IList <Hidistro.Entities.Store.RegionInfo> list = (!containDel) ? (from a in allRegions where a.ParentRegionId == parentRegionId && !a.IsDel select a).ToList() : (from a in allRegions where a.ParentRegionId == parentRegionId select a).ToList(); if (list == null) { return(dictionary); } foreach (Hidistro.Entities.Store.RegionInfo item in list) { if (item.RegionId > 0 && !dictionary.ContainsKey(item.RegionId)) { dictionary.Add(item.RegionId, item.RegionName); } } return(dictionary); }
public static Hidistro.Entities.Store.RegionInfo GetRegion(int regionId, bool containDel = true) { IList <Hidistro.Entities.Store.RegionInfo> allRegions = RegionHelper.GetAllRegions(); Hidistro.Entities.Store.RegionInfo regionInfo = null; try { regionInfo = ((!containDel) ? (from r in allRegions where r.RegionId == regionId && !r.IsDel select r).First() : (from r in allRegions where r.RegionId == regionId select r).First()); } catch { } if (regionInfo == null) { regionInfo = new RegionDao().Get <Hidistro.Entities.Store.RegionInfo>(regionId); if (regionInfo != null && regionInfo.Depth == 4) { Hidistro.Entities.Store.RegionInfo region = RegionHelper.GetRegion(regionInfo.ParentRegionId, true); if (region != null) { IList <Hidistro.Entities.Store.RegionInfo> streetsOfCity = new RegionDao().GetStreetsOfCity(region.ParentRegionId, containDel); if (streetsOfCity != null && streetsOfCity.Count > 0) { IList <Hidistro.Entities.Store.RegionInfo> allRegions2 = RegionHelper.GetAllRegions(); allRegions2 = allRegions2.Concat(streetsOfCity).ToList(); HiCache.Remove("FileCache-Regions"); HiCache.Insert("FileCache-Regions", allRegions2); } } } } return(regionInfo); }
public static string GetFullRegion(int currentRegionId, string separator, bool isEndOnProvince = true, int endDpeth = 0) { Hidistro.Entities.Store.RegionInfo region = RegionHelper.GetRegion(currentRegionId, true); if (region == null) { return(string.Empty); } if (isEndOnProvince) { endDpeth = 1; } string text = region.RegionName; if (region.Depth > endDpeth) { Hidistro.Entities.Store.RegionInfo region2 = RegionHelper.GetRegion(region.ParentRegionId, true); while (region2 != null && region2.Depth >= endDpeth) { text = region2.RegionName + separator + text; region2 = RegionHelper.GetRegion(region2.ParentRegionId, true); } } return(text); }
public static Dictionary <int, string> GetCountys(int cityId, bool containDel = true) { return(RegionHelper.GetChildList(cityId, containDel)); }
public static Dictionary <int, string> GetCitys(int provinceId, bool containDel = true) { return(RegionHelper.GetChildList(provinceId, containDel)); }