using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geodatabase; using KGIS.Framework.Maps; using KGIS.Framework.Utils; using KGIS.Framework.Views; using Kingo.PluginServiceInterface; using System; using System.Collections.Generic; using System.Linq; using UIShell.OSGi; namespace Kingo.Plugin.NYYP.Commands { /// /// 图斑变更-功能 /// public class CmdTBBG : BaseMapMenuCommand { IEngineEditor m_pEditor; IAttrTableHelper uCAttribute_Form = null; IDockPanel2 _Panel = null; private IProofManager ProofMgr = null; List _Elements = null; IElementInfo _TBBG = null; IDockViewService _DockViewService = null; IFeatureLayer featureLayer = null; public override void OnClick() { try { if (ProofMgr == null) ProofMgr = BundleRuntime.Instance.GetFirstOrDefaultService(); if (_Elements == null) _Elements = BundleRuntime.Instance.GetService(); if (_Elements == null) return; if (_TBBG == null) _TBBG = _Elements.FirstOrDefault(f => f.Title == "图斑变更组件"); if (_DockViewService == null) _DockViewService = BundleRuntime.Instance.GetFirstOrDefaultService(); if (_DockViewService == null) return; _DockViewService.IsShowSaveButton = true; _DockViewService.Orientation = EnumOrientation.Vertical; _Panel = _DockViewService.InitView(); if (_TBBG != null) { _TBBG.AllowEdit = true; _TBBG.IsShow = true; _TBBG.BindData(null); _DockViewService.AddElement(_TBBG); } _Panel.Title = "图斑变更"; _Panel.DefaultArea = DockStyle.DockRight; _Panel.DockWidth = 600; _Panel.ShowCloseButton = true; _Panel.CloseViewHandler += (s, e) => { _TBBG.IsShow = false; }; _Panel.ShowPanel(); if (MapsManager.Instance.MapService != null) { MapsManager.Instance.MapService.ProjectClosed -= MapService_ProjectClosed; MapsManager.Instance.MapService.ProjectClosed += MapService_ProjectClosed; } //打开属性检测图斑属性表 uCAttribute_Form = BundleRuntime.Instance.GetFirstOrDefaultService(); if (uCAttribute_Form != null) { _DockViewService.Callback = uCAttribute_Form.SelectRowPrevOrNextRow; List _ViewParam = new List(); var para = new AttributeViewParameter() { LableInfo = "显示监测图斑", Type = "LabCheckBar", RadioGroupName = "ShowType", Data = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB"), Filterriteria = " AND SFJCTB <> '' " }; bool IsLoadComplete = true; para.Callback += (p) => { if (uCAttribute_Form.CurrentView != null && IsLoadComplete) { IsLoadComplete = false; uCAttribute_Form.CurrentView.LoadData(p.Data, null); } if (_TBBG != null) { _TBBG.ShowIndex = 1; } IsLoadComplete = true; }; _ViewParam.Add(para); var para2 = new AttributeViewParameter() { LableInfo = "显示变更图斑", Type = "LabCheckBar", RadioGroupName = "ShowType", Data = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"), IsChecked = true, Filterriteria = " AND SFJCTB <> '' ", }; para2.Callback += (p) => { if (uCAttribute_Form.CurrentView != null && IsLoadComplete) { IsLoadComplete = false; uCAttribute_Form.CurrentView.LoadData(p.Data, null); _Panel = _DockViewService.InitView(); if (_TBBG != null) { _TBBG.IsShow = true; _TBBG.AllowEdit = true; _TBBG.ShowIndex = 0; _DockViewService.AddElement(_TBBG); } _Panel.Title = "图斑变更"; _Panel.DefaultArea = DockStyle.DockRight; _Panel.DockWidth = 600; _Panel.ShowCloseButton = true; _Panel.CloseViewHandler += (s, e) => { _TBBG.IsShow = false; }; _Panel.ShowPanel(); } IsLoadComplete = true; }; _ViewParam.Add(para2); uCAttribute_Form.InitView("图斑变更", m_hookHelper, _ViewParam); featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); if (uCAttribute_Form.CurrentView != null) { uCAttribute_Form.CurrentView.LoadData(featureLayer, null); } } } catch (Exception ex) { LogAPI.Debug("检测图斑初始化失败:" + ex.Message); } } private void MapService_ProjectClosed(object sender, EventArgs e) { if (_Panel != null) { _Panel.ClosePanel(); _Panel = null; } } public override void OnCreate(object Hook) { try { if (m_hookHelper == null) { m_hookHelper = new HookHelperClass(); } m_hookHelper.Hook = Hook; m_pEditor = new EngineEditorClass(); } catch (Exception ex) { LogAPI.Debug("初始化 打开属性表 命令时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("初始化 打开属性表 命令时异常信息结束"); } } public override bool Enabled => JudgeIsHaveTargetPath(); private bool JudgeIsHaveTargetPath() { try { if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo prj)) { return false; } ILayer pLayer = (m_pEditor as EngineEditorClass).TargetLayer; if (pLayer == null) return false; if (pLayer is IFeatureLayer) { if (((pLayer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName != "DLTBBG") return false; } return !string.IsNullOrWhiteSpace(prj.BGDatabase) && m_pEditor.EditState == esriEngineEditState.esriEngineStateEditing; } catch (Exception ex) { LogAPI.Debug("判定 检测数据加载 按钮是否有效时失败,异常原因: " + ex + " ; "); return false; } } } }