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

📄 utilities.cs

📁 arcgis engine地图打印任务的应用
💻 CS
字号:
// Copyright 2006 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See use restrictions at /arcgis/developerkit/userestrictions.
// 

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;

namespace PrintTask_CSharp
{
    class Utilities
    {
        #region GetMapControl method
        /// <summary>
        /// Finds the Map control in the control collection
        /// </summary>
        /// <param name="MapId">ID of the Map control</param>
        /// <param name="controls">Control collection that contains Map (e.g., Page.Controls)</param>
        /// <returns>Map control matching the mapId, or the first Map control
        /// if mapId is empty, or null if no map control found</returns>
        public static Map GetMapControl(string mapId, ControlCollection controls)
        {

            foreach (Control ctl in controls)
            {
                if (ctl is Map && (mapId == String.Empty || ctl.ID == mapId))
                    return (Map)ctl;
                else if (ctl.HasControls())
                {
                    Map mapCtl = GetMapControl(mapId, ctl.Controls);
                    if (mapCtl != null && (mapId == String.Empty || mapCtl.ID == mapId))
                    {
                        // save map in class field
                        return mapCtl;
                    }
                }
            }
            return null;

        }
        #endregion

        #region Refresh control methods
        protected internal static CallbackResult RefreshControlHtml(Control control)
        {
            string htmlContent = RenderControlHtml(control);
            return new CallbackResult(control, "content", htmlContent);
        }

        protected internal static string RenderControlHtml(Control control)
        {
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter writer = new HtmlTextWriter(sw);

            control.RenderControl(writer);
            string htmlContent = sw.ToString();
            sw.Close();

            return htmlContent;
        }
        #endregion

        #region TaskResultItemsChanged method
        internal static bool TaskResultItemsChanged(
            ListItem[] taskResultsItems, CheckBoxList printTaskList)
        {
            bool listChanged = false;

            // If number of items doesn't match the print list, we know we must replace it
            if (taskResultsItems.Length != printTaskList.Items.Count)
            {
                listChanged = true;
            }
            // Otherwise we must compare item by item using taskjobid
            else
            {
                for (int i = 0; i < taskResultsItems.Length; i++)
                {
                    if (taskResultsItems[i].Value != printTaskList.Items[i].Value)
                    {
                        listChanged = true;
                        break;
                    }
                }
            }
            return listChanged;
        }
        #endregion

        #region GetTaskResultList method
        // Gets a current list of the task results that have datasets
        internal static ListItem[] GetTaskResultList(
            BuddyControlCollection taskResultsContainers, Page page)
        {
            // Get the task results controls buddied to the task
            List<TaskResults> taskResList = 
                GetTaskResultsControls(taskResultsContainers, page);
            List<ListItem> resultsItems = new List<ListItem>(taskResList.Count);

            foreach (TaskResults tr in taskResList)
            {
                // Get the names of each result item and add to the list
                foreach (TreeViewPlusNode rNode in tr.Nodes)
                {
                    //TaskResultNode trn = (TaskResultNode)rNode;

                    // if no subnodes, no results to print; make sure
                    //  the subnode is a GraphicsLayer
                    if (rNode.Nodes.Count > 0 && rNode.Nodes[0] is GraphicsLayerNode)

                        resultsItems.Add(new ListItem(rNode.Text, rNode.Value));
                }
            }

            return resultsItems.ToArray();
        }
        #endregion

        #region GetTaskResultsControls method
        internal static List<TaskResults> GetTaskResultsControls(
            BuddyControlCollection taskResultsContainers,
            Page controlPage)
        {
            List<TaskResults> resultsItems = new List<TaskResults>(taskResultsContainers.Count);

            TaskResults tr;

            // TaskResultsContainers has name(s) of TaskResults control(s) - usually only 1 control
            foreach (BuddyControl bc in taskResultsContainers)
            {
                // Get the TaskResults control associated with each buddy control name
                tr = (TaskResults)FindControlRecursive(controlPage, bc.Name);

                if (tr != null)
                    resultsItems.Add(tr);
            }

            return resultsItems;
        }
        #endregion

        #region CapText method
        /// <summary>
        /// Converts string to have initial caps. 
        /// </summary>
        /// <param name="input">String to capitalize</param>
        /// <returns>String with initial caps</returns>
        public static string CapText(string input)
        {
            return input.Substring(0, 1).ToUpper() + input.Substring(1).ToLower();
        }
        #endregion

        #region IsCallbackForExecuteTask method

        /// <summary>
        /// Determines whether the page callback is to execute one of the input task types.
        /// </summary>
        /// <param name="page">Page to check</param>
        /// <param name="taskTypes">Array of names of ITask types supported</param>
        /// <returns>Task (ITask) control being executed, or null if not a task execution.</returns>
        public static ITask IsCallbackForExecuteTask(Page page, string[] taskTypes)
        {
            string callbackIdString = "__CALLBACKID";
            string callbackParamString = "__CALLBACKPARAM";

            string taskUniqueId = page.Request.Form[callbackIdString];
            string taskParams = page.Request.Form[callbackParamString];

            ITask taskControl = null;

            // make sure we've got the callback form arguments
            if (!String.IsNullOrEmpty(taskUniqueId) && !String.IsNullOrEmpty(taskParams))
            {
                // find the task control on the page
                Control control = page.FindControl(taskUniqueId);
                if (control != null && control is ITask)
                {
                    bool taskTypeFound = false;
                    string taskType;

                    // see if the control is one of the task types specified
                    for (int i = 0; i < taskTypes.Length; i++)
                    {
                        taskType = taskTypes[i];

                        if (control.GetType().Name == taskType)
                        {
                            taskTypeFound = true;
                            break;
                        }
                    }

                    if (taskTypeFound)
                    {
                        // make sure it's an execute-task callback (vs. activity-indicator, etc.)
                        if (taskParams.IndexOf("EventArg=executeTask",
                            StringComparison.InvariantCultureIgnoreCase) >= 0)

                            taskControl = control as ITask;
                    }
                }
            }

            return taskControl;
        }

        #endregion

        #region FindControlRecursive method
        /// <summary>
        /// Finds a control by recursively searching containing controls
        /// </summary>
        /// <param name="root">Top-level control that contains controls</param>
        /// <param name="id">ID of the control to find</param>
        /// <returns>Control matching the ID</returns>
        public static Control FindControlRecursive(Control root, string id)
        {
            if (root.ID == id)
            {
                return root;
            }

            foreach (Control c in root.Controls)
            {
                Control t = FindControlRecursive(c, id);
                if (t != null)
                {
                    return t;
                }
            }

            return null;
        }
        #endregion

        #region FindControls method
        /// <summary>
        /// Finds the controls of the type input in the control collection
        /// </summary>
        /// <param name="type">Type to find</param>
        /// <param name="controls">Controls (e.g., Page.Controls)</param>
        /// <returns>List of controls, or empty List if none found</returns>
        public static List<Control> FindControls(Type type, ControlCollection controls)
        {
            List<Control> ctls = new List<Control>();

            foreach (Control ctl in controls)
            {
                if (type.IsInstanceOfType(ctl))
                    ctls.Add(ctl);

                // just in case control contains controls of its own type, always check child controls
                if (ctl.HasControls())
                {
                    List<Control> childCtls = FindControls(type, ctl.Controls);
                    foreach (Control c in childCtls)
                    {
                        ctls.Add(c);
                    }
                    //return childCtls;
                }
            }
            return ctls;
        }
        #endregion
    }
}

⌨️ 快捷键说明

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