Example #1
0
        /// <summary>
        /// 根据城市名称取得IdList字符串(|1|10|100|)
        /// </summary>
        /// <param name="cityName"></param>
        /// <returns></returns>
        public static string ReadRegionIdList(string province, string cityName, string townname)
        {
            //取得所有的市
            List <RegionInfo> regionCityList = new List <RegionInfo>();
            List <RegionInfo> regionList     = ReadRegionCacheList();
            var regionProvinceList           = regionList.Where(k => (k.FatherID == 1 && k.RegionName.Contains(province))).ToList();

            foreach (RegionInfo region in regionProvinceList)
            {
                regionCityList.AddRange(regionList.Where(k => k.FatherID == region.ID).ToList());
            }

            //取得符合城市名称的市
            var regionCity = regionCityList.FirstOrDefault(k => k.RegionName.Contains(cityName)) ?? new RegionInfo();

            if (regionCity.ID > 0)
            {
                RegionInfo regionTown = RegionBLL.ReadRegionChildList(regionCity.ID).FirstOrDefault(k => k.RegionName == townname);
                if (regionTown == null)
                {
                    regionTown            = new RegionInfo();
                    regionTown.RegionName = townname;
                    regionTown.FatherID   = regionCity.ID;
                    RegionBLL.AddRegion(regionTown);
                    CacheHelper.Remove(cacheKey);
                }
                return(string.Format("|1|{0}|{1}|{2}|", regionCity.FatherID, regionCity.ID, regionTown.ID));
            }
            else
            {
                var newregion = new RegionInfo();
                newregion.RegionName = cityName;
                newregion.FatherID   = regionProvinceList[0].ID;
                int newcityid = RegionBLL.AddRegion(newregion);
                newregion            = new RegionInfo();
                newregion.RegionName = townname;
                newregion.FatherID   = newcityid;
                int newtownid = RegionBLL.AddRegion(newregion);
                CacheHelper.Remove(cacheKey);
                return("|1|" + regionProvinceList[0].ID + "|" + newcityid + "|" + newtownid + "|");
            }
        }
Example #2
0
        /// <summary>
        /// 读取地区的湖南级分类
        /// </summary>
        /// <returns></returns>
        public static List <UnlimitClassInfo> ReadRegionUnlimitClassHN()
        {
            List <RegionInfo> regionList = new List <RegionInfo>();

            List <UnlimitClassInfo> unlimitClassList = new List <UnlimitClassInfo>();
            UnlimitClassInfo        unlimitClass     = new UnlimitClassInfo();

            unlimitClass.ClassID   = 27;
            unlimitClass.ClassName = RegionBLL.ReadRegionCache(27).RegionName;
            unlimitClass.FatherID  = RegionBLL.ReadRegionCache(27).FatherID;
            unlimitClassList.Add(unlimitClass);
            regionList = RegionBLL.ReadRegionChildList(27);

            foreach (RegionInfo region in regionList)
            {
                unlimitClass           = new UnlimitClassInfo();
                unlimitClass.ClassID   = region.ID;
                unlimitClass.ClassName = region.RegionName;
                unlimitClass.FatherID  = region.FatherID;
                unlimitClassList.Add(unlimitClass);
            }

            return(unlimitClassList);
        }