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 { /// /// 工具条-属性编辑 的交互逻辑 /// public partial class FrmFeatureAttribute : UserControl, IDockPanel2, INotifyPropertyChanged { private static IHookHelper m_hookHelper; private IEngineEditor pEngineEditor = new EngineEditorClass(); private IProofManager ProofMgr = null; private ISystemCfg SystemCfg = null; /// /// 右键菜单 /// private new ContextMenu ContextMenu { get; set; } private IMapService _MapService; public FrmFeatureAttribute(IHookHelper hook, bool IsShowPhotoPanel = false, bool IsShowWYXXPanel = false) { m_hookHelper = hook; _MapService = MapsManager.Instance.MapService; InitializeComponent(); ProofMgr = BundleRuntime.Instance.GetFirstOrDefaultService(); SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService(); SystemCfg.Load(); InitPanel(); //ucImgXZZP.ChangedPointSymbol = ChangedPointSymbol; _MapService.OnSelectionChanged += AxMapControl_OnSelectionChanged; //Env.Instance.Platfrom.NotifyMsg.NotifyMsgEven += NotifyMsg_NotifyMsgEven; Platform.Instance.NotifyMsgEven2 += NotifyMsg_NotifyMsgEven; List list = new List(); 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(); } else if (obj.MsgType == "SetViewInfo") { if (obj.Content != null) { //rowImg.Height = new GridLength(220); //rowWYXX.Height = new GridLength(150); } } } private void FrmFeatureAttribute_LostFocus(object sender, RoutedEventArgs e) { //Env.Instance.UpdateToolBarShortcutState(true); } private void FrmFeatureAttribute_GotFocus(object sender, RoutedEventArgs e) { //Env.Instance.UpdateToolBarShortcutState(false); } private void AxMapControl_OnSelectionChanged(object sender, object e) { //if (this.Platform != null) //{ // if (!this.Platform.IsDockPanelVisble(this)) // { // return; // } // BindData(); //} 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> pFeatureList) { try { //Env.Instance.KMap.OnSelectionChanged -= AxMapControl_OnSelectionChanged; //tvDataList.Items.Clear(); 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]) { //foreach (TreeViewItem tvItem in tvDataList.Items) //{ // if (tvItem.Header.ToString() == key && (tvItem.Tag as FeatureClass).Workspace.PathName == (f.Class as FeatureClass).Workspace.PathName) // { // groupItem = tvItem; // } //} 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("要素属性:" + ex); LogAPI.Debug("要素属性 识别 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("要素属性 识别 时异常信息结束"); MessageHelper.ShowError(ex.Message); } } private void tvDataList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs 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 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 = ProofMgr.GetProofInfoList(jcbh);//("528") // //ucImgXZZP.InitData(ProofInfo, false); // //EnvironmentVariables.Instance.cameraPoint.AddCameraPoint(ProofInfo); // } // } // } // else if (wylayer.RelevantModel == "图形") // { // ////根据图形范围关联照片 // if (!string.IsNullOrWhiteSpace(wylayer.AreaScale)) // { // List ProofInfo = ProofMgr.GetProofInfoList(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 DockStyle DockAreas { get; set; } /// /// 浮动显示时默认窗体大小 /// public System.Drawing.Size FloatSize { get; set; } public int DockWidth { get; set; } public int DockHeight { get; set; } /// /// 默认显示区域 /// public DockStyle DefaultArea { get; set; } /// /// 是否显示关闭按钮 /// public bool ShowCloseButton { get; set; } /// /// 是否显示自动隐藏按钮 /// public bool ShowAutoHideButton { get; set; } /// /// 标题 /// public string Title { get; set; } public bool IsShowInMap { get; set; } #endregion /// /// 初始化 /// /// public void InitPanel() { this.DockAreas = DockStyle.Float; //Common.Interface.DockStyle.DockRight | Common.Interface.DockStyle.Float; this.FloatSize = new System.Drawing.Size(400, 500); this.DefaultArea = DockStyle.DockRight;// Common.Interface.DockStyle.DockRight; this.DockWidth = 300; this.ShowCloseButton = true; this.ShowAutoHideButton = true; this.Title = "属性编辑"; ProjectInfo prjInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; } void Platform_CloseProjectEvent(object sender, object e) { MapsManager.Instance.MapService.ProjectClosed -= Platform_CloseProjectEvent; this.ClosePanel(); } 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); //IFeature f = item.Tag as IFeature; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = new ESRI.ArcGIS.Display.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; } } //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); // pFeature.Delete(); // pEngineEditor.StopOperation("DeleteFeature"); // //删除节点 // int ParentIndex = tvDataList.Items.IndexOf(item.Parent); // (tvDataList.Items[ParentIndex] as TreeViewItem).Items.Remove(item); // ////实时同步属性表 // //var _platfrom = Env.Instance.Platfrom; // //_platfrom.RefreshPanel(new NotifyMsgPackage() // //{ // // MsgType = "DeleteFeatureRefresh", // // Content = new AttrNotifyMsgModel() // // { // // Key = "", // // Oid = -1, // // Value = "", // // Index = -1 // // } // //}); //} } catch (Exception ex) { LogAPI.Debug("要素属性中 删除要素 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("要素属性中 删除要素 时异常信息结束"); pEngineEditor.AbortOperation(); MessageHelper.Show("删除要素失败:" + ex.Message); } finally { //Env.Instance.KMap.GetMapCtrlDef().ActiveView.Refresh(); 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(); } } public void ShowPanel() { Platform.Instance.OpenView(this, false); if (MapsManager.Instance.MapService != null) { MapsManager.Instance.MapService.ProjectClosed += Platform_CloseProjectEvent; } } public void ClosePanel() { Platform.Instance.CloseView(this); } public void ClosePanelInvoke() { _MapService.OnSelectionChanged -= AxMapControl_OnSelectionChanged; CloseViewHandler?.Invoke(this, null); } } }