コード例 #1
0
        public static int GetRegionId(string county, string city, string province)
        {
            string      xpath          = string.Format("//province[@name='{0}']", province);
            XmlDocument regionDocument = RegionHelper.GetRegionDocument();
            XmlNode     xmlNode        = regionDocument.SelectSingleNode(xpath);
            int         result;

            if (xmlNode != null)
            {
                int num = int.Parse(xmlNode.Attributes["id"].Value);
                xpath   = string.Format("//province[@id='{0}']/city[@name='{1}']", num, city);
                xmlNode = xmlNode.SelectSingleNode(xpath);
                if (xmlNode != null)
                {
                    num     = int.Parse(xmlNode.Attributes["id"].Value);
                    xpath   = string.Format("//city[@id='{0}']/county[@name='{1}']", num, county);
                    xmlNode = xmlNode.SelectSingleNode(xpath);
                    if (xmlNode != null)
                    {
                        num = int.Parse(xmlNode.Attributes["id"].Value);
                    }
                }
                result = num;
            }
            else
            {
                result = 0;
            }
            return(result);
        }
コード例 #2
0
        public static int GetProvinceId(string ProvinceName)
        {
            string      xpath          = string.Format("//province[@name='{0}']", ProvinceName);
            XmlDocument regionDocument = RegionHelper.GetRegionDocument();
            XmlNode     xmlNode        = regionDocument.SelectSingleNode(xpath);

            if (xmlNode != null && xmlNode.Attributes["id"] != null)
            {
                return(int.Parse(xmlNode.Attributes["id"].Value));
            }
            return(0);
        }
コード例 #3
0
        public static System.Collections.Generic.Dictionary <int, string> GetAllProvinces()
        {
            System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>();
            XmlDocument regionDocument = RegionHelper.GetRegionDocument();
            XmlNodeList xmlNodeList    = regionDocument.SelectNodes("//province");

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                dictionary.Add(int.Parse(xmlNode.Attributes["id"].Value), xmlNode.Attributes["name"].Value);
            }
            return(dictionary);
        }
コード例 #4
0
        private static System.Collections.Generic.Dictionary <int, string> GetChildList(string xpath)
        {
            System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>();
            XmlDocument regionDocument = RegionHelper.GetRegionDocument();
            XmlNode     xmlNode        = regionDocument.SelectSingleNode(xpath);

            if (xmlNode != null)
            {
                foreach (XmlNode xmlNode2 in xmlNode.ChildNodes)
                {
                    dictionary.Add(int.Parse(xmlNode2.Attributes["id"].Value), xmlNode2.Attributes["name"].Value);
                }
            }
            return(dictionary);
        }
コード例 #5
0
        public static string GetRegionByCity(int currentRegionId)
        {
            XmlNode xmlNode = RegionHelper.FindNode(currentRegionId);
            string  result;

            if (xmlNode == null)
            {
                result = string.Empty;
            }
            else
            {
                string  text       = xmlNode.Attributes["id"].Value;
                XmlNode parentNode = xmlNode.ParentNode;
                while (parentNode.Name != "region")
                {
                    text = parentNode.Attributes["id"].Value + "," + text;
                }
                result = text;
            }
            return(result);
        }
コード例 #6
0
        public static int GetTopRegionId(int currentRegionId)
        {
            XmlNode xmlNode = RegionHelper.FindNode(currentRegionId);
            int     result;

            if (xmlNode == null)
            {
                result = 0;
            }
            else
            {
                int     num        = currentRegionId;
                XmlNode parentNode = xmlNode.ParentNode;
                while (parentNode.Name != "region")
                {
                    num        = int.Parse(parentNode.Attributes["id"].Value);
                    parentNode = parentNode.ParentNode;
                }
                result = num;
            }
            return(result);
        }
コード例 #7
0
        public static string GetFullRegion(int currentRegionId, string separator)
        {
            XmlNode xmlNode = RegionHelper.FindNode(currentRegionId);
            string  result;

            if (xmlNode == null)
            {
                result = string.Empty;
            }
            else
            {
                string  text       = xmlNode.Attributes["name"].Value;
                XmlNode parentNode = xmlNode.ParentNode;
                while (parentNode.Name != "region")
                {
                    text       = parentNode.Attributes["name"].Value + separator + text;
                    parentNode = parentNode.ParentNode;
                }
                result = text;
            }
            return(result);
        }
コード例 #8
0
        private static XmlNode FindNode(int id)
        {
            string      arg            = id.ToString(System.Globalization.CultureInfo.InvariantCulture);
            string      xpath          = string.Format("//county[@id='{0}']", arg);
            XmlDocument regionDocument = RegionHelper.GetRegionDocument();
            XmlNode     xmlNode        = regionDocument.SelectSingleNode(xpath);
            XmlNode     result;

            if (xmlNode != null)
            {
                result = xmlNode;
            }
            else
            {
                xpath   = string.Format("//city[@id='{0}']", arg);
                xmlNode = regionDocument.SelectSingleNode(xpath);
                if (xmlNode != null)
                {
                    result = xmlNode;
                }
                else
                {
                    xpath   = string.Format("//province[@id='{0}']", arg);
                    xmlNode = regionDocument.SelectSingleNode(xpath);
                    if (xmlNode != null)
                    {
                        result = xmlNode;
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
コード例 #9
0
 public static System.Collections.Generic.Dictionary <int, string> GetCountys(int cityId)
 {
     return(RegionHelper.GetChildList(string.Format("root/region/province/city[@id='{0}']", cityId.ToString(System.Globalization.CultureInfo.InvariantCulture))));
 }
コード例 #10
0
 public static System.Collections.Generic.Dictionary <int, string> GetRegions()
 {
     return(RegionHelper.GetChildList("root"));
 }
コード例 #11
0
 public static XmlNode GetRegion(int regionId)
 {
     return(RegionHelper.FindNode(regionId));
 }