123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
-
- using System.Collections.Generic;
- using System.Linq;
- using Tofly.Core.Context.Support;
- using Tofly.Core.ServiceLocator;
- using Tofly.CoreUI.Plot;
- using Tofly.CoreUI.Control;
- using Tofly.CoreUI.Message;
- using Tofly.DataEdit.Util;
- using Tofly.GISUI.Controls;
- using Tofly.GIS.Carto;
- using Tofly.GIS.SpatialDatabase;
- using Tofly.GIS.Util;
- using Tofly.GISUI.Content;
- using Tofly.GISUI.Plugin;
- using Tofly.GISUI.Utils;
- namespace Tofly.DataEditUI
- {
-
-
-
- [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "设备更换", Describe = "设备更换", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
- [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.IFReplaceCommand")]
- public class IFReplaceCommand : GISPluginButtonBase
- {
-
-
-
- private IMap _cmap;
-
-
-
- private IForm _frmIFReplace;
-
-
-
- private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
-
-
-
- private List<IFeatureLayer> _lstEditableLayer = new List<IFeatureLayer>();
-
-
-
- private IGeoDataSourceHelper _geoDSHelper;
- public IFReplaceCommand()
- {
- this.Enable = false;
- }
- public override void Create(IPluginContent content)
- {
- base.Create(content);
- this.content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
- }
- public override void Click()
- {
- try
- {
- if (this._frmIFReplace != null && this._frmIFReplace.Visible)
- {
- return;
- }
- if (this._cmap.SelectionCount == 0)
- {
- return;
- }
- if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
- {
- throw new System.Exception("请选择需要进行更换的设备要素。");
- }
- var __kvSelLayerFeature = this._dicEditableFeatures.ElementAt(0);
- this._frmIFReplace = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormInterfaceFeatureReplace", new object[] { this.content, __kvSelLayerFeature.Value[0] }) as IForm;
- this._frmIFReplace.FormStartPosition = FormStartPositionType.CenterScreen;
- this._frmIFReplace.FormClosedEvent += (s) =>
- {
- System.Windows.Forms.Form __frmBase = this._frmIFReplace as System.Windows.Forms.Form;
- if (__frmBase != null && __frmBase.IsDisposed == false)
- {
- __frmBase.Dispose();
- }
- this._frmIFReplace = null;
- };
- this._frmIFReplace.ShowDialog(this.content.PluginMainForm);
- }
- catch (System.Exception ex)
- {
- MessageManager.Show("打开失败: " + ex.Message, "设备更换");
- }
- }
- protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
- {
- if (key.Equals(ServiceLocatorKeys.IsMapEdit))
- {
-
- this.ActiveViewContent_ActiveViewSelectionChanged(null);
- }
- else if (key.Equals(ServiceLocatorKeys.DocumentContent))
- {
- this._cmap = (this.content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl).Map;
- var documentcontent = this.content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
- documentcontent.ActiveViewContent.ActiveViewSelectionChanged -= ActiveViewContent_ActiveViewSelectionChanged;
- documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
- }
- }
-
-
-
-
- protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
- {
- this.Enable = false;
- this._dicEditableFeatures = null;
- if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
- {
- if (this._cmap.SelectionCount > 0)
- {
- if (this._lstEditableLayer.Count == 0)
- {
- this._lstEditableLayer.AddRange(this._cmap.GetFeatureLayersByMap());
- this._lstEditableLayer.RemoveAll(clayer => clayer.FeatureClass == null || clayer.FeatureClass.Workspace.IsBeingEdited() == false);
- this._lstEditableLayer.RemoveAll(clayer => this._geoDSHelper.IsInterfaceFeatureLayer(clayer.FeatureClass.ClassName) == false);
- }
- List<IFeatureLayer> __lstEditableLayer = this._lstEditableLayer.Where(flayer => flayer.Visible).ToList();
- this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, __lstEditableLayer, true);
- int __iFeatureCount = this._dicEditableFeatures.Sum(kvLayerFeature => kvLayerFeature.Value.Count);
- string __strArchivalState = (__iFeatureCount == 0 ? "" : this._dicEditableFeatures.ElementAt(0).Value[0].GetValue<string>(AppConfig.g_FieldIFArchivalState));
- this.Enable = (__iFeatureCount == 1 && __strArchivalState == "已存档");
- __lstEditableLayer.Clear();
- }
- }
- }
- }
- }
|