ArcGIS.Server.9.2.DotNet自带例子分析(七、一)

目的:
1.arcgis server9.2 ADF实现Query查询功能

准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫usa的Map Service,并且把这个Service启动起来。
2.找到DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_QueryNewWindowCSharp.zip。

开始:
1.新建名为QueryNewWindow的ASP.NET Web应用程序,  然后在页面上添加MapResourceManager1、Button1。设置MapResourceManager1的属性Type:ArcGIS Server Local;Resource:(default)@usa;Data Source:mycomp。Button1添加Button1_Click时间,具体代码和说明如下:

 1 protected   void  Button1_Click( object  sender, EventArgs e)
 2          {
 3            //获取MapResourceManager1的Resource集合
 4            IEnumerator egrc = MapResourceManager1.GetResources().GetEnumerator();
 5            //判定初始化MapResourceManager1
 6            if (!MapResourceManager1.Initialized)
 7            {
 8                MapResourceManager1.Initialize();
 9            }

10            while (egrc.MoveNext())
11            {
12                //随机数
13                Random random = new Random();
14                int randout = random.Next(01000);
15
16                //获取Resource
17                IGISResource gisresource = (IGISResource)egrc.Current;
18                //判定初始化Resource
19                if (!gisresource.Initialized)
20                {
21                    gisresource.Initialize();
22                }

23                //判定是否支持QueryFunctionality
24                bool supportquery = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
25                if (supportquery)
26                {
27                    //创建QueryFunctionalit
28                    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;
29                    qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
30
31                    //查询图层id和名称
32                    string[] lids;
33                    string[] lnames;
34                    qfunc.GetQueryableLayers(nullout lids, out lnames);
35                    //要查询目标图层名称
36                    string sourcelayername = "states";
37                    //获取查询目标图层的index
38                    int layer_index = 0;
39                    for (int i = 0; i < lnames.Length; i++)
40                    {
41                        if (lnames[i] == sourcelayername)
42                        {
43                            layer_index = i;
44                            break;
45                        }

46                    }

47                    //查询过滤
48                    ESRI.ArcGIS.ADF.Web.QueryFilter queryfilter = new ESRI.ArcGIS.ADF.Web.QueryFilter();
49                    //要查询字段名称
50                    string fieldlist = "STATE_NAME";
51                    //查询的字段集
52                    ESRI.ArcGIS.ADF.StringCollection strcollection = new ESRI.ArcGIS.ADF.StringCollection(fieldlist, ',');
53                    queryfilter.SubFields = strcollection;
54                    //查询语句
55                    queryfilter.WhereClause = "STATE_NAME LIKE 'A%'";
56                    //查询结果存入DataTable
57                    System.Data.DataTable qdatatable = qfunc.Query(null, lids[layer_index], queryfilter);
58                    qdatatable.Columns[0].ColumnName = "STATE_NAME_ALIAS";
59                    //查询结果DataTable存入Session中
60                    Session["dt" + randout] = qdatatable;
61                }

62
63                string argval = "?id=" + randout;
64                //弹出新页面显示查询结果
65                Response.Write("<script>window.open('TableDialog.aspx" + argval + "', '" + randout.ToString() + "', 'dependent=yes ,width=400, height=200, status=no, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=yes'); </script>");
66            }

67        }
2.新建TableDialog.aspx页面用来作为弹出页面显示查询结果,在html里面添加一个<div id="datadiv" runat="server"></div>用来显示查询内容。
3.接下来编写 TableDialog.aspx的Page_Load事件,进行查询内容的显示,具体代码和说明如下:

 1 protected   void  Page_Load( object  sender, EventArgs e)
 2          {
 3            string id = Request.QueryString["id"];
 4            DataTable dt = (DataTable)Session["dt" + id];
 5            if (dt != null)
 6            {
 7                System.Web.UI.HtmlControls.HtmlForm htmlform = (System.Web.UI.HtmlControls.HtmlForm)Page.FindControl("form1");
 8                Control controldiv = htmlform.FindControl("datadiv");
 9
10                GridView gd = new GridView();
11                gd.DataSource = dt;
12                gd.DataBind();
13                gd.Visible = true;
14                gd.BorderWidth = 10;
15                controldiv.Controls.Add(gd);
16            }

17        }
4.这样就可以运行查看效果了,这个例子比较简单了。
ArcGIS.Server.9.2.DotNet自带例子分析(七、一)

你可能感兴趣的:(server)