Exemple #1
0
        public ActionResult _SchoolSelector(string inputId, string areaCode = null, string keyword = null, SchoolType? schoolType = null)
        {
            ViewData["inputId"] = inputId;

            int pageSize = string.IsNullOrEmpty(areaCode) ? 100 : 1000;

            PagingDataSet<School> schools = schoolService.Gets(areaCode, keyword, schoolType, pageSize, 1);

            AreaService areaService = new AreaService();

            var area = areaService.Get(areaCode);
            if (area != null)
            {
                while (area.Depth >= 3)
                {
                    area = areaService.Get(area.ParentCode);
                }
                areaCode = area.AreaCode;
            }
            ViewData["areaCode"] = areaCode;
            return View(schools);
        }
Exemple #2
0
 /// <summary>
 /// 获取子节点
 /// </summary>
 /// <returns></returns>
 public JsonResult GetChildAreas()
 {
     AreaService areaService = new AreaService();
     string parentAreaCode = string.Empty;
     if (Request.QueryString["Id"] != null)
         parentAreaCode = Request.QueryString["Id"].ToString();
     Area area = areaService.Get(parentAreaCode);
     if (area == null)
         return Json(new { }, JsonRequestBehavior.AllowGet);
     return Json(area.Children.Select(n => new { id = n.AreaCode, name = n.Name }), JsonRequestBehavior.AllowGet);
 }
Exemple #3
0
        /// <summary>
        /// 获取所查询地区的编码
        /// </summary>
        /// <param name="ip">要查找的IP地址</param>
        /// <returns>地区编码</returns>
        public string GetAreaCode(string ip)
        {
            string ipAddress = GetAddress(ip);
            if (string.IsNullOrEmpty(ipAddress))
                return string.Empty;
            string ipCountry = ipAddress.Substring(0, ipAddress.LastIndexOf(' '));
            AreaService areaService = new AreaService();

            if (string.IsNullOrEmpty(ipCountry))
                return string.Empty;

            //在中国的省(直辖市)地区查找
            Area china = areaService.Get("A1560000");
            if (china == null)
                return string.Empty;

            foreach (var area in china.Children)
            {
                if (ipCountry.Contains(area.Name.Substring(0, 2)))
                {
                    foreach (var city in area.Children)
                    {
                        if (ipCountry.Contains(city.Name))
                        {
                            foreach (var district in city.Children)
                            {
                                if (ipCountry.Contains(city.Name))
                                {
                                    return city.AreaCode;
                                }
                            }
                            return city.AreaCode;
                        }
                    }
                    return area.AreaCode;
                }
            }

            //先从国家地区中查找
            IEnumerable<Area> areas = areaService.GetRoots();
            foreach (var area in areas)
            {
                if (ipCountry.Contains(area.Name))
                    return area.AreaCode;
            }
            return string.Empty;
        }