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

📄 printtaskwebconfigurator_csharp.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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Design;

namespace PrintTask_CSharp
{
    public class PrintTaskWebConfigurator_CSharp: ESRI.ArcGIS.ADF.Web.UI.WebControls.CompositeControl,
        IWebConfigurator, IBuddyControlSupport
    {
        #region Private fields for controls
        TextBox dialogTitle;
        TextBox printTitle;
        CheckBox ckbEnableTitleChange;
        CheckBox ckbEnableResults;
        TextBox maxWidth;
        DropDownList ddlMaxResolution;
        CheckBox ckbShowIdField;
        #endregion

        #region Web control

        protected override void CreateChildControls()
        {
            #region Setup and dialog/print titles
            Controls.Clear();

            Table ctlTable = new Table();
            Controls.Add(ctlTable);
            TableCell tCell;

            // Title row
            tCell = CreateCellRow(ctlTable, 0);

            tCell.Controls.Add(new LiteralControl("<strong>Print Task</strong><br/>"));
            //tCell.Controls.Add(tabCtl);

            tCell = CreateCellRow(ctlTable, 30);
            tCell.Controls.Add(new LiteralControl("Allows users to print the map and task results<br/>"));
            tCell = CreateCellRow(ctlTable, 0);
            tCell.Controls.Add(new LiteralControl("Title for print dialog in browser: "));
            dialogTitle = new TextBox();
            dialogTitle.ID = "dialogTitle";
            tCell.Controls.Add(dialogTitle);

            // Default print title & enable title change
            tCell = CreateCellRow(ctlTable, 0);
            tCell.Controls.Add(new LiteralControl("Default title for printed page: "));
            printTitle = new TextBox();
            printTitle.ID = "printTitle";
            printTitle.ToolTip = "User may change title unless disabled";
            tCell.Controls.Add(printTitle);
            ckbEnableTitleChange = new CheckBox();
            ckbEnableTitleChange.ID = "enableTitleChange";
            ckbEnableTitleChange.Text = "Allow user to change default title";
            ckbEnableTitleChange.ToolTip = "If disabled, user cannot change title on printed page";
            tCell.Controls.Add(ckbEnableTitleChange);

            #endregion

            #region Map print options
            tCell = CreateCellRow(ctlTable, 0);

            // Maximum map width (height proportioned automatically)
            tCell.Controls.Add(new LiteralControl("Maximum map width "));
            maxWidth = new TextBox();
            maxWidth.ID = "maxWidth";
            maxWidth.ToolTip = "Maximum width allowed for printing, in inches." +
                " Height is sized proportionally to the current Map control size.";
            tCell.Controls.Add(maxWidth);

            // Maximum resolution
            tCell = CreateCellRow(ctlTable, 0);
            tCell.Controls.Add(new LiteralControl("Maximum map resolution "));
            ddlMaxResolution = new DropDownList();
            ddlMaxResolution.ID = "ddlMaxResolution";
            ddlMaxResolution.ToolTip = "Maximum allowed map resolution, in DPI." +
                " Higher resolutions provide better print quality, but " +
                "consume more server resources when generating print map.";         
            tCell.Controls.Add(ddlMaxResolution);

            #endregion

            #region Task results printing

            tCell = CreateCellRow(ctlTable, 0);
            ckbEnableResults = new CheckBox();
            ckbEnableResults.ID = "enableResults";
            ckbEnableResults.Text = "Allow user to print items in Task Results";
            tCell.Controls.Add(ckbEnableResults);

            // Show ID Field
            tCell = CreateCellRow(ctlTable, 0);
            ckbShowIdField = new CheckBox();
            ckbShowIdField.ID = "ckbShowIdField";
            ckbShowIdField.Text = "Show ID field in attributes";
            ckbShowIdField.ToolTip = "If enabled, print includes ID field from attribute tables";
            tCell.Controls.Add(ckbShowIdField);

            #endregion

            #region OK/cancel row
            tCell = CreateCellRow(ctlTable, 0);

            Button okButton = new Button();
            okButton.ID = "okButton";
            okButton.Text = "OK";
            okButton.Width = new Unit(75, UnitType.Pixel);
            okButton.Click += new EventHandler(okButton_Click);
            tCell.Controls.Add(okButton);

            Button cancelButton = new Button();
            cancelButton.ID = "cancelButton";
            cancelButton.Text = "Cancel";
            cancelButton.Width = new Unit(75, UnitType.Pixel);
            cancelButton.Click += new EventHandler(cancelButton_Click);
            tCell.Controls.Add(cancelButton);

            #endregion
        }

        private TableCell CreateCellRow(Table table, int indentPixels)
        {
            TableRow tRow = new TableRow();
            table.Rows.Add(tRow);
            TableCell tCell = new TableCell();
            tCell.Wrap = false;
            tCell.Style[HtmlTextWriterStyle.FontWeight] = "normal";
            if (indentPixels < 1)
            {
                tCell.ColumnSpan = 2;
            }
            else
            {
                TableCell spCell = new TableCell();
                spCell.Width = new Unit(indentPixels, UnitType.Pixel);
                tRow.Cells.Add(spCell);
            }
            tRow.Cells.Add(tCell);
            return tCell;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            OnWebConfigurationCancel(new EventArgs());
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (printTask == null)
                return;

            // get user-selected values from the web dialog and store them in the task
            printTask.Title = dialogTitle.Text;
            printTask.PrintTitle = printTitle.Text;
            printTask.EnablePrintTitleChange = ckbEnableTitleChange.Checked;
            printTask.MaximumWidth = int.Parse(maxWidth.Text);
            printTask.MaximumResolution = int.Parse(ddlMaxResolution.SelectedValue);
            printTask.EnableResultsPrinting = ckbEnableResults.Checked;
            printTask.ShowIdField = ckbShowIdField.Checked;

            OnWebConfigurationComplete(new WebConfigurationCompleteEventArgs(
                printTask, getDesignTimeTag()));
        }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!Page.IsCallback)
            {
                // load current properties of control to edit
                loadProperties();
            }
        }

        private void loadProperties()
        {
            if (printTask == null)
                return;

            dialogTitle.Text = printTask.Title;
            printTitle.Text = printTask.PrintTitle;
            ckbEnableTitleChange.Checked = printTask.EnablePrintTitleChange;
            maxWidth.Text = printTask.MaximumWidth.ToString();

            int[] resOpts = printTask.ResolutionOptions;
            ddlMaxResolution.Items.Clear();
            for (int i = 0; i < resOpts.Length; i++)
                ddlMaxResolution.Items.Add(resOpts[i].ToString());
            string strMaxRes = printTask.MaximumResolution.ToString();
            if (ddlMaxResolution.Items.FindByText(strMaxRes) != null)
                ddlMaxResolution.SelectedValue = strMaxRes;

            ckbEnableResults.Checked = printTask.EnableResultsPrinting;
            ckbShowIdField.Checked = printTask.ShowIdField;
        }

        public override void Refresh()
        {
            loadProperties();
            base.Refresh();
        }

        #endregion

        #region getDesignTimeTag - enables Manager to write out settings to the web application page

        private string getDesignTimeTag()
        {
            StringBuilder sbTag = new StringBuilder();

            sbTag.Append("<printTaskCS:PrintTask_CSharp runat=\"server\"");
            AddTagProperty(sbTag, "ID", printTask.ID);
            sbTag.Append(" bordercolor=\"LightSteelBlue\" borderstyle=\"Outset\"");
            sbTag.Append(" borderwidth=\"1px\" font-names=\"Verdana\"");
            sbTag.Append(" font-size=\"8pt\" forecolor=\"Black\" titlebarcolor=\"WhiteSmoke\"");
            sbTag.Append(" Style=\"z-index: 10000; left: 200px; position: absolute; top: 200px\" ");
            sbTag.Append(" Width=\"200px\" Visible=\"False\" BackColor=\"White\"");
            AddTagProperty(sbTag, "Title", printTask.Title);

            // print task properties
            sbTag.Append(" Map=\"Map1\"");  // assumes Map id is Map1
            AddTagProperty(sbTag, "PrintTitle", printTask.PrintTitle);
            AddTagProperty(sbTag, "EnablePrintTitleChange", 
                printTask.EnablePrintTitleChange.ToString());
            AddTagProperty(sbTag, "EnableResultsPrinting", 
                printTask.EnableResultsPrinting.ToString());
            AddTagProperty(sbTag, "MaximumWidth", printTask.MaximumWidth.ToString());
            AddTagProperty(sbTag, "MaximumResolution", 
                printTask.MaximumResolution.ToString());
            AddTagProperty(sbTag, "ShowIdField", printTask.ShowIdField.ToString());

            sbTag.Append(">");

            // task containers tag
            sbTag.Append("<TaskResultsContainers>");
            sbTag.Append("<esri:BuddyControl Name=\"TaskResults1\" />");
            sbTag.Append("</TaskResultsContainers>");

            // closing tag
            sbTag.Append("</printTaskCS:PrintTask_CSharp>");

            return sbTag.ToString();
        }

        private void AddTagProperty(StringBuilder sb, string name, string value)
        {
            sb.Append(String.Format(" {0}=\"{1}\"", name, value));
        }
        #endregion

        #region IWebConfigurator Members

        private PrintTask_CSharp printTask = null;
        private ControlCollection controls;

        public ControlCollection AdditionalControls
        {
            get { return controls; }
            set { controls = value; }
        }

        public Control ControlToConfigure
        {
            get
            {
                return printTask;
            }
            set
            {
                if (!(value is PrintTask_CSharp))
                    throw new ArgumentException("Control must be a PrintTask");
                else
                    printTask = value as PrintTask_CSharp;
            }
        }

        public bool ValidateResources(out string message)
        {
            message = string.Empty;
            return true;
        }

        private WebConfigurationCompleteEventHandler onWebConfigurationComplete;

        public event WebConfigurationCompleteEventHandler WebConfigurationCompleted
        {
            add { onWebConfigurationComplete += value; }
            remove { onWebConfigurationComplete -= value; }
        }

        protected virtual void OnWebConfigurationComplete(WebConfigurationCompleteEventArgs args)
        {
            if (onWebConfigurationComplete != null) onWebConfigurationComplete(this, args);
        }

        private WebConfigurationCanceledEventHandler onWebConfigurationCancel;

        public event WebConfigurationCanceledEventHandler WebConfigurationCanceled
        {
            add { onWebConfigurationCancel += value; }
            remove { onWebConfigurationCancel -= value; }
        }

        protected virtual void OnWebConfigurationCancel(EventArgs args)
        {
            if (onWebConfigurationCancel != null) onWebConfigurationCancel(this, args);
        }

        #endregion

        #region IBuddyControlSupport Members

        public Type[] GetSupportedBuddyControlTypes()
        {
            Type[] arrTypes = new Type[1];
            arrTypes[0] = typeof(PrintTask_CSharp);
            return arrTypes;
        }

        #endregion
    }
}

⌨️ 快捷键说明

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