年度变更建库软件5.0版本
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.

530 lines
24 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using KGIS.Framework.Views;
using Kingo.Plugin.MapView.Common;
using Kingo.Plugin.MapView.Enum;
using Kingo.Plugin.MapView.Model;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using UIShell.OSGi;
namespace Kingo.Plugin.MapView.Views
{
/// <summary>
/// 工具条-属性查看 的交互逻辑
/// </summary>
public partial class FrmFeatureAttributes : BaseWindow, INotifyPropertyChanged
{
private static IHookHelper m_hookHelper;
private IEngineEditor pEngineEditor = new EngineEditorClass();
private IProofManager ProofMgr = null;
private ISystemCfg SystemCfg = null;
/// <summary>
/// 右键菜单
/// </summary>
private new ContextMenu ContextMenu
{
get;
set;
}
private IMapService _MapService;
public FrmFeatureAttributes(IHookHelper hook, bool IsShowPhotoPanel = false, bool IsShowWYXXPanel = false)
{
m_hookHelper = hook;
_MapService = MapsManager.Instance.MapService;
InitializeComponent();
ProofMgr = BundleRuntime.Instance.GetFirstOrDefaultService<IProofManager>();
SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>();
SystemCfg.Load();
_MapService.OnSelectionChanged += AxMapControl_OnSelectionChanged;
Platform.Instance.NotifyMsgEven2 += NotifyMsg_NotifyMsgEven;
this.Closed += (s, e) =>
{
_MapService.OnSelectionChanged -= AxMapControl_OnSelectionChanged;
Platform.Instance.NotifyMsgEven2 -= NotifyMsg_NotifyMsgEven;
};
List<Linkage> list = new List<Linkage>();
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", TargetPropertyName = "DLMC", TargetPropertyAliasName = "地类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", TargetPropertyName = "TBXHMC", TargetPropertyAliasName = "图斑细化名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", TargetPropertyName = "LYXZFLMC", TargetPropertyAliasName = "利用现状分类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", TargetPropertyName = "ZZSXMC", TargetPropertyAliasName = "种植属性名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDLX", TargetPropertyAliasName = "耕地类型", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDPDJB", TargetPropertyAliasName = "耕地坡度级别", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDDB", TargetPropertyAliasName = "耕地等别", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCDLBM", TargetPropertyAliasName = "扣除地类编码", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCXS", TargetPropertyAliasName = "扣除系数", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCMJ", TargetPropertyAliasName = "扣除面积", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", TargetPropertyName = "QSDWMC", TargetPropertyAliasName = "权属单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", TargetPropertyName = "ZLDWMC", TargetPropertyAliasName = "坐落单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
//list.Add(new Linkage() { SourcePropertyName = "ZZZW", SourcePropertyAliasName = "种植作物", DisplayMemberPath = "DisplayName", ValuePath = "CODE", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
attrEdit.LinkageCfg = list.ToArray();
ContextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
menuItem.Header = "删除";
menuItem.Click += new RoutedEventHandler(DeleteFeature_Click);
ContextMenu.Items.Add(menuItem);
attrEdit.m_hookHelper = m_hookHelper;
}
private void NotifyMsg_NotifyMsgEven(NotifyMsgPackage obj)
{
if (obj.MsgType == "RefreshFeatureAttribute")
{
BindData();
}
}
private void AxMapControl_OnSelectionChanged(object sender, object e)
{
BindData();
}
void BindData()
{
try
{
ClearData();
IMap map = m_hookHelper.FocusMap;
ISelection s = map.FeatureSelection;
IEnumFeatureSetup iEnumFeatureSetup = s as IEnumFeatureSetup;
iEnumFeatureSetup.AllFields = true;
IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup;
pEnumFeature.Reset();
IFeature f = null;
while ((f = pEnumFeature.Next()) != null)
{
IFeatureLayer player = MapsManager.Instance.MapService.GetFeatureLayerByName((f.Class as FeatureClass).BrowseName);
string layerName = player.Name;
TreeViewItem groupItem = null;
foreach (TreeViewItem tvItem in tvDataList.Items)
{
if ((tvItem.Tag as IFeatureClass).AliasName.ToString() == f.Class.AliasName && (tvItem.Tag as FeatureClass).Workspace.PathName == (f.Class as FeatureClass).Workspace.PathName)
{
groupItem = tvItem;
}
}
if (groupItem == null)
{
groupItem = new TreeViewItem();
groupItem.IsExpanded = true;
groupItem.Header = layerName;
groupItem.Tag = f.Class;
tvDataList.Items.Add(groupItem);
}
TreeViewItem item = new TreeViewItem();
item.Header = f.OID;
item.Tag = f;
groupItem.Items.Add(item);
}
if (tvDataList.Items != null && tvDataList.Items.Count > 0)
{
((tvDataList.Items[0] as TreeViewItem).Items[0] as TreeViewItem).IsSelected = true;
}
else
{
attrEdit.ClearData();
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 绑定数据 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 绑定数据 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
public void ClearData()
{
try
{
foreach (TreeViewItem item in tvDataList.Items)
{
if (item.Tag != null && (item.Tag as IFeatureClass) != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject((item.Tag as IFeatureClass));
}
}
tvDataList.Items.Clear();
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 数据置空 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 数据置空 时异常信息结束");
throw ex;
}
}
public void Identify(Dictionary<string, List<IFeature>> pFeatureList)
{
try
{
ClearData();
attrEdit.ClearData();
if (pFeatureList == null || pFeatureList.Count <= 0)
{
return;
}
foreach (var key in pFeatureList.Keys)
{
if (pFeatureList[key].Count == 0)
continue;
TreeViewItem groupItem = null;
if (groupItem == null)
{
groupItem = new TreeViewItem();
groupItem.IsExpanded = true;
groupItem.Header = key;
groupItem.Tag = pFeatureList[key][0].Class;
tvDataList.Items.Add(groupItem);
}
foreach (var f in pFeatureList[key])
{
TreeViewItem item = new TreeViewItem();
item.Header = f.OID;
item.Tag = f;
groupItem.Items.Add(item);
}
}
if (tvDataList.Items != null && tvDataList.Items.Count > 0)
{
((tvDataList.Items[0] as TreeViewItem).Items[0] as TreeViewItem).IsSelected = true;
}
else
{
attrEdit.ClearData();
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 识别 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 识别 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
private void tvDataList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
try
{
if (tvDataList.SelectedItem == null)
return;
TreeViewItem item = tvDataList.SelectedItem as TreeViewItem;
if (item == null || item.Tag == null)
{
return;
}
TreeViewItem par = item.Parent as TreeViewItem;
if (par != null && (par.Tag as IFeatureClass) != null)
{
int OBJECTID = int.Parse(item.Header.ToString());
IFeatureClass pFeatureClass = par.Tag as IFeatureClass;
//获取删除要素
IFeature pFeature = pFeatureClass.GetFeature(OBJECTID);
item.ContextMenu = null;
_MapService.FlashShape((m_hookHelper.Hook as IMapControlDefault), pFeature.Shape, 1, 500);
attrEdit.BindData(pFeature);
//if (ProofMgr != null && SystemCfg != null)
//{
// if (SystemCfg.JZCGCfg == null)
// SystemCfg.Load();
// if (SystemCfg.JZCGCfg != null && SystemCfg.JZCGCfg.LayerInfo != null && SystemCfg.JZCGCfg.LayerInfo.Count != 0)
// {
// string name = (pFeatureClass as IDataset).Name;
// List<SystemConfig.LayerInfo> layerInfoList = SystemCfg.JZCGCfg.LayerInfo.FindAll(x => x.IsCheck == true && x.LayerName == name || x.LayerAliasName == name);
// if (layerInfoList != null && layerInfoList.Count != 0)
// {
// foreach (var wylayer in layerInfoList)
// {
// if (wylayer.RelevantModel == "属性")
// {
// if (!string.IsNullOrWhiteSpace(wylayer.AttributeField))
// {
// int fieldIndex = pFeature.Fields.FindField(wylayer.AttributeField);
// if (fieldIndex < 0)
// continue;
// string jcbh = pFeature.Value[fieldIndex].ToString();
// if (!string.IsNullOrWhiteSpace(jcbh))
// {
// //根据属性字段关联照片
// List<ProofInfo> ProofInfo = ProofMgr.GetProofInfoList<ProofInfo>(jcbh);//("528")
// }
// }
// }
// else if (wylayer.RelevantModel == "图形")
// {
// ////根据图形范围关联照片
// if (!string.IsNullOrWhiteSpace(wylayer.AreaScale))
// {
// List<ProofInfo> ProofInfo = ProofMgr.GetProofInfoList<ProofInfo>(pFeature.ShapeCopy, wylayer.AreaScale);
// //EnvironmentVariables.Instance.cameraPoint.AddCameraPoint(ProofInfo);
// }
// }
// }
// }
// }
//}
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性中 选中点击元素树 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性中 选中点击元素树 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
private void ChangedPointSymbol(string fjmc)
{
EnvironmentVariables.Instance.cameraPoint.ChangedPointSymbol(fjmc);
}
#region IDockPanel接口
public Guid ID
{
get;
set;
}
public DockStyle _DockAreas;
public event EventHandler CloseViewHandler;
public event PropertyChangedEventHandler PropertyChanged;
public bool IsShowInMap { get; set; }
#endregion
/// <summary>
/// 初始化
/// </summary>
/// <param name="Platform"></param>
public void InitPanel()
{
this.Title = "要素属性";
}
void Platform_CloseProjectEvent(object sender, object e)
{
MapsManager.Instance.MapService.ProjectClosed -= Platform_CloseProjectEvent;
}
private void tvDataList_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
try
{
TreeViewItem item = tvDataList.SelectedItem as TreeViewItem;
if (item == null || item.Tag == null)
{
return;
}
TreeViewItem par = item.Parent as TreeViewItem;
if (par != null && (par.Tag as IFeatureClass) != null)
{
int OBJECTID = int.Parse(item.Header.ToString());
IFeatureClass pFeatureClass = par.Tag as IFeatureClass;
//获取删除要素
IFeature pFeature = pFeatureClass.GetFeature(OBJECTID);
attrEdit.BindData(item.Tag);
IFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = new RgbColorClass() { Red = 0, Green = 0, Blue = 255 };
//Env.Instance.KMap.GetMapCtrlDef().FlashShape(f.ShapeCopy, 1, 500);
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性中 元素树操作时鼠标抬起 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性中 元素树操作时鼠标抬起 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
private void tvDataList_MouseDown(object sender, MouseButtonEventArgs e)
{
try
{
if (e.RightButton == MouseButtonState.Pressed)
{
TreeViewItem treeitem = tvDataList.SelectedItem as TreeViewItem;
TreeViewItem treepar = treeitem.Parent as TreeViewItem;
if (treepar != null && (treepar.Tag as IFeatureClass) != null)
{
treeitem.ContextMenu = ContextMenu;
}
}
else
{
TreeViewItem item = tvDataList.SelectedItem as TreeViewItem;
if (item == null || pEngineEditor.EditState != esriEngineEditState.esriEngineStateEditing)
{
return;
}
TreeViewItem par = item.Parent as TreeViewItem;
if (par != null && (par.Tag as IFeatureClass) != null)
{
item.ContextMenu = ContextMenu;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性中 元素树操作时鼠标点击 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性中 元素树操作时鼠标点击 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
void DeleteFeature_Click(object sender, RoutedEventArgs e)
{
IFeatureClass pFeatureclass = null;
IDataset pDataset = null;
IWorkspace pWs = null;
IWorkspaceEdit pWorkspaceEdit = null;
try
{
TreeViewItem item = tvDataList.SelectedItem as TreeViewItem;
if (item == null || item.Tag == null)
{
return;
}
TreeViewItem par = item.Parent as TreeViewItem;
if (par == null && (par.Tag as IFeatureClass) == null)
{
return;
}
pFeatureclass = (par.Tag as IFeatureClass);
string layerName = string.Empty;
if (par.Header != null && !string.IsNullOrWhiteSpace(par.Header.ToString()))
{
layerName = par.Header.ToString();
}
else
{
layerName = pFeatureclass.AliasName;
}
int OBJECTID = int.Parse(item.Header.ToString());
if (pEngineEditor.EditState == esriEngineEditState.esriEngineStateEditing)
{
pEngineEditor.StartOperation();
string messsge = string.Format("是否删除{0}图层OID={1}的数据?删除后数据不可撤回,请谨慎操作!", layerName, OBJECTID);
System.Windows.Forms.DialogResult result = MessageHelper.ShowYesNoAndTips(messsge);
if (result == System.Windows.Forms.DialogResult.OK)
{
//获取删除要素
IFeature pFeature = pFeatureclass.GetFeature(OBJECTID);
pFeature.Delete();
pEngineEditor.StopOperation("DeleteFeature");
//删除节点
int ParentIndex = tvDataList.Items.IndexOf(item.Parent);
(tvDataList.Items[ParentIndex] as TreeViewItem).Items.Remove(item);
}
else
{
return;
}
}
else
{
pDataset = pFeatureclass as IDataset;
pWs = pDataset.Workspace;
pWorkspaceEdit = pWs as IWorkspaceEdit;
string messsge = string.Format("是否删除{0}图层OBJECTID={1}的数据?删除后数据不可撤回,请谨慎操作!", layerName, OBJECTID);
System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(messsge, "删除提示", System.Windows.Forms.MessageBoxButtons.OKCancel);
if (result == System.Windows.Forms.DialogResult.OK)
{
//开始编辑
pWorkspaceEdit.StartEditing(true);
pWorkspaceEdit.StartEditOperation();
//获取删除要素
IFeature pFeature = pFeatureclass.GetFeature(OBJECTID);
pFeature.Delete();
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
//删除节点
int ParentIndex = tvDataList.Items.IndexOf(item.Parent);
(tvDataList.Items[ParentIndex] as TreeViewItem).Items.Remove(item);
}
else
{
return;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性中 删除要素 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性中 删除要素 时异常信息结束");
pEngineEditor.AbortOperation();
MessageHelper.Show("删除要素失败:" + ex.Message);
}
finally
{
if (pFeatureclass != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureclass);
}
if (pDataset != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
}
if (pWs != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pWs);
}
m_hookHelper.ActiveView.Refresh();
}
}
}
}