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

2302 lines
134 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.AE.ExtensionMethod;
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 Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using UIShell.OSGi;
namespace Kingo.Plugin.General.Helper
{
#region 新疆
public class DataOperationHelper_65 : DataOperationHelper_Default
{
private ProjectInfo projectInfo
{
get { return MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; }
}
public DataOperationHelper_65(TreeView _tvPackges) : base(_tvPackges)
{
}
#region 保存单图斑和独立图层数据
/// <summary>
/// 保存单图斑和独立图层数据
/// </summary>
/// <param name="BSM"></param>
/// <param name="rdbHelper"></param>
/// <param name="feature"></param>
public override void SaveBGFWAndDLTC(string tbbsm, string BSM, IRDBHelper rdbHelper, IFeature feature)
{
try
{
DataTable dataTableDetailjson = rdbHelper.ExecuteDatatable("detailjson", $"select * from detailjson where tbbsm = '{tbbsm}' ", true);
DataTable dataTableWYRW = rdbHelper.ExecuteDatatable("wyrw", $"select JCBH from wyrw where tbbsm = '{tbbsm}' ", true);
ILayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑");
ILayer layerPodu = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_省级下发坡度图");
if (string.IsNullOrWhiteSpace(tbbsm) || string.IsNullOrWhiteSpace(BSM))
return;//图斑标识码和标识码不可为空
//判定DTBDLTBGX表中是否有XZGDFJ列 没有则添加
DataTable dataTableDTBDLTB = rdbHelper.ExecuteDatatable("DTBDLTBGX", "select * from DTBDLTBGX", true);
if (dataTableDTBDLTB != null)
{
if (!dataTableDTBDLTB.Columns.Contains("XZGDFJ"))
{
rdbHelper.ExecuteSQL(@"ALTER TABLE DTBDLTBGX ADD COLUMN XZGDFJ text(200);");
}
}
string xzqdm = tbbsm.Substring(0, 6);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBLSYDGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBGFBQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBTTQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBCCWJQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBCZCDYDGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBLMFWGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from PZWJ where bsm='{BSM}'", CommandType.Text);
//rdbHelper.ExecuteNonQueryWithException(string.Format("delete from fjgx where tbbsm='{0}'", BSM), CommandType.Text);
string excuteSQL = "UPDATE DTBDLTBGX SET {0} WHERE BSM='{1}'";
List<string> listField = new List<string>() { "TBBSM", "TBYBH", "DLBM", "KCDLBM", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "GDLX", "XZDWKD", "TBXHDM", "ZZSXDM", "TBXHMC", "GDDB", "CZCSXM", "SJNF", "FRDBS", "MSSM", "EGeometry", "DDTCBZ", "DDTCMC", "SFGX", "WBGYY1", "WBGYY", "SFJZ", "QKSM", "LJLX", "YWTBSM", "NBWQKSM", "SHLZQKSM", "LNGDZB", "SDMSSM", "YDYHFL", "ZGQKSM", "BZ", "SFXML", "XMMC", "XMLX", "XMBH", "DKMC", "CZCTBBH", "LC", "NF", "XZGDFJ", "GXSJ", "LJBZ", "JZYBH", "LJTBBH" };
//独立图层代码
string ddtcbz = string.Empty;
string ddtcmc = string.Empty;
//城镇村属性码
string czcsxm = string.Empty;
//地类编码
string dlbm = string.Empty;
//权属性质
string qsxz = string.Empty;
//权属单位代码
string qsdwdm = string.Empty;
//权属单位名称
string qsdwmc = string.Empty;
//坐落单位代码
string zldwdm = string.Empty;
//坐落单位名称
string zldwmc = string.Empty;
//项目类型
string xmlx = string.Empty;
//种指属性代码
string zzsxdm = string.Empty;
//图斑细化代码
string tbxhdm = string.Empty;
//未变更原因描述
string wbgyyms = string.Empty;
//数据年份
string sjnf = string.Empty;
//求椭圆面积
double mj = Math.Round(feature.ShapeCopy.GetEllipseArea(), 2);
//变更后值
string bgHValue = $"jkry='{(MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).UserName}',tbmj={mj},tbdlmj={mj},gxsj='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', jym = '{GetJym(feature)}', ";
//构建字段值
foreach (string item in listField)
{
int index = feature.Fields.FindField(item);
if (index <= -1)
{
continue;
}
object obj = feature.get_Value(index);
if (!(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString()))
{
if (item.Equals("ddtcbz", StringComparison.CurrentCultureIgnoreCase))
{
ddtcbz = obj.ToString();
}
if (item.Equals("ddtcmc", StringComparison.CurrentCultureIgnoreCase))
{
ddtcmc = obj.ToString();
}
if (item.Equals("CZCSXM", StringComparison.CurrentCultureIgnoreCase))
{
czcsxm = obj.ToString();
}
}
if (item.Equals("XMLX"))
{
xmlx = obj == null ? "" : obj.ToString();
}
if (item.Equals("QSXZ"))
{
qsxz = obj == null ? "" : obj.ToString();
}
if (item.Equals("DLBM"))
{
dlbm = obj == null ? "" : obj.ToString();
}
else if (item.Equals("ZZSXDM"))
{
zzsxdm = obj == null ? "" : obj.ToString();
}
else if (item.Equals("TBXHDM"))
tbxhdm = obj == null ? "" : obj.ToString();
else if (item.Equals("SJNF"))
sjnf = obj == null ? "" : obj.ToString();
IField field = feature.Fields.Field[index];
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeOID:
case esriFieldType.esriFieldTypeBlob:
if (obj == null || obj == DBNull.Value)
{
bgHValue += item + "=0,";
}
else
{
bgHValue += item + "=" + obj + ",";
}
break;
default:
if (item.Equals("KCDLBM", StringComparison.CurrentCultureIgnoreCase))
{
if (!dlbm.StartsWith("01"))
{
bgHValue += item + "='" + "" + "',";
}
else
{
bgHValue += item + "='" + obj + "',";
}
}
else if (item.Equals("WBGYY1", StringComparison.CurrentCultureIgnoreCase))
{
//if (string.IsNullOrEmpty(obj.ToString()))
wbgyyms = obj.ToString();
}
else if (item.Equals("WBGYY", StringComparison.CurrentCultureIgnoreCase))
{
if (obj.ToString() == "其他")
bgHValue += item + "='" + wbgyyms + "',";
else
bgHValue += item + "='" + obj + "',";
}
else if (item.Equals("GDLX", StringComparison.CurrentCultureIgnoreCase))
{
bgHValue += item + "='" + obj + "',";
if (obj != null && (obj.ToString().Equals("TT") || obj.ToString().Equals("PD")))
{
string gdpdjb = "";
int gdpdjbIndex = feature.Fields.FindField("GDPDJB");
if (gdpdjbIndex > -1)
{
object gdpdjbValue = feature.get_Value(gdpdjbIndex);
if (gdpdjbValue != null && !string.IsNullOrEmpty(gdpdjbValue.ToString()))
{
gdpdjb = gdpdjbValue.ToString();
}
else
gdpdjb = GetPojb(feature, layerPodu);
}
else
gdpdjb = GetPojb(feature, layerPodu);
double gdkcxs = DTBDBLoadHelper.GetTKXS(gdpdjb, obj.ToString());
double kcmj = gdkcxs * mj;
double tbdlmj = mj - kcmj;
bgHValue += $"gdpdjb = '{gdpdjb}',kcxs = {gdkcxs}, kcmj = {kcmj}, tbdlmj = {tbdlmj}, ";
}
}
else if ((item.Equals("JZYBH", StringComparison.CurrentCultureIgnoreCase) || item.Equals("TBYBH", StringComparison.CurrentCultureIgnoreCase)) && (obj == null || string.IsNullOrEmpty(obj.ToString())))
{
string JZYBH = string.Empty;
if (CurrentWYRWTB != null) JZYBH = CurrentWYRWTB.JCBH;
else if(dataTableWYRW != null && dataTableWYRW.Rows.Count > 0)
{
JZYBH = dataTableWYRW.Rows[0]["JCBH"].ToString();
}
obj = JZYBH;
bgHValue += item + "='" + obj + "',";
feature.set_Value(index, obj);
}
else if (item.Equals("LJTBBH", StringComparison.CurrentCultureIgnoreCase) && (obj == null || string.IsNullOrEmpty(obj.ToString())))
{
if (dataTableDetailjson != null && dataTableDetailjson.Rows.Count > 0)
{
for (int i = 0; i < dataTableDetailjson.Rows.Count; i++)
{
if (dataTableDetailjson.Rows[i]["Name"].ToString() == "类举图斑编号" || dataTableDetailjson.Rows[i]["Name"].ToString() == "LJTBBH")
{
obj = dataTableDetailjson.Rows[i]["Value"].ToString();
bgHValue += item + "='" + obj + "',";
feature.set_Value(index, obj);
break;
}
}
}
}
else
{
bgHValue += item + "='" + obj + "',";
}
break;
}
}
feature.Store();
string sadff = string.Format(excuteSQL, bgHValue.TrimEnd(','), BSM);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, bgHValue.TrimEnd(','), BSM), CommandType.Text);
//地类名称
string dlmc = string.Empty;
DataDicTionary dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.DLBM).FirstOrDefault(x => x.CODE.Equals(dlbm));
if (dataDicTionary != null)
{
dlmc = dataDicTionary.NAME;
}
//种植属性名称
string zzsxmc = string.Empty;
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.ZZSX).FirstOrDefault(x => x.CODE.Equals(zzsxdm));
if (dataDicTionary != null)
{
zzsxmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}' where bsm='{BSM}'", CommandType.Text);
//单独图层名称
dataDicTionary = Platform.Instance.DicHelper.GetAllDic().FirstOrDefault(x => x.CODE.Equals(ddtcbz));
if (dataDicTionary != null)
{
ddtcmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}' where bsm='{BSM}'", CommandType.Text);
//图斑细化名称
string tbxhmc = string.Empty;
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.TBXHLX).FirstOrDefault(x => x.CODE.Equals(tbxhdm));
if (dataDicTionary != null)
{
tbxhmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}',tbxhmc='{tbxhmc}',qsxz='{qsxz}' where bsm='{BSM}'", CommandType.Text);
//保存独立图层代码
switch (ddtcbz)
{
case "1301"://临时用地2099010100
DataTable dataTable = IRowToDataTable(feature as IRow);
if (dataTable != null && dataTable.Rows.Count > 0)
{
DataRow dr = dataTable.Rows[0];
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBLSYDGX (BSM, DDTCBZ, DDTCMC, YSDM, GLTBBSM, PZWJMC, PZWH, TBMJ, PZMJ, YTFL, JTXMYT, PZRQ, YQSX, TDSYHT, BZ, GXSJ) VALUES('{BSM}', '{ddtcbz}', '{ddtcmc}', '2099010100', '{BSM}', '{dr["PZWJMC_LSYD"]}', '{dr["PZWH_LSYD"]}', {dr["TBMJ"]}, {dr["TBMJ"]}, '{dr["YTFL_LSYD"]}', '{dr["JTXMYT_LSYD"]}', '{dr["PZRQ_LSYD"]}', '{dr["YQSX_LSYD"]}', '{dr["TDSYHT_LSYD"]}', '{dr["BZ"]}', '{dr["GXSJ"]}')", CommandType.Text);
object obj = feature.get_Value(feature.Fields.FindField("PZWJ_LSYD"));
if (obj != null && !(obj is DBNull))
{
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)obj;
object obj1 = null;
varBlobStream.ExportToVariant(out obj1);
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO PZWJ(BSM, Name, Path, Extension) VALUES('{BSM}', '{dr["PZWJMC_LSYD"]}', '', '')", CommandType.Text);
IDbDataParameter[] parameters = new IDbDataParameter[1];
parameters[0] = new System.Data.SQLite.SQLiteParameter("FileContent", DbType.Binary) { Value = obj1 };
rdbHelper.ExecuteNonQueryWithException($"update PZWJ SET FileContent=@FileContent where bsm='{BSM}'", CommandType.Text, parameters);
}
}
break;
case "1302"://光伏板区2099070100
dataTable = IRowToDataTable(feature as IRow);
if (dataTable != null && dataTable.Rows.Count > 0)
{
DataRow dr = dataTable.Rows[0];
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBGFBQGX(BSM, DDTCBZ, DDTCMC, YSDM, XMMC, XMGM, QYMJ, PZYDSJ, BZ, GXSJ) VALUES('{BSM}', '{ddtcbz}', '{ddtcmc}', '2099070100', '{dr["XMMC_GFBQ"]}', '{dr["XMGM_GFBQ"]}', {dr["TBMJ"]}, '{dr["PZYDSJ_GFBQ"]}', '{dr["BZ"]}', '{dr["GXSJ"]}')", CommandType.Text);
}
break;
case "1303"://推土区
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBTTQGX(BSM, DDTCBZ, DDTCMC, YSDM, TTQMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099080100',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
case "1304"://拆除未尽区2099090100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBCCWJQGX (BSM, DDTCBZ, DDTCMC, YSDM, ZDMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099090100',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
case "1305"://路面范围2099100100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBLMFWGX (BSM, DDTCBZ, DDTCMC, YSDM, ZLDWDM, KD, MJ, DLBM, MC, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099100100',zldwdm,xzdwkd,tbmj,dlbm,'',bz,gxsj from dtbdltbgx where bsm='{BSM}';", CommandType.Text);
break;
case "1306"://工厂化种植更新2099120100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO GCHZZGX (BSM,YSDM,ZDMJ,DLBM,DLMC,BZ,GXSJ) select bsm,'2099120100',tbmj,dlbm,'',bz,gxsj from dtbdltbgx where bsm='{BSM}';", CommandType.Text);
break;
case "一般地类":
if (xmlx == "1" || xmlx == "2")
{
DataTable dtXmlx2 = IRowToDataTable(feature as IRow);
if (dtXmlx2 != null && dtXmlx2.Rows.Count > 0)
{
object obj = feature.get_Value(feature.Fields.FindField("XZGDFJ"));
if (obj != null && !(obj is DBNull))
{
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 = '{dtXmlx2.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[5];
if (objBsm == null)
{
strSql = "INSERT INTO WYHCFJ ( HCLX, HCJLBSM, DKID, FJMC, FJLX, MODE,IS_SELECTED, SEQUENCE, SUBTYPE, ARG, ARG4, CJSJ, LENGTH, POINTS_JSON, UserDelete ) VALUES ( 'WYRWTB', @HCJLBSM, @HCJLBSM, @FJMC, 'PDF', '4',1, '0', '1', @ARG, @ARG4, @CJSJ, '0', '[]', '0' )";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx2.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 };
}
else
{
strSql = "UPDATE WYHCFJ SET ARG = @ARG, ARG4 = @ARG4, CJSJ = @CJSJ WHERE HCJLBSM=@HCJLBSM AND FJMC = @FJMC";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx2.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 };
}
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text, parameters);
rdbHelper.ExecuteNonQueryWithException($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{dtXmlx2.Rows[0]["TBBSM"].ToString()}','{strGuid}','{BSM}')", CommandType.Text);
fs.Close();
}
}
}
}
}
break;
}
string czcmc = string.Empty;
//保存城镇村等用地
switch (czcsxm)
{
case "201":
case "201A":
case "202":
case "202A":
case "203":
case "203A":
case "204":
case "205":
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.CZCJGKYD).FirstOrDefault(x => x.CODE.Equals(czcsxm));
if (dataDicTionary != null)
{
czcmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBCZCDYDGX (BSM, DDTCBZ, DDTCMC, YSDM, CZCLX, CZCDM, CZCMC, CZCMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099030100',czcsxm,'{xzqdm.PadRight(19, '0')}','{czcmc}',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
}
////保存附件信息
//object images = feature.get_Value(feature.Fields.FindField("images"));
//if (images != null)
//{
// excuteSQL = "insert into fjgx(WYTBBSM,FJARG,tbbsm)values('{0}','{1}','{2}')";
// foreach (var item in images.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
// {
// rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, tbbsm, item, BSM), CommandType.Text);
// }
//}
//附件文件 保存
DataTable dtXmlx = IRowToDataTable(feature as IRow);
if (dtXmlx != null && dtXmlx.Rows.Count > 0)
{
object obj = feature.get_Value(feature.Fields.FindField("XZGDFJ"));
if (obj != null && !(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString()))
{
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[5];
if (objBsm == null)
{
strSql = "INSERT INTO WYHCFJ ( HCLX, HCJLBSM, DKID, FJMC, FJLX, MODE,IS_SELECTED, SEQUENCE, SUBTYPE, ARG, ARG4, CJSJ, LENGTH, POINTS_JSON, UserDelete ) VALUES ( 'WYRWTB', @HCJLBSM, @HCJLBSM, @FJMC, 'PDF', '4',1, '0', '1', @ARG, @ARG4, @CJSJ, '0', '[]', '0' )";
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 };
}
else
{
strSql = "UPDATE WYHCFJ SET ARG = @ARG, ARG4 = @ARG4, CJSJ = @CJSJ WHERE HCJLBSM=@HCJLBSM AND FJMC = @FJMC";
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 };
}
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text, parameters);
rdbHelper.ExecuteNonQueryWithException($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{dtXmlx.Rows[0]["TBBSM"].ToString()}','{strGuid}','{BSM}')", CommandType.Text);
fs.Close();
}
}
}
}
//根据图斑面积面积,限制外业照片、视频数量
string strTbmj = string.Empty;
int tbmjIndex = feature.Fields.FindField("TBMJ");
if (tbmjIndex > -1)
{
strTbmj = feature.get_Value(tbmjIndex).ToString();
DataTable dtFj = rdbHelper.ExecuteDatatable("wyhcfj", $"select sum(case when mode in ('5') then 1 else 0 end) as videocount,sum(case when mode not in ('4','5') then 1 else 0 end) as imagecount from wyhcfj a inner join fjgx b on a.hcjlbsm=b.wytbbsm and b.fjarg = a.arg and b.tbbsm ='{BSM}' where HCJLBSM='{tbbsm}' and (UserDelete <> 1 or UserDelete is not null)", true);
if (!string.IsNullOrEmpty(strTbmj) && dtFj != null && dtFj.Rows.Count > 0)
{
int imageCount = 0, videoCount = 0;
if (dtFj.Rows[0]["imagecount"] != null && !string.IsNullOrEmpty(dtFj.Rows[0]["imagecount"].ToString()))
{
imageCount = int.Parse(dtFj.Rows[0]["imagecount"].ToString());
}
if (dtFj.Rows[0]["videocount"] != null && !string.IsNullOrEmpty(dtFj.Rows[0]["videocount"].ToString()))
{
videoCount = int.Parse(dtFj.Rows[0]["videocount"].ToString());
}
decimal tbmj = (Convert.ToDouble(strTbmj) / 666.67).ToDecimal(2);
if (tbmj <= 5)
{
if (imageCount > 15 || videoCount > 2)
{
//MessageHelper.Show("图斑面积小于5亩时,外业照片数量超过15张,或者外业视频数量超过2段");
LogAPI.Debug("图斑面积小于5亩时,外业照片数量超过15张,或者外业视频数量超过2段");
return;
}
}
if (5 < tbmj && tbmj <= 20)
{
if (imageCount > 30 || videoCount > 5)
{
//MessageHelper.Show("图斑面积大于5亩小于等于20亩时,外业照片数量超过30张,或者外业视频数量超过5段");
LogAPI.Debug("图斑面积大于5亩小于等于20亩时,外业照片数量超过30张,或者外业视频数量超过5段");
return;
}
}
if (tbmj > 20)
{
if (imageCount > 50 || videoCount > 7)
{
//MessageHelper.Show("图斑面积大于20亩时,外业照片数量超过50张,或者外业视频数量超过7段");
LogAPI.Debug("图斑面积大于20亩时,外业照片数量超过50张,或者外业视频数量超过7段");
return;
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("DataOperationHelper_65.SaveBGFWAndDLTC 异常" + ex.Message);
LogAPI.Debug("DataOperationHelper_65.SaveBGFWAndDLTC 异常" + ex.StackTrace);
throw ex;
}
}
#endregion
#region 初始化界面
/// <summary>
/// 加载单图斑属性数据
/// </summary>
public override ObservableCollection<TreeNode> LoadTreeData()
{
ObservableCollection<TreeNode> DataSource = new ObservableCollection<TreeNode>();
LayerCfg LayerCfg = null;
try
{
TreeNode parentNodes = new TreeNode()
{
Name = $"单图斑任务列表(0个)",
Paixu = 0,
IsExpanded = true,
Icon = "pack://application:,,,/Kingo.Plugin.DTBJK;component/Resources/列表.png",
NodeLevel = 0,
NodeID = Guid.NewGuid().ToString().Replace("-", ""),
Data = null,
IsOpenEdit = true,
ParentButtonVisibility = Visibility.Visible,
Nodes = new ObservableCollection<TreeNode>()
};
#region 单图斑建库任务矢量加载
IDataCatalogService DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
object LayerCfgobj = DataCatalog.CurrentLayers;
int TCXH = 1;//任务序号
if (LayerCfgobj is LayerCfg)
{
LayerCfg = (LayerCfgobj as LayerCfg).Layers.FirstOrDefault(f => f.LayerName == "监测数据" && f.LayerType == EnumLayerType.GroupLayer);
if (LayerCfg != null)
{
foreach (var LayerCfgitem in LayerCfg.Layers)
{
if (LayerCfgitem.Data is FeatureLayer)
{
IFeatureLayer JCTBFeaLayer = LayerCfgitem.Data as FeatureLayer;
IQueryFilter queryFilter = new QueryFilterClass();
if (JCTBFeaLayer is IFeatureLayerDefinition pFLDefinition)
{
queryFilter.WhereClause = pFLDefinition.DefinitionExpression;
}
var jctbcount = JCTBFeaLayer.FeatureClass.FeatureCount(queryFilter);
if (JCTBFeaLayer == null || JCTBFeaLayer.FeatureClass == null || jctbcount == 0) continue;
TreeNode parentNode = new TreeNode()//图层数据一级(类似任务包一级)
{
Name = $"{LayerCfgitem.LayerName}({jctbcount}个)",
Paixu = TCXH++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBJK;component/Resources/数据检查.png",
NodeLevel = 1,
NodeID = Guid.NewGuid().ToString().Replace("-", ""),
Data = LayerCfgitem.Data,
ParentNode = parentNodes,
ParentButtonVisibility = Visibility.Collapsed,
Nodes = new ObservableCollection<TreeNode>(),
LoadingVisibility = Visibility.Collapsed,
OpenPackageVisibility = Visibility.Visible
};
parentNodes.Nodes.Add(parentNode);
}
}
parentNodes.Name = "单图斑任务列表(" + parentNodes.Nodes.Count + "个)";
}
#region 变更范围注释
//if (LayerCfgobj != null)
//{
// LayerCfg = (LayerCfgobj as LayerCfg).Layers.FirstOrDefault(f => f.LayerName == "变更数据" && f.LayerType == EnumLayerType.GroupLayer);
// foreach (var LayerCfgitem in LayerCfg.Layers)
// {
// if (LayerCfgitem.Data is FeatureLayer)
// {
// if (LayerCfgitem.FcName != "DLTBBG") continue;
// IFeatureLayer JCTBFeaLayer = LayerCfgitem.Data as FeatureLayer;
// IQueryFilter queryFilter = new QueryFilterClass();
// if (JCTBFeaLayer is IFeatureLayerDefinition pFLDefinition)
// {
// queryFilter.WhereClause = " SJLY='' OR SJLY is NULL";
// }
// var tbcount = JCTBFeaLayer.FeatureClass.FeatureCount(queryFilter);
// if (JCTBFeaLayer == null || JCTBFeaLayer.FeatureClass == null || tbcount == 0) continue;
// TreeNode parentNode = new TreeNode()
// {
// Name = $"{LayerCfgitem.LayerName}({tbcount}个)",
// Paixu = TCXH++,
// IsExpanded = false,
// Icon = "pack://application:,,,/Kingo.Plugin.DTBJK;component/Resources/数据检查.png",
// NodeLevel = 1,
// NodeID = Guid.NewGuid().ToString().Replace("-", ""),
// Data = LayerCfgitem.Data,
// ParentNode = parentNodes,
// ParentButtonVisibility = Visibility.Collapsed,
// Nodes = new ObservableCollection<TreeNode>(),
// LoadingVisibility = Visibility.Collapsed,
// OpenPackageVisibility = Visibility.Visible
// };
// parentNodes.Nodes.Add(parentNode);
// }
// }
// parentNodes.Name = "单图斑任务列表(" + parentNodes.Nodes.Count + "个)";
//}
#endregion
}
#endregion
#region 单图斑建库任务包加载
SyncPackage(projectInfo.TaskPath);
if (projectInfo.ListTaskPackage != null && projectInfo.ListTaskPackage.Count != 0)
{
List<TaskPackage> lstDelete = new List<TaskPackage>();
foreach (TaskPackage item in projectInfo.ListTaskPackage)
{
if (string.IsNullOrWhiteSpace(item.PackagePath) || !File.Exists(item.PackagePath))
{
lstDelete.Add(item);
continue;
}
string fileName = System.IO.Path.GetFileName(item.PackagePath);
if (item.BID == null || string.IsNullOrWhiteSpace(item.BID.ToString()))
{
item.BID = Guid.NewGuid().ToString().Replace("-", "");
}
TreeNode treeNode = new TreeNode()
{
Name = fileName + "(" + item.TBCount + "个)",
Paixu = TCXH++,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.DTBJK;component/Resources/数据检查.png",
NodeID = Guid.NewGuid().ToString().Replace("-", ""),
NodeLevel = 1,
Data = item,//可区分任务类型
ParentNode = parentNodes,
LoadingVisibility = Visibility.Collapsed,
OpenPackageVisibility = Visibility.Visible,
UncompletedCount = item.WWCCount,
CompletedCount = item.WCCount
};
parentNodes.Nodes.Add(treeNode);
}
foreach (var item in lstDelete)
{
projectInfo.ListTaskPackage.Remove(item);
}
parentNodes.Name = "单图斑任务列表(" + parentNodes.Nodes.Count + "个)";
DataSource = new ObservableCollection<TreeNode>();
projectInfo.Save();
}
#endregion
DataSource.Add(parentNodes);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("任务包加载失败:" + ex.Message);
}
TreeDataSource = DataSource;
return DataSource;
}
#endregion
#region 同步任务目录文件夹任务包文件
/// <summary>
/// 同步任务目录文件夹任务包文件
/// </summary>
/// <param name="dbPath"></param>
/// <returns></returns>
public override void SyncPackage(string taskPath)
{
try
{
if (string.IsNullOrWhiteSpace(taskPath) || !Directory.Exists(taskPath))
{
projectInfo.ListTaskPackage = new List<TaskPackage>();
return;
}
if (projectInfo.ListTaskPackage == null)
{
projectInfo.ListTaskPackage = new List<TaskPackage>();
}
DirectoryInfo directory = new DirectoryInfo(System.IO.Path.Combine(taskPath, "未完成"));
string filter = "*.jkrw";
if (Platform.Instance.SystemType == SystemTypeEnum.WYZS)
{
filter = "*.shrw";
}
FileInfo[] files = directory.GetFiles(filter, SearchOption.AllDirectories);
if (files == null || files.Length <= 0)
{
return;
}
foreach (var item in files)
{
IRDBHelper rdbHelper = null;
try
{
TaskPackage taskPackage = projectInfo.ListTaskPackage.FirstOrDefault(x => x.PackagePath.Equals(item.FullName));
if (taskPackage != null && !string.IsNullOrWhiteSpace(taskPackage.PackageTempPath) && System.IO.File.Exists(taskPackage.PackageTempPath))
{
try
{
if (taskPackage.State.Equals("已输出"))
{
File.Delete(item.FullName);
}
}
catch
{
}
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
FileInfo file = new FileInfo(taskPackage.PackageTempPath);
if (file.IsReadOnly)
{
LogAPI.Debug($"选择的单图斑建库任务包{taskPackage.PackageTempPath}不允许是只读文件!");
throw new Exception("选择的单图斑建库任务包不允许是只读文件!");
}
}
else
{
rdbHelper = RDBFactory.CreateDbHelper($"{item.FullName}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
FileInfo file = new FileInfo(item.FullName);
if (file.IsReadOnly)
{
LogAPI.Debug($"选择的单图斑建库任务包{item.FullName}不允许是只读文件!");
throw new Exception("选择的单图斑建库任务包不允许是只读文件!");
}
}
if (!rdbHelper.TableIsExist("wyrw"))
{
throw new Exception("选择的单图斑建库任务包不存在外业任务(WYRW)表!");
}
if (!rdbHelper.TableIsExist("YSJ"))
{
throw new Exception("选择的单图斑建库任务包不存在元数据(YSJ)表!");
}
CheckTableExist(rdbHelper);
DataTable dataTable = rdbHelper.ExecuteDatatable("ysj", "select * from ysj", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
throw new Exception("选择的单图斑建库任务包元数据(YSJ)表数据为空!");
}
dataTable = rdbHelper.ExecuteDatatable("wyrw", "select ZT,TBBSM from wyrw", true);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
throw new Exception("选择的单图斑建库任务包外业任务表数据为空!");
}
//rdbHelper.ExecuteNonQueryWithException("update dtbdltbgx set ddtcbz='一般地类',ddtcmc='一般地类' where ddtcbz is null or ddtcbz=''", CommandType.Text);
foreach (DataRow dataRow in dataTable.Rows)
{
//如果单图斑一条数据都没有,则把外业任务图斑拷贝到DTBDLTBGX表中,作为一个默认的变更范围
long tbCount = (long)rdbHelper.ExecuteScalar($"select count(1) from dtbdltbgx where tbbsm='{dataRow["tbbsm"]}'", CommandType.Text);
if (tbCount <= 0)
{
string sql = $"INSERT INTO dtbdltbgx (BSM,TBBSM,EGeometry,ZXDX,ZXDY,MAXX,MAXY,MINX,MINY,JKRY,DLBM,ZZSXDM,TBXHDM,DDTCBZ,GDLX,XZDWKD,TBMJ,YDYHFL,BZ) SELECT '{Guid.NewGuid().ToString().Replace("-", "")}' as BSM,A.TBBSM,A.EGeometry,A.ZXDX,A.ZXDY,A.MAXX,A.MAXY,A.MINX,A.MINY,'{projectInfo.UserName}' as JKRY,(case when length(b.HCBGDL)>4 then substr(b.HCBGDL,0,5) else B.HCBGDL end) as HCBGDL,B.ZZSX,B.TBXHSX,(case when length(replace(B.DDTCXX,' ',''))<4 then '一般地类' else replace(B.DDTCXX,' ','') end) as DDTCBZ,B.GDLX,cast(B.XZDLKD as numeric) as XZDWKD,(A.TBMJ*666.67) AS TBMJ,b.YDYHFL AS YDYHFL,b.XJBZ AS XJBZ FROM WYRW A LEFT JOIN WYHCCG B ON A.TBBSM = B.HCRWBSM where tbbsm = '{dataRow["tbbsm"]}' LIMIT 1;";
rdbHelper.ExecuteNonQueryWithException(sql, CommandType.Text);
}
}
if (taskPackage == null)
{
projectInfo.ListTaskPackage.Add(
new TaskPackage()
{
BID = Guid.NewGuid().ToString().Replace("-", ""),
YWLX = UserLoginHelper.GetAppsetingValueByKey("JkTaskDBYWLX"),
PackagePath = item.FullName,
State = "未完成",
TBCount = $"({dataTable.Select("ZT=''").Length}/{dataTable.Rows.Count})",
WCCount = dataTable.Select("ZT='已完成'").Length,
WWCCount = dataTable.Select("ZT<>'已完成' and ZT<>'已上传' and ZT<>'已输出'").Length
});
}
else
{
taskPackage.TBCount = $"({dataTable.Select("ZT=''").Length}/{dataTable.Rows.Count})";
taskPackage.WCCount = dataTable.Select("ZT='已完成'").Length;
taskPackage.WWCCount = dataTable.Select("ZT<>'已完成' and ZT<>'已上传' and ZT<>'已输出'").Length;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowTips(item + "无法添加:" + ex.Message);
MessageHelper.ShowTips(item + "无法添加:" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
rdbHelper = null;
}
}
}
projectInfo.Save();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
#endregion
#region 工具栏修改数据后,点击保存时更新任务包数据
/// <summary>
/// 工具栏修改数据后,点击保存时更新任务包数据
/// </summary>
/// <param name="differenceCursorEx"></param>
/// <param name="modifiedClass"></param>
/// <param name="rdbHelper"></param>
/// <param name="type">0:新增 1:修改 2:删除</param>
public override void UpdateData(IDifferenceCursorEx differenceCursorEx, IRDBHelper rdbHelper, int type)
{
//准备输入参数
int featureOID = -1;
//新图形
IRow sourceRow = null;
//旧图形
IRow differenceRow = null;
//变化字段
ILongArray longArray = null;
// 获取
differenceCursorEx.Next(out featureOID, out sourceRow, out differenceRow, out longArray);
// 获取编辑图形信息
while (featureOID != -1)
{
int bsmIndex = -1;
string excuteSQL = string.Empty;
try
{
string bsm = string.Empty;
switch (type)
{
case 0://0:新增
AddFeature(sourceRow as IFeature, rdbHelper);
break;
case 1://1:修改
AddFeature(sourceRow as IFeature, rdbHelper);
break;
case 2://2:删除
bsmIndex = differenceRow.Fields.FindField("BSM");
int jcbhIndex = differenceRow.Fields.FindField("JCBH");
int tbbsmIndex = differenceRow.Fields.FindField("TBBSM");
int sjlyIndex = differenceRow.Fields.FindField("SJLY");
string JCBHValue = "";
if (bsmIndex > -1)
{
bsm = differenceRow.get_Value(bsmIndex) as string;
}
if (jcbhIndex != -1)
{
JCBHValue = differenceRow.Value[jcbhIndex].ToString();
}
else if (tbbsmIndex != -1)
{
JCBHValue = differenceRow.Value[tbbsmIndex].ToString();
}
TreeNode treeNode = GetNodeByName(TreeDataSource[0], bsm, new List<int>() { 3 });
if (treeNode != null && treeNode.NodeLevel == 3)
{
TreeNode parNode = treeNode.ParentNode;
if (parNode != null)
{
IsAutoSaveEdit = false;//暂时作为避免再次触发保存
parNode.Nodes.Remove(treeNode);
if (parNode.PackageNode.Name.StartsWith("变更范围"))
{
//变更范围删除图斑更新二级节点信息
}
else if (parNode.Data is DataRow)
{
parNode.Name = (parNode.Data as DataRow)["JCBH"].ToString() + $"({parNode.Nodes.Count})";
}
else if (parNode.Data is WYRWTB)
{
parNode.Name = (parNode.Data as WYRWTB).TBBSM.ToString() + $"({parNode.Nodes.Count})";
excuteSQL = "delete from {0} where bsm='{1}'";
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBDLTBGX", bsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBCCWJQGX", bsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBCZCDYDGX", bsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBDLTBGXGC where BGHTBBSM ='{bsm}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBGFBQGX", bsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBLMFWGX", bsm), CommandType.Text);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, "DTBLSYDGX", bsm), CommandType.Text);
//rdbHelper.ExecuteNonQueryWithException($"delete from FJGX where TBBSM ='{bsm}'", CommandType.Text);
//rdbHelper.ExecuteNonQueryWithException($"delete from FJGX where tbbsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from PZWJ where bsm not in(select bsm from DTBDLTBGX);", CommandType.Text);
(DtbFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("DELETE FROM TTQGX where BSM = '" + bsm + "'");
}
IsAutoSaveEdit = true;
}
}
treeNode = GetNodeByName(TreeDataSource[0], JCBHValue, new List<int>() { 2 });
if (sjlyIndex != -1 && treeNode != null && treeNode.NodeLevel == 2)
{
//仅仅修改任务图斑中ZZTB类型数据
if (differenceRow.Value[sjlyIndex].ToString() == "ZZTB")
{
rdbHelper.ExecuteNonQueryWithException($"delete from WYRW where JCBH='{JCBHValue}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from dtbdltbgx where TBBSM='{JCBHValue}'", CommandType.Text);
TreeNode parNode = treeNode.ParentNode;
IsAutoSaveEdit = false;//暂时作为避免再次触发保存
parNode.Nodes.Remove(treeNode);
IsAutoSaveEdit = true;
}
}
break;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
differenceCursorEx.Next(out featureOID, out sourceRow, out differenceRow, out longArray);
}
}
#endregion
#region 新增图斑
/// <summary>
/// 新增图斑(单图斑新增与修改合并)
/// </summary>
public override void AddFeature(IFeature Newfeature, IRDBHelper rdbHelper)
{
try
{
if (Newfeature == null || Newfeature.Shape == null || Newfeature.Shape.IsEmpty) return;
IFeature featureTBBSM = null;
List<IFeature> features = null;
try
{
object LayerCfgobj = DataCatalog.CurrentLayers;
if (LayerCfgobj is LayerCfg && rdbHelper == null)//矢量数据类型
{
LayerCfg jcsj = (LayerCfgobj as LayerCfg).Layers.FirstOrDefault(f => f.LayerName == "监测数据" && f.LayerType == EnumLayerType.GroupLayer);
if (jcsj == null) return;//获取所有的监测数据图层
string JCBHValue = string.Empty;
foreach (LayerCfg itemCfg in jcsj.Layers)
{
features = FeatureAPI.Identify(Newfeature.ShapeCopy, itemCfg.Data as IFeatureLayer);
if (features != null && features.Count > 0)
{
//如果仅压盖到了一个,则挂接到该外业任务图斑
if (features.Count == 1)
{
featureTBBSM = features[0];
}
else if (features.Count > 1)
{
double _area = -1;
foreach (IFeature item in features)
{
//areaas1 = item.ShapeCopy as IArea;
IGeometry geometry = DtbFeatureLayer.FeatureClass.GetFeature(Newfeature.OID).ShapeCopy;
//此处报错可能是空间参考坐标系不一致
double interArea = FeatureAPI.GetInterArea(geometry, item.ShapeCopy);
if (_area < interArea)
{
_area = interArea;
featureTBBSM = item;
}
}
}
int index = featureTBBSM.Fields.FindField("JCBH");
if (index > -1)
{
object obj = featureTBBSM.get_Value(index);
JCBHValue = obj == null ? "" : obj.ToString();
break;
}
}
}
int tbBSMIndex = Newfeature.Fields.FindField("TBBSM");
int tbbhIndex = Newfeature.Fields.FindField("TBYBH");
int bsmIndex = Newfeature.Fields.FindField("BSM");
int tbmjIndex = Newfeature.Fields.FindField("TBMJ");
int zldwdmIndex = Newfeature.Fields.FindField("ZLDWDM");
int jckzldwdmIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("ZLDWDM");
int qsdwdmIndex = Newfeature.Fields.FindField("QSDWDM");
int jckqsdwdmIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSDWDM");
int zldwmcIndex = Newfeature.Fields.FindField("ZLDWMC");
int jckzldwmcIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("ZLDWMC");
int qsdwmcIndex = Newfeature.Fields.FindField("QSDWMC");
int jckqsdwmcIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSDWMC");
int qsxzIndex = Newfeature.Fields.FindField("QSXZ");
int jckqsxzIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSXZ");
try
{ //继承基础库权属及性质
List<IFeature> featureJCKs = FeatureAPI.Identify2(Newfeature.ShapeCopy, DtbFeatureLayer);
double _area2 = -1;
IFeature featureJCK = null;
foreach (IFeature itemF in featureJCKs)
{
if (featureJCKs.Count == 1)
{
featureJCK = itemF;
}
else
{
//此处报错可能是空间参考坐标系不一致
double interArea = FeatureAPI.GetInterArea(Newfeature.ShapeCopy, itemF.ShapeCopy);
if (_area2 < interArea)
{
_area2 = interArea;
featureJCK = itemF;
}
}
}
if (featureJCK != null && jckqsxzIndex != -1 && jckqsdwmcIndex != -1 && jckqsdwdmIndex != -1)
{
//属性不为空 不继承基础库的属性
if (string.IsNullOrEmpty(Newfeature.Value[qsdwdmIndex].ToTrim()))
Newfeature.Value[qsdwdmIndex] = featureJCK.Value[jckqsdwdmIndex];
if (string.IsNullOrEmpty(Newfeature.Value[qsdwmcIndex].ToTrim()))
Newfeature.Value[qsdwmcIndex] = featureJCK.Value[jckqsdwmcIndex];
if (string.IsNullOrEmpty(Newfeature.Value[zldwmcIndex].ToTrim()))
Newfeature.Value[zldwmcIndex] = featureJCK.Value[jckzldwmcIndex];
if (string.IsNullOrEmpty(Newfeature.Value[zldwdmIndex].ToTrim()))
Newfeature.Value[zldwdmIndex] = featureJCK.Value[jckzldwdmIndex];
if (string.IsNullOrEmpty(Newfeature.Value[qsxzIndex].ToTrim()))
Newfeature.Value[qsxzIndex] = featureJCK.Value[jckqsxzIndex];
}
}
catch (Exception ex)
{
LogAPI.Debug("继承基础库属性异常:" + ex.Message);
}
Newfeature.Value[tbbhIndex] = JCBHValue;//图斑编号
if (featureTBBSM != null)
Newfeature.Value[tbBSMIndex] = featureTBBSM.Value[featureTBBSM.Fields.FindField("TBBSM")].ToString();//图斑标识码
IArea area1 = Newfeature.ShapeCopy as IArea;
Newfeature.Value[tbmjIndex] = Math.Round(area1.Area, 2);//图斑面积
Newfeature.Value[bsmIndex] = Guid.NewGuid().ToTrim().Replace("-", "").Substring(0, 18);
Newfeature.Store();
TreeNode treeNode = GetNodeByName(TreeDataSource[0], JCBHValue.Trim(), new List<int>() { 2 });
if (treeNode == null) return;
//节点修改
if (treeNode.Nodes.FirstOrDefault(x => x.NodeID.ToInt() == Newfeature.OID) == null)
{
TreeNode bgfwNode = new TreeNode()//第四级-变更图斑
{
Name = Newfeature.Value[bsmIndex] as string,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeID = Newfeature.OID,
NodeLevel = 3,
Data = Newfeature,
ParentNode = treeNode,
PackageNode = treeNode.PackageNode,
PackageState = "未完成",//新增图斑默认为“未完成”状态
LoadingVisibility = Visibility.Collapsed
};
treeNode.Nodes.Add(bgfwNode);
treeNode.PackageState = GetNodesJCZT(treeNode);
treeNode.Name = Newfeature.Value[tbbhIndex] + $"({treeNode.Nodes.Count})";
}
else
{
TreeNode node = treeNode.Nodes.FirstOrDefault(x => x.NodeID.ToInt() == Newfeature.OID);
node.NodeID = Newfeature.OID;
node.Data = Newfeature;
node.Name = Newfeature.Value[bsmIndex] as string;
}
//循环判断变更图斑图形是否存在,不存在则删除变更范围节点
if (treeNode.Nodes.Count > 0)
{
List<TreeNode> deleteList = new List<TreeNode>();
foreach (var item in treeNode.Nodes)
{
try
{
DtbFeatureLayer.FeatureClass.GetFeature(item.NodeID.ToInt());
}
catch (Exception ex)
{
LogAPI.Debug("新增节点获取图层失败(不处理):" + ex);
deleteList.Add(item);
}
}
IsAutoSaveEdit = false;//暂时作为避免再次触发保存
foreach (var item in deleteList)
{
treeNode.Nodes.Remove(item);
}
IsAutoSaveEdit = true;
}
}
else if (Newfeature.Class.AliasName == "单图斑地类图斑更新" && rdbHelper != null)//任务包类型数据
{
//获取当前变更图斑对应的外业任务图斑
string BSMValue = string.Empty;
string tblx = string.Empty;
int dlbmIndex = Newfeature.Fields.FindField("TBBSM");//地类编码
if (dlbmIndex > -1)
{
BSMValue = Newfeature.get_Value(dlbmIndex).ToString();
}
if (string.IsNullOrWhiteSpace(BSMValue) && CurrentWYRWTB != null)
{
//BSMValue = GetTBBSM(Newfeature, ref tblx);
if (string.IsNullOrWhiteSpace(BSMValue))
BSMValue = CurrentWYRWTB.TBBSM;
}
GenerNewData(Newfeature, rdbHelper, BSMValue);
UpdateKCXS(Newfeature, rdbHelper, BSMValue);
}
else if (Newfeature.Class.AliasName == "外业图斑" && rdbHelper != null)
{
string jcbhValue = string.Empty;
int jcbhIndex = Newfeature.Class.FindField("JCBH");
int sjlyIndex = Newfeature.Class.FindField("SJLY");
if (!Newfeature.Value[sjlyIndex].ToString().Contains("ZZTB") && !string.IsNullOrWhiteSpace(Newfeature.Value[sjlyIndex].ToString()))
{
if (EngineEditorBG != null)
EngineEditorBG.StopEditing(false);
return;//非新增任务图斑修改不保存
}
bool NewJCBH = false;
jcbhValue = Newfeature.Value[jcbhIndex].ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
IJKTBTask GetRWTBDataHelper = new JKTBTaskHelper();
jcbhValue = GetRWTBDataHelper.GetRWTBSEQ(projectInfo.CODE, CurrentTaskPackage.YWLX).ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
MessageHelper.ShowTips("接口获取“JCBH”失败!");
return;
}
NewJCBH = true;
}
#region 分割任务图斑情况
//如果是分割图斑,两个要素jcbhValue是一样的,判断存在多个图斑,则也需要重新赋值jcbhValue
if (!NewJCBH)
{
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"JCBH='{jcbhValue}'"
};
ICursor cursor = (Newfeature.Class as ITable).Search(queryFilter, false);
int count = 0;
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
count++;
if (count > 1)
{
IJKTBTask GetRWTBDataHelper = new JKTBTaskHelper();
jcbhValue = GetRWTBDataHelper.GetRWTBSEQ(projectInfo.CODE, CurrentTaskPackage.YWLX).ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
MessageHelper.ShowTips("接口获取“JCBH”失败!");
return;
}
NewJCBH = true;
break;
}
}
}
#endregion
GenerWYTBNewData(Newfeature, rdbHelper, jcbhValue, NewJCBH);
}
}
catch (Exception ex)
{
LogAPI.Debug("新增/修改图斑发生错误:" + ex.Message);
LogAPI.Debug("可能原因为:空间参考不一样所致");
LogAPI.Debug(ex.StackTrace);
}
finally
{
if (features != null)
{
foreach (var item in features)
{
Marshal.ReleaseComObject(item);
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
}
}
#endregion
#region 新增图斑
/// <summary>
/// 新增图斑(单图斑新增与修改合并)
/// </summary>
public override void UpdateFeatureAttribute(IFeature Newfeature, IRDBHelper rdbHelper)
{
try
{
if (Newfeature == null || Newfeature.Shape == null || Newfeature.Shape.IsEmpty) return;
IFeature featureTBBSM = null;
List<IFeature> features = null;
try
{
object LayerCfgobj = DataCatalog.CurrentLayers;
if (LayerCfgobj is LayerCfg && rdbHelper == null)//矢量数据类型
{
LayerCfg jcsj = (LayerCfgobj as LayerCfg).Layers.FirstOrDefault(f => f.LayerName == "监测数据" && f.LayerType == EnumLayerType.GroupLayer);
if (jcsj == null) return;//获取所有的监测数据图层
string JCBHValue = string.Empty;
foreach (LayerCfg itemCfg in jcsj.Layers)
{
features = FeatureAPI.Identify(Newfeature.ShapeCopy, itemCfg.Data as IFeatureLayer);
if (features != null && features.Count > 0)
{
//如果仅压盖到了一个,则挂接到该外业任务图斑
if (features.Count == 1)
{
featureTBBSM = features[0];
}
else if (features.Count > 1)
{
double _area = -1;
foreach (IFeature item in features)
{
//areaas1 = item.ShapeCopy as IArea;
IGeometry geometry = DtbFeatureLayer.FeatureClass.GetFeature(Newfeature.OID).ShapeCopy;
//此处报错可能是空间参考坐标系不一致
double interArea = FeatureAPI.GetInterArea(geometry, item.ShapeCopy);
if (_area < interArea)
{
_area = interArea;
featureTBBSM = item;
}
}
}
int index = featureTBBSM.Fields.FindField("JCBH");
if (index > -1)
{
object obj = featureTBBSM.get_Value(index);
JCBHValue = obj == null ? "" : obj.ToString();
break;
}
}
}
int tbBSMIndex = Newfeature.Fields.FindField("TBBSM");
int tbbhIndex = Newfeature.Fields.FindField("TBYBH");
int bsmIndex = Newfeature.Fields.FindField("BSM");
int tbmjIndex = Newfeature.Fields.FindField("TBMJ");
int zldwdmIndex = Newfeature.Fields.FindField("ZLDWDM");
int jckzldwdmIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("ZLDWDM");
int qsdwdmIndex = Newfeature.Fields.FindField("QSDWDM");
int jckqsdwdmIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSDWDM");
int zldwmcIndex = Newfeature.Fields.FindField("ZLDWMC");
int jckzldwmcIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("ZLDWMC");
int qsdwmcIndex = Newfeature.Fields.FindField("QSDWMC");
int jckqsdwmcIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSDWMC");
int qsxzIndex = Newfeature.Fields.FindField("QSXZ");
int jckqsxzIndex = DtbFeatureLayer.FeatureClass.Fields.FindField("QSXZ");
try
{ //继承基础库权属及性质
List<IFeature> featureJCKs = FeatureAPI.Identify2(Newfeature.ShapeCopy, DtbFeatureLayer);
double _area2 = -1;
IFeature featureJCK = null;
foreach (IFeature itemF in featureJCKs)
{
if (featureJCKs.Count == 1)
{
featureJCK = itemF;
}
else
{
//此处报错可能是空间参考坐标系不一致
double interArea = FeatureAPI.GetInterArea(Newfeature.ShapeCopy, itemF.ShapeCopy);
if (_area2 < interArea)
{
_area2 = interArea;
featureJCK = itemF;
}
}
}
if (featureJCK != null && jckqsxzIndex != -1 && jckqsdwmcIndex != -1 && jckqsdwdmIndex != -1)
{
//属性不为空 不继承基础库的属性
if (string.IsNullOrEmpty(Newfeature.Value[qsdwdmIndex].ToTrim()))
Newfeature.Value[qsdwdmIndex] = featureJCK.Value[jckqsdwdmIndex];
if (string.IsNullOrEmpty(Newfeature.Value[qsdwmcIndex].ToTrim()))
Newfeature.Value[qsdwmcIndex] = featureJCK.Value[jckqsdwmcIndex];
if (string.IsNullOrEmpty(Newfeature.Value[zldwmcIndex].ToTrim()))
Newfeature.Value[zldwmcIndex] = featureJCK.Value[jckzldwmcIndex];
if (string.IsNullOrEmpty(Newfeature.Value[zldwdmIndex].ToTrim()))
Newfeature.Value[zldwdmIndex] = featureJCK.Value[jckzldwdmIndex];
if (string.IsNullOrEmpty(Newfeature.Value[qsxzIndex].ToTrim()))
Newfeature.Value[qsxzIndex] = featureJCK.Value[jckqsxzIndex];
}
}
catch (Exception ex)
{
LogAPI.Debug("继承基础库属性异常:" + ex.Message);
}
Newfeature.Value[tbbhIndex] = JCBHValue;//图斑编号
if (featureTBBSM != null)
Newfeature.Value[tbBSMIndex] = featureTBBSM.Value[featureTBBSM.Fields.FindField("TBBSM")].ToString();//图斑标识码
IArea area1 = Newfeature.ShapeCopy as IArea;
Newfeature.Value[tbmjIndex] = Math.Round(area1.Area, 2);//图斑面积
Newfeature.Value[bsmIndex] = Guid.NewGuid().ToTrim().Replace("-", "").Substring(0, 18);
Newfeature.Store();
TreeNode treeNode = GetNodeByName(TreeDataSource[0], JCBHValue.Trim(), new List<int>() { 2 });
if (treeNode == null) return;
//节点修改
if (treeNode.Nodes.FirstOrDefault(x => x.NodeID.ToInt() == Newfeature.OID) == null)
{
TreeNode bgfwNode = new TreeNode()//第四级-变更图斑
{
Name = Newfeature.Value[bsmIndex] as string,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeID = Newfeature.OID,
NodeLevel = 3,
Data = Newfeature,
ParentNode = treeNode,
PackageNode = treeNode.PackageNode,
PackageState = "未完成",//新增图斑默认为“未完成”状态
LoadingVisibility = Visibility.Collapsed
};
treeNode.Nodes.Add(bgfwNode);
treeNode.PackageState = GetNodesJCZT(treeNode);
treeNode.Name = Newfeature.Value[tbbhIndex] + $"({treeNode.Nodes.Count})";
}
else
{
TreeNode node = treeNode.Nodes.FirstOrDefault(x => x.NodeID.ToInt() == Newfeature.OID);
node.NodeID = Newfeature.OID;
node.Data = Newfeature;
node.Name = Newfeature.Value[bsmIndex] as string;
}
//循环判断变更图斑图形是否存在,不存在则删除变更范围节点
if (treeNode.Nodes.Count > 0)
{
List<TreeNode> deleteList = new List<TreeNode>();
foreach (var item in treeNode.Nodes)
{
try
{
DtbFeatureLayer.FeatureClass.GetFeature(item.NodeID.ToInt());
}
catch (Exception ex)
{
LogAPI.Debug("新增节点获取图层失败(不处理):" + ex);
deleteList.Add(item);
}
}
IsAutoSaveEdit = false;//暂时作为避免再次触发保存
foreach (var item in deleteList)
{
treeNode.Nodes.Remove(item);
}
IsAutoSaveEdit = true;
}
}
else if (Newfeature.Class.AliasName == "单图斑地类图斑更新" && rdbHelper != null)//任务包类型数据
{
//获取当前变更图斑对应的外业任务图斑
string BSMValue = string.Empty;
string tblx = string.Empty;
int dlbmIndex = Newfeature.Fields.FindField("TBBSM");//地类编码
if (dlbmIndex > -1)
{
BSMValue = Newfeature.get_Value(dlbmIndex).ToString();
}
if (string.IsNullOrWhiteSpace(BSMValue) && CurrentWYRWTB != null)
{
//BSMValue = GetTBBSM(Newfeature, ref tblx);
if (string.IsNullOrWhiteSpace(BSMValue))
BSMValue = CurrentWYRWTB.TBBSM;
}
GenerUpdateNewData(Newfeature, rdbHelper, BSMValue);
UpdateKCXS(Newfeature, rdbHelper, BSMValue);
}
else if (Newfeature.Class.AliasName == "外业图斑" && rdbHelper != null)
{
string jcbhValue = string.Empty;
int jcbhIndex = Newfeature.Class.FindField("JCBH");
int sjlyIndex = Newfeature.Class.FindField("SJLY");
if (!Newfeature.Value[sjlyIndex].ToString().Contains("ZZTB") && !string.IsNullOrWhiteSpace(Newfeature.Value[sjlyIndex].ToString()))
{
if (EngineEditorBG != null)
EngineEditorBG.StopEditing(false);
return;//非新增任务图斑修改不保存
}
bool NewJCBH = false;
jcbhValue = Newfeature.Value[jcbhIndex].ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
IJKTBTask GetRWTBDataHelper = new JKTBTaskHelper();
jcbhValue = GetRWTBDataHelper.GetRWTBSEQ(projectInfo.CODE, CurrentTaskPackage.YWLX).ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
MessageHelper.ShowTips("接口获取“JCBH”失败!");
return;
}
NewJCBH = true;
}
#region 分割任务图斑情况
//如果是分割图斑,两个要素jcbhValue是一样的,判断存在多个图斑,则也需要重新赋值jcbhValue
if (!NewJCBH)
{
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"JCBH='{jcbhValue}'"
};
ICursor cursor = (Newfeature.Class as ITable).Search(queryFilter, false);
int count = 0;
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
count++;
if (count > 1)
{
IJKTBTask GetRWTBDataHelper = new JKTBTaskHelper();
jcbhValue = GetRWTBDataHelper.GetRWTBSEQ(projectInfo.CODE, CurrentTaskPackage.YWLX).ToString();
if (string.IsNullOrWhiteSpace(jcbhValue))
{
MessageHelper.ShowTips("接口获取“JCBH”失败!");
return;
}
NewJCBH = true;
break;
}
}
}
#endregion
GenerWYTBNewData(Newfeature, rdbHelper, jcbhValue, NewJCBH);
}
}
catch (Exception ex)
{
LogAPI.Debug("新增/修改图斑发生错误:" + ex.Message);
LogAPI.Debug("可能原因为:空间参考不一样所致");
LogAPI.Debug(ex.StackTrace);
}
finally
{
if (features != null)
{
foreach (var item in features)
{
Marshal.ReleaseComObject(item);
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
}
}
#endregion
#region GenerNewData
private void GenerUpdateNewData(IFeature Newfeature, IRDBHelper rdbHelper, string tbbsm)
{
IFeature feature = null;
IGeometry convertGeometry = null;
IClone clone = null;
ICursor cursor = null;
IRow row = null;
try
{
string bsm = string.Empty;
int bsmIndex = Newfeature.Fields.FindField("BSM");
if (bsmIndex > -1)
{
bsm = Newfeature.get_Value(bsmIndex) as string;
}
Guid guidBSM;
//如果没值,则赋值新的GUID
if (string.IsNullOrWhiteSpace(bsm) || !Guid.TryParse(bsm, out guidBSM))
{
bsm = Guid.NewGuid().ToString();
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "UpdateFJGX", Content = bsm, Extend = rdbHelper });
}
else
{
//如果是分割图斑,两个要素bsm是一样的,判断存在多个BSM图斑,则也需要重新赋值BSM
IQueryFilter queryFilter = new QueryFilterClass()
{
WhereClause = $"bsm='{bsm}'"
};
cursor = (Newfeature.Class as ITable).Search(queryFilter, false);
int count = 0;
while ((row = cursor.NextRow()) != null)
{
count++;
if (count > 1)
{
bsm = Guid.NewGuid().ToString();
break;
}
}
}
#region 防止存在多部件图形,但另一部分又是空的图形
IGeometryCollection geometryCollection = Newfeature.ShapeCopy as IGeometryCollection;
if (geometryCollection.GeometryCount > 1)
{
for (int i = 0; i < geometryCollection.GeometryCount; i++)
{
IGeometry geometry = geometryCollection.Geometry[i];
IArea areaSub = geometry as IArea;
if (areaSub == null || Math.Abs(areaSub.Area) == 0)
{
geometryCollection.RemoveGeometries(i, 1);
}
}
Newfeature.Shape = geometryCollection as IGeometry;
}
#endregion
#region 设置图形属性
//计算椭球面积
clone = Newfeature.ShapeCopy as IClone;
double tqmj = (clone.Clone() as IPolygon).GetEllipseArea();
//获取图形json坐标串
clone = Newfeature.ShapeCopy as IClone;
IGeometry cloneGeometry = clone.Clone() as IGeometry;
string egeometry = GeometryConvertHelper.ConverIGometryToJson(cloneGeometry);
//此处是为了验证转换后的json坐标串是否可以转换回去,如果转换并投影后图形为空,说明转换后的坐标串egeometry不正确
convertGeometry = GeometryConvertHelper.ConverJsonToIGeoemtry(egeometry);
if (convertGeometry == null)
{
LogAPI.Debug(egeometry);
throw new Exception("图形转换后的Json坐标串无法转回图形!");
}
convertGeometry.Project(this.hookHelper.FocusMap.SpatialReference);
if (convertGeometry == null || convertGeometry.IsEmpty)
{
LogAPI.Debug(egeometry);
throw new Exception("图形转换的Json坐标串坐标参考不正确,请尝试重启软件!");
}
//获取图形四至、中心点坐标
IArea area = cloneGeometry as IArea;
string fields = "BSM,TBBSM,EGeometry,TBMJ,TBDLMJ,ZXDX,ZXDY,MAXX,MAXY,MINX,MINY,JKRY,TBLX,LNGDZB";
string fieldValues = $"'{bsm}','{tbbsm}','{egeometry}',{tqmj},{tqmj},{area.Centroid.X},{area.Centroid.Y},{cloneGeometry.Envelope.XMax},{cloneGeometry.Envelope.YMax},{cloneGeometry.Envelope.XMin},{cloneGeometry.Envelope.YMin},'{projectInfo.UserName}','{"0"}'";
#region 更新要素字段信息
int tempDDTCBZIndex = Newfeature.Fields.FindField("DDTCBZ");
string tempDDTCBZ = null;
if (tempDDTCBZIndex > -1)
tempDDTCBZ = Newfeature.get_Value(tempDDTCBZIndex).ToString();
int tempDLBMIndex = Newfeature.Fields.FindField("DLBM");
string tempDLBM = null;
if (tempDLBMIndex > -1)
tempDLBM = Newfeature.get_Value(tempDLBMIndex).ToString();
//图层信息选择单独图层的,除路面范围,默认地类直接继承基础库原地类
if (!string.IsNullOrEmpty(tempDDTCBZ) && tempDDTCBZ != "一般地类" && !tempDDTCBZ.Equals("1305", StringComparison.CurrentCultureIgnoreCase) && string.IsNullOrEmpty(tempDLBM))
{
ILayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑");
if (layer != null)
{
List<IFeature> JCfeatures = FeatureAPI.Identify2(Newfeature.ShapeCopy, layer);
if (JCfeatures != null && JCfeatures.Count > 0)
{
int jcdlbmIndex = JCfeatures[0].Fields.FindField("DLBM");
if (jcdlbmIndex > -1)
{
tempDLBM = JCfeatures[0].get_Value(jcdlbmIndex).ToString();
Newfeature.set_Value(tempDLBMIndex, tempDLBM);
}
}
}
}
int fIndex = Newfeature.Fields.FindField("bsm");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, bsm);
}
fIndex = Newfeature.Fields.FindField("egeometry");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, egeometry);
}
fIndex = Newfeature.Fields.FindField("tbbsm");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, tbbsm);
}
fIndex = Newfeature.Fields.FindField("BID");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, CurrentTaskPackage.BID);
}
fIndex = Newfeature.Fields.FindField("TBMJ");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, tqmj);
}
fIndex = Newfeature.Fields.FindField("TBDLMJ");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, tqmj);
}
fIndex = Newfeature.Fields.FindField("ZXDX");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, area.Centroid.X);
}
fIndex = Newfeature.Fields.FindField("ZXDY");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, area.Centroid.Y);
}
fIndex = Newfeature.Fields.FindField("MAXX");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, cloneGeometry.Envelope.XMax);
}
fIndex = Newfeature.Fields.FindField("MAXY");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, cloneGeometry.Envelope.YMax);
}
fIndex = Newfeature.Fields.FindField("MINX");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, cloneGeometry.Envelope.XMin);
}
fIndex = Newfeature.Fields.FindField("MINY");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, cloneGeometry.Envelope.YMin);
}
fIndex = Newfeature.Fields.FindField("JKRY");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, projectInfo.UserName);
}
string zzsxdm = null;
fIndex = Newfeature.Fields.FindField("ZZSXDM");
if (fIndex > -1)
{
zzsxdm = Newfeature.get_Value(fIndex).ToString();
if (!string.IsNullOrEmpty(tempDDTCBZ) && !string.IsNullOrEmpty(tempDLBM) && "1301,1302,1303,1304".Contains(tempDDTCBZ) && "0101,0102,0103".Contains(tempDLBM))
{
if (string.IsNullOrEmpty(zzsxdm))
{
zzsxdm = "WG";
Newfeature.set_Value(fIndex, "WG");
}
}
}
fIndex = Newfeature.Fields.FindField("ZZSXMC");
if (fIndex > -1)
{
//种植属性名称
string zzsxmc = string.Empty;
DataDicTionary dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.ZZSX).FirstOrDefault(x => x.CODE.Equals(zzsxdm));
if (dataDicTionary != null)
{
zzsxmc = dataDicTionary.NAME;
}
Newfeature.set_Value(fIndex, zzsxmc);
}
#region 计算变更范围与历年耕地图层的相交面积
double lngdArea = 0;
//shape_area图形面积
IArea area1 = Newfeature.ShapeCopy as IArea;
double jcmj = Math.Round(area1.Area, 2);
string lngdzb = Math.Round((lngdArea / jcmj) * 100, 2) + "%";
fIndex = Newfeature.Fields.FindField("LNGDZB");
if (fIndex > -1)
{
Newfeature.set_Value(fIndex, lngdzb);
}
fieldValues += $",'{lngdzb}'";
#endregion
#endregion
//Newfeature.Store();
#endregion
//删除库中已存在的数据
rdbHelper.ExecuteNonQueryWithException($"delete from dtbdltbgx where bsm='{bsm}'", CommandType.Text);
string excuteSQL = string.Format("insert into dtbdltbgx({0})values({1})", fields, fieldValues);
rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text);
//保存其他属性字段和独立图层信息表
SaveUpdateBGFWAndDLTC(tbbsm, bsm, rdbHelper, Newfeature);
//保存更新过程数据
DTBDBLoadHelper.SaveGXGCData(bsm, tbbsm, Newfeature, rdbHelper, this.hookHelper, false);//同步保存
object dlbmOBJ = Newfeature.get_Value(Newfeature.Fields.FindField("DLBM"));
string dlbm = dlbmOBJ == null ? "" : dlbmOBJ.ToString();
//自动填充是否更新和是否举证字段
//ValidationField(bsm, Newfeature, rdbHelper, dlbm, tqmj);
#region 同步更新树结构数据
TreeNode treeNode = GetNodeByName(TreeDataSource[0], tbbsm, new List<int>() { 2 });
if (treeNode != null && treeNode.NodeLevel == 2)
{
if (treeNode.Nodes == null)
{
treeNode.Nodes = new ObservableCollection<TreeNode>();
}
List<TreeNode> lsttree = treeNode.Nodes.Where(x => x.NodeID.Equals(Newfeature.OID)).ToList();
TreeNode addNode = null;
if (lsttree.Count() <= 0)
{
DataTable dataTable = rdbHelper.ExecuteDatatable("data", $"select * from dtbdltbgx where bsm='{bsm}'", true);
addNode = new TreeNode()
{
Name = bsm,
Paixu = treeNode.Nodes.Count + 10,
IsExpanded = false,
Icon = "pack://application:,,,/Kingo.Plugin.General;component/Resources/变更图斑.png",
NodeLevel = 3,
Data = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity<DTBDLTBGX>(dataTable.Rows[0]),
cMenu = null,
PackageNode = treeNode.PackageNode,
ParentNode = treeNode,
NodeID = Newfeature.OID
};
(addNode.Data as DTBDLTBGX).ObjectID = Newfeature.OID;//补充OID值
treeNode.Name = tbbsm + "(" + (treeNode.Nodes.Count + 1) + ")";
treeNode.Nodes.Add(addNode);
}
else
{
addNode = lsttree[0];
}
addNode.Name = bsm;
//循环判断变更图斑图形是否存在,不存在则删除变更范围节点
if (treeNode.Nodes.Count > 0)
{
List<TreeNode> deleteList = new List<TreeNode>();
foreach (var item in treeNode.Nodes)
{
try
{
DtbFeatureLayer.FeatureClass.GetFeature((int)item.NodeID);
}
catch
{
deleteList.Add(item);
}
}
foreach (var item in deleteList)
{
treeNode.Nodes.Remove(item);
}
}
//更新节点数量
treeNode.Name = tbbsm + "(" + (treeNode.Nodes.Count) + ")";
}
#endregion
SyncDBData(Newfeature.Class as IFeatureClass, rdbHelper, tbbsm);
}
catch (Exception ex)
{
LogAPI.Debug("新增或修改单图斑变更范围失败:" + ex.Message);
LogAPI.Debug("新增或修改单图斑变更范围失败:" + ex.StackTrace);
LogAPI.Debug("新增或修改单图斑变更范围失败:" + ex);
throw ex;
}
finally
{
if (row != null)
Marshal.ReleaseComObject(row);
if (cursor != null)
Marshal.ReleaseComObject(cursor);
if (clone != null)
Marshal.ReleaseComObject(clone);
if (convertGeometry != null)
Marshal.ReleaseComObject(convertGeometry);
if (feature != null)
Marshal.ReleaseComObject(feature);
}
}
#endregion
#region 保存单图斑和独立图层数据
/// <summary>
/// 保存单图斑和独立图层数据
/// </summary>
/// <param name="BSM"></param>
/// <param name="rdbHelper"></param>
/// <param name="feature"></param>
private void SaveUpdateBGFWAndDLTC(string tbbsm, string BSM, IRDBHelper rdbHelper, IFeature feature)
{
try
{
DataTable dataTableDetailjson = rdbHelper.ExecuteDatatable("detailjson", $"select * from detailjson where tbbsm = '{tbbsm}' ", true);
DataTable dataTableWYRW = rdbHelper.ExecuteDatatable("wyrw", $"select JCBH from wyrw where tbbsm = '{tbbsm}' ", true);
ILayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑");
ILayer layerPodu = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_省级下发坡度图");
if (string.IsNullOrWhiteSpace(tbbsm) || string.IsNullOrWhiteSpace(BSM))
return;//图斑标识码和标识码不可为空
//判定DTBDLTBGX表中是否有XZGDFJ列 没有则添加
DataTable dataTableDTBDLTB = rdbHelper.ExecuteDatatable("DTBDLTBGX", "select * from DTBDLTBGX", true);
if (dataTableDTBDLTB != null)
{
if (!dataTableDTBDLTB.Columns.Contains("XZGDFJ"))
{
rdbHelper.ExecuteSQL(@"ALTER TABLE DTBDLTBGX ADD COLUMN XZGDFJ text(200);");
}
}
string xzqdm = tbbsm.Substring(0, 6);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBLSYDGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBGFBQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBTTQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBCCWJQGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBCZCDYDGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from DTBLMFWGX where bsm='{BSM}'", CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($"delete from PZWJ where bsm='{BSM}'", CommandType.Text);
//rdbHelper.ExecuteNonQueryWithException(string.Format("delete from fjgx where tbbsm='{0}'", BSM), CommandType.Text);
string excuteSQL = "UPDATE DTBDLTBGX SET {0} WHERE BSM='{1}'";
List<string> listField = new List<string>() { "TBBSM", "TBYBH", "DLBM", "KCDLBM", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "GDLX", "XZDWKD", "TBXHDM", "ZZSXDM", "TBXHMC", "GDDB", "CZCSXM", "SJNF", "FRDBS", "MSSM", "EGeometry", "DDTCBZ", "DDTCMC", "SFGX", "WBGYY1", "WBGYY", "SFJZ", "QKSM", "LJLX", "YWTBSM", "NBWQKSM", "SHLZQKSM", "LNGDZB", "SDMSSM", "YDYHFL", "ZGQKSM", "BZ", "SFXML", "XMMC", "XMLX", "XMBH", "DKMC", "CZCTBBH", "LC", "NF", "XZGDFJ", "GXSJ", "LJBZ", "JZYBH", "LJTBBH" };
//独立图层代码
string ddtcbz = string.Empty;
string ddtcmc = string.Empty;
//城镇村属性码
string czcsxm = string.Empty;
//地类编码
string dlbm = string.Empty;
//权属性质
string qsxz = string.Empty;
//权属单位代码
string qsdwdm = string.Empty;
//权属单位名称
string qsdwmc = string.Empty;
//坐落单位代码
string zldwdm = string.Empty;
//坐落单位名称
string zldwmc = string.Empty;
//项目类型
string xmlx = string.Empty;
//种指属性代码
string zzsxdm = string.Empty;
//图斑细化代码
string tbxhdm = string.Empty;
//未变更原因描述
string wbgyyms = string.Empty;
//数据年份
string sjnf = string.Empty;
//求椭圆面积
double mj = Math.Round(feature.ShapeCopy.GetEllipseArea(), 2);
//变更后值
string bgHValue = $"jkry='{(MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).UserName}',tbmj={mj},tbdlmj={mj},gxsj='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', jym = '{GetJym(feature)}', ";
//构建字段值
foreach (string item in listField)
{
int index = feature.Fields.FindField(item);
if (index <= -1)
{
continue;
}
object obj = feature.get_Value(index);
if (!(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString()))
{
if (item.Equals("ddtcbz", StringComparison.CurrentCultureIgnoreCase))
{
ddtcbz = obj.ToString();
}
if (item.Equals("ddtcmc", StringComparison.CurrentCultureIgnoreCase))
{
ddtcmc = obj.ToString();
}
if (item.Equals("CZCSXM", StringComparison.CurrentCultureIgnoreCase))
{
czcsxm = obj.ToString();
}
}
if (item.Equals("XMLX"))
{
xmlx = obj == null ? "" : obj.ToString();
}
if (item.Equals("QSXZ"))
{
qsxz = obj == null ? "" : obj.ToString();
}
if (item.Equals("DLBM"))
{
dlbm = obj == null ? "" : obj.ToString();
}
else if (item.Equals("ZZSXDM"))
{
zzsxdm = obj == null ? "" : obj.ToString();
}
else if (item.Equals("TBXHDM"))
tbxhdm = obj == null ? "" : obj.ToString();
else if (item.Equals("SJNF"))
sjnf = obj == null ? "" : obj.ToString();
IField field = feature.Fields.Field[index];
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeOID:
case esriFieldType.esriFieldTypeBlob:
if (obj == null || obj == DBNull.Value)
{
bgHValue += item + "=0,";
}
else
{
bgHValue += item + "=" + obj + ",";
}
break;
default:
if (item.Equals("KCDLBM", StringComparison.CurrentCultureIgnoreCase))
{
if (!dlbm.StartsWith("01"))
{
bgHValue += item + "='" + "" + "',";
}
else
{
bgHValue += item + "='" + obj + "',";
}
}
else if (item.Equals("WBGYY1", StringComparison.CurrentCultureIgnoreCase))
{
//if (string.IsNullOrEmpty(obj.ToString()))
wbgyyms = obj.ToString();
}
else if (item.Equals("WBGYY", StringComparison.CurrentCultureIgnoreCase))
{
if (obj.ToString() == "其他")
bgHValue += item + "='" + wbgyyms + "',";
else
bgHValue += item + "='" + obj + "',";
}
else if (item.Equals("GDLX", StringComparison.CurrentCultureIgnoreCase))
{
bgHValue += item + "='" + obj + "',";
if (obj != null && (obj.ToString().Equals("TT") || obj.ToString().Equals("PD")))
{
string gdpdjb = "";
int gdpdjbIndex = feature.Fields.FindField("GDPDJB");
if (gdpdjbIndex > -1)
{
object gdpdjbValue = feature.get_Value(gdpdjbIndex);
if (gdpdjbValue != null && !string.IsNullOrEmpty(gdpdjbValue.ToString()))
{
gdpdjb = gdpdjbValue.ToString();
}
else
gdpdjb = GetPojb(feature, layerPodu);
}
else
gdpdjb = GetPojb(feature, layerPodu);
double gdkcxs = DTBDBLoadHelper.GetTKXS(gdpdjb, obj.ToString());
double kcmj = gdkcxs * mj;
double tbdlmj = mj - kcmj;
bgHValue += $"gdpdjb = '{gdpdjb}',kcxs = {gdkcxs}, kcmj = {kcmj}, tbdlmj = {tbdlmj}, ";
}
}
else if (item.Equals("JZYBH", StringComparison.CurrentCultureIgnoreCase) && (obj == null || string.IsNullOrEmpty(obj.ToString())))
{
string JZYBH = string.Empty;
if (CurrentWYRWTB != null) JZYBH = CurrentWYRWTB.JCBH;
else if (dataTableWYRW != null && dataTableWYRW.Rows.Count > 0)
{
JZYBH = dataTableWYRW.Rows[0]["JCBH"].ToString();
}
obj = JZYBH;
bgHValue += item + "='" + obj + "',";
feature.set_Value(index, obj);
}
else if (item.Equals("LJTBBH", StringComparison.CurrentCultureIgnoreCase) && (obj == null || string.IsNullOrEmpty(obj.ToString())))
{
if (dataTableDetailjson != null && dataTableDetailjson.Rows.Count > 0)
{
for (int i = 0; i < dataTableDetailjson.Rows.Count; i++)
{
if (dataTableDetailjson.Rows[i]["Name"].ToString() == "类举图斑编号" || dataTableDetailjson.Rows[i]["Name"].ToString() == "LJTBBH")
{
obj = dataTableDetailjson.Rows[i]["Value"].ToString();
bgHValue += item + "='" + obj + "',";
feature.set_Value(index, obj);
break;
}
}
}
}
else
{
bgHValue += item + "='" + obj + "',";
}
break;
}
}
//feature.Store();
string sadff = string.Format(excuteSQL, bgHValue.TrimEnd(','), BSM);
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, bgHValue.TrimEnd(','), BSM), CommandType.Text);
//地类名称
string dlmc = string.Empty;
DataDicTionary dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.DLBM).FirstOrDefault(x => x.CODE.Equals(dlbm));
if (dataDicTionary != null)
{
dlmc = dataDicTionary.NAME;
}
//种植属性名称
string zzsxmc = string.Empty;
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.ZZSX).FirstOrDefault(x => x.CODE.Equals(zzsxdm));
if (dataDicTionary != null)
{
zzsxmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}' where bsm='{BSM}'", CommandType.Text);
//单独图层名称
dataDicTionary = Platform.Instance.DicHelper.GetAllDic().FirstOrDefault(x => x.CODE.Equals(ddtcbz));
if (dataDicTionary != null)
{
ddtcmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}' where bsm='{BSM}'", CommandType.Text);
//图斑细化名称
string tbxhmc = string.Empty;
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.TBXHLX).FirstOrDefault(x => x.CODE.Equals(tbxhdm));
if (dataDicTionary != null)
{
tbxhmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"update dtbdltbgx set dlmc='{dlmc}',zzsxmc='{zzsxmc}',ddtcmc='{ddtcmc}',tbxhmc='{tbxhmc}',qsxz='{qsxz}' where bsm='{BSM}'", CommandType.Text);
//保存独立图层代码
switch (ddtcbz)
{
case "1301"://临时用地2099010100
DataTable dataTable = IRowToDataTable(feature as IRow);
if (dataTable != null && dataTable.Rows.Count > 0)
{
DataRow dr = dataTable.Rows[0];
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBLSYDGX (BSM, DDTCBZ, DDTCMC, YSDM, GLTBBSM, PZWJMC, PZWH, TBMJ, PZMJ, YTFL, JTXMYT, PZRQ, YQSX, TDSYHT, BZ, GXSJ) VALUES('{BSM}', '{ddtcbz}', '{ddtcmc}', '2099010100', '{BSM}', '{dr["PZWJMC_LSYD"]}', '{dr["PZWH_LSYD"]}', {dr["TBMJ"]}, {dr["TBMJ"]}, '{dr["YTFL_LSYD"]}', '{dr["JTXMYT_LSYD"]}', '{dr["PZRQ_LSYD"]}', '{dr["YQSX_LSYD"]}', '{dr["TDSYHT_LSYD"]}', '{dr["BZ"]}', '{dr["GXSJ"]}')", CommandType.Text);
object obj = feature.get_Value(feature.Fields.FindField("PZWJ_LSYD"));
if (obj != null && !(obj is DBNull))
{
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)obj;
object obj1 = null;
varBlobStream.ExportToVariant(out obj1);
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO PZWJ(BSM, Name, Path, Extension) VALUES('{BSM}', '{dr["PZWJMC_LSYD"]}', '', '')", CommandType.Text);
IDbDataParameter[] parameters = new IDbDataParameter[1];
parameters[0] = new System.Data.SQLite.SQLiteParameter("FileContent", DbType.Binary) { Value = obj1 };
rdbHelper.ExecuteNonQueryWithException($"update PZWJ SET FileContent=@FileContent where bsm='{BSM}'", CommandType.Text, parameters);
}
}
break;
case "1302"://光伏板区2099070100
dataTable = IRowToDataTable(feature as IRow);
if (dataTable != null && dataTable.Rows.Count > 0)
{
DataRow dr = dataTable.Rows[0];
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBGFBQGX(BSM, DDTCBZ, DDTCMC, YSDM, XMMC, XMGM, QYMJ, PZYDSJ, BZ, GXSJ) VALUES('{BSM}', '{ddtcbz}', '{ddtcmc}', '2099070100', '{dr["XMMC_GFBQ"]}', '{dr["XMGM_GFBQ"]}', {dr["TBMJ"]}, '{dr["PZYDSJ_GFBQ"]}', '{dr["BZ"]}', '{dr["GXSJ"]}')", CommandType.Text);
}
break;
case "1303"://推土区
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBTTQGX(BSM, DDTCBZ, DDTCMC, YSDM, TTQMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099080100',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
case "1304"://拆除未尽区2099090100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBCCWJQGX (BSM, DDTCBZ, DDTCMC, YSDM, ZDMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099090100',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
case "1305"://路面范围2099100100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBLMFWGX (BSM, DDTCBZ, DDTCMC, YSDM, ZLDWDM, KD, MJ, DLBM, MC, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099100100',zldwdm,xzdwkd,tbmj,dlbm,'',bz,gxsj from dtbdltbgx where bsm='{BSM}';", CommandType.Text);
break;
case "1306"://工厂化种植更新2099120100
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO GCHZZGX (BSM,YSDM,ZDMJ,DLBM,DLMC,BZ,GXSJ) select bsm,'2099120100',tbmj,dlbm,'',bz,gxsj from dtbdltbgx where bsm='{BSM}';", CommandType.Text);
break;
case "一般地类":
if (xmlx == "1" || xmlx == "2")
{
DataTable dtXmlx2 = IRowToDataTable(feature as IRow);
if (dtXmlx2 != null && dtXmlx2.Rows.Count > 0)
{
object obj = feature.get_Value(feature.Fields.FindField("XZGDFJ"));
if (obj != null && !(obj is DBNull))
{
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 = '{dtXmlx2.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[5];
if (objBsm == null)
{
strSql = "INSERT INTO WYHCFJ ( HCLX, HCJLBSM, DKID, FJMC, FJLX, MODE,IS_SELECTED, SEQUENCE, SUBTYPE, ARG, ARG4, CJSJ, LENGTH, POINTS_JSON, UserDelete ) VALUES ( 'WYRWTB', @HCJLBSM, @HCJLBSM, @FJMC, 'PDF', '4',1, '0', '1', @ARG, @ARG4, @CJSJ, '0', '[]', '0' )";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx2.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 };
}
else
{
strSql = "UPDATE WYHCFJ SET ARG = @ARG, ARG4 = @ARG4, CJSJ = @CJSJ WHERE HCJLBSM=@HCJLBSM AND FJMC = @FJMC";
parameters[0] = new System.Data.SQLite.SQLiteParameter("HCJLBSM", DbType.String) { Value = dtXmlx2.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 };
}
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text, parameters);
rdbHelper.ExecuteNonQueryWithException($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{dtXmlx2.Rows[0]["TBBSM"].ToString()}','{strGuid}','{BSM}')", CommandType.Text);
fs.Close();
}
}
}
}
}
break;
}
string czcmc = string.Empty;
//保存城镇村等用地
switch (czcsxm)
{
case "201":
case "201A":
case "202":
case "202A":
case "203":
case "203A":
case "204":
case "205":
dataDicTionary = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.CZCJGKYD).FirstOrDefault(x => x.CODE.Equals(czcsxm));
if (dataDicTionary != null)
{
czcmc = dataDicTionary.NAME;
}
rdbHelper.ExecuteNonQueryWithException($"INSERT INTO DTBCZCDYDGX (BSM, DDTCBZ, DDTCMC, YSDM, CZCLX, CZCDM, CZCMC, CZCMJ, BZ, GXSJ) select bsm,ddtcbz,ddtcmc,'2099030100',czcsxm,'{xzqdm.PadRight(19, '0')}','{czcmc}',tbmj,bz,gxsj from dtbdltbgx where bsm='{BSM}'", CommandType.Text);
break;
}
////保存附件信息
//object images = feature.get_Value(feature.Fields.FindField("images"));
//if (images != null)
//{
// excuteSQL = "insert into fjgx(WYTBBSM,FJARG,tbbsm)values('{0}','{1}','{2}')";
// foreach (var item in images.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
// {
// rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, tbbsm, item, BSM), CommandType.Text);
// }
//}
//附件文件 保存
DataTable dtXmlx = IRowToDataTable(feature as IRow);
if (dtXmlx != null && dtXmlx.Rows.Count > 0)
{
object obj = feature.get_Value(feature.Fields.FindField("XZGDFJ"));
if (obj != null && !(obj is DBNull) && !string.IsNullOrWhiteSpace(obj.ToString()))
{
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[5];
if (objBsm == null)
{
strSql = "INSERT INTO WYHCFJ ( HCLX, HCJLBSM, DKID, FJMC, FJLX, MODE,IS_SELECTED, SEQUENCE, SUBTYPE, ARG, ARG4, CJSJ, LENGTH, POINTS_JSON, UserDelete ) VALUES ( 'WYRWTB', @HCJLBSM, @HCJLBSM, @FJMC, 'PDF', '4',1, '0', '1', @ARG, @ARG4, @CJSJ, '0', '[]', '0' )";
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 };
}
else
{
strSql = "UPDATE WYHCFJ SET ARG = @ARG, ARG4 = @ARG4, CJSJ = @CJSJ WHERE HCJLBSM=@HCJLBSM AND FJMC = @FJMC";
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 };
}
rdbHelper.ExecuteNonQueryWithException(strSql, CommandType.Text, parameters);
rdbHelper.ExecuteNonQueryWithException($"insert into fjgx (wytbbsm,fjarg,tbbsm) values ('{dtXmlx.Rows[0]["TBBSM"].ToString()}','{strGuid}','{BSM}')", CommandType.Text);
fs.Close();
}
}
}
}
//根据图斑面积面积,限制外业照片、视频数量
string strTbmj = string.Empty;
int tbmjIndex = feature.Fields.FindField("TBMJ");
if (tbmjIndex > -1)
{
strTbmj = feature.get_Value(tbmjIndex).ToString();
DataTable dtFj = rdbHelper.ExecuteDatatable("wyhcfj", $"select sum(case when mode in ('5') then 1 else 0 end) as videocount,sum(case when mode not in ('4','5') then 1 else 0 end) as imagecount from wyhcfj a inner join fjgx b on a.hcjlbsm=b.wytbbsm and b.fjarg = a.arg and b.tbbsm ='{BSM}' where HCJLBSM='{tbbsm}' and (UserDelete <> 1 or UserDelete is not null)", true);
if (!string.IsNullOrEmpty(strTbmj) && dtFj != null && dtFj.Rows.Count > 0)
{
int imageCount = 0, videoCount = 0;
if (dtFj.Rows[0]["imagecount"] != null && !string.IsNullOrEmpty(dtFj.Rows[0]["imagecount"].ToString()))
{
imageCount = int.Parse(dtFj.Rows[0]["imagecount"].ToString());
}
if (dtFj.Rows[0]["videocount"] != null && !string.IsNullOrEmpty(dtFj.Rows[0]["videocount"].ToString()))
{
videoCount = int.Parse(dtFj.Rows[0]["videocount"].ToString());
}
decimal tbmj = (Convert.ToDouble(strTbmj) / 666.67).ToDecimal(2);
if (tbmj <= 5)
{
if (imageCount > 15 || videoCount > 2)
{
//MessageHelper.Show("图斑面积小于5亩时,外业照片数量超过15张,或者外业视频数量超过2段");
LogAPI.Debug("图斑面积小于5亩时,外业照片数量超过15张,或者外业视频数量超过2段");
return;
}
}
if (5 < tbmj && tbmj <= 20)
{
if (imageCount > 30 || videoCount > 5)
{
//MessageHelper.Show("图斑面积大于5亩小于等于20亩时,外业照片数量超过30张,或者外业视频数量超过5段");
LogAPI.Debug("图斑面积大于5亩小于等于20亩时,外业照片数量超过30张,或者外业视频数量超过5段");
return;
}
}
if (tbmj > 20)
{
if (imageCount > 50 || videoCount > 7)
{
//MessageHelper.Show("图斑面积大于20亩时,外业照片数量超过50张,或者外业视频数量超过7段");
LogAPI.Debug("图斑面积大于20亩时,外业照片数量超过50张,或者外业视频数量超过7段");
return;
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("DataOperationHelper_65.SaveUpdateBGFWAndDLTC 异常" + ex.Message);
LogAPI.Debug("DataOperationHelper_65.SaveUpdateBGFWAndDLTC 异常" + ex.StackTrace);
throw ex;
}
}
#endregion
}
#endregion
}