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.
1609 lines
78 KiB
1609 lines
78 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.OpenData.Control; |
|
using KGIS.Framework.OpenData.Filter; |
|
using KGIS.Framework.OpenData.InterFace; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils.Interface; |
|
using Kingo.Plugin.General.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using Kingo.PluginServiceInterface.Helper; |
|
using Kingo.PluginServiceInterface.Model; |
|
using KUI.Windows; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading; |
|
using System.Windows; |
|
using System.Xml; |
|
using IRDBHelper = KGIS.Framework.DBOperator.IRDBHelper; |
|
|
|
namespace Kingo.Plugin.General.ViewDTBJK |
|
{ |
|
/// <summary> |
|
/// UCJKResultExport.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCJKResultExport : BaseWindow |
|
{ |
|
public IHookHelper hookHelper { get; set; } |
|
private ProjectInfo ProjectInfo { get; set; } |
|
public string BID { get; set; } |
|
|
|
public UCJKResultExport(bool taskMultExport = false) |
|
{ |
|
InitializeComponent(); |
|
if (taskMultExport) |
|
{ |
|
this.btnCheck.Visibility = Visibility.Collapsed; |
|
this.btnExport.Visibility = Visibility.Collapsed; |
|
this.btnExportRW.Visibility = Visibility.Visible; |
|
this.btnImportCG.Visibility = Visibility.Visible; |
|
} |
|
else |
|
{ |
|
this.btnCheck.Visibility = Visibility.Visible; |
|
this.btnExport.Visibility = Visibility.Visible; |
|
this.btnExportRW.Visibility = Visibility.Collapsed; |
|
this.btnImportCG.Visibility = Visibility.Collapsed; |
|
} |
|
} |
|
|
|
public void BindData() |
|
{ |
|
ProjectInfo = KGIS.Framework.Maps.MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) |
|
{ |
|
return; |
|
} |
|
if (ProjectInfo.ListTaskPackage == null || ProjectInfo.ListTaskPackage.Count == 0) |
|
{ |
|
MessageHelper.Show("请先使用“任务加载”功能加载建库任务包!"); |
|
return; |
|
} |
|
List<ExportEntity> lstPackages = new List<ExportEntity>(); |
|
foreach (var item in ProjectInfo.ListTaskPackage) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
if (!string.IsNullOrWhiteSpace(BID) && !item.BID.Equals(BID)) |
|
{ |
|
continue; |
|
} |
|
string dbPath = string.Empty; |
|
if (!string.IsNullOrWhiteSpace(item.PackageTempPath) && System.IO.File.Exists(item.PackageTempPath)) |
|
{ |
|
dbPath = item.PackageTempPath; |
|
} |
|
else |
|
{ |
|
LogAPI.Debug(item.PackageName + "任务包未初始化!"); |
|
continue; |
|
} |
|
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(KGIS.Framework.Maps.MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("wyrw", $"select '{item.PackageName}' as PackageName,'{item.BID}' AS BID,TBBSM,ZT,(case when FWY==1 then '是' else '否' end) as FWY,(CASE WHEN XBTB==1 then '是' else '否' end) as XBTB,WYBZ,'{dbPath}' as PackagePath,sfsb from wyrw", true); |
|
if (dataTable == null || dataTable.Rows.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
List<ExportEntity> lst = KGIS.Framework.Utils.Utility.TBToList.ToList<ExportEntity>(dataTable); |
|
if (lst == null || lst.Count <= 0) |
|
{ |
|
continue; |
|
} |
|
lstPackages.AddRange(lst); |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError(item.PackageName + "加载失败:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
gridPackage.ItemsSource = lstPackages; |
|
} |
|
|
|
private string fileName { get; set; } |
|
private USBFlashDiskHelper uSBFlashDiskHelper { get; set; } |
|
/// <summary> |
|
/// 导出的成果包路径 |
|
/// </summary> |
|
private string ResultFileName { get; set; } |
|
/// <summary> |
|
/// 导出的成果签章 |
|
/// </summary> |
|
private string SignFileName { get; set; } |
|
private void BtnExport_Click(object sender, RoutedEventArgs e) |
|
{ |
|
IRDBHelper rdbHelperDB = null; |
|
try |
|
{ |
|
if (string.IsNullOrWhiteSpace(EncryptionHelper.GetDogKey(1, this.ProjectInfo.CODE))) |
|
{ |
|
MessageHelper.ShowError("请插入加密狗!"); |
|
return; |
|
} |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开工程!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择需要导出的数据!"); |
|
return; |
|
} |
|
List<ExportEntity> listExport = new List<ExportEntity>(); |
|
string openPath = System.IO.Path.Combine(ProjectInfo.TaskPath, "已输出"); |
|
string mergePath = string.Empty; |
|
string signFileName = string.Empty; |
|
switch (Platform.Instance.SystemType) |
|
{ |
|
case SystemTypeEnum.DTBJK: |
|
#region 导出建库任务包 |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
if (listExport.FirstOrDefault(x => x.TBBSM.Equals(item.TBBSM)) != null) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "存在多个,单次输出只能选择单个" + item.TBBSM + "任务图斑!"); |
|
return; |
|
} |
|
rdbHelperDB = RDBFactory.CreateDbHelper($"{item.PackagePath}{(KGIS.Framework.Maps.MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
DataTable dt = rdbHelperDB.ExecuteDatatable("DTBDLTBGXGC", $"SELECT * FROM DTBDLTBGXGC T WHERE t.tbbsm='{item.TBBSM}' and (t.EGeometry is NULL or t.EGeometry='')", true); |
|
if (dt.Rows.Count > 0) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "数据异常,请重新填写变更范围属性!"); |
|
return; |
|
} |
|
if (item.ZT.Equals("已完成") || item.ZT.Equals("已输出")) |
|
{ |
|
listExport.Add(item); |
|
} |
|
} |
|
if (listExport.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择状态为“已完成”的外业任务图斑输出!"); |
|
return; |
|
} |
|
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips($"共选择{listExport.Count}个可输出图斑,是否继续?"); |
|
if (dialogResult != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
if (!System.IO.Directory.Exists(openPath)) |
|
{ |
|
System.IO.Directory.CreateDirectory(openPath); |
|
} |
|
DataTable dataTable = rdbHelperDB.ExecuteDatatable("result", string.Format("select sjly from wyrw where tbbsm = '{0}'", listExport[0].TBBSM), true); |
|
if (dataTable != null && dataTable.Rows.Count > 0 && dataTable.Rows[0]["sjly"].ToString().ToUpper() == "1") |
|
{ |
|
mergePath = DTBDBLoadHelper.MergeDB(listExport, true); |
|
} |
|
else |
|
{ |
|
mergePath = DTBDBLoadHelper.MergeDB(listExport); |
|
} |
|
this.ShowLoading("正在导出数据……", 0, 0); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在导出数据……"); |
|
DTBDBLoadHelper.ExportDB(mergePath, openPath); |
|
foreach (var item in listExport) |
|
{ |
|
try |
|
{ |
|
rdbHelperDB = RDBFactory.CreateDbHelper($"{item.PackagePath}{(KGIS.Framework.Maps.MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
|
|
//已上传状态 |
|
bool ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelperDB, item.TBBSM); |
|
|
|
DataTable dt = rdbHelperDB.ExecuteDatatable("DTBDLTBGXGC", $"select bsm from DTBDLTBGXGC where bghtbbsm in (select bsm from DTBDLTBGX where tbbsm ='{item.TBBSM}')", true); |
|
if (item.FWY != "是" && dt.Rows.Count == 0) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "数据异常,未检测到更新过程层属性!"); |
|
return; |
|
} |
|
if (!ZTIsUploaded) |
|
rdbHelperDB.ExecuteNonQueryWithException($"update wyrw set zt='已输出' where tbbsm ='{item.TBBSM}'", CommandType.Text); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("导出更新外业任务图斑状态为“已输出”异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (rdbHelperDB != null) |
|
rdbHelperDB.DisConnect(); |
|
} |
|
} |
|
#endregion |
|
break; |
|
case SystemTypeEnum.WYZS: |
|
#region 导出质检审核 |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
if (listExport.FirstOrDefault(x => x.TBBSM.Equals(item.TBBSM)) != null) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "存在多个,单次输出只能选择单个" + item.TBBSM + "任务图斑!"); |
|
return; |
|
} |
|
if ((item.ZT.Equals("质检错误") || item.ZT.Equals("审核不通过") || (item.ZT.Equals("未审核")) && item.FWY != "是")) |
|
{ |
|
continue; |
|
} |
|
listExport.Add(item); |
|
} |
|
if (listExport.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择需要输出的审核通过的图斑!"); |
|
return; |
|
} |
|
else |
|
{ |
|
if (MessageHelper.ShowYesNoCancelAndTips($"状态为“已完成”或标记“返外业”的仅有{listExport.Count}个图斑,是否继续导出?") != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
} |
|
this.ShowLoading("正在导出数据……", 0, 0); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在导出数据......"); |
|
if (!System.IO.Directory.Exists(openPath)) |
|
{ |
|
System.IO.Directory.CreateDirectory(openPath); |
|
} |
|
mergePath = DTBDBLoadHelper.MergeDB(listExport); |
|
ResultFileName = DTBDBLoadHelper.ExportDB(mergePath, openPath, ref signFileName); |
|
this.SignFileName = signFileName; |
|
foreach (var item in listExport) |
|
{ |
|
try |
|
{ |
|
rdbHelperDB = RDBFactory.CreateDbHelper($"{item.PackagePath}{(KGIS.Framework.Maps.MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
|
|
//已上传状态 |
|
bool ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelperDB, item.TBBSM); |
|
|
|
if (!ZTIsUploaded) |
|
rdbHelperDB.ExecuteNonQueryWithException($"update wyrw set zt='已输出' where tbbsm ='{item.TBBSM}'", CommandType.Text); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("导出更新外业任务图斑状态为“已输出”异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (rdbHelperDB != null) |
|
rdbHelperDB.DisConnect(); |
|
} |
|
} |
|
#endregion |
|
break; |
|
default: |
|
break; |
|
} |
|
this.BindData(); |
|
this.CloseLoading(); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
if (!string.IsNullOrWhiteSpace(openPath) && System.IO.Directory.Exists(openPath)) |
|
{ |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
if (MessageHelper.ShowYesNoAndTips($"导出完成,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
System.Diagnostics.Process.Start("explorer.exe", openPath); |
|
} |
|
else |
|
{ |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
MessageHelper.Show($"导出成功!"); |
|
} |
|
Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "AfterLoadRefreshTreeData" }); |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
MessageHelper.ShowError("成果输出异常:" + ex.Message); |
|
LogAPI.Debug("成果输出异常:" + ex.Message); |
|
LogAPI.Debug("成果输出异常:" + ex.StackTrace); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
} |
|
} |
|
|
|
private void SyncUSBTask(string path) |
|
{ |
|
try |
|
{ |
|
if (string.IsNullOrWhiteSpace(fileName) || !System.IO.File.Exists(fileName) || !System.IO.Directory.Exists(path)) |
|
{ |
|
return; |
|
} |
|
string savePath = System.IO.Path.Combine(path, KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("UsbFolderName"), "4-审核任务"); |
|
KGIS.Framework.Platform.Helper.ProgressHelper.SetProcessMsg($"正在输出成果到:{savePath}......"); |
|
if (!System.IO.Directory.Exists(savePath)) |
|
{ |
|
System.IO.Directory.CreateDirectory(savePath); |
|
} |
|
System.IO.File.Copy(fileName, System.IO.Path.Combine(savePath, System.IO.Path.GetFileName(fileName))); |
|
KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
if (System.IO.Directory.Exists(savePath)) |
|
{ |
|
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
System.Diagnostics.Process.Start("explorer.exe", savePath); |
|
} |
|
} |
|
else |
|
{ |
|
MessageHelper.Show("导出成功!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
MessageHelper.ShowError("输出成果拷贝移动存储异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
fileName = string.Empty; |
|
KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导出返回外业Excel |
|
/// </summary> |
|
private int ExportFWYExcel(string wyOuputPath) |
|
{ |
|
try |
|
{ |
|
string state = "返外业"; |
|
List<ExportEntity> listPackage = new List<ExportEntity>(); |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
listPackage.Add(item); |
|
} |
|
if (listPackage.Where(x => x.ZT.Equals(state)).Count() <= 0) |
|
{ |
|
//MessageHelper.ShowTips("当前数据中没有状态为“" + state + "”的任务包,无法导出返外业数据!"); |
|
return 0; |
|
} |
|
foreach (ExportEntity item in listPackage) |
|
{ |
|
if (!item.ZT.Equals(state)) |
|
{ |
|
this.gridPackage.SelectedItems.Remove(item); |
|
} |
|
} |
|
DevExpress.XtraPrinting.XlsxExportOptions options = new DevExpress.XtraPrinting.XlsxExportOptions(); |
|
options.SheetName = state; |
|
viewPackage.ExportToXlsx(System.IO.Path.Combine(wyOuputPath, "返外业_" + this.gridPackage.SelectedItems.Count + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"), options); |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
//item.State = "外业中"; |
|
UpdateState(item, "外业中"); |
|
} |
|
return this.gridPackage.SelectedItems.Count; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 更新状态 |
|
/// </summary> |
|
private void UpdateState(ExportEntity exportEntity, string state) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
if (exportEntity == null) |
|
{ |
|
return; |
|
} |
|
rdbHelper = RDBFactory.CreateDbHelper(exportEntity.PackagePath, DatabaseType.SQLite); |
|
//已上传状态 |
|
bool ZTIsUploaded = DTBDBLoadHelper.JudgeZTIsUploaded(rdbHelper, exportEntity.TBBSM); |
|
string excuteSQL = $"UPDATE WYRW SET ZT='{state}',WYBZ='{exportEntity.WYBZ}' WHERE TBBSM='{exportEntity.TBBSM}'"; |
|
if (!ZTIsUploaded) |
|
excuteSQL = $"UPDATE WYRW SET WYBZ='{exportEntity.WYBZ}' WHERE TBBSM='{exportEntity.TBBSM}'"; |
|
|
|
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text); |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError($"标记任务图斑状态为“{state}”异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
|
|
private void BtnRefresh_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
BindData(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError("刷新失败:" + ex.Message); |
|
LogAPI.Debug("刷新失败" + ex); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导出批量任务 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnExportRW_Click(object sender, RoutedEventArgs e) |
|
{ |
|
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = null; |
|
try |
|
{ |
|
ProjectInfo = KGIS.Framework.Maps.MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开建库工程!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.Show("请选择需要导出的建库任务包!"); |
|
return; |
|
} |
|
List<ExportEntity> listExport = new List<ExportEntity>(); |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
/* 修改人:杨元芝 |
|
* 修改时间:2023-01-10 |
|
* 修改说明:湖南项目要求导出时,“未完成”,“已完成”,“已输出”这三个状态都可以输出GDB文件 |
|
*/ |
|
if (!SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) |
|
{ |
|
if (item.ZT.Equals("已输出")) |
|
{ |
|
continue; |
|
} |
|
} |
|
if (listExport.FirstOrDefault(x => x.TBBSM.Equals(item.TBBSM)) != null) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "存在多个,单次输出只能选择单个" + item.TBBSM + "任务图斑!"); |
|
return; |
|
} |
|
listExport.Add(item); |
|
} |
|
if (listExport.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择状态非“已输出”的数据!"); |
|
return; |
|
} |
|
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips($"共选择{listExport.Count}个图斑,是否确认输出?"); |
|
if (dialogResult != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); |
|
dialogResult = folderBrowserDialog.ShowDialog(); |
|
if (dialogResult != System.Windows.Forms.DialogResult.OK) |
|
{ |
|
return; |
|
} |
|
this.ShowLoading("正在导出批量任务...", 0, 0); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在导出批量任务..."); |
|
int wkid = ProjectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (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) |
|
{ |
|
wkid = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
string gdbPath = System.IO.Path.Combine(folderBrowserDialog.SelectedPath, "JKRW_" + listExport.Count + "个_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".gdb"); |
|
DecompressionDB decompressionDB = new DecompressionDB(); |
|
decompressionDB.MultDBToGDB(listExport, gdbPath, wkid, EncryptionHelper.GetDogKey(1, ProjectInfo.CODE)); |
|
this.CloseLoading(); |
|
if (System.IO.Directory.Exists(gdbPath)) |
|
{ |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
System.Diagnostics.Process.Start("explorer.exe", folderBrowserDialog.SelectedPath); |
|
} |
|
} |
|
else |
|
{ |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar(); |
|
MessageHelper.Show("导出成功!"); |
|
} |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (folderBrowserDialog != null) |
|
{ |
|
folderBrowserDialog.Dispose(); |
|
} |
|
} |
|
} |
|
|
|
private void ImportFjgxData(ISpatialDataObject distObj, System.Windows.Forms.DialogResult dialogResult, Dictionary<string, string> dicPath) |
|
{ |
|
bool b = false; //是否清空已有附件关系数据 |
|
DataTable pTable = new DataTable(); |
|
IDataset pDataset = (distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open() as IDataset; |
|
if (pDataset is ITable) |
|
{ |
|
dialogResult = MessageHelper.ShowYesNoCancelAndTips("导入前是否清空已有附件关系数据?选择“Yes”则清空,选择“No”则追加,选择“Cancel”终止导入"); |
|
if (dialogResult == System.Windows.Forms.DialogResult.Cancel) |
|
{ |
|
MessageHelper.Show("终止导入!"); |
|
return; |
|
} |
|
if (dialogResult == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
b = true; |
|
} |
|
this.ShowLoading("正在导入附件关系数据...", 0, 0); |
|
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在导入附件关系数据..."); |
|
ITable table = pDataset as ITable; |
|
for (int j = 0; j < table.Fields.FieldCount; j++) |
|
{ |
|
pTable.Columns.Add(table.Fields.get_Field(j).Name); |
|
} |
|
ICursor pCursor = table.Search(null, false); |
|
IRow pRow = pCursor.NextRow(); |
|
while (pRow != null) |
|
{ |
|
DataRow dRow = pTable.NewRow(); |
|
string[] strRow = new string[pRow.Fields.FieldCount]; |
|
for (int i = 0; i < pRow.Fields.FieldCount; i++) |
|
{ |
|
strRow[i] = pRow.get_Value(i).ToString(); |
|
} |
|
dRow.ItemArray = strRow; |
|
pTable.Rows.Add(dRow); |
|
pRow = pCursor.NextRow(); |
|
} |
|
} |
|
if (pTable.Rows.Count > 0) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
foreach (var item in dicPath) |
|
{ |
|
try |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper(item.Value, DatabaseType.SQLite); |
|
rdbHelper.BeginTransaction(); |
|
StringBuilder strSql = new StringBuilder(); |
|
if (b) |
|
{ |
|
strSql.Append("DELETE FROM FJGX"); |
|
rdbHelper.ExecuteNonQuery(strSql.ToString(), CommandType.Text); |
|
strSql.Clear(); |
|
} |
|
strSql.Append("INSERT INTO FJGX (BSM,WYTBBSM,FJARG,TBBSM) VALUES "); |
|
for (var n = 0; n < pTable.Rows.Count; n++) |
|
{ |
|
if (pTable.Rows[n]["BSM"] == null || string.IsNullOrEmpty(pTable.Rows[n]["BSM"].ToString())) |
|
{ |
|
MessageHelper.Show("附件关系 BSM 不能为空。"); |
|
return; |
|
} |
|
if (pTable.Rows[n]["WYTBBSM"] == null || string.IsNullOrEmpty(pTable.Rows[n]["WYTBBSM"].ToString())) |
|
{ |
|
MessageHelper.Show("附件关系 WYTBBSM 不能为空。"); |
|
return; |
|
} |
|
if (pTable.Rows[n]["FJARG"] == null || string.IsNullOrEmpty(pTable.Rows[n]["FJARG"].ToString())) |
|
{ |
|
MessageHelper.Show("附件关系 FJARG 不能为空。"); |
|
return; |
|
} |
|
if (pTable.Rows[n]["TBBSM"] == null || string.IsNullOrEmpty(pTable.Rows[n]["TBBSM"].ToString())) |
|
{ |
|
MessageHelper.Show("附件关系 TBBSM 不能为空。"); |
|
return; |
|
} |
|
|
|
strSql.Append(string.Format("('{0}','{1}','{2}','{3}'),", pTable.Rows[n]["BSM"].ToString(), pTable.Rows[n]["WYTBBSM"].ToString(), pTable.Rows[n]["FJARG"].ToString(), pTable.Rows[n]["TBBSM"].ToString())); |
|
} |
|
int i = rdbHelper.ExecuteNonQuery(strSql.ToString().TrimEnd(','), CommandType.Text); |
|
rdbHelper.Commit(); |
|
this.CloseLoading(); |
|
MessageHelper.Show("附件关系数据导入完成。"); |
|
return; |
|
} |
|
catch (Exception ee) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.Show("附件关系数据导入失败。"); |
|
rdbHelper.Rollback(); |
|
throw ee; |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
|
|
} |
|
} |
|
} |
|
else |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.Show("未检测到附件关系数据。"); |
|
return; |
|
} |
|
this.CloseLoading(); |
|
|
|
} |
|
|
|
private void BtnImportCG_Click(object sender, RoutedEventArgs e) |
|
{ |
|
IFeatureClass featureClass = null; |
|
IFeatureClassAPI wyrwFeatureClassAPI = null; |
|
try |
|
{ |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开建库工程!"); |
|
return; |
|
} |
|
if (ProjectInfo.ListTaskPackage == null || ProjectInfo.ListTaskPackage.Count == 0) |
|
{ |
|
MessageHelper.Show("请先使用“任务加载”功能加载建库任务包!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems == null || this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.Show("请从列表中勾选需要导入的图斑!"); |
|
return; |
|
} |
|
List<ExportEntity> lstPackages = new List<ExportEntity>(); |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
lstPackages.Add(item); |
|
} |
|
Dictionary<string, string> dicPath = new Dictionary<string, string>(); |
|
foreach (ExportEntity item in lstPackages) |
|
{ |
|
if (dicPath.ContainsKey(item.TBBSM)) |
|
{ |
|
continue; |
|
} |
|
if (!string.IsNullOrWhiteSpace(item.PackagePath) && System.IO.File.Exists(item.PackagePath)) |
|
{ |
|
dicPath.Add(item.TBBSM, item.PackagePath); |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("未找到任务包:" + item.PackagePath); |
|
continue; |
|
} |
|
} |
|
if (dicPath.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("所选任务包均未找到原始任务包路径!"); |
|
return; |
|
} |
|
OpenDataDialog pDialog = new OpenDataDialog(); |
|
ISpatialDataObjectFilter pOFilter; |
|
pOFilter = new FilterDatasetsAndLayers(); |
|
pDialog.AddFilter(pOFilter, true); |
|
pDialog.Title = "选择导入的数据"; |
|
pDialog.AllowMultiSelect = false; |
|
pDialog.RestoreLocation = true; |
|
pDialog.StartLocation = pDialog.FinalLocation; |
|
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); |
|
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) |
|
{ |
|
foreach (ISpatialDataObject distObj in pDialog.Selection) |
|
{ |
|
if (distObj.DatasetType == esriDatasetType.esriDTFeatureClass) |
|
{ |
|
featureClass = (distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open() as IFeatureClass; |
|
} |
|
if (distObj.DatasetType == esriDatasetType.esriDTTable && SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) |
|
{ |
|
ImportFjgxData(distObj, dialogResult, dicPath); |
|
return; |
|
} |
|
} |
|
} |
|
|
|
if (featureClass == null) |
|
{ |
|
MessageHelper.Show("请选择矢量成果图层!"); |
|
return; |
|
} |
|
if ((featureClass as FeatureClass).Type == esriDatasetType.esriDTTable) |
|
{ |
|
MessageHelper.Show("选择属性表!"); |
|
return; |
|
} |
|
if (featureClass.ShapeType != esriGeometryType.esriGeometryPolygon) |
|
{ |
|
MessageHelper.Show("请选择面图层!"); |
|
return; |
|
} |
|
if (!(featureClass as FeatureClass).Name.Equals("DTBDLTBGX", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
MessageHelper.Show("请选择单图斑地类图斑更新(DTBDLTBGX)图层!"); |
|
return; |
|
} |
|
dialogResult = MessageHelper.ShowYesNoCancelAndTips("导入前是否清空已有变更范围?选择“Yes”则清空,选择“No”则追加,选择“Cancel”终止导入"); |
|
if (dialogResult == System.Windows.Forms.DialogResult.Cancel) |
|
{ |
|
MessageHelper.Show("终止导入!"); |
|
return; |
|
} |
|
bool isConvert = false; |
|
if (dialogResult == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
isConvert = true; |
|
} |
|
this.ShowLoading("正在导入批量变更范围数据...", 0, 0); |
|
int wkid = ProjectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (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) |
|
{ |
|
wkid = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
int importCount = 0; |
|
this.UpdateMsg("正在对选择图层进行质检..."); |
|
CheckFeatureClass(featureClass, wkid, ref wyrwFeatureClassAPI); |
|
this.UpdateMsg("正在导入批量建库数据..."); |
|
string message = string.Empty; |
|
bool isShowSuccendForm = true; |
|
ImportFeatureClass(dicPath, featureClass, wyrwFeatureClassAPI.FeatureClass, ref importCount, ref message, ref isShowSuccendForm, isConvert); |
|
Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "AfterLoadRefreshTreeData" }); |
|
this.CloseLoading(); |
|
if (string.IsNullOrWhiteSpace(message)) |
|
{ |
|
message = $"成功导入{importCount}个图斑!"; |
|
} |
|
else |
|
{ |
|
message = $"成功导入{importCount}个图斑,ObjectID={message.TrimEnd(',')}的图斑面积小于50,不予导入!"; |
|
} |
|
if (isShowSuccendForm) |
|
MessageHelper.Show(message); |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
this.CloseLoading(); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (wyrwFeatureClassAPI != null) |
|
{ |
|
wyrwFeatureClassAPI.CloseFeatureClass(); |
|
} |
|
if (featureClass != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 检查图层坐标参考、自相交 |
|
/// </summary> |
|
/// <param name="featureClass"></param> |
|
/// <param name="wkid"></param> |
|
private void CheckFeatureClass(IFeatureClass featureClass, int wkid, ref IFeatureClassAPI wyrwFeatureClass) |
|
{ |
|
KGIS.Framework.AE.WorkspaceAPI workspaceAPI = null; |
|
ITable table = null; |
|
ICursor cursor = null; |
|
IRow row = null; |
|
try |
|
{ |
|
workspaceAPI = new WorkspaceAPI((featureClass as FeatureClass).Workspace); |
|
if (!workspaceAPI.ExistFeatureClass("wyrw")) |
|
{ |
|
throw new Exception("所选图层所在数据库不存在WYRW(外业任务)图层,无法导入!"); |
|
} |
|
wyrwFeatureClass = workspaceAPI.OpenFeatureClass("wyrw"); |
|
if (!GeoDBAPI.SpatialReferenceCompareByWkid(wkid, (featureClass as IGeoDataset).SpatialReference)) |
|
{ |
|
throw new Exception("选择矢量数据坐标参考与当前任务包不一致,无法导入!"); |
|
} |
|
if (wyrwFeatureClass.FeatureClass.FindField("BID") == -1) |
|
{ |
|
throw new Exception("选择图层不存在BID字段,无法映射导入对应的任务包!"); |
|
} |
|
if (wyrwFeatureClass.FeatureClass.FindField("TBBSM") == -1) |
|
{ |
|
throw new Exception("选择图层不存在TBBSM字段,无法映射导入对应的任务包!"); |
|
} |
|
|
|
#region 检查变更范围图层内是否存在重复BSM |
|
//IQueryFilter queryFilter = new QueryFilterClass() |
|
//{ |
|
// SubFields = "BSM", |
|
// PostfixClause = "ORDER BY BSM ASC" |
|
//}; |
|
//IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); |
|
//IFeature feature = null; |
|
//string BSMValue = "-1"; |
|
//int BSMIndex = featureClass.FindField("BSM"); |
|
//while ((feature = featureCursor.NextFeature()) != null) |
|
//{ |
|
// if (BSMValue.Trim().Equals(feature.Value[BSMIndex].ToString())) |
|
// { |
|
// System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); |
|
// System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); |
|
// throw new Exception("选择图层'DTBDLTBGX'存在重复BSM,请修改后再进行数据导入!"); |
|
// } |
|
// else |
|
// BSMValue = feature.Value[BSMIndex].ToString().Trim(); |
|
//} |
|
#endregion |
|
|
|
string OutFeatureClassPath = System.IO.Path.GetPathRoot(SysAppPath.GetTempPath()) + "UsersKingo"; |
|
if (System.IO.Directory.Exists(OutFeatureClassPath)) |
|
System.IO.Directory.Delete(OutFeatureClassPath, true); |
|
System.IO.Directory.CreateDirectory(OutFeatureClassPath); |
|
GPParamClass gPParamClass = new KGIS.Framework.AE.GPHelper.GPParamClass() |
|
{ |
|
ListInFeatureClassPath = new List<string>() { System.IO.Path.Combine((featureClass as FeatureClass).Workspace.PathName, (featureClass as FeatureClass).BrowseName) }, |
|
OutFeatureClassPath = System.IO.Path.Combine(OutFeatureClassPath, "Check" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5)), |
|
IsGetOutPutFeature = true |
|
}; |
|
KGIS.Framework.AE.GPHelper.GeoprocessorHelper.CheckGeometry(gPParamClass, ref table); |
|
if (table != null) |
|
{ |
|
cursor = table.Search(null, true); |
|
int fieldOIDIndex = table.FindField("FEATURE_ID"); |
|
int fieldProblemIndex = table.FindField("PROBLEM"); |
|
string message = string.Empty; |
|
while ((row = cursor.NextRow()) != null) |
|
{ |
|
if (fieldOIDIndex > -1) |
|
{ |
|
message += "OBJECTID=" + row.get_Value(fieldOIDIndex); |
|
} |
|
if (fieldProblemIndex > -1) |
|
{ |
|
message += row.get_Value(fieldProblemIndex) + ";"; |
|
} |
|
} |
|
if (!string.IsNullOrWhiteSpace(message)) |
|
{ |
|
LogAPI.Debug("图斑存在质检问题:" + message); |
|
//throw new Exception("图斑存在质检问题,问题图斑请查看日志信息,修改后重试!"); |
|
throw new Exception(message); |
|
} |
|
} |
|
this.UpdateMsg("正在对选择图层进行重叠检查..."); |
|
if (OverlapCheck(featureClass, (featureClass as IGeoDataset).SpatialReference as IProjectedCoordinateSystem)) |
|
{ |
|
throw new Exception("所选图层面存在重叠,无法导入!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (workspaceAPI != null) |
|
{ |
|
workspaceAPI.CloseWorkspace(); |
|
} |
|
if (row != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(row); |
|
} |
|
if (table != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(table); |
|
} |
|
} |
|
} |
|
|
|
#region 检查图层内面是否重叠 |
|
/// <summary> |
|
/// 图层内面重叠检查 |
|
/// </summary> |
|
/// <returns></returns> |
|
private bool OverlapCheck(IFeatureClass featureClassDLTB, IProjectedCoordinateSystem spatialReference) |
|
{ |
|
IFeatureDataset featureDataset = null; |
|
IWorkspaceAPI workspaceAPI = null; |
|
IFeatureClassAPI featureClassAPI = null; |
|
try |
|
{ |
|
string tempMdb = GetTempMDB(Guid.NewGuid().ToString().Replace("-", "") + ".mdb"); |
|
workspaceAPI = new WorkspaceAPI(tempMdb, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.MDBFile); |
|
featureDataset = CreateFeatureDataset(workspaceAPI.CurrentWorkspace, "TDBZSJJ", spatialReference); |
|
double tolerance = 0.0001; |
|
SetGeoDatasetSpatialReference(workspaceAPI.CurrentWorkspace, spatialReference, tolerance); |
|
//设置坐标参考精度XYUnits 为二万分之一 |
|
try |
|
{ |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", tolerance)); |
|
} |
|
catch |
|
{ |
|
} |
|
string featureClassName = (featureClassDLTB as FeatureClass).BrowseName; |
|
KGIS.Framework.AE.GPHelper.GeoprocessorHelper.FeatureClassToFeatureClass(featureClassDLTB, System.IO.Path.Combine(tempMdb, "TDBZSJJ"), featureClassName); |
|
featureClassAPI = workspaceAPI.OpenFeatureClass(featureClassName); |
|
// 创建拓扑规则 |
|
List<ITopologyRule> lstRule = new List<ITopologyRule>(); |
|
ITopologyRule topologyRule = new TopologyRuleClass(); |
|
topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTAreaNoOverlap;//面要素间无重叠 |
|
topologyRule.Name = "esriTRTAreaNoOverlap";//面要素间无重叠 |
|
topologyRule.OriginClassID = featureClassAPI.FeatureClass.FeatureClassID; |
|
topologyRule.AllOriginSubtypes = true; |
|
topologyRule.OriginSubtype = 1; |
|
lstRule.Add(topologyRule); |
|
return DataCheckTopologyHelper.CreateTopology(lstRule, workspaceAPI.CurrentWorkspace, new List<string>() { featureClassName }); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (featureDataset != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataset); |
|
} |
|
if (featureClassAPI != null) |
|
{ |
|
featureClassAPI.CloseFeatureClass(); |
|
} |
|
if (workspaceAPI != null) |
|
{ |
|
workspaceAPI.CloseWorkspace(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取临时TempMdb |
|
/// </summary> |
|
/// <returns>返回路径字符串,末尾包括斜杠</returns> |
|
public static string GetTempMDB(string tempMDBName = "") |
|
{ |
|
string templetePath = SysAppPath.GetCurrentAppPath() + @"工作空间DTBJK\DatabaseTemplate\TempMDB.mdb"; |
|
if (!System.IO.File.Exists(templetePath)) |
|
{ |
|
throw new Exception("未找到模板:" + templetePath); |
|
} |
|
string tempMDBPath = System.IO.Path.Combine(GetTempPath(), string.IsNullOrWhiteSpace(tempMDBName) ? "TempMDB.mdb" : tempMDBName); |
|
if (!System.IO.File.Exists(tempMDBPath)) |
|
{ |
|
System.IO.File.Copy(templetePath, tempMDBPath, true); |
|
} |
|
return tempMDBPath; |
|
} |
|
|
|
/// <summary> |
|
/// 获取当前程序下的临时temp目录。支持BS和CS的程序,都是获取到app\Temp目录下,如果没有则创建该路径 |
|
/// </summary> |
|
/// <returns>返回路径字符串,末尾包括斜杠</returns> |
|
public static string GetTempPath() |
|
{ |
|
string strPath = SysAppPath.GetCurrentAppPath(); |
|
strPath += @"Temp\"; |
|
if (System.IO.Directory.Exists(strPath) == false) |
|
{ |
|
System.IO.Directory.CreateDirectory(strPath); |
|
} |
|
return strPath; |
|
} |
|
/// <summary> |
|
/// 给指定工作空间中的对象设置空间参考 |
|
/// </summary> |
|
/// <param name="pWS">工作空间</param> |
|
/// <param name="pSR">空间参考对象</param> |
|
/// <param name="pTolerance">数据库容差</param> |
|
private void SetGeoDatasetSpatialReference(IWorkspace pWS, ISpatialReference pSR, double pTolerance) |
|
{ |
|
try |
|
{ |
|
//double a = 0; |
|
//double b = 0; |
|
//double c = 0; |
|
//double d = 0; |
|
//pSR.SetDomain(-100000000, 0, 0, 0); |
|
//pSR.GetDomain(out a, out b, out c, out d); |
|
if (pSR != null) |
|
{ |
|
//ISpatialReferenceResolution toleranceResolution = pSR as ISpatialReferenceResolution; |
|
//toleranceResolution.set_XYResolution(true, 0.00005); |
|
ISpatialReferenceTolerance tolerance = pSR as ISpatialReferenceTolerance; |
|
if (tolerance != null) |
|
{ |
|
tolerance.XYTolerance = pTolerance; |
|
tolerance.ZTolerance = pTolerance; |
|
tolerance.MTolerance = pTolerance; |
|
} |
|
} |
|
IEnumDataset pEnumDataset = pWS.Datasets[esriDatasetType.esriDTFeatureDataset]; |
|
IDataset ds = null; |
|
if (pEnumDataset != null) |
|
{ |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
|
|
} |
|
} |
|
} |
|
pEnumDataset = pWS.Datasets[esriDatasetType.esriDTFeatureClass]; |
|
if (pEnumDataset == null) |
|
{ |
|
return; |
|
} |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
} |
|
} |
|
//设置坐标参考精度XYUnits 为二万分之一 |
|
try |
|
{ |
|
pWS.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", pTolerance)); |
|
//pWS.ExecuteSQL("UPDATE GDB_SpatialRefs SET FalseX=0,FalseY=0,XYUnits=100000,FalseZ=0,ZUnits=0,FalseM=0,MUnits=0,XYTolerance=0.0001,ZTolerance=0,MTolerance=0"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("设置坐标参考坐标精度和容差异常:" + ex.Message); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
/// <summary> |
|
/// 创建要素数据集 |
|
/// </summary> |
|
/// <param name="workspace"></param> |
|
/// <param name="code"></param> |
|
/// <param name="datasetName"></param> |
|
/// <returns></returns> |
|
private IFeatureDataset CreateFeatureDataset(IWorkspace workspace, string datasetName, IProjectedCoordinateSystem spatialReference) |
|
{ |
|
try |
|
{ |
|
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; |
|
//确定是否支持高精度存储空间 |
|
Boolean supportsHighPrecision = false; |
|
IWorkspaceProperties workspaceProperties = (IWorkspaceProperties)workspace; |
|
IWorkspaceProperty workspaceProperty = workspaceProperties.get_Property |
|
(esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup, |
|
(int)esriWorkspacePropertyType.esriWorkspacePropSupportsHighPrecisionStorage); |
|
if (workspaceProperty.IsSupported) |
|
{ |
|
supportsHighPrecision = Convert.ToBoolean(workspaceProperty.PropertyValue); |
|
} |
|
//设置投影精度 |
|
IControlPrecision2 controlPrecision = (IControlPrecision2)spatialReference; |
|
controlPrecision.IsHighPrecision = supportsHighPrecision; |
|
//设置容差 |
|
ISpatialReferenceResolution spatialRefResolution = (ISpatialReferenceResolution)spatialReference; |
|
spatialRefResolution.ConstructFromHorizon(); |
|
spatialRefResolution.SetDefaultXYResolution(); |
|
ISpatialReferenceTolerance spatialRefTolerance = (ISpatialReferenceTolerance)spatialReference; |
|
spatialRefTolerance.SetDefaultXYTolerance(); |
|
//创建要素集 |
|
IFeatureDataset featureDataset = featureWorkspace.CreateFeatureDataset(datasetName, spatialReference); |
|
return featureDataset; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
#endregion |
|
|
|
private void ImportFeatureClass(Dictionary<string, string> dicPath, IFeatureClass featureClass, IFeatureClass wyrwFeatureClass, ref int importCount, ref string message, ref bool isShowSuccendForm, bool isConvert = false) |
|
{ |
|
IFeatureCursor featureCursor = null; |
|
IFeature feature = null; |
|
try |
|
{ |
|
List<Kingo.RuleCheck.RuleEntity> lstResult = new List<Kingo.RuleCheck.RuleEntity>(); |
|
List<DataDicTionary> tempDic = GetAllDic(); |
|
//“地类编码”“种植属性代码”“图斑细化代码”“耕地类型”“扣除地类编码”中若涉及到小写的英文字母,在导入时直接转为相应大写英文字母 |
|
List<string> checkField = new List<string>() { "DLBM", "ZZSXDM", "TBXHDM", "GDLX", "KCDLBM", }; |
|
//判断值域 |
|
List<string> checkValueField = new List<string>() { "CZCSXM", "QSXZ", "GDPDJB", "GDDB", "DDTCDM" }; |
|
Dictionary<string, object> fieldsValues = new Dictionary<string, object>(); |
|
checkValueField.AddRange(checkField); |
|
|
|
string fields = "YSDM,TBYBH,TBBH,DLBM,DLMC,QSXZ,QSDWDM,QSDWMC,ZLDWDM,ZLDWMC,KCDLBM,KCXS,KCMJ,TBDLMJ,GDLX,GDPDJB,XZDWKD,TBXHDM,TBXHMC,ZZSXDM,ZZSXMC,GDDB,FRDBS,CZCSXM,SJNF,MSSM,HDMC,BZ,GXSJ,TBLX,DDTCBZ,DDTCMC,SFGX,WBGYY,SFJZ,QKSM,LJLX,DCJL,YWTBSM,SDMSSM,SFXML,XMLX,XMMC,XMBH,DKMC,LC,NF";//删除“JCBH” |
|
List<string> lstDBString = new List<string>(); |
|
foreach (var item in dicPath) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
IFeature wyrwFeature = null; |
|
IFeatureCursor wyrwCursor = null; |
|
try |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper($"{item.Value}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
if (!lstDBString.Contains(item.Value)) |
|
{ |
|
//Helper.DBLoadHelper.CheckTableExist(rdbHelper); |
|
lstDBString.Add(item.Value); |
|
} |
|
rdbHelper.BeginTransaction(); |
|
IQueryFilter queryFilter = new QueryFilterClass() |
|
{ |
|
WhereClause = $"TBBSM='{item.Key}'", |
|
}; |
|
wyrwCursor = wyrwFeatureClass.Search(queryFilter, true); |
|
int tbbsmIndex = wyrwFeatureClass.FindField("TBBSM"); |
|
while ((wyrwFeature = wyrwCursor.NextFeature()) != null) |
|
{ |
|
object tbbsm = wyrwFeature.get_Value(tbbsmIndex); |
|
if (tbbsm == null || tbbsm is DBNull) |
|
{ |
|
LogAPI.Debug($"ObjectID={wyrwFeature.OID}的外业任务图斑TBBSM为空,无法导入!"); |
|
continue; |
|
} |
|
if (isConvert) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException($"delete from dtbdltbgx where tbbsm ='{tbbsm}'", CommandType.Text); |
|
} |
|
ISpatialFilter spatialFilter = new SpatialFilterClass() |
|
{ |
|
Geometry = wyrwFeature.ShapeCopy, |
|
SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects, |
|
WhereClause = $"TBBSM='{tbbsm}'" |
|
}; |
|
string excuteSQL = "insert into dtbdltbgx(BSM, TBBSM, TBMJ, EGeometry, ZXDX, ZXDY, MAXX, MAXY, MINX, MINY, JKRY,{0})values({1})"; |
|
//string excuteSQL = "insert into dtbdltbgx(BSM, TBBSM, TBMJ, EGeometry, ZXDX, ZXDY, MAXX, MAXY, MINX, MINY, JKRY)values({0})"; |
|
featureCursor = featureClass.Search(spatialFilter, true); |
|
while ((feature = featureCursor.NextFeature()) != null) |
|
{ |
|
double jcmj = (feature.ShapeCopy as ESRI.ArcGIS.Geometry.IPolygon).GetEllipseArea(); |
|
ESRI.ArcGIS.Geometry.IArea area = feature.ShapeCopy as ESRI.ArcGIS.Geometry.IArea; |
|
if (area.Area < 50) |
|
{ |
|
message += feature.OID + ","; |
|
continue; |
|
} |
|
ESRI.ArcGIS.esriSystem.IClone clone = feature.ShapeCopy as ESRI.ArcGIS.esriSystem.IClone; |
|
IGeometry cloneGeometry = clone.Clone() as ESRI.ArcGIS.Geometry.IGeometry; |
|
string egeometry = DTBDBLoadHelper.ConverIGometryToJson(cloneGeometry); |
|
area = cloneGeometry as IArea; |
|
IEnvelope envelope = cloneGeometry.Envelope; |
|
string bsm = string.Empty; |
|
if (feature.get_Value(0) != null && !string.IsNullOrEmpty(feature.get_Value(0).ToString())) |
|
{ |
|
bsm = feature.get_Value(0).ToString(); |
|
DataTable dataTable = rdbHelper.ExecuteDatatable("tempDtbdltbgx", $"select bsm from dtbdltbgx where bsm ='{bsm}'", true); |
|
if (dataTable != null && dataTable.Rows.Count > 0) |
|
{ |
|
//LogAPI.Debug($"该任务包中已有此标识码{bsm}图斑,不允许导入!"); |
|
//MessageHelper.ShowTips($"该任务包中已有此标识码{bsm}图斑,不允许导入!"); |
|
//isShowSuccendForm = false; |
|
//if (rdbHelper != null) |
|
// rdbHelper.Rollback(); |
|
//return; |
|
|
|
bsm = Guid.NewGuid().ToString(); |
|
} |
|
} |
|
else |
|
{ |
|
bsm = Guid.NewGuid().ToString(); |
|
} |
|
|
|
string valueString = $"'{bsm}','{tbbsm}',{jcmj},'{egeometry}',{area.Centroid.X},{area.Centroid.Y},{envelope.XMax},{envelope.YMax},{envelope.XMin},{envelope.YMin},'{ProjectInfo.UserName}'"; |
|
fieldsValues = new Dictionary<string, object>(); |
|
foreach (var fieldName in fields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) |
|
{ |
|
int fieldIndex = featureClass.Fields.FindField(fieldName); |
|
if (fieldIndex <= -1) |
|
{ |
|
valueString += ",null"; |
|
continue; |
|
} |
|
IField field = feature.Fields.Field[fieldIndex]; |
|
object obj = feature.get_Value(fieldIndex); |
|
if (!(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString())) |
|
{ |
|
//部分字段小写字母转大写 |
|
if (checkField.Contains(fieldName)) |
|
{ |
|
obj = obj.ToString().ToUpper(); |
|
} |
|
//判断字典值是否在值域范围内 |
|
if (checkValueField.Contains(fieldName)) |
|
{ |
|
try |
|
{ |
|
string dicString = fieldName; |
|
switch (fieldName) |
|
{ |
|
case "KCDLBM": |
|
dicString = "DLBM"; |
|
break; |
|
case "ZZSXDM": |
|
dicString = "ZZSX"; |
|
break; |
|
case "TBXHDM": |
|
dicString = "TBXHLX"; |
|
break; |
|
case "CZCSXM": |
|
dicString = "CZCSX"; |
|
break; |
|
} |
|
DicTypeEnum dicType = (DicTypeEnum)System.Enum.Parse(typeof(DicTypeEnum), dicString); |
|
List<DataDicTionary> lstData = GetNoGroupDic(dicType, tempDic); |
|
if (lstData != null && lstData.FirstOrDefault(x => x.CODE.Equals(obj)) != null) |
|
{ |
|
switch (fieldName) |
|
{ |
|
case "DLBM": |
|
fieldsValues.Add("DLMC", lstData.FirstOrDefault(x => x.CODE.Equals(obj)).NAME); |
|
break; |
|
case "ZZSXDM": |
|
fieldsValues.Add("ZZSXMC", lstData.FirstOrDefault(x => x.CODE.Equals(obj)).NAME); |
|
break; |
|
case "TBXHDM": |
|
fieldsValues.Add("TBXHMC", lstData.FirstOrDefault(x => x.CODE.Equals(obj)).NAME); |
|
break; |
|
case "DDTCBZ": |
|
fieldsValues.Add("DDTCMC", lstData.FirstOrDefault(x => x.CODE.Equals(obj)).NAME); |
|
break; |
|
} |
|
} |
|
else |
|
{ |
|
obj = null; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(fieldName + "判断是否在值域范围内异常:" + ex.Message); |
|
} |
|
} |
|
} |
|
if (fieldsValues.Keys.Contains(fieldName)) |
|
{ |
|
valueString += ",'" + fieldsValues.FirstOrDefault(X => X.Key.Equals(fieldName)).Value + "'"; |
|
continue; |
|
} |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
case esriFieldType.esriFieldTypeInteger: |
|
case esriFieldType.esriFieldTypeSingle: |
|
if (obj is DBNull || obj == null || string.IsNullOrWhiteSpace(obj.ToString())) |
|
{ |
|
valueString += ",0"; |
|
} |
|
else |
|
{ |
|
valueString += "," + int.Parse(obj.ToString()); |
|
} |
|
break; |
|
case esriFieldType.esriFieldTypeDouble: |
|
if (obj is DBNull || obj == null || string.IsNullOrWhiteSpace(obj.ToString())) |
|
{ |
|
valueString += ",0"; |
|
} |
|
else |
|
{ |
|
valueString += "," + double.Parse(obj.ToString()); |
|
} |
|
break; |
|
default: |
|
if (obj is DBNull || obj == null || string.IsNullOrWhiteSpace(obj.ToString())) |
|
{ |
|
valueString += ",null"; |
|
} |
|
else |
|
{ |
|
valueString += ",'" + obj.ToString().Trim() + "'"; |
|
} |
|
break; |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, fields, valueString), CommandType.Text); |
|
//rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, valueString), CommandType.Text); |
|
//保存更新过程数据 |
|
importCount++; |
|
} |
|
rdbHelper.Commit(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (rdbHelper != null) |
|
rdbHelper.Rollback(); |
|
if (rdbHelper != null) |
|
rdbHelper.DisConnect(); |
|
LogAPI.Debug(ex.ToString()); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (wyrwFeature != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(wyrwFeature); |
|
} |
|
if (wyrwCursor != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(wyrwCursor); |
|
} |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.ToString()); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (feature != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); |
|
} |
|
} |
|
} |
|
|
|
#region 获取工程下的字典 |
|
private List<DataDicTionary> GetAllDic() |
|
{ |
|
DataTable dt = null; |
|
List<DataDicTionary> result = new List<DataDicTionary>(); |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null) |
|
{ |
|
string dbPath = ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).GetDicDataPath(); |
|
if (!string.IsNullOrWhiteSpace(dbPath)) |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite); |
|
string strSQL = "select * from Sys_DicDetail"; |
|
dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true); |
|
if (dt != null) |
|
{ |
|
result = KGIS.Framework.Utils.Utility.TBToList.ToList<DataDicTionary>(dt).OrderBy(x => x.CODE).ToList(); |
|
result.ForEach(x => x.DisplayName = x.CODE + "-" + x.NAME); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
if (dt != null) |
|
{ |
|
dt.Clear(); |
|
dt.Dispose(); |
|
} |
|
} |
|
return result; |
|
} |
|
private List<DataDicTionary> GetNoGroupDic(DicTypeEnum pDicType, List<DataDicTionary> dicList = null) |
|
{ |
|
List<DataDicTionary> result = null; |
|
try |
|
{ |
|
string s = GetDicTypeID(pDicType); |
|
if (string.IsNullOrWhiteSpace(s)) |
|
return result; |
|
List<DataDicTionary> tempDic = dicList; |
|
if (dicList == null || dicList.Count == 0) |
|
tempDic = GetAllDic(); |
|
if (tempDic == null) |
|
return result; |
|
foreach (DataDicTionary item in tempDic) |
|
{ |
|
if (item.OWNERDIC == s) |
|
{ |
|
if (result == null) |
|
{ |
|
result = new List<DataDicTionary>(); |
|
result.Add(new DataDicTionary() { CODE = "", NAME = "", DisplayName = "" }); |
|
} |
|
result.Add(item); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
return result; |
|
} |
|
private Dictionary<string, string> DicTypes = new Dictionary<string, string>(); |
|
public string GetDicTypeID(DicTypeEnum pDicType, bool GetNewDic = false) |
|
{ |
|
string result = string.Empty; |
|
DataTable dtDicTypeID = null; |
|
try |
|
{ |
|
if (dtDicTypeID == null || GetNewDic) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
string dbPath = ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).GetDicDataPath(); |
|
if (string.IsNullOrWhiteSpace(dbPath)) |
|
{ |
|
LogAPI.Debug("GetDicDataPath 获取失败"); |
|
} |
|
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite); |
|
string strSQL = "select ID,ALIASNAME from Sys_DicManage ";//WHERE ALIASNAME = '" + pDicType + "'"; |
|
dtDicTypeID = rdbHelper.ExecuteDatatable("DicType", strSQL, true); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
if (dtDicTypeID != null && dtDicTypeID.Rows.Count > 0) |
|
{ |
|
foreach (DataRow item in dtDicTypeID.Rows) |
|
{ |
|
if (item[0] != null && !(item[0] is DBNull)) |
|
{ |
|
if (item[1].ToString() == pDicType.ToString()) |
|
result = item[0].ToString(); |
|
if (DicTypes.ContainsKey(item[0].ToString())) |
|
continue; |
|
DicTypes.Add(item[0].ToString(), item[1].ToString()); |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (dtDicTypeID != null) |
|
{ |
|
dtDicTypeID.Clear(); |
|
dtDicTypeID.Dispose(); |
|
} |
|
} |
|
return string.Empty; |
|
} |
|
#endregion |
|
|
|
/// <summary> |
|
/// 变更检查 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnCheck_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开工程!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择需要导出的数据!"); |
|
return; |
|
} |
|
List<ExportEntity> listExport = new List<ExportEntity>(); |
|
foreach (ExportEntity item in this.gridPackage.SelectedItems) |
|
{ |
|
if (listExport.FirstOrDefault(x => x.TBBSM.Equals(item.TBBSM)) != null) |
|
{ |
|
MessageHelper.Show(item.TBBSM + "存在多个,单次输出只能选择单个" + item.TBBSM + "任务图斑!"); |
|
return; |
|
} |
|
listExport.Add(item); |
|
} |
|
if (listExport.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("请选择需要质检的外业任务图斑!"); |
|
return; |
|
} |
|
this.ShowLoading($"正在进行变更检查【0/{listExport.Count}】......", 0, 0); |
|
List<RuleCheck.RuleEntity> lstResult = new List<RuleCheck.RuleEntity>(); |
|
int i = 1; |
|
foreach (var item in listExport) |
|
{ |
|
this.UpdateMsg($"正在进行变更检查【{i++}/{listExport.Count}】......"); |
|
List<RuleCheck.RuleEntity> results = DTBDBLoadHelper.DTBCheckPackage(item.TBBSM, item.PackagePath); |
|
lstResult.AddRange(results); |
|
} |
|
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = lstResult, MsgType = "LoadCheckTBView" }); |
|
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = lstResult, MsgType = "RefreshTreeNodeState" }); |
|
this.CloseLoading(); |
|
MessageHelper.Show("检查完成,共发现" + (lstResult == null ? 0 : lstResult.Count) + "个错误!"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowError("质检异常:" + ex.Message); |
|
MessageHelper.ShowError("质检异常:" + ex.StackTrace); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
} |
|
} |
|
|
|
} |
|
}
|
|
|