📄 webform1.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace sendArcXML
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox ArcXMLInputText;
protected System.Web.UI.WebControls.TextBox ArcXMLOutputText;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox ArcIMSServerText;
protected System.Web.UI.WebControls.Button ClearResponseButton;
protected System.Web.UI.WebControls.Button DisplayButton;
protected System.Web.UI.WebControls.Image ArcIMSImage;
protected System.Web.UI.WebControls.Button GetServicesButton;
protected System.Web.UI.WebControls.Label ServiceNameLabel;
protected System.Web.UI.WebControls.DropDownList ServiceDDList;
protected System.Web.UI.WebControls.Label RequestLabel;
protected System.Web.UI.WebControls.DropDownList RequestDDList;
protected System.Web.UI.WebControls.Button SendArcXMLButton;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.DataGrid FeatureDataGrid;
//Connection information for axl_list.mdb. Be sure you change the path for
//the Data Source to the correct location on your machine
protected string theConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\axl_list.mdb;";
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DisplayButton.Click += new System.EventHandler(this.DisplayButton_Click);
this.ClearResponseButton.Click += new System.EventHandler(this.ClearResponseButton_Click);
this.SendArcXMLButton.Click += new System.EventHandler(this.SendArcXMLButton_Click);
this.GetServicesButton.Click += new System.EventHandler(this.GetServicesButton_Click);
this.RequestDDList.SelectedIndexChanged += new System.EventHandler(this.RequestDDList_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SendArcXMLButton_Click(object sender, System.EventArgs e)
{
string CustomServiceName = "";
localhost.ArcXML_Web_Service getReturnArcXML = new localhost.ArcXML_Web_Service();
//Test for type of request. GET_FEATURES, GET_GEOCODE, and GET_EXTRACT
//must be rerouted using CustomService in the URL.
if (ArcXMLInputText.Text.IndexOf("<GET_FEATURES") > -1) CustomServiceName = "Query";
else if (ArcXMLInputText.Text.IndexOf("<GET_GEOCODE") > -1) CustomServiceName = "Geocode";
else if (ArcXMLInputText.Text.IndexOf("<GET_EXTRACT") > -1) CustomServiceName = "Extract";
DisplayButton.Visible = Boolean.Parse("False");
ArcIMSImage.Visible = Boolean.Parse("False");
FeatureDataGrid.Visible = Boolean.Parse("False");
try
{
//string theCurrentService = TextBox1.Text;
string theCurrentService = ServiceDDList.SelectedItem.Text;
string returnedArcXML = getReturnArcXML.sendMyArcXML(ArcXMLInputText.Text,ArcIMSServerText.Text,theCurrentService,CustomServiceName);
ArcXMLOutputText.Text = returnedArcXML;
//Display Show Map Button if IMAGE response is returned
if (returnedArcXML.IndexOf("<IMAGE>") > -1)
{
DisplayButton.Text = "Show Map";
DisplayButton.Visible = Boolean.Parse("True");
}
//Display Show Layout Button if LAYOUT response is returned
else if (returnedArcXML.IndexOf("<LAYOUT>") > -1)
{
DisplayButton.Text = "Show Layout";
DisplayButton.Visible = Boolean.Parse("True");
}
//Display Show Features Button if FEATURES response is returned and includes <FIELDS> (must have at least one record, and "newxml" must be used isntead of "xml")
else if (returnedArcXML.IndexOf("<FEATURES>") > -1 && returnedArcXML.IndexOf("<FIELDS>") > -1)
{
DisplayButton.Text = "Show Features";
DisplayButton.Visible = Boolean.Parse("True");
}
}
catch(Exception error)
{
ArcXMLOutputText.Text = "The request did not process correctly. Some likely reasons are:\n--The ArcIMS Server and Service combination you have is not valid.\n--The request you sent was blank. \n\nThe returned error message is:\n\n" + error.Message;
}
}
private void ClearResponseButton_Click(object sender, System.EventArgs e)
{
ArcXMLOutputText.Text = "";
DisplayButton.Visible = Boolean.Parse("False");
ArcIMSImage.Visible = Boolean.Parse("False");
}
private void DisplayButton_Click(object sender, System.EventArgs e)
{
//Display Show Map Button if IMAGE response is returned. This code parses
//the IMAGE response for the URL.
if (ArcXMLOutputText.Text.IndexOf("<IMAGE>") > -1 || ArcXMLOutputText.Text.IndexOf("<LAYOUT>") > -1)
{
int theURLstart=ArcXMLOutputText.Text.IndexOf("http://");
int theURLend=ArcXMLOutputText.Text.IndexOf(".",theURLstart);
ArcIMSImage.ImageUrl =ArcXMLOutputText.Text.Substring(theURLstart,theURLend - theURLstart + 4);
ArcIMSImage.Visible = Boolean.Parse("True");
FeatureDataGrid.Visible = Boolean.Parse("False");
}
//Display Show Features Button if FEATURES response is returned
else if (ArcXMLOutputText.Text.IndexOf("<FEATURES>") > -1)
{
FeatureDataGrid.DataSource = procFeatureList();
FeatureDataGrid.DataBind();
FeatureDataGrid.Visible = Boolean.Parse("True");
ArcIMSImage.Visible = Boolean.Parse("False");
}
}
private ArrayList procFeatureList()
{
string theString = ArcXMLOutputText.Text;
//Get the number of features returned
int theStart = theString.IndexOf("<FEATURECOUNT",0) + 21;
int theEnd = theString.IndexOf("hasmore",theStart) -2;
string theItem = theString.Substring(theStart,theEnd - theStart);
int theFeatureCount = Convert.ToInt32(theItem);
//Get the column header items
theStart = theString.IndexOf("<FIELDS");
theEnd=0;
int theFinish = theString.IndexOf("</FIELDS>",theStart);
int numFields = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
ArrayList theArrayList = new ArrayList();
int notFirst = 0;
while (theStart > -1 && theStart < theFinish)
{
if (notFirst == 0) notFirst = 1; else sb.Append("<td>");
theStart = theString.IndexOf("FIELD name=",theEnd) + 12;
if (theEnd > theFinish) break;
theEnd = theString.IndexOf("value",theStart) - 2;
theItem = theString.Substring(theStart,theEnd - theStart);
sb.Append(theItem + "</td>");
numFields ++;
theStart = theString.IndexOf("FIELD name=",theEnd);
}
sb.Remove(sb.Length-5,5); //get rid of last </td>
theArrayList.Add(sb.ToString());
sb.Remove(0,sb.Length); //empty the stringbuilder
//Get the data for each column
theStart = ArcXMLOutputText.Text.IndexOf("<FIELDS>");
theEnd = 0;
//for loop for each FEATURE
for (int icounter = 0; icounter < theFeatureCount; icounter++)
{
//for loop for each FIELD within a FEATURE
for (int jcounter = 0; jcounter < numFields; jcounter++)
{
if (jcounter > 0) sb.Append("<td>");
theStart = theString.IndexOf("value=",theEnd) + 7;
theEnd = theString.IndexOf("/>",theStart) - 2;
theItem = theString.Substring(theStart,theEnd - theStart);
sb.Append(theItem + "</td>");
}
sb.Remove(sb.Length-5,5);
theArrayList.Add(sb.ToString());
sb.Remove(0,sb.Length);
}
return theArrayList;
}
private void GetServicesButton_Click(object sender, System.EventArgs e)
{
try //outer try
{
localhost.ArcXML_Web_Service getReturnArcXML = new localhost.ArcXML_Web_Service();
string returnedArcXML = getReturnArcXML.sendMyArcXML("<GETCLIENTSERVICES/>",ArcIMSServerText.Text,"catalog",""); //bad return goes to outer catch
//set up array to hold service names
ArrayList theArrayList = new ArrayList();
int theEnd = 0;
string theService;
int theStart=returnedArcXML.IndexOf("SERVICE");
while (theStart > -1)
{
//parses the service names from the SERVICEINFO response. All
//services are parsed regardless of service type, so Feature and
//Metadata Services will be listed too.
theStart = returnedArcXML.IndexOf("SERVICE name=",theEnd) + 14;
if (theStart < theEnd) break;
theEnd = returnedArcXML.IndexOf("servicegroup",theStart) - 2;
theService = returnedArcXML.Substring(theStart,theEnd - theStart);
theArrayList.Add(theService);
}
ServiceNameLabel.Visible = Boolean.Parse("True");
ServiceNameLabel.Text = "Service Name";
theArrayList.Sort(); //alphabetize service list
ServiceDDList.Visible = Boolean.Parse("True");
ServiceDDList.Items.Clear();
ServiceDDList.DataSource = theArrayList;
ServiceDDList.DataBind();
SendArcXMLButton.Enabled = Boolean.Parse("True");
//Set up connection to database and bind info in tag column to
//RequestDDList control
OleDbConnection conn = new OleDbConnection(theConnection);
OleDbCommand cmd = new OleDbCommand("SELECT tag FROM axl ORDER BY tag", conn);
try //****inner try
{
conn.Open();
IDataReader reader = cmd.ExecuteReader();
RequestDDList.DataSource = reader;
RequestDDList.DataTextField = "tag";
RequestDDList.DataBind();
reader.Close();
RequestLabel.Visible = Boolean.Parse("True");
RequestDDList.Visible = Boolean.Parse("True");
RequestDDList.SelectedItem.Text = "GET_IMAGE";
showAxl(conn);
}
catch(Exception error) //********inner catch
{
ArcXMLInputText.Text = "The ArcXML samples database did not open correctly. No ArcXML examples are included. You will need to type in ArcXML requests. To get a list of examples, try clicking the Get Services button again. \n\nThe returned error message is:\n\n" + error.Message;
RequestDDList.Visible = Boolean.Parse("False");
RequestLabel.Visible = Boolean.Parse("False");
}
finally //*****inner finally
{
conn.Dispose();
}
}
catch //outer catch
{
ServiceDDList.Visible = Boolean.Parse("False");
DisplayButton.Visible = Boolean.Parse("False");
ArcIMSImage.Visible = Boolean.Parse("False");
ArcXMLOutputText.Text = "";
ArcXMLInputText.Text = "";
ServiceNameLabel.Visible = Boolean.Parse("True");
ServiceNameLabel.Text = "No services at this time";
ServiceNameLabel.ForeColor = Color.Yellow;
FeatureDataGrid.Visible = Boolean.Parse("False");
SendArcXMLButton.Enabled = Boolean.Parse("False");
RequestDDList.Visible = Boolean.Parse("False");
RequestLabel.Visible = Boolean.Parse("False");
}
}
private void RequestDDList_SelectedIndexChanged(object sender, System.EventArgs e)
{
OleDbConnection conn = new OleDbConnection(theConnection);
try
{
conn.Open();
showAxl(conn);
}
catch(Exception error)
{
ArcXMLInputText.Text = "The ArcXML samples database did not open correctly. No ArcXML example is included. \n\nThe returned error message is:\n\n" + error.Message;
}
finally
{
conn.Dispose();
}
}
private void showAxl(OleDbConnection conn)
{
//Read ArcXML request from database based on what user selected in
//RequestDDList dropdown list. Even though only one record is selected
//a while statement can be used to extract that record from the reader.
OleDbCommand cmd = new OleDbCommand("SELECT axl FROM axl WHERE tag = '" + RequestDDList.SelectedItem + "'", conn);
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ArcXMLInputText.Text = reader.GetString(0);
}
reader.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -