ArcGIS.Server.9.2.DotNet实现在线编辑EditorTask使用(自带例子 十、二)
目的:
1.arcgis server9.2 ADF实现实现在线编辑EditorTask使用。
准备工作:
1.参考DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_CustomEditorTaskCSharp.zip。
2.布Map Service,名称:EditParcelsDemo,具体步骤见SQL Server Express和ArcSDE Personal Edition(自带例子 十、一) 。
完成后的效果图:

开始:
1.新建名为CustomEditorTask的ASP.NET Web应用程序,在页面上添加MapResourceManager1、Map1、Menu1、TaskManager1控件,在TaskManager1添加一个EditorTask1控件。
2.设置MapResourceManager1属性,DataSourceType为ArcGIS Server Local,Name为EditParcelsDemo,连接上面发布的EditParcelsDemo。
3.TaskManager1的BuddyControl属性设置为Menu1;Visible为False;MapResource属性为Map1::EditParcelsDemo;EditableLayers属性为0;1;2;4;6,就是对应图层Address Points、Streets、Water Bodies、Parcel Boundaries、Tentative Assessed Parcels,这个属性就设置允许编辑的图层;属性为dbo.DEFAULT;DBO.DemoVersion1。
4.其他的控件也做好相应是设置功能,通过上面的设置就已经实现的基本的编辑功能了可以运行进行编辑操作,EditorTask控件确实方便了没有写任何代码就实现了编辑功能。
5.接下来需要通过代码实现EditorTask控件一些个性化的需要,比如设置哪些属性可以编辑,哪些属性只能只读,哪些元素不能删除等。
6.添加Page_Init事件,并且在这个事件中添加如下代码:
protected void Page_Init(object sender, EventArgs e)2
{3
//编辑前事件4
EditorTask1.PreAttributeEdit += new PreAttributeEditEventHandler(EditorTask1_PreAttributeEdit);5
//编辑post事件6
EditorTask1.PostAttributeEdit += new PostAttributeEditEventHandler(EditorTask1_PostAttributeEdit);7
//命令执行前事件8
EditorTask1.PreCommandExecute += new ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.PreCommandExecuteEventHandler(EditorTask1_PreCommandExecute);9
}EditorTask1_PreAttributeEdit方法(当进行数据编辑时记录编辑用户名)代码如下:
void EditorTask1_PreAttributeEdit(object sender, PreAttributeEditEventArgs e)2
{3
//查找UPDATEDBY字段4
int fieldIndex = e.Feature.Table.FindField("UPDATEDBY");5
//如果有UPDATEDBY字段,则记录当前的更新的用户名6
if (fieldIndex > -1)7
{8
string authenticatedUserName = Context.User.Identity.Name;9
if (!string.IsNullOrEmpty(authenticatedUserName))10
{11
//在UPDATEDBY字段记录用户12
e.Feature.set_Value(fieldIndex, authenticatedUserName);13
}14
}15
}
void EditorTask1_PostAttributeEdit(object sender, PostAttributeEditEventArgs e)2
{3
//更新失败处理4
if (!e.Successful)5
{6
e.ReturnMessage = e.Exception.Message;7
}8
}
void EditorTask1_PreCommandExecute(object sender, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.PreCommandExecuteEventArgs e)2
{3
//命令的名称4
string commandName = e.ServerAction.ToolbarItemInfo.Name;5
//获取编辑的DataSet名6
string datasetName = e.ServerAction.DataSet.Name;7
//如果命令为DeleteFeature而且是EditParcels.DBO.AddressPoints层就不允许删除8
if (commandName.Equals("DeleteFeature") && datasetName.Equals("EditParcels.DBO.AddressPoints"))9
{10
e.Cancel = true;11
e.ReturnMessage = "Cannot delete features in " + datasetName;12
}13
}
protected void Page_Load(object sender, EventArgs e)2
{3
if (!this.Page.IsPostBack)4
{5
//进行属性过滤6
FilterAttributes();7
}8
}
private void FilterAttributes()2
{3
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality agsLocalMapFunctionality =EditorTask1.Editor.MapFunctionality;4
//查询层id和名称5
string[] layerIDs = null;6
string[] layerNames = null;7
agsLocalMapFunctionality.GetLayers(out layerIDs, out layerNames);8

9
for (int i = 0; i < layerIDs.Length; i++)10
{11
string layerName = layerNames[i];12
int layerID = Int32.Parse(layerIDs[i]);13
if (layerName == "Tentative Assessed Parcels")14
{15
//Tentative Assessed Parcels层所有属性只读16
AttributeDisplayInfo attributeDisplayInfo =new AttributeDisplayInfo(layerID, AttributeDisplayMode.ReadOnly);17
//APN属性例外可以修改18
attributeDisplayInfo.Overrides.Add(new AttributeDisplayOverride("APN", AttributeDisplayMode.Editable));19
//把AttributeDisplayInfo添加到EditorTask120
EditorTask1.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo);21
}22
else if (layerName == "Address Points")23
{24
//Address Points层所有属性可写25
AttributeDisplayInfo attributeDisplayInfo =new AttributeDisplayInfo(layerID, AttributeDisplayMode.Editable);26
//APN属性例外只能只读27
attributeDisplayInfo.Overrides.Add(new AttributeDisplayOverride("APN", AttributeDisplayMode.ReadOnly));28
EditorTask1.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo);29
}30
else if (layerName == "Water Bodies")31
{32
//Water Bodies层所有属性不可见33
AttributeDisplayInfo attributeDisplayInfo =new AttributeDisplayInfo(layerID, AttributeDisplayMode.Hidden);34
//NAME属性例外可以编辑35
attributeDisplayInfo.Overrides.Add(new AttributeDisplayOverride("NAME", AttributeDisplayMode.Editable));36
EditorTask1.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo);37
}38
}39
}


浙公网安备 33010602011771号