📄 response.aspx.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 + -