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

1021 lines
47 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.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
namespace Kingo.Plugin.General.Helper
{
/// <summary>
/// 预处理软件的处理逻辑
/// </summary>
public partial class DataOperationHelper_Default
{
#region 初始化界面
public virtual ObservableCollection<TreeNode> LoadTreeData_YCL()
{
ObservableCollection<TreeNode> TreeDataSource = new ObservableCollection<TreeNode>();
try
{
TreeNode parentNode = new TreeNode()
{
Name = $"单图斑任务列表(0个)",
Paixu = 0,
IsExpanded = true,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/列表.png",
NodeLevel = 0,
NodeID = Guid.NewGuid().ToString().Replace("-", ""),
Data = null,
IsOpenEdit = true,
ParentButtonVisibility = Visibility.Visible,
Nodes = new ObservableCollection<TreeNode>()
};
SyncPackage_YCL(projectInfo.TaskPath);
int i = 0;
List<TaskPackage> lstDelete = new List<TaskPackage>();
if (projectInfo.ListTaskPackage == null)
projectInfo.ListTaskPackage = 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,
ParentButtonVisibility = Visibility.Collapsed,
PackageButtonVisibility = Visibility.Visible,
OpenPackageVisibility = Visibility.Visible
};
if (System.IO.File.Exists(item.PackagePath))
{
treeNode.Checked = true;
}
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);
}
if (parentNode.Nodes == null)
{
parentNode.Name = "任务包列表(0个)";
}
else
{
parentNode.Name = "任务包列表(" + parentNode.Nodes.Count + "个)";
}
parentNode.IsExpanded = true;
projectInfo.Save();
TreeDataSource.Add(parentNode);
}
catch (Exception ex)
{
LogAPI.Debug("刷新任务列表异常" + ex);
MessageHelper.ShowError("刷新任务列表异常:" + ex.Message);
}
finally
{
GC.Collect();
}
return TreeDataSource;
}
#endregion
#region 节点切换
public NYYSInfo SelectedItemChanged_YCL()
{
IFeatureLayer featureLayer = null;
IRDBHelper rdbHelper = null;
IWorkspaceAPI workspaceAPI = null;
DataTable Data = null;
NYYSInfo nYYSInfo = new NYYSInfo();
try
{
EngineEditorBG.StopEditing(true);
if (CurrentSelectNode == null || CurrentSelectNode.NodeLevel != 3 || (CurrentSelectNode.Nodes != null && CurrentSelectNode.Nodes.Count > 0))
{
if (CurrentSelectNode != null && CurrentSelectNode.Name.StartsWith("自主图斑"))
{
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateEditing)
{
StartEdit(zztbFeatureLayer);
}
}
else
{
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateNotEditing)
{
EngineEditorBG.StopEditing(true);
}
}
return nYYSInfo;
}
if (CurrentTaskPackage == null || CurrentTaskPackage.PackageTempPath == null || !System.IO.File.Exists(CurrentTaskPackage.PackageTempPath))
{
LogAPI.Debug("工程信息中未找到预处理任务包【" + CurrentSelectNode.Name.ToString() + "】!");
MessageHelper.Show("工程信息中未找到预处理任务包【" + CurrentSelectNode.Name.ToString() + "】!");
return nYYSInfo;
}
bool isReadOnly = false;
string tableName = string.Empty;
if (CurrentSelectNode.ParentNode.Name.StartsWith("下发图斑("))
{
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateNotEditing)
{
EngineEditorBG.StopEditing(true);
}
tableName = "WYRW";
isReadOnly = true;
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("WYRW");
}
else if (CurrentSelectNode.ParentNode.Name.StartsWith("自主图斑("))
{
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateEditing)
StartEdit(zztbFeatureLayer);
tableName = "ZZTB";
isReadOnly = false;
featureLayer = zztbFeatureLayer;
}
else
{
return nYYSInfo;
}
if (featureLayer == null || featureLayer.FeatureClass == null)
{
LogAPI.Debug("未找到矢量图层【" + tableName + "】!");
MessageHelper.Show("未找到矢量图层【" + tableName + "】!");
return nYYSInfo;
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = "TBBSM='" + CurrentSelectNode.Name + "'",
};
IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
if (feature == null) return nYYSInfo;
MapsManager.Instance.MapService.SelectFeature(featureLayer.Name, feature.OID.ToString());
nYYSInfo.TaskPackages = CurrentTaskPackage;
rdbHelper = RDBFactory.CreateDbHelper($"{CurrentTaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
DataTable dataTable = rdbHelper.ExecuteDatatable("WYRW", $"select * from WYRW WHERE TBBSM='{CurrentSelectNode.Name}'", true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
nYYSInfo.WYRWTB = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<WYRWTB>(dataTable.Rows[0]);
}
//加载标注信息
List<string> listTable = new List<string>() { "MarkPoint", "MarkPolygon", "MarkLine" };
workspaceAPI = new WorkspaceAPI(CurrentTaskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
foreach (var item in listTable)
{
LoadData(workspaceAPI.CurrentWorkspace, item, Data);
}
if (Data == null || Data.Rows.Count == 0)
{
nYYSInfo.WYSketch = new List<WYSketch>();
}
else
{
nYYSInfo.WYSketch = KGIS.Framework.Utils.Utility.TBToList.ToList<WYSketch>(Data);
}
//加载内业预审结果信息
if (nYYSInfo.WYRWTB != null)
dataTable = rdbHelper.ExecuteDatatable("nyysresult", "select * from NYYSResult where tbbsm='" + nYYSInfo.WYRWTB.TBBSM + "'", true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
nYYSInfo.NYYSResult = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<NYYSResult>(dataTable.Rows[0]);
}
else
{
nYYSInfo.NYYSResult = new NYYSResult()
{
TBBSM = nYYSInfo.WYRWTB == null ? null : nYYSInfo.WYRWTB.TBBSM,
YPRY = projectInfo.UserName,
YPSJ = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
SFXYWY = 1
};
}
nYYSInfo.IsReadOnly = isReadOnly;
nYYSInfo.BingDataType = PluginServiceInterface.Enums.DTBDataTypeEnum.NYYCL;
}
catch (Exception ex)
{
LogAPI.Debug("节点切换失败:" + ex.Message);
LogAPI.Debug("节点切换失败:" + ex.StackTrace);
MessageHelper.ShowTips("节点切换异常!");
return nYYSInfo;
}
//finally
//{
// if (zztbFeatureLayer != null)
// Marshal.ReleaseComObject(zztbFeatureLayer);
// if (zztbFeatureLayer != null)
// Marshal.ReleaseComObject(zztbFeatureLayer);
//}
return nYYSInfo;
}
#endregion
#region 工具栏修改数据后,点击保存时更新任务包数据
/// <summary>
/// 工具栏修改数据后,点击保存时更新任务包数据
/// </summary>
/// <param name="differenceCursorEx"></param>
/// <param name="rdbHelper"></param>
/// <param name="type">0:新增 1:修改 2:删除</param>
public void UpdateData_YCL(IDifferenceCursorEx differenceCursorEx, IRDBHelper rdbHelper, int type)
{
//准备输入参数
int featureOID = -1;
//新图形
IRow sourceRow = null;
//旧图形
IRow differenceRow = null;
//变化字段
ILongArray longArray = null;
// 获取
differenceCursorEx.Next(out featureOID, out sourceRow, out differenceRow, out longArray);
// 获取编辑图形信息
while (featureOID != -1)
{
try
{
string bsm = string.Empty;
switch (type)
{
case 0://0:新增
AddFeature_YCL(sourceRow as IFeature, rdbHelper);
break;
case 1://1:修改
UpdateFeature_YCL(sourceRow, rdbHelper);
break;
case 2:// 2:删除
DeleteFeature_YCL(differenceRow, rdbHelper);
break;
}
}
catch (Exception ex)
{
LogAPI.Debug("UpdateData_YCL异常:" + ex.Message);
LogAPI.Debug("UpdateData_YCL异常:" + ex.StackTrace);
throw ex;
}
differenceCursorEx.Next(out featureOID, out sourceRow, out differenceRow, out longArray);
}
}
#endregion
#region 修改更新图斑同步保存到任务包
/// <summary>
/// 修改更新图斑同步保存到任务包
/// </summary>
/// <param name="sourceRow"></param>
/// <param name="rdbHelper"></param>
private void UpdateFeature_YCL(IRow sourceRow, IRDBHelper rdbHelper)
{
try
{
string tbbsm = string.Empty;
int tbbsmIndex = sourceRow.Fields.FindField("TBBSM");
if (tbbsmIndex > -1)
{
tbbsm = sourceRow.get_Value(tbbsmIndex) as string;
}
if (string.IsNullOrWhiteSpace(tbbsm))
{
tbbsm = Guid.NewGuid().ToString().Replace("-", "");
}
IClone clone = (sourceRow as IFeature).ShapeCopy as IClone;
if (((sourceRow as IFeature).ShapeCopy as IArea).Area < 50)
{
throw new Exception("自主举证图斑面积(Shape_Area)不允许小于50平方米!");
}
//验证是否和原有数据存在压盖
DBLoadHelper.CheckAddFeature(clone.Clone() as IGeometry, sourceRow.OID);
double tqmj = ATEllipseArea.GetPolygonArea(clone.Clone() as IPolygon) / 666.67;
IGeometry cloneGeometry = clone.Clone() as IGeometry;
string egeometry = GeometryConvertHelper.ConverIGometryToJson(cloneGeometry);
IArea area = cloneGeometry as IArea;
string setValue = $" EGeometry='{egeometry}',geometry='{egeometry}',TBMJ={Math.Round(tqmj, 2)},ZXDX={area.Centroid.X},ZXDY={area.Centroid.Y},MAXX={cloneGeometry.Envelope.XMax},MAXY={cloneGeometry.Envelope.YMax},MINX={cloneGeometry.Envelope.XMin},MINY={cloneGeometry.Envelope.YMin}";
string fieldstr = "sjly,xzqdm,xzdm,cjdm,jcmj,tblx";
foreach (var item in fieldstr.Split(','))
{
int fieldIndex = sourceRow.Fields.FindField(item);
if (fieldIndex == -1)
{
continue;
}
IField field = sourceRow.Fields.Field[fieldIndex];
object obj = sourceRow.get_Value(fieldIndex);
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeOID:
if (obj is DBNull)
{
setValue += "," + item + "=null";
}
else
{
setValue += "," + item + "=" + obj;
}
break;
default:
if (obj is DBNull || string.IsNullOrWhiteSpace(obj.ToString()))
{
setValue += "," + item + "=null";
}
else
{
setValue += "," + item + "='" + obj + "'";
}
break;
}
}
string excuteSQL = string.Format("update wyrw set {0} where tbbsm='{1}'", setValue, tbbsm);
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
rdbHelper.Commit();
}
catch (Exception ex)
{
LogAPI.Debug("UpdateFeature异常:" + ex.Message);
LogAPI.Debug("UpdateFeature异常:" + ex.StackTrace);
throw ex;
}
}
#endregion
#region 新增图斑同步保存到任务包
/// <summary>
/// 新增图斑同步保存到任务包
/// </summary>
private void AddFeature_YCL(IFeature Newfeature, IRDBHelper rdbHelper)
{
try
{
if (Newfeature == null || Newfeature.Shape.IsEmpty) return;
#region 自主新增图斑上图面积最小50
IArea area1 = Newfeature.ShapeCopy as IArea;
double jcmj = Math.Round(Math.Abs(area1.Area), 2);
if (jcmj < 50)
{
MessageHelper.Show("自主举证图斑面积(Shape_Area)不允许小于50平方米!");
Newfeature.Delete();
return;
}
#endregion
#region 验证是否和原有数据存在压盖
try
{
CheckOverlap(Newfeature);
}
catch (Exception ex)
{
MessageHelper.Show(ex.Message);
Newfeature.Delete();
return;
}
#endregion
#region 继承基础库信息:行政区代码,村代码,乡镇代码
string xzqdm = string.Empty;
string xzdm = string.Empty;
string cdm = string.Empty;
IFeatureLayer cjdcqLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_村级调查区");
if (cjdcqLayer != null && cjdcqLayer.FeatureClass != null)
{
List<IFeature> lstFeature = FeatureAPI.Identify(Newfeature.ShapeCopy, cjdcqLayer);
if (lstFeature.Count > 0)
{
IFeature xzqFeature = lstFeature[0];
int indexZLDWDM = xzqFeature.Fields.FindField("zldwdm");
if (indexZLDWDM > -1)
{
object value = xzqFeature.get_Value(indexZLDWDM);
if (!(value is System.DBNull))
{
xzqdm = value.ToString();
if (xzqdm.Length >= 12)
{
cdm = xzqdm.Substring(0, 12);
}
else
{
cdm = xzqdm;
}
if (xzqdm.Length >= 9)
{
xzdm = xzqdm.Substring(0, 9);
}
else
{
xzdm = xzqdm;
}
if (xzqdm.Length >= 6)
{
xzqdm = xzqdm.Substring(0, 6);
}
}
}
}
}
#endregion
#region 验证转换后的json坐标串是否可以转换回去,如果转换并投影后图形为空,说明转换后的坐标串egeometry不正确
string geometryStr = GeometryConvertHelper.ConverIGometryToJson(Newfeature.ShapeCopy);
IGeometry convertGeometry = GeometryConvertHelper.ConverJsonToIGeoemtry(geometryStr);
IClone clone = convertGeometry as IClone;
IGeometry convertGeometry1 = clone.Clone() as IGeometry;
if (convertGeometry == null)
{
LogAPI.Debug("图形转换后的Json坐标串无法转回图形:" + geometryStr);
throw new Exception("图形转换后的Json坐标串无法转回图形!");
}
convertGeometry.Project(this.hookHelper.FocusMap.SpatialReference);
if (convertGeometry.IsEmpty)
{
LogAPI.Debug("图形转换后的Json坐标串无法转回图形:" + geometryStr);
Marshal.ReleaseComObject(convertGeometry);
throw new Exception("图形转换的Json坐标串可能坐标参考不正确!");
}
Marshal.ReleaseComObject(convertGeometry);
#endregion
#region 获取图形相关数据,保存至db文件中
IArea area = convertGeometry1 as IArea;
string tbbsm = Guid.NewGuid().ToString();
string excuteSQL = string.Format("insert into wyrw(tbbsm,sjly,egeometry,geometry,xzqdm,xzdm,cjdm,jcmj,tbmj,zxdx,zxdy,maxx,maxy,minx,miny,tblx)values('{0}','ZZBG','{1}','{1}','{2}','{3}','{4}',{5},{6},{7},{8},{9},{10},{11},{12},'{13}')", tbbsm, geometryStr, xzqdm, xzdm, cdm, Math.Round(jcmj / 666.67, 2), jcmj, area.Centroid.X, area.Centroid.Y, convertGeometry1.Envelope.XMax, convertGeometry1.Envelope.YMax, convertGeometry1.Envelope.XMin, convertGeometry1.Envelope.YMin, "ZZTB");
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
int fIndex = Newfeature.Fields.FindField("Geometry");
if (fIndex > -1)
Newfeature.set_Value(fIndex, geometryStr);
fIndex = Newfeature.Fields.FindField("EGeometry");
if (fIndex > -1)
Newfeature.set_Value(fIndex, geometryStr);
Newfeature.Store();
IFeatureLayer zztbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZZTB");
(zztbFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"update zztb set TBBSM='{tbbsm}',BID='{(CurrentSelectNode.PackageNode.Data as TaskPackage).BID}', SJLY='ZZBG',TBLX='ZZBG',xzqdm='{xzqdm}',xzdm='{xzdm}',cjdm='{cdm}',JCMJ={Math.Round(jcmj / 666.67, 2)},TBMJ={jcmj},ZXDX={area.Centroid.X},ZXDY={area.Centroid.Y},MAXX={convertGeometry1.Envelope.XMax},MAXY={convertGeometry1.Envelope.YMax},MINX={convertGeometry1.Envelope.XMin},MINY={convertGeometry1.Envelope.YMin} where objectid={Newfeature.OID}");
#endregion
#region 新增自主图斑节点刷新
if (CurrentSelectNode != null)
{
TreeNode EditTreeNode = CurrentSelectNode;
if (CurrentSelectNode.NodeLevel == 3)
{
EditTreeNode = CurrentSelectNode.ParentNode;
}
if (EditTreeNode != null)
{
if (EditTreeNode.Nodes == null)
EditTreeNode.Nodes = new ObservableCollection<TreeNode>();
TreeNode addNode = new TreeNode()
{
Name = tbbsm,
Paixu = EditTreeNode.Nodes.Count,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBYCL;component/Resources/自主图斑.png",
NodeID = Guid.NewGuid(),
NodeLevel = 3,
Data = rdbHelper.ExecuteDatatable("data", $"select * from wyrw where tbbsm='{tbbsm}'", true).Rows[0],
cMenu = null,
PackageNode = EditTreeNode.PackageNode,
ParentNode = EditTreeNode,
ZZTBVisibility = Visibility.Visible
};
EditTreeNode.IsExpanded = true;
EditTreeNode.Name = "自主图斑(" + (EditTreeNode.Nodes.Count + 1) + ")";
EditTreeNode.Nodes.Add(addNode);
addNode.Checked = true;
}
}
#endregion
}
catch (Exception ex)
{
if (rdbHelper != null)
rdbHelper.Rollback();
LogAPI.Debug("新增图斑同步保存到任务包异常:" + ex.Message);
LogAPI.Debug("新增图斑同步保存到任务包异常:" + ex);
LogAPI.Debug("新增图斑同步保存到任务包异常:" + ex.StackTrace);
throw ex;
}
}
#endregion
#region 删除图斑同步保存任务包
/// <summary>
/// 删除图斑同步保存任务包
/// </summary>
/// <param name="differenceRow"></param>
/// <param name="rdbHelper"></param>
private void DeleteFeature_YCL(IRow differenceRow, IRDBHelper rdbHelper)
{
string tbbsm = string.Empty;
try
{
int tbbsmIndex = differenceRow.Fields.FindField("TBBSM");
if (tbbsmIndex > -1)
tbbsm = differenceRow.get_Value(tbbsmIndex) as string;
TreeNode EditTreeNode = CurrentSelectNode;
if (CurrentSelectNode.NodeLevel == 3)
{
EditTreeNode = CurrentSelectNode.ParentNode;
}
if (EditTreeNode != null)
{
TreeNode treeNode = EditTreeNode.Nodes.FirstOrDefault(x => x.Name.Equals(tbbsm));
if (treeNode != null)
{
EditTreeNode.Nodes.Remove(treeNode);
EditTreeNode.Name = $"自主图斑({EditTreeNode.Nodes.Count})";
}
}
string excuteSQL = "delete from {0} where tbbsm='{1}'";
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "WYRW", tbbsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "NYYSResult", tbbsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "WYSketch", tbbsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from FJGX where TBBSM ='{tbbsm}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from FJGX where tbbsm not in(select tbbsm from WYRW);", CommandType.Text);
}
catch (Exception ex)
{
LogAPI.Debug("DeleteFeature_YCL异常:" + ex.Message);
LogAPI.Debug("DeleteFeature_YCL异常:" + ex.StackTrace);
}
}
#endregion
#region 判断图形是否与图层内数据有压盖
public virtual void CheckOverlap(IFeature feature)
{
try
{
IFeatureLayer featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZZTB");
if (featureLayer != null && featureLayer.FeatureClass != null)
{
var dic = FeatureAPI.Identify2(feature.ShapeCopy, featureLayer);
if (dic != null && dic.Count > 0)
{
if (dic.Count == 1 && dic.FindFirst().OID == feature.OID) { }
else
throw new Exception("新增图斑存在与自主图斑图层(ZZTB)数据压盖!");
}
}
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("WYRW");
if (featureLayer != null && featureLayer.FeatureClass != null)
{
var dic = FeatureAPI.Identify2(feature.ShapeCopy, featureLayer as ILayer);
if (dic != null && dic.Count > 0)
{
throw new Exception("新增图斑存在与外业任务图层(WYRW)数据压盖!");
}
}
List<string> lstLayerName = new List<string>() { "基础_国家下发监测图斑", "基础_专项数据" };
foreach (var layerName in lstLayerName)
{
IFeatureLayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName(layerName);
if (layer == null || !(layer is IFeatureLayer) || (layer as IFeatureLayer).FeatureClass == null)
continue;
featureLayer = layer as IFeatureLayer;
if (featureLayer != null && featureLayer.FeatureClass != null)
{
var dic = FeatureAPI.Identify2(feature.ShapeCopy, featureLayer);
if (dic != null && dic.Count > 0)
{
throw new Exception($"新增图斑存在与【{layerName}】数据压盖!");
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("判断图形是否与图层内数据有压盖异常:" + ex.Message);
LogAPI.Debug("判断图形是否与图层内数据有压盖异常:" + ex);
LogAPI.Debug("判断图形是否与图层内数据有压盖异常:" + ex.StackTrace);
throw ex;
}
}
#endregion
#region 打开任务包
public virtual void OpenPackage_YCL()
{
try
{
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateNotEditing)
{
if (EngineEditorBG.HasEdits())
SaveEingineEdit();
EngineEditorBG.StopEditing(true);
}
if ((CurrentSelectNode.Data as TaskPackage) != null)
LoadDB(CurrentSelectNode);
if (EngineEditorBG.EditState != esriEngineEditState.esriEngineStateEditing)
StartEdit(zztbFeatureLayer);
}
catch (Exception ex)
{
LogAPI.Debug("OpenPackage_YCL异常:" + ex.Message);
LogAPI.Debug("OpenPackage_YCL异常:" + ex.StackTrace);
throw ex;
}
}
private void LoadDB(TreeNode treeNode, bool reloadDB = false)
{
try
{
treeNode.Nodes = new ObservableCollection<TreeNode>();
treeNode.IsExpanded = true;
Dictionary<DataRow, int> dicTBInfo = new 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,
};
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;
}
treeZZBTNode.Nodes.Add(treeWYTBNode);
}
treeZZBTNode.Name = "自主图斑(" + treeZZBTNode.Nodes.Count + ")";
treeNode.Nodes.Add(treeZZBTNode);
}
treeNode.OpenPackageVisibility = Visibility.Collapsed;
}
catch (Exception ex)
{
LogAPI.Debug("LoadDB执行异常:" + ex.Message);
LogAPI.Debug("LoadDB执行异常:" + ex.StackTrace);
throw ex;
}
}
#endregion
#region 关闭任务包
/// <summary>
/// 预处理---关闭任务包
/// </summary>
/// <param name="closeNode"></param>
public virtual void ClosePackage_YCL(TreeNode closeNode)
{
IWorkspaceAPI workspaceAPI = null;
IWorkspaceAPI workspaceSchemeAPI = null;
try
{
if (EngineEditorBG.EditState == esriEngineEditState.esriEngineStateEditing)
EngineEditorBG.StopEditing(true);
TaskPackage taskPackage = closeNode.Data as TaskPackage;
if (!System.IO.File.Exists(taskPackage.PackageTempPath) || string.IsNullOrWhiteSpace(taskPackage.GDBPath))
return;
workspaceAPI = new WorkspaceAPI(taskPackage.GDBPath, WorkspaceTypeEnum.GDBFile, true);
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM WYRW where bid='{0}'", taskPackage.BID));
workspaceSchemeAPI = new WorkspaceAPI(taskPackage.SchemeGDBPath, WorkspaceTypeEnum.GDBFile, true);
workspaceSchemeAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM ZZTB where bid='{0}'", taskPackage.BID));
workspaceSchemeAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM MarkPoint where bid='{0}'", taskPackage.BID));
workspaceSchemeAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM MarkLine where bid='{0}'", taskPackage.BID));
workspaceSchemeAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM MarkPolygon where bid='{0}'", taskPackage.BID));
closeNode.Nodes = null;
this.hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground | esriViewDrawPhase.esriViewGeoSelection, null, this.hookHelper.ActiveView.Extent);
closeNode.OpenPackageVisibility = Visibility.Visible;
}
catch (Exception ex)
{
LogAPI.Debug("关闭任务包异常:" + ex.Message);
LogAPI.Debug("关闭任务包异常:" + ex.StackTrace);
MessageHelper.ShowError("关闭任务包异常:" + ex.Message);
}
finally
{
if (workspaceSchemeAPI != null)
workspaceSchemeAPI.CloseWorkspace();
if (workspaceAPI != null)
workspaceAPI.CloseWorkspace();
}
}
#endregion
#region 同步任务目录文件夹任务包文件
/// <summary>
/// 同步任务目录文件夹任务包文件
/// </summary>
/// <param name="taskPath"></param>
public virtual void SyncPackage_YCL(string taskPath)
{
IRDBHelper rdbHelper = null;
DataTable dataTable = null;
try
{
if (string.IsNullOrWhiteSpace(taskPath) || !Directory.Exists(taskPath))
{
return;
}
if (projectInfo.ListTaskPackage == null)
{
projectInfo.ListTaskPackage = new List<TaskPackage>();
}
DirectoryInfo directory = new DirectoryInfo(System.IO.Path.Combine(taskPath, "未完成"));
FileInfo[] files = directory.GetFiles("*.ysrw", SearchOption.AllDirectories);
if (files == null || files.Length <= 0)
{
return;
}
foreach (var item in files)
{
try
{
TaskPackage taskPackage = projectInfo.ListTaskPackage.FirstOrDefault(x => x.PackagePath.Equals(item.FullName));
if (taskPackage != null) continue;
rdbHelper = RDBFactory.CreateDbHelper($"{item.FullName}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (!rdbHelper.TableIsExist("wyrw"))
{
throw new Exception("选择的内业预处理任务包不存在外业任务(WYRW)表!");
}
if (!rdbHelper.TableIsExist("YSJ"))
{
throw new Exception("选择的内业预处理任务包不存在元数据(YSJ)表!");
}
dataTable = rdbHelper.ExecuteDatatable("ysj", "select * from ysj", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
throw new Exception("选择的内业预处理任务包元数据(YSJ)表数据为空!");
}
string blx = dataTable.Rows[0]["BLX"] as string;
dataTable = rdbHelper.ExecuteDatatable("wyrw", "select * from wyrw", true);
if ((dataTable == null || dataTable.Rows.Count <= 0) && !blx.Equals("YSRW_New"))
{
throw new Exception("选择的内业预处理任务包外业任务表数据为空!");
}
projectInfo.ListTaskPackage.Add(new TaskPackage() { BID = Guid.NewGuid().ToString(), PackagePath = item.FullName, State = "未完成" });
projectInfo.Save();
}
catch (Exception ex)
{
LogAPI.Debug(item + "无法添加:" + ex.Message);
LogAPI.Debug(item + "无法添加:" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region LoadData
private void LoadData(IWorkspace workspace, string tableName, DataTable Data)
{
ICursor cursor = null;
ITable table = null;
try
{
table = (workspace as IFeatureWorkspace).OpenTable(tableName);
if (Data == null)
{
Data = new DataTable();
ConstructColumn(table.Fields, Data);
}
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"TBBSM='{CurrentSelectNode.Name}' and BID='{(CurrentSelectNode.PackageNode.Data as TaskPackage).BID}'"
};
cursor = table.Search(queryFilter, true);
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
DataRow dr = Data.NewRow();
for (int i = 0; i < Data.Columns.Count; i++)
{
object obj = row.get_Value((int)Data.Columns[i].ExtendedProperties["index"]);
if (obj == null)
{
continue;
}
else
{
if ((obj.ToString()).Contains("1899/12/30 0:00:00"))
{
obj = System.DBNull.Value;
}
}
//字符串时,去空格,对应bug10473
if (obj is string)
{
obj = obj.ToString().Trim();
}
dr[i] = obj;
}
Data.Rows.Add(dr);
Marshal.ReleaseComObject(row);
}
}
catch (Exception ex)
{
LogAPI.Debug("加载" + tableName + "数据异常:" + ex.Message);
MessageHelper.ShowError("加载" + tableName + "数据异常:" + ex.Message);
}
finally
{
if (cursor != null)
{
Marshal.ReleaseComObject(cursor);
}
//if (tableAPI != null)
//{
// tableAPI.CloseTable();
//}
}
}
private void ConstructColumn(IFields fields, DataTable Data)
{
if (fields != null)
{
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.get_Field(i);
if (field.Name.ToUpper().EndsWith("SHAPE"))
continue;
DataColumn col = new DataColumn();
col.ExtendedProperties.Add("index", i);
col.ColumnName = field.Name;
col.Caption = field.AliasName;
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
col.DataType = typeof(short);
break;
case esriFieldType.esriFieldTypeInteger:
col.DataType = typeof(int);
break;
case esriFieldType.esriFieldTypeSingle:
break;
case esriFieldType.esriFieldTypeDouble:
col.DataType = typeof(double);
break;
case esriFieldType.esriFieldTypeString:
col.DataType = typeof(string);
break;
case esriFieldType.esriFieldTypeDate:
col.DataType = typeof(DateTime);
break;
case esriFieldType.esriFieldTypeOID:
col.DataType = typeof(Int32);
break;
case esriFieldType.esriFieldTypeGeometry:
break;
case esriFieldType.esriFieldTypeBlob:
break;
case esriFieldType.esriFieldTypeRaster:
break;
case esriFieldType.esriFieldTypeGUID:
break;
case esriFieldType.esriFieldTypeGlobalID:
break;
case esriFieldType.esriFieldTypeXML:
break;
default:
break;
}
col.ReadOnly = !field.Editable;//编辑状态启用默认是否可以编辑
Data.Columns.Add(col);
System.Runtime.InteropServices.Marshal.ReleaseComObject(field);
}
}
}
#endregion
}
}