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

598 lines
26 KiB

using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.Plugin.General.Helper;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Windows;
using System.Windows.Documents;
//using KGIS.Plugin.SH.View;
namespace Kingo.Plugin.General.View
{
/// <summary>
/// UCWyfjInfo.xaml 的交互逻辑
/// </summary>
public partial class UCWyfjInfo : System.Windows.Controls.UserControl, IElementInfo
{
private NYYSInfo m_nYYSInfo { get; set; }
private object Data { get; set; }
public IHookHelper hookHelper { get; set; }
private UCShowFile WyfjForm { get; set; }
private UCShowImage WyfjImage { get; set; }
private IRDBHelper rdbHelper = null;
private TaskPackage TaskPackage { get; set; }
public bool IsShow { get; set; }
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 UCWyfjInfo()
{
InitializeComponent();
this.Title = "外业附件";
}
private void btnPdf_Click(object sender, RoutedEventArgs e)
{
try
{
string pdfPath = ((Kingo.Plugin.General.View.WyhcfjInfo)((System.Windows.FrameworkElement)sender).DataContext).FjPath;
string extension = System.IO.Path.GetExtension(pdfPath);
switch (extension)
{
case ".pdf":
ShowPdf(pdfPath);
break;
default:
ShowImage(pdfPath);
break;
}
}
catch (Exception ee)
{
LogAPI.Debug("btnPdf_Click ERROR:" + ee.ToString());
}
}
private void ShowPdf(string filePath)
{
if (WyfjForm == null)
{
WyfjForm = new UCShowFile();
}
WyfjForm.Title = "附件预览";
WyfjForm.Height = 650;
WyfjForm.Width = 800;
WyfjForm.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
WyfjForm.Closed += PdfForm_Closed;
if (!string.IsNullOrEmpty(filePath))
{
WyfjForm.BindData(filePath, ".pdf");
WyfjForm.ShowInMainWindow(false);
}
}
private void ShowImage(string filePath)
{
if (WyfjImage == null)
{
WyfjImage = new UCShowImage();
}
WyfjImage.Title = "附件预览";
WyfjImage.Height = 650;
WyfjImage.Width = 800;
WyfjImage.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
WyfjImage.Closed += WyfjImage_Closed;
if (!string.IsNullOrEmpty(filePath))
{
WyfjImage.LoadImage(filePath);
WyfjImage.ShowInMainWindow(false);
}
}
private void PdfForm_Closed(object sender, EventArgs e)
{
if (WyfjForm != null)
{
WyfjForm = null;
}
}
private void WyfjImage_Closed(object sender, EventArgs e)
{
if (WyfjImage != null)
{
WyfjImage = null;
}
}
private void cboxPdf_Click(object sender, RoutedEventArgs e)
{
try
{
WyhcfjInfo pdfObj = (Kingo.Plugin.General.View.WyhcfjInfo)((System.Windows.FrameworkElement)sender).DataContext;
if (TaskPackage == null)
{
throw new Exception("相关附件获取任务包异常。");
}
rdbHelper = RDBFactory.CreateDbHelper($"{TaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
object obj = rdbHelper.ExecuteScalar($"select bsm from fjgx where wytbbsm = '{pdfObj.Tbbsm}' and tbbsm ='{pdfObj.Bsm}' and fjarg = '{pdfObj.Arg}'", CommandType.Text);
if (((System.Windows.Controls.Primitives.ToggleButton)e.Source).IsChecked == true)
{
pdfObj.Sfxz = 1;
if (obj == null)
{
rdbHelper.ExecuteNonQuery($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{pdfObj.Tbbsm}','{pdfObj.Arg}','{pdfObj.Bsm}')", CommandType.Text);
}
}
else
{
pdfObj.Sfxz = 0;
if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
{
rdbHelper.ExecuteNonQuery($"delete from fjgx where wytbbsm = '{pdfObj.Tbbsm}' and tbbsm ='{pdfObj.Bsm}' and fjarg = '{pdfObj.Arg}'", CommandType.Text);
}
}
}
catch (Exception ee)
{
LogAPI.Debug("cboxPdf_Click ERROR :" + ee.ToString());
throw ee;
}
finally
{
if (rdbHelper.State == ConnectionState.Open)
{
rdbHelper.DisConnect();
}
rdbHelper.Clear();
rdbHelper = null;
}
}
public void BindData(object obj)
{
if (obj == null)
{
this.dgdPdf.ItemsSource = null;
return;
}
IRDBHelper rdbHelper = null;
try
{
NYYSInfo nYYSInfo = obj as NYYSInfo;
m_nYYSInfo = nYYSInfo;
if (m_nYYSInfo.DTBDLTBGX == null) return;
try
{
this.Data = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG").FeatureClass.GetFeature(m_nYYSInfo.DTBDLTBGX.ObjectID);
}
catch (Exception)
{ }
TaskPackage = m_nYYSInfo.TaskPackages;
if (TaskPackage == null) return;
string strSqlFj = "select BSM,HCLX,HCJLBSM,DKID,FJMC,FJLX,MODE,SEQUENCE,SUBTYPE,ARG,ARG2,ARG3,ARG4,LENGTH,POINTS_JSON,HCRY,GROUP_INDEX,GROUPCODE,SUBTASKID,CHECK_CODE,UserDelete,0 as IsChecked,CJSJ from wyhcfj where HCJLBSM='{0}' and (UserDelete=0 or UserDelete is null) and mode in (4)";
rdbHelper = RDBFactory.CreateDbHelper($"{nYYSInfo.TaskPackages.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
var dataTable = rdbHelper.ExecuteDatatable("fj", string.Format(strSqlFj, nYYSInfo.WYRWTB.TBBSM), true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
string pdfPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(TaskPackage.PackageTempPath), "PDF");
if (!System.IO.Directory.Exists(pdfPath))
{
System.IO.Directory.CreateDirectory(pdfPath);
}
DataTable dt = rdbHelper.ExecuteDatatable("fjgx", $"select fjarg from fjgx where WYTBBSM='{nYYSInfo.WYRWTB.TBBSM}' and tbbsm = '{nYYSInfo.DTBDLTBGX.BSM}'", true);
List<PhotoInfo> list = JKTBTaskHelper.ToList<PhotoInfo>(dataTable);
foreach (var item in list)
{
try
{
item.ImagePath = System.IO.Path.Combine(pdfPath, item.FJMC.ToString().Trim());
if (!System.IO.File.Exists(item.ImagePath))
{
item.FJ = item.ARG4;
System.IO.File.WriteAllBytes(item.ImagePath, item.ARG4);
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
if (item.ARG == row["fjarg"].ToString())
{
item.SFXZ = 1;
break;
}
else
{
item.SFXZ = 0;
}
}
}
else
{
item.SFXZ = 0;
}
}
catch (Exception ex)
{
LogAPI.Debug(item.FJMC.ToString().Trim() + "外业附件下载失败:" + ex.Message);
}
}
if (list != null && list.Count > 0)
{
List<WyhcfjInfo> fjList = new List<WyhcfjInfo>();
foreach (var item in list)
{
fjList.Add(new WyhcfjInfo(item.BSM.ToString(), item.BSM.ToString(), item.HCJLBSM, item.FJMC, item.ImagePath, item.ARG, item.HCRY, item.PSSJ, item.SFXZ));
}
this.dgdPdf.ItemsSource = fjList;
}
else
{
this.dgdPdf.ItemsSource = null;
}
}
else
{
this.dgdPdf.ItemsSource = null;
}
}
catch (Exception ee)
{
LogAPI.Debug("外业附件BindData ERROR:" + ee.Message);
LogAPI.Debug(ee.Source);
}
finally
{
if (rdbHelper != null && rdbHelper.State == ConnectionState.Open)
{
rdbHelper.DisConnect();
}
rdbHelper = null;
}
}
private void Refresh()
{
if (m_nYYSInfo == null)
{
return;
}
IRDBHelper rdbHelper = null;
try
{
this.Data = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG").FeatureClass.GetFeature(m_nYYSInfo.DTBDLTBGX.ObjectID);
TaskPackage = m_nYYSInfo.TaskPackages;
string strSqlFj = "select BSM,HCLX,HCJLBSM,DKID,FJMC,FJLX,MODE,SEQUENCE,SUBTYPE,ARG,ARG2,ARG3,ARG4,LENGTH,POINTS_JSON,HCRY,GROUP_INDEX,GROUPCODE,SUBTASKID,CHECK_CODE,UserDelete,0 as IsChecked,CJSJ from wyhcfj where HCJLBSM='{0}' and (UserDelete=0 or UserDelete is null) and mode in (4)";
rdbHelper = RDBFactory.CreateDbHelper($"{m_nYYSInfo.TaskPackages.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
var dataTable = rdbHelper.ExecuteDatatable("fj", string.Format(strSqlFj, m_nYYSInfo.WYRWTB.TBBSM), true);
if (dataTable != null && dataTable.Rows.Count > 0)
{
string pdfPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(TaskPackage.PackageTempPath), "PDF");
if (!System.IO.Directory.Exists(pdfPath))
{
System.IO.Directory.CreateDirectory(pdfPath);
}
DataTable dt = rdbHelper.ExecuteDatatable("fjgx", $"select fjarg from fjgx where WYTBBSM='{m_nYYSInfo.WYRWTB.TBBSM}' and tbbsm = '{m_nYYSInfo.DTBDLTBGX.BSM}'", true);
List<PhotoInfo> list = JKTBTaskHelper.ToList<PhotoInfo>(dataTable);
foreach (var item in list)
{
try
{
item.ImagePath = System.IO.Path.Combine(pdfPath, item.FJMC.ToString().Trim());
if (!System.IO.File.Exists(item.ImagePath))
{
item.FJ = item.ARG4;
System.IO.File.WriteAllBytes(item.ImagePath, item.ARG4);
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
if (item.ARG == row["fjarg"].ToString())
{
item.SFXZ = 1;
break;
}
else
{
item.SFXZ = 0;
}
}
}
else
{
item.SFXZ = 0;
}
}
catch (Exception ex)
{
LogAPI.Debug(item.FJMC.ToString().Trim() + "外业附件下载失败:" + ex.Message);
}
}
if (list != null && list.Count > 0)
{
List<WyhcfjInfo> fjList = new List<WyhcfjInfo>();
foreach (var item in list)
{
fjList.Add(new WyhcfjInfo(item.BSM.ToString(), item.BSM.ToString(), item.HCJLBSM, item.FJMC, item.ImagePath, item.ARG, item.HCRY, item.PSSJ, item.SFXZ));
}
this.dgdPdf.ItemsSource = fjList;
}
else
{
this.dgdPdf.ItemsSource = null;
}
}
else
{
this.dgdPdf.ItemsSource = null;
}
}
catch (Exception ee)
{
LogAPI.Debug("外业附件BindData ERROR:" + ee.Message);
LogAPI.Debug(ee.Source);
}
finally
{
if (rdbHelper.State == ConnectionState.Open)
{
rdbHelper.DisConnect();
}
rdbHelper = null;
}
}
public void SaveEdit()
{
}
private void addFJButton_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog openFileDialog = null;
try
{
openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Title = "选择新增耕地附件";
openFileDialog.Filter = "新增耕地附件(*.pdf)|*.pdf";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (this.Data == null || this.Data as IFeature == null)
{
MessageHelper.ShowError("添加附件,获取当前图斑异常!");
return;
}
int index = (this.Data as IFeature).Fields.FindField("XZGDFJ");
//打开文件对话框选择的文件
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
(this.Data as IFeature).set_Value(index, DBNull.Value);
return;
}
if (openFileDialog.FileName == null)
{
MessageHelper.ShowError("请选择文件!");
return;
}
string fileNames = string.Join(";", openFileDialog.FileNames);
(this.Data as IFeature).set_Value(index, string.Join(";", openFileDialog.FileNames));
SaveFJTowyhcfj();
Refresh();
}
catch (Exception ex)
{
MessageHelper.ShowError("选择文件异常:" + ex.Message);
LogAPI.Debug("选择文件异常:" + ex);
}
finally
{
if (openFileDialog != null)
{
openFileDialog.Dispose();
}
}
}
//附件文件 保存
private void SaveFJTowyhcfj()
{
string BSM = string.Empty;
string userName = string.Empty;
try
{
DataTable dtXmlx = IRowToDataTable((this.Data as IFeature) as IRow);
int bsmIndex = (this.Data as IFeature).Fields.FindField("TBBSM");
if (bsmIndex > -1)
{
BSM = (this.Data as IFeature).get_Value(bsmIndex) as string;
}
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (prj != null)
userName = prj.UserName;
if (dtXmlx != null && dtXmlx.Rows.Count > 0)
{
object obj = (this.Data as IFeature).get_Value((this.Data as IFeature).Fields.FindField("XZGDFJ"));
if (obj != null && !(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString()))
{
rdbHelper = RDBFactory.CreateDbHelper($"{TaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
string[] files = obj.ToString().Split(';');
string strSql = string.Empty;
foreach (string file in files)
{
string strGuid = Guid.NewGuid().ToString();
var objBsm = rdbHelper.ExecuteScalar($"select bsm from wyhcfj where hcjlbsm = '{dtXmlx.Rows[0]["TBBSM"].ToString()}' and fjmc = '{file.Substring(file.LastIndexOf("\\") + 1)}'", CommandType.Text);
using (System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
IDbDataParameter[] parameters = new IDbDataParameter[6];
if (objBsm == null)
{
strSql = "INSERT INTO WYHCFJ ( HCLX, HCJLBSM, DKID, FJMC, FJLX, MODE,IS_SELECTED, SEQUENCE, SUBTYPE, ARG, ARG4, CJSJ, LENGTH, POINTS_JSON, UserDelete, HCRY ) VALUES ( 'WYRWTB', @HCJLBSM, @HCJLBSM, @FJMC, 'PDF', '4',1, '0', '1', @ARG, @ARG4, @CJSJ, '0', '[]', '0', @HCRY )";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx.Rows[0]["TBBSM"].ToString() };
parameters[1] = new System.Data.SQLite.SQLiteParameter("FJMC", DbType.String) { Value = file.Substring(file.LastIndexOf("\\") + 1) };
parameters[2] = new System.Data.SQLite.SQLiteParameter("ARG", DbType.String) { Value = strGuid };
parameters[3] = new System.Data.SQLite.SQLiteParameter("ARG4", DbType.Binary) { Value = bytes };
parameters[4] = new System.Data.SQLite.SQLiteParameter("CJSJ", DbType.DateTime) { Value = DateTime.Now };
parameters[5] = new System.Data.SQLite.SQLiteParameter("HCRY", DbType.String) { Value = userName };
}
else
{
strSql = "UPDATE WYHCFJ SET ARG = @ARG, ARG4 = @ARG4, CJSJ = @CJSJ WHERE HCJLBSM=@HCJLBSM AND FJMC = @FJMC AND HCRY = @HCRY";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx.Rows[0]["TBBSM"].ToString() };
parameters[1] = new System.Data.SQLite.SQLiteParameter("FJMC", DbType.String) { Value = file.Substring(file.LastIndexOf("\\") + 1) };
parameters[2] = new System.Data.SQLite.SQLiteParameter("ARG", DbType.String) { Value = strGuid };
parameters[3] = new System.Data.SQLite.SQLiteParameter("ARG4", DbType.Binary) { Value = bytes };
parameters[4] = new System.Data.SQLite.SQLiteParameter("CJSJ", DbType.DateTime) { Value = DateTime.Now };
parameters[5] = new System.Data.SQLite.SQLiteParameter("HCRY", DbType.String) { Value = userName };
}
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text, parameters);
rdbHelper.ExecuteNonQueryWithException($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{dtXmlx.Rows[0]["TBBSM"].ToString()}','{strGuid}','{dtXmlx.Rows[0]["BSM"].ToString()}')", CommandType.Text);
fs.Close();
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("保存附件文件异常:" + ex);
}
finally
{
if (rdbHelper.State == ConnectionState.Open)
{
rdbHelper.DisConnect();
}
rdbHelper.Clear();
rdbHelper = null;
}
}
/// <summary>
/// 将IRow转换为DataTable
/// </summary>
/// <param name="mTable"></param>
/// <returns></returns>
public static DataTable IRowToDataTable(IRow row)
{
try
{
DataTable pTable = new DataTable();
for (int i = 0; i < row.Fields.FieldCount; i++)
{
pTable.Columns.Add(row.Fields.get_Field(i).Name);
}
DataRow pRow = pTable.NewRow();
string[] StrRow = new string[row.Fields.FieldCount];
for (int i = 0; i < row.Fields.FieldCount; i++)
{
StrRow[i] = row.get_Value(i).ToString();
}
pRow.ItemArray = StrRow;
pTable.Rows.Add(pRow);
return pTable;
}
catch (Exception ex)
{
throw ex;
}
}
private void deleteFJButton_Click(object sender, RoutedEventArgs e)
{
if (this.dgdPdf.ItemsSource == null) return;
List<WyhcfjInfo> fjList = this.dgdPdf.ItemsSource as List<WyhcfjInfo>;
if (fjList == null || fjList.Count == 0) return;
fjList = fjList.FindAll(a => a.Sfxz == 1);
if (fjList.Count == 0)
{
MessageHelper.ShowTips("请选择附件文件进行删除!");
return;
}
if (MessageHelper.ShowYesNoAndTips("是否删除选中的" + fjList.Count + "个附件文件吗?") != System.Windows.Forms.DialogResult.Yes)
return;
string BSM = string.Empty;
string fileNameXZGDFJ = string.Empty;
try
{
if (this.Data == null || this.Data as IFeature == null)
{
MessageHelper.ShowError("删除附件,获取当前图斑异常!");
return;
}
int bsmIndex = (this.Data as IFeature).Fields.FindField("TBBSM");
if (bsmIndex > -1)
BSM = (this.Data as IFeature).get_Value(bsmIndex) as string;
int indexXZGDFJ = (this.Data as IFeature).Fields.FindField("XZGDFJ");
if (indexXZGDFJ > -1)
fileNameXZGDFJ = (this.Data as IFeature).get_Value(indexXZGDFJ) as string;
rdbHelper = RDBFactory.CreateDbHelper($"{TaskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
foreach (WyhcfjInfo currentWyhcfj in fjList)
{
rdbHelper.ExecuteSQL($"delete from wyhcfj where hcjlbsm = '{BSM}' and fjmc = '{currentWyhcfj.Fjmc}'");
rdbHelper.ExecuteSQL($"delete from fjgx where wytbbsm = '{BSM}' and fjarg = '{currentWyhcfj.Arg}' and tbbsm = '{currentWyhcfj.Bsm}'");
}
Refresh();
}
catch (Exception ex)
{
LogAPI.Debug("删除附件文件异常:" + ex);
}
finally
{
if (rdbHelper.State == ConnectionState.Open)
{
rdbHelper.DisConnect();
}
rdbHelper.Clear();
rdbHelper = null;
}
}
}
}