Common_CustomEditorTask_CSharp\CustomEditorTask_CSharp\CustomEditorTask.cs
// Copyright 2010 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 the use restrictions. // namespace CustomEditorTask_CSharp { [System.ComponentModel.DefaultProperty("Text")] [System.Web.UI.ToolboxData("<{0}:CustomEditorTask runat=server></{0}:CustomEditorTask>")] public class CustomEditorTask : ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask { #region WebControl Life Cycle Event Overrides protected override void OnLoad(System.EventArgs eventArgs) { base.OnLoad(eventArgs); ////Uncomment the following if you want to Set attribute filtering parameters for the EditorTask during the //// Page Load event of the initial request. //if (!this.Page.IsPostBack) //{ // FilterAttributes(); //} } #endregion #region EditorTask Overrides // Override to create and return a custom settings panel protected override ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorSettingsPanel CreateSettingsPanel() { return new CustomEditorSettingsPanel(this); //return base.CreateSettingsPanel(); } // Override to create and return a custom Editor protected override ESRI.ArcGIS.ADF.ArcGISServer.Editor.Editor CreateEditor() { return new CustomEditor(this); //return base.CreateEditor(); } // Override to execute logic after an editor tool has completed execution protected override void OnPostToolExecute( ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolEventArgs editorToolEventArgs, ESRI.ArcGIS.ADF.ArcGISServer.Editor.StringList returnMessages) { base.OnPostToolExecute(editorToolEventArgs, returnMessages); // After a tool that modifies features has executed, add creation and modified time to edited feature. // The "Tentative Assessed Parcel" layer contains two Date fields: CreationTime and LastModified. // If a new feature was created, update the CreationTime field with the current Date. // If an existing feature was modified (via the tools listed), update the LastModified field with the current Date. //if (editorToolEventArgs.ServerAction.Editor.SelectedLayerName == "Tentative Assessed Parcels") if (editorToolEventArgs.ServerAction.Editor.SelectedLayerName == "Blocks") { // Get the feature class underlying the layer containing the edited feature ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = editorToolEventArgs.ServerAction.Editor.FeatureLayer.FeatureClass; // If statements check the ServerAction type to determine which tool executed if (editorToolEventArgs.ServerAction is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature) { // Get a reference to the feature that was modified via the tool that executed ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature createFeature = (ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature)editorToolEventArgs.ServerAction; ESRI.ArcGIS.Geodatabase.IFeature feature = featureClass.GetFeature(createFeature.Feature); // Populate the CreationTime field with the current time on the server int index = feature.Fields.FindField("CreationTime"); if (index > -1) { feature.set_Value(index, System.DateTime.Now); feature.Store(); } } // For simplicity only a few tools that modify features have been included else if (editorToolEventArgs.ServerAction is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex) { // Get the tool that executed and update the last modified time attribute via utility method ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex addVertex = (ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex)editorToolEventArgs.ServerAction; UpdateLastModifiedTime(addVertex.Features, featureClass); } else if (editorToolEventArgs.ServerAction is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex) { // Get the tool that executed and update the last modified time attribute via utility method ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex moveVertex = (ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex)editorToolEventArgs.ServerAction; UpdateLastModifiedTime(moveVertex.Features, featureClass); } else if (editorToolEventArgs.ServerAction is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature) { // Get the tool that executed and update the last modified time attribute via utility method ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature moveFeature = (ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature)editorToolEventArgs.ServerAction; UpdateLastModifiedTime(moveFeature.Features, featureClass); } // Refreshes the EditAttributesPanel (returned from call to Editor.AttributesEditor property) // and adds callbacks to the Map control associated with the Editor. ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorUtilities.RefreshAttributes( editorToolEventArgs.ServerAction.Editor, null); } } #endregion #region Instance Properties // Custom property to set limit on number of records returned from query. [ System.ComponentModel.Browsable(true), System.ComponentModel.Category("Select by Attributes"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(100), System.ComponentModel.Description("Maximum number of sample values to return on select by attributes panel.") ] public int SampleValueLimit { get { if (StateManager.GetProperty("sampleValueLimit") == null) this.SampleValueLimit = 100; return (int)StateManager.GetProperty("sampleValueLimit"); } set { StateManager.SetProperty("sampleValueLimit", value); } } // Custom property to define snapping in map units [ System.ComponentModel.Browsable(true), System.ComponentModel.Category("Snapping"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS), System.ComponentModel.Description("The maximum distance in map units for which " + "snapping rules will be effective.") ] public double SnapToleranceMapUnits { get { object obj = StateManager.GetProperty("snapTolMapUnits"); if (obj == null) { return CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS; } return (double)obj; } set { StateManager.SetProperty("snapTolMapUnits", value); } } // Custom property to define if snapping should use pixels (default) or map units. [ System.ComponentModel.Browsable(true), System.ComponentModel.Category("Snapping"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(true), System.ComponentModel.Description("Indicates if snapping uses map units or pixels.") ] public bool UseMapUnitsForSnapping { get { object obj = StateManager.GetProperty("useSnappingMapUnits"); if (obj != null) return (bool)obj; return true; } set { StateManager.SetProperty("useSnappingMapUnits", value); } } #endregion #region Instance Methods // Used during post tool execute to update the LastModified field of edited features private void UpdateLastModifiedTime(System.Collections.Generic.List<int> featureIDs, ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass) { // Iterate through the passed-in feature IDs and update the corresponding feature's // LastModified field with the current server time int index = featureClass.Fields.FindField("LastModified"); foreach (int featureID in featureIDs) { ESRI.ArcGIS.Geodatabase.IFeature feature = featureClass.GetFeature(featureID); feature.set_Value(index, System.DateTime.Now); feature.Store(); } } //This function is not used currently in the sample. private void FilterAttributes() { // Get the ArcGIS Server Local MapFunctionality associated with the EditorTask ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality agsLocalMapFunctionality = this.Editor.MapFunctionality; string[] layerIDs = null; string[] layerNames = null; agsLocalMapFunctionality.GetLayers(out layerIDs, out layerNames); // Iterate through feature layers in the MapFunction (map resource) and set // attribute display parameters when editing attributes in the EditAttributesPanel. for (int i = 0; i < layerIDs.Length; i++) { string layerName = layerNames[i]; int layerID = System.Int32.Parse(layerIDs[i]); if (layerName == "Parcels") { ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo attributeDisplayInfo = new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.ReadOnly); attributeDisplayInfo.Overrides.Add( new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("Parcel_ID", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable)); this.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo); } else if (layerName == "Road centerline") { ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo attributeDisplayInfo = new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable); attributeDisplayInfo.Overrides.Add( new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("NAME", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.ReadOnly)); this.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo); } else if (layerName == "Blocks") { ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo attributeDisplayInfo = new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Hidden); attributeDisplayInfo.Overrides.Add( new ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("Res", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable)); this.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo); } } } #endregion } }