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.
3578 lines
189 KiB
3578 lines
189 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.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.Crypto; |
|
using Kingo.PluginServiceInterface; |
|
using Kingo.PluginServiceInterface.Model; |
|
using Kingo.RuleCheck; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Xml.Linq; |
|
|
|
namespace Kingo.Plugin.General.Helper |
|
{ |
|
public class DTBDBLoadHelper |
|
{ |
|
private ProjectInfo ProjectInfo { get; set; } |
|
/// <summary> |
|
/// 返回变更范围数据,用来绑定树结构 |
|
/// </summary> |
|
private Dictionary<WYRWTB, List<DTBDLTBGX>> DicTBInfo { get; set; } |
|
/// <summary> |
|
/// 编号 |
|
/// </summary> |
|
private string bh { get; set; } |
|
|
|
/// <summary> |
|
/// 加载db,矢量化图形 |
|
/// </summary> |
|
/// <param name="dbPath">任务包路径</param> |
|
/// <param name="reload">重新加载原始任务包</param> |
|
public Dictionary<WYRWTB, List<DTBDLTBGX>> DBTaskLoad(TaskPackage taskPackage, IHookHelper hookHelper, bool reload = false) |
|
{ |
|
IWorkspaceAPI workspaceAPI = null; |
|
IWorkspaceAPI workspaceSchemeAPI = null; |
|
IRDBHelper rdbHelper = null; |
|
string tempPath = string.Empty; |
|
try |
|
{ |
|
DicTBInfo = new Dictionary<WYRWTB, List<DTBDLTBGX>>(); |
|
string openPath = taskPackage.PackagePath; |
|
if (string.IsNullOrWhiteSpace(openPath) || !File.Exists(openPath)) |
|
{ |
|
return DicTBInfo; |
|
} |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) |
|
{ |
|
throw new Exception("未检测到当前打开的工程,请先打开工程!"); |
|
} |
|
if (string.IsNullOrWhiteSpace(ProjectInfo.JCKPath)) |
|
{ |
|
throw new Exception("请先使用“工作目录设置”功能设置基础库数据!"); |
|
} |
|
if (string.IsNullOrWhiteSpace(ProjectInfo.UserName)) |
|
{ |
|
throw new Exception("请先使用“用户信息设置”功能设置用户名!"); |
|
} |
|
rdbHelper = RDBFactory.CreateDbHelper($"{openPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
if (!rdbHelper.TableIsExist("WYRW")) |
|
{ |
|
throw new Exception("选择的任务包不存在WYRW(外业任务)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("WYHCCG")) |
|
{ |
|
throw new Exception("选择的任务包不存在WYHCCG(外业核查成果)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("WYHCFJ")) |
|
{ |
|
throw new Exception("选择的任务包不存在WYHCFJ(附件)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("LABEL")) |
|
{ |
|
throw new Exception("选择的任务包不存在LABEL(外业草图)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("NYYSResult")) |
|
{ |
|
throw new Exception("选择的任务包不存在NYYSResult(内业预审结果)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("WYSketch")) |
|
{ |
|
throw new Exception("选择的任务包不存在WYSketch(外业指导草图)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
if (!rdbHelper.TableIsExist("YSJ")) |
|
{ |
|
throw new Exception("选择的任务包不存在YSJ(元数据)表,请确认是否是《单图斑建库任务包》!"); |
|
} |
|
long count = (long)rdbHelper.ExecuteScalar("select count(1) from wyrw", CommandType.Text); |
|
if (count <= 0) |
|
{ |
|
throw new Exception("选择的任务包外业任务数据(WYRW)表为空,请检查是否是《单图斑建库任务包》!"); |
|
} |
|
//else if (count > 1) |
|
//{ |
|
// throw new Exception("选择的任务包外业任务数据(WYRW)共" + count + "条数据(单图斑建库只允许有一条外业任务图斑),请检查《单图斑建库任务包》数据!"); |
|
//} |
|
DataTable dt = rdbHelper.ExecuteDatatable("ysj", "select * from ysj", true); |
|
if (dt == null || dt.Rows.Count <= 0) |
|
{ |
|
throw new Exception("选择的任务包元数据(YSJ)表为空,请检查是否是《单图斑建库任务包》!"); |
|
} |
|
if (dt.Rows[0]["Encrypted"].ToString() == "1" && !System.IO.Path.GetFileName(openPath).EndsWith(".encrypt.jkrw")) |
|
{ |
|
throw new Exception("选择的任务包元数据(YSJ)Encrypted=1表示是加密包,但任务包文件名后缀不是“.encrypt.jkrw”!"); |
|
} |
|
//如果wkid为空,则在打开的时候将工程的坐标参考wkid回写到db包中 |
|
int wkid = 0; |
|
if (!(dt.Rows[0]["WKID"] is DBNull)) |
|
{ |
|
wkid = int.Parse(dt.Rows[0]["WKID"].ToString()); |
|
} |
|
if (wkid <= 0) |
|
{ |
|
wkid = this.ProjectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (wkid <= 0) |
|
{ |
|
KGIS.Framework.AE.GaussCalculate.CoordinateReferenceMapping coordinateReferenceMapping = KGIS.Framework.AE.GaussCalculate.CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (this.ProjectInfo.ZYJD > x.MinX && ProjectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(ProjectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
wkid = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
rdbHelper.ExecuteNonQuery($"update ysj set wkid={wkid}", CommandType.Text); |
|
} |
|
//任务包包号 |
|
bh = taskPackage.BID; |
|
string fileName = System.IO.Path.GetFileName(openPath); |
|
tempPath = System.IO.Path.Combine(ProjectInfo.TaskPath, "临时", fileName); |
|
if (!Directory.Exists(tempPath)) |
|
{ |
|
Directory.CreateDirectory(tempPath); |
|
} |
|
//if (!System.IO.Directory.Exists(taskPackage.PackagePath + "_Work")) |
|
//{ |
|
// System.IO.Directory.CreateDirectory(taskPackage.PackagePath + "_Work"); |
|
//} |
|
if (fileName.EndsWith(".encrypt.jkrw", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
taskPackage.DecryptPackagePath = System.IO.Path.Combine(tempPath, fileName.Substring(0, fileName.Length - 13) + ".jkrw_back"); |
|
if (!File.Exists(taskPackage.DecryptPackagePath)) |
|
{ |
|
File.Copy(openPath, taskPackage.DecryptPackagePath, true); |
|
DecryptDB(taskPackage.DecryptPackagePath); |
|
} |
|
} |
|
else |
|
{ |
|
taskPackage.DecryptPackagePath = System.IO.Path.Combine(tempPath, fileName + "_back"); |
|
if (!File.Exists(taskPackage.DecryptPackagePath)) |
|
{ |
|
File.Copy(openPath, taskPackage.DecryptPackagePath, true); |
|
} |
|
} |
|
taskPackage.PackageTempPath = taskPackage.DecryptPackagePath.Substring(0, taskPackage.DecryptPackagePath.Length - 5); |
|
//拷贝临时db |
|
if (!File.Exists(taskPackage.PackageTempPath)) |
|
{ |
|
DecryptDB(taskPackage.DecryptPackagePath); |
|
File.Copy(taskPackage.DecryptPackagePath, taskPackage.PackageTempPath, true); |
|
|
|
if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("65")) |
|
{ |
|
try |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS) |
|
{ |
|
int aaa = rdbHelper.ExecuteNonQueryWithException("update WYHCFJ set IS_SELECTED=1 where IS_SELECTED is null or IS_SELECTED = '' or IS_SELECTED <> 1", CommandType.Text); |
|
} |
|
} |
|
catch { } |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
rdbHelper = null; |
|
} |
|
} |
|
} |
|
|
|
//第一次加载任务包时,做一次质检:耗时太久 |
|
//List<Kingo.RuleCheck.RuleEntity> results = Helper.DBLoadHelper.DTBCheckPackage(null, taskPackage.PackageTempPath); |
|
//Helper.OpenTaskTreeViewHelper.OpenCheckResult(hookHelper, results); |
|
} |
|
else if (reload) |
|
{ |
|
if (File.Exists(taskPackage.PackageTempPath)) |
|
{ |
|
File.Copy(taskPackage.PackageTempPath, taskPackage.PackageTempPath + "-" + DateTime.Now.ToString("yyyyMMddHHmmss"), true); |
|
} |
|
File.Copy(taskPackage.DecryptPackagePath, taskPackage.PackageTempPath, true); |
|
} |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
rdbHelper = null; |
|
} |
|
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
CheckTableExist(rdbHelper); |
|
|
|
if (taskPackage.GDBPath == null || string.IsNullOrWhiteSpace(taskPackage.GDBPath) || !Directory.Exists(taskPackage.GDBPath)) |
|
{ |
|
taskPackage.GDBPath = ProjectInfo.DTBJKDatabase; |
|
if (!Directory.Exists(taskPackage.GDBPath)) |
|
{ |
|
PluginServiceInterface.CommonHelper.DirectoryCopy(SysAppPath.GetCurrentAppPath() + "工作空间DTBJK\\DatabaseTemplate\\Scheme-JK.gdb", System.IO.Path.GetDirectoryName(taskPackage.GDBPath)); |
|
} |
|
} |
|
if (taskPackage.SchemeGDBPath == null || string.IsNullOrWhiteSpace(taskPackage.SchemeGDBPath) || !Directory.Exists(taskPackage.SchemeGDBPath)) |
|
{ |
|
taskPackage.SchemeGDBPath = ProjectInfo.DTBBGGXDatabase; |
|
if (!Directory.Exists(taskPackage.SchemeGDBPath)) |
|
{ |
|
PluginServiceInterface.CommonHelper.DirectoryCopy(SysAppPath.GetCurrentAppPath() + "工作空间DTBJK\\DatabaseTemplate\\DTBDLTBBGGX.gdb", System.IO.Path.GetDirectoryName(taskPackage.SchemeGDBPath)); |
|
} |
|
} |
|
ProjectInfo.Save(); |
|
workspaceAPI = new WorkspaceAPI(taskPackage.GDBPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true); |
|
workspaceSchemeAPI = new WorkspaceAPI(taskPackage.SchemeGDBPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true); |
|
SetISpatialReference(workspaceSchemeAPI); |
|
SetISpatialReference(workspaceAPI); |
|
ImportDB(workspaceAPI, workspaceSchemeAPI, rdbHelper); |
|
return DicTBInfo; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("加载db,矢量化图形 DBTaskLoad 异常:" + ex.Message); |
|
LogAPI.Debug("加载db,矢量化图形 DBTaskLoad 异常:" + ex.StackTrace); |
|
|
|
try |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
rdbHelper = null; |
|
} |
|
if (Directory.Exists(tempPath)) |
|
{ |
|
Directory.Delete(tempPath, true); |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (workspaceSchemeAPI != null) |
|
{ |
|
workspaceSchemeAPI.CloseWorkspace(); |
|
} |
|
if (workspaceAPI != null) |
|
{ |
|
workspaceAPI.CloseWorkspace(); |
|
} |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 解密db |
|
/// </summary> |
|
private void DecryptDB(string dbPath, IRDBHelper rdbHelper = null) |
|
{ |
|
bool closeRDBHelper = false; |
|
try |
|
{ |
|
if (rdbHelper == null) |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
closeRDBHelper = true; |
|
} |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("ysj", "select * from ysj", true); |
|
if (dataTable == null || dataTable.Rows.Count == 0) |
|
{ |
|
throw new Exception("元数据为空!"); |
|
} |
|
YSJ YSJInfo = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<YSJ>(dataTable.Rows[0]); |
|
if (YSJInfo == null) |
|
{ |
|
throw new Exception("获取元数据失败!"); |
|
} |
|
string key = string.Empty; |
|
if (YSJInfo.Encrypted == 1) |
|
{ |
|
if (string.IsNullOrWhiteSpace(YSJInfo.Pwd)) |
|
{ |
|
throw new Exception("任务包元数据表Encrypted字段为1(加密包),但Pwd密码字段为空!"); |
|
} |
|
key = SM2Decrypt(YSJInfo.Pwd, this.ProjectInfo.CODE); |
|
List<string> listTableName = new List<string>() { "wyrw", "dtbdltbgx", "dtbdltbgxgc" }; |
|
foreach (var tableName in listTableName) |
|
{ |
|
dataTable = rdbHelper.ExecuteDatatable("wyrw", $"select bsm,egeometry from {tableName}", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
string excuteSQL = "update {2} set geometry='{0}',egeometry='{0}' where bsm='{1}'"; |
|
if (tableName.Equals("dtbdltbgx", StringComparison.CurrentCultureIgnoreCase) || tableName.Equals("dtbdltbgxgc", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
excuteSQL = "update {2} set egeometry='{0}' where bsm='{1}'"; |
|
} |
|
foreach (DataRow item in dataTable.Rows) |
|
{ |
|
string geometryStr = item["egeometry"] as string; |
|
try |
|
{ |
|
if (!string.IsNullOrWhiteSpace(geometryStr)) |
|
{ |
|
geometryStr = SM4Decrypt(geometryStr, key); |
|
} |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
try |
|
{ |
|
IGeometry geometry = ConverJsonToIGeoemtry(geometryStr); |
|
} |
|
catch |
|
{ |
|
throw ex; |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, geometryStr, item["bsm"], tableName), CommandType.Text); |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException("update ysj set Encrypted=0,pwd=null", CommandType.Text); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("解密任务包异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (closeRDBHelper && rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 非对称解密 |
|
/// </summary> |
|
public static string SM2Decrypt(string txtWord, string xzqdm) |
|
{ |
|
try |
|
{ |
|
return Encoding.UTF8.GetString(SM2.Decrypt(GetDogKey(1, xzqdm), txtWord)); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("非对称解密失败,请检查是否插入加密狗:" + ex.Message); |
|
throw new Exception("请检查是否插入加密狗!"); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取加密狗 |
|
/// </summary> |
|
/// <param name="keyType">1:内网私钥 2:内网公钥 3:枢纽机公钥</param> |
|
/// <returns></returns> |
|
public static string GetDogKey(int keyType, string xzqdm) |
|
{ |
|
try |
|
{ |
|
KGIS.USBDog.USBKey uSBKey = KGIS.USBDog.Dog.GetDogContent(); |
|
if (uSBKey == null) |
|
{ |
|
string dogKey = SysConfigsOprator.GetAppsetingValueByKey("TestKey"); |
|
if (!string.IsNullOrWhiteSpace(dogKey) && dogKey.Equals("kingo")) |
|
{ |
|
switch (keyType) |
|
{ |
|
case 1: |
|
return SysConfigsOprator.GetAppsetingValueByKey("SM2PriK"); |
|
case 2: |
|
return SysConfigsOprator.GetAppsetingValueByKey("SM2PubK"); |
|
case 3: |
|
return SysConfigsOprator.GetAppsetingValueByKey("SM2OutPubK"); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
if (uSBKey.Xzqdm.EndsWith("0000"))//省级加密狗 |
|
{ |
|
|
|
} |
|
else if (uSBKey.Xzqdm.EndsWith("00") && xzqdm.StartsWith(uSBKey.Xzqdm.Substring(0, 4)))//市级加密狗 |
|
{ |
|
|
|
} |
|
else if (uSBKey.Type != 2 || !uSBKey.Xzqdm.Equals(xzqdm)) //uSBKey.Type = 2 县级内网加密狗 |
|
{ |
|
//LogAPI.Debug($"获取到的加密狗不是{xzqdm}县内网加密狗!"); |
|
return string.Empty; |
|
} |
|
switch (keyType) |
|
{ |
|
case 1: |
|
return uSBKey.SelfPrivateKey; |
|
case 2: |
|
return uSBKey.SelfPublicKey; |
|
case 3: |
|
return uSBKey.PublicKey; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取加密狗异常:" + ex.Message); |
|
} |
|
return string.Empty; |
|
} |
|
|
|
/// <summary> |
|
/// 对称解密 |
|
/// </summary> |
|
public static string SM4Decrypt(string txtWord, string key) |
|
{ |
|
try |
|
{ |
|
SM4 sm4 = new SM4 |
|
{ |
|
secretKey = key, |
|
hexString = true |
|
}; |
|
return sm4.DecryptECB(txtWord); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("对称解密失败:" + ex.Message); |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 合并外业任务图斑到一个DB包中 |
|
/// </summary> |
|
/// <param name="listExport"></param> |
|
/// <param name="isNdbg">是否年度变更数据</param> |
|
/// <returns></returns> |
|
public static string MergeDB(List<ExportEntity> listExport, bool isNdbg) |
|
{ |
|
|
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
//导出成果 |
|
string tempPath = KGIS.Framework.Utils.SysAppPath.GetTempPath(); |
|
try |
|
{ |
|
//清空临时文件夹输出的临时成果包 |
|
if (!string.IsNullOrWhiteSpace(tempPath) && System.IO.Directory.Exists(tempPath)) |
|
{ |
|
string[] files = System.IO.Directory.GetFiles(tempPath, "*.ExportTemp"); |
|
if (files != null) |
|
{ |
|
foreach (var item in files) |
|
{ |
|
System.IO.File.Delete(item); |
|
} |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
string savePackagePath = System.IO.Path.Combine(tempPath, Guid.NewGuid() + ".ExportTemp"); |
|
//拷贝一个任务包,并清空数据,作为输出成果的模板db |
|
System.IO.File.Copy(listExport[0].PackagePath, savePackagePath, true); |
|
//rdbHelper = RDBFactory.CreateDbHelper(savePackagePath, DatabaseType.SQLite); |
|
rdbHelper = RDBFactory.CreateDbHelper($"{savePackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
DataTable hasTable = rdbHelper.ExecuteDatatable("alltables", "SELECT name FROM sqlite_master WHERE type = 'table' and name<>'sqlite_sequence' ORDER BY name desc;", true); |
|
foreach (DataRow dr in hasTable.Rows) |
|
{ |
|
if ((dr[0] as string).ToUpper().Equals("YSJ")) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException($"delete from {dr[0] as string}", CommandType.Text); |
|
} |
|
//合并任务包 |
|
var groupValue = listExport.GroupBy(x => x.PackagePath); |
|
int j = 1; |
|
//记录是否有可以导出的外业图斑 |
|
bool hasExport = false; |
|
foreach (IGrouping<string, ExportEntity> group in groupValue) |
|
{ |
|
IRDBHelper rdbHelperDB = null; |
|
try |
|
{ |
|
KGIS.Framework.Platform.Helper.ProgressHelper.SetProcessMsg($"正在合并第{j++}个外业任务图斑......"); |
|
//rdbHelperDB = RDBFactory.CreateDbHelper(group.Key, DatabaseType.SQLite); |
|
rdbHelper = RDBFactory.CreateDbHelper($"{group.Key}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
List<ExportEntity> lstExport = group.ToList<ExportEntity>(); |
|
string bsmString = string.Empty; |
|
foreach (var item in lstExport) |
|
{ |
|
bsmString += $"'{item.TBBSM}',"; |
|
} |
|
//没有可以输出的图斑 |
|
if (string.IsNullOrWhiteSpace(bsmString)) |
|
{ |
|
continue; |
|
} |
|
hasExport = true; |
|
bsmString = bsmString.TrimEnd(','); |
|
rdbHelperDB.BeginTransaction(); |
|
rdbHelperDB.ExecuteNonQueryWithException($"attach database '{savePackagePath}' AS BDB;", CommandType.Text); |
|
string sqlAppend = $"select bsm from dtbdltbgx where (isDelete ISNULL or isDelete = '' or isDelete <> '1' ) and tbbsm in({bsmString})"; |
|
//bool =true 标识通过bsm合并数据 |
|
Dictionary<string, bool> dicTables = new Dictionary<string, bool>(); |
|
dicTables.Add("WYRW", false); |
|
dicTables.Add("NYYSResult", false); |
|
dicTables.Add("WYSketch", false); |
|
dicTables.Add("DTBDLTBGX", false); |
|
dicTables.Add("DTBDLTBGXGC", false); |
|
dicTables.Add("DTBLSYDGX", true); |
|
dicTables.Add("DTBTTQGX", true); |
|
dicTables.Add("DTBGFBQGX", true); |
|
dicTables.Add("DTBLMFWGX", true); |
|
dicTables.Add("DTBCCWJQGX", true); |
|
dicTables.Add("DTBCZCDYDGX", true); |
|
dicTables.Add("FJGX", false); |
|
dicTables.Add("GJFKJG", false); |
|
dicTables.Add("PZWJ", true); |
|
dicTables.Add("ReturnComments", true); |
|
dicTables.Add("SJSHBZ", true); |
|
dicTables.Add("WYHCRW", false); |
|
dicTables.Add("WYHCFJ", false); |
|
dicTables.Add("Label", false); |
|
dicTables.Add("WYHCCG", false); |
|
foreach (var item in dicTables) |
|
{ |
|
string tableName = item.Key.ToUpper(); |
|
DataTable dataTable = rdbHelperDB.ExecuteDatatable(tableName, $"pragma table_info('{tableName}')", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
//查询目标db中的字段 |
|
DataTable dataTableTarget = rdbHelperDB.ExecuteDatatable(tableName, $"select * from BDB.{tableName} where 1=2", true); |
|
if (dataTableTarget == null) |
|
{ |
|
continue; |
|
} |
|
string fields = string.Empty; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string columnName = dataRow["name"] as string; |
|
if (dataRow["PK"].ToString() == "1" && !tableName.Equals("DTBDLTBGX") && columnName.Equals("BSM", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
continue; |
|
} |
|
//判断目标表是否也包含该字段,不包含则跳过 |
|
if (!dataTableTarget.Columns.Contains(columnName)) |
|
{ |
|
continue; |
|
} |
|
if (columnName.Equals("Check", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
fields += "'" + columnName + "',"; |
|
} |
|
else |
|
{ |
|
fields += columnName + ","; |
|
} |
|
} |
|
fields = fields.TrimEnd(','); |
|
//合并数据SQL语句的条件 |
|
string queryWhere = bsmString; |
|
//合并数据SQL语句的筛选的字段名称 |
|
string queryField = "bsm"; |
|
if (item.Value) |
|
{ |
|
queryWhere = sqlAppend; |
|
} |
|
else |
|
{ |
|
queryField = "tbbsm"; |
|
} |
|
if (tableName.Equals("GJFKJG") || tableName.Equals("SJSHBZ")) |
|
{ |
|
queryField = "tbbsm"; |
|
} |
|
else if (tableName.Equals("WYHCFJ")) |
|
{ |
|
queryField = "HCJLBSM"; |
|
} |
|
else if (tableName.Equals("WYHCCG")) |
|
{ |
|
queryField = "HCRWBSM"; |
|
} |
|
else if (tableName.Equals("FJGX")) |
|
{ |
|
queryField = "WYTBBSM"; |
|
} |
|
string sql = $"INSERT INTO BDB.{tableName}({fields}) select {fields} from {tableName} where {queryField} in({queryWhere})"; |
|
//图斑为年度变更数据时,将 WYHCFJ 表内 ARG4 字段去掉 |
|
if (isNdbg == true && tableName.Equals("WYHCFJ")) |
|
{ |
|
sql = sql.Replace("ARG4,", ""); |
|
} |
|
int count = rdbHelperDB.ExecuteNonQueryWithException(sql, CommandType.Text); |
|
} |
|
//输出的任务图斑改为“已输出” |
|
//rdbHelperDB.ExecuteNonQueryWithException($"update wyrw set zt='已输出' where tbbsm in({bsmString})", CommandType.Text); |
|
rdbHelperDB.Commit(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelperDB != null) |
|
{ |
|
rdbHelperDB.DisConnect(); |
|
} |
|
} |
|
} |
|
if (!hasExport) |
|
{ |
|
throw new Exception("没有可以输出的外业图斑!"); |
|
} |
|
//去除冗余数据 |
|
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); |
|
|
|
//已上传状态 |
|
bool ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, null); |
|
//输出的是审核任务包,所以將外业任务图斑的状态改为“未完成” |
|
if (!ZTIsUploaded) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"update wyrw set zt='未完成'", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException($"update wyrw set zt='已完成' where fwy=1", CommandType.Text); |
|
} |
|
return savePackagePath; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导出审核成果包 |
|
/// </summary> |
|
/// <param name="savePackagePath">临时审核成果包路径</param> |
|
/// <param name="savePath">生成成果包保存路径</param> |
|
public static string ExportDB1(string savePackagePath, string savePath, ref string signFileName) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
rdbHelper = RDBFactory.CreateDbHelper($"{savePackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
rdbHelper.BeginTransaction(); |
|
DTBDBLoadHelper.CheckTableExist(rdbHelper); |
|
rdbHelper.ExecuteNonQueryWithException("delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DELETE FROM WYHCFJ WHERE ARG not in(select distinct fjarg from fjgx) and MODE<>6", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DELETE FROM YSJ", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DROP TABLE IF EXISTS CheckResult", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("update dtbdltbgx set ddtcbz=null,ddtcmc=null where ddtcbz='一般地类'"); |
|
//生成对称加密秘钥 |
|
List<string> listTable = new List<string>() { "DTBDLTBGX", "DTBDLTBGXGC" }; |
|
DataTable dataTable = new DataTable(); |
|
foreach (var item in listTable) |
|
{ |
|
dataTable = rdbHelper.ExecuteDatatable(item, "select bsm,egeometry from " + item, true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
if (item == "DTBDLTBGX") |
|
{ |
|
//将县级审核结果和县级审核说明置为空 |
|
if (dataTable.Columns.Contains("XJSHJG")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("update dtbdltbgx set xjshjg=null,xjshsm=null"); |
|
} |
|
} |
|
string updateSQL = "UPDATE {2} SET EGEOMETRY='{0}' WHERE BSM='{1}'"; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string geometry = dataRow[1] as string; |
|
if (string.IsNullOrWhiteSpace(geometry)) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(updateSQL, "暂不加密", dataRow[0], item)); |
|
} |
|
} |
|
} |
|
//处理输出成果包文件的名称 |
|
string fileReName = string.Empty; |
|
dataTable = rdbHelper.ExecuteDatatable("result", "select * from wyrw", true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
fileReName = dataTable.Rows[0]["XZQDM"] + "_" + dataTable.Rows.Count + "个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jkcg"; |
|
string updateSQL = "UPDATE wyrw SET EGEOMETRY='{0}',geometry='' WHERE BSM='{1}'"; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string geometry = dataRow["EGEOMETRY"] as string; |
|
if (string.IsNullOrWhiteSpace(geometry)) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(updateSQL, "暂不加密", dataRow[0])); |
|
} |
|
} |
|
else |
|
{ |
|
fileReName = "未知_0个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jkcg"; |
|
} |
|
//如果工程坐标参考WKID为空则重新赋值 |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
projectInfo.WKID = projectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
KGIS.Framework.AE.GaussCalculate.CoordinateReferenceMapping coordinateReferenceMapping = KGIS.Framework.AE.GaussCalculate.CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (projectInfo.ZYJD > x.MinX && projectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(projectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
projectInfo.WKID = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
projectInfo.Save(); |
|
} |
|
//文件元数据信息 |
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(savePackagePath); |
|
string insertSQL = string.Format("insert into ysj (blx, bedition, encrypted, pwd, createtime, createuser, updateuser, lastupdatetime,wkid,ruleversion) values('{0}', '{1}', {2}, '{3}','{4}', '{5}', '{6}', '{7}','{8}','{9}');", "审核成果包", KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("SystemVersion"), 1, "000", DateTime.Now.ToString(), projectInfo.UserName, projectInfo.UserName, fileInfo.LastWriteTime, projectInfo.WKID, KGIS.Framework.Utils.Helper.CommonHelper.GetVersion(new Kingo.RuleCheck.XJRuleCheck.SJJCCheck_DTB().GetType())); |
|
rdbHelper.ExecuteNonQueryWithException(insertSQL, CommandType.Text); |
|
rdbHelper.Commit(); |
|
ExecuteZip(savePackagePath); |
|
string saveFilePath = System.IO.Path.Combine(savePath, fileReName); |
|
//重命名输出成果包到导出目标文件 |
|
System.IO.File.Copy(savePackagePath, saveFilePath, true); |
|
return saveFilePath; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导出审核成果包 |
|
/// </summary> |
|
/// <param name="savePackagePath">临时审核成果包路径</param> |
|
/// <param name="savePath">生成成果包保存路径</param> |
|
public static string ExportDB(string savePackagePath, string savePath, ref string signFileName) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
rdbHelper = RDBFactory.CreateDbHelper($"{savePackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
rdbHelper.BeginTransaction(); |
|
DTBDBLoadHelper.CheckTableExist(rdbHelper); |
|
rdbHelper.ExecuteNonQueryWithException("delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DELETE FROM WYHCFJ WHERE ARG not in(select distinct fjarg from fjgx) and MODE<>6", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DELETE FROM YSJ", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("DROP TABLE IF EXISTS CheckResult", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("update dtbdltbgx set ddtcbz=null,ddtcmc=null where ddtcbz='一般地类'"); |
|
//生成对称加密秘钥 |
|
string key = EncryptionHelper.GenerKeySM4(); |
|
List<string> listTable = new List<string>() { "DTBDLTBGX", "DTBDLTBGXGC" }; |
|
DataTable dataTable = new DataTable(); |
|
foreach (var item in listTable) |
|
{ |
|
dataTable = rdbHelper.ExecuteDatatable(item, "select bsm,egeometry from " + item, true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
if (item == "DTBDLTBGX") |
|
{ |
|
//将县级审核结果和县级审核说明置为空 |
|
if (dataTable.Columns.Contains("XJSHJG")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("update dtbdltbgx set xjshjg=null,xjshsm=null"); |
|
} |
|
} |
|
string updateSQL = "UPDATE {2} SET EGEOMETRY='{0}' WHERE BSM='{1}'"; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string geometry = dataRow[1] as string; |
|
if (string.IsNullOrWhiteSpace(geometry)) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(updateSQL, EncryptionHelper.SM4Encrypt(geometry, key), dataRow[0], item)); |
|
} |
|
} |
|
} |
|
//处理输出成果包文件的名称 |
|
string fileReName = string.Empty; |
|
dataTable = rdbHelper.ExecuteDatatable("result", "select * from wyrw", true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
//fileReName = dataTable.Rows[0]["XZQDM"] + "_" + dataTable.Rows[0]["tbbsm"] + "_" + dataTable.Rows[0]["JCBH"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jkcg"; |
|
fileReName = dataTable.Rows[0]["XZQDM"] + "_" + dataTable.Rows.Count + "个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jkcg"; |
|
string updateSQL = "UPDATE wyrw SET EGEOMETRY='{0}',geometry='' WHERE BSM='{1}'"; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string geometry = dataRow["EGEOMETRY"] as string; |
|
if (string.IsNullOrWhiteSpace(geometry)) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(updateSQL, EncryptionHelper.SM4Encrypt(geometry, key), dataRow[0])); |
|
} |
|
} |
|
else |
|
{ |
|
fileReName = "未知_0个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jkcg"; |
|
} |
|
//如果工程坐标参考WKID为空则重新赋值 |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
projectInfo.WKID = projectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
GaussCalculateLibrary.CoordinateReferenceMapping coordinateReferenceMapping = GaussCalculateLibrary.CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (projectInfo.ZYJD > x.MinX && projectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(projectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
projectInfo.WKID = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
projectInfo.Save(); |
|
} |
|
//文件元数据信息 |
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(savePackagePath); |
|
string insertSQL = string.Format("insert into ysj (blx, bedition, encrypted, pwd, createtime, createuser, updateuser, lastupdatetime,wkid,ruleversion) values('{0}', '{1}', {2}, '{3}','{4}', '{5}', '{6}', '{7}','{8}','{9}');", "审核成果包", KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("SystemVersion"), 1, EncryptionHelper.SM2Encrypt(key, 3, projectInfo.CODE), DateTime.Now.ToString(), projectInfo.UserName, projectInfo.UserName, fileInfo.LastWriteTime, projectInfo.WKID, KGIS.Framework.Utils.Helper.CommonHelper.GetVersion((new Kingo.RuleCheck.XJRuleCheck.SJJCCheck_DTB()).GetType())); |
|
rdbHelper.ExecuteNonQueryWithException(insertSQL, CommandType.Text); |
|
rdbHelper.Commit(); |
|
Kingo.PluginServiceInterface.CommonHelper.ExecuteZip(savePackagePath); |
|
string saveFilePath = System.IO.Path.Combine(savePath, fileReName); |
|
//重命名输出成果包到导出目标文件 |
|
System.IO.File.Copy(savePackagePath, saveFilePath, true); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.SetProcessMsg("正在生成签章......"); |
|
//基础库gdb路径:用来生成基础库数据的签章 |
|
Dictionary<string, string> dic = new Dictionary<string, string>(); |
|
dic.Add("Result", EncryptionHelper.GetFileSing(saveFilePath, projectInfo.CODE)); |
|
dic.Add("JCData", EncryptionHelper.GetFileSing(projectInfo.JCKPath, projectInfo.CODE, "GDB")); |
|
if (!string.IsNullOrEmpty(projectInfo.GJNMKPath)) |
|
dic.Add("GJNMKData", EncryptionHelper.GetFileSing(projectInfo.GJNMKPath, projectInfo.CODE, "GDB")); |
|
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(dic); |
|
signFileName = System.IO.Path.Combine(savePath, System.IO.Path.GetFileNameWithoutExtension(saveFilePath) + ".sign"); |
|
EncryptionHelper.CreateSign(jsonString, signFileName); |
|
return saveFilePath; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
|
|
/// <summary> |
|
/// 导出成果包 |
|
/// </summary> |
|
/// <param name="savePackagePath"></param> |
|
/// <param name="savePath"></param> |
|
public static string ExportDB(string savePackagePath, string savePath) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
rdbHelper = RDBFactory.CreateDbHelper($"{savePackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
DTBDBLoadHelper.CheckTableExist(rdbHelper); |
|
if (((long)rdbHelper.ExecuteScalar("select count(1) from DTBDLTBGX", CommandType.Text)) <= 0) |
|
{ |
|
throw new Exception("单图斑地类图斑更新(DTBDLTBGX)层数据为空,无法导出成果!"); |
|
} |
|
//去除冗余的数据 |
|
rdbHelper.ExecuteNonQueryWithException("delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException("delete from wyhcfj where arg not in (select distinct fjarg from fjgx) and fjlx = 'IMAGE'", 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 YSJ", CommandType.Text); |
|
//处理输出成果包文件的名称 |
|
string fileReName = string.Empty; |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("result", "select * from wyrw", true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
//fileReName = dataTable.Rows[0]["XZQDM"] + "_" + dataTable.Rows[0]["tbbsm"] + "_" + dataTable.Rows[0]["JCBH"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".shrw"; |
|
fileReName = dataTable.Rows[0]["XZQDM"] + "_" + dataTable.Rows.Count + "个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".shrw"; |
|
} |
|
else |
|
{ |
|
fileReName = "未知_0个_" + projectInfo.UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".shrw"; |
|
} |
|
//如果工程坐标参考WKID为空则重新赋值 |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
projectInfo.WKID = projectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (projectInfo.WKID <= 0) |
|
{ |
|
KGIS.Framework.AE.GaussCalculate.CoordinateReferenceMapping coordinateReferenceMapping = KGIS.Framework.AE.GaussCalculate.CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (projectInfo.ZYJD > x.MinX && projectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(projectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
projectInfo.WKID = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
projectInfo.Save(); |
|
} |
|
//创建批次time |
|
//rdbHelper.ExecuteNonQuery("ALTER TABLE YSJ ADD PCTime TEXT;"); |
|
//文件元数据信息 |
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo(savePackagePath); |
|
string insertSQL = string.Format("insert into ysj (blx, bedition, encrypted, pwd, createtime, createuser, updateuser, lastupdatetime,wkid,ruleversion) values('{0}', '{1}', {2}, '{3}','{4}', '{5}', '{6}', '{7}','{8}','{9}');", "审核任务包", KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("SystemVersion"), 0, "", DateTime.Now.ToString(), projectInfo.UserName, projectInfo.UserName, fileInfo.LastWriteTime, projectInfo.WKID, KGIS.Framework.Utils.Helper.CommonHelper.GetVersion((new Kingo.RuleCheck.XJRuleCheck.SJJCCheck_DTB()).GetType())); |
|
rdbHelper.ExecuteNonQueryWithException(insertSQL, CommandType.Text); |
|
string saveFilePath = System.IO.Path.Combine(savePath, fileReName); |
|
//重命名输出成果包到导出目标文件 |
|
System.IO.File.Copy(savePackagePath, saveFilePath, true); |
|
//压缩输出成果db文件 |
|
ExecuteZip(saveFilePath); |
|
return saveFilePath; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 合并外业任务图斑到一个DB包中 |
|
/// </summary> |
|
/// <param name="listExport"></param> |
|
/// <returns></returns> |
|
public static string MergeDB(List<ExportEntity> listExport) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
//导出成果 |
|
string tempPath = KGIS.Framework.Utils.SysAppPath.GetTempPath(); |
|
try |
|
{ |
|
//清空临时文件夹输出的临时成果包 |
|
if (!string.IsNullOrWhiteSpace(tempPath) && System.IO.Directory.Exists(tempPath)) |
|
{ |
|
string[] files = System.IO.Directory.GetFiles(tempPath, "*.ExportTemp"); |
|
if (files != null) |
|
{ |
|
foreach (var item in files) |
|
{ |
|
System.IO.File.Delete(item); |
|
} |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
string savePackagePath = System.IO.Path.Combine(tempPath, Guid.NewGuid() + ".ExportTemp"); |
|
//拷贝一个任务包,并清空数据,作为输出成果的模板db |
|
System.IO.File.Copy(listExport[0].PackagePath, savePackagePath, true); |
|
rdbHelper = RDBFactory.CreateDbHelper($"{savePackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
DataTable hasTable = rdbHelper.ExecuteDatatable("alltables", "SELECT name FROM sqlite_master WHERE type = 'table' and name<>'sqlite_sequence' ORDER BY name desc;", true); |
|
foreach (DataRow dr in hasTable.Rows) |
|
{ |
|
if ((dr[0] as string).ToUpper().Equals("YSJ")) |
|
{ |
|
continue; |
|
} |
|
rdbHelper.ExecuteNonQueryWithException($"delete from {dr[0] as string}", CommandType.Text); |
|
} |
|
//合并任务包 |
|
var groupValue = listExport.GroupBy(x => x.PackagePath); |
|
int j = 1; |
|
//记录是否有可以导出的外业图斑 |
|
bool hasExport = false; |
|
foreach (IGrouping<string, ExportEntity> group in groupValue) |
|
{ |
|
IRDBHelper rdbHelperDB = null; |
|
try |
|
{ |
|
KGIS.Framework.Platform.Helper.ProgressHelper.SetProcessMsg($"正在合并第{j++}个外业任务图斑......"); |
|
rdbHelperDB = RDBFactory.CreateDbHelper($"{group.Key}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
List<ExportEntity> lstExport = group.ToList<ExportEntity>(); |
|
string bsmString = string.Empty; |
|
foreach (var item in lstExport) |
|
{ |
|
bsmString += $"'{item.TBBSM}',"; |
|
} |
|
//没有可以输出的图斑 |
|
if (string.IsNullOrWhiteSpace(bsmString)) |
|
{ |
|
continue; |
|
} |
|
hasExport = true; |
|
bsmString = bsmString.TrimEnd(','); |
|
rdbHelperDB.BeginTransaction(); |
|
rdbHelperDB.ExecuteNonQueryWithException($"attach database '{savePackagePath}' AS BDB;", CommandType.Text); |
|
string sqlAppend = $"select bsm from dtbdltbgx where (isDelete ISNULL or isDelete = '' or isDelete<> '1' ) and tbbsm in({bsmString})"; |
|
//bool =true 标识通过bsm合并数据 |
|
Dictionary<string, bool> dicTables = new Dictionary<string, bool>(); |
|
dicTables.Add("WYRW", false); |
|
dicTables.Add("NYYSResult", false); |
|
dicTables.Add("WYSketch", false); |
|
dicTables.Add("DTBDLTBGX", false); |
|
dicTables.Add("DTBDLTBGXGC", false); |
|
dicTables.Add("SHJG", true); |
|
dicTables.Add("SHBZ", true); |
|
dicTables.Add("DTBLSYDGX", true); |
|
dicTables.Add("DTBTTQGX", true); |
|
dicTables.Add("DTBGFBQGX", true); |
|
dicTables.Add("DTBLMFWGX", true); |
|
dicTables.Add("DTBCCWJQGX", true); |
|
dicTables.Add("DTBCZCDYDGX", true); |
|
dicTables.Add("FJGX", false); |
|
dicTables.Add("GJFKJG", false); |
|
dicTables.Add("PZWJ", true); |
|
dicTables.Add("ReturnComments", true); |
|
dicTables.Add("SJSHBZ", true); |
|
dicTables.Add("WYHCRW", false); |
|
dicTables.Add("WYHCFJ", false); |
|
dicTables.Add("Label", false); |
|
dicTables.Add("WYHCCG", false); |
|
foreach (var item in dicTables) |
|
{ |
|
string tableName = item.Key.ToUpper(); |
|
DataTable dataTable = rdbHelperDB.ExecuteDatatable(tableName, $"pragma table_info('{tableName}')", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
//查询目标db中的字段 |
|
DataTable dataTableTarget = rdbHelperDB.ExecuteDatatable(tableName, $"select * from BDB.{tableName} where 1=2", true); |
|
if (dataTableTarget == null) |
|
{ |
|
continue; |
|
} |
|
string fields = string.Empty; |
|
foreach (DataRow dataRow in dataTable.Rows) |
|
{ |
|
string columnName = dataRow["name"] as string; |
|
if (dataRow["PK"].ToString() == "1" && !tableName.Equals("DTBDLTBGX") && columnName.Equals("BSM", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
continue; |
|
} |
|
//判断目标表是否也包含该字段,不包含则跳过 |
|
if (!dataTableTarget.Columns.Contains(columnName)) |
|
{ |
|
continue; |
|
} |
|
if (columnName.Equals("Check", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
fields += "'" + columnName + "',"; |
|
} |
|
else |
|
{ |
|
fields += columnName + ","; |
|
} |
|
} |
|
fields = fields.TrimEnd(','); |
|
//合并数据SQL语句的条件 |
|
string queryWhere = bsmString; |
|
//合并数据SQL语句的筛选的字段名称 |
|
string queryField = "bsm"; |
|
if (item.Value) |
|
{ |
|
queryWhere = sqlAppend; |
|
} |
|
else |
|
{ |
|
queryField = "tbbsm"; |
|
} |
|
if (tableName.Equals("GJFKJG") || tableName.Equals("SJSHBZ")) |
|
{ |
|
queryField = "tbbsm"; |
|
} |
|
else if (tableName.Equals("WYHCFJ")) |
|
{ |
|
queryField = "HCJLBSM"; |
|
} |
|
else if (tableName.Equals("WYHCCG")) |
|
{ |
|
queryField = "HCRWBSM"; |
|
} |
|
else if (tableName.Equals("FJGX")) |
|
{ |
|
queryField = "WYTBBSM"; |
|
} |
|
else if (tableName.Equals("SHJG")) |
|
{ |
|
queryField = "TBBSM"; |
|
} |
|
string sql = $"INSERT INTO BDB.{tableName}({fields}) select {fields} from {tableName} where {queryField} in({queryWhere})"; |
|
int count = rdbHelperDB.ExecuteNonQueryWithException(sql, CommandType.Text); |
|
} |
|
//输出的任务图斑改为“已输出” |
|
//rdbHelperDB.ExecuteNonQueryWithException($"update wyrw set zt='已输出' where tbbsm in({bsmString})", CommandType.Text); |
|
rdbHelperDB.Commit(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelperDB != null) |
|
{ |
|
rdbHelperDB.DisConnect(); |
|
} |
|
} |
|
} |
|
if (!hasExport) |
|
{ |
|
throw new Exception("没有可以输出的外业图斑!"); |
|
} |
|
//去除冗余数据 |
|
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); |
|
|
|
|
|
bool ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, null); |
|
|
|
//输出的是审核任务包,所以將外业任务图斑的状态改为“未完成” |
|
if (!ZTIsUploaded) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"update wyrw set zt='未完成'", CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException($"update wyrw set zt='已完成' where fwy=1", CommandType.Text); |
|
} |
|
return savePackagePath; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 设置工程数据库要素集和要素类坐标参考 |
|
/// </summary> |
|
/// <param name="workspaceAPI"></param> |
|
private void SetISpatialReference(IWorkspaceAPI workspaceAPI) |
|
{ |
|
ISpatialReference reference = ProjectInfo.GetCurentProjectedCoordinate(); |
|
double Tolerance = 0.0001; |
|
//设置坐标参考精度XYUnits 为二万分之一 |
|
try |
|
{ |
|
GeoDBAPI.SetGeoDatasetSpatialReference(workspaceAPI.CurrentWorkspace, reference, Tolerance); |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", Tolerance)); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("新建工程 页面 中 设置坐标参考坐标精度和容差异常 时失败,异常原因: " + ex + " ; "); |
|
throw new Exception("设置坐标参考坐标精度和容差异常:" + ex.Message); |
|
} |
|
} |
|
|
|
private void ImportDB(IWorkspaceAPI workspaceAPI, IWorkspaceAPI workspaceSchemeAPI, IRDBHelper rdbHelper) |
|
{ |
|
try |
|
{ |
|
DataTable hasTable = rdbHelper.ExecuteDatatable("alltables", "SELECT name FROM sqlite_master WHERE type = 'table' and name<>'sqlite_sequence' ORDER BY name desc;", true); |
|
foreach (DataRow dr in hasTable.Rows) |
|
{ |
|
ITableAPI tableAPI = null; |
|
string tableName = dr[0] as string; |
|
try |
|
{ |
|
if (tableName.Equals("DTBDLTBGX", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
try |
|
{ |
|
tableAPI = workspaceSchemeAPI.OpenTable("DLTBBG"); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
workspaceSchemeAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM {0} where bid='{1}'", "DLTBBG", this.bh)); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, |
|
@" select a.*,d.NAME AS PZWJMC_LSYD,d.FileContent as PZWJ_LSYD, b.PZWH as PZWH_LSYD, b.YTFL as YTFL_LSYD, b.PZRQ as PZRQ_LSYD,b.PZMJ as PZMJ_LSYD, b.TDSYHT as TDSYHT_LSYD,b.JTXMYT as JTXMYT_LSYD, b.YQSX as YQSX_LSYD, c.XMMC as XMMC_GFBQ, c.XMGM as XMGM_GFBQ, c.PZYDSJ as PZYDSJ_GFBQ,x.images as images from dtbdltbgx as a |
|
left join DTBLSYDGX as b on b.bsm=a.bsm |
|
left join DTBGFBQGX as c on c.bsm=a.bsm |
|
left join pzwj as d on d.bsm=a.bsm |
|
left join (SELECT tbbsm, group_concat(distinct FJARG) as images FROM FJGX group by tbbsm) as x on x.tbbsm=a.bsm where a.IsDelete <> '1' or a.IsDelete ISNULL or a.IsDelete = '' or a.IsDelete = ' ' ", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
} |
|
else if (tableName.Equals("SJSHBZ", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
Dictionary<string, string> dciBZTable = new Dictionary<string, string>(); |
|
dciBZTable.Add("('1','点')", "SJSHPoint"); |
|
dciBZTable.Add("('2','线')", "SJSHLine"); |
|
dciBZTable.Add("('3','面')", "SJSHPolygon"); |
|
foreach (var item in dciBZTable) |
|
{ |
|
try |
|
{ |
|
tableAPI = workspaceAPI.OpenTable(item.Value); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM {0} where bid='{1}'", item.Value, this.bh)); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, $"select * from {tableName} where bzlx in{item.Key}", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
} |
|
} |
|
else if (tableName.Equals("WYSketch", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
Dictionary<string, string> dciBZTable = new Dictionary<string, string>(); |
|
dciBZTable.Add("点", "MarkPoint"); |
|
dciBZTable.Add("线", "MarkLine"); |
|
dciBZTable.Add("面", "MarkPolygon"); |
|
foreach (var item in dciBZTable) |
|
{ |
|
try |
|
{ |
|
tableAPI = workspaceAPI.OpenTable(item.Value); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM {0} where bid='{1}'", item.Value, this.bh)); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, "select * from " + tableName + " where bzlx='" + item.Key + "'", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
} |
|
} |
|
else if (tableName.Equals("LABEL", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
Dictionary<int, string> dciBZTable = new Dictionary<int, string>(); |
|
dciBZTable.Add(0, "WYCTPoint"); |
|
dciBZTable.Add(1, "WYCTLine"); |
|
dciBZTable.Add(2, "WYCTPolygon"); |
|
foreach (var item in dciBZTable) |
|
{ |
|
try |
|
{ |
|
tableAPI = workspaceAPI.OpenTable(item.Value); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM {0} where bid='{1}'", item.Value, this.bh)); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, "select * from " + tableName + " where TYPE=" + item.Key, true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
} |
|
} |
|
else if (tableName.Equals("WYRW", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
//此方法很慢 |
|
//if (!workspaceAPI.ExistFeatureClass(tableName)) |
|
//{ |
|
// continue; |
|
//} |
|
try |
|
{ |
|
tableAPI = workspaceAPI.OpenTable(tableName); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("DELETE FROM {0} where bid='{1}'", tableName, this.bh)); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, "select * from " + tableName, true); |
|
if (dataTable == null || dataTable.Rows.Count < 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
|
|
} |
|
else |
|
{ |
|
try |
|
{ |
|
tableAPI = workspaceAPI.OpenTable(tableName); |
|
} |
|
catch |
|
{ |
|
continue; |
|
} |
|
DataTable dataTable = rdbHelper.ExecuteDatatable(tableName, "select * from " + tableName, true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
DataTableImportToGDB(tableName, dataTable, tableAPI); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception(tableName + "数据矢量化失败:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (tableAPI != null) |
|
{ |
|
tableAPI.CloseTable(); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("DTBDBLoadHelper.ImportDB 异常:" + ex.Message); |
|
LogAPI.Debug("DTBDBLoadHelper.ImportDB 异常:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
} |
|
|
|
private void DataTableImportNew(string tableName, DataTable dataTable, ITableAPI tableAPI) |
|
{ |
|
ICursor cursor = null; |
|
try |
|
{ |
|
cursor = tableAPI.ITable.Insert(true); |
|
IRowBuffer rowBuffer = tableAPI.ITable.CreateRowBuffer(); |
|
|
|
int indexShape = tableAPI.ITable.FindField("Shape"); |
|
int indexBSM = tableAPI.ITable.FindField("BSM"); |
|
int indexTBBSM = tableAPI.ITable.FindField("TBBSM"); |
|
int indexEGeometry = tableAPI.ITable.FindField("EGeometry"); |
|
int indexGeometry = tableAPI.ITable.FindField("Geometry"); |
|
IFeatureClass featureClass = tableAPI.ITable as IFeatureClass; |
|
List<string> listSql = new List<string>(); |
|
foreach (DataRow dr in dataTable.Rows) |
|
{ |
|
if (indexBSM > -1) |
|
{ |
|
rowBuffer.set_Value(indexBSM, this.bh.ToString()); |
|
} |
|
if (indexTBBSM > -1) |
|
{ |
|
rowBuffer.set_Value(indexTBBSM, dr["TBBSM"]); |
|
} |
|
string geometryStr = String.Empty; |
|
if (dataTable.Columns.Contains("egeometry")) |
|
{ |
|
geometryStr = dr["egeometry"] as string; |
|
} |
|
else if (dataTable.Columns.Contains("geometry")) |
|
{ |
|
geometryStr = dr["geometry"] as string; |
|
} |
|
else if (dataTable.Columns.Contains("shape")) |
|
{ |
|
geometryStr = dr["shape"] as string; |
|
} |
|
else |
|
{ |
|
throw new Exception("未找到EGeometry、Geometry或Shape图形字段"); |
|
} |
|
if (indexEGeometry > -1) |
|
{ |
|
rowBuffer.set_Value(indexEGeometry, geometryStr); |
|
} |
|
if (indexGeometry > -1) |
|
{ |
|
rowBuffer.set_Value(indexGeometry, geometryStr); |
|
} |
|
IGeometry geometry = null; |
|
switch (featureClass.ShapeType) |
|
{ |
|
case esriGeometryType.esriGeometryPoint: |
|
geometry = ConverJsonToIGeoemtry(geometryStr, esriGeometryType.esriGeometryPoint); |
|
break; |
|
case esriGeometryType.esriGeometryPolyline: |
|
geometry = ConverJsonToIGeoemtry(geometryStr, esriGeometryType.esriGeometryPolyline); |
|
break; |
|
case esriGeometryType.esriGeometryPolygon: |
|
geometry = ConverJsonToIGeoemtry(geometryStr); |
|
break; |
|
} |
|
if (geometry != null) |
|
{ |
|
geometry.Project((tableAPI.ITable as IGeoDataset).SpatialReference); |
|
rowBuffer.set_Value(indexShape, geometry); |
|
} |
|
cursor.InsertRow(rowBuffer); |
|
string featureName = (featureClass as FeatureClass).BrowseName.ToUpper(); |
|
switch (featureName) |
|
{ |
|
case "DLTBBG": |
|
listSql.Add($"update DTBDLTBGX set TBBSM='{dr["TBBSM"]}', YSDM='{dr["YSDM"]}', TBYBH='{dr["TBYBH"]}', TBBH='{dr["TBBH"]}', DLBM='{dr["DLBM"]}', DLMC='{dr["DLMC"]}', QSXZ='{dr["QSXZ"]}', QSDWDM='{dr["QSDWDM"]}', QSDWMC='{dr["QSDWMC"]}', ZLDWDM='{dr["ZLDWDM"]}', ZLDWMC='{dr["ZLDWMC"]}', TBMJ={dr["TBMJ"]}, KCDLBM='{dr["KCDLBM"]}', KCXS={dr["KCXS"]}, KCMJ={dr["KCMJ"]}, TBDLMJ={dr["TBDLMJ"]}, GDLX='{dr["GDLX"]}', GDPDJB='{dr["GDPDJB"]}', XZDWKD={dr["XZDWKD"]}, TBXHDM='{dr["TBXHDM"]}', TBXHMC='{dr["TBXHMC"]}', ZZSXDM='{dr["ZZSXDM"]}', ZZSXMC='{dr["ZZSXMC"]}', GDDB={dr["GDDB"]}, FRDBS='{dr["FRDBS"]}', CZCSXM='{dr["CZCSXM"]}', SJNF='{dr["SJNF"]}', MSSM='{dr["MSSM"]}', HDMC='{dr["HDMC"]}', BZ='{dr["BZ"]}', GXSJ='{dr["GXSJ"]}', TBLX='{dr["TBLX"]}', DDTCBZ='{dr["DDTCBZ"]}', DDTCMC='{dr["DDTCMC"]}', SFGX='{dr["SFGX"]}', WBGYY='{dr["WBGYY"]}', SFJZ='{dr["SFJZ"]}', QKSM='{dr["QKSM"]}', LJLX='{dr["LJLX"]}', DCJL='{dr["DCJL"]}', YWTBSM='{dr["YWTBSM"]}', ZXDX={dr["ZXDX"]}, ZXDY={dr["ZXDY"]}, MAXX={dr["MAXX"]}, MAXY={dr["MAXY"]}, MINX={dr["MINX"]}, MINY={dr["MINY"]}, JKRY='{dr["JKRY"]}',BID='{this.bh.ToString()}' where BSM='{dr["BSM"]}'"); |
|
break; |
|
case "MARKPOINT": |
|
case "MARKLINE": |
|
case "MARKPOLYGON": |
|
case "SHBZPOINT": |
|
case "SHBZLINE": |
|
case "SHBZPOLYGON": |
|
listSql.Add($"update {featureName} set TBBSM='{dr["TBBSM"]}',BZLX='{dr["BZLX"]}',BZMS='{dr["BZMS"]}',BID='{this.bh.ToString()}' WHERE BSM='{dr["BSM"]}'"); |
|
break; |
|
case "ZZTB": |
|
case "WYRW": |
|
listSql.Add($"update {featureName} set BSM='{dr["BSM"]}', XZQDM='{dr["XZQDM"]}', XZDM='{dr["XZDM"]}', CJDM='{dr["CJDM"]}', JCBH='{dr["JCBH"]}', TBLX='{dr["TBLX"]}', SJLY='{dr["SJLY"]}', JCMJ={dr["JCMJ"]}, TBMJ={dr["TBMJ"]}, ZXDX={dr["ZXDX"]}, ZXDY={dr["ZXDY"]}, MAXX={dr["MAXX"]}, MAXY={dr["MAXY"]}, MINX={dr["MINX"]}, MINY={dr["MINY"]},BID='{this.bh.ToString()}' where TBBSM='{dr["TBBSM"]}'"); |
|
break; |
|
} |
|
} |
|
cursor.Flush(); |
|
foreach (var item in listSql) |
|
{ |
|
(featureClass as FeatureClass).Workspace.ExecuteSQL(item); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (cursor != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// DataTable数据插入到GDB |
|
/// </summary> |
|
/// <param name="dataTable"></param> |
|
/// <param name="featureClassAPI"></param> |
|
private void DataTableImportToGDB(string tableName, DataTable dataTable, ITableAPI tableAPI) |
|
{ |
|
ICursor cursor = null; |
|
try |
|
{ |
|
IFeatureClass tempFeatureClass = tableAPI.ITable as IFeatureClass; |
|
IFeatureClassLoad pFclsLoad = null; |
|
if (tempFeatureClass != null) |
|
{ |
|
pFclsLoad = tempFeatureClass as IFeatureClassLoad; |
|
if (pFclsLoad != null) |
|
pFclsLoad.LoadOnlyMode = true; |
|
} |
|
cursor = tableAPI.ITable.Insert(true); |
|
IRowBuffer rowBuffer = tableAPI.ITable.CreateRowBuffer(); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.SetProcessMsg("正在导入" + tableName + "数据......"); |
|
//string message = "正在导入" + tableName + "数据[{0}/" + dataTable.Rows.Count + "]......"; |
|
int indexShape = tableAPI.ITable.FindField("Shape"); |
|
int indexBH = tableAPI.ITable.FindField("BID"); |
|
foreach (DataRow dr in dataTable.Rows) |
|
{ |
|
//更新包号字段 |
|
if (indexBH > -1) |
|
{ |
|
rowBuffer.set_Value(indexBH, this.bh.ToString()); |
|
} |
|
foreach (DataColumn dc in dataTable.Columns) |
|
{ |
|
int index = tableAPI.ITable.FindField(dc.ColumnName); |
|
if (index > -1) |
|
{ |
|
if (dr[dc.ColumnName] is System.DBNull) |
|
{ |
|
rowBuffer.set_Value(index, DBNull.Value); |
|
}//外业草图shape字段存储的是图形json坐标串,不能直接赋值给矢量图层的shape字段,应该给Geometry字段 |
|
else if (dc.ColumnName.Equals("shape", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
int indexGeometry = tableAPI.ITable.FindField("Geometry"); |
|
if (indexGeometry > -1) |
|
{ |
|
rowBuffer.set_Value(indexGeometry, dr[dc.ColumnName]); |
|
} |
|
} |
|
else |
|
{ |
|
if (tableAPI.ITable.Fields.Field[index].Type == esriFieldType.esriFieldTypeBlob) |
|
{ |
|
IMemoryBlobStream pMBS = new MemoryBlobStreamClass(); |
|
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)pMBS; |
|
object objValue = dr[dc.ColumnName]; |
|
varBlobStream.ImportFromVariant(objValue); |
|
rowBuffer.set_Value(index, varBlobStream); |
|
} |
|
else |
|
{ |
|
rowBuffer.set_Value(index, dr[dc.ColumnName]); |
|
} |
|
} |
|
} |
|
//处理图形 |
|
if ((dc.ColumnName.EndsWith("geometry", StringComparison.CurrentCultureIgnoreCase) || |
|
dc.ColumnName.EndsWith("shape", StringComparison.CurrentCultureIgnoreCase)) |
|
&& indexShape > -1 && !string.IsNullOrWhiteSpace(dr[dc.ColumnName] as string)) |
|
{ |
|
string geometryStr = dr[dc.ColumnName] as string; |
|
if (string.IsNullOrWhiteSpace(geometryStr)) |
|
{ |
|
continue; |
|
} |
|
IGeometry geometry = null; |
|
IFeatureClass featureClass = tableAPI.ITable as IFeatureClass; |
|
if (featureClass != null) |
|
{ |
|
switch (featureClass.ShapeType) |
|
{ |
|
case esriGeometryType.esriGeometryPoint: |
|
geometry = ConverJsonToIGeoemtry(geometryStr, esriGeometryType.esriGeometryPoint); |
|
break; |
|
case esriGeometryType.esriGeometryPolyline: |
|
geometry = ConverJsonToIGeoemtry(geometryStr, esriGeometryType.esriGeometryPolyline); |
|
break; |
|
case esriGeometryType.esriGeometryPolygon: |
|
geometry = ConverJsonToIGeoemtry(geometryStr); |
|
break; |
|
} |
|
} |
|
if (geometry != null) |
|
{ |
|
geometry.Project((tableAPI.ITable as IGeoDataset).SpatialReference); |
|
rowBuffer.set_Value(indexShape, geometry); |
|
} |
|
} |
|
} |
|
object oid = cursor.InsertRow(rowBuffer); |
|
if (DicTBInfo == null) |
|
{ |
|
DicTBInfo = new Dictionary<WYRWTB, List<DTBDLTBGX>>(); |
|
} |
|
if (tableName.Equals("DTBDLTBGX", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
DTBDLTBGX dltbgx = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<DTBDLTBGX>(dr); |
|
WYRWTB wyrwtb = DicTBInfo.Keys.FirstOrDefault(x => x.TBBSM == dltbgx.TBBSM); |
|
if (wyrwtb != null) |
|
{ |
|
if (DicTBInfo[wyrwtb] == null) |
|
{ |
|
DicTBInfo[wyrwtb] = new List<DTBDLTBGX>(); |
|
} |
|
dltbgx.ObjectID = (int)oid; |
|
DicTBInfo[wyrwtb].Add(dltbgx); |
|
} |
|
} |
|
else if (tableName.Equals("WYRW", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
WYRWTB wyrwtb = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<WYRWTB>(dr); |
|
wyrwtb.ObjectID = (int)oid; |
|
DicTBInfo.Add(wyrwtb, null); |
|
} |
|
} |
|
cursor.Flush(); |
|
if (pFclsLoad != null) |
|
pFclsLoad.LoadOnlyMode = false; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("DataTable数据插入到GDB异常:" + ex.Message); |
|
LogAPI.Debug("DataTable数据插入到GDB异常:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (cursor != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 验证包表结构是否都存在 |
|
/// </summary> |
|
public static void CheckTableExist(IRDBHelper rdbHelper) |
|
{ |
|
try |
|
{ |
|
string excuteSQL = @"CREATE TABLE if not exists FJGX ( |
|
BSM INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
|
WYTBBSM TEXT NOT NULL, |
|
FJARG TEXT NOT NULL, |
|
TBBSM TEXT NOT NULL); |
|
CREATE TABLE if not exists DTBDLTBGXGC ( |
|
BSM INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
|
TBBSM TEXT, |
|
BGXW TEXT, |
|
XZQTZLX INTEGER, |
|
TBBGMJ NUMERIC, |
|
BGQBSM TEXT, |
|
BGQTBBH TEXT, |
|
BGQDLBM TEXT, |
|
BGQDLMC TEXT, |
|
BGQQSXZ TEXT, |
|
BGQQSDWDM TEXT, |
|
BGQQSDWMC TEXT, |
|
BGQZLDWDM TEXT, |
|
BGQZLDWMC TEXT, |
|
BGQKCDLBM TEXT, |
|
BGQKCXS NUMERIC, |
|
BGQKCMJ NUMERIC, |
|
BGQTBDLMJ NUMERIC, |
|
BGQGDLX TEXT, |
|
BGQGDPDJB TEXT, |
|
BGQXZDWKD NUMERIC, |
|
BGQTBXHDM TEXT, |
|
BGQTBXHMC TEXT, |
|
BGQZZSXDM TEXT, |
|
BGQZZSXMC TEXT, |
|
BGQGDDB TEXT, |
|
BGQFRDBS TEXT, |
|
BGQCZCSXM TEXT, |
|
BGQMSSM TEXT, |
|
BGQHDMC TEXT, |
|
BGHTBBSM TEXT, |
|
BGHTBBH TEXT, |
|
BGHDLBM TEXT, |
|
BGHDLMC TEXT, |
|
BGHQSXZ TEXT, |
|
BGHQSDWDM TEXT, |
|
BGHQSDWMC TEXT, |
|
BGHZLDWDM TEXT, |
|
BGHZLDWMC TEXT, |
|
BGHKCDLBM TEXT, |
|
BGHKCXS NUMERIC, |
|
BGHKCMJ NUMERIC, |
|
BGHTBDLMJ NUMERIC, |
|
BGHGDLX TEXT, |
|
BGHGDPDJB NUMERIC, |
|
BGHXZDWKD NUMERIC, |
|
BGHTBXHDM TEXT, |
|
BGHTBXHMC TEXT, |
|
BGHZZSXDM TEXT, |
|
BGHZZSXMC TEXT, |
|
BGHGDDB INTEGER, |
|
BGHFRDBS TEXT, |
|
BGHCZCSXM TEXT, |
|
BGHMSSM INTEGER, |
|
BGHHDMC INTEGER, |
|
EGeometry TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists DTBDLTBGX ( |
|
BSM TEXT NOT NULL PRIMARY KEY, |
|
TBBSM TEXT, |
|
YSDM TEXT, |
|
TBYBH TEXT, |
|
TBBH TEXT, |
|
DLBM TEXT, |
|
DLMC TEXT, |
|
QSXZ TEXT, |
|
QSDWDM TEXT, |
|
QSDWMC TEXT, |
|
ZLDWDM TEXT, |
|
ZLDWMC TEXT, |
|
TBMJ NUMERIC, |
|
KCDLBM TEXT, |
|
KCXS NUMERIC, |
|
KCMJ NUMERIC, |
|
TBDLMJ NUMERIC, |
|
GDLX TEXT, |
|
GDPDJB TEXT, |
|
XZDWKD NUMERIC, |
|
TBXHDM TEXT, |
|
TBXHMC TEXT, |
|
ZZSXDM TEXT, |
|
ZZSXMC TEXT, |
|
GDDB INTEGER, |
|
FRDBS TEXT, |
|
CZCSXM TEXT, |
|
SJNF INTEGER, |
|
MSSM TEXT, |
|
HDMC TEXT, |
|
BZ TEXT, |
|
GXSJ TEXT, |
|
TBLX TEXT, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
SFGX TEXT, |
|
WBGYY TEXT, |
|
SFJZ TEXT, |
|
QKSM TEXT, |
|
NBWQKSM TEXT, |
|
SHLZQKSM TEXT, |
|
LJLX TEXT, |
|
DCJL TEXT, |
|
YWTBSM TEXT, |
|
EGeometry TEXT, |
|
ZXDX NUMERIC, |
|
ZXDY NUMERIC, |
|
MAXX NUMERIC, |
|
MAXY NUMERIC, |
|
MINX NUMERIC, |
|
MINY NUMERIC, |
|
JKRY TEXT, |
|
LNGDZB TEXT, |
|
SFXML TEXT, |
|
XMLX TEXT, |
|
XMMC TEXT, |
|
XMBH TEXT, |
|
CZCTBBH TEXT, |
|
LC TEXT, |
|
NF TEXT |
|
); |
|
CREATE TABLE if not exists DTBCCWJQGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
ZDMJ NUMERIC, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists DTBGFBQGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
XMMC TEXT, |
|
XMGM TEXT, |
|
QYMJ NUMERIC, |
|
PZYDSJ TEXT, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists DTBLSYDGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
GLTBBSM TEXT, |
|
PZWJMC TEXT, |
|
PZWH TEXT, |
|
TBMJ NUMERIC, |
|
PZMJ NUMERIC, |
|
YTFL TEXT, |
|
JTXMYT TEXT, |
|
PZRQ TEXT, |
|
YQSX TEXT, |
|
TDSYHT TEXT, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists PZWJ ( |
|
BSM TEXT NOT NULL, |
|
Name TEXT, |
|
Path TEXT, |
|
Extension TEXT, |
|
FileContent BLOB |
|
); |
|
CREATE TABLE if not exists DTBTTQGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
TTQMJ NUMERIC, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists DTBCZCDYDGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
CZCLX TEXT, |
|
CZCDM TEXT, |
|
CZCMC TEXT, |
|
CZCMJ NUMERIC, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists DTBLMFWGX ( |
|
BSM TEXT NOT NULL, |
|
DDTCBZ TEXT, |
|
DDTCMC TEXT, |
|
YSDM TEXT, |
|
ZLDWDM TEXT, |
|
KD NUMERIC, |
|
MJ NUMERIC, |
|
DLBM TEXT, |
|
MC TEXT, |
|
BZ TEXT, |
|
GXSJ TEXT |
|
); |
|
CREATE TABLE if not exists CheckResult( |
|
XH INTEGER NOT NULL, |
|
RuleCode TEXT, |
|
CheckObject TEXT, |
|
TBBSM TEXT, |
|
ErrorType TEXT, |
|
ErrorId TEXT, |
|
ErrorTip TEXT, |
|
RuleName TEXT, |
|
RuleContent TEXT, |
|
GeometryType INTEGER, |
|
Geometry TEXT |
|
); |
|
CREATE TABLE if not exists WYRWTB_VOICE ( |
|
BSM INTEGER PRIMARY KEY NOT NULL, |
|
TBBSM TEXT NOT NULL, |
|
YWLX TEXT NOT NULL, |
|
VOICE BLOB |
|
)"; |
|
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text); |
|
//WYHRFJ外业核查附件表增加用户是否标记删除字段 |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("wyhcfj", "select * from WYHCFJ where 1=2", true); |
|
if (dataTable != null && !dataTable.Columns.Contains("UserDelete")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE WYHCFJ ADD 'UserDelete' INTEGER;"); |
|
//增加字段后,默认都为0:非删除状态,1是删除状态,删除状态的不展示该附件 |
|
rdbHelper.ExecuteNonQueryWithException("UPDATE WYHCFJ SET UserDelete=0;"); |
|
} |
|
//单独图层添加列 |
|
#region 单独图层添加列 |
|
List<string> fields = new List<string>() { "DDTCBZ", "DDTCMC" }; |
|
List<string> tables = new List<string>() { "DTBCCWJQGX", "DTBGFBQGX", "DTBLSYDGX", "DTBTTQGX", "DTBCZCDYDGX", "DTBLMFWGX" }; |
|
foreach (string table in tables) |
|
{ |
|
dataTable = rdbHelper.ExecuteDatatable(table, $"select * from '{table}' where 1=2", true); |
|
foreach (string field in fields) |
|
{ |
|
if (dataTable != null && !dataTable.Columns.Contains(field)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE '{table}' ADD '{field}' TEXT;"); |
|
} |
|
} |
|
} |
|
#endregion |
|
|
|
#region 省级审核标注 SJSHBZ |
|
List<string> SJSHBZfields = new List<string>() { "TBZT", "UserID", "BzRole" }; |
|
dataTable = rdbHelper.ExecuteDatatable("SJSHBZ", $"select * from SJSHBZ where 1=2", true); |
|
foreach (string field in SJSHBZfields) |
|
{ |
|
if (dataTable != null && !dataTable.Columns.Contains(field)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE SJSHBZ ADD '{field}' TEXT;"); |
|
} |
|
} |
|
#endregion |
|
|
|
#region 省级反馈结果 ReturnComments |
|
List<string> ReturnCommentsfields = new List<string>() { "JLDLHCJG", "JLDLHCSM", "JLSXHCJG", "JLSXHCSM", "JLTXHCJG", "JLTXHCSM", "JLSHSM", "JLBZ", "JLSHRY", "JLSHSJ" }; |
|
dataTable = rdbHelper.ExecuteDatatable("ReturnComments", $"select * from ReturnComments where 1=2", true); |
|
foreach (string field in ReturnCommentsfields) |
|
{ |
|
if (dataTable != null && !dataTable.Columns.Contains(field)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE ReturnComments ADD '{field}' TEXT;"); |
|
} |
|
} |
|
#endregion |
|
|
|
//DTBDLTBGX表增加LNGDZB历年耕地占比字段 |
|
dataTable = rdbHelper.ExecuteDatatable("dtbdltbgx", "select * from dtbdltbgx where 1=2", true); |
|
List<string> lstStringField = null; |
|
List<string> lstIntField = null; |
|
if (dataTable != null) |
|
{ |
|
lstStringField = new List<string>() { "LNGDZB", "SDMSSM", "YDYHFL", "ZGQKSM", "SFXML", "XMLX", "XMMC", "XMBH", "DKMC", "CZCTBBH", "LC", "NF", "JYM", "LJBZ", "JZYBH", "LJTBBH", "IsDelete", "ZZZW", "SZLX", "LYZZZW", "LXJZGLBH" }; |
|
foreach (var item in lstStringField) |
|
{ |
|
if (!dataTable.Columns.Contains(item)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE dtbdltbgx ADD '{item}' TEXT;"); |
|
} |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException("UPDATE dtbdltbgx SET SFXML='0' where SFXML is null or SFXML =''"); |
|
dataTable = rdbHelper.ExecuteDatatable("fjgx", "select * from fjgx where 1=2", true); |
|
if (dataTable != null && !dataTable.Columns.Contains("WYTBBSM")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE fjgx ADD 'WYTBBSM' TEXT;"); |
|
} |
|
//国家反馈意见添加照片合理性字段 |
|
dataTable = rdbHelper.ExecuteDatatable("GJFKJG", "select * from GJFKJG where 1=2", true); |
|
if (dataTable != null && !dataTable.Columns.Contains("ZPHLX")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE GJFKJG ADD 'ZPHLX' TEXT;"); |
|
} |
|
//WYRW表增加外业备注和状态字段 |
|
dataTable = rdbHelper.ExecuteDatatable("WYRW", "select * from WYRW where 1=2", true); |
|
if (dataTable != null) |
|
{ |
|
lstStringField = new List<string>() { "ZT", "WYBZ" };//"CheckR" |
|
foreach (var item in lstStringField) |
|
{ |
|
if (!dataTable.Columns.Contains(item)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE WYRW ADD '{item}' TEXT;"); |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException("UPDATE WYRW SET ZT='未完成' where zt is null or zt =''"); |
|
//rdbHelper.ExecuteNonQueryWithException("UPDATE WYRW SET CheckR=0 where CheckR is null or CheckR =''"); |
|
lstIntField = new List<string>() { "FWY", "XBTB", "SFSB", "GJDLBM" }; |
|
foreach (var item in lstIntField) |
|
{ |
|
if (item == "SFSB") |
|
{ |
|
if (!dataTable.Columns.Contains(item)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE WYRW ADD '{item}' NUMERIC;"); |
|
} |
|
//continue; |
|
} |
|
else |
|
{ |
|
if (!dataTable.Columns.Contains(item)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE WYRW ADD '{item}' TEXT;"); |
|
} |
|
} |
|
|
|
} |
|
} |
|
dataTable = rdbHelper.ExecuteDatatable("CheckResult", "select * from CheckResult where 1=2", true); |
|
if (dataTable != null) |
|
{ |
|
lstStringField = new List<string>() { "TBBSM", "Geometry" }; |
|
foreach (var item in lstStringField) |
|
{ |
|
if (!dataTable.Columns.Contains(item)) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"ALTER TABLE CheckResult ADD '{item}' TEXT;"); |
|
} |
|
} |
|
if (!dataTable.Columns.Contains("GeometryType")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE CheckResult ADD 'GeometryType' INTEGER;"); |
|
} |
|
} |
|
//DTBDLTBGXGC表增加图形字段EGeometry |
|
dataTable = rdbHelper.ExecuteDatatable("DTBDLTBGXGC", "select * from DTBDLTBGXGC where 1=2", true); |
|
if (dataTable != null) |
|
{ |
|
if (!dataTable.Columns.Contains("EGeometry")) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE DTBDLTBGXGC ADD 'EGeometry' TEXT;"); |
|
} |
|
DataTable dt = rdbHelper.ExecuteDatatable("DTBDLTBGXGC", "pragma table_info ('DTBDLTBGXGC')", true); |
|
int pk = Convert.ToInt32(dt.Rows[0]["pk"].ToString()); //判断bsm字段pk列是否为1,name即为列名 |
|
if (pk != 1) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("ALTER TABLE DTBDLTBGXGC RENAME TO DTBDLTBGXGC_Copy"); |
|
string sql = @"CREATE TABLE DTBDLTBGXGC( |
|
BSM INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
|
TBBSM TEXT, |
|
BGXW TEXT, |
|
XZQTZLX INTEGER, |
|
TBBGMJ NUMERIC, |
|
BGQBSM TEXT, |
|
BGQTBBH TEXT, |
|
BGQDLBM TEXT, |
|
BGQDLMC TEXT, |
|
BGQQSXZ TEXT, |
|
BGQQSDWDM TEXT, |
|
BGQQSDWMC TEXT, |
|
BGQZLDWDM TEXT, |
|
BGQZLDWMC TEXT, |
|
BGQKCDLBM TEXT, |
|
BGQKCXS NUMERIC, |
|
BGQKCMJ NUMERIC, |
|
BGQTBDLMJ NUMERIC, |
|
BGQGDLX TEXT, |
|
BGQGDPDJB TEXT, |
|
BGQXZDWKD NUMERIC, |
|
BGQTBXHDM TEXT, |
|
BGQTBXHMC TEXT, |
|
BGQZZSXDM TEXT, |
|
BGQZZSXMC TEXT, |
|
BGQGDDB TEXT, |
|
BGQFRDBS TEXT, |
|
BGQCZCSXM TEXT, |
|
BGQMSSM TEXT, |
|
BGQHDMC TEXT, |
|
BGHTBBSM TEXT, |
|
BGHTBBH TEXT, |
|
BGHDLBM TEXT, |
|
BGHDLMC TEXT, |
|
BGHQSXZ TEXT, |
|
BGHQSDWDM TEXT, |
|
BGHQSDWMC TEXT, |
|
BGHZLDWDM TEXT, |
|
BGHZLDWMC TEXT, |
|
BGHKCDLBM TEXT, |
|
BGHKCXS NUMERIC, |
|
BGHKCMJ NUMERIC, |
|
BGHTBDLMJ NUMERIC, |
|
BGHGDLX TEXT, |
|
BGHGDPDJB NUMERIC, |
|
BGHXZDWKD NUMERIC, |
|
BGHTBXHDM TEXT, |
|
BGHTBXHMC TEXT, |
|
BGHZZSXDM TEXT, |
|
BGHZZSXMC TEXT, |
|
BGHGDDB INTEGER, |
|
BGHFRDBS TEXT, |
|
BGHCZCSXM TEXT, |
|
BGHMSSM INTEGER, |
|
BGHHDMC INTEGER, |
|
EGeometry TEXT, |
|
GXSJ TEXT |
|
)"; |
|
rdbHelper.ExecuteNonQueryWithException(sql, CommandType.Text); |
|
string coloum = "BSM,TBBSM,BGXW, XZQTZLX, TBBGMJ, BGQBSM, BGQTBBH, BGQDLBM, BGQDLMC, BGQQSXZ, BGQQSDWDM, BGQQSDWMC, BGQZLDWDM, BGQZLDWMC, BGQKCDLBM, BGQKCXS, BGQKCMJ, BGQTBDLMJ, BGQGDLX, BGQGDPDJB, BGQXZDWKD, BGQTBXHDM, BGQTBXHMC, BGQZZSXDM, BGQZZSXMC, BGQGDDB, BGQFRDBS, BGQCZCSXM, BGQMSSM, BGQHDMC,EGeometry,BGHTBBSM, BGHTBBH, BGHDLBM, BGHDLMC, BGHQSXZ, BGHQSDWDM, BGHQSDWMC, BGHZLDWDM, BGHZLDWMC, BGHKCDLBM, BGHKCXS, BGHKCMJ, BGHTBDLMJ, BGHGDLX, BGHGDPDJB, BGHXZDWKD, BGHTBXHDM, BGHTBXHMC, BGHZZSXDM, BGHZZSXMC, BGHGDDB, BGHFRDBS, BGHCZCSXM, BGHMSSM, BGHHDMC,GXSJ"; |
|
rdbHelper.ExecuteNonQueryWithException(string.Format("INSERT INTO DTBDLTBGXGC({0}) SELECT {0} FROM DTBDLTBGXGC_Copy", coloum)); |
|
rdbHelper.ExecuteNonQueryWithException("DROP TABLE DTBDLTBGXGC_Copy"); |
|
} |
|
} |
|
//} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("新建初始化任务表、外业指导草图表异常:" + ex); |
|
} |
|
} |
|
|
|
public static void SaveGXGCData(string tbbsm, string wyrwtbbsm, IFeature newFeature, IRDBHelper rdbHelper, ESRI.ArcGIS.Controls.IHookHelper hookHelper, bool isNeedStone = true) |
|
{ |
|
try |
|
{ |
|
//保存更新过程数据 |
|
ILayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑"); |
|
//KGIS.Framework.AE.LayerHelper.GetLayerByName<ESRI.ArcGIS.Carto.ILayer>(hookHelper.FocusMap, "基础_地类图斑", false); |
|
ILayer layerPodu = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_省级下发坡度图"); |
|
ILayer layerCz = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_城镇村等用地"); |
|
ILayer layerNmk = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑_年末库"); |
|
rdbHelper.ExecuteNonQueryWithException(string.Format("delete from DTBDLTBGXGC where BGHTBBSM='{0}'", tbbsm), CommandType.Text); |
|
rdbHelper.ExecuteNonQueryWithException(string.Format("update wyrw set sfsb=0 where tbbsm='{0}'", wyrwtbbsm), CommandType.Text); |
|
if (layer == null) |
|
{ |
|
LogAPI.Debug("未找到:基础_地类图斑(JC_DLTB)图层,更新过程(DTBDLTBGXGC)数据为空!"); |
|
MessageHelper.ShowTips("未找到:基础_地类图斑(JC_DLTB)图层!"); |
|
return; |
|
} |
|
string excuteSQL = "insert into DTBDLTBGXGC(TBBSM,BGXW, XZQTZLX, TBBGMJ, BGQBSM, BGQTBBH, BGQDLBM, BGQDLMC, BGQQSXZ, BGQQSDWDM, BGQQSDWMC, BGQZLDWDM, BGQZLDWMC, BGQKCDLBM, BGQKCXS, BGQKCMJ, BGQTBDLMJ, BGQGDLX, BGQGDPDJB, BGQXZDWKD, BGQTBXHDM, BGQTBXHMC, BGQZZSXDM, BGQZZSXMC, BGQGDDB, BGQFRDBS, BGQCZCSXM, BGQMSSM, BGQHDMC,EGeometry,BGHTBBSM, BGHTBBH, BGHDLBM, BGHDLMC, BGHQSXZ, BGHQSDWDM, BGHQSDWMC, BGHZLDWDM, BGHZLDWMC, BGHKCDLBM, BGHKCXS, BGHKCMJ, BGHTBDLMJ, BGHGDLX, BGHGDPDJB, BGHXZDWKD, BGHTBXHDM, BGHTBXHMC, BGHZZSXDM, BGHZZSXMC, BGHGDDB, BGHFRDBS, BGHCZCSXM, BGHMSSM, BGHHDMC,GXSJ) values({0},{1})"; |
|
List<string> listField = new List<string>() { "BSM", "TBBH", "DLBM", "DLMC", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "KCDLBM", "KCXS", "KCMJ", "TBDLMJ", "GDLX", "GDPDJB", "XZDWKD", "TBXHDM", "TBXHMC", "ZZSXDM", "ZZSXMC", "GDDB", "FRDBS", "CZCSXM", "MSSM", "HDMC", "SHAPE" }; |
|
//变更后字段 |
|
|
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
//变更后值 |
|
Dictionary<string, object> bghFieldValues = GetHFieldValues(newFeature, layerPodu, listField, projectInfo.CODE, layer, rdbHelper, isNeedStone); |
|
if (bghFieldValues == null || bghFieldValues["DLBM"] == null) return; |
|
string dlbm = bghFieldValues["DLBM"].ToString(); |
|
Dictionary<IGeometry, IFeature> listFeatures = IdentifyReturnIntersect(newFeature.ShapeCopy, layer); |
|
foreach (var item in listFeatures) |
|
{ |
|
IArea area1 = item.Key as IArea; |
|
double tbbgmj = Math.Round(area1.Area, 2);//(item.Key as IPolygon).GetEllipseArea(); |
|
//double tbbgsj = (item.Key as IPolygon).GetEllipseArea();//某些情况下,得到得值为-1 |
|
if (tbbgmj < 0.01)//图斑变更面积小于0.01不做操作 |
|
{ |
|
continue; |
|
} |
|
IFeature feature = item.Value; |
|
int bgqDLBMIndex = feature.Fields.FindField("DLBM"); |
|
string bgqDLBM = feature.get_Value(bgqDLBMIndex).ToString(); |
|
|
|
if (dlbm.Equals("8801")) |
|
{ |
|
int bgqDLMCIndex = feature.Fields.FindField("DLMC"); |
|
string bgqDLMC = feature.get_Value(bgqDLMCIndex).ToString(); |
|
bghFieldValues["DLBM"] = bgqDLBM; |
|
bghFieldValues["DLMC"] = bgqDLMC; |
|
if (bgqDLBM == "0101" || bgqDLBM == "0102" || bgqDLBM == "0103") |
|
{ |
|
bghFieldValues["ZZSXDM"] = "WG"; |
|
bghFieldValues["ZZSXMC"] = "未耕种"; |
|
} |
|
else |
|
{ |
|
int bgqZZSXDMIndex = feature.Fields.FindField("ZZSXDM"); |
|
string bgqZZSXDM = feature.get_Value(bgqZZSXDMIndex).ToString(); |
|
int bgqZZSXMCIndex = feature.Fields.FindField("ZZSXMC"); |
|
string bgqZZSXMC = feature.get_Value(bgqZZSXMCIndex).ToString(); |
|
bghFieldValues["ZZSXDM"] = bgqZZSXDM.Trim(); |
|
bghFieldValues["ZZSXMC"] = bgqZZSXMC; |
|
} |
|
int bgqTBXHDMIndex = feature.Fields.FindField("TBXHDM"); |
|
string bgqTBXHDM = feature.get_Value(bgqTBXHDMIndex).ToString(); |
|
int bgqTBXHMCIndex = feature.Fields.FindField("TBXHMC"); |
|
string bgqTBXHMC = feature.get_Value(bgqTBXHMCIndex).ToString(); |
|
bghFieldValues["TBXHDM"] = bgqTBXHDM.Trim(); |
|
bghFieldValues["TBXHMC"] = bgqTBXHMC; |
|
int bgqGDLXIndex = feature.Fields.FindField("GDLX"); |
|
string bgqGDLX = feature.get_Value(bgqGDLXIndex).ToString(); |
|
bghFieldValues["GDLX"] = bgqGDLX; |
|
} |
|
else |
|
{ |
|
//地类名称 |
|
DataDicTionary dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.DLBM).FirstOrDefault(x => x.CODE.Equals(dlbm)); |
|
if (dataDicTionary != null) |
|
{ |
|
bghFieldValues["DLMC"] = dataDicTionary.NAME; |
|
} |
|
} |
|
|
|
//图斑变更面积:TBBGMJ=SHAPE_Area*K(零米线图斑图斑系数默认K=1,基础库DLTB图层变更面积系数K=TBMJ/SHAPE_Area) |
|
int tbmjIndex = feature.Fields.FindField("TBMJ"); |
|
int shpateIndex = feature.Fields.FindField("SHAPE_Area"); |
|
double qtbmj = Convert.ToDouble(feature.get_Value(tbmjIndex)); |
|
double qshapearea = Convert.ToDouble(feature.get_Value(shpateIndex)); |
|
double mjK = qtbmj / qshapearea; |
|
tbbgmj = (item.Key as IArea).Area * mjK; |
|
|
|
//与国家下发城镇村叠加 |
|
Dictionary<IGeometry, IFeature> bgqFeature = IdentifyReturnIntersect(item.Key, layerCz); |
|
if (bgqFeature.Count > 0) |
|
{ |
|
//变更范围需要与国家下发城镇村进行擦除处理 |
|
IGeometry newGeo = item.Key; |
|
foreach (var czc in bgqFeature) |
|
{ |
|
newGeo = Erase(newGeo, czc.Key); |
|
double mj = (czc.Key as IArea).Area; |
|
tbbgmj = mj * mjK; |
|
string czcsxm = GetCZCSXM(czc.Value, bgqDLBM); |
|
if (dlbm == "8801") |
|
bghFieldValues["CZCSXM"] = czcsxm; |
|
string bgqValuesStr = GetQFieldValues(czc.Key, feature, tbbgmj, layerCz, listField, newFeature, wyrwtbbsm, czcsxm); |
|
string bghValuesStr = GetHValues(bghFieldValues, item.Value, layerPodu, tbbgmj, projectInfo.CODE); |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, bgqValuesStr, bghValuesStr + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"), CommandType.Text); |
|
} |
|
//判断擦除后是否还存在,如果存在,则需要插入到更新过程表中; |
|
if (newGeo != null && (newGeo as IArea).Area > 0.001) |
|
{ |
|
string czcsxm = ""; |
|
tbbgmj = (newGeo as IArea).Area * mjK; |
|
string bgqValuesStr = GetQFieldValues(newGeo, feature, tbbgmj, layerCz, listField, newFeature, wyrwtbbsm, czcsxm); |
|
string bghValuesStr = GetHValues(bghFieldValues, item.Value, layerPodu, tbbgmj, projectInfo.CODE); |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, bgqValuesStr, bghValuesStr + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"), CommandType.Text); |
|
} |
|
|
|
} |
|
else |
|
{ |
|
string bgqValuesStr = GetQFieldValues(item.Key, feature, tbbgmj, layerCz, listField, newFeature, wyrwtbbsm, ""); |
|
string bghValuesStr = GetHValues(bghFieldValues, item.Value, layerPodu, tbbgmj, projectInfo.CODE); |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, bgqValuesStr, bghValuesStr + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"), CommandType.Text); |
|
} |
|
//湖南需求:补充更新过程层数据缺失 |
|
rdbHelper.ExecuteNonQueryWithException("update DTBDLTBGXGC set BGHQSDWDM=BGQQSDWDM,BGHQSDWMC=BGQQSDWMC,BGHZLDWDM=BGQZLDWDM,BGHZLDWMC=BGQZLDWMC WHERE BGHQSDWDM is NULL OR BGHQSDWDM='' OR BGHQSDWMC is NULL OR BGHQSDWMC='' OR BGHZLDWDM is NULL OR BGHZLDWDM='' OR BGHZLDWMC is NULL OR BGHZLDWMC=''"); |
|
|
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("生成更新过程数据异常:" + ex.Message); |
|
LogAPI.Debug("生成更新过程数据异常:" + ex.StackTrace); |
|
MessageHelper.ShowTips("生成更新过程数据异常:" + ex.Message); |
|
throw new Exception("生成更新过程数据异常:" + ex.Message); |
|
} |
|
} |
|
|
|
private static Dictionary<string, object> GetHFieldValues(IFeature newFeature, ILayer layerPodu, List<string> listFields, string xzqdm, ILayer layerDLTB, IRDBHelper rdbHelper, bool isNeedStone = true) |
|
{ |
|
bool isReadOnly = false; |
|
Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
|
try |
|
{ |
|
List<IFeature> JCfeatures = FeatureAPI.Identify2(newFeature.ShapeCopy, layerDLTB); |
|
double TempBL = 0.0; |
|
IFeature featureTempJC = null; |
|
if (JCfeatures != null && JCfeatures.Count > 1) |
|
{ |
|
int tbmjIndex = newFeature.Fields.FindField("TBMJ"); |
|
if (newFeature.get_Value(tbmjIndex) == null || string.IsNullOrEmpty(newFeature.get_Value(tbmjIndex).ToString())) |
|
{ |
|
MessageHelper.ShowTips("图斑面积是空,请输入后重试!"); |
|
return null; |
|
} |
|
double qtbmj = Convert.ToDouble(newFeature.get_Value(tbmjIndex).ToString()); |
|
foreach (var feature in JCfeatures) |
|
{ |
|
int shpateIndex = feature.Fields.FindField("SHAPE_Area"); |
|
double qshapearea = Convert.ToDouble(feature.get_Value(shpateIndex)); |
|
double mjK = qtbmj / qshapearea; |
|
if (mjK >= TempBL) |
|
featureTempJC = feature; |
|
TempBL = mjK; |
|
} |
|
} |
|
else if (JCfeatures != null && JCfeatures.Count == 1) |
|
featureTempJC = JCfeatures[0]; |
|
try |
|
{ |
|
string dlbmValue = string.Empty; |
|
int iDLBM = newFeature.Fields.FindField("DLBM"); |
|
if (iDLBM > -1) |
|
dlbmValue = newFeature.Value[iDLBM].ToString(); |
|
#region 更新部分数据属性继承基础库 |
|
LayerFieldCfg Cfg = null; |
|
if (newFeature != null && featureTempJC != null) |
|
{ |
|
string cfgFilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "LayerFieldsCfg.xml"); |
|
if (!string.IsNullOrEmpty(cfgFilePath) && Cfg == null) |
|
Cfg = SerializeAPI.DeserializeToObject2<LayerFieldCfg>(cfgFilePath); |
|
|
|
|
|
string cfgname = $"{"单图斑地类图斑更新"}_{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE.Substring(0, 2)}"; |
|
LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname); |
|
//LayerInfo layer = Cfg.Layers[0]; |
|
foreach (FieldCfg Fielditem in layer.Fields) |
|
{ |
|
//字段配置文件-只读且可见的字段 继承基础库数据--当前为新疆需求逻辑 |
|
isReadOnly = false; |
|
if (Fielditem.NotEdit != null && dlbmValue != null) |
|
{ |
|
var norEdit = Fielditem.NotEdit.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
|
if (norEdit.Contains(dlbmValue) || Fielditem.IsReadOnly == true) |
|
{ |
|
isReadOnly = true; |
|
} |
|
} |
|
else if (Fielditem.CanEdit != null && dlbmValue != null) |
|
{ |
|
var canEdit = Fielditem.CanEdit.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
|
if (canEdit.Contains(dlbmValue)) |
|
{ |
|
isReadOnly = false; |
|
} |
|
else if (Fielditem.IsReadOnly == true) |
|
{ |
|
isReadOnly = true; |
|
} |
|
} |
|
else if (Fielditem.IsReadOnly == true) |
|
{ |
|
isReadOnly = true; |
|
} |
|
|
|
if ((((Fielditem.Name == "QSXZ" || Fielditem.Name == "GDPDJB" || Fielditem.Name == "GDDB") && Fielditem.Display == true) || Fielditem.Name == "XZDWKD") && featureTempJC.Fields.FindField(Fielditem.Name) != -1 && newFeature.Fields.FindField(Fielditem.Name) != -1) |
|
{ |
|
string valueField = ""; |
|
if (Fielditem.Name == "XZDWKD" && Fielditem.CanEdit != null && dlbmValue != null) |
|
{ |
|
var canEdit = Fielditem.CanEdit.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
|
if (!canEdit.Contains(dlbmValue)) valueField = "0"; |
|
else if (string.IsNullOrEmpty(newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)].ToString())) |
|
valueField = featureTempJC.Value[featureTempJC.Fields.FindField(Fielditem.Name)].ToString(); |
|
else |
|
valueField = newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)].ToString(); |
|
|
|
valueField = string.IsNullOrEmpty(valueField) ? null : valueField; |
|
newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)] = valueField; |
|
string GXBSM = newFeature.Value[newFeature.Fields.FindField("BSM")].ToString(); |
|
rdbHelper.ExecuteNonQueryWithException($"update DTBDLTBGX set {Fielditem.Name}='{valueField}' where bsm='{GXBSM}'", CommandType.Text); |
|
} |
|
else if (string.IsNullOrEmpty(newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)].ToString())) |
|
{ |
|
valueField = featureTempJC.Value[featureTempJC.Fields.FindField(Fielditem.Name)].ToString(); |
|
valueField = string.IsNullOrEmpty(valueField) ? null : valueField; |
|
newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)] = valueField; |
|
string GXBSM = newFeature.Value[newFeature.Fields.FindField("BSM")].ToString(); |
|
rdbHelper.ExecuteNonQueryWithException($"update DTBDLTBGX set {Fielditem.Name}='{valueField}' where bsm='{GXBSM}'", CommandType.Text); |
|
} |
|
else |
|
{ |
|
valueField = newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)].ToString(); |
|
newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)] = valueField; |
|
string GXBSM = newFeature.Value[newFeature.Fields.FindField("BSM")].ToString(); |
|
rdbHelper.ExecuteNonQueryWithException($"update DTBDLTBGX set {Fielditem.Name}='{valueField}' where bsm='{GXBSM}'", CommandType.Text); |
|
|
|
} |
|
} |
|
else if (isReadOnly == true && featureTempJC.Fields.FindField(Fielditem.Name) != -1 && newFeature.Fields.FindField(Fielditem.Name) != -1) |
|
{ |
|
string valueField = ""; |
|
string GXBSM = newFeature.Value[newFeature.Fields.FindField("BSM")].ToString(); |
|
if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("14") && (Fielditem.Name == "ZLDWDM" || Fielditem.Name == "ZLDWMC")) |
|
{ |
|
//修改 坐落单位名称,坐落单位代码 继承基础库数据不对的问题。(图形分割后,分属两个不同的村) |
|
valueField = GetAttributeValue(newFeature, Fielditem.Name, layerDLTB); |
|
} |
|
else |
|
{ |
|
if (Fielditem.SetNullValue != null && Fielditem.SetNullValue.Contains(dlbmValue)) |
|
valueField = string.Empty; |
|
else |
|
valueField = featureTempJC.Value[featureTempJC.Fields.FindField(Fielditem.Name)].ToString(); |
|
} |
|
newFeature.Value[newFeature.Fields.FindField(Fielditem.Name)] = valueField; |
|
rdbHelper.ExecuteNonQueryWithException($"update DTBDLTBGX set {Fielditem.Name}='{valueField}' where bsm='{GXBSM}'", CommandType.Text); |
|
} |
|
} |
|
if (isNeedStone) |
|
newFeature.Store(); |
|
} |
|
#endregion |
|
} |
|
catch (Exception) |
|
{ |
|
LogAPI.Debug("获取继承基础库字段值异常!"); |
|
} |
|
foreach (string item in listFields) |
|
{ |
|
int index = newFeature.Fields.FindField(item); |
|
if (index > -1) |
|
{ |
|
IField field = newFeature.Fields.Field[index]; |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
case esriFieldType.esriFieldTypeInteger: |
|
case esriFieldType.esriFieldTypeSingle: |
|
case esriFieldType.esriFieldTypeDouble: |
|
case esriFieldType.esriFieldTypeOID: |
|
case esriFieldType.esriFieldTypeBlob: |
|
object obj = newFeature.get_Value(index); |
|
if (obj == null || obj == DBNull.Value) |
|
{ |
|
keyValues.Add(item, 0); |
|
} |
|
else |
|
{ |
|
keyValues.Add(item, obj); |
|
} |
|
break; |
|
case esriFieldType.esriFieldTypeGeometry: |
|
break; |
|
default: |
|
keyValues.Add(item, newFeature.get_Value(index)); |
|
break; |
|
} |
|
//湖南需求:单图斑地类图斑更新层缺失数据由基础地类图斑补充 |
|
if (featureTempJC != null && featureTempJC.Fields.FindField(item) != -1 && keyValues.ContainsKey(item) && string.IsNullOrWhiteSpace(keyValues[item].ToString())) |
|
{ |
|
//新疆需求:选择地类编码为1202不继承种植属性 |
|
if (item == "ZZSXDM" || item == "ZZSXMC") |
|
{ |
|
int tempDlbm = newFeature.Fields.FindField("DLBM"); |
|
if (tempDlbm > -1) |
|
{ |
|
object obj = newFeature.get_Value(tempDlbm); |
|
if (obj != null && obj.ToString() == "1202") { } |
|
else |
|
{ |
|
int indexS = featureTempJC.Fields.FindField(item); |
|
keyValues[item] = featureTempJC.get_Value(indexS); |
|
} |
|
} |
|
|
|
} |
|
else |
|
{ |
|
int indexS = featureTempJC.Fields.FindField(item); |
|
keyValues[item] = featureTempJC.get_Value(indexS); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
keyValues.Add(item, ""); |
|
} |
|
} |
|
string dlbm = keyValues["DLBM"].ToString(); |
|
if (dlbm.StartsWith("01"))//当地类为01类时 |
|
{ |
|
#region 单图斑扣除系数 |
|
string poduMax = ""; |
|
try |
|
{ |
|
Dictionary<ESRI.ArcGIS.Geometry.IGeometry, IFeature> data = IdentifyReturnIntersect(newFeature.ShapeCopy, layerPodu); |
|
if (data != null && data.Count > 0) |
|
{ |
|
int poduindex = data.Values.FirstOrDefault().Fields.FindField("PDJB"); |
|
Dictionary<string, double> pdMj = new Dictionary<string, double>(); |
|
foreach (var item in data) |
|
{ |
|
string pdjb = item.Value.get_Value(poduindex).ToString(); |
|
if (pdMj.ContainsKey(pdjb)) |
|
{ |
|
pdMj[pdjb] = pdMj[pdjb] + (item.Key as ESRI.ArcGIS.Geometry.IArea).Area; |
|
} |
|
else |
|
{ |
|
pdMj.Add(pdjb, (item.Key as ESRI.ArcGIS.Geometry.IArea).Area); |
|
} |
|
} |
|
poduMax = pdMj.OrderByDescending(x => x.Value).FirstOrDefault().Key; |
|
if (poduMax == "1") |
|
{ |
|
keyValues["GDLX"] = ""; |
|
} |
|
keyValues["GDPDJB"] = poduMax;//坡度级别 |
|
} |
|
else |
|
{ |
|
keyValues["GDLX"] = ""; |
|
} |
|
|
|
int gdlxindex = newFeature.Fields.FindField("GDLX"); |
|
keyValues["KCDLBM"] = "1203"; |
|
keyValues["KCXS"] = GetTKXS(poduMax, newFeature.get_Value(gdlxindex)?.ToString()); |
|
//if (newFeature.get_Value(gdlxindex)?.ToString() == "TT") |
|
//{ |
|
// DCParams.Init(); |
|
// keyValues["KCDLBM"] = "1203"; |
|
// double? kcNumber = DCParams.XZBMDIC.Where(x => x.GradeLevel.Contains(poduMax) && x.Code == xzqdm).FirstOrDefault()?.DeductNumber; |
|
|
|
// if (kcNumber == null) |
|
// { |
|
// kcNumber = 0; |
|
// } |
|
// keyValues["KCXS"] = kcNumber; |
|
//} |
|
} |
|
catch |
|
{ } |
|
#endregion |
|
} |
|
else |
|
{ |
|
keyValues["KCXS"] = 0; |
|
keyValues["KCMJ"] = 0; |
|
} |
|
return keyValues; |
|
} |
|
catch (Exception exce) |
|
{ |
|
LogAPI.Debug("DTBDBLoadHelper.GetHFieldValues 异常:" + exce.Message); |
|
LogAPI.Debug("DTBDBLoadHelper.GetHFieldValues 异常:" + exce.StackTrace); |
|
return keyValues; |
|
} |
|
} |
|
|
|
private static string GetQFieldValues(IGeometry geometry, IFeature feature, double tbbgmj, ILayer layerCZ, List<string> listFeilds, IFeature newFeature, string wyrwtbbsm, string czcsxm) |
|
{ |
|
try |
|
{ |
|
int kcxsIndex = feature.Fields.FindField("KCXS"); |
|
string bsm = string.Empty; |
|
|
|
string bgQValue = $"'{wyrwtbbsm}','2','',{tbbgmj}"; |
|
foreach (string item in listFeilds) |
|
{ |
|
int index = feature.Fields.FindField(item); |
|
if (index > -1) |
|
{ |
|
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 (item == "KCMJ") |
|
{ |
|
//前扣除面积:BGQKCMJ=TBBGMJ*BGQKCXS |
|
object kcxsObj = feature.get_Value(kcxsIndex); |
|
if (kcxsObj is System.DBNull) |
|
{ |
|
bgQValue += ",0"; |
|
} |
|
else |
|
{ |
|
bgQValue += "," + (tbbgmj * Convert.ToDouble(kcxsObj)); |
|
} |
|
} |
|
else if (item == "TBDLMJ") |
|
{ |
|
double kcmj = 0; |
|
object kcxsObj = feature.get_Value(kcxsIndex); |
|
if (kcxsObj is System.DBNull) |
|
{ |
|
kcmj = 0; |
|
} |
|
else |
|
{ |
|
kcmj = tbbgmj * Convert.ToDouble(kcxsObj); |
|
} |
|
bgQValue += "," + (tbbgmj - kcmj); |
|
} |
|
else |
|
{ |
|
object value = feature.get_Value(index); |
|
if (value is System.DBNull) |
|
{ |
|
bgQValue += "," + 0; |
|
} |
|
else |
|
{ |
|
bgQValue += "," + value; |
|
} |
|
} |
|
break; |
|
case esriFieldType.esriFieldTypeGeometry: |
|
object objs = feature.get_Value(index); |
|
if (objs == null || objs == DBNull.Value) |
|
{ |
|
bgQValue += ",''"; |
|
} |
|
else |
|
{ |
|
string egeometry = ConverIGometryToJson(geometry); |
|
bgQValue += ",'" + egeometry + "'"; |
|
} |
|
break; |
|
default: |
|
if (item == "CZCSXM") |
|
{ |
|
string czclx = czcsxm; |
|
string dlbm = string.Empty; |
|
int dlbmIndex = feature.Fields.FindField("DLBM"); |
|
if (dlbmIndex > -1) |
|
{ |
|
dlbm = feature.get_Value(dlbmIndex).ToString(); |
|
} |
|
string dl4 = dlbm.Length >= 4 ? dlbm.Substring(0, 4) : dlbm; |
|
if ((czclx == "204" || czclx == "205") && !DLParams.jsyd_dlbms.Contains(dlbm)) |
|
{ |
|
bgQValue += ",''"; |
|
} |
|
else if (dl4 == "1001" || dl4 == "1002" || dl4 == "1003" || dl4 == "1007" || dl4 == "1008" || dl4 == "1009" || dl4 == "1109") |
|
{ |
|
bgQValue += ",''"; |
|
} |
|
else |
|
{ |
|
bgQValue += ",'" + czclx + "'"; |
|
} |
|
} |
|
else if (item == "BSM") |
|
{ |
|
bsm = feature.get_Value(index).ToString(); |
|
bgQValue += ",'" + bsm + "'"; |
|
} |
|
else |
|
{ |
|
bgQValue += ",'" + feature.get_Value(index).ToString().Trim() + "'"; |
|
} |
|
break; |
|
} |
|
} |
|
else |
|
{ |
|
bgQValue += ",''"; |
|
} |
|
} |
|
return bgQValue; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("DTBDBLoadHelper.GetQFieldValues 异常!" + ex.Message); |
|
LogAPI.Debug("DTBDBLoadHelper.GetQFieldValues 异常!" + ex.StackTrace); |
|
return null; |
|
} |
|
} |
|
|
|
private static string GetHValues(Dictionary<string, object> keyValues, IFeature newFeature, ILayer layerPodu, double tbbgmj, string xzqdm) |
|
{ |
|
string fieldValuesStr = ""; |
|
try |
|
{ |
|
string dlbm = keyValues["DLBM"].ToString(); |
|
double kcxs = 0; |
|
double.TryParse(keyValues["KCXS"]?.ToString(), out kcxs); |
|
keyValues["KCMJ"] = tbbgmj * kcxs; |
|
keyValues["TBDLMJ"] = tbbgmj - tbbgmj * kcxs; |
|
string czcsxm = keyValues["CZCSXM"]?.ToString(); |
|
if ((czcsxm == "204" || czcsxm == "205") && !DLParams.jsyd_dlbms.Contains(dlbm)) |
|
{ |
|
//当BGHCZCSXM为204与205的,BGHDLBM为非建设用地的图斑,将对应的BGHCZCSXM清空; |
|
keyValues["CZCSXM"] = ""; |
|
} |
|
if (dlbm == "1001" || dlbm == "1002" || dlbm == "1003" || dlbm == "1007" || dlbm == "1008" || dlbm == "1009" || dlbm == "1109" || dlbm == "1001A" || dlbm == "1002A" || dlbm == "1003A") |
|
{ |
|
keyValues["CZCSXM"] = ""; |
|
} |
|
foreach (var item in keyValues) |
|
{ |
|
if (item.Value.GetType() == typeof(Double) || item.Value.GetType() == typeof(Int32)) |
|
{ |
|
fieldValuesStr += item.Value + ","; |
|
} |
|
else |
|
{ |
|
fieldValuesStr += "'" + item.Value + "',"; |
|
} |
|
} |
|
return fieldValuesStr; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("DTBDBLoadHelper.GetQFieldValues 异常!" + ex.Message); |
|
LogAPI.Debug("DTBDBLoadHelper.GetQFieldValues 异常!" + ex.StackTrace); |
|
return fieldValuesStr; |
|
} |
|
} |
|
|
|
private static string GetCZCSXM(IFeature featureCZC, string dlbm) |
|
{ |
|
string czclx = string.Empty; |
|
|
|
int rowindex = featureCZC.Fields.FindField("CZCLX"); |
|
if (rowindex > -1) |
|
{ |
|
czclx = featureCZC.get_Value(rowindex).ToString(); //城镇村等用地类型 |
|
} |
|
string dl4 = dlbm.Length >= 4 ? dlbm.Substring(0, 4) : dlbm; |
|
if ((czclx == "204" || czclx == "205") && !DLParams.jsyd_dlbms.Contains(dlbm)) |
|
{ |
|
return ""; |
|
} |
|
else if (dl4 == "1001" || dl4 == "1002" || dl4 == "1003" || dl4 == "1007" || dl4 == "1008" || dl4 == "1009" || dl4 == "1109") |
|
{ |
|
return ""; |
|
} |
|
else |
|
{ |
|
return czclx; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 识别要素 |
|
/// </summary> |
|
/// <param name="pGeo">指定图形</param> |
|
/// <param name="pLayer">目标图层</param> |
|
/// <returns>返回目标图层中与指定图形有交集的要素集合(不包含相邻要素)</returns> |
|
public static Dictionary<IGeometry, IFeature> IdentifyReturnIntersect(IGeometry pGeo, ILayer pLayer) |
|
{ |
|
Dictionary<IGeometry, IFeature> result = new Dictionary<IGeometry, IFeature>(); |
|
try |
|
{ |
|
if (pGeo != null && !pGeo.IsEmpty && pLayer != null) |
|
{ |
|
IIdentify identify = pLayer as IIdentify; |
|
if (identify == null) |
|
return result; |
|
IArray array = identify.Identify(pGeo); |
|
if (array == null) |
|
return result; |
|
for (int i = 0; i < array.Count; i++) |
|
{ |
|
IRowIdentifyObject row = (IRowIdentifyObject)array.get_Element(i); |
|
if (row == null) |
|
{ |
|
continue; |
|
} |
|
IFeature f = row.Row as IFeature; |
|
IGeometry geometry = f.ShapeCopy; |
|
if (!geometry.SpatialReference.Name.Equals(pGeo.SpatialReference.Name)) |
|
{ |
|
geometry.Project(pGeo.SpatialReference); |
|
} |
|
IGeometry geo = FeatureAPI.InterSect(geometry, pGeo); |
|
if (geo != null && !geo.IsEmpty) |
|
{ |
|
result.Add(geo, f); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 执行压缩SQLite数据库 |
|
/// </summary> |
|
/// <returns>压缩数据库db路径</returns> |
|
public static void ExecuteZip(string dbPath) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
rdbHelper.ExecuteNonQueryWithException("VACUUM", CommandType.Text); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("输出成果压缩db异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
public static List<Kingo.RuleCheck.BasicDataInfo> GetBasicData() |
|
{ |
|
List<Kingo.RuleCheck.BasicDataInfo> lstBasicData = null; |
|
IFeatureLayer featureLayer = null; |
|
Kingo.RuleCheck.BasicDataInfo basicDataInfo = null; |
|
FeatureClass featureClass = null; |
|
try |
|
{ |
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
lstBasicData = new List<Kingo.RuleCheck.BasicDataInfo>(); |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.JCKPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_地类图斑”层!"); |
|
//throw new Exception("未找到“基础_地类图斑”层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("JC_DLTB", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_行政区"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_行政区”层!"); |
|
//throw new Exception("未找到“基础_行政区”层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("JC_XZQ", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.HFJSYDPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_合法建设用地范围"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
//throw new Exception("未找到“基础_合法建设用地范围”图层!"); |
|
LogAPI.Debug("未找到“基础_合法建设用地范围”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("HFJSYDFW", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.LNGDFWPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_历年耕地"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_历年耕地”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("LNGDFW", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.GDJHFSXPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_恢复属性"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_恢复属性”图层!"); |
|
//throw new Exception("未找到“基础_耕地恢复属性”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("GDHFSX", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
//if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.CZCDYDPath)) |
|
if (projectInfo != null) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_城镇村等用地"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("CZCDYDI"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_城镇村等用地”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("CZCDYDI", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.YDGLXXPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_农转用项目图斑"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
//暂时注释,基础_农转用项目图斑 当前没有具体需求 |
|
//LogAPI.Debug("未找到“基础_农转用项目图斑”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("NYZXMTB", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.PDTPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_省级下发坡度图"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“基础_省级下发坡度图”图层!"); |
|
//throw new Exception("未找到“基础_省级下发坡度图”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("SJXF_PDT", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
|
|
} |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("质检结果"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null) |
|
{ |
|
LogAPI.Debug("未找到“质检结果”图层!"); |
|
//throw new Exception("未找到“质检结果”图层!"); |
|
} |
|
else |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("N", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.GJNMKPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("行政区_年末库"); |
|
if (featureLayer != null && featureLayer.FeatureClass != null) |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("XZQ_NMK", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.BGFWCGPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_变更范围成果"); |
|
if (featureLayer != null && featureLayer.FeatureClass != null) |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("JC_BGFWCG", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
} |
|
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.CNGDPath)) |
|
{ |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_承诺耕地"); |
|
if (featureLayer != null && featureLayer.FeatureClass != null) |
|
{ |
|
basicDataInfo = new Kingo.RuleCheck.BasicDataInfo() |
|
{ |
|
WorkspacePath = (featureLayer.FeatureClass as FeatureClass).Workspace.PathName, |
|
FeatureClassName = new Dictionary<string, string>() |
|
}; |
|
featureClass = featureLayer.FeatureClass as FeatureClass; |
|
basicDataInfo.FeatureClassName.Add("JC_CNGD", featureClass.BrowseName); |
|
switch (GetWorkspaceType(featureClass.Workspace)) |
|
{ |
|
case "SHP": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.ShapeFile; |
|
break; |
|
case "GDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.GDBFile; |
|
break; |
|
case "MDB": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.MDBFile; |
|
break; |
|
case "SDEConn": |
|
basicDataInfo.WorkspaceType = WorkspaceTypeEnum.SDEConn; |
|
break; |
|
} |
|
lstBasicData.Add(basicDataInfo); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("质检前获取参考数据失败:" + ex.Message); |
|
} |
|
return lstBasicData; |
|
} |
|
|
|
/// <summary> |
|
/// 获取工作空间类型 |
|
/// </summary> |
|
/// <param name="workspace"></param> |
|
/// <returns></returns> |
|
public static string GetWorkspaceType(IWorkspace workspace) |
|
{ |
|
try |
|
{ |
|
string workspaceType = string.Empty; |
|
switch (workspace.Type) |
|
{ |
|
case esriWorkspaceType.esriFileSystemWorkspace: |
|
workspaceType = "SHP"; |
|
break; |
|
case esriWorkspaceType.esriLocalDatabaseWorkspace: |
|
if (workspace.PathName.EndsWith(".gdb", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
workspaceType = "GDB"; |
|
} |
|
else if (workspace.PathName.EndsWith(".mdb", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
workspaceType = "MDB"; |
|
} |
|
break; |
|
case esriWorkspaceType.esriRemoteDatabaseWorkspace: |
|
workspaceType = "SDEConn"; |
|
break; |
|
} |
|
if (string.IsNullOrWhiteSpace(workspaceType)) |
|
{ |
|
throw new Exception("未知的工作空间类型"); |
|
} |
|
return workspaceType; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
private static IGeometry Erase(IGeometry geoSource, IGeometry geoTarget) |
|
{ |
|
ITopologicalOperator topologicalOperator = geoSource as ITopologicalOperator; |
|
return topologicalOperator.Difference(geoTarget); |
|
} |
|
|
|
/// <summary> |
|
/// IGeometry转JSON字符串 |
|
/// </summary> |
|
/// <param name="geometry">待转换图形</param> |
|
/// <param name="wkid">坐标参考wkid,4490:CGCS2000球面坐标参考,默认输出CGCS2000球面坐标参考的json图形</param> |
|
/// <param name="isGeograhicCoordinateSystem">是地理坐标参考</param> |
|
/// <returns></returns> |
|
public static string ConverIGometryToJson(IGeometry geometry, int wkid = 4490, bool isGeograhicCoordinateSystem = true) |
|
{ |
|
try |
|
{ |
|
if (geometry == null || geometry.IsEmpty || geometry.SpatialReference == null) |
|
{ |
|
throw new Exception("图形或坐标参考为空,无法转换!"); |
|
} |
|
if (wkid > 0) |
|
{ |
|
if (isGeograhicCoordinateSystem) |
|
{ |
|
geometry.Project(GeoDBAPI.CreateGeographicCoordinateSystem(wkid)); |
|
} |
|
else |
|
{ |
|
geometry.Project(GeoDBAPI.CreteSpatialReference(wkid)); |
|
} |
|
} |
|
using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser()) |
|
{ |
|
JSONConverterGeometryClass jsonConverter = new JSONConverterGeometryClass(); |
|
comReleaser.ManageLifetime(jsonConverter); |
|
IJSONWriter jsonWriter = new JSONWriterClass(); |
|
jsonWriter.WriteToString(); |
|
comReleaser.ManageLifetime(jsonWriter); |
|
jsonConverter.WriteGeometry(jsonWriter, null, geometry, false); |
|
return Encoding.UTF8.GetString(jsonWriter.GetStringBuffer()); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// JSON图图形转IGeometry |
|
/// </summary> |
|
/// <param name="jsonGeometry">图形串</param> |
|
/// <param name="geometryType">图形类型:点,线、面</param> |
|
/// <param name="wkid">输出图形坐标参考wkid,4490:CGCS2000球面坐标参考,默认输出CGCS2000球面坐标参考的json图形</param> |
|
/// <param name="isGeograhicCoordinateSystem">是地理坐标参考</param> |
|
/// <returns></returns> |
|
public static IGeometry ConverJsonToIGeoemtry(string jsonGeometry, esriGeometryType geometryType = esriGeometryType.esriGeometryPolygon, int wkid = 4490, bool isGeograhicCoordinateSystem = true) |
|
{ |
|
try |
|
{ |
|
using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser()) |
|
{ |
|
ESRI.ArcGIS.esriSystem.IJSONReader reader = new ESRI.ArcGIS.esriSystem.JSONReaderClass(); |
|
comReleaser.ManageLifetime(reader); |
|
reader.ReadFromString(jsonGeometry); |
|
ESRI.ArcGIS.Geometry.JSONConverterGeometryClass jsonConverter = new JSONConverterGeometryClass(); |
|
comReleaser.ManageLifetime(jsonConverter); |
|
IGeometry geometry = jsonConverter.ReadGeometry(reader, geometryType, false, false); |
|
if (geometry == null || geometry.IsEmpty) |
|
{ |
|
throw new Exception("转换后图形为空!"); |
|
} |
|
//此处发现湖南抽取过来的图形Simplify之后图形变化较大,会删除节点,所以湖南暂时不执行图形简化操作 |
|
if (!KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) |
|
{ |
|
ESRI.ArcGIS.Geometry.ITopologicalOperator topological = geometry as ESRI.ArcGIS.Geometry.ITopologicalOperator; |
|
if (!topological.IsSimple) |
|
{ |
|
topological.Simplify(); |
|
} |
|
} |
|
ISpatialReference spatialReference = null; |
|
if (isGeograhicCoordinateSystem) |
|
{ |
|
spatialReference = GeoDBAPI.CreateGeographicCoordinateSystem(wkid); |
|
} |
|
else |
|
{ |
|
spatialReference = GeoDBAPI.CreteSpatialReference(wkid); |
|
} |
|
if (wkid > 0) |
|
{ |
|
if (geometry.SpatialReference == null) |
|
{ |
|
geometry.SpatialReference = spatialReference; |
|
} |
|
else if (wkid != geometry.SpatialReference.FactoryCode) |
|
{ |
|
geometry.Project(spatialReference); |
|
} |
|
} |
|
return geometry; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 质检 |
|
/// </summary> |
|
/// <param name="dbPath"></param> |
|
/// <param name="rdbHelper"></param> |
|
/// <returns></returns> |
|
public static List<RuleEntity> DTBCheckPackage(string tbbsm, string dbPath) |
|
{ |
|
bool ZTIsUploaded = false; |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
//rdbHelper = RDBFactory.CreateDbHelper(dbPath, DatabaseType.SQLite); |
|
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
|
|
//已上传状态 |
|
ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, tbbsm); |
|
|
|
List<RuleEntity> lstResult = new List<Kingo.RuleCheck.RuleEntity>(); |
|
//去除冗余数据 |
|
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); |
|
if (tbbsm == null) |
|
{ |
|
//排除返外业的不检查 |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("data", "select TBBSM from wyrw where FWY=0 OR FWY IS NULL", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
return null; |
|
} |
|
foreach (DataRow dr in dataTable.Rows) |
|
{ |
|
tbbsm = dr[0] as string; |
|
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 Kingo.RuleCheck.RuleEntity() { ErrorId = tbbsm, ErrorTip = "当前外业图斑下不存在变更图斑!", RuleContent = "当前外业图斑下不存在变更图斑", ErrorType = "一类错误" }); |
|
continue; |
|
} |
|
List<Kingo.RuleCheck.RuleEntity> results = Kingo.RuleCheck.XJRuleCheck.RuleCheckOpertion_DTB.StartXJSHCheck(dr[0] as string, dbPath, GetBasicData()); |
|
if (results != null && results.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; |
|
results.OrderBy(X => X.ErrorId); |
|
foreach (var item in results) |
|
{ |
|
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); |
|
} |
|
lstResult.AddRange(results); |
|
} |
|
} |
|
else |
|
{ |
|
//返外业的不检查 |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("data", $"select TBBSM from wyrw where TBBSM='{tbbsm}' AND FWY=1", true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
return lstResult; |
|
} |
|
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 Kingo.RuleCheck.RuleEntity() { ErrorId = tbbsm, ErrorTip = "当前外业图斑下不存在变更图斑!", RuleContent = "当前外业图斑下不存在变更图斑", ErrorType = "一类错误" }); |
|
} |
|
else |
|
{ |
|
lstResult = Kingo.RuleCheck.XJRuleCheck.RuleCheckOpertion_DTB.StartXJSHCheck(tbbsm, dbPath, GetBasicData()); |
|
} |
|
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); |
|
} |
|
} |
|
return lstResult; |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
if (!ZTIsUploaded) |
|
rdbHelper.ExecuteNonQueryWithException($"update wyrw set ZT='质检错误' where tbbsm='{tbbsm}'", CommandType.Text); |
|
} |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
private ControlsEditingSaveCommandClass saveCommandClass { get; set; } |
|
/// <summary> |
|
/// 保存编辑 |
|
/// </summary> |
|
/// <param name="hookHelper"></param> |
|
public void SaveEingineEdit(IHookHelper hookHelper) |
|
{ |
|
try |
|
{ |
|
if (saveCommandClass == null) |
|
{ |
|
saveCommandClass = new ControlsEditingSaveCommandClass(); |
|
saveCommandClass.OnCreate(hookHelper.Hook); |
|
} |
|
saveCommandClass.OnClick(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
public static double GetTKXS(string gdpdjb, string gdlx) |
|
{ |
|
double kcxs = 0; |
|
string ConfigPath = System.IO.Path.Combine(KGIS.Framework.Utils.SysAppPath.GetConfigPath(), "BG_GDLXConfig.xml"); |
|
XDocument SystemConfigDocument = XDocument.Load(ConfigPath); |
|
var elements = SystemConfigDocument.Element("GDLX").Elements(); |
|
foreach (XElement item in elements) |
|
{ |
|
if (item.Attribute("GDLX").Value == gdlx && item.Attribute("GDPDJB").Value == gdpdjb) |
|
{ |
|
if (!string.IsNullOrEmpty(item.Attribute("KCDLXS").Value)) |
|
{ |
|
kcxs = double.Parse(item.Attribute("KCDLXS").Value); |
|
} |
|
} |
|
} |
|
return kcxs; |
|
} |
|
|
|
/// <summary> |
|
/// 判断是否是已上传状态 |
|
/// </summary> |
|
/// <returns></returns> |
|
public static bool JudgeZTIsUploaded(IRDBHelper rdbHelper, string tbbsm) |
|
{ |
|
string sql = ""; |
|
try |
|
{ |
|
if (string.IsNullOrEmpty(tbbsm)) |
|
sql = $"select distinct tbbsm, ZT from wyrw "; |
|
else |
|
sql = $"select distinct tbbsm, ZT from wyrw where tbbsm='{tbbsm}' "; |
|
|
|
DataTable dtWyrwZT = rdbHelper.ExecuteDatatable("wyrw", sql, true); |
|
if (dtWyrwZT != null && dtWyrwZT.Rows.Count > 0) |
|
{ |
|
if (dtWyrwZT.Rows[0]["ZT"].ToString() == "已上传") |
|
return true; |
|
else |
|
return false; |
|
} |
|
return false; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("JudgeZTIsUploaded 异常" + ex.Message); |
|
LogAPI.Debug("JudgeZTIsUploaded 异常" + ex.StackTrace); |
|
return false; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 图形相交获取基础库字段值 |
|
/// </summary> |
|
/// <param name="newFeature"></param> |
|
/// <param name="attributeName"></param> |
|
/// <param name="layerDLTB"></param> |
|
/// <returns></returns> |
|
private static string GetAttributeValue(IFeature newFeature, string attributeName, ILayer layerDLTB) |
|
{ |
|
if(layerDLTB == null) |
|
{ |
|
return ""; |
|
} |
|
string strValue = string.Empty; |
|
Dictionary<ESRI.ArcGIS.Geometry.IGeometry, IFeature> data = DTBDBLoadHelper.IdentifyReturnIntersect(newFeature.ShapeCopy, layerDLTB); |
|
if (data != null && data.Count > 0) |
|
{ |
|
int index = data.Values.FirstOrDefault().Fields.FindField(attributeName); |
|
double gArea = 0; |
|
foreach (var item in data) |
|
{ |
|
if (gArea < (item.Key as ESRI.ArcGIS.Geometry.IArea).Area) |
|
{ |
|
gArea = (item.Key as ESRI.ArcGIS.Geometry.IArea).Area; |
|
strValue = item.Value.get_Value(index).ToString(); |
|
} |
|
} |
|
} |
|
return strValue; |
|
} |
|
|
|
} |
|
}
|
|
|