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

432 lines
18 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace Kingo.Plugin.DataCheck.Views
{
/// <summary>
/// FrmDataCheckHelp.xaml 的交互逻辑
/// </summary>
public partial class FrmFeatureDataCheck : Window, IDataCheckHelper
{
System.Windows.Forms.Control panel = null;
private bool isMouseEnter = false;
public FrmFeatureDataCheck(IHookHelper hookHelper)
{
InitializeComponent();
//Storyboard sb = this.Resources["loading"] as Storyboard;
//sb.Begin();
this.Closed += (e, a) =>
{
UIShell.OSGi.BundleRuntime.Instance.RemoveService<IDataCheckHelper>(this);
};
UIShell.OSGi.BundleRuntime.Instance.AddService<IDataCheckHelper>(this);
IdataChecks = new List<IDataCheck>();
IdataChecks.Add(new BGQDataCheck());
IdataChecks.Add(new BGHDataCheck());
IdataChecks.Add(new JCDLTBDataCheck());
IdataChecks.Add(new JCCZCDYDDataCheck());
//IDataCheck = new BGQDataCheck();
m_hookHelper = hookHelper;
this.AllowDrop = true;
this.LocationChanged += FrmDataCheckHelp_LocationChanged;
panel = KGIS.Framework.Maps.MapsManager.Instance.MapService.getAxMapControl();
panel.SizeChanged += Panel_SizeChanged;
System.Drawing.Point p = panel.Location;
System.Drawing.Point p2 = panel.PointToScreen(p);
Top = p2.Y + panel.Height - this.Height - 10;
Left = p2.X + panel.Width - this.Width - 10;
}
IMapService _mapService = null;
private IHookHelper m_hookHelper = null;
//public event CheckDataPr DataCheckComplate;
public IDataCheck IDataCheck { get; set; }
public List<IDataCheck> IdataChecks { get; set; }
public void BinddataGridView()
{
_mapService = MapsManager.Instance.MapService;
ProjectInfo projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo);
string dbPath = System.IO.Path.Combine(projectInfo.ProjDir, "DataCheckrResult.db");
DataTable DataCheckrResult = SQLiteDBOperate.Instance.ExceDataTable(dbPath, $"SELECT OBJECTID,ErrorDesc 错误说明, ErrorArea 错误图形 FROM DataCheckResults ");
//if (DataCheckrResult != null)
//MyPropertyGrid.ItemsSource = DataCheckrResult.DefaultView;
}
private void ShowDetail(object o)
{
}
private void Panel_SizeChanged(object sender, EventArgs e)
{
System.Drawing.Point p = panel.Location;
System.Drawing.Point p2 = panel.PointToScreen(p);
if (Top < p2.Y)
this.Top = p2.Y;
if (Left < p2.X)
this.Left = p2.X;
if (Top + this.Height > p2.Y + panel.Height)
Top = p2.Y + panel.Height - this.Height;
if (Left + this.Width > p2.X + panel.Width)
Left = p2.X + panel.Width - this.Width;
}
private void FrmDataCheckHelp_LocationChanged(object sender, EventArgs e)
{
System.Windows.Forms.Control panel = KGIS.Framework.Maps.MapsManager.Instance.MapService.getAxMapControl();
System.Drawing.Point p = panel.Location;
System.Drawing.Point p2 = panel.PointToScreen(p);
if (Top < p2.Y)
this.Top = p2.Y;
if (Left < p2.X)
this.Left = p2.X;
if (Top + this.Height > p2.Y + panel.Height)
Top = p2.Y + panel.Height - this.Height;
if (Left + this.Width > p2.X + panel.Width)
Left = p2.X + panel.Width - this.Width;
if (this.Top - p2.Y < popContent.Height)
{
//下
//popContent.VerticalOffset = popContent.Height + this.Height - 10;
}
else
{
//上
//popContent.VerticalOffset = 10;
}
if (this.Left - p2.X < popContent.Width)
{
//右
//popContent.HorizontalOffset = 0 + this.Width - 10;// popContent.Width - (this.Left - p2.X);// this.Left;// popContent.Width + this.Width;
}
else
{
//左
//popContent.HorizontalOffset = -popContent.Width + 10;
}
}
private void btnClosePage_Click(object sender, RoutedEventArgs e)
{
isMouseEnter = false;
Storyboard sb = this.Resources["closeDW2"] as Storyboard;
this.BeginStoryboard(sb);
//this.popContent.IsOpen = false;
}
private void MyPropertyGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (_mapService == null) return;
var gridView = sender as DataGrid;
var errorMessage = gridView.SelectedItem as DataRowView;
if (errorMessage == null) return;
if (errorMessage.Row.ItemArray[2].ToString().Contains("paths"))
{
ESRI.ArcGIS.Geometry.IGeometry geometry = IPolygonExtension.ToGeometry(errorMessage.Row.ItemArray[2].ToString(), true, ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline);
_mapService.DrawGraph(geometry);
_mapService.Zoom(geometry);
m_hookHelper.FocusMap.ClearSelection();//清除图层上要素选择
}
else
{
object pLayer = m_hookHelper.GetCustomProperty();//获取对象的创建者的Application对象
if (pLayer != null)
{
IFeatureLayer pTocFeatureLayer = pLayer as IFeatureLayer;
_mapService.SelectFeature(pTocFeatureLayer.Name, errorMessage.Row.ItemArray[0].ToString());
}
}
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
#region 一键修复
private void KImgButton_Click(object sender, RoutedEventArgs e)
{
}
#endregion
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//this.DragMove();
}
public void DataCheckByThread(CheckParametr pParm)
{
try
{
IDataCheck = IdataChecks.FirstOrDefault(x => x.IDataCheckName == pParm.IDataCheckName);
if (IDataCheck != null)
{
//cavLoading.Visibility = Visibility.Visible;
if (pParm.DataSource as IFeature != null)
{
//Thread thread = new Thread(new ParameterizedThreadStart(IDataCheck.FeatureCheck));
//thread.SetApartmentState(ApartmentState.STA);
//thread.Start(pParm);
ThreadManager2.QueueUserWorkItem(new WaitCallback(IDataCheck.FeatureCheck), pParm, new WaitCallback(ThreadCallBack));
}
else if (pParm.DataSource as IFeatureClass != null)
{
//Thread thread = new Thread(new ParameterizedThreadStart(IDataCheck.FeatureClassCheck));
//thread.SetApartmentState(ApartmentState.STA);
//thread.Start(pParm);
ThreadManager2.QueueUserWorkItem(new WaitCallback(IDataCheck.FeatureCheck), pParm, new WaitCallback(ThreadCallBack));
}
//IDataCheck.DataCheckComplate += _BindTree;
}
}
catch (Exception ex)
{
throw ex;
}
}
void ThreadCallBack(object o)
{
CheckParametr result = o as CheckParametr;
int oid = (result.DataSource as IFeature).OID;
this.Dispatcher.Invoke(() =>
{
//cavLoading.Visibility = Visibility.Collapsed;
if (result.CheckResults != null)
{
_CheckInterface_InspectionCompleted(null, result);
IEnumerable<IGrouping<int, CheckResult>> gData = result.CheckResults.GroupBy(g => g.ObjectID);
TreeNode rootNode = new TreeNode();
rootNode.Nodes = new System.Collections.ObjectModel.ObservableCollection<TreeNode>();
foreach (var item in gData)
{
TreeNode subNode = new TreeNode();//树节点赋值属性
subNode.Name = "图斑:" + item.Key;
subNode.Paixu = 0;
subNode.IsExpanded = true;
subNode.Data = item;
subNode.Icon = "pack://application:,,,/Kingo.Plugin.DataCheck;component/Resources/自主图斑.png";
subNode.Nodes = new System.Collections.ObjectModel.ObservableCollection<TreeNode>();
foreach (var err in item)
{
TreeNode childNodeItem = new TreeNode();//树节点赋值属性
childNodeItem.Name = err.Synopsis;
childNodeItem.Tip = err.ErrorDesc;
childNodeItem.Paixu = 0;
childNodeItem.IsExpanded = true;
childNodeItem.Data = item;
childNodeItem.Icon = "pack://application:,,,/Kingo.Plugin.DataCheck;component/Resources/错误.png";
subNode.Nodes.Add(childNodeItem);
}
rootNode.Nodes.Add(subNode);
}
this.tvTypes.ItemsSource = null;
this.tvTypes.ItemsSource = rootNode.Nodes;
//IDataCheck.DataCheckComplate -= _BindTree;
}
});
}
public void DataCheck(CheckParametr pParm)
{
try
{
IDataCheck = IdataChecks.FirstOrDefault(x => x.IDataCheckName == pParm.IDataCheckName);
if (IDataCheck != null)
{
//IDataCheck.DataCheckComplate += (o) =>
//{
// if (o != null)
// {
// _CheckInterface_InspectionCompleted(o, pParm);
// }
//};
IDataCheck.DataCheckComplate += _CheckInterface_InspectionCompleted;
if (pParm.DataSource as IFeature != null)
{
IDataCheck.FeatureCheck(pParm);
}
else if (pParm.DataSource as IFeatureClass != null)
{
IDataCheck.FeatureClassCheck(pParm);
}
IDataCheck.DataCheckComplate -= _CheckInterface_InspectionCompleted;
}
}
catch (Exception ex)
{
throw ex;
}
}
private void _BindTree(List<CheckResult> dataCheckResults, CheckParametr pParm)
{
}
void _CheckInterface_InspectionCompleted(List<CheckResult> Result, CheckParametr pParm)
{
try
{
string dbPath = string.Empty;
IFeature feature = pParm.DataSource as IFeature;
try
{
//更新界面逻辑
ProjectInfo projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo);
dbPath = System.IO.Path.Combine(projectInfo.ProjDir, "DataCheckrResult.db");
SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"CREATE TABLE IF NOT exists DataCheckResults (`ID` INTEGER, `ErrorLayer` TEXT,`OBJECTID` TEXT,`ErrorType` TEXT,`ErrorCode` TEXT,`ErrorDesc` TEXT,`ErrorData` TEXT,`ErrorArea` TEXT,`ErrorMJ` NUMERIC,`Synopsis` TEXT,`ErrorCategory` TEXT ,PRIMARY KEY(`ID`))", null);
if (feature != null)
SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults WHERE OBJECTID='{feature.OID}' ;", null);//删除当前数据相关的核查结果
else
SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults where ErrorLayer='{pParm.IDataCheckName}' and ErrorCategory='{pParm.CheckType}' ;", null);
if (pParm.CheckResults == null) return;
if (pParm.CheckResults.Count == 0) return;
List<string> sqlList = new List<string>();
foreach (var item in pParm.CheckResults)
{
sqlList.Add(string.Format("INSERT INTO DataCheckResults (ErrorLayer,OBJECTID,ErrorType,ErrorCode,ErrorDesc,ErrorArea,Synopsis,ErrorCategory) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", item.ErrorLayer, item.ObjectID, item.ErrorType, item.ErrorCode, item.ErrorDesc, item.ErrorArea, item.Synopsis, item.ErrorCategory));
}
InsertSQLiteData(dbPath, sqlList);
}
catch (Exception ex)
{
LogAPI.Debug("批量插入SQLite数据(地址:" + dbPath + ") 执行失败,异常原因: " + ex.Message + " ; ");
throw ex;
}
}
catch (Exception ex)
{
throw ex;
}
}
private void InsertSQLiteData(string dbPath, List<string> sqlList)
{
try
{
using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (System.Data.SQLite.SQLiteTransaction pTrans = conn.BeginTransaction())
{
using (System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(conn))
{
for (int i = 0; i < sqlList.Count(); i++)
{
cmd.CommandText = sqlList[i];
cmd.ExecuteNonQuery();
}
pTrans.Commit();
}
}
conn.Close();
}
}
catch (Exception ex)
{
LogAPI.Debug("批量插入SQLite数据(地址:" + dbPath + ") 执行失败,异常原因: " + ex.Message + " ; ");
return;
}
}
private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
}
private void win_MouseMove(object sender, MouseEventArgs e)
{
}
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
IsMove = true;
}
bool IsMove = false;
private void Grid_MouseEnter(object sender, MouseEventArgs e)
{
//Storyboard sb = this.Resources["showDW2"] as Storyboard;
//if (this.popContent.IsOpen && IsMove)
//{
// IsMove = false;
// sb = this.Resources["closeDW2"] as Storyboard;
// this.BeginStoryboard(sb);
// this.popContent.IsOpen = false;
// return;
//}
//if (this.popContent.IsOpen)
// return;
////IsErr = false;
////else
////{
//this.popContent.IsOpen = true;// !this.popContent.IsOpen;
//popContent.HorizontalOffset = 0;// this.Width - detailGrid.ActualWidth;
//System.Windows.Forms.Control panel = KGIS.Framework.Maps.MapsManager.Instance.MapService.getAxMapControl();
//System.Drawing.Point p = panel.Location;
//System.Drawing.Point p2 = panel.PointToScreen(p);
//if (this.Top - p2.Y < popContent.Height)
//{
// popContent.VerticalOffset = this.Height - 10;
// ((Canvas1.RenderTransform as System.Windows.Media.TransformGroup).Children[0] as System.Windows.Media.ScaleTransform).CenterY = 0;
// //Canvas1.RenderTransform.Value = new System.Windows.Media.Matrix(0, 0, 0, 0, 0, 0);
//}
//else
//{
// popContent.VerticalOffset = 10;
// ((Canvas1.RenderTransform as System.Windows.Media.TransformGroup).Children[0] as System.Windows.Media.ScaleTransform).CenterY = popContent.Height;
//}
//if (this.Left - p2.X < popContent.Width)
//{
// popContent.HorizontalOffset = this.Width - 10;
// ((Canvas1.RenderTransform as System.Windows.Media.TransformGroup).Children[0] as System.Windows.Media.ScaleTransform).CenterX = 0;
//}
//else
//{
// popContent.HorizontalOffset = 10;
// ((Canvas1.RenderTransform as System.Windows.Media.TransformGroup).Children[0] as System.Windows.Media.ScaleTransform).CenterX = popContent.Width;
//}
//this.BeginStoryboard(sb);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Width = 240;
this.Height = 300;
Canvas1.Visibility = Visibility.Visible;
Storyboard sb = this.Resources["showDW2"] as Storyboard;
sb.Begin();
//this.DragMove();
//IsMove = true;
}
//}
}
}