年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

439 lines
23 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using Kingo.ImageViewForWebSocket;
using Kingo.PluginServiceInterface;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
namespace Kingo.Plugin.DataLoad.Service
{
public class ProofManager : IProofManager
{
private string DBPath = string.Empty;
private ProjectInfo PrjInfo
{
get
{
return MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
}
}
private Dictionary<string, IRDBHelper> DICIRDBHelper = null;
private string pPath = string.Empty;
public List<T> GetProofInfoList<T>(string pJCBH)
{
#region
//if (string.IsNullOrWhiteSpace(pJCBH) || PrjInfo == null)
// return null;
//List<T> result = new List<T>();
//try
//{
// ProofInfo proofInfo = new ProofInfo();
// DataTable tbDT = SQLiteDBOperate.Instance.ExceDataTable(DBPath, string.Format("select * from BGDC2020 where JCBH='{0}'", pJCBH));
// if (tbDT != null && tbDT.Rows.Count > 0)
// {
// foreach (DataRow dr in tbDT.Rows)
// {
// proofInfo.JCBH = dr["JCBH"].ToTrim();
// proofInfo.BGDL = dr["BGDL"].ToTrim();
// proofInfo.BGFW = dr["BGFW"].ToTrim();
// proofInfo.WBGLX = dr["WBGLX"].ToTrim();
// proofInfo.BZ = dr["BZ"].ToTrim();
// }
// }
// var tempPrj = new ProjectInfo();
// byte[] jcbh = tempPrj.AesEncrypt(pJCBH.ToTrim(), "58ef12f9891a4cd89fa7bdd181ef13a7");
// DataTable dt = SQLiteDBOperate.Instance.ExceDataTable(DBPath, string.Format("select TCBM,TBYBH,FJMC,XZB,YZB,Longitude,Latitude,PSJD,FJLX from FJ where TBYBH='{0}' or TBYBH='{1}' ", pJCBH, Convert.ToBase64String(jcbh)));
// if (dt != null && dt.Rows.Count > 0)
// {
// List<AttachEntity> imgList = new List<AttachEntity>();
// proofInfo.ImgList = imgList;
// foreach (DataRow dr in dt.Rows)
// {
// AttachEntity entity = new AttachEntity();
// entity.FJMC = dr["FJMC"].ToString();
// entity.AttachLocationPath = PrjInfo.ProjDir + "\\Picture\\" + dr["FJMC"].ToString();
// double xzb, yzb;
// if (double.TryParse(dr["Longitude"].ToString(), out xzb) && double.TryParse(dr["Latitude"].ToString(), out yzb))
// {
// IPoint mapPointC = new PointClass() { X = xzb, Y = yzb };
// if (mapPointC.X != 0)
// {
// ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass();
// mapPointC.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
// //创建图层
// ISpatialReference spatiaReference = GeoDBAPI.CreteSpatialReference(PrjInfo.PrjFileStr);
// mapPointC.Project(spatiaReference);
// entity.X = mapPointC.X;
// entity.Y = mapPointC.Y;
// System.Runtime.InteropServices.Marshal.ReleaseComObject(NewSpatialReference);
// NewSpatialReference = null;
// System.Runtime.InteropServices.Marshal.ReleaseComObject(mapPointC);
// mapPointC = null;
// }
// else
// {
// continue;
// }
// }
// else
// {
// if (dr["XZB"] != DBNull.Value)
// {
// entity.X = Convert.ToDouble(dr["XZB"]);
// }
// if (dr["YZB"] != DBNull.Value)
// {
// entity.Y = Convert.ToDouble(dr["YZB"]);
// }
// }
// if (dr["PSJD"] != DBNull.Value)
// {
// entity.Angle = Convert.ToDouble(dr["PSJD"]);
// }
// //if (dr["FJLX"].ToString() != "V" && entity is T)
// if (dr["FJLX"].ToString() != "V")
// imgList.Add(entity);
// }
// }
// ExportPic(new List<string>() { pJCBH, Convert.ToBase64String(jcbh) }, DBPath);
// result.Add((T)(object)proofInfo);
//}
//catch (Exception ex)
//{
// MessageHelper.Show("获取举证信息时发生异常,详细信息请查看日志");
// LogAPI.Debug("获取举证信息时发生异常,异常信息如下:");
// LogAPI.Debug(ex);
//}
//return result;
#endregion
if (string.IsNullOrWhiteSpace(pJCBH) || PrjInfo == null)
return null;
List<T> result = new List<T>();
string DBPath = string.Empty;
string Extension = string.Empty;//文件扩展名
DataTable tbbh_dbpath = null;
DataTable dt = null;
DataTable tbInfoDT = null;
IRDBHelper rdbHelper = null;
try
{
ProofInfo proofInfo = null;
if (pPath != PrjInfo.ProjDir)
{
pPath = PrjInfo.ProjDir;
Clear();
}
if (DICIRDBHelper == null)
DICIRDBHelper = new Dictionary<string, IRDBHelper>();
string dbPath = $"{PrjInfo.ProjDir}\\BGTJ.sqlite";
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
tbbh_dbpath = rdbHelper.ExecuteDatatable("tbbh", $@"select IsChecked,FileName,ParengFolder||'\'||FileName DbPath,Extension from DBFILEINFO WHERE ParengFolder||'\'||FileName=(select DbPath from hcdb_relation WHERE TBBH='{pJCBH}') and IsChecked<>0 and IsDelete<>0 ", true);
if (tbbh_dbpath == null || tbbh_dbpath.Rows.Count == 0)
return null;
Extension = tbbh_dbpath.Rows[0]["Extension"].ToString();
DBPath = tbbh_dbpath.Rows[0]["DbPath"].ToString();
switch (Extension)
{
case ".db":
var tempPrj = new ProjectInfo();
if (!DICIRDBHelper.ContainsKey(DBPath))
DICIRDBHelper.Add(DBPath, RDBFactory.CreateDbHelper("Data Source=" + DBPath, DatabaseType.SQLite));
rdbHelper = DICIRDBHelper[DBPath];
proofInfo = new ProofInfo();
tbInfoDT = rdbHelper.ExecuteDatatable("tb", $"select BSM, TBLX, XZQDM, XMC, TBBH, TBMC, TBMJ, XZB, YZB, BZ, b.KZXX, TBFW,WYHSQK,SDDLDM,DCRY,DCSJ from TBJBXX a ,DCHSXX b on a.BSM=b.TBBSM where TBBH='{pJCBH}'", true);
if (tbInfoDT != null && tbInfoDT.Rows.Count > 0)
{
Dictionary<string, object> dicJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(tbInfoDT.Rows[0]["KZXX"].ToTrim());
if (dicJson != null)
{
#region 外业信息
if (!string.IsNullOrWhiteSpace(tbInfoDT.Rows[0]["WYHSQK"].ToTrim()))
proofInfo.WYHSQK = tbInfoDT.Rows[0]["WYHSQK"].ToTrim();
if (!string.IsNullOrWhiteSpace(tbInfoDT.Rows[0]["SDDLDM"].ToTrim()))
proofInfo.SDDLDM = tbInfoDT.Rows[0]["SDDLDM"].ToTrim();
if (!string.IsNullOrWhiteSpace(tbInfoDT.Rows[0]["DCRY"].ToTrim()))
proofInfo.DCRY = tbInfoDT.Rows[0]["DCRY"].ToTrim();
if (!string.IsNullOrWhiteSpace(tbInfoDT.Rows[0]["DCSJ"].ToTrim()))
proofInfo.DCSJ = tbInfoDT.Rows[0]["DCSJ"].ToTrim();//当前调查时间为字符串类型
if (!string.IsNullOrWhiteSpace(tbInfoDT.Rows[0]["TBBH"].ToTrim()))
proofInfo.JCBH = tbInfoDT.Rows[0]["TBBH"].ToTrim();
if (dicJson.ContainsKey("BGFW"))
proofInfo.BGFW = dicJson["BGFW"].ToTrim();
if (dicJson.ContainsKey("WBGLX"))
proofInfo.WBGLX = dicJson["WBGLX"].ToTrim();
if (dicJson.ContainsKey("BZ"))
proofInfo.BZ = dicJson["BZ"].ToTrim();
#endregion
}
dt = rdbHelper.ExecuteDatatable("tb", string.Format("select TBBSM,FJMC,Longitude,Latitude,PSJD,FJLX,ISSELECTED from FJ where TBBSM='{0}' ", tbInfoDT.Rows[0]["BSM"]), true);
if (dt != null && dt.Rows.Count > 0)
{
List<AttachEntity> imgList = new List<AttachEntity>();
foreach (DataRow dr in dt.Rows)
{
AttachEntity entity = new AttachEntity();
entity.FJMC = dr["FJMC"].ToString();
entity.AttachLocationPath = PrjInfo.ProjDir + "\\Picture\\" + dr["FJMC"].ToString();
entity.JCBH = dr["TBBSM"].ToTrim();
entity.isCheck = (bool)dr["ISSELECTED"];
double xzb, yzb;
if (double.TryParse(dr["Longitude"].ToString(), out xzb) && double.TryParse(dr["Latitude"].ToString(), out yzb))
{
IPoint mapPointC = new PointClass() { X = xzb, Y = yzb };
if (mapPointC.X != 0)
{
ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass();
mapPointC.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
//创建图层
ISpatialReference spatiaReference = GeoDBAPI.CreteSpatialReference(PrjInfo.PrjFileStr);
mapPointC.Project(spatiaReference);
entity.X = mapPointC.X;
entity.Y = mapPointC.Y;
System.Runtime.InteropServices.Marshal.ReleaseComObject(NewSpatialReference);
NewSpatialReference = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(mapPointC);
mapPointC = null;
}
else
{
continue;
}
}
else
{
if (tbInfoDT.Rows[0]["XZB"] != DBNull.Value)
{
entity.X = Convert.ToDouble(tbInfoDT.Rows[0]["XZB"]);
}
if (tbInfoDT.Rows[0]["YZB"] != DBNull.Value)
{
entity.Y = Convert.ToDouble(tbInfoDT.Rows[0]["YZB"]);
}
}
if (dr["PSJD"] != DBNull.Value)
{
entity.Angle = Convert.ToDouble(dr["PSJD"]);
}
if (dr["FJLX"].ToString() != "V")
imgList.Add(entity);
}
proofInfo.ImgList = imgList;
}
ExportPic(new List<string>() { tbInfoDT.Rows[0]["BSM"].ToTrim() }, DBPath);
}
//result.Add((T)(object)proofInfo);
break;
case ".hcdb":
proofInfo = new ProofInfo();
if (!DICIRDBHelper.ContainsKey(DBPath))
DICIRDBHelper.Add(DBPath, RDBFactory.CreateDbHelper("Data Source=" + DBPath, DatabaseType.SQLite));
rdbHelper = DICIRDBHelper[DBPath];
tbInfoDT = rdbHelper.ExecuteDatatable("tb", string.Format("select WYRDDL as BGDL,'' BGFW ,'' WBGLX, WYBZ as BZ,DHRY as JZRY from SURVEY_RECORD where TBBH='{0}'", pJCBH), true);
if (tbInfoDT != null && tbInfoDT.Rows.Count > 0)
{
proofInfo.BGDL = tbInfoDT.Rows[0]["BGDL"].ToTrim();
proofInfo.BGFW = tbInfoDT.Rows[0]["BGFW"].ToTrim();
proofInfo.WBGLX = tbInfoDT.Rows[0]["WBGLX"].ToTrim();
proofInfo.BZ = tbInfoDT.Rows[0]["BZ"].ToTrim();
}
dt = rdbHelper.ExecuteDatatable("tb", string.Format("select FJMC,ZBX,ZBY,Longitude,Latitude,PSJD,FJLX,ISSelected from WYHCFJ where TBBH='{0}' ", pJCBH), true);
if (dt != null && dt.Rows.Count > 0)
{
List<AttachEntity> imgList = new List<AttachEntity>();
proofInfo.ImgList = imgList;
foreach (DataRow dr in dt.Rows)
{
AttachEntity entity = new AttachEntity();
entity.FJMC = dr["FJMC"].ToString();
entity.AttachLocationPath = PrjInfo.ProjDir + "\\Picture\\" + dr["FJMC"].ToString();
entity.isCheck = dr["ISSelected"].ToTrim() == "1";
entity.JCBH = pJCBH;
double xzb, yzb;
if (double.TryParse(dr["Longitude"].ToString(), out xzb) && double.TryParse(dr["Latitude"].ToString(), out yzb))
{
IPoint mapPointC = new PointClass() { X = xzb, Y = yzb };
if (mapPointC.X != 0)
{
ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass();
mapPointC.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490);
//创建图层
ISpatialReference spatiaReference = GeoDBAPI.CreteSpatialReference(PrjInfo.PrjFileStr);
mapPointC.Project(spatiaReference);
entity.X = mapPointC.X;
entity.Y = mapPointC.Y;
System.Runtime.InteropServices.Marshal.ReleaseComObject(NewSpatialReference);
NewSpatialReference = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(mapPointC);
mapPointC = null;
}
else
{
continue;
}
}
else
{
if (dr["ZBX"] != DBNull.Value)
{
entity.X = Convert.ToDouble(dr["ZBX"]);
}
if (dr["ZBY"] != DBNull.Value)
{
entity.Y = Convert.ToDouble(dr["ZBY"]);
}
}
if (dr["PSJD"] != DBNull.Value)
{
entity.Angle = Convert.ToDouble(dr["PSJD"]);
}
if (dr["FJLX"].ToString() != "V")
imgList.Add(entity);
}
}
ExportPic(new List<string>() { pJCBH }, DBPath);
break;
default:
break;
}
if (proofInfo != null)
result.Add((T)(object)proofInfo);
}
catch (Exception ex)
{
if (rdbHelper != null)
rdbHelper.DisConnect();
//MessageHelper.Show("获取举证信息时发生异常,详细信息请查看日志");
LogAPI.Debug("获取举证信息时发生异常,异常信息如下:");
LogAPI.Debug(ex);
}
return result;
}
public List<T> GetProofInfoList<T>(object pGeo, string pAreaScale)
{
IGeometry geo = pGeo as IGeometry;
if (geo == null)
return null;
List<T> result = new List<T>();
//空间查询逻辑
try
{
IFeatureLayer tysdjzLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JZCG");
if (tysdjzLayer != null && tysdjzLayer.FeatureClass != null)
{
List<IFeature> tysdjzFeatureList = FeatureAPI.Identify(geo, tysdjzLayer);
if (tysdjzFeatureList != null && tysdjzFeatureList.Count != 0)
{
for (int i = 0; i < tysdjzFeatureList.Count; i++)
{
IFeature feature = tysdjzFeatureList[i];
if (feature != null)
{
IGeometry tysdjzGeo = feature.Shape;
IGeometry interSectGeo = FeatureAPI.InterSect(geo, tysdjzGeo);
IArea area = tysdjzGeo as IArea;
IArea interSectArea = interSectGeo as IArea;
IArea BGTBArea = geo as IArea;
if (!string.IsNullOrWhiteSpace(pAreaScale))
{
double scale = Convert.ToDouble(pAreaScale);
if (interSectArea.Area / area.Area > scale / 100 || interSectArea.Area / BGTBArea.Area > scale / 100)
{
int fieldIndex = feature.Fields.FindField("JCBH");
if (fieldIndex < 0)
continue;
string jcbh = feature.Value[fieldIndex].ToString();
if (!string.IsNullOrWhiteSpace(jcbh))
{
List<T> list = GetProofInfoList<T>(jcbh);
if (list != null)
result.AddRange(list);
}
}
}
}
}
}
}
}
catch (Exception ex)
{
throw;
}
//
return result;
}
private void ExportPic(List<string> lstPic, string dbPath)
{
try
{
if (lstPic != null && lstPic.Count > 0)
{
string picPath = string.Empty;
string picturePath = PrjInfo.ProjDir + "\\Picture";
if (!Directory.Exists(picturePath))
{
Directory.CreateDirectory(picturePath);
}
foreach (string tbybh in lstPic)
{
DataTable tmDt = SQLiteDBOperate.Instance.ExceDataTable(dbPath, $"select FJ,FJMC from FJ where TBBSM='{tbybh}' ");
if (tmDt != null && tmDt.Rows.Count > 0)
{
foreach (DataRow tmpDr in tmDt.Rows)
{
if (tmpDr != null && tmpDr["FJ"] != System.DBNull.Value)
{
picPath = PrjInfo.ProjDir + "\\Picture\\" + tmpDr["FJMC"].ToString();
if (!File.Exists(picPath))
{
File.WriteAllBytes(PrjInfo.ProjDir + "\\Picture" + "\\" + tmpDr["FJMC"].ToString(), (tmpDr["FJ"] as byte[]));
}
}
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("举证照片写入本地异常:" + ex.Message);
}
}
public void Clear()
{
if (DICIRDBHelper != null)
{
foreach (var item in DICIRDBHelper)
{
if (item.Value == null) continue;
item.Value.DisConnect();
}
DICIRDBHelper = null;
}
}
}
}