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

765 lines
25 KiB

using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Utils;
using Kingo.PluginServiceInterface.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Text;
namespace Kingo.PluginServiceInterface
{
/// <summary>
/// Model:工程结构
/// Description:用于记录工程信息
/// Author:李进营
/// Finished:2017年11月18日
/// </summary>
[Serializable]
public class ProjectInfo
{
/// <summary>
/// =======临时增加,用于控制图形合并提示框=========
/// 是否再次提醒(true:下次继续提醒;false:下次不再提醒)
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public bool IsPromptAgain = true;
/// <summary>
/// 工程名称
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public string ProjName { get; set; }
/// <summary>
/// 单图斑建库-工程使用人
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public string ProjUserName { get; set; }
/// <summary>
/// 默认方案
/// </summary>
//public string DefaultScheme { get; set; }
///// <summary>
///// 当前方案
///// </summary>
//public string CurrentScheme { get; set; }
///// <summary>
///// 记录所有方案
///// </summary>
//public List<string> SchemeList { get; set; }
/// <summary>
/// 数据库名称
/// </summary>
public string DataBaseName { get; set; }
/// <summary>
/// 变更数据库
/// </summary>
public string BGDatabase { get; set; }
/// <summary>
/// 变更成果导出路径
/// </summary>
public string BGResultPath { get; set; }
/// <summary>
/// 监测图层数据库
/// </summary>
public string JCDatabase { get; set; }
/// <summary>
/// 单图斑基础库图层数据库
/// </summary>
public string DTBJKDatabase { get; set; }
/// <summary>
/// 单图斑变更更新图层图层数据库
/// </summary>
public string DTBBGGXDatabase { get; set; }
/// <summary>
/// 单图斑数据检查库
/// </summary>
public string DTBCheckDatabase { get; set; }
/// <summary>
/// 单图斑预处理数据库
/// </summary>
public string DTBYCLDatabase { get; set; }
/// <summary>
/// 单图斑预处理预审数据库
/// </summary>
public string DTBYCLYHDatabase { get; set; }
/// <summary>
/// 增量数据库
/// </summary>
public string ZLDatabase { get; set; }
/// <summary>
/// 年末数据库
/// </summary>
public string NMDatabase { get; set; }
/// <summary>
/// 变化图斑数据库
/// </summary>
public string BHTBDatabase { get; set; }
/// <summary>
/// 举证成果包地址
/// </summary>
public string DBPath { get; set; }
/// <summary>
/// 工程后缀名
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public string ProjSuffix { get; set; }
/// <summary>
/// 行政代码
/// </summary>
public string CODE { get; set; }
/// <summary>
/// 陆地调查面积
/// </summary>
public double DCMJ { get; set; }
/// <summary>
/// 海岛调查面积
/// </summary>
public double DCMJHD { get; set; }
public KZMJInfo KZMJ { get; set; }
/// <summary>
/// 比例尺
/// </summary>
public string Scale { get; set; }
/// <summary>
/// 比例尺代码
/// </summary>
public string ScaleCode { get; set; }
/// <summary>
/// 容差
/// </summary>
public double XYResolution { get; set; }
/// <summary>
/// 陆地控制面积公顷
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public double DCMJ2 { get; set; }
/// <summary>
/// 海岛控制面积公顷
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public double DCMJHD2 { get; set; }
/// <summary>
/// 分度带
/// </summary>
public string FDD { get; set; }
//private string
/// <summary>
/// 图形带号
/// </summary>
public int TXDH { get; set; }
/// <summary>
/// 中央经度
/// </summary>
public int ZYJD { get; set; }
/// <summary>
/// 影像路径
/// </summary>
public string[] ImgPath { get; set; }
/// <summary>
/// 坐标参考文件路径(已经过时,请使用PrjFileStr)
/// </summary>
public string PrjFilePath { get; set; }
/// <summary>
/// 坐标参考字符串
/// </summary>
public string PrjFileStr { get; set; }
/// <summary>
/// 工程所在文件夹
/// </summary>
public string ProjDir { get; set; }
/// <summary>
/// 工程目录文件夹名称(行政区名称+代码)
/// </summary>
public string ProWorkDir { get; set; }
/// <summary>
/// 模板数据
/// </summary>
public string TempData { get; set; }
public string MulitMapData { get; set; }
public string DicData { get; set; }
/// <summary>
/// 是否启用快捷键
/// </summary>
public bool EnableShortcut { get; set; }
/// <summary>
/// 工作目录-基础库路径
/// </summary>
public string JCKPath { get; set; }
/// <summary>
/// 工作目录-国检年末库路径
/// </summary>
public string GJNMKPath { get; set; }
/// <summary>
/// 工作目录-变更范围成果
/// </summary>
public string BGFWCGPath { get; set; }
/// <summary>
/// 工作目录-监测图斑路径
/// </summary>
public string JCTBPath { get; set; }
/// <summary>
/// 工作目录-临时用地范围路径
/// </summary>
public string LSYDFWPath { get; set; }
/// <summary>
/// 工作目录-历年耕地范围路径
/// </summary>
public string LNGDFWPath { get; set; }
/// <summary>
/// 工作目录-用地管理信息路径
/// </summary>
public string YDGLXXPath { get; set; }
/// <summary>
/// 工作目录-专项数据路径
/// </summary>
public string ZXSJPath { get; set; }
/// <summary>
/// 工作目录-坡度图路径
/// </summary>
public string PDTPath { get; set; }
/// <summary>
/// 工作目录-合法建设用地范围
/// </summary>
public string HFJSYDPath { get; set; }
/// <summary>
/// 工作目录-耕地及恢复属性图斑路径
/// </summary>
public string GDJHFSXPath { get; set; }
/// <summary>
/// 工作目录-城镇村等用地路径
/// </summary>
public string CZCDYDPath { get; set; }
/// <summary>
/// 工作目录-影像路径
/// </summary>
public string YXPath { get; set; }
/// <summary>
/// 工作目录-5级坡度图
/// </summary>
public string txtfivePDT { get; set; }
/// <summary>
/// 工作目录-承诺耕地参考图层
/// </summary>
public string CNGDPath { get; set; }
/// <summary>
/// 工作目录-国家下发监测图层
/// </summary>
public string GJXFJCPath { get; set; }
/// <summary>
/// 工作目录-撂荒耕地参考图层
/// </summary>
public string LHGDPath { get; set; }
public List<TaskPackage> ListTaskPackage { get; set; }
public string TaskPath { get; set; }
public int WKID { get; set; }
/// <summary>
/// 设置的用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 用户密码
/// </summary>
public string UserPassword { get; set; }
/// <summary>
/// 任务包密码
/// </summary>
public string Pathpassword = "; password = 009FA8952F59C8853AF0CC8DA4394D00FEDCD51361C7F1C9C2629EBEB8FDE5B2A1";
/// <summary>
/// 批量赋属性值列表
/// </summary>
public List<BatchAttribute> ListBatchAttributes { get; set; } = new List<BatchAttribute>();
/// <summary>
/// 创建投影坐标系
/// </summary>
/// <param name="pcType">esriSRProjCS4Type</param>
/// <returns></returns>
public ISpatialReference GetCurentProjectedCoordinate()
{
try
{
if (!string.IsNullOrWhiteSpace(PrjFileStr))
{
//创建一个要素集创建一个投影
ISpatialReferenceFactory pSpatialRefFac = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatialReference;
int s;
PrjFileStr = PrjFileStr.Replace("'", "\"");
pSpatialRefFac.CreateESRISpatialReference(PrjFileStr, out pSpatialReference, out s);
return pSpatialReference;
}
return null;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return null;
}
}
public ProjectInfo()
{
//DefaultScheme = "初始方案";
//CurrentScheme = "初始方案";
}
public static ProjectInfo OpenProject(string pFilePath)
{
if (!string.IsNullOrWhiteSpace(pFilePath) && File.Exists(pFilePath))
{
string strBase64 = string.Empty;
//读取文件内容到字节数组
using (FileStream stream = new FileStream(pFilePath, FileMode.Open))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Close();
//将字节数组转换成Base64字符串
strBase64 = Convert.ToBase64String(bytes);
}
//将Base64字符串进行解密,得到原始文件数据
string strData = Decrypt(strBase64, "58ef12f9891a4cd89fa7bdd181ef13a7");
//将原始文件数据反序列化为对象
ProjectInfo data = JsonConvert.DeserializeObject<ProjectInfo>(strData);
if (data == null)
{
data = SerializeAPI.DeserializeToObject<ProjectInfo>(strData.Substring(1));
}
if (data != null)
{
data.ProjName = System.IO.Path.GetFileNameWithoutExtension(pFilePath);
data.ProjSuffix = System.IO.Path.GetExtension(pFilePath);
data.ProjDir = System.IO.Path.GetDirectoryName(pFilePath);
data.BGDatabase = System.IO.Path.Combine(data.ProjDir, "BGDB.gdb");
if (!Directory.Exists(data.BGDatabase))
data.BGDatabase = string.Empty;
data.ZLDatabase = System.IO.Path.Combine(data.ProjDir, "ZLDB.gdb");
if (!Directory.Exists(data.ZLDatabase))
data.ZLDatabase = string.Empty;
data.NMDatabase = System.IO.Path.Combine(data.ProjDir, "NMDB.gdb");
if (!Directory.Exists(data.NMDatabase))
data.NMDatabase = string.Empty;
FileInfo fIf = new FileInfo(data.ProjDir);
//data.ProWorkDir=
data.DCMJ2 = Math.Round(data.DCMJ * 0.0001, 2);
data.DCMJHD2 = Math.Round(data.DCMJHD2 * 0.0001, 2);
//if (string.IsNullOrEmpty(data.PrjFileStr) && !string.IsNullOrEmpty(data.PrjFilePath) && System.IO.File.Exists(data.PrjFilePath))
//{
// // 兼容老的坐标参考系
// SetPrjFileStrByOldPrjFilePath(data);
//}
}
return data;
}
else
{
return null;
}
}
//public static ProjectInfo OpenProject1(string pFilePath)
//{
// if (!string.IsNullOrWhiteSpace(pFilePath) && File.Exists(pFilePath))
// {
// ProjectInfo data = null;
// return data;
// }
// else
// {
// return null;
// }
//}
/// <summary>
/// 获取工程文件路径
/// </summary>
/// <returns></returns>
public string GetProjFilePath()
{
try
{
if (string.IsNullOrWhiteSpace(ProjDir))
return string.Empty;
string filePath = ProjDir + "\\" + ProjName + ProjSuffix;
if (File.Exists(filePath))
return filePath;
else
return "";
}
catch (Exception ex)
{
LogAPI.Debug("获取工程文件路径异常:" + ex);
return "";
}
}
/// <summary>
/// 获取数据字典文件路径
/// </summary>
/// <returns></returns>
public string GetDicDataPath()
{
if (!string.IsNullOrWhiteSpace(ProjDir))
{
string dbPath = System.IO.Path.Combine(ProjDir, "BGTJ.sqlite");
if (File.Exists(dbPath))
{
return dbPath;
}
}
return string.Empty;
}
/// <summary>
/// 获取检查结果DB路径
/// </summary>
/// <returns></returns>
public string GetDataCheckrResultPath()
{
if (!string.IsNullOrWhiteSpace(ProjDir))
{
string dbPath = System.IO.Path.Combine(ProjDir, "DataCheckrResult.db");
if (File.Exists(dbPath))
{
return dbPath;
}
}
return string.Empty;
}
public string GetDHZSDBPath()
{
if (!string.IsNullOrWhiteSpace(ProjDir))
{
string dbPath = System.IO.Path.Combine(ProjDir, "外业助手.gdb");
if (Directory.Exists(dbPath))
{
return dbPath;
}
}
return string.Empty;
}
/// <summary>
/// 地图范围
/// </summary>
public MapExtent MapExtent { get; set; }
public bool Save()
{
try
{
if (string.IsNullOrWhiteSpace(this.ProjDir))
{
return false;
}
//将对象序列化成字符串
//string Str = SerializeAPI.SerializeToXML<ProjectInfo>(this);
string sss = JsonConvert.SerializeObject(this);
//对字符串进行加密
Byte[] resultArray = AesEncrypt(sss, "58ef12f9891a4cd89fa7bdd181ef13a7");
//修改人:李进营 修改时间 增加using引用
using (Stream stream = new FileStream(this.ProjDir + "\\" + this.ProjName + ProjSuffix, FileMode.Create, FileAccess.Write, FileShare.None))
{
stream.Write(resultArray, 0, resultArray.Length);
stream.Close();
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
public string GetPRJName()
{
string result = string.Empty;
if (!string.IsNullOrWhiteSpace(PrjFileStr))
{
try
{
string beginstr = "[";
int leftindex = PrjFileStr.IndexOf(beginstr) + beginstr.Length;
string spatialrefrightstr = PrjFileStr.Substring(leftindex);
int length = spatialrefrightstr.IndexOf(",");
result = spatialrefrightstr.Substring(0, length).Replace("\"", "");
}
catch
{
}
}
return result;
}
/// <summary>
/// AES 加密
/// </summary>
/// <param name="str">需要加密的字符串</param>
/// <param name="key">秘钥</param>
/// <returns></returns>
public Byte[] AesEncrypt(string str, string strKey)
{
try
{
if (string.IsNullOrWhiteSpace(strKey))
throw new Exception("加密秘钥为空!");
byte[] Key = Encoding.UTF8.GetBytes(strKey);
if (Key.Length != 32)
throw new Exception("秘钥长度不符合要求!");
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
string strBase64 = Convert.ToBase64String(toEncryptArray);
byte[] contentArray = Encoding.UTF8.GetBytes(strBase64);
#region 加密
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
{
Key = Key,
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
};
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(contentArray, 0, contentArray.Length);
#endregion
return resultArray;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 解密函数
/// </summary>
/// <param name="content">Base64字符串</param>
/// <param name="strKey">秘钥</param>
/// <returns></returns>
public static string Decrypt(string content, string strKey)
{
string result = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(content))
return string.Empty;
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(strKey),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
};
//将base64字符串转换成byte数组
byte[] contentArray = Convert.FromBase64String(content);
//创建解密转换器
System.Security.Cryptography.ICryptoTransform cDecryptTransform = rm.CreateDecryptor();
//对byte数组进行解密转换
Byte[] DecryptArray = cDecryptTransform.TransformFinalBlock(contentArray, 0, contentArray.Length);
//将解密后的byte[]转换成字符串(base64)
string strDecrypt = Encoding.UTF8.GetString(DecryptArray);
//将base64字符串转换成8位无符号整数数组
byte[] base64ToByte = Convert.FromBase64String(strDecrypt);
//string s = Encoding.UTF8.GetString(base64ToByte);
//将8位无符号整数数组转换成等效字符串,并返回
return Encoding.UTF8.GetString(base64ToByte);
}
catch (Exception ex)
{
throw new Exception("解密工程文件异常:" + ex.Message);
}
finally
{
GC.Collect();
}
}
private string ByteToString(byte[] arrByte)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in arrByte)
{
sb.Append(b > 15 ? Convert.ToString(b, 16) : '0' + Convert.ToString(b, 16));
}
return sb.ToString();
}
#region 工程信息增加
/// <summary>
/// 项目类型
/// </summary>
public EnumProjType ProjType { get; set; }
/// <summary>
/// 县级行政区代码发生变化
/// </summary>
public bool XZQDMChange { get; set; }
/// <summary>
/// 城镇村等用地碎图斑小于30平的是否自动修复
/// </summary>
public bool LessThan30Missing { get; set; }
/// <summary>
/// 村级调查区名称发生变化
/// </summary>
public bool ZLDWMCChange { get; set; }
/// <summary>
/// 调入村级调查区
/// </summary>
public string DR_CJDCQPath { get; set; }
/// <summary>
/// 调入行政区
/// </summary>
public string DR_XZQPath { get; set; }
/// <summary>
/// 坐落变更信息
/// </summary>
public ObservableCollection<ZLXXInfo> ListZLXXInfo { get; set; }
#endregion
public string DataCheckPath { get; set; }
/// <summary>
/// 调入CZC
/// </summary>
public string DR_CZCPath { get; set; }
}
/// <summary>
/// 属性赋值配置类
/// </summary>
[Serializable]
public class KZMJInfo : INotifyPropertyChanged
{
private double tZQ_LDMJ;
private double tZQ_LDMJ_GQ;
private double tZQ_HDMJ;
private double tZQ_HDMJ_GQ;
private double tZH_LDMJ;
private double tZH_LDMJ_GQ;
private double tZH_HDMJ;
private double tZH_HDMJ_GQ;
/// <summary>
/// 调整前陆地面积
/// </summary>
public double TZQ_LDMJ
{
get => tZQ_LDMJ;
set
{
tZQ_LDMJ = value;
TZQ_LDMJ_GQ = Math.Round(value * 0.0001, 2);
RaisePropertyChanged("TZQ_LDMJ");
}
}
/// <summary>
/// 调整前陆地面积(公顷)
/// </summary>
public double TZQ_LDMJ_GQ
{
get => tZQ_LDMJ_GQ; set
{
tZQ_LDMJ_GQ = value;
RaisePropertyChanged("TZQ_LDMJ_GQ");
}
}
/// <summary>
/// 调整前海岛面积
/// </summary>
public double TZQ_HDMJ
{
get => tZQ_HDMJ; set
{
tZQ_HDMJ = value;
TZQ_HDMJ_GQ = Math.Round(value * 0.0001, 2);
RaisePropertyChanged("TZQ_HDMJ");
}
}
/// <summary>
/// 调整前海岛面积(公顷)
/// </summary>
public double TZQ_HDMJ_GQ
{
get => tZQ_HDMJ_GQ; set
{
tZQ_HDMJ_GQ = value;
RaisePropertyChanged("TZQ_HDMJ_GQ");
}
}
/// <summary>
/// 调整后陆地面积
/// </summary>
public double TZH_LDMJ
{
get => tZH_LDMJ; set
{
tZH_LDMJ = value;
TZH_LDMJ_GQ = Math.Round(value * 0.0001, 2);
RaisePropertyChanged("TZH_LDMJ");
}
}
/// <summary>
/// 调整后陆地面积(公顷)
/// </summary>
public double TZH_LDMJ_GQ
{
get => tZH_LDMJ_GQ; set
{
tZH_LDMJ_GQ = value;
RaisePropertyChanged("TZH_LDMJ_GQ");
}
}
/// <summary>
/// 调整后海岛面积
/// </summary>
public double TZH_HDMJ
{
get => tZH_HDMJ; set
{
tZH_HDMJ = value;
TZH_HDMJ_GQ = Math.Round(value * 0.0001, 2);
RaisePropertyChanged("TZH_HDMJ");
}
}
/// <summary>
/// 调整后海岛面积(公顷)
/// </summary>
public double TZH_HDMJ_GQ
{
get => tZH_HDMJ_GQ; set
{
tZH_HDMJ_GQ = value;
RaisePropertyChanged("TZH_HDMJ_GQ");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// 地图范围
/// </summary>
[Serializable]
public class MapExtent
{
public double XMax { get; set; }
public double YMax { get; set; }
public double XMin { get; set; }
public double YMin { get; set; }
}
public enum EnumProjType
{
NDBG,
RCBG_ZJG,
RCBG_BCGD,
BHTBTQ,
DTBJK,
YCLJK,
WYZS
}
}