⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 response.aspx.cs

📁 中国县及县以上行政规划数字代码 用于数据库方面的应用。
💻 CS
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

public partial class response : System.Web.UI.Page
{
    string datapath = "app_data/areacode.xml";
    protected void Page_Load(object sender, EventArgs e)
    {
        string province = Request.QueryString["province"];
        string district = Request.QueryString["district"];
        //string city = Request.QueryString["city"];
        //int type = Convert.ToInt32(Request.QueryString["type"]);
        if (province == null&&district==null)
        {
            Response.Write(Find_Province());
        }
        if ((province != null) && (district == null))
        {
            Response.Write(Find_District(province));
        }
        if ((province == null) && (district != null))
        {
            Response.Write(Find_City(district));
        }
    }
    private string Find_Province()
    {
        XmlTextReader readXML = new XmlTextReader(Server.MapPath(datapath));
        string str = "";
        while (readXML.Read())
        {
                if (readXML.Name == "province")
                {
                    if (readXML.MoveToFirstAttribute()) { str += readXML.Value + ","; }
                    if (readXML.MoveToNextAttribute()) { str += readXML.Value + "|"; }
                }
        }
        readXML.Close();
        return str;
    }
    private string Find_District(string province)
    {
        XmlTextReader readXML = new XmlTextReader(Server.MapPath(datapath));
        string str= "";
        while (readXML.Read())
        {
            if (readXML.Name == "province")
            {
                if (readXML.MoveToFirstAttribute())
                {
                   
                    if (readXML.Value == province)
                    {
                        while (readXML.Read() && readXML.Depth >=3) 
                        { 
                            if (readXML.Name == "district")
                            {
                                if (readXML.MoveToFirstAttribute()) { str += readXML.Value+ ","; }
                                if (readXML.MoveToNextAttribute()) { str += readXML.Value + "|"; }
                            }
                        }
                        break;
                    }
                }
            }
        }
        readXML.Close();
        return str;
    }
    private string Find_City(string district)
    {
        XmlTextReader readXML = new XmlTextReader(Server.MapPath(datapath));
        string str = "";
        string strid = "";
        string strname = "";
        while (readXML.Read())
        {
            if (readXML.Name == "district")
            {
                if (readXML.MoveToFirstAttribute())
                {

                    if (readXML.Value == district)
                    {
                        while (readXML.Read() && readXML.Depth >= 4)
                        {
                            if (readXML.Name == "city")
                            {
                                if (readXML.MoveToFirstAttribute())
                                {
                                    strid = readXML.Value;
                                }
                                if (readXML.MoveToNextAttribute())
                                {
                                    strname = readXML.Value;
                                }
                                if (strname != "市辖区")
                                {
                                    str += strid + "," + strname + "|";
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
        readXML.Close();
        return str;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -