年度变更建库软件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.

498 lines
22 KiB

4 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.AE.ExtensionMethod;
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;
using UIShell.OSGi;
namespace Kingo.Plugin.NYYP.View
{
/// <summary>
/// UCTBBG.xaml 的交互逻辑
/// </summary>
public partial class UCTBBG : UserControl, IElementInfo
{
private IProofManager ProofMgr = null;
List<IElementInfo> _Elements = null;
IElementInfo _WYInfo = null;
IElementInfo _FeatureInfo = null;
IElementInfo _NYYPInfo = null;
IElementInfo _WYImgInfo = null;
IFeatureLayer _curFeatureLayer;
IFeatureLayer _curJCTBFeatureLayer;
private object Hook = null;
public UCTBBG()
{
InitializeComponent();
Title = "图斑变更组件";
DockWidth = 550;
this.Loaded += (s, e) =>
{
MapsManager.Instance.MapService.OnSelectionChanged -= MapService_OnSelectionChanged;
MapsManager.Instance.MapService.OnSelectionChanged += MapService_OnSelectionChanged;
_curFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
_curJCTBFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB");
Hook = MapsManager.Instance.MapService.Hook;
};
}
private int CurShowJCOID = 0;
private void MapService_OnSelectionChanged(object sender, EventArgs e)
{
try
{
if (!IsShow)
{
MapsManager.Instance.MapService.OnSelectionChanged -= MapService_OnSelectionChanged;
return;
}//当前窗口关闭时,注销触发事件
ISelectionSet pSelectionSetes = (_curFeatureLayer as IFeatureSelection).SelectionSet;//获取图层要素已被选择的
ISelectionSet pJCSelectionSetes = (_curJCTBFeatureLayer as IFeatureSelection).SelectionSet;//获取图层要素已被选择的
int oid = -1; //ShowIndex 暂时当做区分变更范围与监测图斑
if (pSelectionSetes != null && pSelectionSetes.Count != 0 && this.ShowIndex == 0)
{
if (IsSave) return;
IEnumIDs enumIDs = pSelectionSetes.IDs;
enumIDs.Reset();
while ((oid = enumIDs.Next()) >= 0)
{
IFeature f = _curFeatureLayer.FeatureClass.GetFeature(oid);
BindData(f);
Marshal.ReleaseComObject(enumIDs);
break;
}
}//监测是否有要素被选择
else if (pJCSelectionSetes != null && pJCSelectionSetes.Count != 0 && this.ShowIndex == 1)
{
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(pSelectionSetes);
Marshal.ReleaseComObject(pJCSelectionSetes);
if (oid == -1)
{
BindData(null);
return;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
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 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")
{
GetBGTBForJCTB(tempFeature);
if (tvDataList.SelectedItem is ListBoxItem item) item.FontStyle = FontStyles.Oblique;
}
else if (mFcName == "DLTBBG")
{
_FeatureInfo?.BindData(obj);
_NYYPInfo?.BindData(obj);
object wyData = GetProofData(obj as IFeature);
if (wyData == null)
{
labIsProof.Content = "图斑未举证";
labIsProof.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
}
else
{
labIsProof.Content = "图斑已举证";
labIsProof.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green);
}
_WYInfo?.BindData(wyData);
_WYImgInfo?.BindData(wyData);
}
return;
}
else
{
ISelectionSet pSelectionSetes = (_curFeatureLayer as IFeatureSelection).SelectionSet;//获取图层要素已被选择的
if (pSelectionSetes == null) return;//监测是否有要素被选择
IEnumIDs enumIDs = pSelectionSetes.IDs;
enumIDs.Reset();
List<int> selectionOIDs = new List<int>();
int oid = -1;
while ((oid = enumIDs.Next()) >= 0)
{
obj = _curFeatureLayer.FeatureClass.GetFeature(oid);
break;
}
}
_FeatureInfo?.BindData(obj);
_WYInfo?.BindData(obj);
_NYYPInfo?.BindData(obj);
_WYImgInfo?.BindData(obj);
}
catch (Exception ex)
{
LogAPI.Debug("加载图斑变更详情页面时发生异常,异常信息如下:");
LogAPI.Debug(ex);
}
}
public void GetBGTBForJCTB(IFeature pJCTB)
{
if (pJCTB == null) return;
IFeatureLayer featureLayerBG = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
int JCBHIndex = pJCTB.Fields.FindField("JCBH");
if (JCBHIndex == -1) return;
string strJCBH = pJCTB.Value[JCBHIndex].ToTrim();
if (string.IsNullOrWhiteSpace(strJCBH))
{
labIsProof.Content = "图斑未举证";
labIsProof.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
_WYInfo?.BindData(null);
_WYImgInfo?.BindData(null);
_FeatureInfo?.BindData(null);
return;
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = string.Format("TBYBH='{0}'", strJCBH)
};
#region 验证监测/变更是否存在空间关系
int BGTBYBHIndex = featureLayerBG.FeatureClass.FindField("TBYBH");
List<IFeature> BGFs = FeatureAPI.Identify2(pJCTB.ShapeCopy, featureLayerBG);
bool IsExit = false;
foreach (IFeature itemBG in BGFs)
{
ITopologicalOperator topo = pJCTB.ShapeCopy as ITopologicalOperator;
IGeometry newGeo = topo.Intersect(itemBG.ShapeCopy, itemBG.ShapeCopy.Dimension);
decimal ares = newGeo.GetEllipseArea().ToDecimal();
decimal asde = Convert.ToDecimal(pJCTB.ShapeCopy.GetEllipseArea());
//decimal asdw = ares / asde;
if (ares / asde > 0.8.ToDecimal())
{
if (BGTBYBHIndex == -1) continue;
itemBG.Value[BGTBYBHIndex] = strJCBH;
itemBG.Store();
IsExit = true;
}
}
#endregion
#region 无对应变更图斑数据,可从监测图层中加载
if (!IsExit && featureLayerBG.FeatureClass.FeatureCount(queryFilter) == 0)
{
System.Windows.Forms.DialogResult result = MessageHelper.ShowYesNoCancelAndTips("无对应变更图斑数据,是否从监测图层中加载?");
if (result == System.Windows.Forms.DialogResult.Yes)
{
#region 字段属性
int JCJCBHIndex = pJCTB.Fields.FindField("TBBH");
int JCBGDLIndex = pJCTB.Fields.FindField("BGDL");
int JCTZIndex = pJCTB.Fields.FindField("TZ");
int JCBGFWIndex = pJCTB.Fields.FindField("BGFW");
int JCWBGLXIndex = pJCTB.Fields.FindField("WBGLX");
int JCSJLYIndex = pJCTB.Fields.FindField("SJLY");
int BGDLBMIndex = featureLayerBG.FeatureClass.FindField("DLBM");
int TZIndex = featureLayerBG.FeatureClass.FindField("TZ");
int BGDLIndex = featureLayerBG.FeatureClass.FindField("BGDL");
int BGFWIndex = featureLayerBG.FeatureClass.FindField("BGFW");
int WBGLXIndex = featureLayerBG.FeatureClass.FindField("WBGLX");
int SJLYIndex = featureLayerBG.FeatureClass.FindField("SJLY");
#endregion
//监测图斑
IFeatureClassLoad pFclsLoad = featureLayerBG.FeatureClass as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//地类变更图斑
IFeatureBuffer buffer = featureLayerBG.FeatureClass.CreateFeatureBuffer();
IFeatureCursor T_Cursor = featureLayerBG.FeatureClass.Insert(true);
#region 属性赋值
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] = pJCTB.Value[JCSJLYIndex];
buffer.Value[BGTBYBHIndex] = pJCTB.Value[JCJCBHIndex];
int DLBMFieldLength = featureLayerBG.FeatureClass.Fields.get_Field(BGDLBMIndex).Length;
if (!string.IsNullOrWhiteSpace(pJCTB.Value[JCBGDLIndex].ToTrim()) && pJCTB.Value[JCBGDLIndex].ToTrim().Length <= DLBMFieldLength)
buffer.Value[BGDLBMIndex] = pJCTB.Value[JCBGDLIndex];
else if (!string.IsNullOrWhiteSpace(pJCTB.Value[JCBGDLIndex].ToTrim()) && pJCTB.Value[JCBGDLIndex].ToTrim().Contains(','))
buffer.Value[BGDLBMIndex] = pJCTB.Value[JCBGDLIndex].ToTrim().Split(',')[0];
else
buffer.Value[BGDLBMIndex] = DBNull.Value;
#endregion
T_Cursor.InsertFeature(buffer);
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
Marshal.ReleaseComObject(T_Cursor);
Marshal.ReleaseComObject(buffer);
Marshal.ReleaseComObject(pFclsLoad);
}
}
#endregion
#region 展示选项卡
IFeatureCursor featureCursorBG = featureLayerBG.FeatureClass.Search(queryFilter, false);
IFeature bgF = null;
while ((bgF = featureCursorBG.NextFeature()) != null)
{
ListBoxItem item = new ListBoxItem
{
Margin = new Thickness(32, 0, 0, 0),
Content = "图斑:" + bgF.OID,
Tag = bgF
};
tvDataList.Items.Add(item);
}
#endregion
Marshal.ReleaseComObject(featureCursorBG);
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();
_WYImgInfo?.SaveEdit();
}
public void Init()
{
try
{
if (_Elements == null)
{
_Elements = BundleRuntime.Instance.GetService<IElementInfo>();
}
if (_Elements == null)
return;
if (_WYImgInfo == null)
{
_WYImgInfo = _Elements.FirstOrDefault(f => f.Title == "外业照片");
}
if (_WYImgInfo != null && (_WYImgInfo as UserControl).Parent != null)
{
((_WYImgInfo as UserControl).Parent as Grid).Children.Clear();
}
if (_WYImgInfo != null)
WYImgInfo.Children.Add(_WYImgInfo as UIElement);
//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 (_WYInfo == null)
{
_WYInfo = _Elements.FirstOrDefault(f => f.Title == "外业信息组件");
}
if ((_WYInfo as UserControl).Parent != null)
{
((_WYInfo as UserControl).Parent as Grid).Children.Clear();
}
WYInfo.Children.Add(_WYInfo 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);
if (item.Tag is IFeature)
{
MoveToCenter(item.Tag as IFeature);
ISelectionSet pSelectionSet = (_curFeatureLayer as IFeatureSelection).SelectionSet;
pSelectionSet.Add((item.Tag as IFeature).OID);
}
//_WYInfo?.BindData(item.Tag);
_NYYPInfo?.BindData(item.Tag);
object wyData = GetProofData(item.Tag as IFeature);
if (wyData == null)
{
labIsProof.Content = "图斑未举证";
labIsProof.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
}
else
{
labIsProof.Content = "图斑已举证";
labIsProof.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green);
}
_WYInfo?.BindData(wyData);
_WYImgInfo?.BindData(wyData);
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw;
}
}
private void MoveToCenter(IFeature pFeatures)
{
try
{
IEnvelope pEnvelope = new EnvelopeClass() as IEnvelope;
pEnvelope = pFeatures.ShapeCopy.Envelope;
List<IFeature> featureList = new List<IFeature>();
featureList.Add(pFeatures);
//(Hook as IMapControlDefault).Map.SelectFeature(_curFeatureLayer as ILayer, pFeatures);与变更图斑产生冲突
if (pEnvelope.XMax < pFeatures.ShapeCopy.Envelope.XMax)
pEnvelope.XMax = pFeatures.ShapeCopy.Envelope.XMax;
if (pEnvelope.XMin > pFeatures.ShapeCopy.Envelope.XMin)
pEnvelope.XMin = pFeatures.ShapeCopy.Envelope.XMin;
if (pEnvelope.YMax < pFeatures.ShapeCopy.Envelope.YMax)
pEnvelope.YMax = pFeatures.ShapeCopy.Envelope.YMax;
if (pEnvelope.YMin > pFeatures.ShapeCopy.Envelope.YMin)
pEnvelope.YMin = pFeatures.ShapeCopy.Envelope.YMin;
////投影到当前地图坐标系定位缩放到当前要素
pEnvelope.Project((Hook as IMapControlDefault).SpatialReference);
IUnitConverter pUnitConverter = new UnitConverterClass();
double dScale = pUnitConverter.ConvertUnits(20, esriUnits.esriMeters, (Hook as IMapControlDefault).MapUnits);
pEnvelope.PutCoords(pEnvelope.XMin - dScale, pEnvelope.YMin - dScale, pEnvelope.XMax + dScale, pEnvelope.YMax + dScale);
(Hook as IMapControlDefault).ActiveView.Extent = pEnvelope;
(Hook as IMapControlDefault).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, (Hook as IMapControlDefault).ActiveView.Extent);
(Hook as IMapControlDefault).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, featureList, (Hook as IMapControlDefault).ActiveView.Extent);
}
catch (Exception ex)
{
MessageHelper.ShowError("操作异常!异常信息:" + ex.Message);
LogAPI.Debug(ex);
}
}
private List<ProofInfo> GetProofData(IFeature pFeature)
{
if (ProofMgr == null)
ProofMgr = BundleRuntime.Instance.GetFirstOrDefaultService<IProofManager>();
List<ProofInfo> result = new List<ProofInfo>();
int fieldIndex = pFeature.Fields.FindField("TBYBH");
if (fieldIndex == -1)
fieldIndex = pFeature.Fields.FindField("TBBH");
if (fieldIndex > 0)
{
result = ProofMgr.GetProofInfoList<ProofInfo>(pFeature.Value[fieldIndex].ToString());
}
return result;
}
}
}