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

5852 lines
282 KiB

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.Enum;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Dialog;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using KGIS.Framework.Views;
using Kingo.Plugin.General.Helper;
using Kingo.Plugin.General.Model;
using Kingo.Plugin.General.ViewDTBJK;
using Kingo.Plugin.General.ViewDTBResultCheck;
using Kingo.Plugin.General.ViewYCLJK;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using Kingo.PluginServiceInterface.Model;
using Kingo.RuleCheck;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
using UIShell.OSGi;
using static KGIS.Framework.ThreadManager.CustomDelegate;
namespace Kingo.Plugin.General.View
{
/// <summary>
/// UCJCTBTree.xaml 的交互逻辑
/// </summary>
public partial class UCJCTBTree : UserControl, IDockPanel3, INotifyPropertyChanged, IElementInfo
{
public IHookHelper hookHelper { get; set; }
/// <summary>
/// 外业任务图层
/// </summary>
private IFeatureLayer WyrwFeatureLayer { get; set; }
/// <summary>
/// 单图斑地类图斑变更
/// </summary>
private IFeatureLayer DtbFeatureLayer { get; set; }
/// <summary>
/// 树结构的数据 源
/// </summary>
public ObservableCollection<TreeNode> TreeDataSource { get; set; }
private IEngineEditor EngineEditorBG { get; set; }
private UCDTBAllInfo uCDTBAllInfo { get; set; }
private ProjectInfo ProjectInfo { get; set; }
/// <summary>
/// 单图斑质检页面
/// </summary>
private UCCheckResults CheckResultsView { get; set; }
private UCBGDataImport frmDataImport { get; set; }
private FrmDataImport frmDataImportForZZTB { get; set; }
private UCSelectUSB uCSelectUSB { get; set; }
private TaskPackage AddTaskPackage { get; set; }
private TreeNode CurrentSelectNode
{
get
{
return tvPackges.SelectedItem as TreeNode;
}
set { }
}
/// <summary>
/// 当前选中任务包
/// </summary>
private TaskPackage CurrentTaskPackage { get; set; }
/// <summary>
/// 当前选中外业任务图斑
/// </summary>
private WYRWTB CurrentWYRWTB
{
get
{
if (CurrentSelectNode == null)
{
return null;
}
if (CurrentSelectNode.NodeLevel == 2 && (CurrentSelectNode.Data as WYRWTB) != null)
{
return CurrentSelectNode.Data as WYRWTB;
}
else if (CurrentSelectNode.NodeLevel == 3 && (CurrentSelectNode.ParentNode.Data as WYRWTB) != null)
{
return CurrentSelectNode.ParentNode.Data as WYRWTB;
}
return null;
}
}
/// <summary>
/// 当前选择的监测图斑树节点
/// </summary>
private TreeNode CurrentWYRWTBTreeNode
{
get
{
if (CurrentSelectNode == null)
{
return null;
}
if (CurrentSelectNode.NodeLevel == 2 && (CurrentSelectNode.Data as WYRWTB) != null)
{
return CurrentSelectNode;
}
else if (CurrentSelectNode.NodeLevel == 3 && (CurrentSelectNode.ParentNode.Data as WYRWTB) != null)
{
return CurrentSelectNode.ParentNode;
}
return null;
}
}
private USBFlashDiskHelper uSBFlashDiskHelper { get; set; }
/// <summary>
/// 自主图斑图层
/// </summary>
private IFeatureLayer zztbFeatureLayer
{
set { }
get
{
return MapsManager.Instance.MapService.GetFeatureLayerByName("ZZTB");
}
}
/// <summary>
/// 外业任务图层
/// </summary>
private IFeatureLayer wyrwFeatureLayer
{
get
{
return MapsManager.Instance.MapService.GetFeatureLayerByName("WYRW");
}
}
/// <summary>
/// 基础地类图斑图层
/// </summary>
private IFeatureLayer DLTBFeatureLayer { get; set; }
/// <summary>
/// 基础_村级调查区
/// </summary>
private IFeatureLayer cjdcqLayer
{
get
{
return MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_村级调查区");
}
}
private UCJKResultExport ucJKResultExport { get; set; }
private UCSetBatchAttribute ucSetBatchAttribute { get; set; }
private DTBDBLoadHelper dBLoadHelper = new DTBDBLoadHelper();
private string BGTJSqlitePath { get; set; }
/// <summary>
/// 任务图斑相关数据接口帮助类
/// </summary>
private IJKTBTask GetRWTBDataHelper = new JKTBTaskHelper();
private DataOperationHelper_Default dataOperation = null;
public UCJCTBTree()
{
try
{
InitializeComponent();
this.Title = "任务列表";
this.DockWidth = 300;
this.DockHeight = 800;
this.DefaultArea = DockStyle.DockLeft;
this.DockAreas = DockStyle.DockLeft;
this.ShowAutoHideButton = true;
this.IsShowInMap = false;
this.IsDockToPanel = true;
this.IsShow = false;
this.ShowCloseButton = true;
this.DockToPanelStyle = DockStyle.DockLeft | DockStyle.Document;
if (!SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("65"))
{
secondRow.MaxHeight = 0;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
/// <summary>
/// 展示单图斑详情页-单图斑建库版本
/// </summary>
private void ShowDTBDetails(string SystemType)
{
try
{
this.ShowPanel();
//单图斑属性详情
if (uCDTBAllInfo == null)
{
uCDTBAllInfo = new UCDTBAllInfo(SystemType);
uCDTBAllInfo.PreData += PreData;
uCDTBAllInfo.NextData += NextData;
uCDTBAllInfo.FWYAction += SetFWY;
uCDTBAllInfo.CloseViewHandler += UCJCTBTree_CloseViewHandler;
}
uCDTBAllInfo.ShowPanel();
//if (SystemType != SystemTypeEnum.YCLJK.ToTrim() && SystemType != SystemTypeEnum.WYZS.ToTrim())
if (SystemType != SystemTypeEnum.YCLJK.ToTrim())
{
if (CheckResultsView == null)
{
CheckResultsView = new UCCheckResults(hookHelper, null, DtbFeatureLayer);
CheckResultsView.ShowPanel();
}
}
if (MapsManager.Instance.MapService != null)
{
MapsManager.Instance.MapService.ProjectClosed += MapsService_ProjectClosed;
}
}
catch (Exception ex)
{
LogAPI.Debug("ShowDTBDetails异常:" + ex.Message);
LogAPI.Debug("ShowDTBDetails异常:" + ex.StackTrace);
throw ex;
}
}
private void MapsService_ProjectClosed(object sender, EventArgs e)
{
ClosePanel();
}
private void UCJCTBTree_CloseViewHandler(object sender, EventArgs e)
{
try
{
if (uCDTBAllInfo != null)
{
uCDTBAllInfo.DataContext = null;
uCDTBAllInfo = null;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
#region 单图斑功能逻辑代码
/// <summary>
/// 加载任务包
/// </summary>
/// <param name="treeNode">任务包节点</param>
private void LoadDBToTreeNode(TreeNode treeNode)
{
try
{
if (treeNode == null || treeNode.Data == null || (treeNode.Data as TaskPackage) == null)
{
return;
}
treeNode.Nodes.Clear();
TaskPackage taskPackage = treeNode.Data as TaskPackage;
if (string.IsNullOrWhiteSpace(taskPackage.PackagePath) || !File.Exists(taskPackage.PackagePath))
{
throw new Exception("任务包源文件已删除,无法打开!");
}
//打开任务包
PluginServiceInterface.CommonHelper.UpdateAppsettingValueByKey("JkTaskDBName", $"{ProjectInfo.TaskPath}\\临时\\{taskPackage.PackageName}\\{taskPackage.PackageName.Replace("encrypt.", "")}", "UserLoginConfig");
Dictionary<WYRWTB, List<DTBDLTBGX>> dicTBInfo = dBLoadHelper.DBTaskLoad(treeNode.Data as TaskPackage, this.hookHelper);
if (dicTBInfo != null && dicTBInfo.Count > 0)
{
int i = 0;
foreach (var item in dicTBInfo)
{
//外业任务图斑
TreeNode treeWYRWNode = new TreeNode()
{
Name = item.Key.TBBSM + "(0)",
Paixu = i++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/未星标.png",
Data = item.Key,
NodeLevel = 2,
NodeID = item.Key.ObjectID,
ParentNode = treeNode,
PackageNode = treeNode,
PackageState = item.Key.ZT,
cMenu = new ContextMenu()
};
if (item.Key.XBTB == 1)
{
treeWYRWNode.Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/星标.png";
}
int j = 0;
if (item.Value != null)
{
foreach (var bgfw in item.Value)
{
TreeNode treeWYTBNode = new TreeNode()
{
Name = bgfw.BSM,
Paixu = j++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeID = bgfw.ObjectID,
NodeLevel = 3,
Data = bgfw,
ParentNode = treeWYRWNode,
PackageNode = treeNode//任务包对应节点
};
treeWYRWNode.Nodes.Add(treeWYTBNode);
}
}
treeWYRWNode.Name = item.Key.TBBSM + "(" + treeWYRWNode.Nodes.Count + ")";
treeNode.Nodes.Add(treeWYRWNode);
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
/// <summary>
/// 加载指定外业任务图斑到任务包节点
/// </summary>
/// <param name="TaakPacktreeNode"></param>
/// <param name="WYRWTBFeature"></param>
private void LoadTBToTreeNode(TreeNode TaakPacktreeNode, object WYRWTBOID)
{
IRDBHelper rdbHelper = null;
try
{
if (TaakPacktreeNode == null || TaakPacktreeNode.Data == null || (TaakPacktreeNode.Data as TaskPackage) == null || WYRWTBOID == null)
{
IFeature WYRWTBFea = WyrwFeatureLayer.FeatureClass.GetFeature(WYRWTBOID.ToInt());
WYRWTBFea.Delete();//若是未能获取当前任务包相关信息,则撤销数据插入
return;
}
if (TaakPacktreeNode.Nodes == null)
TaakPacktreeNode.Nodes = new ObservableCollection<TreeNode>();
IFeature WYRWTBFeature = WyrwFeatureLayer.FeatureClass.GetFeature(WYRWTBOID.ToInt());
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
rdbHelper.BeginTransaction();
//提取任务图斑
dataOperation.GenerWYTBNewData(WYRWTBFeature, rdbHelper, WYRWTBFeature.Value[WYRWTBFeature.Class.FindField("JCBH")].ToString(), true);
TaakPacktreeNode.Name = $"建库任务_{TaakPacktreeNode.Nodes.Count}个图斑_{TaakPacktreeNode.Name.Split('_')[2]}";
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
rdbHelper = null;
}
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug("加载新增的任务图斑到树节点失败:" + ex);
MessageHelper.ShowError("加载新增的任务图斑到树节点失败" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 提取地类图斑到监测图斑节点
/// </summary>
/// <param name="TaakPacktreeNode"></param>
/// <param name="WYRWTBOID"></param>
private void WithDrawDLTBToTreeNode(TreeNode TaakPacktreeNode, object NewBGTBOID)
{
IRDBHelper rdbHelper = null;
try
{
if (TaakPacktreeNode == null || TaakPacktreeNode.Data == null || (TaakPacktreeNode.PackageNode.Data as TaskPackage) == null)
{
throw new Exception("获取选中的节点失败!");
}
if (TaakPacktreeNode.NodeLevel != 3)
{
throw new Exception("选中节点不在变更范围上!");
}
if (TaakPacktreeNode.Nodes == null)
TaakPacktreeNode.Nodes = new ObservableCollection<TreeNode>();
IFeature OldBGFeature = DtbFeatureLayer.FeatureClass.GetFeature(TaakPacktreeNode.NodeID.ToInt());
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
rdbHelper.BeginTransaction();
//提取任务图斑
GenerBGTBNewData(OldBGFeature, rdbHelper, NewBGTBOID.ToInt());
TaakPacktreeNode.PackageNode.Name = $"建库任务_{TaakPacktreeNode.PackageNode.Nodes.Count}个图斑_{TaakPacktreeNode.PackageNode.Name.Split('_')[2]}";
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
rdbHelper = null;
}
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug("加载新增的任务图斑到树节点失败:" + ex);
MessageHelper.ShowError("加载新增的任务图斑到树节点失败" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 加载指定外业任务图斑到任务包节点
/// </summary>
/// <param name="TaakPacktreeNode"></param>
/// <param name="WYRWTBFeature"></param>
private void LoadTBToTreeNode(TreeNode RWTBtreeNode, IFeature WYRWTB)
{
IRDBHelper rdbHelper = null;
IWorkspaceEdit workspaceEdit = (WyrwFeatureLayer.FeatureClass as IDataset).Workspace as IWorkspaceEdit;
try
{
if (RWTBtreeNode == null || RWTBtreeNode.Data == null || (RWTBtreeNode.Data as WYRWTB) == null || WYRWTB == null)
{
IFeature WYRWTBFea = WyrwFeatureLayer.FeatureClass.GetFeature(WYRWTB.OID);
WYRWTBFea.Delete();//若是未能获取当前任务包相关信息,则撤销数据插入
return;
}
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
rdbHelper.BeginTransaction();
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
//替换任务图斑图形及相关数据
IFeature OldRWTB = WyrwFeatureLayer.FeatureClass.GetFeature((RWTBtreeNode.Data as WYRWTB).ObjectID);
OldRWTB.Shape = WYRWTB.ShapeCopy;
IArea area1 = WYRWTB.ShapeCopy as IArea;
OldRWTB.set_Value(OldRWTB.Class.FindField("TBMJ"), Math.Round(area1.Area, 2));
double JCMJValue = area1.Area / 666.67;//转化为亩
OldRWTB.set_Value(OldRWTB.Class.FindField("JCMJ"), Math.Round(JCMJValue, 2));
OldRWTB.Store();
(hookHelper.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, WyrwFeatureLayer, null);
workspaceEdit.StopEditing(true);
workspaceEdit.StopEditOperation();
if (workspaceEdit != null)
Marshal.ReleaseComObject(workspaceEdit);
//替换任务图斑节点数据
(RWTBtreeNode.Data as WYRWTB).JCMJ = Math.Round(JCMJValue, 2).ToDecimal(2);
(RWTBtreeNode.Data as WYRWTB).TBMJ = Math.Round(area1.Area, 2).ToDecimal(2);
//替换任务包数据
string egeometry = GeometryConvertHelper.ConverIGometryToJson(OldRWTB.ShapeCopy);
string excuteSQL = $"update WYRW set tbmj='{Math.Round(area1.Area, 2)}',jcmj='{Math.Round(JCMJValue, 2)}',EGeometry='{egeometry}' where JCBH ='{(RWTBtreeNode.Data as WYRWTB).JCBH}'";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
rdbHelper = null;
}
InitBGDataByJCSJ(RWTBtreeNode, true);
MessageHelper.ShowTips("图斑覆盖完成!");
}
catch (Exception ex)
{
workspaceEdit.AbortEditOperation();
workspaceEdit.StopEditing(false);
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug("加载新增的任务图斑到树节点失败:" + ex);
MessageHelper.ShowError("加载新增的任务图斑到树节点失败" + ex.Message);
}
finally
{
if (workspaceEdit != null)
Marshal.ReleaseComObject(workspaceEdit);
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
#endregion
[DllImport("user32")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_WHEEL = 0x0800;
const int MOUSEEVENTF_LEFTUP = 0x0004;//表示鼠标左键释放事件。
private void Movemouse()
{
mouse_event(MOUSEEVENTF_MOVE, 0, 0, 0, 0);
//mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
//如果刪除图斑会移除树节点,这样会导致触发节点选择话事件
private bool isSaving = false;
private void UCTaskPackageTree_OnSaveEditing()
{
string tbbsm = string.Empty;
IFeatureCursor featureCursor = null;
IFeature feature = null;
IRDBHelper rdbHelper = null;
try
{
try
{
Movemouse();
if (uCDTBAllInfo != null)
uCDTBAllInfo.SaveData();
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateEditing || !EngineEditorBG.HasEdits())
return;
if (isSaving) return;
isSaving = true;
#region 模拟滚轮,为了调整图斑后显示方位角
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -10, 0);
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 10, 0);
#endregion
IWorkspaceEdit2 workspaceEdit2 = (IWorkspaceEdit2)EngineEditorBG.EditWorkspace;
IDataChangesEx dataChangesEx = workspaceEdit2.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinSession);
//获取所有变化的要素集
IEnumBSTR modifiedClasses = dataChangesEx.ModifiedClasses;
string modifiedClass = modifiedClasses.Next();
if (string.IsNullOrWhiteSpace(modifiedClass)) return;
while (!string.IsNullOrWhiteSpace(modifiedClass))
{
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
if (CurrentSelectNode != null && CurrentSelectNode.NodeLevel > 0)
CurrentSelectNode.OpenPackageVisibility = Visibility.Collapsed;
if (!modifiedClass.Equals("ZZTB", StringComparison.CurrentCultureIgnoreCase))
{
modifiedClass = modifiedClasses.Next();
continue;
}
}
else
{
if (modifiedClass.Equals("DLTBBG", StringComparison.CurrentCultureIgnoreCase) || modifiedClass.Equals("WYRW", StringComparison.CurrentCultureIgnoreCase)) { }
else
{
modifiedClass = modifiedClasses.Next();
continue;
}
}
if (CurrentSelectNode.NodeLevel == 1)
{
CurrentTaskPackage = CurrentSelectNode.Data as TaskPackage;
}
else
{
CurrentTaskPackage = CurrentSelectNode.PackageNode.Data as TaskPackage;
}
if (CurrentTaskPackage != null)
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
rdbHelper.BeginTransaction();
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
IDifferenceCursorEx differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeDeleteNoChange);
dataOperation.UpdateData_YCL(differenceCursorEx, rdbHelper, 2);
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeUpdateNoChange);
dataOperation.UpdateData_YCL(differenceCursorEx, rdbHelper, 1);
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeInsert);
dataOperation.UpdateData_YCL(differenceCursorEx, rdbHelper, 0);
}
else
{
IDifferenceCursorEx differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeDeleteNoChange);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 2);
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeUpdateNoChange);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 1);
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeInsert);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 0);
}
break;
}
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
rdbHelper = null;
}
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
rdbHelper.DisConnect();
rdbHelper = null;
}
throw ex;
}
finally
{
List<RuleEntity> lstResult = null;
#region 调用质检
if (CurrentWYRWTBTreeNode != null && CurrentWYRWTBTreeNode.Nodes != null && CurrentWYRWTBTreeNode.Data is WYRWTB)
{
lstResult = dataOperation.DTBCheckPackage(CurrentWYRWTBTreeNode);//检查任务包变更范围图斑(质检)
}
else if (CurrentSelectNode != null && CurrentSelectNode.ParentNode != null && CurrentSelectNode.ParentNode.Data is DataRow)
{
dataOperation.SelectedItemChanged(CurrentSelectNode, ref lstResult);
}
if (CheckResultsView != null)
CheckResultsView.InitData(lstResult);
#endregion
UpdateWCAndWWCNum();
if (uCDTBAllInfo != null)
uCDTBAllInfo.InitDTBInfoView();//刷新右侧界面数据
}
}
catch (Exception ex)
{
if (rdbHelper != null)
rdbHelper.Rollback();
if (EngineEditorBG.EditState == esriEngineEditState.esriEngineStateEditing)
{
EngineEditorBG.AbortOperation();
EngineEditorBG.StopOperation("保存同步任务异常");
}
MessageHelper.ShowError("保存失败:" + ex.Message);
LogAPI.Debug("单图斑执行保存异常:" + ex.Message);
LogAPI.Debug("单图斑执行保存异常:" + ex.StackTrace);
}
finally
{
isSaving = false;
if (feature != null)
Marshal.ReleaseComObject(feature);
if (featureCursor != null)
Marshal.ReleaseComObject(featureCursor);
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
private void Instance_NotifyMsgEven2(NotifyMsgPackage msg)
{
switch (msg.MsgType)
{
case "RefreshTreeNodeState":
if (CurrentSelectNode != null && msg.Content.ToTrim() == "已完成")
{
if (CurrentSelectNode.NodeLevel == 3)
{
CurrentSelectNode.ParentNode.PackageState = "已完成";
}
}
else if (msg.Content != null)
RefreshCheckState(msg.Content as List<RuleEntity>);
break;
case "LoadTreeData":
TreeDataSource = dataOperation.LoadTreeData();
tvPackges.ItemsSource = null;
tvPackges.ItemsSource = TreeDataSource;
//this.LoadTreeData();//Instance_NotifyMsgEven2全局调用刷新
break;
case "AfterLoadRefreshTreeData":
this.RefreshTreeData();
break;
case "LoadCheckTBView":
if (CheckResultsView != null)
CheckResultsView.InitData(msg.Content as List<RuleEntity>);
break;
case "WithDrawTBToTreeNode":
if (CurrentSelectNode != null && CurrentSelectNode.NodeLevel == 1)
LoadTBToTreeNode(CurrentSelectNode, msg.Content);
else if (CurrentSelectNode != null && CurrentSelectNode.NodeLevel == 3)
WithDrawDLTBToTreeNode(CurrentSelectNode, msg.Content);
break;
case "CoverRWTBToTreeNode":
if (CurrentWYRWTBTreeNode != null && CurrentWYRWTBTreeNode.NodeLevel == 2)
LoadTBToTreeNode(CurrentWYRWTBTreeNode, msg.Content as IFeature);
break;
case "CheckResultLocation":
string values = string.Empty;
if (msg.Content != null)
values = msg.Content.ToString();
if (TreeDataSource != null && TreeDataSource.Count > 0 && !string.IsNullOrEmpty(values))
{
TreeNode treeNode = GetNode(TreeDataSource[0], values, new List<int>() { 3 });
if (treeNode == null)
{
return;
}
if (treeNode.ParentNode != null && !treeNode.ParentNode.IsExpanded)
{
treeNode.ParentNode.IsExpanded = true;
}
if (treeNode.Checked == false)
{
treeNode.Checked = true;
}
}
break;
case "CheckResultLW":
var lstResult = dataOperation.LoadCheckResult(msg.Content as RuleEntity, true);
UpdateWCAndWWCNum();
if (CheckResultsView != null)
CheckResultsView.InitData(lstResult);
break;
case "RefreshPackageTreeNode":
RefreshPackageTreeNode(msg.Content.ToString());
break;
case "RefreshGeometry":
RefreshGeometry(msg.Content as RuleEntity);
UpdateWCAndWWCNum();
break;
case "Positioning"://定位至选中的节点
if (msg.Content != null)
Positioning(msg.Content);
break;
case "UpdateAttribute"://批量赋属性值 继承
if (msg.Content != null && msg.Content as UpdateAttributeEntity != null)
dataOperation.UpdateFeatureAttribute((msg.Content as UpdateAttributeEntity).feature, (msg.Content as UpdateAttributeEntity).rdbHelper);
break;
case "SignDelete"://图斑 标记删除
SignDelete();
break;
default:
break;
}
}
#region 更新任务包内未完成图斑个数/已完成图斑个数
//更新任务包内未完成图斑个数/已完成图斑个数
private void UpdateWCAndWWCNum()
{
IRDBHelper rdbHelper = null;
try
{
if (!SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("65")) return;
if (CurrentTaskPackage == null || CurrentTaskPackage.PackageTempPath == null) return;
if (CurrentSelectNode == null) return;
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
DataTable dataTable = rdbHelper.ExecuteDatatable("wyrw", "select ZT,TBBSM from wyrw", true);
if (dataTable == null || dataTable.Rows.Count <= 0) return;
CurrentTaskPackage.WCCount = dataTable.Select("ZT='已完成'").Length;
CurrentTaskPackage.WWCCount = dataTable.Select("ZT<>'已完成' and ZT<>'已上传' and ZT<>'已输出'").Length;
if (CurrentSelectNode.NodeLevel == 1)
{
CurrentSelectNode.UncompletedCount = CurrentTaskPackage.WWCCount;
CurrentSelectNode.CompletedCount = CurrentTaskPackage.WCCount;
}
else if (CurrentSelectNode.NodeLevel == 3 && CurrentSelectNode.PackageNode != null)
{
CurrentSelectNode.PackageNode.UncompletedCount = CurrentTaskPackage.WWCCount;
CurrentSelectNode.PackageNode.CompletedCount = CurrentTaskPackage.WCCount;
}
}
catch (Exception ex)
{
LogAPI.Debug("更新任务包内未完成图斑个数/已完成图斑个数 异常:" + ex.Message);
LogAPI.Debug("更新任务包内未完成图斑个数/已完成图斑个数 异常:" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
#endregion
#region 图斑 标记删除
private void SignDelete()
{
IRDBHelper rdbHelper = null;
try
{
if (SystemType != SystemTypeEnum.DTBJK.ToTrim()) return;
if (CurrentSelectNode == null || CurrentTaskPackage == null) return;
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
string strSql = "select * from dtbdltbgx";
if (CurrentSelectNode.NodeLevel == 1)//包一级
{
strSql = $"update dtbdltbgx set isDelete = '1' ";
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text);
CurrentSelectNode.Nodes[0].Nodes.Clear();
CurrentSelectNode.Nodes[0].Name = CurrentSelectNode.Nodes[0].Name.Split('(')[0] + "(0)";
}
else if (CurrentSelectNode.NodeLevel == 3)//变更范围一级
{
strSql = $"update dtbdltbgx set isDelete = '1' where BSM = '{CurrentSelectNode.Name}' ";
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text);
CurrentSelectNode.ParentNode.Nodes.Remove(CurrentSelectNode);
//执行之后 CurrentSelectNode变成第二层级
string name = CurrentSelectNode.Name;
CurrentSelectNode.Name = name.Split('(')[0] + "(" + CurrentSelectNode.Nodes.Count + ")";
}
}
catch (Exception ex)
{
LogAPI.Debug("SignDelete.SignDelete() 异常" + ex.Message);
LogAPI.Debug("SignDelete.SignDelete() 异常" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
#endregion
#region 根据属性表定位树节点
private void Positioning(object feature)
{
try
{
if (feature == null || (feature as IFeature) == null) return;
if (TreeDataSource == null) return;
if (DtbFeatureLayer == null) return;
IFeature BGF = null;
IFeatureSelection featureSelection = DtbFeatureLayer as IFeatureSelection;
featureSelection.SelectionSet.Search(null, false, out ICursor cursor);
// 遍历游标,查找与指定IFeature匹配的要素
IFeatureCursor featureCursor = cursor as IFeatureCursor;
IFeature currentFeature = featureCursor.NextFeature();
while (currentFeature != null)
{
if (currentFeature == feature) // 假设使用OID作为唯一标识符
{
BGF = DtbFeatureLayer.FeatureClass.GetFeature((feature as IFeature).OID);
break;
}
currentFeature = featureCursor.NextFeature();
}
if (BGF == null) return;
string BSMValue = BGF.Value[DtbFeatureLayer.FeatureClass.FindField("BSM")].ToString();
TreeNode BGtreeNode = GetNodeByName(TreeDataSource[0], BSMValue, new List<int>() { 3 });
if (BGtreeNode != null)
{
BGtreeNode.ParentNode.IsExpanded = true;
BGtreeNode.LoadingVisibility = Visibility.Collapsed;
BGtreeNode.IsExpanded = true;
BGtreeNode.Checked = true;
}
}
catch (Exception ex)
{
LogAPI.Debug("Positioning失败:" + ex.Message);
LogAPI.Debug("Positioning失败:" + ex.StackTrace);
}
}
#endregion
private void RefreshPackageTreeNode(string msg)
{
try
{
if (string.IsNullOrWhiteSpace(msg) || !msg.Contains("&")) return;
string tbbsm = msg.Split('&')[0];
string zt = msg.Split('&')[1];
if (string.IsNullOrWhiteSpace(tbbsm)) return;
if (TreeDataSource != null && TreeDataSource.Count > 0)
{
TreeNode treeNode = GetNode(TreeDataSource[0], tbbsm, new List<int>() { 2 });
if (treeNode == null)
{
return;
}
treeNode.PackageState = zt;
}
}
catch (Exception ex)
{
LogAPI.Debug("刷新任务包树节点状态失败:" + ex);
}
}
//修复图形后更新原图形,并更新包数据
private void RefreshGeometry(RuleEntity ruleEntity)
{
if (ruleEntity == null) return;
IRDBHelper rDBHelper = null;
IFeature feature = null;
try
{
if (CurrentTaskPackage == null || !File.Exists(CurrentTaskPackage.PackageTempPath))
return;
IVerificationOfFeatureNodeDensity taskHelper = BundleRuntime.Instance.GetFirstOrDefaultService<IVerificationOfFeatureNodeDensity>();
IFeatureCursor jcCursor = DtbFeatureLayer.FeatureClass.Update(new QueryFilter() { WhereClause = $"BSM='{ruleEntity.ErrorId}' " }, true);
rDBHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
while ((feature = jcCursor.NextFeature()) != null)
{
feature.Shape = taskHelper.RepairGeometry(feature.ShapeCopy);
jcCursor.UpdateFeature(feature);
string egeometry = GeometryConvertHelper.ConverIGometryToJson(feature.Shape);
rDBHelper.ExecuteNonQueryWithException($"update dtbdltbgx set EGeometry = '{egeometry}' where BSM='{ruleEntity.ErrorId}' ", CommandType.Text);
}
jcCursor.Flush();
rDBHelper.ExecuteNonQueryWithException($"delete from CheckResult where RuleCode='{ruleEntity.RuleCode}' and ErrorId='{ruleEntity.ErrorId}' and tbbsm='{ruleEntity.TBBSM}'", CommandType.Text);
LoadCheckResult();
}
catch (Exception ex)
{
LogAPI.Debug("RefreshGeometry失败:" + ex.Message);
LogAPI.Debug("RefreshGeometry失败:" + ex.StackTrace);
}
finally
{
if (feature != null)
Marshal.ReleaseComObject(feature);
if (rDBHelper != null)
rDBHelper.DisConnect();
}
}
private void GenerBGTBNewData(IFeature OldBGFeature, IRDBHelper rdbHelper, int NewBGTBOID)
{
try
{
IFeature JCDLTBFeature = DLTBFeatureLayer.FeatureClass.GetFeature(NewBGTBOID);
int BSMIndex = OldBGFeature.Fields.FindField("BSM");
//int TBYBHIndex = OldBGFeature.Fields.FindField("TBYBH");
List<IFeature> features = FeatureAPI.Identify2(JCDLTBFeature.ShapeCopy, DtbFeatureLayer);
if (features.Count == 1)//覆盖当前位置范围
{
OldBGFeature.Shape = JCDLTBFeature.ShapeCopy;
OldBGFeature.Store();
string egeometry = GeometryConvertHelper.ConverIGometryToJson(OldBGFeature.ShapeCopy);
string strSql = $"update dtbdltbgx set EGeometry = '{egeometry}' where bsm ='{OldBGFeature.Value[BSMIndex].ToString()}'";
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text);
}
else if (features.Count > 1)
{
}
}
catch (Exception)
{
throw new Exception("覆盖变更范围失败!");
}
}
/// <summary>
/// 复制监测图斑图形
/// </summary>
/// <param name="treeNode"></param>
private void CopyJCTBToDLTBGX(TreeNode treeNode)
{
IRDBHelper rdbHelper = null;
try
{
if (treeNode.Data is WYRWTB)
{
IFeature wyFeature = WyrwFeatureLayer.FeatureClass.GetFeature(int.Parse(treeNode.NodeID.ToString()));
if (wyFeature == null || wyFeature.Shape.IsEmpty)
{
MessageHelper.Show("外业任务图斑图形为空:" + treeNode.NodeID.ToString());
return;
}
string tbbsm = (treeNode.Data as WYRWTB).TBBSM;
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{tbbsm}'"
};
IFeatureCursor cursor = DtbFeatureLayer.FeatureClass.Search(queryFilter, false);
IFeature feature = null;
while ((feature = cursor.NextFeature()) != null)
{
feature.Shape = wyFeature.ShapeCopy;
feature.Store();
}
//cursor.Flush();
rdbHelper = RDBFactory.CreateDbHelper($"{(treeNode.ParentNode.Data as TaskPackage).PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
{
string egeometry = GeometryConvertHelper.ConverIGometryToJson(wyFeature.ShapeCopy);
string strSql = $"update dtbdltbgx set EGeometry = '{egeometry}' where tbbsm ='{tbbsm}'";
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text);
}
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
}
if (cursor != null)
{
Marshal.ReleaseComObject(cursor);
}
if (wyFeature != null)
{
Marshal.ReleaseComObject(wyFeature);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("复制监测图斑图形异常:" + ex.Message);
LogAPI.Debug("复制监测图斑图形异常:" + ex.StackTrace);
MessageHelper.ShowError("复制监测图斑图形异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
MapsManager.Instance.MapService.getAxMapControl().Refresh();
}
}
/// <summary>
/// 更新省级审核意见信息表
/// </summary>
/// <param name="treeNode"></param>
private void UpdateSJSHYJXXdetailjson(TreeNode treeNode)
{
IRDBHelper rdbHelper = null;
try
{
if (treeNode.Data is WYRWTB)
{
CurrentSelectNode = treeNode;
string tbbsm = (treeNode.Data as WYRWTB).TBBSM;
if (treeNode.ParentNode == null || treeNode.ParentNode.Data == null || !(treeNode.ParentNode.Data is TaskPackage)) return;
CurrentTaskPackage = CurrentSelectNode.ParentNode.Data as TaskPackage;
rdbHelper = RDBFactory.CreateDbHelper($"{(treeNode.ParentNode.Data as TaskPackage).PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
string ywlx = UserLoginHelper.GetAppsetingValueByKey("YWLX");
if (string.IsNullOrEmpty(ywlx))
{
MessageBox.Show("业务类型获取失败", "提示信息", MessageBoxButton.OK);
return;
}
IJKTBTask taskHelper = new JKTBTaskHelper();
var jktbDataInfo = taskHelper.GetJKTBData(tbbsm, ywlx.Split(',')[0]);
if (jktbDataInfo == null)
{
LogAPI.Debug($"UpdateSJSHYJXXdetailjson 接口获取数据为空:TBBSM:{tbbsm}, 未获取到接口返回数据。");
MessageHelper.Show($"TBBSM : {tbbsm} 接口获取数据为空!");
return;
}
#region 保存省级审核意见信息表
if (jktbDataInfo.WYRW == null || jktbDataInfo.WYRW.Count <= 0)
{
LogAPI.Debug($"UpdateSJSHYJXXdetailjson 异常信息:TBBSM:{tbbsm},WYRW表没有数据。");
return;
}
else
{
if (!string.IsNullOrEmpty(jktbDataInfo.WYRW[0].detailjson))
{
var detailjson = jktbDataInfo.WYRW[0].detailjson.ToString().Substring(1, jktbDataInfo.WYRW[0].detailjson.Length - 2).Split(',').ToList();
rdbHelper.ExecuteNonQuery($"delete from detailjson where tbbsm='{tbbsm}'", System.Data.CommandType.Text);
StringBuilder stringBuilder = new StringBuilder();
foreach (var item in detailjson)
{
var sql = "";
if (!item.Contains(':'))
sql = $"INSERT INTO detailjson (Name,Value,tbbsm)VALUES( '{item.ToString().ToTrim().Trim('"')}','{item.ToString().ToTrim().Trim('"')}','{tbbsm}');";
else
sql = $"INSERT INTO detailjson (Name,Value,tbbsm)VALUES( '{item.Split(':')[0].ToString().ToTrim().Trim('"')}','{item.Split(':')[1].ToString().ToTrim().Trim('"')}','{tbbsm}');";
stringBuilder.Append(sql);
}
rdbHelper.ExecuteNonQuery(stringBuilder.ToString(), System.Data.CommandType.Text);
}
}
#endregion
if (rdbHelper != null)
{
rdbHelper.DisConnect();
rdbHelper = null;
}
#region 更新页面
List<RuleEntity> lstResult = null;
NYYSInfo nYYSInfo = dataOperation.SelectedItemChanged(CurrentSelectNode, ref lstResult);
uCDTBAllInfo.BindDataInfo(nYYSInfo);
#endregion
MessageHelper.ShowTips("更新省级审核意见信息表完成。");
}
}
catch (Exception ex)
{
LogAPI.Debug("更新省级审核意见信息表异常:" + ex.Message);
LogAPI.Debug("更新省级审核意见信息表异常:" + ex.StackTrace);
MessageHelper.ShowError("更新省级审核意见信息表异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
rdbHelper = null;
}
}
}
#region 图斑列表右键目录功能
/// <summary>
/// 初始化图斑
/// </summary>
/// <param name="sender"></param>
/// <param name="IsDirectoverlay">是否直接初始化</param>
private void InitBGDataByJCSJ(TreeNode treeNode, bool IsDirectoverlay = false)
{
IRDBHelper rdbHelper = null;
try
{
if (treeNode.Data is DataRow)//初始化矢量数据图斑
{
if (treeNode.Nodes.Count > 0)
{
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips("是否覆盖已有变更范围?");
if (dialogResult != System.Windows.Forms.DialogResult.Yes)
{
return;
}
}
var v = DtbFeatureLayer.FeatureClass as FeatureClass;
string TBBSMValue = (treeNode.Data as DataRow)["TBBSM"].ToString();
if (string.IsNullOrWhiteSpace(TBBSMValue))
{
TBBSMValue = (treeNode.Data as DataRow)["JCBH"].ToString();
v.Workspace.ExecuteSQL(string.Format("DELETE FROM DLTBBG where TBYBH='{0}'", TBBSMValue));
}
else
v.Workspace.ExecuteSQL(string.Format("DELETE FROM DLTBBG where tbbsm='{0}'", TBBSMValue));
treeNode.Nodes.Clear();//初始化变更图斑
IFeature JCfeature = (treeNode.ParentNode.Data as IFeatureLayer).FeatureClass.GetFeature(treeNode.NodeID.ToString().ToInt());
if (DtbFeatureLayer == null)
DtbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
IFeatureCursor BGcursor = DtbFeatureLayer.FeatureClass.Insert(true);
IFeatureBuffer BGbuffer = DtbFeatureLayer.FeatureClass.CreateFeatureBuffer();
BGbuffer.Shape = JCfeature.ShapeCopy;
IFields fields = JCfeature.Fields;//JC
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.get_Field(i);
if (BGbuffer.Fields.FindField(field.Name) != -1 && field.Name.ToUpper() == "SFJZ")
{
BGbuffer.Value[BGbuffer.Fields.FindField(field.Name)] = "0";//当前仅为“SFJZ”为不可为空情况
}
else if (BGbuffer.Fields.FindField(field.Name) != -1 && field.Editable == true && field.Name.ToUpper() != "SHAPE_AREA")
{
BGbuffer.Value[BGbuffer.Fields.FindField(field.Name)] = JCfeature.Value[i];
}
}
BGbuffer.Value[BGbuffer.Fields.FindField("TBBH")] = "";
//陕西需求
BGbuffer.Value[BGbuffer.Fields.FindField("TBYBH")] = JCfeature.Value[JCfeature.Fields.FindField("JCBH")].ToString();
IArea area1 = JCfeature.ShapeCopy as IArea;
BGbuffer.Value[BGbuffer.Fields.FindField("TBMJ")] = Math.Round(area1.Area, 2);//图斑面积
if (BGbuffer.Fields.FindField("GLTC") > -1)
BGbuffer.Value[BGbuffer.Fields.FindField("GLTC")] = ((IDataset)JCfeature.Class).Name;//关联图层
BGbuffer.Value[BGbuffer.Fields.FindField("BSM")] = Guid.NewGuid().ToTrim().Replace("-", "").Substring(0, 18);
object OIDXZ = BGcursor.InsertFeature(BGbuffer);
BGcursor.Flush();
IFeature DTBBgF = DtbFeatureLayer.FeatureClass.GetFeature(Convert.ToInt32(OIDXZ));
TreeNode bgfwNode = new TreeNode()//第四级-变更图斑
{
Name = BGbuffer.Value[BGbuffer.Fields.FindField("BSM")] as string,
Paixu = 1,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeID = OIDXZ,
NodeLevel = 3,
Data = DTBBgF,
ParentNode = treeNode,
PackageNode = treeNode.ParentNode,//图层一级
PackageState = "未完成"
};
treeNode.Nodes.Add(bgfwNode);
treeNode.Name = JCfeature.Value[JCfeature.Fields.FindField("JCBH")] + $"({treeNode.Nodes.Count})";
if (BGcursor != null)
Marshal.ReleaseComObject(BGcursor);
if (BGbuffer != null)
Marshal.ReleaseComObject(BGbuffer);
if (JCfeature != null)
Marshal.ReleaseComObject(JCfeature);
}
else if (treeNode.Data is WYRWTB) //初始化任务包数据图斑
{
if (treeNode.Nodes.Count > 0 && !IsDirectoverlay)
{
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips("是否覆盖已有变更范围?");
if (dialogResult != System.Windows.Forms.DialogResult.Yes)
{
return;//不覆盖当前图斑则不进行图斑初始化
}
treeNode.Nodes.Clear();//初始化变更图斑
treeNode.Name = (treeNode.Data as WYRWTB).TBBSM + $"({treeNode.Nodes.Count})";
}
else//IsDirectoverlay 是否直接初始化
{
treeNode.Nodes.Clear();//初始化变更图斑
}
#region 删除当前外业任务图斑下的变更图斑
//首先获取到当前外业图斑
IFeature wyFeature = WyrwFeatureLayer.FeatureClass.GetFeature(int.Parse(treeNode.NodeID.ToString()));
if (wyFeature == null || wyFeature.Shape.IsEmpty)
{
MessageHelper.Show("外业任务图斑图形为空:" + treeNode.NodeID.ToString());
return;
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{(treeNode.Data as WYRWTB).TBBSM}'"
};
dataOperation.StartEdit(DtbFeatureLayer);//StartEditForDTBJK(EngineEditorBG, DtbFeatureLayer);
EngineEditorBG.StartOperation();
IFeatureCursor cursor = DtbFeatureLayer.FeatureClass.Search(queryFilter, false);
IFeature feature = null;
while ((feature = cursor.NextFeature()) != null)
{
feature.Delete();
}
#endregion
//新增外业任务图斑
IFeature newFeature = DtbFeatureLayer.FeatureClass.CreateFeature();
newFeature.Shape = wyFeature.ShapeCopy;
newFeature.set_Value(newFeature.Fields.FindField("BSM"), Guid.NewGuid().ToString().Replace("-", ""));
newFeature.set_Value(newFeature.Fields.FindField("TBBSM"), (treeNode.Data as WYRWTB).TBBSM);
rdbHelper = RDBFactory.CreateDbHelper($"{(treeNode.ParentNode.Data as TaskPackage).PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
{
//恢复已删除的外业照片
rdbHelper.BeginTransaction();
rdbHelper.ExecuteNonQueryWithException($"update wyhcfj set UserDelete=0 WHERE HCJLBSM='{(treeNode.Data as WYRWTB).TBBSM}'", CommandType.Text);
//继承外业属性字段
DataTable dataTable = rdbHelper.ExecuteDatatable("data", $"select HCBGDL as DLBM,WBGYY,ZZSX AS ZZSXDM,TBXHSX AS TBXHDM,(case when length(replace(ddtcxx,' ',''))< 4 then '一般地类' else replace(ddtcxx,' ','') end) AS DDTCBZ,GDLX,cast(XZDLKD as numeric) AS XZDWKD from wyhccg where hcrwbsm='{CurrentWYRWTB.TBBSM}'", true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
foreach (DataColumn item in dataTable.Columns)
{
int fieldIndex = newFeature.Fields.FindField(item.ColumnName);
if (fieldIndex > -1)
{
newFeature.set_Value(fieldIndex, dataTable.Rows[0][item.ColumnName]);
}
}
}
}
newFeature.Store();
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
}
EngineEditorBG.StopOperation("初始化任务包变更图斑");
dBLoadHelper.SaveEingineEdit(this.hookHelper);
EngineEditorBG.StopEditing(true);
MapsManager.Instance.MapService.getAxMapControl().CurrentTool = null;
#region 释放初始化图斑变量
if (cursor != null)
{
Marshal.ReleaseComObject(cursor);
}
if (wyFeature != null)
{
Marshal.ReleaseComObject(wyFeature);
}
#endregion
}
}
catch (Exception ex)
{
if (EngineEditorBG != null)
{
EngineEditorBG.AbortOperation();
}
LogAPI.Debug("初始化图斑变量" + ex.Message);
MessageHelper.ShowError("初始化图斑变量" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
MapsManager.Instance.MapService.getAxMapControl().Refresh();
}
}
/// <summary>
/// 树节点右键菜单:清空变更范围事件
/// </summary>
private void ClearZZTBData(TreeNode treeNode)
{
IWorkspaceAPI workspaceAPI = null;
IRDBHelper rdbHelper = null;
try
{
if (treeNode.Data is WYRWTB)
{
TaskPackage CurrentTaskPackage = treeNode.ParentNode.Data as TaskPackage;
if (CurrentTaskPackage == null)
{
return;
}
if (!File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("未找到任务包:" + CurrentTaskPackage.PackageTempPath);
return;
}
if (MessageHelper.ShowYesNoAndTips("是否确定清空变更范围数据(清空后无法恢复,请谨慎操作)?") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
rdbHelper.BeginTransaction();
rdbHelper.ExecuteNonQueryWithException($"delete from dtbdltbgx where tbbsm='{(treeNode.Data as WYRWTB).TBBSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from PZWJ where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBDLTBGXGC where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBLSYDGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBTTQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBGFBQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBCCWJQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBCZCDYDGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBLMFWGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
workspaceAPI = new WorkspaceAPI(CurrentTaskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM DLTBBG where bid='{0}' and tbbsm='{1}'", CurrentTaskPackage.BID, (treeNode.Data as WYRWTB).TBBSM));
rdbHelper.Commit();
treeNode.Nodes.Clear();
treeNode.Name = (treeNode.Data as WYRWTB).TBBSM + "(0)";
}
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug(ex);
MessageHelper.ShowError("清空当前任务包变更范围数据异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
if (workspaceAPI != null)
{
workspaceAPI.CloseWorkspace();
}
}
}
/// <summary>
/// 导入变更范围(任务包数据)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LeadIntoBGData(TreeNode treeNode)
{
try
{
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{(treeNode.Data as WYRWTB).TBBSM}'"
};
IFeatureCursor featureCursor = WyrwFeatureLayer.FeatureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
if (feature == null)
{
MessageHelper.ShowTips($"外业任务图层未找到TBBSM={(treeNode.Data as WYRWTB).TBBSM}的外业图斑!");
return;
}
frmDataImport = new UCBGDataImport()
{
TargetLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"),
TBBSM = (treeNode.Data as WYRWTB).TBBSM,
WYRWTB = feature.ShapeCopy,
Title = "导入变更范围",
TreeDanNode = treeNode
};
frmDataImport.ImpComplate += ImpComplate;
frmDataImport.WindowStartupLocation = WindowStartupLocation.Manual;
frmDataImport.Left = 240;
frmDataImport.Top = 110;
frmDataImport.Closed += FrmDataImport_Closed;
frmDataImport.ShowInMainWindow(true);
}
catch (Exception ex)
{
MessageHelper.ShowError("预处理-自主图斑节点右键数据导入异常:" + ex);
LogAPI.Debug("预处理-自主图斑节点右键数据导入异常:" + ex);
}
}
/// <summary>
/// 导入变更范围-关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmDataImport_Closed(object sender, EventArgs e)
{
try
{
if (frmDataImport != null)
{
frmDataImport.Close();
}
frmDataImport = null;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
/// <summary>
/// 矢量数据导入完成后,继续要数据导入到任务包中
/// </summary>
/// <param name="pIsComplate"></param>
private void ImpComplate(bool pIsComplate, List<string> listBSM, TreeNode CurrentSelectNode)
{
IRDBHelper rdbHelper = null;
IFeatureCursor featureCursor = null;
IFeature feature = null;
TaskPackage CurrentTaskPackage = CurrentSelectNode.ParentNode.Data as TaskPackage;
WYRWTB CurrentWYRWTB = CurrentSelectNode.Data as WYRWTB;
try
{
if (!pIsComplate || CurrentTaskPackage == null || CurrentSelectNode == null)
{
return;
}
this.ShowLoading("正在更新任务包......", 0, 0);
System.Threading.Thread.Sleep(1000);
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{CurrentWYRWTB.TBBSM}'"
};
featureCursor = DtbFeatureLayer.FeatureClass.Search(queryFilter, true);
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
rdbHelper.BeginTransaction();
rdbHelper.ExecuteNonQueryWithException($"delete from dtbdltbgx where tbbsm='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
List<string> lstField = new List<string>() { "BSM", "TBBSM", "YSDM", "TBYBH", "TBBH", "DLBM", "DLMC", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "TBMJ", "KCDLBM", "KCXS", "KCMJ", "TBDLMJ", "GDLX", "GDPDJB", "XZDWKD", "TBXHDM", "TBXHMC", "ZZSXDM", "ZZSXMC", "GDDB", "FRDBS", "CZCSXM", "SJNF", "MSSM", "HDMC", "BZ", "GXSJ", "TBLX", "DDTCBZ", "DDTCMC", "SFGX", "WBGYY", "SFJZ", "QKSM", "LJLX", "DCJL", "YWTBSM", "EGeometry", "ZXDX", "ZXDY", "MAXX", "MAXY", "MINX", "MINY", "JKRY" };
string insertSQL = "INSERT INTO dtbdltbgx (BSM, TBBSM, YSDM, TBYBH, TBBH, DLBM, DLMC, QSXZ, QSDWDM, QSDWMC, ZLDWDM, ZLDWMC, TBMJ, KCDLBM, KCXS, KCMJ, TBDLMJ, GDLX, GDPDJB, XZDWKD, TBXHDM, TBXHMC, ZZSXDM, ZZSXMC, GDDB, FRDBS, CZCSXM, SJNF, MSSM, HDMC, BZ, GXSJ, TBLX, DDTCBZ, DDTCMC, SFGX, WBGYY, SFJZ, QKSM, LJLX, DCJL, YWTBSM, EGeometry, ZXDX, ZXDY, MAXX, MAXY, MINX, MINY, JKRY) VALUES({0})";
int indexBSM = DtbFeatureLayer.FeatureClass.Fields.FindField("BSM");
while ((feature = featureCursor.NextFeature()) != null)
{
string bsm = string.Empty;
string valueString = string.Empty;
foreach (string item in lstField)
{
if (item.Equals("EGeometry", StringComparison.CurrentCultureIgnoreCase))
{
valueString += "'" + DTBDBLoadHelper.ConverIGometryToJson(feature.ShapeCopy) + "',";
continue;
}
if (item.Equals("TBBSM", StringComparison.CurrentCultureIgnoreCase))
{
valueString += "'" + CurrentWYRWTB.TBBSM + "',";
continue;
}
int index = feature.Fields.FindField(item);
if (index > -1)
{
object obj = feature.get_Value(index);
IField field = feature.Fields.Field[index];
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeOID:
case esriFieldType.esriFieldTypeBlob:
if (obj == null || obj == DBNull.Value)
{
valueString += "0,";
}
else
{
valueString += obj + ",";
}
break;
default:
valueString += "'" + obj + "',";
break;
}
}
else
{
valueString += "'',";
}
}
if (indexBSM > -1)
{
bsm = feature.get_Value(indexBSM) as string;
}
string kjashd = string.Format(insertSQL, valueString.TrimEnd(','));
rdbHelper.ExecuteNonQueryWithException(string.Format(insertSQL, valueString.TrimEnd(',')), CommandType.Text);
DTBDBLoadHelper.SaveGXGCData(bsm, CurrentWYRWTB.TBBSM, feature, rdbHelper, this.hookHelper);
}
rdbHelper.Commit();
if (hookHelper.Hook is IMapControlDefault mapControl)
{
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, mapControl.ActiveView.Extent);
mapControl.ActiveView.Extent = (DtbFeatureLayer as ILayer).AreaOfInterest;
}
var wyrwtb = CurrentSelectNode.Data as WYRWTB;
LoadDBToTreeNode(CurrentSelectNode.ParentNode);
this.CloseLoading();
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug(ex);
this.CloseLoading();
if (ex.Message.Contains("UNIQUE constraint failed"))
MessageHelper.ShowError("BSM重复,请修改后再导入!");
else
MessageHelper.ShowError("导入更新任务包(" + CurrentTaskPackage.PackageTempPath + ")失败:" + ex.Message);
}
finally
{
this.CloseLoading();
if (feature != null)
{
Marshal.ReleaseComObject(feature);
}
if (featureCursor != null)
{
Marshal.ReleaseComObject(featureCursor);
}
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
#endregion
private List<ContentMenu> contentMenus = new List<ContentMenu>();
/// <summary>
/// 设置节点菜单
/// </summary>
/// <param name="treeNode">树节点</param>
private void SetContentMenu(TreeNode treeNode, bool IsXML)
{
try
{
string layerConfigsPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "工作空间DTBJK", "DTBConfigs", "LoadContentMenuConfig.xml");
if (File.Exists(layerConfigsPath) && contentMenus.Count == 0)
{
XDocument xDoc = XDocument.Load(layerConfigsPath);
XElement configElement = xDoc.Element("ContentMenu");
XElement jcsjLayersElment = configElement.Element("Menus");
if (jcsjLayersElment != null)
{
foreach (XElement item in jcsjLayersElment.Elements("Menu"))
{
ContentMenu Menu = new ContentMenu
{
Header = item.Attribute("Header").Value,
SystemType = item.Attribute("SystemType").Value,
Visible = item.Attribute("Visible").Value.ToLower() == "true" ? true : false
};
contentMenus.Add(Menu);
}
}
}
if (SystemType == SystemTypeEnum.DTBJK.ToTrim())
{
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
if (treeNode.NodeLevel == 0 || (treeNode.NodeLevel == 1 && treeNode.Data is IFeatureLayer))//父节点
{
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部展开叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 1 && treeNode.Data is TaskPackage)//任务包节点
{
menuItem = new MenuItem();
menuItem.Header = "导出成果包";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/成果导出.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (ucJKResultExport == null)
{
ucJKResultExport = new UCJKResultExport()//树目录功能菜单页
{
hookHelper = hookHelper,
Width = 900,
Height = 450,
Title = "成果输出",
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
ucJKResultExport.Closed += UcJKResultExport_Closed;
ucJKResultExport.BID = (treeNode.Data as TaskPackage).BID;
ucJKResultExport.BindData();
ucJKResultExport.ShowInMainForm(true);
}
}
catch (Exception ex)
{
if (ucJKResultExport != null)
{
ucJKResultExport.Close();
ucJKResultExport = null;
}
LogAPI.Debug("导出成果包详情异常:" + ex.Message);
MessageHelper.ShowError("导出成果包异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "批量赋属性值";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/编辑要素属性.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
SetBatchAttribute(treeNode.Data as TaskPackage);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "打开所在文件夹";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/菜单图标.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
System.Diagnostics.Process.Start("explorer.exe", System.IO.Path.GetDirectoryName((treeNode.Data as TaskPackage).PackagePath));
}
catch (Exception ex)
{
LogAPI.Debug("打开所在文件夹 失败:" + ex);
MessageHelper.ShowError(ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}//任务包节点
else if (treeNode.NodeLevel == 2 && treeNode.Data is DataRow)//矢量检测图斑数据
{
menuItem = new MenuItem();
menuItem.Header = "初始化图斑";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/初始化.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
InitBGDataByJCSJ(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "清空变更范围";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/删除图斑.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips("是否清空变更范围?");
if (dialogResult != System.Windows.Forms.DialogResult.Yes)
{
return;
}
treeNode.Nodes.Clear();
string JCBHValue = (treeNode.Data as DataRow)["JCBH"].ToString();
treeNode.Name = $"{JCBHValue}(0)";
(DtbFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("DELETE FROM DLTBBG where tbbsm='{0}'", JCBHValue));
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 2 && treeNode.Data is WYRWTB) //任务包二级节点:监测图斑
{
WYRWTB wYRWTB = treeNode.Data as WYRWTB;
menuItem = new MenuItem();
menuItem.Header = "变更检查";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/变更检查.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
DTBCheckPackage(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "取消返外业";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/返外业.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
UpdateState(treeNode, (treeNode.ParentNode.Data as TaskPackage), "取消返外业");
DTBCheckPackage(treeNode);//取消“返外业”后的图斑检查
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "初始化图斑";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/初始化.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
InitBGDataByJCSJ(treeNode);//任务包-初始化图斑
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制监测图斑图形";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/设置图形.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyJCTBToDLTBGX(treeNode);//复制监测图斑图形到变更范围
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "更新省级审核意见信息表";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/更新表.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
UpdateSJSHYJXXdetailjson(treeNode);//更新省级审核意见信息表
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "导入变更范围";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/菜单图标.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
LeadIntoBGData(treeNode);//导入变更范围
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "追加外业成果";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/追加.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
AddDTBWYResult();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "导出外业成果";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/成果导出.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
ExportResult();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "清空变更范围";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/删除图斑.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
ClearZZTBData(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 3 && treeNode.Data is DTBDLTBGX)
{
//推土区按基础库上图 1303
menuItem = new MenuItem();
menuItem.Header = "推土区按基础库上图";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/推土区.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
GraphAccordingBasicLibrary(treeNode, "1303");
SaveDTTC(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
//拆除未尽区按基础库上图 1304
menuItem = new MenuItem();
menuItem.Header = "拆除未尽区按基础库上图";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/推土区.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
GraphAccordingBasicLibrary(treeNode, "1304");
SaveDTTC(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
//光伏板区按基础库上图 1302
menuItem = new MenuItem();
menuItem.Header = "光伏板区按基础库上图";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/推土区.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
GraphAccordingBasicLibrary(treeNode, "1302");
SaveDTTC(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
//临时用地按基础库上图 1301
menuItem = new MenuItem();
menuItem.Header = "临时用地按基础库上图";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/推土区.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
GraphAccordingBasicLibrary(treeNode, "1301");
SaveDTTC(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
if (contextMenu.Items == null || contextMenu.Items.Count <= 0)
{
treeNode.cMenu = null;
}
else
{
treeNode.cMenu = contextMenu;
}
}
else if (SystemType == SystemTypeEnum.RCBGJK.ToTrim())
{
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
if (treeNode.NodeLevel == 0 || (treeNode.NodeLevel == 1 && treeNode.Data is IFeatureLayer))//父节点
{
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部展开叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 2 && treeNode.Data is DataRow)//矢量检测图斑数据
{
menuItem = new MenuItem();
menuItem.Header = "初始化图斑";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/初始化.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
InitBGDataByJCSJ(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "清空变更范围";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/删除图斑.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips("是否清空变更范围?");
if (dialogResult != System.Windows.Forms.DialogResult.Yes)
{
return;
}
treeNode.Nodes.Clear();
string asjh = (treeNode.Data as DataRow)["JCBH"].ToString();
(DtbFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("DELETE FROM DTBDLTBGX where tbybh='{0}'", (treeNode.Data as DataRow)["JCBH"].ToString()));
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 3 && treeNode.Data is IFeature)
{
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
if (contextMenu.Items == null || contextMenu.Items.Count <= 0)
{
treeNode.cMenu = null;
}
else
{
treeNode.cMenu = contextMenu;
}
}
else if (SystemType == SystemTypeEnum.WYZS.ToTrim())
{
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
if (treeNode.NodeLevel == 0 || (treeNode.NodeLevel == 1 && treeNode.Data is IFeatureLayer))//父节点
{
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部展开叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 1 && treeNode.Data is TaskPackage)//任务包节点
{
menuItem = new MenuItem();
menuItem.Header = "导出成果包";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/成果导出.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (ucJKResultExport == null)
{
ucJKResultExport = new UCJKResultExport()//树目录功能菜单页
{
hookHelper = hookHelper,
Width = 900,
Height = 450,
Title = "成果输出",
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
ucJKResultExport.Closed += UcJKResultExport_Closed;
ucJKResultExport.BID = (treeNode.Data as TaskPackage).BID;
ucJKResultExport.BindData();
ucJKResultExport.ShowInMainForm(true);
}
}
catch (Exception ex)
{
if (ucJKResultExport != null)
{
ucJKResultExport.Close();
ucJKResultExport = null;
}
LogAPI.Debug("导出成果包详情异常:" + ex.Message);
MessageHelper.ShowError("导出成果包异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "打开所在文件夹";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/菜单图标.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
System.Diagnostics.Process.Start("explorer.exe", System.IO.Path.GetDirectoryName((treeNode.Data as TaskPackage).PackagePath));
}
catch (Exception ex)
{
LogAPI.Debug("打开所在文件夹 失败:" + ex);
MessageHelper.ShowError(ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}//任务包节点
else if (treeNode.NodeLevel == 2 && treeNode.Data is WYRWTB) //任务包二级节点:监测图斑
{
WYRWTB wYRWTB = treeNode.Data as WYRWTB;
menuItem = new MenuItem();
menuItem.Header = "变更检查";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/变更检查.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
DTBCheckPackage(treeNode);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "取消返外业";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/返外业.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
UpdateState(treeNode, (treeNode.ParentNode.Data as TaskPackage), "取消返外业");
DTBCheckPackage(treeNode);//取消“返外业”后的图斑检查
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "导出外业成果";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/成果导出.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
ExportResult();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 3 && treeNode.Data is DTBDLTBGX)
{
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
if (contextMenu.Items == null || contextMenu.Items.Count <= 0)
{
treeNode.cMenu = null;
}
else
{
treeNode.cMenu = contextMenu;
}
}
else if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = null;
if (treeNode.NodeLevel == 0)//父节点
{
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (TreeDataSource != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部展开叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 1)
{
menuItem = new MenuItem();
menuItem.Header = "导出成果包";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/成果导出.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
BtnExportPackage_MouseLeftButtonUp(null, null);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "批量标记外业";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/标记.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
SetSFWY(1);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "批量标记不外业";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/标记.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
SetSFWY(0);
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "打开所在文件夹";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/打开文件夹.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (CurrentTaskPackage == null)
{
return;
}
System.Diagnostics.Process.Start("explorer.exe", System.IO.Path.GetDirectoryName(CurrentTaskPackage.PackagePath));
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部折叠";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/折叠.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (treeNode != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = false);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部折叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "全部展开";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/展开.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
try
{
if (treeNode != null)
{
treeNode.Nodes.ForEach(x => x.IsExpanded = true);
}
}
catch (Exception ex)
{
LogAPI.Debug("全部展开叠异常:" + ex.Message);
}
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 2 && treeNode.Name.StartsWith("自主图斑"))//图斑分组节点,下发图斑图斑是不可以新增的,只有自主变更才可以新增
{
menuItem = new MenuItem();
menuItem.Header = "导入自主图斑";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/导入.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
BtnImportZZTB_MouseLeftButtonUp(null, null);
});
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "清空自主图斑";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/清空.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
ClearZZTBData();
});
contextMenu.Items.Add(menuItem);
}
else if (treeNode.NodeLevel == 3)//图斑根节点
{
menuItem = new MenuItem();
menuItem.Header = "追加外业成果";
menuItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/追加.png", UriKind.RelativeOrAbsolute))
};
//menuItem.Click += MenuItem_Click;
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
AddWYResult();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.Header = "复制名称";
menuItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/Kingo.Plugin.General;component/Resources/复制.png", UriKind.RelativeOrAbsolute))
};
menuItem.Click += new RoutedEventHandler((sender, e) =>
{
CopyName();
});
if (contentMenus.FirstOrDefault(x => x.Visible == true && x.SystemType.Equals(SystemType) && x.Header.Equals(menuItem.Header)) != null)
contextMenu.Items.Add(menuItem);
}
//treeNode.cMenu = contextMenu;
if (contextMenu.Items == null || contextMenu.Items.Count <= 0)
{
treeNode.cMenu = null;
}
else
{
treeNode.cMenu = contextMenu;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("节点菜单项执行失败:" + ex);
throw ex;
}
}
/// <summary>
/// 批量赋属性值
/// </summary>
private void SetBatchAttribute(TaskPackage taskPackage)
{
if (taskPackage == null) return;
try
{
if (ucSetBatchAttribute == null)
{
ucSetBatchAttribute = new UCSetBatchAttribute()//树目录功能菜单页
{
Width = 500,
Height = 600,
Title = "批量赋属性值",
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
ucSetBatchAttribute.Closed += UcSetBatchAttribute_Closed;
ucSetBatchAttribute.BindData(taskPackage);
ucSetBatchAttribute.ShowInMainForm(true);
}
}
catch (Exception ex)
{
if (ucSetBatchAttribute != null)
{
ucSetBatchAttribute.Close();
ucSetBatchAttribute = null;
}
LogAPI.Debug("批量赋属性值异常:" + ex.Message);
LogAPI.Debug("批量赋属性值异常:" + ex.StackTrace);
MessageHelper.ShowError("批量赋属性值异常:" + ex.Message);
}
}
/// <summary>
/// 导入自主变更图斑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnImportZZTB_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
try
{
if (EngineEditorBG.EditState == esriEngineEditState.esriEngineStateEditing)
{
if (EngineEditorBG.HasEdits())
{
DBLoadHelper dBLoad = new DBLoadHelper();
dBLoad.SaveEingineEdit(this.hookHelper);
}
EngineEditorBG.StopEditing(true);
//MessageHelper.Show("当前地图处于编辑状态,请先保存停止编辑!");
//return;
}
if (zztbFeatureLayer == null || zztbFeatureLayer.FeatureClass == null)
{
MessageHelper.Show("未找到自主变更图斑图层(ZZTB)");
return;
}
if (frmDataImportForZZTB == null)
{
if (CurrentTaskPackage == null)
CurrentTaskPackage = CurrentSelectNode.PackageNode.Data as TaskPackage;
frmDataImportForZZTB = new FrmDataImport(CurrentTaskPackage)
{
TargetLayer = zztbFeatureLayer,
Title = "导入自主图斑"
};
frmDataImportForZZTB.ImpComplate += ImpComplateForZZTB;
frmDataImportForZZTB.WindowStartupLocation = WindowStartupLocation.Manual;
frmDataImportForZZTB.Left = 240;
frmDataImportForZZTB.Top = 110;
frmDataImportForZZTB.Closed += FrmDataImportForZZTB_Closed;
frmDataImportForZZTB.ShowInMainWindow(true);
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
LogAPI.Debug("导入自主图斑失败!" + ex);
}
}
/// <summary>
/// 预处理-数据导入-成功回调
/// </summary>
/// <param name="pIsComplate"></param>
private void ImpComplateForZZTB(bool pIsComplate)
{
IRDBHelper rdbHelper = null;
IFeatureCursor featureCursor = null;
IFeature feature = null;
try
{
CurrentTaskPackage = CurrentSelectNode.PackageNode.Data as TaskPackage;
if (!pIsComplate || CurrentTaskPackage == null || CurrentSelectNode == null)
{
LogAPI.Debug("预处理-数据导入CurrentTaskPackage/CurrentSelectNode发生异常!");
return;
}
if (zztbFeatureLayer == null || zztbFeatureLayer.FeatureClass == null)
{
MessageHelper.Show("未找到自主变更图斑图层(ZZTB)");
return;
}
//this.ShowLoading("正在更新任务包......", 0, 0);
//System.Threading.Thread.Sleep(1000);
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"BID='{CurrentTaskPackage.BID}'"
};
featureCursor = zztbFeatureLayer.FeatureClass.Search(queryFilter, true);
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
rdbHelper.BeginTransaction();
rdbHelper.ExecuteNonQueryWithException("delete from wyrw where sjly='ZZBG' or sjly='zzbg'", CommandType.Text);
List<string> lstField = new List<string>() { "XZQDM", "XZDM", "CJDM", "JCBH", "TBLX" };
Dictionary<int, bool> dicField = new Dictionary<int, bool>();
string fieldStr = "TBBSM, SJLY, JCMJ, TBMJ, ZXDX, ZXDY,MAXX, MAXY, MINX,MINY, Geometry, EGeometry";
foreach (var item in lstField)
{
int index = zztbFeatureLayer.FeatureClass.Fields.FindField(item);
if (index > -1)
{
fieldStr += "," + item;
IField field = zztbFeatureLayer.FeatureClass.Fields.Field[index];
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeOID:
dicField.Add(index, true);
break;
default:
dicField.Add(index, false);
break;
}
}
}
string excuteSQL = "INSERT INTO WYRW (" + fieldStr + ") VALUES({0});";
string valueStr = string.Empty;
int indexTBBSM = zztbFeatureLayer.FeatureClass.FindField("TBBSM");
while ((feature = featureCursor.NextFeature()) != null)
{
if (indexTBBSM > -1)
{
object tbbsmOBJ = feature.get_Value(indexTBBSM);
if (tbbsmOBJ is DBNull || tbbsmOBJ == null || string.IsNullOrWhiteSpace(tbbsmOBJ.ToString()))
{
valueStr = $"'{Guid.NewGuid().ToTrim().Replace("-", "")}'";
}
else
{
valueStr = $"'{tbbsmOBJ}'";
}
}
else
{
valueStr = $"'{Guid.NewGuid().ToTrim().Replace("-", "")}'";
}
IGeometry geometry = feature.ShapeCopy;
valueStr += $",'ZZBG',{ Math.Round((geometry as IArea).Area / 666.67, 2) },{Math.Round(ATEllipseArea.GetPolygonArea(geometry as IPolygon), 2)}";//面积换算为亩
string geometryStr = GeometryConvertHelper.ConverIGometryToJson(geometry);
IArea area = geometry as ESRI.ArcGIS.Geometry.IArea;
valueStr += $",{area.Centroid.X},{area.Centroid.Y},{geometry.Envelope.XMax},{geometry.Envelope.YMax},{geometry.Envelope.XMin},{geometry.Envelope.YMin},'{ geometryStr }','{ geometryStr }'";
foreach (var item in dicField)
{
object obj = feature.get_Value(item.Key);
if (item.Value)
{
if (obj is System.DBNull)
{
valueStr += "," + 0;
}
else
{
valueStr += "," + obj;
}
}
else
{
if (obj is System.DBNull)
{
valueStr += ",Null";
}
else
{
valueStr += ",'" + obj + "'";
}
}
}
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, valueStr));
}
rdbHelper.Commit();
if (hookHelper.Hook is IMapControlDefault mapControl)
{
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, mapControl.ActiveView.Extent);
mapControl.ActiveView.Extent = (zztbFeatureLayer as ILayer).AreaOfInterest;
}
(zztbFeatureLayer.FeatureClass as ITable).DeleteSearchedRows(queryFilter);
LoadDB(CurrentSelectNode.PackageNode);
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
MessageHelper.ShowError("预处理导入数据更新任务包(" + CurrentTaskPackage.PackageTempPath + ")失败:" + ex.Message);
LogAPI.Debug("预处理导入数据更新任务包(" + CurrentTaskPackage.PackageTempPath + ")失败:" + ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
private void FrmDataImportForZZTB_Closed(object sender, EventArgs e)
{
try
{
if (frmDataImportForZZTB != null)
{
frmDataImportForZZTB.Close();
}
frmDataImportForZZTB = null;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
private void ClearZZTBData()
{
IWorkspaceAPI workspaceAPI = null;
IRDBHelper rdbHelper = null;
try
{
if (CurrentSelectNode != null && CurrentSelectNode.NodeLevel == 2)
{
CurrentTaskPackage = CurrentSelectNode.PackageNode.Data as TaskPackage;
}
if (CurrentSelectNode == null || CurrentTaskPackage == null)
{
MessageHelper.ShowTips("获取包节点信息异常!");
return;
}
if (!File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("未找到任务包:" + CurrentTaskPackage.PackageTempPath);
return;
}
if (MessageHelper.ShowYesNoAndTips("是否清空自主举证图斑?") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
this.ShowLoading("正在清空当前任务包自主图斑数据......", 0, 0);
System.Threading.Thread.Sleep(1000);
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
rdbHelper.BeginTransaction();//不根据包ID删除,一个外业任务对应一个文件
rdbHelper.ExecuteNonQueryWithException("delete from wyrw where sjly='zzbg' or sjly='ZZBG'");
if (rdbHelper.GetTable("nyysresult") != null)
rdbHelper.ExecuteNonQueryWithException("delete from nyysresult where tbbsm not in(select tbbsm from wyrw)", CommandType.Text);
if (rdbHelper.GetTable("wysketch") != null)
rdbHelper.ExecuteNonQueryWithException("delete from wysketch where tbbsm not in(select tbbsm from wyrw)", CommandType.Text);
rdbHelper.Commit();
workspaceAPI = new WorkspaceAPI(CurrentTaskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM ZZTB where bid='{0}'", CurrentTaskPackage.BID));
CurrentSelectNode.Nodes = null;
CurrentSelectNode.Name = "自主图斑(0)";
this.hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground | esriViewDrawPhase.esriViewGeoSelection, null, this.hookHelper.ActiveView.Extent);
this.CloseLoading();
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug(ex);
this.CloseLoading();
MessageHelper.ShowError("清空当前任务包自主图斑数据异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
if (workspaceAPI != null)
{
workspaceAPI.CloseWorkspace();
}
}
}
private void GraphAccordingBasicLibrary(TreeNode treeNode, string ddtcbzdlbm)
{
try
{
string bsm = treeNode.Name;
if (DtbFeatureLayer == null)
{
MessageHelper.Show("未找到单图斑地类图斑更新(DTBDLTBGX)层!");
return;
}
IFeature Newfeature = null;
try
{
Newfeature = DtbFeatureLayer.FeatureClass.GetFeature((int)CurrentSelectNode.NodeID);
}
catch { }
if (Newfeature == null)
{
MessageHelper.Show("未找到当前节点的图斑!");
return;
}
int ddtcbzIndex = Newfeature.Fields.FindField("DDTCBZ");//图层属性
string ddtcbz = string.Empty;
if (ddtcbzIndex > -1)
{
object obj = Newfeature.get_Value(ddtcbzIndex);
ddtcbz = obj == null ? "" : obj.ToString();
}
//如果是推土区,则根据基础库拆分为多个
if (!ddtcbz.Equals(ddtcbzdlbm))
{
MessageHelper.Show($"当前图斑“图层信息”不是该{ddtcbzdlbm}图斑类型!");
return;
}
IFeatureLayer featureLayer1 = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑");
if (featureLayer1 == null || featureLayer1.FeatureClass == null)
{
LogAPI.Debug("基础_地类图斑(JC_DLTB)图层为空!");
return;
}
//叠加基础库获取推土区数据
Dictionary<IGeometry, IFeature> dicData = DBLoadHelper.IdentifyReturnIntersect(Newfeature.ShapeCopy, featureLayer1);
if (dicData == null || dicData.Count <= 0)
{
return;
}
this.ShowLoading("正在生成单独图层数据......", 0, 0);
foreach (var item in dicData)
{
IGeometry geometryIntersect = item.Key;
//防止存在多部件图形,但另一部分又是空的图形
IGeometryCollection geometryCollection = geometryIntersect as IGeometryCollection;
if (geometryCollection.GeometryCount > 1)
{
bool reshape = false;
for (int i = 0; i < geometryCollection.GeometryCount; i++)
{
IGeometry geometry = geometryCollection.Geometry[i];
IArea areaSub = geometry as IArea;
if (areaSub == null || Math.Abs(areaSub.Area) == 0)
{
geometryCollection.RemoveGeometries(i, 1);
reshape = true;
}
}
if (reshape)
{
geometryIntersect = geometryCollection as IGeometry;
}
}
object dlbm = string.Empty;
IClone clone = geometryIntersect as IClone;
IGeometry cloneGeometry = clone.Clone() as IGeometry;
string egeometry = DTBDBLoadHelper.ConverIGometryToJson(cloneGeometry);
//此处是为了验证转换后的json坐标串是否可以转换回去,如果转换并投影后图形为空,说明转换后的坐标串egeometry不正确
IGeometry convertGeometry = DTBDBLoadHelper.ConverJsonToIGeoemtry(egeometry);
if (convertGeometry == null)
{
continue;
}
convertGeometry.Project(this.hookHelper.FocusMap.SpatialReference);
if (convertGeometry == null || convertGeometry.IsEmpty)
{
continue;
}
Marshal.ReleaseComObject(cloneGeometry);
Marshal.ReleaseComObject(convertGeometry);
IFeature feature = DtbFeatureLayer.FeatureClass.CreateFeature();
feature.Shape = geometryIntersect;
for (int i = 0; i < feature.Fields.FieldCount; i++)
{
IField field = feature.Fields.Field[i];
if (!field.Editable || field.Name.ToLower().StartsWith("shape"))
{
continue;
}
if (field.Name.ToLower().StartsWith("bsm") || field.Name.ToLower().StartsWith("tbbsm"))
{
continue;
}
int indexF = item.Value.Fields.FindField(field.Name);
//记录基础库地类编码
if (field.Name.Equals("dlbm", StringComparison.CurrentCultureIgnoreCase))
{
dlbm = item.Value.get_Value(indexF);
}
object value = DBNull.Value;
//字段以DTBDLTBGX层为主,地类编码赋值基础库地类编码
if (indexF > -1)
{
value = item.Value.get_Value(indexF);
}
else
{
indexF = feature.Fields.FindField(field.Name);
if (indexF > -1)
{
value = feature.get_Value(indexF);
}
}
if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("65"))
{
if (field.Name.Equals("ddtcbz", StringComparison.CurrentCultureIgnoreCase))
{
value = "1399";
}
else if (field.Name.Equals("ddtcmc", StringComparison.CurrentCultureIgnoreCase))
{
value = "临时层";
}
}
else
{
if (field.Name.Equals("ddtcbz", StringComparison.CurrentCultureIgnoreCase))
value = ddtcbz;
}
feature.set_Value(i, value);
}
string xzdw_dlbm = "1009/1101/1107/1107A";
string czcsxmdl = "05H1/0508/0701/0702/08H1/08H2/08H2A/0809/0810/0810A/1005/1201/1004/0601/0602/0603/09";
//若原地类为01类(耕地),按原地类上图后自动将种植属性改为未耕
if (dlbm != null && !(dlbm is DBNull))
{
if (dlbm.ToString().StartsWith("01"))
{
int indexF = feature.Fields.FindField("ZZSXDM");
if (indexF > -1)
{
feature.set_Value(indexF, "WG");
}
indexF = feature.Fields.FindField("ZZSXMC");
if (indexF > -1)
{
feature.set_Value(indexF, "未耕");
}
}
else if (!czcsxmdl.Split('/').Contains(dlbm))
{
int indexF = feature.Fields.FindField("CZCSXM");
if (indexF > -1)
{
feature.set_Value(indexF, DBNull.Value);
}
}
//按原地类上图时,把线状地物宽度置空
if (!xzdw_dlbm.Split('/').Contains(dlbm))
{
int indexF = feature.Fields.FindField("XZDWKD");
if (indexF > -1)
{
feature.set_Value(indexF, DBNull.Value);
}
}
}
feature.Store();
}
Newfeature.Delete();
//this.CloseLoading();
}
catch (Exception ex)
{
this.CloseLoading();
MessageHelper.ShowError("推土区按基础库上图失败:" + ex.Message);
LogAPI.Debug("推土区按基础库上图失败:" + ex);
}
finally
{
//this.CloseLoading();
}
}
private void SaveDTTC(TreeNode treeNode)
{
string tbbsm = string.Empty;
IFeatureCursor featureCursor = null;
IFeature feature = null;
IRDBHelper rdbHelper = null;
try
{
if (uCDTBAllInfo != null)
uCDTBAllInfo.SaveData();
if (isSaving) return;
isSaving = true;
IWorkspaceEdit2 workspaceEdit2 = (IWorkspaceEdit2)EngineEditorBG.EditWorkspace;
IDataChangesEx dataChangesEx = workspaceEdit2.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinSession);
//获取所有变化的要素集
IEnumBSTR modifiedClasses = dataChangesEx.ModifiedClasses;
string modifiedClass = modifiedClasses.Next();
if (string.IsNullOrWhiteSpace(modifiedClass))
{
return;
}
while (!string.IsNullOrWhiteSpace(modifiedClass))
{
if (modifiedClass.Equals("DLTBBG", StringComparison.CurrentCultureIgnoreCase)) { }
else if (modifiedClass.Equals("WYRW", StringComparison.CurrentCultureIgnoreCase)) { }//WYRW
else
{
modifiedClass = modifiedClasses.Next();
continue;
}
if (SystemType == SystemTypeEnum.DTBJK.ToTrim() && CurrentTaskPackage != null)//与预处理内部链接冲突
{
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (rdbHelper != null)
rdbHelper.BeginTransaction();
}
//获取删除图形信息
IDifferenceCursorEx differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeDeleteNoChange);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 2);
//获取当前要素类所有变化图形信息
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeUpdateNoChange);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 1);
//获取插入图形信息
differenceCursorEx = dataChangesEx.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeInsert);
dataOperation.UpdateData(differenceCursorEx, rdbHelper, 0);
break;
}
if (rdbHelper != null)
{
rdbHelper.Commit();
rdbHelper.DisConnect();
rdbHelper = null;
}
EngineEditorBG.StopEditing(true);
if (CurrentWYRWTBTreeNode != null && CurrentWYRWTBTreeNode.Nodes != null && CurrentWYRWTBTreeNode.Data is WYRWTB)
{
DTBCheckPackage(CurrentWYRWTBTreeNode);//检查任务包变更范围图斑(质检)
}
//单独图层上图 原图斑删除 会添加在最后一个 确保选中之前的当前节点
if (treeNode.NodeLevel == 3 && treeNode.ParentNode != null && treeNode.ParentNode.Nodes != null && treeNode.ParentNode.Nodes.Count > 0)
{
treeNode.ParentNode.Nodes[treeNode.ParentNode.Nodes.Count - 1].Checked = true;
}
//if (uCDTBAllInfo != null)
// uCDTBAllInfo.InitDTBInfoView();
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
if (EngineEditorBG.EditState == esriEngineEditState.esriEngineStateEditing)
{
EngineEditorBG.AbortOperation();
EngineEditorBG.StopOperation("保存同步任务异常");
}
MessageHelper.ShowError("保存失败:" + ex.Message);
LogAPI.Debug("保存单独图层异常:" + ex);
}
finally
{
this.CloseLoading();
isSaving = false;
if (feature != null)
{
Marshal.ReleaseComObject(feature);
}
if (featureCursor != null)
{
Marshal.ReleaseComObject(featureCursor);
}
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 拷贝、复制节点名称
/// </summary>
private void CopyName()
{
try
{
if (CurrentSelectNode == null || string.IsNullOrWhiteSpace(CurrentSelectNode.Name))
{
return;
}
string copyText = CurrentSelectNode.Name;
int index = CurrentSelectNode.Name.IndexOf('(');
if (index > 0)
{
copyText = copyText.Substring(0, index);
}
PluginServiceInterface.CommonHelper.CopyToClipboard(copyText, false);
}
catch (Exception ex)
{
MessageHelper.Show("复制失败:" + ex.Message);
}
}
/// <summary>
/// 追加外业成果
/// </summary>
/// <param name="rdbHelper"></param>
private void AddWYResult()
{
IRDBHelper rdbHelper = null;
OpenFileDialog openFileDialog = null;
try
{
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 3 || CurrentTaskPackage == null)
{
return;
}
if (string.IsNullOrWhiteSpace(CurrentTaskPackage.PackageTempPath) || !System.IO.File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("当前任务包从未打开过,请先初始化“打开任务包”再进行其他操作!");
return;
}
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "选择外业成果文件";
openFileDialog.Filter = "外业成果文件(*.*)|*.*";
//openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = false;
//打开文件对话框选择的文件
if (!openFileDialog.ShowDialog())
{
return;
}
string selectDBPath = openFileDialog.FileName;
try
{
rdbHelper = RDBFactory.CreateDbHelper($"{selectDBPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
}
catch
{
try
{
rdbHelper = RDBFactory.CreateDbHelper(selectDBPath, DatabaseType.SQLite);
}
catch (Exception ex)
{
throw new Exception("打开外业成果文件失败,请检查选择的文件是不是有效的外业成果文件:" + ex.Message);
}
}
if (!rdbHelper.TableIsExist("WYHCFJ"))
{
MessageHelper.ShowTips("选择的外业成果文件不存在WYHCFJ(附件)表,请确认该文件是否是《外业成果文件》!");
return;
}
//外业附件追加
DataTable dataTable = rdbHelper.ExecuteDatatable("WYHCFJ", "select BSM,ARG from WYHCFJ", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
MessageHelper.ShowTips("外业核查附件(WYHCFJ)表数据为空!");
return;
}
rdbHelper.BeginTransaction();
string attchPath = string.Format("attach database '{0}' AS BDB", CurrentTaskPackage.PackageTempPath);
try
{
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
catch
{
attchPath = string.Format("attach database '{0}' AS BDB key '009FA8952F59C8853AF0CC8DA4394D00FEDCD51361C7F1C9C2629EBEB8FDE5B2A1';", CurrentTaskPackage.PackageTempPath);
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
string excuteSQL = string.Empty;
//外业附件追加
excuteSQL = "insert into BDB.WYHCFJ(HCLX, HCJLBSM, DKID, FJMC, FJLX, FJLJ, MODE, SEQUENCE, SUBTYPE, ARG, ARG2, ARG3, ARG4, IS_SELECTED, CJSJ, LENGTH, POINTS_JSON, HCRY, GROUP_INDEX, GROUPCODE, SUBTASKID, CHECK_CODE) select HCLX, HCJLBSM, DKID, FJMC, FJLX, FJLJ, MODE, SEQUENCE, SUBTYPE, ARG, ARG2, ARG3, ARG4, IS_SELECTED, CJSJ, LENGTH, POINTS_JSON, HCRY, GROUP_INDEX, GROUPCODE, SUBTASKID, CHECK_CODE from WYHCFJ where bsm='{0}'";
foreach (DataRow dr in dataTable.Rows)
{
long exists = (long)rdbHelper.ExecuteScalar("select count(1) from BDB.WYHCFJ where arg='" + dr["ARG"] + "'", CommandType.Text);
if (exists <= 0)
{
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, dr["bsm"]), CommandType.Text);
}
else
{
rdbHelper.ExecuteNonQueryWithException($"update BDB.WYHCFJ set UserDelete=0 where arg='{dr["ARG"]}'", CommandType.Text);
}
exists = (long)rdbHelper.ExecuteScalar($"select count(1) from BDB.FJGX where FJARG='{dr["ARG"]}' and tbbsm='{CurrentSelectNode.Name}'", CommandType.Text);
if (exists <= 0)
{
rdbHelper.ExecuteNonQueryWithException($"insert into BDB.fjgx(fjarg,tbbsm)values('{dr["ARG"]}','{CurrentSelectNode.Name}')", CommandType.Text);
}
}
rdbHelper.ExecuteNonQueryWithException("update BDB.WYHCFJ set UserDelete=0 where UserDelete IS null", CommandType.Text);
rdbHelper.Commit();
//追加后重新加载图斑,否则照片不加载
tvProperties_SelectedItemChanged(null, null);
MessageHelper.ShowTips("追加外业成果成功!");
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
MessageHelper.ShowError(ex.Message);
}
finally
{
if (openFileDialog != null)
{
openFileDialog.Dispose();
}
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 单图斑-追加外业成果
/// </summary>
private void AddDTBWYResult()
{
IRDBHelper rdbHelper = null;
System.Windows.Forms.OpenFileDialog openFileDialog = null;
try
{
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 2 || CurrentTaskPackage == null)
{
return;
}
if (string.IsNullOrWhiteSpace(CurrentTaskPackage.PackageTempPath) || !File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("当前任务包从未打开过,请先初始化“打开任务包”再进行其他操作!");
return;
}
openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Title = "选择外业成果文件";
openFileDialog.Filter = "外业成果文件(*.*)|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = false;
//打开文件对话框选择的文件
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
string selectDBPath = openFileDialog.FileName;
try
{
//rdbHelper = RDBFactory.CreateDbHelper(selectDBPath, DatabaseType.SQLite);
rdbHelper = RDBFactory.CreateDbHelper($"{selectDBPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
}
catch (Exception ex)
{
throw new Exception("打开外业成果文件失败,请检查选择的文件是不是有效的外业成果文件:" + ex.Message);
}
if (!rdbHelper.TableIsExist("WYHCCG"))
{
MessageHelper.ShowError("选择的DB不存在WYHCCG(外业核查成果)表,请确认该文件是否是《外业成果文件》!");
return;
}
if (!rdbHelper.TableIsExist("WYHCFJ"))
{
MessageHelper.ShowError("选择的外业成果文件不存在WYHCFJ(附件)表,请确认该文件是否是《外业成果文件》!");
return;
}
if (!rdbHelper.TableIsExist("LABEL"))
{
MessageHelper.ShowError("选择的外业成果文件不存在LABEL(外业草图)表,请确认该文件是否是《外业成果文件》!");
return;
}
//外业附件追加
DataTable dataTable = rdbHelper.ExecuteDatatable("WYHCFJ", "select BSM,ARG from WYHCFJ", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
MessageHelper.ShowTips("外业核查附件(WYHCFJ)表数据为空!");
return;
}
//ProgressHelper.ShowProcessBar("正在追加外业成果数据......");
rdbHelper.BeginTransaction();
string attchPath = string.Format("attach database '{0}' AS BDB;", CurrentTaskPackage.PackageTempPath);
try
{
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
catch
{
attchPath = string.Format("attach database '{0}' AS BDB key '009FA8952F59C8853AF0CC8DA4394D00FEDCD51361C7F1C9C2629EBEB8FDE5B2A1';", CurrentTaskPackage.PackageTempPath);
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
string excuteSQL = "insert into BDB.WYHCFJ(HCLX, HCJLBSM, DKID, FJMC, FJLX, FJLJ, MODE, SEQUENCE, SUBTYPE, ARG, ARG2, ARG3, ARG4, IS_SELECTED, CJSJ, LENGTH, POINTS_JSON, HCRY, GROUP_INDEX, GROUPCODE, SUBTASKID, CHECK_CODE,UserDelete) select HCLX, '{1}', '{1}', FJMC, FJLX, FJLJ, MODE, SEQUENCE, SUBTYPE, ARG, ARG2, ARG3, ARG4, IS_SELECTED, CJSJ, LENGTH, POINTS_JSON, HCRY, GROUP_INDEX, GROUPCODE, SUBTASKID, CHECK_CODE,0 as UserDelete from WYHCFJ where bsm='{0}'";
foreach (DataRow dr in dataTable.Rows)
{
long exists = (long)rdbHelper.ExecuteScalar($"select count(1) from BDB.WYHCFJ where arg='{dr["ARG"]}' and HCJLBSM='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
if (exists <= 0)
{
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, dr["bsm"], CurrentWYRWTB.TBBSM), CommandType.Text);
}
else
{
rdbHelper.ExecuteNonQueryWithException($"update BDB.WYHCFJ set UserDelete=0 where arg='{dr["ARG"]}' and HCJLBSM='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
}
}
//外业草图追加
long count = (long)rdbHelper.ExecuteScalar($"select count(1) from BDB.label where tbbsm='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
long count1 = (long)rdbHelper.ExecuteScalar($"select count(1) from label", CommandType.Text);
if (count <= 0 || (count > 0 && count1 > 0 && MessageHelper.ShowYesNoAndTips("外业草图已存在,是否覆盖?") == System.Windows.Forms.DialogResult.Yes))
{
rdbHelper.ExecuteNonQueryWithException($"delete from label where tbbsm='{CurrentWYRWTB.TBBSM}' or TBBSM IS NULL OR TBBSM=''", CommandType.Text);
excuteSQL = $"insert into BDB.label(TBBSM, YWLX, XZQDM, DKID, SHAPE, USERID, BZ, TYPE, CREATETIME, ATTACHMENTPATH, ATTACHMENT, SUBTASKID) select '{CurrentWYRWTB.TBBSM}', YWLX, XZQDM, '{CurrentWYRWTB.TBBSM}', SHAPE, USERID, BZ, TYPE, CREATETIME, ATTACHMENTPATH, ATTACHMENT, SUBTASKID from label limit 1";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
}
//外业核查成果(图斑核实记录信息)
count = (long)rdbHelper.ExecuteScalar($"select count(1) from BDB.WYRWTB_VOICE where TBBSM='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
count1 = (long)rdbHelper.ExecuteScalar($"select count(1) from WYRWTB_VOICE", CommandType.Text);
if (count <= 0 || (count > 0 && count1 > 0 && MessageHelper.ShowYesNoAndTips("图斑核实记录已存在,是否覆盖?") == System.Windows.Forms.DialogResult.Yes))
{
rdbHelper.ExecuteNonQueryWithException($"delete from wyhccg where HCRWBSM='{CurrentWYRWTB.TBBSM}' or HCRWBSM IS NULL OR HCRWBSM=''", CommandType.Text);
excuteSQL = $"insert into BDB.wyhccg(TBXHSX, DDTCXX, SUBTASKID, DKID, SFXYJZ, HCRY, HCBGDL, HCLX, GDLX, WYJL, ZZSX, STATUS, HCSJ, WBGYY, LJBZ, XZQDM, HCJL, HCRWBSM, HCBGFW, XZDLKD, LXJZGLBH) select TBXHSX, DDTCXX, SUBTASKID, '{CurrentWYRWTB.TBBSM}', SFXYJZ, HCRY, HCBGDL, HCLX, GDLX, WYJL, ZZSX, STATUS, HCSJ, WBGYY, LJBZ, XZQDM, HCJL, '{CurrentWYRWTB.TBBSM}', HCBGFW, XZDLKD, LXJZGLBH from wyhccg limit 1";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
}
//外业语音
if (rdbHelper.TableIsExist("WYRWTB_VOICE"))
{
rdbHelper.ExecuteScalar($"insert into BDB.WYRWTB_VOICE(tbbsm, ywlx, voice) select tbbsm, ywlx, voice from WYRWTB_VOICE where TBBSM='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
}
rdbHelper.Commit();
UpdateState(CurrentSelectNode, CurrentTaskPackage, "待确认");
//tvProperties_SelectedItemChanged(null, null);
//单图斑追加后重新加载图斑,否则照片不加载
tvProperties_SelectedItemChanged(null, null);
MessageHelper.ShowTips("追加外业成果成功!");
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
MessageHelper.ShowError(ex.Message);
}
finally
{
if (openFileDialog != null)
{
openFileDialog.Dispose();
}
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 导出外业成果,可以追加到其他外业图斑(广东省先上的专项数据,方便专项数据的附件复用)
/// </summary>
private void ExportResult()
{
IRDBHelper rdbHelper = null;
System.Windows.Forms.SaveFileDialog saveFileDialog = null;
try
{
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 2 || CurrentTaskPackage == null)
{
return;
}
if (string.IsNullOrWhiteSpace(CurrentTaskPackage.PackageTempPath) || !File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("当前任务包从未打开过,请先初始化“打开任务包”再进行其他操作!");
return;
}
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.Title = "请选择外业成果保存路径";
saveFileDialog.Filter = "外业成果文件(*.wyhccg)|*.wyhccg";
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
saveFileDialog.RestoreDirectory = true;
saveFileDialog.FileName = $"{CurrentWYRWTB.TBBSM}-{DateTime.Now.ToString("yyyyMMddHHmmss")}.wyhccg";
//打开文件对话框选择的文件
if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
string savePath = saveFileDialog.FileName;
File.Copy(System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间DTBJK\\初始化工程模板\\WYHCCG.wyhccg"), savePath);
//rdbHelper = RDBFactory.CreateDbHelper(savePath, DatabaseType.SQLite);
rdbHelper = RDBFactory.CreateDbHelper($"{savePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
string attchPath = string.Format("attach database '{0}' AS BDB;", CurrentTaskPackage.PackageTempPath);
try
{
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
catch
{
attchPath = string.Format("attach database '{0}' AS BDB key '009FA8952F59C8853AF0CC8DA4394D00FEDCD51361C7F1C9C2629EBEB8FDE5B2A1';", CurrentTaskPackage.PackageTempPath);
rdbHelper.ExecuteNonQueryWithException(attchPath, CommandType.Text);
}
Dictionary<string, string> dicTableName = new Dictionary<string, string>();
dicTableName.Add("BDB.WYHCFJ", "hcjlbsm");
dicTableName.Add("BDB.LABEL", "tbbsm");
dicTableName.Add("BDB.WYHCCG", "hcrwbsm");
dicTableName.Add("BDB.WYRWTB_VOICE", "tbbsm");
foreach (var item in dicTableName)
{
if (rdbHelper.TableIsExist(item.Key)) continue;
rdbHelper.ExecuteNonQueryWithException($"create table {item.Key.Split('.')[1]} as select * from {item.Key} where {item.Value} = '{CurrentWYRWTB.TBBSM}'", CommandType.Text);
}
if (!string.IsNullOrWhiteSpace(savePath) && File.Exists(savePath))
{
if (MessageHelper.ShowYesNoAndTips($"导出完成,是否查看结果?") == System.Windows.Forms.DialogResult.Yes)
{
System.Diagnostics.Process.Start("explorer.exe", System.IO.Path.GetDirectoryName(savePath));
}
}
else
{
MessageHelper.Show($"导出成功!");
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
if (saveFileDialog != null)
{
saveFileDialog.Dispose();
}
}
}
/// <summary>
/// 批量标记外业和取消标记外业
/// </summary>
/// <param name="sfwy">0:不外业 1:外业</param>
private void SetSFWY(int sfwy)
{
IRDBHelper rdbHelper = null;
string ypsmString = "批量标记外业";
try
{
if (sfwy == 0)
{
ypsmString = "批量标记不外业";
}
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 1 || CurrentSelectNode.Data == null)
{
return;
}
TaskPackage taskPackage = CurrentSelectNode.Data as TaskPackage;
if (!File.Exists(taskPackage.PackageTempPath))
{
MessageHelper.ShowError("检测到任务包未初始化(未打开过),无法标记外业!");
return;
}
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
DataTable dataTable = rdbHelper.ExecuteDatatable("Data", "select a.tbbsm,b.tbbsm as btbbsm,b.sfxywy from wyrw as a left join NYYSResult as b on a.tbbsm =b.tbbsm", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
MessageHelper.ShowError("检测到任务包无外业任务图斑!");
return;
}
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoCancelAndTips("是否覆盖已有外业任务图斑的预判结果?");
if (dialogResult == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
bool isConvertOldData = false;
if (dialogResult == System.Windows.Forms.DialogResult.Yes)
{
isConvertOldData = true;
}
this.ShowLoading($"正在{ypsmString}......", 0, 0);
System.Threading.Thread.Sleep(1000);
rdbHelper.BeginTransaction();
string excuteSQL = string.Empty;
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
foreach (DataRow dr in dataTable.Rows)
{
//未预判过,新插入一条预判结果
if (dr["btbbsm"] is DBNull || dr["btbbsm"] == null)
{
excuteSQL = string.Format("INSERT INTO NYYSResult (TBBSM, SFXYWY, YPRY, YPSJ, YPSM) VALUES('{0}', {1}, '{2}', '{3}','{4}');", dr["TBBSM"], sfwy, projectInfo.UserName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ypsmString);
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
}
else if (isConvertOldData)
{
excuteSQL = "update NYYSResult set sfxywy={2},YPSJ='{1}',YPSM='{3}' where tbbsm='{0}'";
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, dr["tbbsm"], DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), sfwy, ypsmString), CommandType.Text);
}
}
rdbHelper.Commit();
this.CloseLoading();
MessageHelper.Show($"任务包{ypsmString}成功!");
}
catch (Exception ex)
{
LogAPI.Debug($"{ypsmString}异常:" + ex.Message);
this.CloseLoading();
MessageHelper.ShowError($"{ypsmString}异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
private string fileName { get; set; }
/// <summary>
/// 导出预审成果
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnExportPackage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
IRDBHelper rdbHelper = null;
try
{
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (string.IsNullOrWhiteSpace(EncryptionHelper.GetDogKey(1, projectInfo.CODE)))
{
MessageHelper.Show("请插入加密狗!");
return;
}
fileName = string.Empty;
if (CurrentTaskPackage == null)
{
return;
}
if (string.IsNullOrWhiteSpace(CurrentTaskPackage.PackageTempPath) || !File.Exists(CurrentTaskPackage.PackageTempPath))
{
MessageHelper.Show("当前任务包从未打开过,请先初始化“打开任务包”再进行其他操作!");
return;
}
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
long count = (long)rdbHelper.ExecuteScalar("select count(*) from wyrw as a left join nyysresult as b on a.tbbsm=b.tbbsm where b.tbbsm is null", CommandType.Text);
if (count > 0)
{
MessageHelper.Show("当前任务包预审未完成,无法导出预审成果!");
CurrentTaskPackage.State = "未完成";
return;
}
else
{
CurrentTaskPackage.State = "完成";
}
rdbHelper.DisConnect();
rdbHelper = null;
if (MessageHelper.ShowYesNoAndTips("是否导出成果?") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
this.ShowLoading("正在导出预审成果......", 0, 0);
System.Threading.Thread.Sleep(1000);
string tempPath = SysAppPath.GetTempPath();//System.IO.Path.GetDirectoryName(CurrentTaskPackage.PackageTempPath);
try
{
//清空临时文件夹输出的临时成果包
if (!string.IsNullOrWhiteSpace(tempPath) && Directory.Exists(tempPath))
{
string[] files = Directory.GetFiles(tempPath, "*.ExportTemp");
if (files != null)
{
foreach (var item in files)
{
File.Delete(item);
}
}
}
}
catch
{ }
string savePackagePath = System.IO.Path.Combine(tempPath, CurrentTaskPackage.BID + ".ExportTemp");
File.Copy(CurrentTaskPackage.PackageTempPath, savePackagePath, true);
string savePath = System.IO.Path.Combine(projectInfo.TaskPath, "已输出");
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
fileName = DBLoadHelper.ExportDB(savePackagePath, savePath);
CurrentTaskPackage.State = "已输出";
projectInfo.Save();
if (uSBFlashDiskHelper == null)
{
uSBFlashDiskHelper = new USBFlashDiskHelper();
}
uSBFlashDiskHelper.LoadUSB();
this.CloseLoading();
if (uSBFlashDiskHelper.lstUSB != null && uSBFlashDiskHelper.lstUSB.Count > 0 && MessageHelper.ShowYesNoAndTips("是否同时输出成果到移动存储中?") == System.Windows.Forms.DialogResult.Yes)
{
if (uSBFlashDiskHelper.lstUSB.Count > 1)
{
if (uCSelectUSB == null || uCSelectUSB.IsVisible == false)
{
uCSelectUSB = new UCSelectUSB();
uCSelectUSB.Title = "选择将成果输出到移动存储?";
uCSelectUSB.WindowStartupLocation = WindowStartupLocation.CenterOwner;
uCSelectUSB.RefreshTree = SyncUSBTask2;
uCSelectUSB.Topmost = true;
uCSelectUSB.Show();
}
uCSelectUSB.InitData(uSBFlashDiskHelper.lstUSB);
}
else
{
if (uCSelectUSB != null)
{
uCSelectUSB.Close();
uCSelectUSB = null;
}
SyncUSBTask2(uSBFlashDiskHelper.lstUSB[0].Split('(')[0].Trim());
}
}
else
{
if (System.IO.Directory.Exists(savePath))
{
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes)
{
System.Diagnostics.Process.Start("explorer.exe", savePath);
}
}
else
{
MessageHelper.Show("导出成功!");
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
this.CloseLoading();
MessageHelper.Show("导出异常:" + ex.Message);
}
finally
{
this.CloseLoading();
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
private void SyncUSBTask2(string path)
{
try
{
if (string.IsNullOrWhiteSpace(fileName) || !System.IO.File.Exists(fileName) || !System.IO.Directory.Exists(path))
{
return;
}
string savePath = System.IO.Path.Combine(path, KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("UsbFolderName"), "2-预处理成果");
this.ShowLoading($"正在输出成果到:{savePath}......", 0, 0);
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
System.IO.File.Copy(fileName, System.IO.Path.Combine(savePath, System.IO.Path.GetFileName(fileName)));
string signFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileName), System.IO.Path.GetFileNameWithoutExtension(fileName) + ".sign");
if (!string.IsNullOrWhiteSpace(signFileName) && System.IO.File.Exists(signFileName))
{
System.IO.File.Copy(signFileName, System.IO.Path.Combine(savePath, System.IO.Path.GetFileName(signFileName)), true);
}
this.CloseLoading();
if (System.IO.Directory.Exists(savePath))
{
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes)
{
System.Diagnostics.Process.Start("explorer.exe", savePath);
}
}
else
{
MessageHelper.Show("导出成功!");
}
}
catch (Exception ex)
{
this.CloseLoading();
MessageHelper.ShowError("输出成果拷贝移动存储异常:" + ex.Message);
}
}
/// <summary>
/// 更新外业任务图斑状态:未完成、已完成、返外业、星标图斑、待确认
/// </summary>
private void UpdateState(TreeNode treeNode, TaskPackage taskPackage, string state)
{
bool ZTIsUploaded = false;
IRDBHelper rdbHelper = null;
try
{
if (treeNode == null || taskPackage == null || treeNode.NodeLevel != 2)
{
return;
}
WYRWTB wyrwtb = treeNode.Data as WYRWTB;
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
//已上传状态
ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, wyrwtb.TBBSM);
string excuteSQL = string.Empty;
if (state.Equals("返外业"))
{
wyrwtb.FWY = 1;
treeNode.PackageState = "已完成";
excuteSQL = $"UPDATE WYRW SET WYBZ='{wyrwtb.WYBZ}',FWY=1,ZT='已完成' WHERE TBBSM='{wyrwtb.TBBSM}'";
if (ZTIsUploaded)
excuteSQL = $"UPDATE WYRW SET WYBZ='{wyrwtb.WYBZ}',FWY=1 WHERE TBBSM='{wyrwtb.TBBSM}'";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
treeNode.Data = wyrwtb;
}
else if (state.Equals("取消返外业"))
{
wyrwtb.FWY = 0;
treeNode.PackageState = "未完成";
excuteSQL = $"UPDATE WYRW SET WYBZ=null,FWY=0,ZT='未完成' WHERE TBBSM='{wyrwtb.TBBSM}'";
if (ZTIsUploaded)
excuteSQL = $"UPDATE WYRW SET WYBZ=null,FWY=0 WHERE TBBSM='{wyrwtb.TBBSM}'";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
treeNode.Data = wyrwtb;
}
else if (state.Contains("星标"))
{
if (state.Equals("星标"))
{
wyrwtb.XBTB = 1;
}
else
{
wyrwtb.XBTB = 0;
}
excuteSQL = $"UPDATE WYRW SET XBTB={wyrwtb.XBTB} WHERE TBBSM='{wyrwtb.TBBSM}'";
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
treeNode.Data = wyrwtb;
}
else
{
excuteSQL = $"UPDATE WYRW SET ZT='{state}' WHERE TBBSM='{wyrwtb.TBBSM}'";
if (!ZTIsUploaded)
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
wyrwtb.ZT = state;
treeNode.PackageState = state;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError($"标记图斑为“{state}”异常:" + ex.Message);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
/// <summary>
/// 质检-外业任务图斑
/// </summary>
/// <param name="obj">质检</param>
/// <returns></returns>
private void DTBCheckPackage(object obj)
{
bool ZTIsUploaded = false;
IRDBHelper rdbHelper = null;
string tbbsm = string.Empty;
try
{
TreeNode treeNode = obj as TreeNode;
tbbsm = (treeNode.Data as WYRWTB).TBBSM;
string dbPath = (treeNode.PackageNode.Data as TaskPackage).PackageTempPath;
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
//已上传状态
ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, tbbsm);
List<RuleEntity> lstResult = new List<RuleEntity>();
rdbHelper.BeginTransaction();
//去除冗余数据
rdbHelper.ExecuteNonQueryWithException("delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBDLTBGXGC where bghtbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBLSYDGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBTTQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBGFBQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBCCWJQGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBCZCDYDGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from DTBLMFWGX where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException("delete from checkresult where tbbsm in(select TBBSM from wyrw where FWY=1);", CommandType.Text);
//返外业的不检查
DataTable dataTable = rdbHelper.ExecuteDatatable("data", $"select TBBSM from wyrw where TBBSM='{tbbsm}' AND FWY=1", true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
UpdateControlInvoke(UpdateControl, treeNode, 0);
return;
}
rdbHelper.ExecuteNonQueryWithException($"delete from checkresult where tbbsm='{tbbsm}';", CommandType.Text);
//判断当前外业任务图斑下是否存在变更图斑
dataTable = rdbHelper.ExecuteDatatable("data", $"select TBBSM from dtbdltbgx where TBBSM='{tbbsm}'", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
lstResult.Add(new RuleEntity() { ErrorId = tbbsm, ErrorTip = "当前外业图斑下不存在变更图斑!", RuleContent = "当前外业图斑下不存在变更图斑", ErrorType = "一类错误" });
}
else
{
try
{
lstResult = RuleCheck.XJRuleCheck.RuleCheckOpertion_DTB.StartXJSHCheck(tbbsm, dbPath, DTBDBLoadHelper.GetBasicData());
}
catch (Exception exce)
{
LogAPI.Debug("质检异常:" + exce);
}
}
if (lstResult != null && lstResult.Count > 0)
{
string excuteSQL = "INSERT INTO CheckResult (XH, CheckObject, ErrorType, ErrorId, ErrorTip,RuleCode, RuleName, RuleContent,TBBSM,GeometryType,Geometry) VALUES({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}','{8}', {9},'{10}');";
int i = 1;
lstResult.OrderBy(X => X.ErrorId);
foreach (var item in lstResult)
{
item.XH = i++;
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, item.XH, item.CheckObject, item.ErrorType, item.ErrorId, item.ErrorTip, item.RuleCode, item.RuleName, item.RuleContent, tbbsm, item.GeometryType, item.Geometry), CommandType.Text);
}
if (!ZTIsUploaded)
rdbHelper.ExecuteNonQueryWithException($"update wyrw set ZT='质检错误' where tbbsm='{tbbsm}'", CommandType.Text);
}
else
{
if (!ZTIsUploaded)
rdbHelper.ExecuteNonQueryWithException($"update wyrw set ZT='已完成' where tbbsm='{tbbsm}'", CommandType.Text);
}
if (rdbHelper != null)
{
rdbHelper.Commit();
LoadCheckResult(null, rdbHelper, true);
}
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
if (!ZTIsUploaded)
rdbHelper.ExecuteNonQueryWithException($"update wyrw set ZT='质检错误' where tbbsm='{tbbsm}'", CommandType.Text);
rdbHelper.Commit();
}
LogAPI.Debug(ex);
throw ex;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
/// <summary>
/// Invoke方式刷新控件
/// </summary>
/// <param name="setDele"></param>
/// <param name="control"></param>
/// <param name="value"></param>
private void UpdateControlInvoke(UpdateControlDelegate setDele, TreeNode control, int value)
{
this.Dispatcher.Invoke(setDele, new object[] { control, value });
}
/// <summary>
/// 委托界面刷新的方法
/// </summary>
/// <param name="control"></param>
/// <param name="value"></param>
private void UpdateControl(object control, object value)
{
try
{
int num = -1;
int.TryParse(value.ToString(), out num);
(control as TreeNode).LoadingVisibility = Visibility.Collapsed;
if (num > 0)
{
(control as TreeNode).PackageState = "质检错误";
}
else
{
(control as TreeNode).PackageState = "已完成";
}
}
catch (Exception ex)
{
MessageHelper.Show("质检更新状态:" + ex.Message);
}
}
/// <summary>
/// 加载质检结果(加载对应任务图斑质检错误)
/// </summary>
private void LoadCheckResult(RuleEntity ruleEntity = null, IRDBHelper rDBHelper = null, bool isCheck = false)
{
bool ZTIsUploaded = false;
try
{
if (CurrentTaskPackage == null || !File.Exists(CurrentTaskPackage.PackageTempPath))
return;
if (rDBHelper == null)
{
rDBHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
//rDBHelper.BeginTransaction();
}
if (ruleEntity != null)
rDBHelper.ExecuteNonQueryWithException($"delete from CheckResult where ErrorType='二类错误' and RuleCode='{ruleEntity.RuleCode}' and ErrorId='{ruleEntity.ErrorId}' and tbbsm='{ruleEntity.TBBSM}'", CommandType.Text);
string excuteSQL = $"SELECT * FROM CheckResult";
if (CurrentSelectNode != null && CurrentWYRWTB != null)
excuteSQL = $"SELECT * FROM CheckResult WHERE TBBSM='{CurrentWYRWTB.TBBSM}'";
//已上传状态
if (CurrentSelectNode != null && CurrentWYRWTB != null)
ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rDBHelper, CurrentWYRWTB.TBBSM);
DataTable dataTable = rDBHelper.ExecuteDatatable("result", excuteSQL, true);
List<RuleEntity> lst = null;
if (dataTable != null && dataTable.Rows.Count > 0)
{
lst = KGIS.Framework.Utils.Utility.TBToList.ToList<RuleEntity>(dataTable);
}
if (CheckResultsView == null) return;
CheckResultsView.InitData(lst);
TreeNode treeNode = null;
if (CurrentSelectNode.NodeLevel == 2)
{
treeNode = CurrentSelectNode;
}
else if (CurrentSelectNode.NodeLevel == 3)
{
treeNode = CurrentSelectNode.ParentNode;
}
if (treeNode != null && rDBHelper != null)
{
if (lst == null || lst.Count <= 0)
{
if (treeNode.PackageState.Equals("质检错误"))
{
if (!ZTIsUploaded)
{
rDBHelper.ExecuteNonQueryWithException($"update wyrw set zt='已完成' where tbbsm='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
treeNode.PackageState = "已完成";
}
}
else if (treeNode.PackageState.Equals("未完成") && isCheck)
{
if (!ZTIsUploaded)
{
rDBHelper.ExecuteNonQueryWithException($"update wyrw set zt='已完成' where tbbsm='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
treeNode.PackageState = "已完成";
}
}
}
else
{
if (!ZTIsUploaded)
{
rDBHelper.ExecuteNonQueryWithException($"update wyrw set zt='质检错误' where tbbsm='{CurrentWYRWTB.TBBSM}'", CommandType.Text);
treeNode.PackageState = "质检错误";
}
}
//rDBHelper.Commit();
}
}
catch (Exception ex)
{
//if (rDBHelper != null) rDBHelper.Rollback();
LogAPI.Debug("加载质检结果失败:" + ex);
throw ex;
}
finally
{
if (rDBHelper != null)
{
rDBHelper.DisConnect();
rDBHelper = null;
}
}
}
private void RefreshCheckState(List<RuleEntity> lstResult)
{
bool ZTIsUploaded = false;
IRDBHelper rDBHelper = null;
try
{
rDBHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
string excuteSQL = $"SELECT * FROM CheckResult";
foreach (RuleEntity Ruleitem in lstResult)
{
TreeNode treeNode = GetNodeByName(TreeDataSource[0], Ruleitem.BGFWBSM, new List<int>() { 3 });
if (treeNode != null)
{
//已上传状态
ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rDBHelper, (treeNode.ParentNode.Data as WYRWTB).TBBSM);
excuteSQL = $"SELECT * FROM CheckResult WHERE TBBSM='{(treeNode.ParentNode.Data as WYRWTB).TBBSM}'";
DataTable dataTable = rDBHelper.ExecuteDatatable("result", excuteSQL, true);
List<RuleEntity> lst = null;
if (dataTable != null && dataTable.Rows.Count > 0)
{
lst = KGIS.Framework.Utils.Utility.TBToList.ToList<RuleEntity>(dataTable);
}
if (lst == null || lst.Count <= 0)
{
if (treeNode.PackageState.Equals("质检错误"))
{
if (!ZTIsUploaded)
{
rDBHelper.ExecuteNonQueryWithException($"update wyrw set zt='已完成' where tbbsm='{(treeNode.ParentNode.Data as WYRWTB).TBBSM}'", CommandType.Text);
treeNode.ParentNode.PackageState = "已完成";
}
}
}
else
{
if (!ZTIsUploaded)
{
rDBHelper.ExecuteNonQueryWithException($"update wyrw set zt='质检错误' where tbbsm='{(treeNode.ParentNode.Data as WYRWTB).TBBSM}'", CommandType.Text);
treeNode.ParentNode.PackageState = "质检错误";
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("同步视图检查状态失败:" + ex);
}
finally
{
if (rDBHelper != null)
rDBHelper.DisConnect();
}
}
#region 目录树相关事件
private void btnRefresh_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
try
{
this.ShowLoading("正在刷新列表加载数据........", 0, 0);
System.Threading.Thread.Sleep(500);
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
RefreshTreeData();
}
else
{
try
{
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (prj != null)
{
if (prj.ProjType != EnumProjType.NDBG)
{
ClearData();
}
}
}
catch (Exception ex)
{
LogAPI.Debug("刷新列表失败:" + ex.Message);
LogAPI.Debug("刷新列表失败:" + ex.StackTrace);
}
finally
{
TreeDataSource = dataOperation.LoadTreeData();
tvPackges.ItemsSource = null;
tvPackges.ItemsSource = TreeDataSource;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("刷新列表失败:" + ex.Message);
LogAPI.Debug("刷新列表失败:" + ex.StackTrace);
MessageHelper.ShowError("刷新列表失败:" + ex.Message);
}
finally
{
this.CloseLoading();
}
}
/// <summary>
/// 双击节点定位-矢量监测数据定位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvTypes_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
try
{
if (e.OriginalSource is FrameworkElement clickedElement && clickedElement.DataContext is TreeNode)
{
if (SystemType == SystemTypeEnum.YCLJK.ToTrim() && (clickedElement.DataContext as TreeNode).NodeLevel == 3)
{
ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = null;
string tableName = string.Empty;
if (CurrentSelectNode.ParentNode.Name.StartsWith("下发图斑("))
{
tableName = "WYRW";
featureLayer = wyrwFeatureLayer;
}
else if (CurrentSelectNode.ParentNode.Name.StartsWith("自主图斑("))
{
tableName = "ZZTB";
featureLayer = zztbFeatureLayer;
}
if (featureLayer == null || featureLayer.FeatureClass == null)
{
LogAPI.Debug("未找到矢量图层【" + tableName + "】!");
MessageHelper.Show("未找到矢量图层【" + tableName + "】!");
return;
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = "TBBSM='" + CurrentSelectNode.Name + "'",
};
IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
if (feature == null)
{
return;
}
MapsManager.Instance.MapService.SelectFeature(featureLayer.Name, feature.OID.ToString());
return;
}
if ((clickedElement.DataContext as TreeNode).NodeLevel == 2 && (clickedElement.DataContext as TreeNode).Data is IFeature)
{
if (e.Handled) return;
e.Handled = true;//监测图斑双击定位
TreeNode layer = (clickedElement.DataContext as TreeNode).ParentNode;
int JCOid = (clickedElement.DataContext as TreeNode).NodeID.ToString().ToInt();
IFeature JCF = (layer.Data as IFeatureLayer).FeatureClass.GetFeature(JCOid);
if (JCF.Class.AliasName == "监测图斑")
MapsManager.Instance.MapService.SelectFeature("JCTB", JCF.OID.ToString(), true);
else
MapsManager.Instance.MapService.SelectFeature((layer.Data as IFeatureLayer).FeatureClass.AliasName, JCF.OID.ToString(), true);
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
/// <summary>
/// 树节点右键-设置树结构右键菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvTypes_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
if (e != null)
{
if (e.Handled) return;
e.Handled = true;
}
if (e.OriginalSource is FrameworkElement clickedElement && clickedElement.DataContext is TreeNode)
{
(clickedElement.DataContext as TreeNode).Checked = true;
//设置树结构右键菜单
SetContentMenu(clickedElement.DataContext as TreeNode, true);
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
}
/// <summary>
/// 树节点左键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvTypes_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
}
/// <summary>
/// 树节点展开
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TvPackges_Expanded(object sender, RoutedEventArgs e)
{
try
{
if (e.OriginalSource is FrameworkElement clickedElement && clickedElement.DataContext is TreeNode)
{
if ((clickedElement.DataContext as TreeNode).Nodes == null || (clickedElement.DataContext as TreeNode).Nodes.Count == 0) return;
//监测图层一级(缓加载监测图斑)
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
/// <summary>
/// 树节点切换选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
try
{
if (e != null)
{
if (e.Handled) return;
e.Handled = true;
}
if (isSaving) return;
GetCurrentSelectTreeNode();//获取节点所属的任务包及任务图斑
List<RuleEntity> lstResult = null;
if (CurrentSelectNode is TreeNode)
{
NYYSInfo nYYSInfo = null;
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
nYYSInfo = dataOperation.SelectedItemChanged_YCL();
}
else
{
//CurrentSelectNode.ClosePackageVisibility
nYYSInfo = dataOperation.SelectedItemChanged(CurrentSelectNode, ref lstResult);
}
uCDTBAllInfo.BindDataInfo(nYYSInfo);
//刷新地图 正常显示方位角
MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, MapsManager.Instance.MapService.getAxMapControl().Extent);
}
#region 调用质检
if (CurrentWYRWTBTreeNode != null && CurrentWYRWTBTreeNode.Nodes != null && CurrentWYRWTBTreeNode.Data is WYRWTB)
{
if (CurrentWYRWTBTreeNode.PackageState == "已完成" || CurrentWYRWTBTreeNode.PackageState == "已上传")
{
CheckResultsView.InitData(null);
return;
}
lstResult = dataOperation.DTBCheckPackage(CurrentWYRWTBTreeNode);//检查任务包变更范围图斑(质检)
}
if (CheckResultsView != null)//质检结果展示
CheckResultsView.InitData(lstResult);
#endregion
UpdateWCAndWWCNum();
}
catch (Exception ex)
{
LogAPI.Debug("节点切换失败:" + ex.Message);
LogAPI.Debug("节点切换失败:" + ex.StackTrace);
MessageHelper.ShowTips("节点切换异常!");
}
}
/// <summary>
/// 地图选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MapsService_OnSelectionChanged(object sender, EventArgs e)
{
if (SystemType == SystemTypeEnum.DTBJK.ToTrim())
{
}
else if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
try
{
IFeatureSelection s = null;
IFeatureLayer jc_dltbLayer = wyrwFeatureLayer;
if (jc_dltbLayer == null || jc_dltbLayer.FeatureClass == null || (jc_dltbLayer as IFeatureSelection).SelectionSet.Count != 1)
{
jc_dltbLayer = zztbFeatureLayer;
if (jc_dltbLayer == null || jc_dltbLayer.FeatureClass == null)
{
MessageHelper.Show("当前工程未找到自主图斑(ZZTB)和外业图斑(WYTB)图层!");
return;
}
}
s = (jc_dltbLayer as IFeatureSelection);
if (s.SelectionSet.Count != 1)
{
return;
}
IEnumIDs ids = s.SelectionSet.IDs;
int oid = 0;
while ((oid = ids.Next()) > 0)
{
IFeature currFeature = null;
try
{
currFeature = jc_dltbLayer.FeatureClass.GetFeature(oid);
if (currFeature == null || currFeature.ShapeCopy.IsEmpty)
{
continue;
}
}
catch
{
continue;
}
int indexBSM = currFeature.Fields.FindField("TBBSM");
if (indexBSM > -1)
{
object obj = currFeature.get_Value(indexBSM);
if (obj is DBNull || obj == null)
{
return;
}
TreeNode treeNode = GetNode(TreeDataSource[0], obj.ToString(), new List<int>() { 3 });
if (treeNode != null && treeNode.Checked != true)
{
treeNode.Checked = true;
}
}
break;
}
}
catch (Exception ex)
{
LogAPI.Debug("选择图斑异常:" + ex);
MessageHelper.ShowError("选择图斑异常:" + ex.Message);
}
}
}
/// <summary>
/// 获取树节点
/// </summary>
/// <param name="treeNode"></param>
/// <param name="nodeName"></param>
/// <param name="nodeLevel"></param>
/// <param name="nodeID"></param>
/// <returns></returns>
private TreeNode GetNode(TreeNode treeNode, string name, List<int> nodeLevel, string nodeID = null)
{
try
{
if (treeNode != null && nodeLevel.Contains(treeNode.NodeLevel))
{
if (!string.IsNullOrWhiteSpace(nodeID))//获取图斑节点
{
if (treeNode.Name.Equals(name) && treeNode.ParentNode != null && treeNode.ParentNode.NodeID.ToString().Equals(nodeID))
{
return treeNode;
}
}
else if (!string.IsNullOrWhiteSpace(name) && treeNode.Name.Contains(name))
{
return treeNode;
}
else
{
if (treeNode.NodeID.ToString().Equals(name))
{
return treeNode;
}
}
}
if (treeNode.Nodes != null && treeNode.Nodes.Count > 0)
{
foreach (var item in treeNode.Nodes)
{
TreeNode node = GetNode(item, name, nodeLevel, nodeID);
if (node != null)
{
return node;
}
}
}
return null;
}
catch (Exception ex)
{
LogAPI.Debug("预处理获取树节点异常:" + ex);
throw ex;
}
}
/// <summary>
/// 切换到上一条数据
/// </summary>
public void PreData()
{
try
{
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
PreDataForYCL();
return;
}
TreeNode CurrentSelectNode = tvPackges.SelectedItem as TreeNode;
if (TreeDataSource == null || CurrentSelectNode == null || CurrentSelectNode.NodeLevel == 0)
{
return;
}
TreeNode treeNode = GetPreTreeNode(CurrentSelectNode);
if (treeNode != null && treeNode.NodeLevel == 2)
{
treeNode = GetPreTreeNode(treeNode);
}
if (treeNode.NodeLevel == 1 || treeNode.NodeLevel == 0)
{
MessageHelper.ShowTips("当前是第一条数据!");
return;
}
treeNode.IsExpanded = true;
treeNode.Checked = true;
}
catch (Exception ex)
{
LogAPI.Debug("切换上一条数据失败:" + ex);
MessageHelper.ShowError("切换上一条数据失败:" + ex.Message);
}
}
public void PreDataForYCL()
{
try
{
if (TreeDataSource == null || CurrentSelectNode == null)
{
return;
}
List<TreeNode> allTreeNodes = new List<TreeNode>();
foreach (TreeNode parentNode in TreeDataSource)
{
GetAllNodes(parentNode, allTreeNodes);
}
if (allTreeNodes != null && allTreeNodes.Count != 0)
allTreeNodes = allTreeNodes.FindAll(a => a.NodeLevel == 3);
TreeNode treeNode = null;
if (CurrentSelectNode.NodeLevel == 0)
{
treeNode = CurrentSelectNode;
MessageHelper.ShowTips("当前是任务列表节点!");
}
else if (CurrentSelectNode.NodeLevel == 1)
{
treeNode = CurrentSelectNode;
MessageHelper.ShowTips("当前是任务包节点!");
}
else if (CurrentSelectNode.NodeLevel == 2)
{
treeNode = CurrentSelectNode;
MessageHelper.ShowTips("当前是变更范围节点!");
}
else if (allTreeNodes != null && allTreeNodes.Count != 0)
{
if (CurrentSelectNode.Name.Equals(allTreeNodes[0].Name))
{
treeNode = CurrentSelectNode;
MessageHelper.ShowTips("当前是第一条数据!");
}
else
{
for (int i = 1; i < allTreeNodes.Count; i++)
{
if (CurrentSelectNode.Name.Equals(allTreeNodes[i].Name))
{
treeNode = allTreeNodes[i - 1];
break;
}
}
}
}
if (treeNode == null) treeNode = CurrentSelectNode;
//CurrentSelectNode.YYSVisibility = Visibility.Visible;
//此处是为了重新绑定当前这条数据:原因是如果用户名修改了以后,又是最后一条数据,保存完后,当前数据没切换,未重新绑定数据,此处为了保存后重新绑定下数据
//if (treeNode.NodeLevel == 0)
//{
// if (isSave)
// {
// tvProperties_SelectedItemChanged(null, null);
// MessageHelper.Show("保存成功!");
// }
// return;
//}
CurrentSelectNode.Checked = false;
treeNode.IsExpanded = true;
treeNode.Checked = true;
}
catch (Exception ex)
{
LogAPI.Debug("切换上一条数据失败:" + ex);
MessageHelper.ShowError("切换上一条数据失败:" + ex.Message);
}
}
private TreeNode GetPreTreeNode(TreeNode treeNode, bool isFirst = true)
{
try
{
TreeNode parentNode = treeNode.ParentNode;
if (parentNode.Nodes[0].Name != treeNode.Name)
{
for (int i = 1; i < parentNode.Nodes.Count; i++)
{
if (treeNode.Name.Equals(parentNode.Nodes[i].Name))
{
TreeNode node = parentNode.Nodes[i - 1];
if (node.Nodes != null && node.NodeLevel < 3 && node.Nodes.Count > 0)
{
node.IsExpanded = true;
return node.Nodes[node.Nodes.Count - 1];
}
return node;
}
}
}
return parentNode;
}
catch (Exception ex)
{
LogAPI.Debug("GetPreTreeNode失败:" + ex);
throw ex;
}
}
/// <summary>
/// 切换到下一条数据
/// </summary>
public void NextData(bool isSave = false)
{
try
{
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
NextDataForYCL(isSave);
return;
}
TreeNode CurrentSelectNode = tvPackges.SelectedItem as TreeNode;
if (TreeDataSource == null || CurrentSelectNode == null)
{
return;
}
TreeNode treeNode = GetNextTreeNode(CurrentSelectNode);
if (treeNode == null || treeNode.NodeLevel == 0 || treeNode.NodeLevel == 1)
{
MessageHelper.ShowTips("当前是最后一条数据!");
return;
}
//此处是为了重新绑定当前这条数据:原因是如果用户名修改了以后,又是最后一条数据,保存完后,当前数据没切换,未重新绑定数据,此处为了保存后重新绑定下数据
treeNode.IsExpanded = true;
if (treeNode.NodeLevel == 2 && treeNode.Nodes.Count > 0)
{
treeNode.Nodes[0].Checked = true;
}
else
{
treeNode.Checked = true;
}
}
catch (Exception ex)
{
LogAPI.Debug("切换下一条数据失败:" + ex);
MessageHelper.ShowError("切换下一条数据失败:" + ex.Message);
}
}
/// <summary>
/// 标记任务包返外业
/// </summary>
private void SetFWY()
{
try
{
TreeNode CurrentSelectNode = tvPackges.SelectedItem as TreeNode;
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel == 1 || CurrentSelectNode.NodeLevel == 0 || CurrentSelectNode.Data is null) return;
string BZTemp = CurrentSelectNode.ParentNode.Data is WYRWTB ? (CurrentSelectNode.ParentNode.Data as WYRWTB).WYBZ : (CurrentSelectNode.Data as WYRWTB).WYBZ;
UCFWYBZ ucFwybz = new UCFWYBZ(BZTemp)
{
Left = 300,
Top = 250,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
if (ucFwybz.ShowDialog() == true)
{
if (CurrentSelectNode.NodeLevel == 3)
{
(CurrentSelectNode.ParentNode.Data as WYRWTB).WYBZ = ucFwybz.BZ;
UpdateState(CurrentSelectNode.ParentNode, CurrentSelectNode.ParentNode.ParentNode.Data as TaskPackage, "返外业");
}
else if (CurrentSelectNode.NodeLevel == 2)
{
(CurrentSelectNode.Data as WYRWTB).WYBZ = ucFwybz.BZ;
UpdateState(CurrentSelectNode, CurrentSelectNode.ParentNode.Data as TaskPackage, "返外业");
}
else
return;
}
}
catch (Exception ex)
{
LogAPI.Debug("标记返外业异常:" + ex);
MessageHelper.ShowError("标记返外业异常:" + ex.Message);
}
}
public void GetAllNodes(TreeNode node, List<TreeNode> allTreeNodes)
{
if (node != null)
{
if (node.NodeLevel == 0)
{
allTreeNodes.Add(node);
}
if (node.Nodes != null)
{
foreach (TreeNode childNode in node.Nodes)
{
allTreeNodes.Add(childNode);
GetAllNodes(childNode, allTreeNodes);
}
}
}
}
/// <summary>
/// 切换到下一条数据
/// </summary>
public void NextDataForYCL(bool isSave = false)
{
try
{
if (this.TreeDataSource == null || CurrentSelectNode == null)
{
return;
}
List<TreeNode> allTreeNodes = new List<TreeNode>();
foreach (TreeNode parentNode in TreeDataSource)
{
GetAllNodes(parentNode, allTreeNodes);
}
if (allTreeNodes != null && allTreeNodes.Count != 0)
allTreeNodes = allTreeNodes.FindAll(a => a.NodeLevel == 3);
TreeNode treeNode = null;
if (allTreeNodes != null && allTreeNodes.Count != 0)
{
if (CurrentSelectNode.Name.Equals(allTreeNodes[allTreeNodes.Count - 1].Name))
{
treeNode = CurrentSelectNode;
if (!isSave)
MessageHelper.ShowTips("当前是最后一条数据!");
}
else
{
for (int i = 0; i < allTreeNodes.Count - 1; i++)
{
if (CurrentSelectNode.Name.Equals(allTreeNodes[i].Name))
{
treeNode = allTreeNodes[i + 1];
break;
}
}
}
}
if (treeNode == null) treeNode = CurrentSelectNode;
if (isSave)
CurrentSelectNode.YYSVisibility = Visibility.Visible;
//此处是为了重新绑定当前这条数据:原因是如果用户名修改了以后,又是最后一条数据,保存完后,当前数据没切换,未重新绑定数据,此处为了保存后重新绑定下数据
//if (treeNode.NodeLevel == 0)
//{
// if (isSave)
// {
// tvProperties_SelectedItemChanged(null, null);
// MessageHelper.Show("保存成功!");
// }
// return;
//}
CurrentSelectNode.Checked = false;
treeNode.IsExpanded = true;
treeNode.Checked = true;
}
catch (Exception ex)
{
LogAPI.Debug("切换下一条数据失败" + ex);
MessageHelper.ShowError("切换下一条数据失败:" + ex.Message);
}
}
private TreeNode GetNextTreeNode(TreeNode treeNode, bool isFirst = true)
{
try
{
if (!isFirst && treeNode.NodeLevel == 0)
{
return treeNode;
}
if (isFirst && treeNode.Nodes != null && treeNode.Nodes.Count > 0)
{
return treeNode.Nodes[0];
}
TreeNode parentNode = treeNode.ParentNode;
if (parentNode.Nodes[parentNode.Nodes.Count - 1].Name != treeNode.Name)
{
for (int i = 0; i < parentNode.Nodes.Count - 1; i++)
{
if (treeNode.Name.Equals(parentNode.Nodes[i].Name))
{
return parentNode.Nodes[i + 1];
}
}
}
return GetNextTreeNode(parentNode, false);
}
catch (Exception ex)
{
LogAPI.Debug("GetNextTreeNode执行失败" + ex);
throw ex;
}
}
#endregion
/// <summary>
/// 根据树结构展示名为条件查询某一节点
/// </summary>
/// <param name="treeNode"></param>
/// <param name="name"></param>
/// <param name="nodeLevel"></param>
/// <param name="nodeID"></param>
/// <returns></returns>
private TreeNode GetNodeByName(TreeNode treeNode, string name, List<int> nodeLevel, string nodeID = null)
{
try
{
if (treeNode != null && nodeLevel.Contains(treeNode.NodeLevel))
{
if (!string.IsNullOrWhiteSpace(nodeID))//获取图斑节点
{
if (treeNode.Name.StartsWith(name) && treeNode.ParentNode != null && treeNode.ParentNode.NodeID.ToString().Equals(nodeID))
{
return treeNode;
}
}
else if (!string.IsNullOrWhiteSpace(name) && treeNode.Name.StartsWith(name))
{
return treeNode;
}
}
if (treeNode.Nodes != null && treeNode.Nodes.Count > 0)
{
foreach (var item in treeNode.Nodes)
{
TreeNode node = GetNodeByName(item, name, nodeLevel, nodeID);
if (node != null)
{
return node;
}
}
}
return null;
}
catch (Exception ex)
{
LogAPI.Debug("GetNodeByName执行失败(特殊情况不处理):" + ex.Message);
return null;
}
}
#region DockPanle继承属性
public bool IsShowInMap { 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 bool IsDockToPanel { get; set; }
public DockStyle DockToPanelStyle { get; set; }
//元素类属性
public bool IsShow { get; set; }
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler CloseViewHandler;
public void ClosePanel()
{
Platform.Instance.NotifyMsgEven2 -= Instance_NotifyMsgEven2;
MapsManager.Instance.MapService.OnSelectionChanged -= MapsService_OnSelectionChanged;
(EngineEditorBG as IEngineEditEvents_Event).OnSaveEdits -= UCTaskPackageTree_OnSaveEditing;
if (uCDTBAllInfo != null)
uCDTBAllInfo.ClosePanel();
if (CheckResultsView != null)
CheckResultsView.ClosePanel();
this.IsShow = false;
Platform.Instance.CloseView(this);
}
public void ClosePanelInvoke()
{
CloseViewHandler?.Invoke(this, null);
ClosePanel();
}
public void ShowPanel()
{
Platform.Instance.OpenView(this, false);
}
private void UcJKResultExport_Closed(object sender, EventArgs e)
{
try
{
if (ucJKResultExport != null)
{
ucJKResultExport.Close();
}
ucJKResultExport = null;
}
catch (Exception ex)
{
LogAPI.Debug("UcJKResultExport_Closed执行异常:" + ex);
}
}
private void UcSetBatchAttribute_Closed(object sender, EventArgs e)
{
try
{
if (ucSetBatchAttribute != null)
{
ucSetBatchAttribute.Close();
}
ucSetBatchAttribute = null;
}
catch (Exception ex)
{
LogAPI.Debug("UcSetBatchAttribute_Closed执行异常:" + ex);
}
}
#endregion
#region 树筛选事件
/// <summary>
/// 失去焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TxtJCBHValue_LostFocus(object sender, RoutedEventArgs e)
{
StateRefresh(TreeDataSource);
}
private void TxtJCBHValue_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
StateRefresh(TreeDataSource);
}
}
private void BtnQuery_Click(object sender, RoutedEventArgs e)
{
StateRefresh(TreeDataSource);
}
private void StateRefresh(ObservableCollection<TreeNode> treeNodeSouce)
{
if (!string.IsNullOrWhiteSpace(txtJCBHValue.Text) && txtJCBHValue.Text != "全部" && treeNodeSouce.Count != 0)
{
string queryText = txtJCBHValue.Text.Trim();
foreach (TreeNode Treeitems in treeNodeSouce[0].Nodes)//监测图层一级
{
if (Treeitems.Nodes == null) continue;
foreach (var Treeitem in Treeitems.Nodes)//任务图斑一级
{
if ("质检错误,已完成,未完成".Contains(queryText))
{
if (Treeitem.PackageState.Contains(queryText))
{
Treeitem.TreeVisibility = Visibility.Visible;
}
else
{
Treeitem.TreeVisibility = Visibility.Collapsed;
}
}
else if (queryText.Equals("星标图斑") && Treeitem.Data is WYRWTB && (Treeitem.Data as WYRWTB).XBTB == 1)
{
Treeitem.TreeVisibility = Visibility.Visible;
if (Treeitem.Nodes != null && Treeitem.Nodes.Count > 0)
{
Treeitem.Nodes.ToList().ForEach(x => x.TreeVisibility = Visibility.Visible);
}
}
else if (queryText.Equals("返外业") && Treeitem.Data is WYRWTB && (Treeitem.Data as WYRWTB).FWY == 1)
{
Treeitem.TreeVisibility = Visibility.Visible;
if (Treeitem.Nodes != null && Treeitem.Nodes.Count > 0)
{
Treeitem.Nodes.ToList().ForEach(x => x.TreeVisibility = Visibility.Visible);
}
}
else if (Treeitem.Name.Contains(queryText))
{
Treeitem.TreeVisibility = Visibility.Visible;
if (Treeitem.Nodes != null)
Treeitem.Nodes.ForEach(x => x.TreeVisibility = Visibility.Visible);
Treeitem.ParentNode.IsExpanded = true;
}
else
{
if (Treeitem.Nodes == null) continue;//输入字符在监测图斑一级查询到则停止向下遍历
Treeitem.TreeVisibility = Visibility.Collapsed;
foreach (var BGitem in Treeitem.Nodes)
{
if (BGitem.Name.Contains(queryText))
{
BGitem.TreeVisibility = Visibility.Visible;
Treeitem.TreeVisibility = Visibility.Visible;
Treeitem.ParentNode.IsExpanded = true;
}
else
BGitem.TreeVisibility = Visibility.Collapsed;
}
}
if (Treeitem.Data == null)
Treeitem.TreeVisibility = Visibility.Visible;
}
}
}
else
{
if (treeNodeSouce == null || treeNodeSouce.Count == 0 || treeNodeSouce[0].Nodes == null) return;
foreach (TreeNode Treeitem in treeNodeSouce[0].Nodes)
{
Treeitem.TreeVisibility = Visibility.Visible;
if (Treeitem.Nodes == null) continue;
foreach (var JCitem in Treeitem.Nodes)
{
JCitem.TreeVisibility = Visibility.Visible;
if (JCitem.Nodes == null) continue;
foreach (var BGitem in JCitem.Nodes)
{
BGitem.TreeVisibility = Visibility.Visible;
}
}
}
}
}
private string SystemType = string.Empty;
/// <summary>
/// 绑定树结构数据
/// </summary>
/// <param name="obj"></param>
public void BindData(object obj)
{
try
{
this.ShowLoading("任务列表数据加载中.......", 0, 0);
SystemType = obj.ToTrim();
dataOperation = DataOperationHelper.GetDefaultType(tvPackges);
if (MapsManager.Instance.MapService != null)
MapsManager.Instance.MapService.OnSelectionChanged += MapsService_OnSelectionChanged;
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (ProjectInfo != null && File.Exists(ProjectInfo.ProjDir + "\\BGTJ.sqlite"))
BGTJSqlitePath = ProjectInfo.ProjDir + "\\BGTJ.sqlite";
if (DtbFeatureLayer == null)
DtbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
if (WyrwFeatureLayer == null)
WyrwFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("WYRW");
if (DLTBFeatureLayer == null)
DLTBFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTB");
Platform.Instance.NotifyMsgEven2 += Instance_NotifyMsgEven2;
EngineEditorBG = new EngineEditorClass();
(EngineEditorBG as IEngineEditEvents_Event).OnSaveEdits += UCTaskPackageTree_OnSaveEditing;
hookHelper = new HookHelperClass
{
Hook = MapsManager.Instance.MapService.getAxMapControl().Object
};
ShowDTBDetails(SystemType);
if (SystemTypeEnum.YCLJK.ToTrim() == SystemType)
{
lbScreeningCondition.Visibility = Visibility.Collapsed;
txtJCBHValue.Visibility = Visibility.Collapsed;
firstRow.MaxHeight = 0;
TreeDataSource = dataOperation.LoadTreeData_YCL();
}
else
{
TreeDataSource = dataOperation.LoadTreeData();
}
tvPackges.ItemsSource = null;
tvPackges.ItemsSource = TreeDataSource;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
MessageHelper.ShowError("任务列表加载异常。");
}
finally
{
this.CloseLoading();
}
}
public void SaveEdit()
{
}
#endregion
#region 图斑预处理数据初始化绑定
/// <summary>
/// 打开任务包
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnOpenPackage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
IRDBHelper rdbHelper = null;
IRDBHelper dbHelper = null;
try
{
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 1)
return;
//System.Threading.Thread.Sleep(1000);
//预处理打开任务包
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
this.ShowLoading("正在加载预处理数据......", 0, 0);
//showToips:如果是导入自主图斑导致的重新加载数据,则不提示:是否重新打开任务包?
if (CurrentSelectNode.Nodes != null && CurrentSelectNode.Nodes.Count > 0)
{
if (MessageHelper.ShowYesNoAndTips("任务包已打开,是否重新打开任务包?") != System.Windows.Forms.DialogResult.Yes)
return;
}
dataOperation.ClosePackage_YCL(CurrentSelectNode);
dataOperation.OpenPackage_YCL();
return;
}
//单图斑建库/单图斑质检打开任务包(矢量数据加载)
if (CurrentSelectNode.Data is IFeatureLayer)
{
//dataOperation.LoadSLDataTreeNode(CurrentSelectNode);
this.ShowLoading("正在获取矢量任务包数据......", 0, 0);
System.Threading.Thread.Sleep(1000);
IQueryFilter queryFilter = new QueryFilterClass();
if (CurrentSelectNode.Data as IFeatureLayer is IFeatureLayerDefinition pFLDefinition)
{
queryFilter.WhereClause = pFLDefinition.DefinitionExpression;
}
DataTable dataJCTB = AECommonHelper.GetTableByFeatureClass((CurrentSelectNode.Data as IFeatureLayer).FeatureClass, queryFilter);
DataTable dataDtbBGFW = AECommonHelper.GetTableByFeatureClass(DtbFeatureLayer.FeatureClass);
IVariantArray YBParam = new VarArrayClass();
YBParam.Add(CurrentSelectNode);
YBParam.Add(dataJCTB);
YBParam.Add(dataDtbBGFW);
ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ThreadLoadData), YBParam, new System.Threading.WaitCallback(LoadDataCompleteCallBack));
}
else if (CurrentSelectNode.Data is TaskPackage)
{
this.ShowLoading("正在加载任务包数据......", 0, 0);
dataOperation.ClosePackage(CurrentSelectNode);
dataOperation.LoadDBToTreeNode(CurrentSelectNode);
}
CurrentSelectNode.IsExpanded = true;
CurrentSelectNode.OpenPackageVisibility = Visibility.Collapsed;
dataOperation.StartEdit(WyrwFeatureLayer);//StartEditForDTBJK(EngineEditorBG, WyrwFeatureLayer);
#region 更新任务包记录文件 JCTB_TaskPackage
string strTbbsm = "";
try
{
if (ProjectInfo != null && ProjectInfo.ProjDir != null && File.Exists(System.IO.Path.Combine(ProjectInfo.ProjDir, "BGTJ.sqlite")))
{
GetCurrentSelectTreeNode();//获取节点所属的任务包及任务图斑
if (CurrentTaskPackage != null && CurrentTaskPackage.PackageTempPath != null && File.Exists(CurrentTaskPackage.PackageTempPath))
{
rdbHelper = RDBFactory.CreateDbHelper(System.IO.Path.Combine(ProjectInfo.ProjDir, "BGTJ.sqlite"), DatabaseType.SQLite);
rdbHelper.ExecuteNonQueryWithException(@"CREATE TABLE if not exists JCTB_TaskPackage ( ID integer NOT NULL PRIMARY KEY AUTOINCREMENT,JCBH TEXT(100),YWLX TEXT(50),PackageName TEXT(255),PackagePath TEXT(500),PackageTempPath TEXT(255)); ", System.Data.CommandType.Text);
DataTable TaskPackagedataTable = rdbHelper.ExecuteDatatable("JCTB_TaskPackage", "select JCBH from JCTB_TaskPackage", true);
if (TaskPackagedataTable != null && TaskPackagedataTable.Rows.Count > 0)
{
strTbbsm = string.Join(",", TaskPackagedataTable.Rows.OfType<DataRow>().Select(r => $"{r[0].ToString()}"));
}
dbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
DataTable dataTable = dbHelper.ExecuteDatatable("WYRW", "select TBBSM from WYRW", true);
StringBuilder stringBuilder = new StringBuilder();
if (dataTable != null && dataTable.Rows.Count > 0)
{
foreach (DataRow item in dataTable.Rows)
{
if (strTbbsm.Contains(item["TBBSM"].ToString())) continue;
var sql = $"INSERT INTO JCTB_TaskPackage (JCBH,YWLX,PackageName,PackagePath,PackageTempPath) VALUES('{item["TBBSM"]}','{CurrentTaskPackage.YWLX}', '{CurrentTaskPackage.PackageName}', '{CurrentTaskPackage.PackagePath}', '{CurrentTaskPackage.PackageTempPath}'); ";
stringBuilder.Append(sql);
}
rdbHelper.ExecuteNonQueryWithException(stringBuilder.ToString(), CommandType.Text);
}
this.CloseLoading();
}
}
}
catch (Exception exce)
{
this.CloseLoading();
LogAPI.Debug("更新任务包记录文件:" + exce.Message);
LogAPI.Debug("更新任务包记录文件:" + exce.StackTrace);
}
#endregion
}
catch (Exception ex)
{
this.CloseLoading();
//任务包加载异常-处理后续操作
CurrentSelectNode.IsExpanded = false;
dataOperation.StopEditForDTBJK(EngineEditorBG);
LogAPI.Debug("任务包加载失败:" + ex.Message);
LogAPI.Debug("任务包加载失败:" + ex.StackTrace);
MessageHelper.ShowError("任务包加载失败:" + ex.Message);
}
finally
{
this.CloseLoading();
if (rdbHelper != null)
rdbHelper.DisConnect();
if (dbHelper != null)
dbHelper.DisConnect();
}
}
private void ThreadLoadData(object pParm)
{
TreeNode parentNode = new TreeNode();//临时存储数据节点
TreeNode CruutreeNode = (pParm as IVariantArray).Element[0] as TreeNode;//当前要加载的节点
parentNode.Data = CruutreeNode.Data;
try
{
this.UpdateMsg("正在加载图斑数据......");
//System.Threading.Thread.Sleep(1000);
#region 监测图斑
IFeatureLayer strDtbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
DataTable dataJCTB = (pParm as IVariantArray).Element[1] as DataTable;
DataTable dataDtbBGFW = (pParm as IVariantArray).Element[2] as DataTable;
if (dataDtbBGFW == null || dataJCTB.Rows.Count <= 0) return;
foreach (DataRow item in dataJCTB.Rows)
{
string jcbh = item["JCBH"] as string;
//第三级-监测图斑数据
TreeNode jctbNode = new TreeNode()
{
Name = jcbh + "(0)",
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBJK;component/Resources/监测图斑.png",
Data = item,
NodeLevel = 2,
NodeID = item[(CruutreeNode.Data as IFeatureLayer).FeatureClass.OIDFieldName],
ParentNode = parentNode,
PackageNode = parentNode,//监测图层一级节点
PackageState = "未完成",
cMenu = new ContextMenu()
};
DataRow[] dataRows = dataDtbBGFW.Select($"TBYBH='{jcbh}'");
if (dataRows != null && dataRows.Length > 0)
{
foreach (DataRow row in dataRows)
{
TreeNode bgfwNode = new TreeNode()//第四级-变更图斑
{
Name = row["BSM"] as string,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeID = row[strDtbFeatureLayer.FeatureClass.OIDFieldName],
NodeLevel = 3,
//Data = strDtbFeatureLayer.FeatureClass.GetFeature(Convert.ToInt32(row[strDtbFeatureLayer.FeatureClass.OIDFieldName])),
ParentNode = jctbNode,
PackageNode = parentNode//监测图层一级节点
};
bgfwNode.PackageState = row["JCZT"].ToString() ?? "未完成";
jctbNode.Nodes.Add(bgfwNode);
}
}
else
{
dataOperation.InitBGDataByJCSJ(jctbNode);//打开任务包加载数据时
jctbNode.PackageState = dataOperation.GetNodesJCZT(jctbNode);
}
jctbNode.Name = $"{jcbh}({jctbNode.Nodes.Count})";
jctbNode.PackageState = dataOperation.GetNodesJCZT(jctbNode);
parentNode.Nodes.Add(jctbNode);
if (parentNode.Nodes.Count == 100 || parentNode.Nodes.Count % 2000 == 0 || dataJCTB.Rows.Count == parentNode.Nodes.Count)
{
if (parentNode.Nodes.Count == 100) this.CloseLoading();
this.Dispatcher.Invoke((Action)delegate ()
{
CruutreeNode.Nodes.Clear();
CruutreeNode.Nodes.AddRange(parentNode.Nodes);
});
}
}
if (strDtbFeatureLayer != null)
Marshal.ReleaseComObject(strDtbFeatureLayer);
#endregion
}
catch (Exception ex)
{
LogAPI.Debug("加载矢量数据树节点失败:" + ex.Message);
LogAPI.Debug("加载矢量数据树节点失败:" + ex.StackTrace);
throw ex;
}
finally
{
MapsManager.Instance.MapService.getAxMapControl().Refresh();
}
}
public void LoadDataCompleteCallBack(object obj)
{
try
{
this.Dispatcher.Invoke((Action)delegate ()
{
tvPackges.UpdateLayout();
});
}
catch (Exception)
{
LogAPI.Debug("属性表数据加载this.Invoke执行失败!");
}
}
/// <summary>
/// 关闭任务包
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnClosePackage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
try
{
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 1 || CurrentSelectNode.Data == null)
return;
if (SystemType == SystemTypeEnum.YCLJK.ToTrim())
{
dataOperation.ClosePackage_YCL(CurrentSelectNode);
}
else
{
//质检界面数据源置空
if (CheckResultsView != null)
CheckResultsView.InitData(null);
dataOperation.ClosePackage(CurrentSelectNode);
}
}
catch (Exception ex)
{
LogAPI.Debug("关闭任务包异常:" + ex.Message);
LogAPI.Debug("关闭任务包异常:" + ex.StackTrace);
MessageHelper.ShowError("关闭任务包异常:" + ex.Message);
}
}
private void LoadDB(TreeNode treeNode, bool reloadDB = false)
{
try
{
if (treeNode == null || treeNode.Data == null || (treeNode.Data as TaskPackage) == null)
{
return;
}
treeNode.Nodes = new ObservableCollection<TreeNode>();
treeNode.IsExpanded = true;
DBLoadHelper dBLoadHelper = new DBLoadHelper();
Dictionary<DataRow, int> dicTBInfo = dBLoadHelper.DBTaskLoad(treeNode.Data as TaskPackage, reloadDB);
if (dicTBInfo != null)
{
//下发图斑
TreeNode treeWYRWNode = new TreeNode()
{
Name = "下发图斑(0)",
Paixu = 1,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/外业任务.png",
Data = null,
NodeID = Guid.NewGuid(),
NodeLevel = 2,
ParentNode = treeNode,
PackageNode = treeNode,
ParentButtonVisibility = Visibility.Collapsed,
Nodes = new ObservableCollection<TreeNode>(),
cMenu = null,
};
//SetContentMenu(treeWYRWNode);
int i = 0;
foreach (var item in dicTBInfo.Where(X => X.Value == 1))
{
TreeNode treeWYTBNode = new TreeNode()
{
Name = item.Key["TBBSM"] as string,
Paixu = i++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/外业图斑.png",
//IsParent = false,
NodeID = Guid.NewGuid(),
NodeLevel = 3,
Data = item.Key,
ParentNode = treeWYRWNode,
PackageNode = treeNode,
ParentButtonVisibility = Visibility.Collapsed,
TBVisibility = bool.Parse(item.Key["ybc"] as string) == true ? Visibility.Visible : Visibility.Collapsed
};
if (i == 1)
{
treeWYTBNode.Checked = true;
}
//SetContentMenu(treeWYTBNode);
treeWYRWNode.Nodes.Add(treeWYTBNode);
}
treeWYRWNode.Name = "下发图斑(" + treeWYRWNode.Nodes.Count + ")";
treeNode.Nodes.Add(treeWYRWNode);
//自主变更图斑
TreeNode treeZZBTNode = new TreeNode()
{
Name = "自主图斑(0)",
Paixu = 2,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/自主变更.png",
NodeID = Guid.NewGuid(),
NodeLevel = 2,
//IsParent = false,
cMenu = null,
Data = null,
ParentNode = treeNode,
PackageNode = treeNode,
ZZBGVisibility = Visibility.Visible,
ParentButtonVisibility = Visibility.Collapsed,
Nodes = new ObservableCollection<TreeNode>()
};
//SetContentMenu(treeZZBTNode);
i = 0;
foreach (var item in dicTBInfo.Where(X => X.Value == 2))
{
TreeNode treeWYTBNode = new TreeNode()
{
Name = item.Key["TBBSM"] as string,
Paixu = i++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/自主图斑.png",
NodeID = Guid.NewGuid(),
NodeLevel = 3,
//IsParent = false,
Data = item.Key,
cMenu = null,
ParentNode = treeZZBTNode,
PackageNode = treeNode,
ZZTBVisibility = Visibility.Visible,
ParentButtonVisibility = Visibility.Collapsed,
TBVisibility = bool.Parse(item.Key["ybc"] as string) == true ? Visibility.Visible : Visibility.Collapsed
};
if (treeWYRWNode.Nodes.Count <= 0 && i == 1)
{
treeWYTBNode.Checked = true;
}
//SetContentMenu(treeWYTBNode);
treeZZBTNode.Nodes.Add(treeWYTBNode);
}
treeZZBTNode.Name = "自主图斑(" + treeZZBTNode.Nodes.Count + ")";
treeNode.Nodes.Add(treeZZBTNode);
}
treeNode.OpenPackageVisibility = Visibility.Collapsed;
}
catch (Exception ex)
{
LogAPI.Debug("LoadDB执行异常:" + ex);
throw ex;
}
}
/// <summary>
/// 设置星标/未星标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
if (CurrentSelectNode.NodeLevel != 2 || CurrentWYRWTB == null)
{
return;
}
string state = "星标";
if (CurrentWYRWTB.XBTB == 1)
{
state = "未星标";
}
else
{
state = "星标";
}
UpdateState(CurrentSelectNode, CurrentTaskPackage, state);
}
catch (Exception ex)
{
LogAPI.Debug("设置星标/未星标 异常:" + ex);
MessageHelper.ShowError(ex.Message);
}
}
#endregion
#region 图斑预处理相关事件功能
/// <summary>
/// 获取当前选择的图斑对应的外业任务
/// </summary>
private void GetCurrentSelectTreeNode()
{
try
{
if (tvPackges.SelectedItem is TreeNode && SystemType != SystemTypeEnum.YCLJK.ToTrim())
{
CurrentSelectNode = tvPackges.SelectedItem as TreeNode;
CurrentTaskPackage = null;
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel <= 0)
{
return;
}
if (CurrentSelectNode.NodeLevel == 1 && CurrentSelectNode.Data is TaskPackage)
{
CurrentTaskPackage = CurrentSelectNode.Data as TaskPackage;
}
else if (CurrentSelectNode.NodeLevel == 1 && CurrentSelectNode.Data is IFeatureLayer)
{ //矢量数据获取监测一级图层
CurrentTaskPackage = null;
}
else if (CurrentSelectNode.NodeLevel == 2 && CurrentSelectNode.Data is WYRWTB)
{
CurrentTaskPackage = CurrentSelectNode.ParentNode.Data as TaskPackage;
}
else if (CurrentSelectNode.NodeLevel == 2 && CurrentSelectNode.Data is DataRow)
{ //矢量数据获取监测图斑
CurrentTaskPackage = null;
}
else if (CurrentSelectNode.NodeLevel == 3 && CurrentSelectNode.Data is DTBDLTBGX)
{
CurrentTaskPackage = CurrentSelectNode.ParentNode.ParentNode.Data as TaskPackage;
}
else
{
CurrentTaskPackage = null;
}
}
else if (tvPackges.SelectedItem is TreeNode && Platform.Instance.SystemType == SystemTypeEnum.YCLJK)
{
CurrentSelectNode = tvPackges.SelectedItem as TreeNode;
CurrentTaskPackage = null;
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel <= 0)
{
return;
}
if (CurrentSelectNode.NodeLevel == 1)
{
CurrentTaskPackage = CurrentSelectNode.Data as TaskPackage;
}
else if (CurrentSelectNode.PackageNode != null)
{
CurrentTaskPackage = CurrentSelectNode.PackageNode.Data as TaskPackage;
}
else
{
CurrentTaskPackage = null;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("获取当前选择的图斑错误:" + ex.Message);
throw ex;
}
}
/// <summary>
/// 加载任务包数据
/// </summary>
/// <param name="dbPath">初始化后默认打开加载的任务包路径</param>
public void RefreshTreeData(string dbPath = "")
{
try
{
if (EngineEditorBG.EditState == esriEngineEditState.esriEngineStateEditing)
{
EngineEditorBG.StopEditing(true);
}
ClearData();
if (TreeDataSource == null || TreeDataSource.Count == 0) return;
TreeNode parentNode = TreeDataSource[0];
if (parentNode == null) return;
if (parentNode.Nodes != null)
parentNode.Nodes.Clear();
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
DBLoadHelper dBLoadHelper = new DBLoadHelper();
dBLoadHelper.SyncPackage(projectInfo.TaskPath);
int i = 0;
TreeNode defaultLoadTreeNode = null;
List<TaskPackage> lstDelete = new List<TaskPackage>();
foreach (var item in projectInfo.ListTaskPackage)
{
if (string.IsNullOrWhiteSpace(item.PackagePath) || !System.IO.File.Exists(item.PackagePath) || !System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(item.PackagePath)).Equals(projectInfo.TaskPath))
{
lstDelete.Add(item);
continue;
}
string fileName = System.IO.Path.GetFileName(item.PackagePath);
if (item.BID == null || string.IsNullOrWhiteSpace(item.BID.ToString()))
{
item.BID = Guid.NewGuid().ToString();
}
TreeNode treeNode = new TreeNode()
{
Name = fileName,
Paixu = i++,
IsExpanded = true,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/任务包.png",
NodeID = Guid.NewGuid(),
NodeLevel = 1,
Data = item,
PackageButtonVisibility = Visibility.Visible,
OpenPackageVisibility = Visibility.Visible
};
if (System.IO.File.Exists(item.PackagePath))
{
treeNode.Checked = true;
defaultLoadTreeNode = treeNode;
}
treeNode.ParentNode = parentNode;
if (parentNode.Nodes == null)
parentNode.Nodes = new ObservableCollection<TreeNode>();
parentNode.Nodes.Add(treeNode);
}
foreach (var item in lstDelete)
{
projectInfo.ListTaskPackage.Remove(item);
}
projectInfo.Save();
if (parentNode.Nodes == null)
parentNode.Name = "任务包列表(0个)";
else
parentNode.Name = "任务包列表(" + parentNode.Nodes.Count + "个)";
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("刷新任务列表异常:" + ex.Message);
}
finally
{
this.Dispatcher.Invoke(new Action(delegate
{
this.tvPackges.ItemsSource = TreeDataSource;
}));
}
}
private void ClearData()
{
try
{
if (zztbFeatureLayer != null && zztbFeatureLayer.FeatureClass != null)
{
IWorkspace workspace = (zztbFeatureLayer.FeatureClass as FeatureClass).Workspace;
workspace.ExecuteSQL("DELETE FROM ZZTB");
workspace.ExecuteSQL("DELETE FROM MarkPoint");
workspace.ExecuteSQL("DELETE FROM MarkLine");
workspace.ExecuteSQL("DELETE FROM MarkPolygon");
}
if (wyrwFeatureLayer != null && wyrwFeatureLayer.FeatureClass != null)
{
IWorkspace workspace = (wyrwFeatureLayer.FeatureClass as FeatureClass).Workspace;
workspace.ExecuteSQL("DELETE FROM WYRW");
}
if (DtbFeatureLayer != null && DtbFeatureLayer.FeatureClass != null)
{
IWorkspace workspace = (DtbFeatureLayer.FeatureClass as FeatureClass).Workspace;
workspace.ExecuteSQL("DELETE FROM DLTBBG");
}
IGraphicsContainer graphics = hookHelper.ActiveView.GraphicsContainer;
if (graphics != null)
{
graphics.DeleteAllElements();
}
this.hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground | ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, this.hookHelper.ActiveView.Extent);
}
catch (Exception ex)
{
LogAPI.Debug("“初始化”和“关闭”预审任务列表时,任务包都是未打开状态,所以需要清除预审图层数据,清除失败:" + ex.Message);
}
}
#endregion
private void tbSearchTB_TextChanged(object sender, TextChangedEventArgs e)
{
IRDBHelper rdbHelper = null;
DataTable dataTable = null;
try
{
if (TreeDataSource != null && TreeDataSource.Count != 0)
{
string queryText = tbSearchTB.Text.Trim();
foreach (TreeNode treeNode in TreeDataSource[0].Nodes)//包一级
{
treeNode.TreeVisibility = Visibility.Visible;
if (treeNode == null || treeNode.Data == null || treeNode.Data as TaskPackage == null) continue;
TaskPackage taskPackage = treeNode.Data as TaskPackage;
if (string.IsNullOrWhiteSpace(taskPackage.PackagePath) || !File.Exists(taskPackage.PackagePath)) continue;
string path = taskPackage.PackagePath;
if (taskPackage.PackageTempPath != null && File.Exists(taskPackage.PackageTempPath)) path = taskPackage.PackageTempPath;
rdbHelper = RDBFactory.CreateDbHelper($"{path}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
dataTable = rdbHelper.ExecuteDatatable("data", $"select * from DTBDLTBGX where TBBSM like '%{queryText}%' or BSM like '%{queryText}%' ", true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
treeNode.TreeVisibility = Visibility.Visible;
}
else
{
treeNode.TreeVisibility = Visibility.Collapsed;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("搜索图斑出现错误,可能的原因是::" + ex.Message);
LogAPI.Debug("搜索图斑出现错误,可能的原因是::" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
}
}