You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
7.8 KiB
167 lines
7.8 KiB
using System; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Controls; |
|
using System.Runtime.InteropServices; |
|
using ESRI.ArcGIS.Carto; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.Platform.Helper; |
|
using KGIS.Framework.Maps; |
|
using KUI.Windows; |
|
|
|
namespace Kingo.Plugin.MapView.Commands |
|
{ |
|
//[PathAttribute("Kingo.Plugin.MapView.Commands.ClearFeatureCmd")] |
|
public class ClearFeatureCmd : BaseMapMenuCommand |
|
{ |
|
private EngineEditorClass editor = null; |
|
private new IHookHelper m_hookHelper = null; |
|
public override void OnCreate(object hook) |
|
{ |
|
m_hookHelper = new HookHelper(); |
|
m_hookHelper.Hook = hook; |
|
} |
|
public override void OnClick() |
|
{ |
|
IFeatureLayer layer = null; |
|
IFeatureClass featureClass = null; |
|
IWorkspace ws = null; |
|
ITable pTable = null; |
|
try |
|
{ |
|
if (editor == null) |
|
editor = new EngineEditorClass(); |
|
object obj = m_hookHelper.GetCustomProperty(); |
|
if (obj != null && obj is ILayer) |
|
{ |
|
if (obj is IFeatureLayer) |
|
{ |
|
layer = obj as IFeatureLayer; |
|
if (layer != null) |
|
{ |
|
string msg = string.Empty; |
|
IDataset dataset = layer.FeatureClass as IDataset; |
|
string pathName = dataset.Workspace.PathName; |
|
string extension = System.IO.Path.GetExtension(pathName); |
|
string layerName = dataset.Name; |
|
string fullName = System.IO.Path.Combine(pathName, layerName + ".shp"); |
|
|
|
if ((layer.FeatureClass as FeatureClass).Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) |
|
{ |
|
msg = string.Format("当前为网络版图层,是否确定要清除{0}数据?清除后所有用户数据都被清除,且不可恢复,请谨慎操作!", layer.Name); |
|
} |
|
else if (string.IsNullOrWhiteSpace(extension) && System.IO.File.Exists(fullName)) |
|
{ |
|
msg = string.Format("是否确定要清除本地'{0}'文件的数据?清除后数据不可恢复,请谨慎操作!", fullName); |
|
} |
|
else |
|
{ |
|
msg = string.Format("是否确定要清除{0}数据?清除后数据不可恢复,请谨慎操作!", layer.Name); |
|
} |
|
if (MessageHelper.ShowYesNoAndTips(msg) == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
if ((layer.FeatureClass as FeatureClass).Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) |
|
{ |
|
editor.StartEditing((layer.FeatureClass as FeatureClass).Workspace, m_hookHelper.FocusMap); |
|
} |
|
else |
|
{ |
|
if (editor.EditState != esriEngineEditState.esriEngineStateNotEditing) |
|
{ |
|
MessageHelper.ShowTips("请先停止编辑!"); |
|
return; |
|
} |
|
} |
|
this.ShowLoading("正在删除数据,请稍候...", 0, 0); |
|
System.Threading.Thread.Sleep(1000); |
|
featureClass = layer.FeatureClass; |
|
if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation) |
|
{ |
|
ws = (layer as IDataset).Workspace; |
|
ws.ExecuteSQL(string.Format("delete from {0}", (layer.FeatureClass as IDataset).Name)); |
|
} |
|
else |
|
{ |
|
int sjlyIndex = featureClass.FindField("SJLY"); |
|
IQueryFilter queryfilter = new QueryFilterClass(); |
|
if (layer.Name == "国家监测图斑" && sjlyIndex != -1) |
|
{ |
|
queryfilter.WhereClause = string.Format("SJLY='GJJC'"); |
|
} |
|
else if (layer.Name == "自主变更图斑" && sjlyIndex != -1) |
|
{ |
|
queryfilter.WhereClause = string.Format("SJLY='ZZBG'"); |
|
} |
|
else if (layer.Name == "无人机举证图斑" && sjlyIndex != -1) |
|
{ |
|
queryfilter.WhereClause = string.Format("SJLY='3'"); |
|
} |
|
else |
|
{ |
|
queryfilter.WhereClause = string.Format("1=1"); |
|
} |
|
pTable = featureClass as ITable; |
|
pTable.DeleteSearchedRows(queryfilter); |
|
} |
|
|
|
ControlsMapRefreshViewCommandClass refresh = new ControlsMapRefreshViewCommandClass(); |
|
refresh.OnCreate(m_hookHelper.Hook); |
|
refresh.OnClick(); |
|
|
|
if ((layer.FeatureClass as FeatureClass).Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) |
|
{ |
|
editor.StopEditing(true); |
|
} |
|
this.CloseLoading(); |
|
MessageHelper.ShowTips("图层数据清除成功。"); |
|
} |
|
else |
|
{ |
|
return; |
|
} |
|
if (dataset != null) |
|
Marshal.ReleaseComObject(dataset); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
if ((layer.FeatureClass as FeatureClass).Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) |
|
{ |
|
editor.AbortOperation(); |
|
} |
|
MessageHelper.ShowTips("清除图层数据异常:" + ex); |
|
LogAPI.Debug("清除图层数据异常:" + ex); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (layer != null) |
|
Marshal.ReleaseComObject(layer); |
|
if (featureClass != null) |
|
Marshal.ReleaseComObject(featureClass); |
|
if (ws != null) |
|
Marshal.ReleaseComObject(ws); |
|
if (pTable != null) |
|
Marshal.ReleaseComObject(pTable); |
|
} |
|
} |
|
public override bool Enabled |
|
{ |
|
get |
|
{ |
|
return base.Enabled; |
|
} |
|
} |
|
public new string Caption |
|
{ |
|
get |
|
{ |
|
return "清除图层数据"; |
|
} |
|
} |
|
} |
|
}
|
|
|