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

1144 lines
56 KiB

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using KGIS.Framework.Views;
using Kingo.ImageViewForWebSocket;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows;
using System.Windows.Controls;
namespace Kingo.Plugin.General.View
{
/// <summary>
/// UCImgView.xaml 的交互逻辑
/// </summary>
public partial class UCImgView : UserControl, IElementInfo, INotifyPropertyChanged
{
ICameraPoint CameraHelper = null;
private Dictionary<string, IRDBHelper> DICIRDBHelper = null;
private string pPath = string.Empty;
private List<string> DelFJList = new List<string>();
IProofManager ProofMgr = null;
private List<AttachEntity> ImgList = null;
private AttachEntity currentAttach;
private ProjectInfo PrjInfo
{
get
{
return MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
}
}
public event PropertyChangedEventHandler PropertyChanged;// = delegate { };
public UCImgView()
{
try
{
InitializeComponent();
this.DataContext = this;
Title = "单图斑外业照片";
DockHeight = 240;
this.Loaded += (s1, e1) =>
{
if (string.IsNullOrWhiteSpace(mapBrowser.Address))
{
//SocketPort = 7080;
//WebsocketHelper.Instance.ConnectionCallback = (s) =>
//{
// WebsocketHelper.Instance.Conn = s as IWebSocketConnection;
// {
// (s as IWebSocketConnection).OnOpen = () => { };
// }
//};
//WebsocketHelper.Instance.Start(SocketPort);
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ImgView", "imgView.html");
mapBrowser.Address = path;
}
MapsManager.Instance.MapService.getAxMapControl().OnMouseDown += (s, e) =>
{
try
{
if (e.button != 1)
{
return;
}
//System.Drawing.Point point = new System.Drawing.Point() { X = e.x, Y = e.y };
if (!(ImgList != null && ImgList.Count > 0))
{
return;
}
int x = 0, y = 0;
foreach (var item in ImgList)
{
ESRI.ArcGIS.Geometry.IPoint mP = new ESRI.ArcGIS.Geometry.PointClass() { X = item.X, Y = item.Y };
MapsManager.Instance.MapService.getAxMapControl().FromMapPoint(mP, ref x, ref y);
double d = Math.Pow(x - e.x, 2) + Math.Pow(y - e.y, 2);
double l = Math.Sqrt(d);
if (l < 21)
{
CurrentAttach = item;
WebsocketHelper.Instance.Send("src:" + CurrentAttach.AttachLocationPath);
ChangedPointSymbol(item?.FJMC, item.isCheck);
break;
//ucImgXZZP.SetImage(item.FJMC);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("方位角选择同步照片异常:" + ex.Message);
}
};
};
//ucImgXZZP.ChangedPointSymbol = ChangedPointSymbol;
//ucImgXZZP.ShowImgHandel = (path) =>
//{
// WebsocketHelper.Instance.Send("src:" + path);
//};
//ucImgXZZP.RotateImgHandel = (angle) =>
//{
// WebsocketHelper.Instance.Send("angle:" + angle);
//};
//ucImgXZZP.FullImgHandel = () =>
//{
// WebsocketHelper.Instance.Send("full:");
//};
Platform.Instance.NotifyMsgEven2 += (o) =>
{
try
{
switch (o.MsgType)
{
case "BindProofImg":
//ucImgXZZP.InitData(o.Content as List<AttachEntity>);
break;
case "FullShowPic":
//ucImgXZZP.Img_Full_MouseLeftButtonDown(null, null);
break;
case "Select":
//ucImgXZZP.CbIsCheck_Checked(null, null);
break;
case "Next":
WebsocketHelper.Instance.Send("Next:" + ImgList);
break;
case "Prev":
WebsocketHelper.Instance.Send("Prev:" + ImgList);
break;
case "SelectFWJ":
SelectFWJ(o);
break;
case "UpdateFJGX":
UpdateFJGX(o.Content.ToString(), o.Extend as IRDBHelper);
break;
default:
break;
}
}
catch (Exception ex)
{
LogAPI.Debug("绑定外业照片时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("绑定外业照片时异常 异常信息结束");
}
};
}
catch (Exception ex)
{
LogAPI.Debug("Kingo.Plugin.General.View异常" + ex.Message);
LogAPI.Debug("Kingo.Plugin.General.View异常" + ex.StackTrace);
}
}
private void ChangedPointSymbol(string fjmc, bool isCheck)
{
//更新地图显示方位角样式
//EnvironmentVariables.Instance.cameraPoint.ChangedPointSymbol(fjmc);
if (CameraHelper == null)
CameraHelper = MapsManager.Instance.MapService as ICameraPoint;
if (CameraHelper != null)
CameraHelper.ChangedPointSymbol(fjmc, isCheck);
}
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public Guid ID { get; set; }
public DockStyle DockAreas { get; set; }
public System.Drawing.Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
public bool IsShow { get; set; }
private NYYSInfo NYYSInfo { get; set; }
private TaskPackage taskPackage { get; set; }
public AttachEntity CurrentAttach
{
get => currentAttach; set
{
currentAttach = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentAttach"));
//PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("isCheck"));
}
}
private bool BeForIsCheck { get; set; }
List<PhotoInfo> photoInfos { get; set; }
List<ProofInfo> _ProofList { get; set; }
NYYSInfo nYYSInfo { get; set; }
Dictionary<string, IPoint> dicPic = new Dictionary<string, IPoint>(); //加载图片名称和矩形框范围的集合
public void BindData(object obj)
{
try
{
nYYSInfo = obj as NYYSInfo;
if (nYYSInfo == null)
{
if (ImgList != null)
{
ImgList.Clear();
WebsocketHelper.Instance.Send("Init:" + "12");
}
return;
}
if (nYYSInfo != null && nYYSInfo.BingDataType == PluginServiceInterface.Enums.DTBDataTypeEnum.DTBSL)
{
this.NYYSInfo = nYYSInfo;
//单图斑建库矢量数据加载照片,根据提供的DB
if (NYYSInfo.WYRWTB == null || PrjInfo == null || !Directory.Exists(System.IO.Path.Combine(PrjInfo.ProjDir, "SLDB"))) return;
List<ProofInfo> _ProofList = LoadDTBSLImgByDB(NYYSInfo.WYRWTB.JCBH, System.IO.Path.Combine(PrjInfo.ProjDir, "SLDB"));
if (_ProofList != null && _ProofList.Count > 0)
{
//设置方位角
if (CameraHelper == null)
CameraHelper = MapsManager.Instance.MapService as ICameraPoint;
if (CameraHelper != null)
CameraHelper.AddCameraPoint(_ProofList[0].ImgList);
//设置外业调查信息 新页面
if (this.NYYSInfo.NYYSResult == null)
this.NYYSInfo.NYYSResult = new NYYSResult();
this.NYYSInfo.NYYSResult.TBBSM = string.IsNullOrWhiteSpace(_ProofList[0].JCBH) ? NYYSInfo.WYRWTB.JCBH : _ProofList[0].JCBH;
this.NYYSInfo.NYYSResult.NYYPDL = string.IsNullOrWhiteSpace(_ProofList[0].SDDLDM) ? "" : _ProofList[0].SDDLDM;
this.NYYSInfo.NYYSResult.YPSM = string.IsNullOrWhiteSpace(_ProofList[0].WYHSQK) ? "" : _ProofList[0].WYHSQK;
this.NYYSInfo.NYYSResult.YPRY = string.IsNullOrWhiteSpace(_ProofList[0].DCRY) ? "" : _ProofList[0].DCRY;
this.NYYSInfo.NYYSResult.YPSJ = string.IsNullOrWhiteSpace(_ProofList[0].DCSJ) ? "" : _ProofList[0].DCSJ;
}
var tempData = _ProofList;
if (tempData != null && tempData.Count > 0)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string imgList = serializer.Serialize(tempData[0].ImgList);
//ucImgXZZP.InitData(tempData[0].ImgList as List<AttachEntity>, true);
WebsocketHelper.Instance.OnMessageCallback = (msg) =>
{
if (msg.ToTrim().Contains("Next:undefined")) return;
if (msg.ToTrim().StartsWith("Next:"))
{
if (CurrentAttach != null)
BeForIsCheck = CurrentAttach.isCheck;
AttachEntity temp = serializer.Deserialize<AttachEntity>(msg.ToTrim().Replace("Next:", ""));
CurrentAttach = ImgList.FirstOrDefault(f => f.FJMC == temp.FJMC);
ChangedPointSymbol(CurrentAttach?.FJMC, BeForIsCheck);
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = CurrentAttach.isCheck;
});
}
else if (msg.ToTrim().StartsWith("SelecteAll:"))
{
if (msg.ToTrim().Replace("SelecteAll:", "") == "1")
{
foreach (var item in ImgList)
{
item.isCheck = true;
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = true;
});
}
}
else
{
foreach (var item in ImgList)
{
item.isCheck = false;
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = false;
});
}
}
}
else
{
if (CurrentAttach != null)
BeForIsCheck = CurrentAttach.isCheck;
AttachEntity item = serializer.Deserialize<AttachEntity>(msg.ToTrim());
CurrentAttach = ImgList.FirstOrDefault(f => f.FJMC == item.FJMC);
CurrentAttach.isCheck = item.isCheck;
ChangedPointSymbol(CurrentAttach?.FJMC, BeForIsCheck);
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = CurrentAttach.isCheck;
});
}
};
WebsocketHelper.Instance.Send("Init:" + imgList);
ImgList = tempData[0].ImgList as List<AttachEntity>;
}
else
{
//ImgList = null;
WebsocketHelper.Instance.Send("Init:" + "12");
}
}
else if (nYYSInfo != null)
{
this.NYYSInfo = nYYSInfo;
this.taskPackage = nYYSInfo.TaskPackages;
string tbbsm = null;
string excuteSQL = string.Empty;
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS)
{
if (NYYSInfo.DTBDLTBGX == null) return;
tbbsm = NYYSInfo.DTBDLTBGX.TBBSM;
excuteSQL = "select a.BSM,HCLX,HCJLBSM,DKID,FJMC,FJLX,MODE,SEQUENCE,SUBTYPE,ARG,ARG2,ARG3,IS_SELECTED,LENGTH,POINTS_JSON,HCRY,GROUP_INDEX,GROUPCODE,SUBTASKID,CHECK_CODE,UserDelete,IS_SELECTED as IsChecked,a.CJSJ from wyhcfj a where HCJLBSM='{0}' and (UserDelete=0 or UserDelete is null) and a.mode in(1,2,3,7,8)";
}
else if (Platform.Instance.SystemType == SystemTypeEnum.YCLJK)
{
if (NYYSInfo.WYRWTB == null) return;
tbbsm = NYYSInfo.WYRWTB.TBBSM;
excuteSQL = @"select distinct a.*,1 as IsChecked from (select * from wyhcfj a where a.mode in (1, 4, 6, 7, 8, 9) and a.arg in(select fjarg from fjgx where tbbsm = '{0}') group by arg) a";
}
if (taskPackage == null || string.IsNullOrWhiteSpace(taskPackage.PackageTempPath) || !System.IO.File.Exists(taskPackage.PackageTempPath) || string.IsNullOrWhiteSpace(tbbsm))
{
this.DataContext = null;
return;
}
photoInfos = GetProofInfoList_DTBJK(tbbsm, taskPackage.PackageTempPath, excuteSQL);
_ProofList = PhotoInfoTOProofInfo(photoInfos);
if (_ProofList != null && _ProofList.Count > 0)
{
if (CameraHelper == null)
CameraHelper = MapsManager.Instance.MapService as ICameraPoint;
if (CameraHelper != null)
CameraHelper.AddCameraPoint(_ProofList[0].ImgList);
}
var tempData = _ProofList;
if (tempData != null && tempData.Count > 0)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string imgList = serializer.Serialize(tempData[0].ImgList);
BeForIsCheck = false;
WebsocketHelper.Instance.OnMessageCallback = (msg) =>
{
if (msg.ToTrim().StartsWith("FullScreen:"))
{
try
{
AttachEntity temp = serializer.Deserialize<AttachEntity>(msg.ToTrim().Replace("FullScreen:", ""));
Thread th = new Thread
(
() =>
{
UCShowImage uCShowImage = new UCShowImage(temp.AttachLocationPath, ImgList)
{
//Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - 200,
//Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - 200,
Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * 3 / 4,
Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * 3 / 4,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
};
uCShowImage.ShowDialog();
}
);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
return;
}
if (msg.ToTrim().Contains("Next:undefined")) return;
if (msg.ToTrim().StartsWith("Next:"))
{
if (CurrentAttach != null)
BeForIsCheck = CurrentAttach.isCheck;
AttachEntity temp = serializer.Deserialize<AttachEntity>(msg.ToTrim().Replace("Next:", ""));
CurrentAttach = ImgList.FirstOrDefault(f => f.FJMC == temp.FJMC);
ChangedPointSymbol(CurrentAttach?.FJMC, BeForIsCheck);
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = CurrentAttach.isCheck;
});
}
else if (msg.ToTrim().StartsWith("SelecteAll:"))
{
if (msg.ToTrim().Replace("SelecteAll:", "") == "1")
{
foreach (var item in ImgList)
{
item.isCheck = true;
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = true;
ChangedPointSymbol(item?.FJMC, true);
});
}
}
else
{
foreach (var item in ImgList)
{
item.isCheck = false;
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = false;
ChangedPointSymbol(item?.FJMC, false);
});
}
}
}
else
{
if (CurrentAttach != null)
BeForIsCheck = CurrentAttach.isCheck;
AttachEntity item = serializer.Deserialize<AttachEntity>(msg.ToTrim());
CurrentAttach = ImgList.FirstOrDefault(f => f.FJMC == item.FJMC);
CurrentAttach.isCheck = item.isCheck;
ChangedPointSymbol(CurrentAttach?.FJMC, BeForIsCheck);
cbIsCheck.Dispatcher.Invoke(() =>
{
cbIsCheck.IsChecked = CurrentAttach.isCheck;
});
}
};
WebsocketHelper.Instance.Send("Init:" + imgList);
ImgList = tempData[0].ImgList as List<AttachEntity>;
}
else
{
ImgList = null;
}
}
}
catch (Exception ex)
{
LogAPI.Debug("绑定外业照片时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("绑定外业照片时异常 异常信息结束");
}
}
private List<ProofInfo> GetProofData(IFeature pFeature)
{
List<ProofInfo> result = new List<ProofInfo>();
int fieldIndex = pFeature.Fields.FindField("TBYBH");
if (fieldIndex > 0)
{
result = ProofMgr.GetProofInfoList<ProofInfo>(pFeature.Value[fieldIndex].ToString());
}
return result;
}
public void SaveEdit()
{
IRDBHelper rdbHelper = null;
try
{
List<AttachEntity> attachEntities = ImgList;// ucImgXZZP.GetAttachEntityList();
if (attachEntities != null && attachEntities.Count > 0)
{
if (taskPackage == null || string.IsNullOrWhiteSpace(taskPackage.PackageTempPath)) return;
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
rdbHelper.BeginTransaction();
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS)
{
if (NYYSInfo.DTBDLTBGX == null)
{
rdbHelper.Rollback();
return;
}
rdbHelper.ExecuteNonQueryWithException(string.Format("delete from fjgx where tbbsm='{0}'", NYYSInfo.DTBDLTBGX.BSM), CommandType.Text);
string excuteSQL = "insert into fjgx(WYTBBSM,FJARG,tbbsm)values('{0}','{1}','{2}')";
foreach (var item in attachEntities)
{
if (item.isCheck)
{
var fjarg = rdbHelper.ExecuteDatatable("fjarg", $" select ARG from WYHCFJ WHERE fjmc='{item.FJMC}' and HCJLBSM='{item.JCBH}' ", true).Rows[0]["ARG"].ToString();
var x = rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, NYYSInfo.WYRWTB.TBBSM, fjarg, NYYSInfo.DTBDLTBGX.BSM), CommandType.Text);
//LogAPI.Debug($"insert_SQL:{string.Format(excuteSQL, NYYSInfo.WYRWTB.TBBSM, fjarg, NYYSInfo.DTBDLTBGX.BSM)}");
//LogAPI.Debug($"insert_SQL执行结果:{x}");
}
var IS_SELECTED = item.isCheck == true ? 1 : 0;
rdbHelper.ExecuteNonQueryWithException($"update WYHCFJ set IS_SELECTED={IS_SELECTED} where FJMC='{item.FJMC}' and HCJLBSM='{item.JCBH}'", CommandType.Text);
}
}
bool xx = rdbHelper.Commit();
//LogAPI.Debug($"insert_SQL执行结果:{xx}");
}
else
{
//当前无照片不做提示
//LogAPI.Debug("ImgList数据为空");
}
}
catch (Exception ex)
{
LogAPI.Debug("保存照片状态时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("保存照片状态时异常 异常信息结束");
rdbHelper.Rollback();
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
public void UpdateFJGX(string tbbsm, IRDBHelper rdbHelper)
{
if (rdbHelper == null || ImgList == null) return;
try
{
List<AttachEntity> attachEntities = ImgList;
if (attachEntities != null && attachEntities.Count > 0)
{
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS)
{
if (NYYSInfo.DTBDLTBGX == null) return;
string excuteSQL = "insert into fjgx(WYTBBSM,FJARG,tbbsm)values('{0}','{1}','{2}')";
foreach (var item in attachEntities)
{
if (item.isCheck)
{
var fjarg = rdbHelper.ExecuteDatatable("fjarg", $" select ARG from WYHCFJ WHERE fjmc='{item.FJMC}' and HCJLBSM='{item.JCBH}' ", true).Rows[0]["ARG"].ToString();
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, NYYSInfo.WYRWTB.TBBSM, fjarg, tbbsm), CommandType.Text);
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("UpdateFJGX异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("UpdateFJGX异常 异常信息结束");
}
}
public void Clear()
{
if (DICIRDBHelper != null)
{
foreach (var item in DICIRDBHelper)
{
if (item.Value == null) continue;
item.Value.DisConnect();
}
DICIRDBHelper = null;
}
}
public List<PhotoInfo> GetProofInfoList_DTBJK(string TBBSM, string PackageTempPath, string excuteSQL)
{
if (string.IsNullOrWhiteSpace(TBBSM) || PrjInfo == null)
return null;
List<PhotoInfo> result = new List<PhotoInfo>();
IRDBHelper rdbHelper = null;
DataTable dataTable = null;
try
{
if (pPath != PrjInfo.ProjDir)
{
pPath = PrjInfo.ProjDir;
Clear();
}
if (string.IsNullOrWhiteSpace(PackageTempPath) || !System.IO.File.Exists(PackageTempPath) || string.IsNullOrWhiteSpace(TBBSM))
{
return null;
}
rdbHelper = RDBFactory.CreateDbHelper($"{PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
dataTable = rdbHelper.ExecuteDatatable("fj", string.Format(excuteSQL, TBBSM), true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
string picPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(PackageTempPath), "Picture");
if (!System.IO.Directory.Exists(picPath))
{
System.IO.Directory.CreateDirectory(picPath);
}
List<PhotoInfo> list = ToList<PhotoInfo>(dataTable);
foreach (var item in list)
{
if (!SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("65"))
{
item.isSelected = false;
item.IsChecked = 0;
}
try
{
if (item.FJMC == null) continue;
item.ImagePath = System.IO.Path.Combine(picPath, item.FJMC.ToString().Trim());
if (!System.IO.File.Exists(item.ImagePath))
{
string iexcuteSQL = string.Format("select ARG4 from wyhcfj where bsm='{0}'", item.BSM);
item.ARG4 = rdbHelper.ReadBlobToBytes(iexcuteSQL, null);
item.FJ = item.ARG4;
System.IO.File.WriteAllBytes(item.ImagePath, item.ARG4);
}
else
{
try
{
DataTable dataTable2 = rdbHelper.ExecuteDatatable("fjargs", $" select FJARG from fjgx WHERE tbbsm='{NYYSInfo.DTBDLTBGX.BSM}' ", true);
foreach (DataRow itemFJGX in dataTable2.Rows)
{
if (item.ARG.ToTrim().Equals(itemFJGX["FJARG"].ToString()))
item.IsChecked = 1;
}
}
catch (Exception)
{ }
}
}
catch (Exception ex)
{
LogAPI.Debug(item.FJMC.ToString().Trim() + "照片下载失败:" + ex.Message);
}
}
if (list != null && list.Count > 0)
{
result = list;
}
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug("获取举证信息时发生异常,异常信息如下:");
LogAPI.Debug(ex);
return result;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
if (dataTable != null)
{
dataTable.Clear();
dataTable.Dispose();
}
GC.Collect();
}
}
public static List<T> ToList<T>(DataTable dt)
{
if (dt == null || dt.Rows.Count == 0)
{
return new List<T>();
}
System.Reflection.PropertyInfo[] properties = typeof(T).GetProperties();//获取实体类型的属性集合
List<T> list = new List<T>();
T model = default(T);
foreach (DataRow dr in dt.Rows)
{
model = System.Activator.CreateInstance<T>();//创建实体
foreach (System.Reflection.PropertyInfo p in properties)
{
foreach (DataColumn col in dt.Columns)
{
try
{
if (col.ColumnName.ToLower().Equals(p.Name.ToLower()))
{
object obj = dr[col.ColumnName];
if (obj == null || obj is DBNull)
break;
if (obj.ToString().Replace(" ", "").Length == 0)
break;
if (p.PropertyType == typeof(string))
{
p.SetValue(model, obj.ToString(), null);
}
else if (p.PropertyType == typeof(object))
{
p.SetValue(model, (object)(obj.ToString()), null);
}
else if (p.PropertyType == typeof(int) || p.PropertyType == typeof(int?))
{
p.SetValue(model, int.Parse(obj.ToString()), null);
}
else if (p.PropertyType == typeof(DateTime) || p.PropertyType == typeof(DateTime?))
{
p.SetValue(model, DateTime.Parse(obj.ToString()), null);
}
else if (p.PropertyType == typeof(float) || p.PropertyType == typeof(float?))
{
p.SetValue(model, float.Parse(obj.ToString()), null);
}
else if (p.PropertyType == typeof(double) || p.PropertyType == typeof(double?))
{
p.SetValue(model, double.Parse(obj.ToString()), null);
}
else if (p.PropertyType == typeof(decimal) || p.PropertyType == typeof(decimal?))
{
p.SetValue(model, decimal.Parse(obj.ToString()), null);
}
else if (p.PropertyType == typeof(bool) || p.PropertyType == typeof(bool?))
{
bool b = false;
if (Boolean.TryParse(obj.ToString(), out b))
{
p.SetValue(model, b, null);
}
else
{
if (obj.ToString().Equals("0"))
{
p.SetValue(model, false, null);
}
else
{
p.SetValue(model, true, null);
}
}
}
else if (p.PropertyType == typeof(Byte[]))
{
p.SetValue(model, obj as Byte[], null);
}
break;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
list.Add(model);
}
return list;
}
#region 经纬度转平面坐标
/// <summary>
/// 经纬度转平面坐标
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private IPoint GetProject(double x, double y)
{
try
{
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = MapsManager.Instance.MapService.getAxMapControl().SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = earthref;
geo.Project(flatref);
return pt;
}
catch (Exception ex)
{
return null;
}
}
#endregion
private List<ProofInfo> PhotoInfoTOProofInfo(List<PhotoInfo> photoInfos)
{
try
{
dicPic.Clear();
List<ProofInfo> list = new List<ProofInfo>();
List<AttachEntity> attachEntities = new List<AttachEntity>();
if (photoInfos != null)
{
foreach (PhotoInfo Photoitem in photoInfos)
{
if (Photoitem.XZB == 0 || Photoitem.YZB == 0) continue;
AttachEntity entity = new AttachEntity();
IPoint mapPoint = GetProject(Photoitem.XZB, Photoitem.YZB);
if (mapPoint == null) continue;
entity.FJMC = Photoitem.FJMC;
entity.AttachLocationPath = Photoitem.ImagePath;
entity.JCBH = Photoitem.HCJLBSM;
entity.isCheck = Photoitem.IsChecked == 0 ? false : true;
entity.X = mapPoint.X;
entity.Y = mapPoint.Y;
entity.Angle = Photoitem.PSJD;
entity.centerPoint = new CenterPoint() { X = mapPoint.X, Y = mapPoint.Y };
attachEntities.Add(entity);
if (!dicPic.Keys.Contains(Photoitem.FJMC))
{
dicPic.Add(Photoitem.FJMC, mapPoint);
}
}
ProofInfo proofInfo = new ProofInfo()
{
ImgList = attachEntities
};
list.Add(proofInfo);
}
return list;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private void cbIsCheck_Checked(object sender, System.Windows.RoutedEventArgs e)
{
if (CurrentAttach != null)
CurrentAttach.isCheck = true;
JavaScriptSerializer serializer = new JavaScriptSerializer();
WebsocketHelper.Instance.Send("selected:" + serializer.Serialize(CurrentAttach));
}
private void cbIsCheck_Unchecked(object sender, System.Windows.RoutedEventArgs e)
{
if (CurrentAttach != null)
CurrentAttach.isCheck = false;
JavaScriptSerializer serializer = new JavaScriptSerializer();
WebsocketHelper.Instance.Send("selected:" + serializer.Serialize(CurrentAttach));
}
private List<ProofInfo> LoadDTBSLImgByDB(string pJCBH, string DbPath)
{
List<ProofInfo> photoInfos = new List<ProofInfo>();
//DbPath = @"E:\单图斑建库测试数据\陕西单图斑测试数据\(610116)长安区.db";//测试数据
foreach (string filePath in InitYXData(DbPath))
{
SQLiteDBOperate.Instance.OnlySQL($"alter table FJ add column 'isSelected' bool default true", filePath);//添加isSelected 是否选择照片字段
photoInfos.AddRange(GetProofInfoList<ProofInfo>(pJCBH, filePath));
//photoInfos.AddRange(GetProofInfoList<ProofInfo>("610116DF155870".Trim(), filePath));//当前仅为测试数据,不提交
}
return photoInfos;
}
public List<T> GetProofInfoList<T>(string pJCBH, string DBPath)
{
if (string.IsNullOrWhiteSpace(pJCBH) || PrjInfo == null)
return null;
List<T> result = new List<T>();
string Extension = string.Empty;
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>();
Extension = System.IO.Path.GetExtension(DBPath);
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,XZQDM,XMC,DKBH,DKMC,DKMJ,XZB,YZB,BZ,b.KZXX,DKFW,WYHSQK,SDDLDM,DCRY,DCSJ from DKJBXX a ,DKDCHSXX b on a.BSM=b.DKBSM where DKBH='{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 (dicJson.ContainsKey("SDXZ"))
proofInfo.BGFW = dicJson["SDXZ"].ToTrim();
if (dicJson.ContainsKey("WBGLX"))
proofInfo.WBGLX = dicJson["WBGLX"].ToTrim();
if (dicJson.ContainsKey("BZ"))
proofInfo.BZ = dicJson["BZ"].ToTrim();
#endregion
}
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]["DKBH"].ToTrim()))
proofInfo.JCBH = tbInfoDT.Rows[0]["DKBH"].ToTrim();
dt = rdbHelper.ExecuteDatatable("tb", string.Format("select DKBSM,FJMC,Longitude,Latitude,PSJD,FJLX from FJ where DKBSM='{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["DKBSM"].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);
}
break;
default:
break;
}
if (proofInfo != null && !string.IsNullOrWhiteSpace(proofInfo.JCBH))
result.Add((T)(object)proofInfo);
}
catch (Exception ex)
{
if (rdbHelper != null)
rdbHelper.DisConnect();
LogAPI.Debug("获取举证信息时发生异常,异常信息如下:");
LogAPI.Debug(ex);
}
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 DKBSM='{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);
}
}
private List<string> InitYXData(string YXPath)
{
try
{
List<string> YXList = new List<string>();
if (string.IsNullOrWhiteSpace(YXPath) || !Directory.Exists(YXPath))
{
return YXList;
}
DirectoryInfo folder = new DirectoryInfo(YXPath);
FileInfo[] finfoList = folder.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo fileInfo in finfoList)
{
if (fileInfo.Extension.Equals(".db", StringComparison.CurrentCultureIgnoreCase))
{
YXList.Add(fileInfo.FullName);
}
}
return YXList;
}
catch (Exception ex)
{
LogAPI.Debug("获取DB文件失败:" + ex);
MessageHelper.ShowError("获取DB文件失败:" + ex.Message);
throw ex;
}
}
private void SelectFWJ(NotifyMsgPackage msg)
{
bool isSelectPicture = false;
try
{
if (photoInfos == null || photoInfos.Count == 0) return;
if (msg.Content is IGeometry)
{
int num = 0;
foreach (var item in dicPic)
{
if (FeatureAPI.IsContains(msg.Content as IGeometry, item.Value))
{
num++;
PhotoInfo photoInfo = photoInfos.FirstOrDefault(Z => Z.FJMC.Equals(item.Key));
if (photoInfo != null)
{
for (int i = 0; i < photoInfos.Count; i++)
{
if (photoInfos[i].FJMC.Equals(item.Key, StringComparison.CurrentCultureIgnoreCase))
{
if (!isSelectPicture)
isSelectPicture = true;
if (photoInfos[i].isSelected == false && photoInfos[i].IsChecked == 0)
{
photoInfos[i].IsChecked = 1;
photoInfos[i].isSelected = true;
}
else
{
photoInfos[i].IsChecked = 0;
photoInfos[i].isSelected = false;
}
break;
}
}
}
}
}
}
else if (msg.Content is IPoint)
{
IPoint e = msg.Content as IPoint;
//int x1 = 0, y1 = 0;
int x = 0, y = 0;
foreach (var item in dicPic)
{
//_MapService.getAxMapControl().FromMapPoint(ePoint, ref x1, ref y1);
MapsManager.Instance.MapService.getAxMapControl().FromMapPoint(item.Value, ref x, ref y);
double d = Math.Pow(x - e.X, 2) + Math.Pow(y - e.Y, 2);
double l = Math.Sqrt(d);
PhotoInfo photoInfo = photoInfos.FirstOrDefault(Z => Z.FJMC.Equals(item.Key));
if (l < 21 && photoInfo != null)
{
for (int i = 0; i < photoInfos.Count; i++)
{
if (photoInfos[i].FJMC.Equals(item.Key, StringComparison.CurrentCultureIgnoreCase))
{
if (!isSelectPicture)
isSelectPicture = true;
if (photoInfos[i].isSelected == false && photoInfos[i].IsChecked == 0)
{
photoInfos[i].IsChecked = 1;
photoInfos[i].isSelected = true;
}
else
{
photoInfos[i].IsChecked = 0;
photoInfos[i].isSelected = false;
}
break;
}
}
}
}
}
//触发了框选操作 执行保存及刷新
if (isSelectPicture)
{
_ProofList = PhotoInfoTOProofInfo(photoInfos);
if (_ProofList != null && _ProofList.Count > 0)
{
ImgList = _ProofList[0].ImgList as List<AttachEntity>;
}
SaveEdit();
if (nYYSInfo != null)
BindData(nYYSInfo);
//地图刷新
MapsManager.Instance.MapService.getAxMapControl().Refresh();
}
}
catch (Exception ex)
{
LogAPI.Debug("地图框选照片失败!" + ex);
MessageHelper.ShowError("地图框选照片失败!" + ex.Message);
}
}
}
}