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

543 lines
21 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 FrmDataCheckHelp : Window, IDataCheckHelper
{
System.Windows.Forms.Control panel = null;
private bool isMouseEnter = false;
Storyboard sbShow = null;
Storyboard sbClose = null;
Storyboard sbLoading = null;
public FrmDataCheckHelp(IHookHelper hookHelper)
{
InitializeComponent();
sbShow = this.Resources["ShowDetail"] as Storyboard;
sbClose = this.Resources["CloseDetail"] as Storyboard;
sbLoading = this.Resources["loading"] as Storyboard;
//Storyboard sb = this.Resources["loading"] as Storyboard;
sbLoading.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 - 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 + 10;// + panel.Height - this.Height;
//if (Left + this.Width > p2.X + panel.Width)
Left = p2.X + panel.Width - this.Width - 10;
}
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);
ThreadManager.Instance.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);
ThreadManager.Instance.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;
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;
ErrorCount.Content = result.CheckResults.Count > 0 ? gData.FirstOrDefault().ToList().Count : 0;
}
});
}
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}' ", 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);
}
bool isShow = false;
private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Left)
{
e.Handled = true;
return;
}
if (isShow)
{
isShow = false;
//ErrDetail.Visibility = Visibility.Collapsed;
if (sbClose != null)
sbClose.Begin();
}
else
{
isShow = true;
//ErrDetail.Visibility = Visibility.Visible;
if (sbShow != null)
sbShow.Begin();
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//}
}
public class TreeNode
{
#region Property
private string _Text;
/// <summary>
/// 显示的文本值
/// </summary>
public string Name
{
get { return this._Text; }
set { this._Text = value; }
}
private string _Tip;
/// <summary>
/// 显示的文本值
/// </summary>
public string Tip
{
get { return this._Tip; }
set { this._Tip = value; }
}
private ContextMenu _cMenu;
public ContextMenu cMenu
{
get { return this._cMenu; }
set { this._cMenu = value; }
}
private bool? _Checked;
/// <summary>
/// 是否选中
/// </summary>
public bool? Checked
{
get { return this._Checked; }
set { this._Checked = value; }
}
private bool _IsExpanded;
/// <summary>
/// 是否展开
/// </summary>
public bool IsExpanded
{
get { return this._IsExpanded; }
set { this._IsExpanded = value; }
}
/// <summary>
/// 节点图标:相对路径
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 子节点,默认null
/// </summary>
public IList<TreeNode> Nodes { get; set; }
/// <summary>
/// 该节点数据项,默认null
/// </summary>
public virtual object Data { get; set; }
public virtual bool IsOpenEdit { get; set; }
public object Paixu { get; internal set; }
public bool IsParent { get; internal set; }
#endregion
#region NodeX-构造函数(初始化)
/// <summary>
/// NodeX-构造函数(初始化)
/// </summary>
public TreeNode()
{
this.Name = string.Empty;
this.Icon = string.Empty;
this.Checked = false;
}
#endregion
}
}