Exemplo n.º 1
0
        public IEnumerable <KeyValuePair <long, string> > GetRegion(long parentId)
        {
            IEnumerable <KeyValuePair <long, string> > county;
            IEnumerable <ProvinceMode> regions = GetRegions();

            if (parentId <= 0)
            {
                return
                    (from item in regions
                     select new KeyValuePair <long, string>(item.Id, item.Name));
            }
            ProvinceMode provinceMode = (
                from item in regions
                where item.Id == parentId
                select item).FirstOrDefault();

            if (provinceMode != null)
            {
                return
                    (from item in provinceMode.City
                     select new KeyValuePair <long, string>(item.Id, item.Name));
            }
            List <ProvinceMode> .Enumerator enumerator = regions.ToList().GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ProvinceMode current  = enumerator.Current;
                    CityMode     cityMode = (
                        from item in current.City
                        where item.Id == parentId
                        select item).FirstOrDefault();
                    if (cityMode == null || cityMode.County == null || cityMode.County.Count() <= 0)
                    {
                        continue;
                    }
                    county =
                        from item in cityMode.County
                        select new KeyValuePair <long, string>(item.Id, item.Name);
                    return(county);
                }
                return(null);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(county);
        }
Exemplo n.º 2
0
        public IEnumerable <KeyValuePair <long, string> > GetRegion(long parentId)
        {
            IEnumerable <KeyValuePair <long, string> > county;
            IEnumerable <ProvinceMode> regions = this.GetRegions();

            if (parentId > (long)0)
            {
                ProvinceMode provinceMode = (
                    from item in regions
                    where item.Id == parentId
                    select item).FirstOrDefault <ProvinceMode>();
                if (provinceMode == null)
                {
                    foreach (ProvinceMode list in regions.ToList <ProvinceMode>())
                    {
                        CityMode cityMode = (
                            from item in list.City
                            where item.Id == parentId
                            select item).FirstOrDefault <CityMode>();
                        if ((cityMode == null || cityMode.County == null ? false : cityMode.County.Count <CountyMode>() > 0))
                        {
                            county =
                                from item in cityMode.County
                                select new KeyValuePair <long, string>(item.Id, item.Name);
                            return(county);
                        }
                    }
                    county = null;
                }
                else
                {
                    county =
                        from item in provinceMode.City
                        select new KeyValuePair <long, string>(item.Id, item.Name);
                }
            }
            else
            {
                county =
                    from item in regions
                    select new KeyValuePair <long, string>(item.Id, item.Name);
            }
            return(county);
        }
Exemplo n.º 3
0
        public long GetCityIdByName(string CityName, long RegionId, bool NullGetFirst = false)
        {
            long id = 0;
            IEnumerable <ProvinceMode> regions = GetRegions();
            ProvinceMode provinceMode          = regions.FirstOrDefault((ProvinceMode d) => d.Id == RegionId);

            if (provinceMode != null)
            {
                CityMode cityMode = provinceMode.City.FirstOrDefault((CityMode d) => d.Name.Contains(CityName));
                if (cityMode == null && NullGetFirst)
                {
                    cityMode = provinceMode.City.FirstOrDefault();
                }
                if (cityMode != null)
                {
                    id = cityMode.Id;
                }
            }
            return(id);
        }
Exemplo n.º 4
0
        private string GetRegionName(long regionId)
        {
            string name;

            List <ProvinceMode> .Enumerator enumerator = GetRegions().ToList().GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ProvinceMode current = enumerator.Current;
                    if (current.Id != regionId)
                    {
                        List <CityMode> .Enumerator enumerator1 = current.City.ToList().GetEnumerator();
                        try
                        {
                            while (enumerator1.MoveNext())
                            {
                                CityMode cityMode = enumerator1.Current;
                                if (cityMode.Id != regionId)
                                {
                                    if (cityMode.County == null)
                                    {
                                        continue;
                                    }
                                    List <CountyMode> .Enumerator enumerator2 = cityMode.County.ToList().GetEnumerator();
                                    try
                                    {
                                        while (enumerator2.MoveNext())
                                        {
                                            CountyMode countyMode = enumerator2.Current;
                                            if (countyMode.Id != regionId)
                                            {
                                                continue;
                                            }
                                            name = countyMode.Name;
                                            return(name);
                                        }
                                    }
                                    finally
                                    {
                                        ((IDisposable)enumerator2).Dispose();
                                    }
                                }
                                else
                                {
                                    name = cityMode.Name;
                                    return(name);
                                }
                            }
                        }
                        finally
                        {
                            ((IDisposable)enumerator1).Dispose();
                        }
                    }
                    else
                    {
                        name = current.Name;
                        return(name);
                    }
                }
                return(string.Empty);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(name);
        }
Exemplo n.º 5
0
        public string GetRegionIdPath(long regionId)
        {
            string str;

            List <ProvinceMode> .Enumerator enumerator = GetRegions().ToList().GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ProvinceMode current = enumerator.Current;
                    if (current.Id != regionId)
                    {
                        List <CityMode> .Enumerator enumerator1 = current.City.ToList().GetEnumerator();
                        try
                        {
                            while (enumerator1.MoveNext())
                            {
                                CityMode cityMode = enumerator1.Current;
                                if (cityMode.Id != regionId)
                                {
                                    if (cityMode.County == null)
                                    {
                                        continue;
                                    }
                                    List <CountyMode> .Enumerator enumerator2 = cityMode.County.ToList().GetEnumerator();
                                    try
                                    {
                                        while (enumerator2.MoveNext())
                                        {
                                            CountyMode countyMode = enumerator2.Current;
                                            if (countyMode.Id != regionId)
                                            {
                                                continue;
                                            }
                                            string[] strArrays = new string[] { current.Id.ToString(), ",", cityMode.Id.ToString(), ",", countyMode.Id.ToString() };
                                            str = string.Concat(strArrays);
                                            return(str);
                                        }
                                    }
                                    finally
                                    {
                                        ((IDisposable)enumerator2).Dispose();
                                    }
                                }
                                else
                                {
                                    string str1 = current.Id.ToString();
                                    long   id   = cityMode.Id;
                                    str = string.Concat(str1, ",", id.ToString());
                                    return(str);
                                }
                            }
                        }
                        finally
                        {
                            ((IDisposable)enumerator1).Dispose();
                        }
                    }
                    else
                    {
                        str = current.Id.ToString();
                        return(str);
                    }
                }
                return(string.Empty);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(str);
        }
Exemplo n.º 6
0
        public string GetRegionFullName(long regionId, string seperator = " ")
        {
            string name;

            List <ProvinceMode> .Enumerator enumerator = GetRegions().ToList().GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ProvinceMode current = enumerator.Current;
                    if (current.Id != regionId)
                    {
                        List <CityMode> .Enumerator enumerator1 = current.City.ToList().GetEnumerator();
                        try
                        {
                            while (enumerator1.MoveNext())
                            {
                                CityMode cityMode = enumerator1.Current;
                                if (cityMode.Id != regionId)
                                {
                                    if (cityMode.County == null)
                                    {
                                        continue;
                                    }
                                    List <CountyMode> .Enumerator enumerator2 = cityMode.County.ToList().GetEnumerator();
                                    try
                                    {
                                        while (enumerator2.MoveNext())
                                        {
                                            CountyMode countyMode = enumerator2.Current;
                                            if (countyMode.Id != regionId)
                                            {
                                                continue;
                                            }
                                            string[] strArrays = new string[] { current.Name, seperator, cityMode.Name, seperator, countyMode.Name };
                                            name = string.Concat(strArrays);
                                            return(name);
                                        }
                                    }
                                    finally
                                    {
                                        ((IDisposable)enumerator2).Dispose();
                                    }
                                }
                                else
                                {
                                    name = string.Concat(current.Name, seperator, cityMode.Name);
                                    return(name);
                                }
                            }
                        }
                        finally
                        {
                            ((IDisposable)enumerator1).Dispose();
                        }
                    }
                    else
                    {
                        name = current.Name;
                        return(name);
                    }
                }
                return(string.Empty);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(name);
        }