年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
14 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Kingo.Plugin.NYYP.View
{
/// <summary>
/// UCNYYP.xaml 的交互逻辑
/// </summary>
public partial class UCNYYP : UserControl, IElementInfo
{
List<IElementInfo> _Elements = null;
IElementInfo _FeatureInfo = null;
IElementInfo _NYYPInfo = null;
IFeatureLayer _curFeatureLayer;
IFeatureLayer _curJCTBFeatureLayer;
public UCNYYP()
{
InitializeComponent();
Title = "图斑预判组件";
DockWidth = 550;
this.Loaded += (s, e) =>
{
MapsManager.Instance.MapService.OnSelectionChanged -= MapService_OnSelectionChanged;
MapsManager.Instance.MapService.OnSelectionChanged += MapService_OnSelectionChanged;
_curJCTBFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB");
};
}
private int CurShowJCOID = 0;
private void MapService_OnSelectionChanged(object sender, EventArgs e)
{
try
{
if (!IsShow)
{
MapsManager.Instance.MapService.OnSelectionChanged -= MapService_OnSelectionChanged;
return;
}//当前窗口关闭时,注销触发事件
ISelectionSet pJCSelectionSetes = (_curJCTBFeatureLayer as IFeatureSelection).SelectionSet;//获取图层要素已被选择的
int oid = -1;
if (pJCSelectionSetes != null && pJCSelectionSetes.Count != 0)
{
IEnumIDs enumIDs = pJCSelectionSetes.IDs;
enumIDs.Reset();
oid = -1;
while ((oid = enumIDs.Next()) >= 0)
{
if (CurShowJCOID == oid) break;//不重新绑定当前已选择行
IFeature f = _curJCTBFeatureLayer.FeatureClass.GetFeature(oid);
BindData(f);
Marshal.ReleaseComObject(f);
Marshal.ReleaseComObject(enumIDs);
CurShowJCOID = oid;
break;
}
}
Marshal.ReleaseComObject(pJCSelectionSetes);
if (oid == -1)
{
BindData(null);
return;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
public void BindData(object obj)
{
try
{
if (_curFeatureLayer == null)
_curFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
Init();
tvDataList.Items.Clear();
if (obj is IFeature)
{
IFeature tempFeature = obj as IFeature;
string mFcName = (tempFeature.Class as FeatureClass).BrowseName;
if (mFcName == "JCTB")
{
_FeatureInfo?.BindData(obj);
_NYYPInfo?.BindData(obj);
int SJLYIndex = _curJCTBFeatureLayer.FeatureClass.FindField("SJLY");
ListBoxItem item = new ListBoxItem
{
Margin = new Thickness(32, 0, 0, 0),
Tag = obj
};
if ((obj as IFeature).Value[SJLYIndex].ToString().Trim() == "ZZBG")
item.Content = "自主变更图斑:" + (obj as IFeature).OID;
else
item.Content = "国家监测图斑:" + (obj as IFeature).OID;
tvDataList.Items.Add(item);
if (tvDataList.Items.Count > 0)
{
(tvDataList.Items[0] as ListBoxItem).IsSelected = true;
}
//GetBGTBForJCTB(tempFeature);
if (tvDataList.SelectedItem is ListBoxItem itemSe) itemSe.FontStyle = FontStyles.Oblique;
}
else if (mFcName == "DLTBBG")
{
_FeatureInfo?.BindData(obj);
_NYYPInfo?.BindData(obj);
}
return;
}
_FeatureInfo?.BindData(obj);
_NYYPInfo?.BindData(obj);
}
catch (Exception ex)
{
LogAPI.Debug("加载图斑变更详情页面时发生异常,异常信息如下:");
LogAPI.Debug(ex);
}
}
public void GetBGTBForJCTB(IFeature pJCTB)
{
if (pJCTB == null) return;
List<TBInfo> listBGFC = new List<TBInfo>();
IFeatureClass featureClassBG = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");
int JCBHIndex = pJCTB.Fields.FindField("TBBH");
if (JCBHIndex == -1) return;
string strJCBH = pJCTB.Value[JCBHIndex].ToTrim();
if (string.IsNullOrWhiteSpace(strJCBH)) return;
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = string.Format("TBYBH='{0}'", strJCBH)
};
if (featureClassBG.FeatureCount(queryFilter) == 0)
{
System.Windows.Forms.DialogResult result = MessageHelper.ShowYesNoCancelAndTips("无对应变更图斑数据,是否从监测图层中加载?");
if (result == System.Windows.Forms.DialogResult.Yes)
{
IFeatureClassAPI featureClassAPI_GJJCTB = new FeatureClassAPI(_curJCTBFeatureLayer.FeatureClass);
int JCJCBHIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("TBBH");
int JCBGDLIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("BGDL");
int JCTZIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("TZ");
int JCBGFWIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("KZXX");
int JCWBGLXIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("WBGLX");
int JCSJLYIndex = featureClassAPI_GJJCTB.FeatureClass.FindField("SJLY");
//AddFildsToBGTB(featureClassBG);
int BGTBYBHIndex = featureClassBG.FindField("TBYBH");
int BGDLBMIndex = featureClassBG.FindField("DLBM");
int BGSFJCTBIndex = featureClassBG.FindField("SFJCTB");
int TZIndex = featureClassBG.FindField("TZ");
int BGDLIndex = featureClassBG.FindField("BGDL");
int BGFWIndex = featureClassBG.FindField("BGFW");
int WBGLXIndex = featureClassBG.FindField("WBGLX");
int SJLYIndex = featureClassBG.FindField("SJLY");
//检测图斑
IFeatureCursor T_Cursor = null;
if (featureClassAPI_GJJCTB.FeatureClass != null)
{
IFeatureClassLoad pFclsLoad = featureClassBG as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//地类变更图斑
IFeatureBuffer buffer = featureClassBG.CreateFeatureBuffer();
T_Cursor = featureClassBG.Insert(true);
buffer.Shape = pJCTB.ShapeCopy;
buffer.Value[BGDLIndex] = pJCTB.Value[JCBGDLIndex];
buffer.Value[TZIndex] = pJCTB.Value[JCTZIndex];
buffer.Value[BGFWIndex] = pJCTB.Value[JCBGFWIndex];
buffer.Value[WBGLXIndex] = pJCTB.Value[JCWBGLXIndex];
buffer.Value[SJLYIndex] = "1";
buffer.Value[BGTBYBHIndex] = pJCTB.Value[JCJCBHIndex];
buffer.Value[BGDLBMIndex] = pJCTB.Value[JCBGDLIndex];
buffer.Value[BGSFJCTBIndex] = "1";
T_Cursor.InsertFeature(buffer);
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
Marshal.ReleaseComObject(T_Cursor);
Marshal.ReleaseComObject(buffer);
Marshal.ReleaseComObject(pFclsLoad);
}
}
}
IFeatureCursor featureCursorBG = featureClassBG.Search(queryFilter, false);
IFeature bgF = null;
while ((bgF = featureCursorBG.NextFeature()) != null)
{
ListBoxItem item = new ListBoxItem();
item.Margin = new Thickness(32, 0, 0, 0);
item.Content = "图斑:" + bgF.OID;
item.Tag = bgF;
tvDataList.Items.Add(item);
}
Marshal.ReleaseComObject(featureCursorBG);
Marshal.ReleaseComObject(featureClassBG);
if (tvDataList.Items.Count > 0)
{
(tvDataList.Items[0] as ListBoxItem).IsSelected = true;
}
}
ControlsEditingSaveCommandClass saveCmd = null;
bool IsSave = false;
public void SaveEdit()
{
IsSave = true;
if (saveCmd == null)
{
saveCmd = new ControlsEditingSaveCommandClass();
saveCmd.OnCreate(MapsManager.Instance.MapService.Hook);
}
if (saveCmd.Enabled)
{
saveCmd.OnClick();
}
IsSave = false;
_FeatureInfo?.SaveEdit();
_NYYPInfo?.SaveEdit();
}
public void Init()
{
try
{
if (_Elements == null)
{
_Elements = UIShell.OSGi.BundleRuntime.Instance.GetService<IElementInfo>();
}
if (_Elements == null) return;
if (_NYYPInfo == null)
{
_NYYPInfo = _Elements.FirstOrDefault(f => f.Title == "内业预判");
}
if ((_NYYPInfo as UserControl).Parent != null)
{
((_NYYPInfo as UserControl).Parent as Grid).Children.Clear();
}
if (_NYYPInfo != null)
NYYPInfoPanel.Children.Add(_NYYPInfo as UIElement);
if (_FeatureInfo == null)
{
_FeatureInfo = _Elements.FirstOrDefault(f => f.Title == "要素属性");
}
if ((_FeatureInfo as UserControl).Parent != null)
{
((_FeatureInfo as UserControl).Parent as Grid).Children.Clear();
}
TBInfo.Children.Add(_FeatureInfo as UIElement);
}
catch (Exception ex)
{
LogAPI.Debug("初始化图斑详情页面失败!");
LogAPI.Debug(ex);
}
}
private void tvDataList_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
try
{
//ListBoxItem item = tvDataList.SelectedItem as ListBoxItem;
foreach (ListBoxItem itemBOX in tvDataList.Items)
{
if (itemBOX.IsSelected == true)
itemBOX.FontStyle = FontStyles.Oblique;
else
itemBOX.FontStyle = FontStyles.Normal;
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性中 元素树操作时鼠标抬起 时异常,异常信息如下:");
LogAPI.Debug(ex);
}
}
private void tvDataList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if (tvDataList.SelectedItem == null)
return;
ListBoxItem item = tvDataList.SelectedItem as ListBoxItem;
if (item == null || item.Tag == null)
{
return;
}
object Data = null;
if (item.Tag is IFeature)
{
Data = item.Tag;
}
_FeatureInfo?.BindData(item.Tag);
_NYYPInfo?.BindData(item.Tag);
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw;
}
}
public bool IsShow { get; set; }
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public Guid ID { get; set; }
public DockStyle DockAreas { get; set; }
public System.Drawing.Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
}
public class TBInfo
{
public string Caption { get; set; }
public object Data { get; set; }
public TBInfo(IFeature pFeature)
{
Caption = pFeature.OID.ToString();
Data = pFeature;
}
}
}