目的:
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事件,并且在这个事件中添加如下代码:
1
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
}
7.上面代码为EditorTask1添加了3个事件,需要为这3个事件添加方法代码。
EditorTask1_PreAttributeEdit方法(当进行数据编辑时记录编辑用户名)代码如下:
1
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
}
8.EditorTask1_PostAttributeEdit方法(处理编辑失败)代码如下:
1
void EditorTask1_PostAttributeEdit(object sender, PostAttributeEditEventArgs e)
2
{
3
//更新失败处理
4
if (!e.Successful)
5
{
6
e.ReturnMessage = e.Exception.Message;
7
}
8
}
9.EditorTask1_PreCommandExecute方法(设置AddressPoints层的数据不允许删除)代码如下:
1
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
}
10.接下实现属性编辑的控制,在Page_Load事件中添加如下代码:
1
protected void Page_Load(object sender, EventArgs e)
2
{
3
if (!this.Page.IsPostBack)
4
{
5
//进行属性过滤
6
FilterAttributes();
7
}
8
}
11.FilterAttributes()方法代码和说明如下:
1
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添加到EditorTask1
20
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
}
12.这样就实现是属性编辑的过滤,运行测试,进行AddressPoints层的数据删除测试,进行Tentative Assessed Parcels、Address Points、Water Bodies三个层的属性编辑测试。本篇就写到这里,下一篇继续讲对EditorTask控件进行个性化的功能扩展。