IFReUsingCommand.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.DataEditUI
  7. // 类 名: IFReUsingCommand
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2018/06/28
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using Tofly.Core.Context.Support;
  17. using Tofly.Core.ServiceLocator;
  18. using Tofly.CoreUI.Plot;
  19. using Tofly.CoreUI.Control;
  20. using Tofly.CoreUI.Message;
  21. using Tofly.DataEdit.Util;
  22. using Tofly.GISUI.Controls;
  23. using Tofly.GIS.Carto;
  24. using Tofly.GIS.SpatialDatabase;
  25. using Tofly.GIS.Util;
  26. using Tofly.GISUI.Content;
  27. using Tofly.GISUI.Plugin;
  28. using Tofly.GISUI.Utils;
  29. namespace Tofly.DataEditUI
  30. {
  31. /// <summary>
  32. /// 设备重新启用命令
  33. /// </summary>
  34. [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "设备启用", Describe = "设备启用", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
  35. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.IFReUsingCommand")]
  36. public class IFReUsingCommand : GISPluginButtonBase
  37. {
  38. /// <summary>
  39. ///
  40. /// </summary>
  41. private IMap _cmap;
  42. /// <summary>
  43. /// 当前选择可编辑要素字典
  44. /// </summary>
  45. private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
  46. /// <summary>
  47. /// 可编辑图层集合
  48. /// </summary>
  49. private List<IFeatureLayer> _lstEditableLayer = new List<IFeatureLayer>();
  50. /// <summary>
  51. ///
  52. /// </summary>
  53. private IGeoDataSourceHelper _geoDSHelper;
  54. public IFReUsingCommand()
  55. {
  56. this.Enable = false;
  57. }
  58. public override void Create(IPluginContent content)
  59. {
  60. base.Create(content);
  61. this.content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  62. }
  63. public override void Click()
  64. {
  65. try
  66. {
  67. if (this._cmap.SelectionCount == 0)
  68. {
  69. return;
  70. }
  71. if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
  72. {
  73. throw new System.Exception("请选择需要进行更换的设备要素。");
  74. }
  75. var __kvSelLayerFeature = this._dicEditableFeatures.ElementAt(0);
  76. IFeature __ftrStopUsing = __kvSelLayerFeature.Value[0];
  77. IFeatureWorkspace __fwsEditing = __ftrStopUsing.FeatureClass.Workspace;
  78. __fwsEditing.StartEditOperation(); //建立操作记录(以供redo/undo)
  79. try
  80. {
  81. __ftrStopUsing.SetValue(AppConfig.g_FieldIFStatus, "");
  82. __ftrStopUsing.SetValue(AppConfig.g_FieldIFArchivalState, "");
  83. __ftrStopUsing.FeatureClass.Save(__ftrStopUsing); //保存要素处理
  84. __fwsEditing.StopEditOperation();
  85. EditorSurroundings.WriteEditLog("修改要素", string.Format("修改要素 1条({0} {1})", __ftrStopUsing.FeatureClass.AliasName, __ftrStopUsing.OID)); //记录编辑日志
  86. //SystemLogHelper.WriteOperationLog(string.Format("修改要素(属性)【{0}】", __strPropertyChangedJson)); //记录属性修改操作日志
  87. //this.CMap.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeography, null, this.CMap.Extent);
  88. Dictionary<int, IFeatureWorkspace> __dicEditingWorkkspace = new Dictionary<int, IFeatureWorkspace>();
  89. __dicEditingWorkkspace.Add(1, __fwsEditing);
  90. EditorSurroundings.UpdateEditOperation(this.content, __dicEditingWorkkspace); //刷新编辑操作队列
  91. MessageManager.Show("成功完成设备启用操作。", "设备启用");
  92. }
  93. catch
  94. {
  95. __fwsEditing.AbortEditOperation();
  96. throw;
  97. }
  98. finally
  99. {
  100. __fwsEditing = null;
  101. }
  102. }
  103. catch (System.Exception ex)
  104. {
  105. MessageManager.Show(ex.Message, "设备启用");
  106. }
  107. }
  108. protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
  109. {
  110. if (key.Equals(ServiceLocatorKeys.IsMapEdit))
  111. {
  112. //this.Enable = content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit);
  113. this.ActiveViewContent_ActiveViewSelectionChanged(null);
  114. }
  115. else if (key.Equals(ServiceLocatorKeys.DocumentContent))
  116. {
  117. this._cmap = (this.content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl).Map;
  118. var documentcontent = this.content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
  119. documentcontent.ActiveViewContent.ActiveViewSelectionChanged -= ActiveViewContent_ActiveViewSelectionChanged;
  120. documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
  121. }
  122. }
  123. /// <summary>
  124. ///
  125. /// </summary>
  126. /// <param name="e"></param>
  127. protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
  128. {
  129. this.Enable = false;
  130. this._dicEditableFeatures = null;
  131. if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
  132. {
  133. if (this._cmap.SelectionCount > 0)
  134. {
  135. if (this._lstEditableLayer.Count == 0)
  136. {
  137. this._lstEditableLayer.AddRange(this._cmap.GetFeatureLayersByMap());
  138. this._lstEditableLayer.RemoveAll(clayer => clayer.FeatureClass == null || clayer.FeatureClass.Workspace.IsBeingEdited() == false); //移除不可编辑图层
  139. this._lstEditableLayer.RemoveAll(clayer => this._geoDSHelper.IsInterfaceFeatureLayer(clayer.FeatureClass.ClassName) == false); //移除非接口设备图层
  140. }
  141. List<IFeatureLayer> __lstEditableLayer = this._lstEditableLayer.Where(flayer => flayer.Visible).ToList(); //筛选出可见要素图层类
  142. this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, __lstEditableLayer, true);
  143. int __iFeatureCount = this._dicEditableFeatures.Sum(kvLayerFeature => kvLayerFeature.Value.Count);
  144. string __strArchivalState = (__iFeatureCount == 0 ? "" : this._dicEditableFeatures.ElementAt(0).Value[0].GetValue<string>(AppConfig.g_FieldIFArchivalState));
  145. string __strIFStatus = (__iFeatureCount == 0 ? "" : this._dicEditableFeatures.ElementAt(0).Value[0].GetValue<string>(AppConfig.g_FieldIFStatus));
  146. this.Enable = (__iFeatureCount == 1 && __strArchivalState == "已存档" && __strIFStatus == "停用"); //分离出可编辑要素集合
  147. __lstEditableLayer.Clear();
  148. }
  149. }
  150. }
  151. }
  152. }