📄 printtask_csharp.cs
字号:
Controls.Add(cblResults);
}
#endregion
#region Print sizing
// Map width
ddlMapWidth = new DropDownList();
ddlMapWidth.ID = "width";
Controls.Add(ddlMapWidth);
ddlMapWidth.Items.Clear();
ddlMapWidth.Items.Add("Default");
string labelVal;
for (int i = 3; i <= MaximumWidth; i++)
{
labelVal = String.Format("{0} ({1:F0})", i, i * 2.54);
ddlMapWidth.Items.Add(new ListItem(labelVal, i.ToString()));
}
// Map resolution
ddlMapResolution = new DropDownList();
ddlMapResolution.ID = "resolution";
Controls.Add(ddlMapResolution);
ddlMapResolution.Items.Clear();
foreach (int num in _resolutionOptions)
if (num <= this.MaximumResolution)
ddlMapResolution.Items.Add(num.ToString());
// Scale
txtScale = new TextBox();
txtScale.ID = "scale";
Controls.Add(txtScale);
#endregion
#region Submit button
btnSubmit = new Button();
btnSubmit.ID = "btnSubmit";
Controls.Add(btnSubmit);
#endregion
base.CreateChildControls();
}
#endregion
#region OnPreRender - client scripts added; properties of controls set
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
#region Set controls properties
// More efficient to set these here than in CreateChildControls,
// since pre/render methods only called on full postback
Map mapCtrl = Utilities.GetMapControl(this.Map, Page.Controls);
if (mapCtrl == null)
throw new Exception(
"A Map control is required in the application using a PrintTask");
btnSubmit.OnClientClick =
String.Format("PrintTaskSendRequest(this, \"{0}\", \"{1}\");return false;",
CallbackFunctionString, mapCtrl.UniqueID);
#endregion
#region Add client scripts
ClientScriptManager scriptMgr = Page.ClientScript;
Type controlType = this.GetType();
string fileName = controlType.Namespace + ".ClientPrintFunctions.js";
scriptMgr.RegisterClientScriptResource(controlType, fileName);
#endregion
// if application does postback, need to refresh the task results list
if (Page.IsPostBack && !Page.IsCallback)
UpdateResultsListInPrintTask();
}
#endregion
#region RenderContents method
protected override void RenderContents(HtmlTextWriter writer)
{
// We render controls here rather than use CreateChildControls(),
// since RenderContents not called on normal callbacks
#region Set up and title
List<Control> ctlList = new List<Control>();
LiteralControl lc;
string cellText;
string toolTip;
writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "10pt");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
if (EnablePrintTitleChange)
{
cellText = "标题: ";
toolTip = "打印页标题";
txtTitle.ToolTip = toolTip;
RenderTableRowControl(writer, txtTitle, cellText, toolTip);
}
#endregion
#region Print options - map, task results
//cellText = "Print: ";
toolTip = "Include map on print page";
ckbPrintMap.ToolTip = toolTip;
RenderTableRowControl(writer, ckbPrintMap, null, toolTip);
if (EnableResultsPrinting)
{
cellText = "<hr /><br />打印任务结果:<br/>";
// checklist of task results: will be updated dynamically via callbacks
// (checkboxlist doesn't preserve value in ListItems - just use span?)
//cblResults.Items.Clear();
//cblResults.Items.Add(new ListItem("(None available)"));
cblResults.ToolTip = "Choose results to include on print page";
lc = new LiteralControl("<hr /><br />");
ctlList.Clear();
ctlList.Add(cblResults);
ctlList.Add(lc);
RenderTableRowControls(writer, ctlList.ToArray(), cellText, null);
}
#endregion
#region Print sizing
cellText = "地图宽度(英尺(厘米)): ";
ddlMapWidth.ToolTip = "Width of map (height is sized in proportion to width)";
ddlMapWidth.Items.Add("Default");
lc = new LiteralControl("<br />分辨率: ");
ddlMapResolution.ToolTip = "96 is default for screens. " +
"Higher values give better print quality, but use more computer resources.";
ctlList.Clear();
ctlList.Add(ddlMapWidth);
ctlList.Add(lc);
ctlList.Add(ddlMapResolution);
RenderTableRowControls(writer, ctlList.ToArray(), cellText, null);
// Scale
cellText = "刻度(可选) 1:";
toolTip = "Use numerical (RF) scale, such as 24000. If specified, map is " +
"scaled and centered at current map center.";
txtScale.ToolTip = toolTip;
txtScale.Width = new Unit(90, UnitType.Pixel);
RenderTableRowControl(writer, txtScale, cellText, toolTip);
#endregion
#region Submit button
btnSubmit.Text = "打印预览";
btnSubmit.ToolTip = "Click to open a new browser window with print preview." +
" Note that popup blockers must be disabled for print page to display.";
RenderTableRowControl(writer, btnSubmit, null, null);
#endregion
writer.RenderEndTag(); // table
//base.RenderContents(writer);
}
#endregion
#region Renderer helper methods
private TableCell CreateTableCell(Table table) {
TableRow tr = new TableRow();
table.Rows.Add(tr);
TableCell tc = new TableCell();
tc.Wrap = false;
tr.Cells.Add(tc);
return tc;
}
private void RenderTableRowControl(HtmlTextWriter writer, Control control,
string cellText, string cellTooltip)
{
Control[] ctls = new Control[] { control };
RenderTableRowControls(writer, ctls, cellText, cellTooltip);
}
private void RenderTableRowControls(HtmlTextWriter writer, Control[] controls,
string cellText, string cellTooltip)
{
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
if (cellTooltip != null)
writer.AddAttribute(HtmlTextWriterAttribute.Title, cellTooltip);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
if (cellText != null)
writer.Write(cellText);
if (controls != null)
foreach (Control ctl in controls)
ctl.RenderControl(writer);
writer.RenderEndTag(); // td
writer.RenderEndTag(); // tr
}
#endregion
#region OnLoad method
protected override void OnLoad(EventArgs e)
{
if (!Page.IsPostBack || !_contextMenuEventRegistered)
{
// attach to clicked event of task results--so detect when task results removed
List<TaskResults> tResList =
Utilities.GetTaskResultsControls(TaskResultsContainers, Page);
foreach (TaskResults tr in tResList)
{
tr.TaskResultContextMenu.ItemClicked +=
new ContextMenuItemClickedEventHandler(TaskResultContextMenu_ItemClicked);
}
_contextMenuEventRegistered = true;
}
// Handles updating task results when a task executes and adds new results
if (Page.IsCallback)
{
// For updating list of task results on callbacks
ITask taskControlBeingExecuted =
Utilities.IsCallbackForExecuteTask(Page, this.SupportedTaskTypes);
if (taskControlBeingExecuted != null)
{
// Add callback to the executing task with instructions to call
// client function which updates this task
// (need to use another callback because the task results haven't actually
// been added yet)
CallbackResult cbRefreshTaskResults = new CallbackResult(
this, "javascript",
String.Format("RefreshTaskResults(\"{0}\")", CallbackFunctionString));
taskControlBeingExecuted.CallbackResults.Add(cbRefreshTaskResults);
}
}
base.OnLoad(e);
}
#endregion
#endregion
#region OnShow override - updates list of tasks in print UI when PrintTask displayed
protected override void OnShow(EventArgs args)
{
// Update the list of task results in the print task UI, if task results have changed
if (Page.IsCallback)
{
// Update the list of task results in the task UI
// - since this is a callback, need to pass the taskresults HTML to display in browser
CallbackResult cbResultTaskList = RefreshTaskResultsList();
this.CallbackResults.Add(cbResultTaskList);
}
base.OnShow(args);
}
#endregion
#region GetCallbackResult
public override string GetCallbackResult()
{
string argUnesc = System.Uri.UnescapeDataString(_callbackArg);
NameValueCollection keyValColl =
CallbackUtility.ParseStringIntoNameValueCollection(argUnesc);
string eventArg = keyValColl["EventArg"];
// Get the type of operation requested by browser
switch (eventArg)
{
case "updateTaskResults":
// Called after another task executes--updates list of task results
CallbackResult cbr = this.RefreshTaskResultsList();
this.CallbackResults.Add(cbr);
break;
case "executeTask":
// since have multiple values, just store the whole collection as Input
Input = keyValColl;
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -