コード例 #1
0
ファイル: RegionFormat.cs プロジェクト: xuanbg/AddressFormat
        /// <summary>
        /// 在省级区划范围内尝试通过县级区划反向查询市级区划
        /// </summary>
        private void FindCityReverse()
        {
            var list = (from r in _Citys
                        join c in Countys on r.ID equals c.ParentId
                        let alias = c.Alias.Split(',').FirstOrDefault(_Address.Contains)
                                    let key = alias ?? c.Name
                                              let index = GetIndex(key)
                                                          where index >= 0
                                                          orderby index
                                                          select new { region = c, index, key }).ToList();

            if (!list.Any())
            {
                if (!"北京,天津,上海,重庆".Contains(_Province.Alias))
                {
                    return;
                }

                _City = Citys.Single(c => c.ParentId == _Province.ID && c.Name == "市辖区");
                return;
            }

            var county = list.First();

            _County = county.region;
            _City   = Citys.Single(c => c.ID == _County.ParentId);
            _Towns  = Towns.Where(t => t.ParentId == _County.ID).ToList();

            SetIndex(county.index, _County.Name, county.key);
            FindTown();
        }
コード例 #2
0
ファイル: RegionFormat.cs プロジェクト: xuanbg/AddressFormat
        /// <summary>
        /// 通过县级行政区划反查省市
        /// </summary>
        /// <returns>Address 结构化地址数据</returns>
        private void ReverseFromCounty()
        {
            var list = (from c in Countys
                        let alias = c.Alias.Split(',').FirstOrDefault(_Address.Contains)
                                    let key = alias ?? c.Name
                                              let index = GetIndex(key)
                                                          where index >= 0
                                                          orderby index
                                                          select new { region = c, index, key }).ToList();

            if (!list.Any())
            {
                return;
            }

            var county = list.First();

            _County   = county.region;
            _City     = Citys.Single(c => c.ID == _County.ParentId);
            _Province = Provinces.Single(p => p.ID == _City.ParentId);

            SetIndex(county.index, _County.Name, county.key);
            FindTown();
        }