123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
-
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using Tofly.Core.Context.Support;
- using Tofly.Core.Context;
- using Tofly.Core.ServiceLocator;
- using Tofly.CoreUI.Plot;
- using Tofly.CoreUI.Control;
- using Tofly.CoreUI.Message;
- using Tofly.CoreUI.Win.Form.Forms;
- using Tofly.CoreUI.Utils;
- using Tofly.Data.Metadata;
- using Tofly.GIS.Display;
- using Tofly.GISUI.Content;
- using Tofly.GISUI.Controls;
- using Tofly.GIS.Geometry;
- using Tofly.GIS.Carto;
- using Tofly.GIS.SpatialDatabase;
- using Tofly.GIS.Util;
- using Tofly.DataEditUI.Properties;
- using Tofly.GISUI.Plugin;
- using Tofly.Data.General;
- using Tofly.DataEdit.Util;
- 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.FeatureClearCommand")]
- public class FeatureClearCommand : GISPluginButtonBase
- {
-
-
-
- private IMap _cmap;
-
-
-
- private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
-
-
-
- private List<IFeatureLayer> _lstEditableGWLayer = new List<IFeatureLayer>();
- public FeatureClearCommand()
- {
- 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("无有效可编辑要素.");
- }
- Dictionary<IFeatureLayer, List<IFeature>> __dicSelFeaturesByLayer = new Dictionary<IFeatureLayer, List<IFeature>>();
- #region --------- 获取待清除要素集合 ---------
- if (this._dicEditableFeatures.Count > 1 || this._dicEditableFeatures.ElementAt(0).Value.Count > 1)
- {
-
- ISelectMultiEditFeature __frmSelMultiEditFeature = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormSelectMultiEditFeature") as ISelectMultiEditFeature;
- __frmSelMultiEditFeature.CMap = this._cmap;
- __frmSelMultiEditFeature.LoadSelectableFeatures(this._dicEditableFeatures);
- if (__frmSelMultiEditFeature.ShowDialog(this.content.PluginMainForm) == DialogResult.OK)
- {
- __dicSelFeaturesByLayer = __frmSelMultiEditFeature.SelectedLayerFeatues;
- System.Windows.Forms.Application.DoEvents();
- }
- __frmSelMultiEditFeature.Dispose();
- __frmSelMultiEditFeature = null;
- }
- else
- {
- __dicSelFeaturesByLayer.Add(this._dicEditableFeatures.ElementAt(0).Key, this._dicEditableFeatures.ElementAt(0).Value);
- }
- #endregion
- if (__dicSelFeaturesByLayer.Count > 0 && MessageManager.Show("确定清除设备要素数据?", "要素清除", MessageButton.YesNo, MessageType.Question) == MessageResult.Yes)
- {
-
- FormProgress __frmProgress = new FormProgress(tfProgressType.ProgressProcess, true)
- {
- StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
- ProgressMaxValue = __dicSelFeaturesByLayer.Sum(kvClassFeatures => kvClassFeatures.Value.Count)
- };
- __frmProgress.Show(this.content.PluginMainForm);
- System.Windows.Forms.Application.DoEvents();
- List<string> __lstExcludeFields = new List<string>();
- List<string> __lstMustClearedField = new List<string>() { "SID" };
- List<Field> __lstClearedProperty = new List<Field>();
- int __iFeature = 0;
- IFeatureWorkspace __fwsEditing = __dicSelFeaturesByLayer.ElementAt(0).Key.FeatureClass.Workspace;
- __fwsEditing.StartEditOperation();
- try
- {
- #region --------- 遍历进行要素清除操作 ---------
- __lstExcludeFields.AddRange(RowBaseEx.ExcludeClearedFields());
- __lstExcludeFields.AddRange(RowBaseEx.ReadOnlyFields());
- __lstExcludeFields.RemoveAll(excField => __lstMustClearedField.Exists(mcField => excField.Equals(mcField, StringComparison.OrdinalIgnoreCase)));
- foreach (var __kvLayerFeatures in __dicSelFeaturesByLayer)
- {
- __lstClearedProperty.AddRange(__kvLayerFeatures.Key.FeatureClass.Fields.Where(fieldItem => fieldItem.IsGISField == false && fieldItem.IsKey == false && fieldItem.AllowNull));
- foreach (string __strExcField in __lstExcludeFields)
- {
- __lstClearedProperty.RemoveAll(cproperty => cproperty.FieldName.Equals(__strExcField, StringComparison.OrdinalIgnoreCase));
- }
- foreach (var __ftrCleared in __kvLayerFeatures.Value)
- {
- __iFeature += 1;
- __frmProgress.UpdateTitle(string.Format("正在清除第 {0} 个要素.", __iFeature));
- System.Windows.Forms.Application.DoEvents();
- foreach (var __cpField in __lstClearedProperty)
- {
- __ftrCleared.SetValue(__cpField.FieldName, DBNull.Value);
- }
- }
- __kvLayerFeatures.Key.FeatureClass.Save(__kvLayerFeatures.Value.Select(ftr => ftr as IRow).ToList());
- }
- #endregion
- __fwsEditing.StopEditOperation();
- Dictionary<int, IFeatureWorkspace> __dicEditingWorkkspace = new Dictionary<int, IFeatureWorkspace>();
- __dicEditingWorkkspace.Add(1, __fwsEditing);
- EditorSurroundings.UpdateEditOperation(this.content, __dicEditingWorkkspace);
- __frmProgress.Reset();
- MessageManager.Show(MessageType.Information, "成功完成选择要素的数据清空操作.", "要素清空");
- this._cmap.PartialRefresh(ViewDrawPhase.ViewGeography, null, this._cmap.Extent);
- }
- catch
- {
- __fwsEditing.AbortEditOperation();
- throw;
- }
- finally
- {
-
- __frmProgress.Dispose();
- __frmProgress = null;
- __lstExcludeFields.Clear();
- __lstMustClearedField.Clear();
- __lstClearedProperty.Clear();
- }
- }
- }
- catch(System.Exception ex)
- {
- MessageManager.Show("清除失败: " + ex.Message, "要素清空");
- }
- }
- protected 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 = content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
- documentcontent.ActiveViewContent.ActiveViewSelectionChanged -= ActiveViewContent_ActiveViewSelectionChanged;
- documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
- }
- }
- protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
- {
- try
- {
- this.Enable = false;
- this._dicEditableFeatures = null;
- if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
- {
- if (this._cmap.SelectionCount > 0)
- {
- if (this._lstEditableGWLayer.Count == 0)
- {
- this._lstEditableGWLayer.AddRange(FeatureLayerHelper.GetFeatureLayersByDataset(this._cmap, AppConfig.GWDatasetName));
- this._lstEditableGWLayer.RemoveAll(flyrItem => flyrItem.FeatureClass.Workspace.IsBeingEdited() == false);
- }
- this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, this._lstEditableGWLayer, true);
- this.Enable = (this._dicEditableFeatures.Count > 0);
- }
- }
- }
- catch
- {
- this.Enable = false;
- }
- }
- }
- }
|