using Dapper;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.ProofManager.Common;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Windows;
using KUI.Windows;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Collections;
using GeometryConvertHelper = Kingo.Plugin.ProofManager.Common.GeometryConvertHelper;
namespace Kingo.Plugin.ProofManager.View
{
///
/// UCDBCheckSetting.xaml 的交互逻辑
///
public partial class EvidentiaryResults : BaseWindow
{
ProjectInfo prj = null;
List loadFiles = null;
List exportInfos = null;
List exportInfos_DEL = null;
string hcdbPath { get; set; }
string targetPath { get; set; }
string xzqdm { get; set; }
string xzqmc { get; set; }
string TCBM = "BGDC2020";
public EvidentiaryResults()
{
InitializeComponent();
prj = (ProjectInfo)MapsManager.Instance.CurrProjectInfo;
if (prj != null)
{
string dbPath = $"{(MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjDir}\\BGTJ.sqlite";
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
var dataTable = rdbHelper.ExecuteDatatable("tab", @" select filename DBNAME,ParengFolder||'\'||filename DbPath from DBFILEINFO ", true);
exportInfos = KGIS.Framework.Utils.Utility.TBToList.ToList(dataTable);
exportInfos_DEL = new List();
if (exportInfos != null && exportInfos.Count > 0)
{
foreach (var item in exportInfos)
{
dataTable = rdbHelper.ExecuteDatatable("tab", $" select TBBH,DbPath DBNAME,'' BZ,'' ZT from hcdb_relation where DbPath='{item.DBpath}' ", true);
item.ExportInfo_details = KGIS.Framework.Utils.Utility.TBToList.ToList(dataTable);
}
}
this.dgFileData.ItemsSource = exportInfos;
dataTable = rdbHelper.ExecuteDatatable("tab", " select * from DBFILEINFO ", true);
loadFiles = KGIS.Framework.Utils.Utility.TBToList.ToList(dataTable);
this.lbDbList.ItemsSource = loadFiles;
this.lbDbList.SelectionChanged += LbDbList_SelectionChanged;
}
}
private void BtnOK_Click(object sender, RoutedEventArgs e)
{
SQLiteConnection sqlConnection = null;
SQLiteTransaction pTran = null;
SQLiteCommand cmd = null;
try
{
if (string.IsNullOrEmpty(txtExcelPath.Text))
{
MessageHelper.Show("请选择举证成果保存路径.");
return;
}
if (loadFiles.Where(x => x.IsChecked).ToList().Count == 0)
{
MessageHelper.Show("请选择要导出的举证成果.");
return;
}
this.ShowLoading("正在进行成果导出...", 0, 0);
xzqdm = prj.CODE;
List Getxzqmc = new List(prj.ProjDir.Split('\\'));
xzqmc = Getxzqmc.Where(x => x.Contains(xzqdm)).FirstOrDefault().Replace(xzqdm, "").Replace(")", "").Replace("(", "");
string currentAppPath = SysAppPath.GetCurrentAppPath();
string resultPath = txtExcelPath.Text;
if (!Directory.Exists(resultPath))
{
Directory.CreateDirectory(resultPath);
}
string templeteDBPath = System.IO.Path.Combine(currentAppPath, "Template", "HCCGResult.db");
string resultDBPath = System.IO.Path.Combine(resultPath, $"({prj.CODE}).db");
File.Copy(templeteDBPath, resultDBPath, true);
sqlConnection = new SQLiteConnection(@"Data Source=" + resultDBPath);
sqlConnection.Open();
string sload = string.Format("SELECT load_extension('{0}stgeometry_sqlite.dll','SDE_SQL_funcs_init')", AppDomain.CurrentDomain.BaseDirectory);
pTran = sqlConnection.BeginTransaction();
cmd = new SQLiteCommand(sload, sqlConnection);
//foreach (var db in loadFiles)
//{
// if (!db.IsChecked)
// continue;
// hcdbPath = $"{db.ParengFolder}\\{db.FileName}";
// DataTable dtRecord = SQLiteDBOperate.Instance.ExceDataTable(hcdbPath, "select * from SURVEY_RECORD");//查询调绘成果表
// if (dtRecord != null && dtRecord.Rows.Count != 0)
// {
// int count = 0;
// ProcessTbybh(dtRecord, cmd, tableName);//转换图形数据
// InsertFJ(cmd, null, count);
// }
//}
#region 仅导出与变更图斑关联的数据
string dbPath = $"{(MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjDir}\\BGTJ.sqlite";
IRDBHelper rdbHelper1 = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
List tabNameList = new List() { "DB_INFO", "DCHSXX", "FJ", "JMXX", "KZXXYSJ", "TBJBXX" };
string sql = string.Empty;
foreach (var tabName in tabNameList)
{
DataTable Mergedt = null;
DataTable dt = null;
switch (tabName)
{
#region DB_INFO
case "DB_INFO":
//INSERT INTO DB_INFO(version, createtime, updatetime, createuser, description) VALUES ();
sql = $@"INSERT INTO DB_INFO(version, createtime) VALUES ('1.0', '{DateTime.Now}');";
int r = cmd.Connection.Execute(sql);
break;
#endregion
#region DCHSXX
case "DCHSXX":
//INSERT INTO DCHSXX(TBBSM, WYHSQK, SDDLDM, KZXX, DCRY, DCSJ) VALUES ();
foreach (var item in loadFiles)
{
if (!item.IsChecked) continue;
string connectionString = $"{item.ParengFolder}\\{item.FileName}";
dt = SQLiteDBOperate.Instance.ExceDataTable(connectionString, $"select TBBSM,WYHSQK,SDDLDM,KZXX,DCRY,DCSJ from DCHSXX ");
if (dt != null && dt.Rows.Count > 0)
{
if (Mergedt == null)
Mergedt = dt.Clone();
Mergedt.Merge(dt);
}
}
if (Mergedt != null && Mergedt.Rows.Count > 0)
{
DataTable DistTable = GetDistinctSelf(Mergedt, "TBBSM", "DCSJ");
foreach (DataRow row in DistTable.Rows)
{
sql = $@"INSERT INTO DCHSXX(TBBSM, WYHSQK, SDDLDM, KZXX, DCRY, DCSJ) VALUES
('{row["TBBSM"].ToString()}',
'{row["WYHSQK"].ToString()}',
'{row["SDDLDM"].ToString()}',
'{row["KZXX"].ToString()}',
'{row["DCRY"].ToString()}',
'{row["DCSJ"].ToString()}');";
cmd.Connection.Execute(sql);
}
}
break;
#endregion
#region FJ
case "FJ":
string sqlFJ = "Insert into FJ (TBLX, TBBSM, XZQDM, FJMC, FJLX, PSTZ, FJ, FJHXZ, PSSJ, XDGD, JDGD, Longitude, Latitude, PSFYJ, PSJD, PSHGJ, PSJJ, FJYSKD, FJYSGD, PSRY, SPKZXX, ZSDM, QKLDM, JYM) values (@TBLX, @TBBSM, @XZQDM, @FJMC, @FJLX, @PSTZ, @FJ, @FJHXZ, @PSSJ, @XDGD, @JDGD, @Longitude, @Latitude, @PSFYJ, @PSJD, @PSHGJ, @PSJJ, @FJYSKD, @FJYSGD, @PSRY, @SPKZXX, @ZSDM, @QKLDM, @JYM)";
foreach (var item in loadFiles)
{
if (!item.IsChecked) continue;
string connectionString = $"{item.ParengFolder}\\{item.FileName}";
IRDBHelper rdbHelper11 = RDBFactory.CreateDbHelper("Data Source=" + connectionString, DatabaseType.SQLite);
var dbDtCount = rdbHelper11.ExecuteDatatable("count", "select count(0) from FJ Where isSelected=1", true).Rows[0][0].ToDouble();
var pagecount = 1.00;
if (dbDtCount > 1000)
{
pagecount = Math.Ceiling(dbDtCount / 1000);
}
var offset = 0;
for (int j = 0; j < pagecount; j++)
{
var limit = 1000;
dt = rdbHelper11.ExecuteDatatable("tab", $"select TBLX, TBBSM, XZQDM, FJMC, FJLX, PSTZ, FJ, FJHXZ, PSSJ, XDGD, JDGD, Longitude, Latitude, PSFYJ, PSJD, PSHGJ, PSJJ, FJYSKD, FJYSGD, PSRY, SPKZXX, ZSDM, QKLDM, JYM from FJ Where isSelected=1 limit { limit } offset { offset } ;", true);
foreach (DataRow row in dt.Rows)
{
cmd.Connection.Execute(sqlFJ, new
{
TBLX = row["TBLX"],
TBBSM = row["TBBSM"],
XZQDM = row["XZQDM"],
FJMC = row["FJMC"],
FJLX = row["FJLX"],
PSTZ = row["PSTZ"],
FJ = row["FJ"],
FJHXZ = row["FJHXZ"],
PSSJ = row["PSSJ"],
XDGD = row["XDGD"],
JDGD = row["JDGD"],
Longitude = row["Longitude"],
Latitude = row["Latitude"],
PSFYJ = row["PSFYJ"],
PSJD = row["PSJD"],
PSHGJ = row["PSHGJ"],
PSJJ = row["PSJJ"],
FJYSKD = row["FJYSKD"],
FJYSGD = row["FJYSGD"],
PSRY = row["PSRY"],
SPKZXX = row["SPKZXX"],
ZSDM = row["ZSDM"],
QKLDM = row["QKLDM"],
JYM = row["JYM"]
});
}
dt.Clear();
dt = null;
offset = limit + offset;
}
}
//dt = SQLiteDBOperate.Instance.ExceDataTable(connectionString, $"select TBLX, TBBSM, XZQDM, FJMC, FJLX, PSTZ, FJ, FJHXZ, PSSJ, XDGD, JDGD, Longitude, Latitude, PSFYJ, PSJD, PSHGJ, PSJJ, FJYSKD, FJYSGD, PSRY, SPKZXX, ZSDM, QKLDM, JYM from FJ Where isSelected=1 ");
//if (dt != null && dt.Rows.Count > 0)
//{
// if (Mergedt == null)
// Mergedt = dt.Clone();
// Mergedt.Merge(dt);
//}
//}
//if (Mergedt != null && Mergedt.Rows.Count > 0)
//{
// DataView dv = new DataView(Mergedt);
// DataTable DistTable = dv.ToTable(true, new string[] { "TBLX", "TBBSM", "XZQDM", "FJMC", "FJLX", "PSTZ", "FJ", "FJHXZ", "PSSJ", "XDGD", "JDGD", "Longitude", "Latitude", "PSFYJ", "PSJD", "PSHGJ", "PSJJ", "FJYSKD", "FJYSGD", "PSRY", "SPKZXX", "ZSDM", "QKLDM", "JYM" });
// foreach (DataRow row in DistTable.Rows)
// {
// string sqlFJ = "Insert into FJ (TBLX, TBBSM, XZQDM, FJMC, FJLX, PSTZ, FJ, FJHXZ, PSSJ, XDGD, JDGD, Longitude, Latitude, PSFYJ, PSJD, PSHGJ, PSJJ, FJYSKD, FJYSGD, PSRY, SPKZXX, ZSDM, QKLDM, JYM) values (@TBLX, @TBBSM, @XZQDM, @FJMC, @FJLX, @PSTZ, @FJ, @FJHXZ, @PSSJ, @XDGD, @JDGD, @Longitude, @Latitude, @PSFYJ, @PSJD, @PSHGJ, @PSJJ, @FJYSKD, @FJYSGD, @PSRY, @SPKZXX, @ZSDM, @QKLDM, @JYM)";
// cmd.Connection.Execute(sqlFJ, new
// {
// TBLX = row["TBLX"],
// TBBSM = row["TBBSM"],
// XZQDM = row["XZQDM"],
// FJMC = row["FJMC"],
// FJLX = row["FJLX"],
// PSTZ = row["PSTZ"],
// FJ = row["FJ"],
// FJHXZ = row["FJHXZ"],
// PSSJ = row["PSSJ"],
// XDGD = row["XDGD"],
// JDGD = row["JDGD"],
// Longitude = row["Longitude"],
// Latitude = row["Latitude"],
// PSFYJ = row["PSFYJ"],
// PSJD = row["PSJD"],
// PSHGJ = row["PSHGJ"],
// PSJJ = row["PSJJ"],
// FJYSKD = row["FJYSKD"],
// FJYSGD = row["FJYSGD"],
// PSRY = row["PSRY"],
// SPKZXX = row["SPKZXX"],
// ZSDM = row["ZSDM"],
// QKLDM = row["QKLDM"],
// JYM = row["JYM"]
// });
// }
//}
break;
#endregion
#region JMXX
case "JMXX":
//INSERT INTO JMXX(ZSDM, SZZS, ZSBFJGDM, ZSBFJGGY, QKLFWDZ) VALUES ();
foreach (var item in loadFiles)
{
if (!item.IsChecked) continue;
string connectionString = $"{item.ParengFolder}\\{item.FileName}";
dt = SQLiteDBOperate.Instance.ExceDataTable(connectionString, $"select ZSDM, SZZS, ZSBFJGDM, ZSBFJGGY, QKLFWDZ from JMXX ");
if (dt != null && dt.Rows.Count > 0)
{
if (Mergedt == null)
Mergedt = dt.Clone();
Mergedt.Merge(dt);
}
}
if (Mergedt != null && Mergedt.Rows.Count > 0)
{
DataTable DistTable = GetDistinctSelf(Mergedt, "ZSDM", "ZSDM");
foreach (DataRow row in DistTable.Rows)
{
sql = $@"INSERT INTO JMXX(ZSDM, SZZS, ZSBFJGDM, ZSBFJGGY, QKLFWDZ) VALUES
('{row["ZSDM"].ToString()}',
'{row["SZZS"].ToString()}',
'{row["ZSBFJGDM"].ToString()}',
'{row["ZSBFJGGY"].ToString()}',
'{row["QKLFWDZ"].ToString()}');";
cmd.Connection.Execute(sql);
}
}
break;
#endregion
#region KZXXYSJ
case "KZXXYSJ":
//INSERT INTO KZXXYSJ(BSM, TBLX, ZDMC, ZDBM, ZDMS, ZDLX, ZDCD, SFBT, SJZD, KZXXLX) VALUES ();
foreach (var item in loadFiles)
{
if (!item.IsChecked) continue;
string connectionString = $"{item.ParengFolder}\\{item.FileName}";
dt = SQLiteDBOperate.Instance.ExceDataTable(connectionString, $"select TBLX, ZDMC, ZDBM, ZDMS, ZDLX, ZDCD, SFBT, SJZD, KZXXLX from KZXXYSJ ");
if (dt != null && dt.Rows.Count > 0)
{
if (Mergedt == null)
Mergedt = dt.Clone();
Mergedt.Merge(dt);
}
}
if (Mergedt != null && Mergedt.Rows.Count > 0)
{
//DataTable DistTable = GetDistinctSelf(Mergedt, "ZDMC", "TBLX");
foreach (DataRow row in Mergedt.Rows)
{
sql = $@"INSERT INTO KZXXYSJ(TBLX, ZDMC, ZDBM, ZDMS, ZDLX, ZDCD, SFBT, SJZD, KZXXLX) VALUES
('{row["TBLX"].ToString()}',
'{row["ZDMC"].ToString()}',
'{row["ZDBM"].ToString()}',
'{row["ZDMS"].ToString()}',
'{row["ZDLX"].ToString()}',
'{row["ZDCD"].ToString()}',
'{row["SFBT"].ToString()}',
'{row["SJZD"].ToString()}',
'{row["KZXXLX"].ToString()}');";
cmd.Connection.Execute(sql);
}
}
break;
#endregion
#region TBJBXX
case "TBJBXX":
//INSERT INTO TBJBXX(BSM, TBLX, XZQDM, XMC, TBBH, TBMC, TBMJ, XZB, YZB, BZ, KZXX, TBFW) VALUES();
foreach (var item in loadFiles)
{
if (!item.IsChecked) continue;
string connectionString = $"{item.ParengFolder}\\{item.FileName}";
dt = SQLiteDBOperate.Instance.ExceDataTable(connectionString, $"select BSM, TBLX, XZQDM, XMC, TBBH, TBMC, TBMJ, XZB, YZB, BZ, KZXX, TBFW from TBJBXX ");
if (dt != null && dt.Rows.Count > 0)
{
if (Mergedt == null)
Mergedt = dt.Clone();
Mergedt.Merge(dt);
}
}
if (Mergedt != null && Mergedt.Rows.Count > 0)
{
DataTable DistTable = GetDistinctSelf(Mergedt, "BSM", "BSM");
foreach (DataRow row in DistTable.Rows)
{
sql = $@"INSERT INTO TBJBXX(BSM, TBLX, XZQDM, XMC, TBBH, TBMC, TBMJ, XZB, YZB, BZ, KZXX, TBFW) VALUES
('{row["BSM"].ToString()}',
'{row["TBLX"].ToString()}',
'{row["XZQDM"].ToString()}',
'{row["XMC"].ToString()}',
'{row["TBBH"].ToString()}',
'{row["TBMC"].ToString()}',
{row["TBMJ"].ToString()},
{row["XZB"].ToString()},
{row["YZB"].ToString()},
'{row["BZ"].ToString()}',
'{row["KZXX"].ToString()}',
'{row["TBFW"].ToString()}');";
cmd.Connection.Execute(sql);
}
}
break;
#endregion
}
}
//InsertBGDC(cmd);
#endregion
if (ISChangeResults.IsChecked == true)
{
IFeatureClass DLTBBG = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");
if (DLTBBG != null)
{
IFeature feature = null;
IFeatureCursor featureCursor = null;
featureCursor = DLTBBG.Search(null, true);
List listSQL = new List();
string insertsql = "INSERT INTO DLTBBG(OBJECTID, SHAPE, BSM, YSDM, TBYBH, TBBH, DLBM, DLMC, QSXZ, QSDWDM, QSDWMC, ZLDWDM, ZLDWMC, TBMJ, KCDLBM, KCXS, KCMJ, TBDLMJ, GDLX, GDPDJB, XZDWKD, TBXHDM, TBXHMC, ZZSXDM, ZZSXMC, GDDB, FRDBS, CZCSXM, MSSM, HDMC, BZ, SHAPE_Length, SHAPE_Area) VALUES ({0});";
#region Createsql
string Createsql = @"CREATE TABLE If not EXISTS DLTBBG
(
OBJECTID integer NOT NULL PRIMARY KEY AUTOINCREMENT,
SHAPE text,
BSM text(18),
YSDM text(10),
TBYBH text(500),
TBBH text(8),
DLBM text(5),
DLMC text(60),
QSXZ text(2),
QSDWDM text(19),
QSDWMC text(60),
ZLDWDM text(19),
ZLDWMC text(60),
TBMJ float64,
KCDLBM text(5),
KCXS float64,
KCMJ float64,
TBDLMJ float64,
GDLX text(2),
GDPDJB text(2),
XZDWKD float64,
TBXHDM text(6),
TBXHMC text(20),
ZZSXDM text(6),
ZZSXMC text(20),
GDDB int16,
FRDBS text(1),
CZCSXM text(4),
MSSM text(2),
HDMC text(100),
BZ text(255),
SHAPE_Length float64,
SHAPE_Area float64
); ";
#endregion
listSQL.Add(Createsql);
#region MyRegion
Dictionary keyValuePairs = new Dictionary();
keyValuePairs.Add("OBJECTID", "");
keyValuePairs.Add("SHAPE", "");
keyValuePairs.Add("BSM", "");
keyValuePairs.Add("YSDM", "");
keyValuePairs.Add("TBYBH", "");
keyValuePairs.Add("TBBH", "");
keyValuePairs.Add("DLBM", "");
keyValuePairs.Add("DLMC", "");
keyValuePairs.Add("QSXZ", "");
keyValuePairs.Add("QSDWDM", "");
keyValuePairs.Add("QSDWMC", "");
keyValuePairs.Add("ZLDWDM", "");
keyValuePairs.Add("ZLDWMC", "");
keyValuePairs.Add("TBMJ", "");
keyValuePairs.Add("KCDLBM", "");
keyValuePairs.Add("KCXS", "");
keyValuePairs.Add("KCMJ", "");
keyValuePairs.Add("TBDLMJ", "");
keyValuePairs.Add("GDLX", "");
keyValuePairs.Add("GDPDJB", "");
keyValuePairs.Add("XZDWKD", "");
keyValuePairs.Add("TBXHDM", "");
keyValuePairs.Add("TBXHMC", "");
keyValuePairs.Add("ZZSXDM", "");
keyValuePairs.Add("ZZSXMC", "");
keyValuePairs.Add("GDDB", "");
keyValuePairs.Add("FRDBS", "");
keyValuePairs.Add("CZCSXM", "");
keyValuePairs.Add("MSSM", "");
keyValuePairs.Add("HDMC", "");
keyValuePairs.Add("BZ", "");
keyValuePairs.Add("SHAPE_Length", "");
keyValuePairs.Add("SHAPE_Area", "");
#endregion
var rowcount = DLTBBG.FeatureCount(null);
var num = 0;
while ((feature = featureCursor.NextFeature()) != null)
{
num++;
if (num % 100 == 0 || num == rowcount)
this.UpdateMsg($"变更成果数据导出...【{num}/{rowcount}】");
for (int i = 0; i < DLTBBG.Fields.FieldCount; i++)
{
IField field = feature.Fields.get_Field(i);
if (!keyValuePairs.ContainsKey(field.Name))
continue;
if (field.Name == "SHAPE")
{
keyValuePairs["SHAPE"] = GeometryConvertHelper.ConvertIGeoemtryToWKT(feature.ShapeCopy);
}
else
{
keyValuePairs[field.Name] = feature.Value[i].ToString();
}
}
listSQL.Add(string.Format(insertsql, string.Join(",", keyValuePairs.Values.Select(x => $"'{x}'"))));
if (listSQL.Count == 10000)
{
foreach (var item in listSQL)
{
cmd.CommandText = item;
int r = cmd.ExecuteNonQuery();
}
listSQL.Clear();
}
}
foreach (var item in listSQL)
{
cmd.CommandText = item;
int r = cmd.ExecuteNonQuery();
}
}
}
this.CloseLoading();
MessageHelper.ShowTips("导出完成!");
this.Close();
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug(ex);
MessageHelper.Show(ex.Message);
}
finally
{
this.CloseLoading();
if (pTran != null)
{
try
{
pTran.Commit();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
if (sqlConnection != null)
{
if (cmd != null)
cmd.Dispose();
sqlConnection.Close();
sqlConnection.Dispose();
SQLiteConnection.ClearPool(sqlConnection);
}
}
}
public DataTable GetDistinctSelf(DataTable SourceDt, string filedName, string OrderByName)
{
for (int i = SourceDt.Rows.Count - 2; i >= 0; i--)
{
DataRow[] rows = SourceDt.Select($"{filedName}='{SourceDt.Rows[i][filedName]}'");
if (rows.Length > 1)
{
List rows1 = rows.OrderByDescending(x => x[OrderByName]).ToList();
for (int j = 0; j < rows1.Count; j++)
{
if (j == 0) continue;
SourceDt.Rows.Remove(rows1[j]);
}
}
}
return SourceDt;
}
private void DCTable(SQLiteCommand cmd, DataTable dtSource, string TableName, string[] ColumnNames)
{
string sql = string.Empty;
try
{
if (dtSource != null)
{
switch (TableName)
{
case "DB_INFO":
sql = $@"INSERT INTO DB_INFO(version, createtime) VALUES ('1.0', '{DateTime.Now}');";
int r = cmd.Connection.Execute(sql);
break;
case "DCHSXX":
foreach (DataRow drFJ in dtSource.Rows)
{
string values = string.Empty;
foreach (var colnum in ColumnNames)
{
values += $"'{drFJ[$"{colnum}"]}',";
}
sql = $@"INSERT INTO DCHSXX(TBBSM, WYHSQK, SDDLDM, KZXX, DCRY, DCSJ) VALUES ({values});";
cmd.Connection.Execute(sql);
}
break;
default:
break;
}
//foreach (DataRow drFJ in dtSource.Rows)
//{
// string values = string.Empty;
// foreach (var colnum in ColumnNames)
// {
// if (colnum == "BSM")
// {
// values += $"{drFJ[$"{colnum}"]},";
// }
// else
// {
// values += $"'{drFJ[$"{colnum}"]}',";
// }
// }
// string sql = $@"Insert into {TableName } ({string.Join(",", ColumnNames)}) values ({values.Substring(0, values.Length - 1)})";
// int r = cmd.Connection.Execute(sql);
//}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private void DCFJ(SQLiteCommand cmd, DataTable dtFj)
{
try
{
string sqlFJ = "Insert into FJ (TBLX, TBBSM, XZQDM, FJMC, FJLX, PSTZ, FJ, FJHXZ, PSSJ, XDGD, JDGD, Longitude, Latitude, PSFYJ, PSJD, PSHGJ, PSJJ, FJYSKD, FJYSGD, PSRY, SPKZXX, ZSDM, QKLDM, JYM) values (@TBLX, @TBBSM, @XZQDM, @FJMC, @FJLX, @PSTZ, @FJ, @FJHXZ, @PSSJ, @XDGD, @JDGD, @Longitude, @Latitude, @PSFYJ, @PSJD, @PSHGJ, @PSJJ, @FJYSKD, @FJYSGD, @PSRY, @SPKZXX, @ZSDM, @QKLDM, @JYM)";
if (dtFj != null)
{
foreach (DataRow drFJ in dtFj.Rows)
{
int r = cmd.Connection.Execute(sqlFJ, new
{
TBLX = drFJ["TBLX"],
TBBSM = drFJ["TBBSM"],
XZQDM = drFJ["XZQDM"],
FJMC = drFJ["FJMC"],
FJLX = drFJ["FJLX"],
PSTZ = drFJ["PSTZ"],
FJ = drFJ["FJ"],
FJHXZ = drFJ["FJHXZ"],
PSSJ = drFJ["PSSJ"],
XDGD = drFJ["XDGD"],
JDGD = drFJ["JDGD"],
Longitude = drFJ["Longitude"],
Latitude = drFJ["Latitude"],
PSFYJ = drFJ["PSFYJ"],
PSJD = drFJ["PSJD"],
PSHGJ = drFJ["PSHGJ"],
PSJJ = drFJ["PSJJ"],
FJYSKD = drFJ["FJYSKD"],
FJYSGD = drFJ["FJYSGD"],
PSRY = drFJ["PSRY"],
SPKZXX = drFJ["SPKZXX"],
ZSDM = drFJ["ZSDM"],
QKLDM = drFJ["QKLDM"],
JYM = drFJ["JYM"]
});
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private void InsertBGDC(SQLiteCommand cmd)
{
IFeatureCursor Cursor = null;
IFeature feature = null;
try
{
string sqlInsertTysdjz = @"Insert into " + TCBM +
"(JCBH,TBLX,XZQDM,XMC,JCMJ,HSX,XZB,YZB,TZ,BGDL,BGFW,WBGLX,BZ,TBFW,SJLY) " +
"values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')";
IFeatureClass JCTB = MapsManager.Instance.MapService.GetFeatureClassByName("JCTB");
Cursor = JCTB.Search(null, true);
string JCBH = "";
string TBLX = "";
string XZQDM = "";
string XMC = "";
double JCMJ = 0.00;
string HSX = "";
double XZB = 0.00;
double YZB = 0.00;
string TZ = "";
string BGDL = "";
string BGFW = "";
string WBGLX = "";
string BZ = "";
string TBFW = "";
string SJLY = "";
while ((feature = Cursor.NextFeature()) != null)
{
for (int i = 0; i < feature.Fields.FieldCount; i++)
{
if (feature.Fields.Field[i].Name == "JCBH")
JCBH = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "TBLX")
TBLX = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "XZQDM")
XZQDM = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "XMC")
XMC = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "JCMJ")
{
if (!string.IsNullOrEmpty(feature.Value[i].ToString()))
JCMJ = feature.Value[i].ToString().ToDouble();
}
if (feature.Fields.Field[i].Name == "HSX")
HSX = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "XZB")
{
if (!string.IsNullOrEmpty(feature.Value[i].ToString()))
XZB = feature.Value[i].ToString().ToDouble();
}
if (feature.Fields.Field[i].Name == "YZB")
{
if (!string.IsNullOrEmpty(feature.Value[i].ToString()))
YZB = feature.Value[i].ToString().ToDouble();
}
if (feature.Fields.Field[i].Name == "TZ")
TZ = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "BGDL")
BGDL = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "BGFW")
BGFW = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "WBGLX")
WBGLX = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "BZ")
BZ = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "TBFW")
TBFW = feature.Value[i].ToString();
if (feature.Fields.Field[i].Name == "SJLY")
SJLY = feature.Value[i].ToString();
}
string wkt = GeometryConvertHelper.ConvertIGeoemtryToWKT(feature.Shape);
cmd.CommandText = string.Format(sqlInsertTysdjz, JCBH, TBLX, xzqdm, xzqmc, Math.Round(JCMJ, 2), HSX, Math.Round(XZB, 3), Math.Round(YZB, 3), TZ, BGDL, GetBGFW(BGFW), WBGLX, BZ, wkt, SJLY);
int r = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void InsertFJ_DB(SQLiteCommand cmd, DataTable TBYBH, int count, string Path)
{
try
{
var tempPrj = new ProjectInfo();
DataTable dtFJ = new DataTable();
using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Path))
{
var rowcount = TBYBH.Rows.Count;
var num = 0;
//List listSQL = new List();
//string sqlFJ = "Insert into FJ (F_ID,TCBM,TBYBH,XZQDM,JKBSM,FJMC,FJLX,FJ,PSSJ,PSJD,PSRY,Longitude,Latitude,XZB,YZB,JYM,LYSB,TAKEOFFLON,TAKEOFFLAT,TAKEOFFRELHEIGHT,TAKEOFFALTITUDE,PSGD,PSFYJ,PSALTITUDE) values ({0})";
foreach (DataRow item in TBYBH.Rows)
{
num++;
//if (num % 100 == 0 || num == rowcount)
this.UpdateMsg($"附件导出...【{num}/{rowcount}】");
byte[] jcbh = tempPrj.AesEncrypt(item["TBBH"].ToString().Replace("'", "").ToTrim(), "58ef12f9891a4cd89fa7bdd181ef13a7");
var reader = connection.ExecuteReader($"select * from FJ where isSelected=false and (TBYBH='{item["TBBH"].ToString().ToTrim()}' or TBYBH='{Convert.ToBase64String(jcbh)}') ");
dtFJ.Load(reader);
if (dtFJ == null)
{
LogAPI.Debug($"导出举证成果错误:监测编号:{item["TBBH"].ToString()}");
continue;
}
else
{
if (dtFJ.Rows.Count == 0)
{
dtFJ.Clear();
reader.Dispose();
continue;
}
//foreach (DataRow drFJ in dtFJ.Rows)
//{
// var sql = string.Format(sqlFJ, $"'{drFJ["F_ID"]}','{TCBM}','{drFJ["TBYBH"]}','{drFJ["XZQDM"]}','{drFJ["JKBSM"]}','{drFJ["FJMC"]}','{drFJ["FJLX"]}','{drFJ["FJ"].ToString()}','{drFJ["PSSJ"]}','{drFJ["PSJD"]}','{drFJ["PSRY"]}','{drFJ["Longitude"]}','{drFJ["Latitude"]}','{drFJ["XZB"]}','{drFJ["YZB"]}','{drFJ["JYM"]}','{drFJ["LYSB"]}','{drFJ["TakeOffLon"]}','{drFJ["TakeOffLat"]}','{drFJ["TakeOffRelHeight"]}','{drFJ["TakeOffAltitude"]}','{drFJ["PSGD"]}','{drFJ["PSFYJ"]}','{drFJ["PSAltitude"]}'");
// listSQL.Add(sql);
//}
//dtFJ.Clear();
//reader.Dispose();
//if (listSQL.Count > 10000)
//{
// foreach (var str in listSQL)
// {
// cmd.Connection.Execute(str);
// }
// listSQL.Clear();
//}
DCFJ(cmd, dtFJ, null);
dtFJ.Clear();
reader.Dispose();
}
//DCFJ(cmd, dtFJ, null);//转换附件数据
}
//foreach (var str in listSQL)
//{
// cmd.Connection.Execute(str);
//}
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void InsertFJ_HCDB(SQLiteCommand cmd, DataTable TBYBH, int count, string Path)
{
try
{
var tempPrj = new ProjectInfo();
DataTable dtFJ = new DataTable();
using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Path))
{
foreach (DataRow item in TBYBH.Rows)
{
var reader = connection.ExecuteReader($"select * from WYHCFJ where isSelected=true and TBYBH={item["TBBH"].ToString()}) ");
dtFJ.Load(reader);
if (dtFJ == null)
{
LogAPI.Debug($"导出举证成果错误:监测编号:{item["TBBH"].ToString()}");
continue;
}
DCFJ_HCDB(cmd, dtFJ, null);//转换附件数据
dtFJ.Clear();
reader.Dispose();
}
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
public bool TableToTable(IFeatureWorkspace pInWork, IWorkspace pOutWork, string tableName, IQueryFilter queryFilter = null)
{
try
{
if (pInWork == null || pOutWork == null || string.IsNullOrEmpty(tableName)) return false;
IWorkspace2 workspace2 = pInWork as IWorkspace2;
if (workspace2 != null)
{
if (!workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, tableName))
{
return false;
}
}
ITable pInTable = pInWork.OpenTable(tableName);
if (pInTable == null) return false;
IDataset pIndataset = (IDataset)pInTable;
IDatasetName pInDatasetName = (IDatasetName)pIndataset.FullName;
IEnumDataset enumDataset = pOutWork.get_Datasets(esriDatasetType.esriDTTable);
IDataset dataset;
enumDataset.Reset();
while ((dataset = enumDataset.Next()) != null)
{
string[] names = dataset.Name.Split('.');
if (string.Equals(names[names.Length - 1], tableName, StringComparison.CurrentCultureIgnoreCase))
{
dataset.Delete();
break;
}
}
IDataset pOutDataset = (IDataset)pOutWork;
IDatasetName pOutDatasetName = new TableNameClass();
pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName;
pOutDatasetName.Name = tableName;
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields targetFeatureClassFields = pInTable.Fields;
IFields sourceFeatureClassFields = pInTable.Fields;
IEnumFieldError enumFieldError;
fieldChecker.InputWorkspace = pInWork as IWorkspace;
fieldChecker.ValidateWorkspace = pOutWork;
fieldChecker.Validate(sourceFeatureClassFields, out enumFieldError, out targetFeatureClassFields);
IFeatureDataConverter one2another = new FeatureDataConverterClass();
try
{
one2another.ConvertTable(pInDatasetName, queryFilter, pOutDatasetName, targetFeatureClassFields, "", 1000, 0);
}
finally
{
Marshal.ReleaseComObject(one2another);
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private void ProcessTbybh(DataTable dtRecord, SQLiteCommand cmd, string tableName)
{
try
{
string Tblx = "";
if (dtRecord != null)
{
for (int i = 0; i < dtRecord.Rows.Count; i++)
{
Tblx = dtRecord.Rows[i]["TBLX"].ToString();
if (string.IsNullOrWhiteSpace(Tblx))
{
dtRecord.Rows[i]["TBLX"] = "XZTB";//地方自主图斑
}
}
DataRow[] drs = dtRecord.Select(" TBLX = 'CCJZ'");//插入内业预判地类字段
if (drs != null && drs.Length != 0)
{
InsertCCJZ(drs, cmd);
}
drs = dtRecord.Select(" TBLX = 'YBDL'");
if (drs != null && drs.Length != 0)
{
InsertYBDL(drs, cmd);
}
DataTable dtTYSDJZ = SQLiteDBOperate.Instance.ExceDataTable(hcdbPath, "select a.SHAPE,a.TBLX,b.* from SURVEY_RECORD a left join TYSDJZ b on a.TBBH=b.TBYBH");//统一时点举证
if (dtTYSDJZ != null)
{
drs = dtTYSDJZ.Select(" TBLX = 'TYSDJZ'");
if (drs != null && drs.Length != 0)
{
InsertTYSDJZ(drs, cmd);
}
}
DataTable dtGJJCTB = SQLiteDBOperate.Instance.ExceDataTable(hcdbPath, "select a.SHAPE,a.TBLX as TBLX2,a.DHRY,a.BZ as BZ2 ,a.BGFW as BGFW2,a.WBGLX as WBGLX2,ATTRIBUTES,b.* from SURVEY_RECORD a left join GJJCTB b on a.TBBH=b.JCBH");//国家监测图斑
if (dtGJJCTB != null)
{
drs = dtGJJCTB.Select(" TBLX2 = 'GJJCTB'");
if (drs != null && drs.Length != 0)
{
InsertTYSDJZ2(drs, cmd, "1", tableName);
}
}
DataTable dtZZBGTB = SQLiteDBOperate.Instance.ExceDataTable(hcdbPath, "select a.SHAPE,a.TBBH,a.TBMJ as JCMJ2,a.TBLX as TBLX2,a.DHRY,a.BZ as BZ2 ,a.BGFW as BGFW2,a.WBGLX as WBGLX2,ATTRIBUTES,b.* from SURVEY_RECORD a left join ZZBGTB b on a.TBBH=b.JCBH");//自主变更图斑
if (dtZZBGTB != null)
{
drs = dtZZBGTB.Select(" TBLX2 = 'ZZBGTB'");
if (drs != null && drs.Length != 0)
{
InsertTYSDJZ2(drs, cmd, "2", tableName);
}
}
DataTable dtDFZZTB = SQLiteDBOperate.Instance.ExceDataTable(hcdbPath, "select * from SURVEY_RECORD");//自主变更图斑
if (dtDFZZTB != null)
{
drs = dtDFZZTB.Select(" TBLX <> 'GJJCTB' and TBLX <> 'ZZBGTB'");
if (drs != null && drs.Length != 0)
{
InsertTYSDJZ2(drs, cmd, "2", tableName);
}
}
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void InsertCCJZ(DataRow[] drCCJZTBSet, SQLiteCommand cmd)
{
try
{
string sqlInsertCcjz = @"Insert into CCJZ (TBYBH,JKBSM,XZQDM,XMC,TBMJ,XZB,YZB,QSDWMC,QSXZ,DLBM,YPDL,NYBZ,PZD,DLYZX,WYRDDL,SFJZ,WJZLX,JZSM,BZ,JZRY,SFXZ,TBFW)
values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}')";
foreach (DataRow dr in drCCJZTBSet)
{
//初次举证的主键
dr["WYRDDL"] = stringSprt(dr["WYRDDL"].ToString());
#region 从属性字段里面取出预判地类和内业标注
string ypdl = "";
string nybz = "";
string dlbm = "";
string qsdwmc = "";
string qsxz = "";
string atrributes = "";
if (!string.IsNullOrEmpty(dr["attributes"].ToString()))
{
try
{
atrributes = dr["attributes"].ToString().Replace("{", "").Replace("}", "").Replace("[", "").Replace("]", "");
atrributes = "[" + "{" + atrributes + "}" + "]";
atrributes = "{\"dl\":" + atrributes + "}";
Newtonsoft.Json.Linq.JObject jObect = Newtonsoft.Json.Linq.JObject.Parse(atrributes);
Newtonsoft.Json.Linq.JToken jToken = jObect["dl"][0].SelectToken("YPDL");
if (string.IsNullOrWhiteSpace(xzqdm))
{
xzqdm = jObect["dl"][0]["XZQDM"] == null ? "" : jObect["dl"][0]["XZQDM"].ToString();
}
if (string.IsNullOrWhiteSpace(xzqmc))
{
xzqmc = jObect["dl"][0]["XMC"] == null ? "" : jObect["dl"][0]["XMC"].ToString();
}
if (jToken != null)
{
qsdwmc = jObect["dl"][0]["QSDWMC"] == null ? "" : jObect["dl"][0]["QSDWMC"].ToString();
qsxz = jObect["dl"][0]["QSXZ"] == null ? "" : jObect["dl"][0]["QSXZ"].ToString();
ypdl = jObect["dl"][0]["YPDL"] == null ? "" : jObect["dl"][0]["YPDL"].ToString();
nybz = jObect["dl"][0]["NYBZ"] == null ? "" : jObect["dl"][0]["NYBZ"].ToString();
dlbm = jObect["dl"][0]["DLBM"] == null ? "" : jObect["dl"][0]["DLBM"].ToString();
}
else
{
qsdwmc = jObect["dl"][0]["QSDWMC"] == null ? "" : jObect["dl"][0]["QSDWMC"].ToString();
qsxz = jObect["dl"][0]["QSDWDM"] == null ? "" : jObect["dl"][0]["QSDWDM"].ToString();
ypdl = jObect["dl"][0]["NYYPDL"] == null ? "" : jObect["dl"][0]["NYYPDL"].ToString();
nybz = jObect["dl"][0]["BZ"] == null ? "" : jObect["dl"][0]["BZ"].ToString();
dlbm = jObect["dl"][0]["NYDLBM"] == null ? "" : jObect["dl"][0]["NYDLBM"].ToString();
}
}
catch (Exception e)
{
KGIS.Framework.Utils.LogAPI.Debug("样本地类:" + dr["TBBH"] + "attributes字段异常:" + e.ToString());
}
}
#endregion
GeometryEntity result = GdalShapeOperate.Instance.GetWKT(dr["Shape"].ToString());
if (result != null)
{
cmd.CommandText = string.Format(sqlInsertCcjz, dr["TBBH"], "0", xzqdm, xzqmc, string.IsNullOrEmpty(dr["TBMJ"].ToString().Replace(" ", "")) ? "0" : Math.Round(Convert.ToDouble(dr["TBMJ"]), 2).ToString(), result.x, result.y, qsdwmc, qsxz, dlbm, ypdl, nybz, "", stringSprt(dr["TBYZX"].ToString()), dr["WYRDDL"], string.IsNullOrEmpty(dr["SFJZ"].ToString()) ? "N" : stringSprt(dr["SFJZ"].ToString()), stringSprt(dr["WJZLX"].ToString()), dr["JZSM"], dr["BZ"], dr["DHRY"], "1", result.wktStr);
}
int r = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void InsertYBDL(DataRow[] drYBDLBSet, SQLiteCommand cmd)
{
try
{
string sqInsertDlyb = @"Insert into DLYB (TBYBH,JKBSM,XZQDM,XMC,TBMJ,XZB,YZB,YBDL,NYBZ,PZD,YBMS,JZRY,SFXZ,TBFW)
values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')";
foreach (DataRow dr in drYBDLBSet)
{
dr["WYRDDL"] = stringSprt(dr["WYRDDL"].ToString());
GeometryEntity result = GdalShapeOperate.Instance.GetWKT(dr["Shape"].ToString());
string ypdl = "";
string nybz = "";
string atrributes = "";
if (!string.IsNullOrEmpty(dr["attributes"].ToString()))
{
try
{
atrributes = dr["attributes"].ToString().Replace("{", "").Replace("}", "").Replace("[", "").Replace("]", "");
atrributes = "[" + "{" + atrributes + "}" + "]";
atrributes = "{\"dl\":" + atrributes + "}";
Newtonsoft.Json.Linq.JObject jObect = Newtonsoft.Json.Linq.JObject.Parse(atrributes);
ypdl = jObect["dl"][0]["YBDL"] == null ? "" : jObect["dl"][0]["YBDL"].ToString();
nybz = jObect["dl"][0]["NYBZ"] == null ? "" : jObect["dl"][0]["NYBZ"].ToString();
if (string.IsNullOrWhiteSpace(xzqdm))
{
xzqdm = jObect["dl"][0]["XZQDM"] == null ? "" : jObect["dl"][0]["XZQDM"].ToString();
}
if (string.IsNullOrWhiteSpace(xzqmc))
{
xzqmc = jObect["dl"][0]["XMC"] == null ? "" : jObect["dl"][0]["XMC"].ToString();
}
}
catch (Exception e)
{
KGIS.Framework.Utils.LogAPI.Debug("样本地类:" + dr["TBBH"] + "attributes字段异常:" + e.ToString());
}
}
if (result != null)
{
cmd.CommandText = string.Format(sqInsertDlyb, dr["TBBH"], 1, xzqdm, xzqmc, string.IsNullOrEmpty(dr["TBMJ"].ToString().Replace(" ", "")) ? "0" : dr["TBMJ"], result.x, result.y, string.IsNullOrEmpty(dr["WYRDDL"].ToString()) ? ypdl : dr["WYRDDL"], nybz, "", "", dr["DHRY"], "1", result.wktStr);
}
int r = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void InsertTYSDJZ(DataRow[] drTYSDJZTBSet, SQLiteCommand cmd)
{
try
{
string sqlInsertTysdjz = @"Insert into TYSDJZ (XZQDM,XMC,TBYBH,BGDL,SFJZ,WJZLX,BZ,JZSM,TBLB,JZRY,PZD,BGFW,SFBG,WBGYY)
values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')";
foreach (DataRow dr in drTYSDJZTBSet)
{
string atrributes = "";
if (!string.IsNullOrEmpty(dr["attributes"].ToString()) && !string.IsNullOrWhiteSpace(xzqdm) && !string.IsNullOrWhiteSpace(xzqmc))
{
try
{
atrributes = dr["attributes"].ToString().Replace("{", "").Replace("}", "").Replace("[", "").Replace("]", "");
atrributes = "[" + "{" + atrributes + "}" + "]";
atrributes = "{\"dl\":" + atrributes + "}";
Newtonsoft.Json.Linq.JObject jObect = Newtonsoft.Json.Linq.JObject.Parse(atrributes);
if (string.IsNullOrWhiteSpace(xzqdm))
{
xzqdm = jObect["dl"][0]["XZQDM"] == null ? "" : jObect["dl"][0]["XZQDM"].ToString();
}
if (string.IsNullOrWhiteSpace(xzqmc))
{
xzqmc = jObect["dl"][0]["XMC"] == null ? "" : jObect["dl"][0]["XMC"].ToString();
}
}
catch (Exception e)
{
KGIS.Framework.Utils.LogAPI.Debug("统一时点举证:" + dr["TBBH"] + "attributes字段异常:" + e.ToString());
}
}
cmd.CommandText = string.Format(sqlInsertTysdjz, xzqdm, xzqmc, dr["TBYBH"].ToString().Trim(), dr["BGDL"], dr["SFJZ"], dr["WJZLX"], dr["BZ"], dr["JZSM"], dr["TBLB"], dr["JZRY"], dr["PZD"], dr["BGFW"], dr["SFBG"], dr["WBGYY"]);
int r = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void InsertTYSDJZ2(DataRow[] drTYSDJZTBSet, SQLiteCommand cmd, string sjly, string tableName)
{
try
{
string sqlInsertTysdjz = @"Insert into " + tableName +
"(JCBH,TBLX,XZQDM,XMC,JCMJ,HSX,XZB,YZB,TZ,BGDL,BGFW,WBGLX,BZ,JZRY,TBFW,SJLY) " +
"values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')";
foreach (DataRow dr in drTYSDJZTBSet)
{
string atrributes = "";
string tbbh = "";
string tblx = "";
string hsx = "";
string tz = "";
string bgdl = "";
string bgfw = "";
string wbglx = "";
string bz = "";
string jzry = "";
double xzb = 0.00;
double yzb = 0.00;
double jcmj = 0.00;
if (dr.Table.Columns.Contains("attributes") && !string.IsNullOrEmpty(dr["attributes"].ToString()))
{
try
{
atrributes = dr["attributes"].ToString().Replace("{", "").Replace("}", "").Replace("[", "").Replace("]", "");
string atrributesStr = atrributes.Replace(",", "");
if (!string.IsNullOrWhiteSpace(atrributesStr))
{
atrributes = "[" + "{" + atrributes + "}" + "]";
atrributes = "{\"dl\":" + atrributes + "}";
Newtonsoft.Json.Linq.JObject jObect = Newtonsoft.Json.Linq.JObject.Parse(atrributes);
if (string.IsNullOrWhiteSpace(tbbh))
{
tbbh = jObect["dl"][0]["JCBH"] == null ? "" : jObect["dl"][0]["JCBH"].ToString().Trim();
}
if (jcmj == 0)
{
jcmj = jObect["dl"][0]["JCMJ"] == null ? 0 : double.Parse(jObect["dl"][0]["JCMJ"].ToString());
}
if (string.IsNullOrWhiteSpace(xzqdm))
{
xzqdm = jObect["dl"][0]["XZQDM"] == null ? "" : jObect["dl"][0]["XZQDM"].ToString().Trim();
}
if (string.IsNullOrWhiteSpace(xzqmc))
{
xzqmc = jObect["dl"][0]["XMC"] == null ? "" : jObect["dl"][0]["XMC"].ToString().Trim();
}
if (string.IsNullOrWhiteSpace(hsx))
{
hsx = jObect["dl"][0]["HSX"] == null ? "" : jObect["dl"][0]["HSX"].ToString().Trim();
}
if (xzb == 0)
{
xzb = jObect["dl"][0]["XZB"] == null ? 0 : double.Parse(jObect["dl"][0]["XZB"].ToString());
}
if (yzb == 0)
{
yzb = jObect["dl"][0]["YZB"] == null ? 0 : double.Parse(jObect["dl"][0]["YZB"].ToString());
}
if (string.IsNullOrWhiteSpace(tz))
{
tz = jObect["dl"][0]["TZ"] == null ? "" : jObect["dl"][0]["TZ"].ToString().Trim();
}
if (string.IsNullOrWhiteSpace(bgdl))
{
bgdl = jObect["dl"][0]["BGDL"] == null ? "" : jObect["dl"][0]["BGDL"].ToString().Trim();
}
if (string.IsNullOrWhiteSpace(bgfw))
{
bgfw = jObect["dl"][0]["BGFW"] == null ? "" : jObect["dl"][0]["BGFW"].ToString().Trim();
}
if (string.IsNullOrWhiteSpace(wbglx))
{
wbglx = jObect["dl"][0]["WBGLX"] == null ? "" : jObect["dl"][0]["WBGLX"].ToString().Trim();
}
}
}
catch (Exception e)
{
KGIS.Framework.Utils.LogAPI.Debug("统一时点举证:" + dr["JCBH"] + "attributes字段异常:" + e.ToString());
}
}
if (dr.Table.Columns.Contains("JCBH") && string.IsNullOrWhiteSpace(tbbh))
{
tbbh = dr["JCBH"].ToString().Trim();
}
if (dr.Table.Columns.Contains("TBBH") && string.IsNullOrWhiteSpace(tbbh))
{
tbbh = dr["TBBH"].ToString().Trim();
}
if (dr.Table.Columns.Contains("XZQDM") && string.IsNullOrWhiteSpace(xzqdm))
{
xzqdm = dr["XZQDM"].ToString().Trim();
}
if (dr.Table.Columns.Contains("XMC") && string.IsNullOrWhiteSpace(xzqmc))
{
xzqmc = dr["XMC"].ToString().Trim();
}
if (dr.Table.Columns.Contains("JCMJ2") && jcmj == 0)
{
if (dr["JCMJ2"] != null && !string.IsNullOrWhiteSpace(dr["JCMJ2"].ToString()))
{
jcmj = double.Parse(dr["JCMJ2"].ToString());
}
}
if (dr.Table.Columns.Contains("JCMJ") && jcmj == 0)
{
if (dr["JCMJ"] != null && !string.IsNullOrWhiteSpace(dr["JCMJ"].ToString()))
{
jcmj = double.Parse(dr["JCMJ"].ToString());
}
}
if (dr.Table.Columns.Contains("TBMJ") && jcmj == 0)
{
if (dr["TBMJ"] != null && !string.IsNullOrWhiteSpace(dr["TBMJ"].ToString()))
{
jcmj = double.Parse(dr["TBMJ"].ToString());
}
}
if (dr.Table.Columns.Contains("TBLX2") && string.IsNullOrWhiteSpace(tblx))
{
tblx = dr["TBLX2"].ToString().Trim();
}
if (dr.Table.Columns.Contains("TBLX") && string.IsNullOrWhiteSpace(tblx))
{
tblx = dr["TBLX"].ToString().Trim();
}
if (dr.Table.Columns.Contains("HSX") && string.IsNullOrWhiteSpace(hsx))
{
hsx = dr["HSX"].ToString().Trim();
}
if (dr.Table.Columns.Contains("TZ") && string.IsNullOrWhiteSpace(tz))
{
tz = dr["TZ"].ToString().Trim();
}
if (dr.Table.Columns.Contains("BGDL") && string.IsNullOrWhiteSpace(bgdl))
{
bgdl = dr["BGDL"].ToString().Trim();
}
if (dr.Table.Columns.Contains("BGFW2") && string.IsNullOrWhiteSpace(bgdl))
{
bgfw = dr["BGFW2"].ToString().Trim();
}
if (dr.Table.Columns.Contains("BGFW") && string.IsNullOrWhiteSpace(bgfw))
{
bgfw = dr["BGFW"].ToString().Trim();
}
if (dr.Table.Columns.Contains("WBGLX2") && string.IsNullOrWhiteSpace(wbglx))
{
wbglx = dr["WBGLX2"].ToString().Trim();
}
if (dr.Table.Columns.Contains("WBGLX") && string.IsNullOrWhiteSpace(wbglx))
{
wbglx = dr["WBGLX"].ToString().Trim();
}
if (dr.Table.Columns.Contains("BZ2") && string.IsNullOrWhiteSpace(bz))
{
bz = dr["BZ2"].ToString().Trim();
}
if (dr.Table.Columns.Contains("BZ") && string.IsNullOrWhiteSpace(bz))
{
bz = dr["BZ"].ToString().Trim();
}
if (dr.Table.Columns.Contains("DHRY"))
{
jzry = dr["DHRY"].ToString().Trim();
}
IGeometry geo = GeometryConvertHelper.ConverJsonToIGeoemtry(dr["Shape"].ToString(), esriGeometryType.esriGeometryPolygon, 4528, false);
string wkt = GeometryConvertHelper.ConvertIGeoemtryToWKT(geo);
IPoint centerPoint = new PointClass();//获得要素的中心点
IArea pArea = geo as IArea;
pArea.QueryCentroid(centerPoint);
//GeometryEntity result = GdalShapeOperate.Instance.GetWKT(dr["Shape"].ToString());
if (dr.Table.Columns.Contains("XZB") && xzb == 0)
{
if (dr["XZB"] != null && !string.IsNullOrWhiteSpace(dr["XZB"].ToString()))
{
xzb = double.Parse(dr["XZB"].ToString());
}
}
if (dr.Table.Columns.Contains("YZB") && yzb == 0)
{
if (dr["YZB"] != null && !string.IsNullOrWhiteSpace(dr["YZB"].ToString()))
{
yzb = double.Parse(dr["YZB"].ToString());
}
}
if (xzb == 0)
{
xzb = centerPoint.X;
}
if (yzb == 0)
{
yzb = centerPoint.Y;
}
if (geo != null)
{
//JCBH,TBLX,XZQDM,XMC,JCMJ,HSX,XZB,YZB,TZ,BGDL,BGFW,WBGLX,BZ,JZRY,TBFW,SJLY
cmd.CommandText = string.Format(sqlInsertTysdjz,
tbbh, tblx, xzqdm, xzqmc, Math.Round(jcmj, 2), hsx, Math.Round(xzb, 3), Math.Round(yzb, 3), tz, bgdl, GetBGFW(bgfw),
wbglx, bz, jzry, wkt, sjly);
}
int r = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
List FJMCList = null;
private void InsertFJ(SQLiteCommand cmd, DataTable dtGeometry, int count)
{
try
{
DataTable dtCount = SQLiteDBOperate.Instance.ExceDataTableQuick(hcdbPath, "select count(1) from WYHCFJ where isSelected=true ");//查询外业核查附件
int num = int.Parse(dtCount.Rows[0][0].ToString()) / 10 + 1;
using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + hcdbPath))
{
for (int i = 0; i < num; i++)
{
DataTable dtFJ = new DataTable();
var reader = connection.ExecuteReader("select * from WYHCFJ where isSelected=true Limit 10 offset " + i * 10);
dtFJ.Load(reader);
if (dtFJ == null)
{
LogAPI.Debug("导入外业包异常,dtFJ为空");
continue;
}
DCFJ(cmd, dtFJ, dtGeometry);//转换附件数据
count = count + dtFJ.Rows.Count;
dtFJ.Clear();
}
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
}
private void DCFJ(SQLiteCommand cmd, DataTable dtFj, DataTable dtGeo)
{
try
{
string sqlFJ = "Insert into FJ (F_ID,TCBM,TBYBH,XZQDM,JKBSM,FJMC,FJLX,FJ,PSSJ,PSJD,PSRY,Longitude,Latitude,XZB,YZB,JYM,LYSB,TAKEOFFLON,TAKEOFFLAT,TAKEOFFRELHEIGHT,TAKEOFFALTITUDE,PSGD,PSFYJ,PSALTITUDE) " +
"values (@F_ID,@TCBM,@TBYBH,@XZQDM,@JKBSM,@FJMC,@FJLX,@FJ,@PSSJ,@PSJD,@PSRY,@Longitude,@Latitude,@XZB,@YZB,@JYM,@LYSB,@TAKEOFFLON,@TAKEOFFLAT,@TAKEOFFRELHEIGHT,@TAKEOFFALTITUDE,@PSGD,@PSFYJ,@PSALTITUDE)";
if (dtFj != null)
{
foreach (DataRow drFJ in dtFj.Rows)
{
int r = cmd.Connection.Execute(sqlFJ, new
{
F_ID = drFJ["F_ID"],
TCBM = TCBM,
TBYBH = drFJ["TBYBH"],
XZQDM = drFJ["XZQDM"],
JKBSM = drFJ["JKBSM"],
FJMC = drFJ["FJMC"],
FJLX = drFJ["FJLX"],
FJ = drFJ["FJ"],
PSSJ = drFJ["PSSJ"],
PSJD = drFJ["PSJD"],
PSRY = drFJ["PSRY"],
Longitude = drFJ["Longitude"],
Latitude = drFJ["Latitude"],
XZB = drFJ["XZB"],
YZB = drFJ["YZB"],
JYM = drFJ["JYM"],
LYSB = drFJ["LYSB"],
TAKEOFFLON = drFJ["TakeOffLon"],
TAKEOFFLAT = drFJ["TakeOffLat"],
TAKEOFFRELHEIGHT = drFJ["TakeOffRelHeight"],
TAKEOFFALTITUDE = drFJ["TakeOffAltitude"],
PSGD = drFJ["PSGD"],
PSFYJ = drFJ["PSFYJ"],
PSALTITUDE = drFJ["PSAltitude"]
});
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private void DCFJ_HCDB(SQLiteCommand cmd, DataTable dtFj, DataTable dtGeo)
{
try
{
string sqlFJ = "Insert into FJ (F_ID,TCBM,TBYBH,XZQDM,JKBSM,FJMC,FJLX,FJ,PSSJ,PSJD,PSRY,Longitude,Latitude,XZB,YZB,JYM,LYSB,TAKEOFFLON,TAKEOFFLAT,TAKEOFFRELHEIGHT,TAKEOFFALTITUDE,PSGD,PSFYJ,PSALTITUDE) " +
"values (@F_ID,@TCBM,@TBYBH,@XZQDM,@JKBSM,@FJMC,@FJLX,@FJ,@PSSJ,@PSJD,@PSRY,@Longitude,@Latitude,@XZB,@YZB,@JYM,@LYSB,@TAKEOFFLON,@TAKEOFFLAT,@TAKEOFFRELHEIGHT,@TAKEOFFALTITUDE,@PSGD,@PSFYJ,@PSALTITUDE)";
if (dtFj != null)
{
foreach (DataRow drFJ in dtFj.Rows)
{
int r = cmd.Connection.Execute(sqlFJ, new
{
F_ID = drFJ["F_ID"],
TCBM = TCBM,
TBYBH = drFJ["TBBH"],
XZQDM = xzqdm,//drFJ["XZQDM"],
JKBSM = "",//drFJ["JKBSM"],
FJMC = drFJ["FJMC"],
FJLX = drFJ["FJLX"],
FJ = drFJ["FJ"],
PSSJ = drFJ["PSSJ"],
PSJD = drFJ["PSJD"],
PSRY = drFJ["PSRY"],
Longitude = drFJ["Longitude"],
Latitude = drFJ["Latitude"],
XZB = drFJ["ZBX"],
YZB = drFJ["ZBY"],
JYM = drFJ["JYM"],
LYSB = "",//drFJ["LYSB"],
TAKEOFFLON = "",//drFJ["TakeOffLon"],
TAKEOFFLAT = "",//drFJ["TakeOffLat"],
TAKEOFFRELHEIGHT = "",// drFJ["TakeOffRelHeight"],
TAKEOFFALTITUDE = "",// drFJ["TakeOffAltitude"],
PSGD = "",//drFJ["PSGD"],
PSFYJ = "",// drFJ["PSFYJ"],
PSALTITUDE = "",// drFJ["PSAltitude"]
});
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private string GetBGFW(string bgfw)
{
if (bgfw.Contains("1"))
{
return "1";
}
else if (bgfw.Contains("2"))
{
return "2";
}
else
{
return string.Empty;
}
}
private string BindMode(string mode)
{
switch (mode)
{
case "1": return "Y";
case "2": return "J";
case "3": return "T";
case "4": return "S";
default: return "";
}
}
string stringSprt(string str)
{
try
{
if (string.IsNullOrWhiteSpace(str))
return "";
string[] ss = str.Split('-');
return ss[0];
}
catch (Exception ex)
{
throw ex;
}
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void chkSelectedAll_EditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e)
{
try
{
if (this.loadFiles != null && this.loadFiles.Count > 0)
{
bool check = (sender as DevExpress.Xpf.Editors.CheckEdit).IsChecked == null ? false : bool.Parse((sender as DevExpress.Xpf.Editors.CheckEdit).IsChecked.Value.ToString());
this.loadFiles.ForEach(x => x.IsChecked = check);
this.dgFileData.ItemsSource = loadFiles;
this.dgFileData.RefreshData();
}
}
catch (Exception ex)
{
MessageHelper.ShowError("全选发生异常:" + ex.Message);
}
}
private void ExportPath_Click(object sender, RoutedEventArgs e)
{
try
{
KGIS.Framework.Utils.Dialog.FolderBrowserDialog pBrowser = new KGIS.Framework.Utils.Dialog.FolderBrowserDialog
{
ShowNewFolderButton = true
};
if (pBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtExcelPath.Text = pBrowser.SelectedPath;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
#region 选中举证包
private void LbDbList_SelectionChanged(object sender, RoutedEventArgs e)
{
var listBox = sender as System.Windows.Controls.ListBox;
if (listBox == null) return;
var loadFile = listBox.SelectedItem as LoadFile;
if (loadFile != null)
{
this.dgFileData.ExpandGroupRow((this.dgFileData.ItemsSource as List).FindIndex(p => p.DBNAME == loadFile.FileName));
}
}
#endregion
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
var check = sender as System.Windows.Controls.CheckBox;
if (check != null)
{
var info = exportInfos_DEL.Where(x => x.DBNAME == check.Tag.ToString()).FirstOrDefault();
if (info == null) return;
exportInfos.Add(info);
this.dgFileData.RefreshData();
}
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
var check = sender as System.Windows.Controls.CheckBox;
if (check != null)
{
var info = exportInfos.Where(x => x.DBNAME == check.Tag.ToString()).FirstOrDefault();
if (!exportInfos_DEL.Contains(info))
exportInfos_DEL.Add(info);
if (info == null) return;
exportInfos.Remove(info);
this.dgFileData.RefreshData();
}
}
}
public class POINT_JSON
{
public string userName { get; set; }
public string lon { get; set; }
public string lat { get; set; }
public string azimuth { get; set; }
public string datetime { get; set; }
public PHOTOINFO_ENTITY PHOTOINFO { get; set; }
public static POINT_JSON FromJson(string json)
{
if (string.IsNullOrEmpty(json)) return null;
var serializer = new DataContractJsonSerializer(typeof(POINT_JSON));
var mStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
return (POINT_JSON)serializer.ReadObject(mStream);
}
}
public class PHOTOINFO_ENTITY
{
public double longitude { get; set; }
public double latitude { get; set; }
public double pitch { get; set; }
public string datetime { get; set; }
public double takeOffX { get; set; }
public double takeOffY { get; set; }
public double takeOffHeight { get; set; }
public double takeOffAltitude { get; set; }
public double height { get; set; }
public double takePictureAltitude { get; set; }
public double yaw { get; set; }
public PHOTO_AREA_ENTITY PHOTO_AREA { get; set; }
}
public class PHOTO_AREA_ENTITY
{
public double xmin { get; set; }
public double ymin { get; set; }
public double xmax { get; set; }
public double ymax { get; set; }
}
public class ExportInfo
{
public string DBNAME { get; set; }
public string DBpath { get; set; }
public List ExportInfo_details { get; set; }
}
public class ExportInfo_details
{
public string TBBH { get; set; }
public string BZ { get; set; }
public string ZT { get; set; }
public string DBNAME { get; set; }
}
}