/// <summary> /// Locations the info. /// </summary> /// <param name="ipAddress">The ip.</param> /// <returns></returns> public LocationInfoDto GetLocationInfo(string ipAddress) { if (ipAddress.CompareTo("::1") == 0 || ipAddress.CompareTo("127.0.0.1") == 0) { return GetLocationInfo(); } else { string sinaResult; using (var w = new WebClient()) { sinaResult = w.DownloadString("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=xml&ip=" + ipAddress); } ArrayList sinaInfo = new ArrayList(sinaResult.Split('\t')); if (sinaInfo.Count > 1) { if (Convert.ToInt16(sinaInfo[0]) < 1) { return GetLocationInfo(); } else { if (sinaInfo.Count > 7) { LocationInfoDto location = new LocationInfoDto(); location.startIP = sinaInfo[1].ToString(); location.endIP = sinaInfo[2].ToString(); location.Country = sinaInfo[3].ToString(); location.Province = sinaInfo[4].ToString(); location.City = sinaInfo[5].ToString(); location.ISP = sinaInfo[7].ToString(); return location; } else { return GetLocationInfo(); } } } else { return GetLocationInfo(); //return LocationInfo(ip); } } }
/// <summary> /// Locations the info. /// </summary> /// <returns></returns> public LocationInfoDto GetLocationInfo() { string sinaResult; using (var w = new WebClient()) { sinaResult = w.DownloadString("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=xml"); } ArrayList sinaInfo = new ArrayList(sinaResult.Split('\t')); if (sinaInfo != null && sinaInfo.Count > 7) { LocationInfoDto location = new LocationInfoDto(); location.startIP = sinaInfo[1].ToString(); location.endIP = sinaInfo[2].ToString(); location.Country = sinaInfo[3].ToString(); location.Province = sinaInfo[4].ToString(); location.City = sinaInfo[5].ToString(); location.ISP = sinaInfo[7].ToString(); return location; } else { return GetLocationInfo(); } }
/// <summary> /// Gets the city info by sina. /// 从新浪IP得到,我们数据库里面的一个城市信息 /// </summary> /// <param name="li">The li.</param> /// <returns></returns> public iPow.Domain.Dto.Sys_CityInfoDto GetCityInfoBySina(LocationInfoDto li) { //edit by yjihrp 2011.8.16.13.2 //modify:li.city == null ?"shenzhen":li.city var ci = cityInfoRepository.GetList(). Where(e => e.city == (string.IsNullOrEmpty(li.City) ? "shenzhen" : li.City) && e.province == li.Province) .FirstOrDefault(); return ci.ToDto(); }
/// <summary> /// Inits the city info. /// 根据名字中文名字找到当前传入省的所有城市 /// 如果省为空则按市选 /// 如果市为空则按省选 /// 两个为空则按当前IP地址选 /// edit by yjihrp 2011.8.2.17.18 /// </summary> /// <param name="province">The province.</param> /// <param name="city">The city.</param> public List<iPow.Domain.Dto.Sys_CityInfoDto> GetCityInfoByName(LocationInfoDto li, string province, string city) { IQueryable<iPow.Infrastructure.Data.DataSys.Sys_CityInfo> ci = null; //根据IP中的城市选出这个省的 其他城市哈在数据库中选哦 if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city)) { ci = (from d in cityInfoRepository.GetList() where d.province == li.Province && d.city != li.City select d).AsQueryable(); } //根据市选 else if (string.IsNullOrEmpty(province) && !string.IsNullOrEmpty(city)) { List<iPow.Infrastructure.Data.DataSys.Sys_CityInfo> c = (from e in cityInfoRepository.GetList() where e.city == city select e).Distinct().ToList(); if (c != null) { if (c.Count > 0) { ci = (from d in cityInfoRepository.GetList() where d.city == c[0].city && c[0].province == d.province select d).AsQueryable(); } } else { ci = (from d in cityInfoRepository.GetList() where d.city == city select d).AsQueryable(); } } //根据省选 else if (!string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city)) { ci = (from d in cityInfoRepository.GetList() where d.province == province select d).AsQueryable(); } //根据省市选 else { ci = (from d in cityInfoRepository.GetList() where d.province == province && d.city != city select d).AsQueryable(); } return ci.ToDto().ToList(); }