123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
-
- 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.IFReUsingCommand")]
- public class IFReUsingCommand : GISPluginButtonBase
- {
-
-
-
- private IMap _cmap;
-
-
-
- private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
-
-
-
- private List<IFeatureLayer> _lstEditableLayer = new List<IFeatureLayer>();
-
-
-
- private IGeoDataSourceHelper _geoDSHelper;
- public IFReUsingCommand()
- {
- 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._cmap.SelectionCount == 0)
- {
- return;
- }
- if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
- {
- throw new System.Exception("请选择需要进行更换的设备要素。");
- }
- var __kvSelLayerFeature = this._dicEditableFeatures.ElementAt(0);
- IFeature __ftrStopUsing = __kvSelLayerFeature.Value[0];
- IFeatureWorkspace __fwsEditing = __ftrStopUsing.FeatureClass.Workspace;
- __fwsEditing.StartEditOperation();
- try
- {
- __ftrStopUsing.SetValue(AppConfig.g_FieldIFStatus, "");
- __ftrStopUsing.SetValue(AppConfig.g_FieldIFArchivalState, "");
- __ftrStopUsing.FeatureClass.Save(__ftrStopUsing);
- __fwsEditing.StopEditOperation();
- EditorSurroundings.WriteEditLog("修改要素", string.Format("修改要素 1条({0} {1})", __ftrStopUsing.FeatureClass.AliasName, __ftrStopUsing.OID));
-
-
- Dictionary<int, IFeatureWorkspace> __dicEditingWorkkspace = new Dictionary<int, IFeatureWorkspace>();
- __dicEditingWorkkspace.Add(1, __fwsEditing);
- EditorSurroundings.UpdateEditOperation(this.content, __dicEditingWorkkspace);
- MessageManager.Show("成功完成设备启用操作。", "设备启用");
- }
- catch
- {
- __fwsEditing.AbortEditOperation();
- throw;
- }
- finally
- {
- __fwsEditing = null;
- }
- }
- 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));
- string __strIFStatus = (__iFeatureCount == 0 ? "" : this._dicEditableFeatures.ElementAt(0).Value[0].GetValue<string>(AppConfig.g_FieldIFStatus));
- this.Enable = (__iFeatureCount == 1 && __strArchivalState == "已存档" && __strIFStatus == "停用");
- __lstEditableLayer.Clear();
- }
- }
- }
- }
- }
|