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

728 lines
37 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.Filter;
using KGIS.Framework.OpenData.InterFace;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Data.SQLite;
using KGIS.Framework.Maps;
using Kingo.PluginServiceInterface;
using KUI.Windows;
using System.IO;
using KGIS.Framework.AE;
using ESRI.ArcGIS.Geometry;
using Path = System.IO.Path;
using Kingo.OpenData.Filter;
using KGIS.Framework.AE.Enum;
namespace Kingo.Plugin.BuildZLDatabase.View
{
/// <summary>
/// UCInheritBSM.xaml 的交互逻辑
/// </summary>
public partial class FrmInheritBSM : BaseWindow
{
private IWorkspaceAPI s_WsAPI = null;
public FrmInheritBSM()
{
InitializeComponent();
}
/// <summary>
/// 当前正在执行的图层
/// </summary>
public IFeatureClass CurrfeatureClass = null;
/// <summary>
/// 继承BSM无图形变化
/// </summary>
public List<DLTBBSM> dLTBBSMs = new List<DLTBBSM>();
/// <summary>
/// 重编BSM图形变化
/// </summary>
public List<DLTBBSM> dLTBBSM_ResetBSM = new List<DLTBBSM>();
public string MaxBSM = string.Empty;
private void btnSelectedImportDataPath_Click(object sender, RoutedEventArgs e)
{
try
{
List<string> baseDataPathList = new List<string>();
OpenDataDialog pDialog = new OpenDataDialog();
ISpatialDataObjectFilter pOFilter = new FilterGeoDatabasePersonal();
pDialog.AddFilter(pOFilter, true);
pOFilter = new FilterVCTFile();///VCT文件模式
pDialog.AddFilter(pOFilter, true);
pOFilter = new FilterGeoDatabaseFile();
pDialog.AddFilter(pOFilter, true);
pDialog.AllowMultiSelect = false;
pDialog.Title = "选择基础数据";
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog();
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0)
{
string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart();
if (string.IsNullOrWhiteSpace(ImportDataType) || (ImportDataType != "GDB" && ImportDataType != "MDB"))
{
MessageHelper.Show("选择的数据路径有误,请根据过滤条件,重新选择数据库!!");
return;
}
string filePath = pDialog.FinalLocation;
if (string.IsNullOrWhiteSpace(filePath)) return;
if (ImportDataType == "MDB" || ImportDataType == "VCT")
{
s_WsAPI = new WorkspaceAPI(filePath, WorkspaceTypeEnum.MDBFile);
}
else
{
s_WsAPI = new WorkspaceAPI(filePath, WorkspaceTypeEnum.GDBFile, true);
}
if (s_WsAPI == null)
{
MessageHelper.Show("选择的数据路径有误,请根据过滤条件,重新选择数据库!!");
return;
}
if (!s_WsAPI.ExistFeatureClass("DLTBGX") || !s_WsAPI.ExistFeatureClass("DLTBGXGC"))
{
MessageHelper.Show("选择的数据库中缺失增量数据图层,请重新选择包含(DLTBGX,GLTBGXGC)图层!");
return;
}
btnImportDataPath.EditValue = pDialog.FinalLocation;
}
}
catch (Exception ex)
{
LogAPI.Debug("选择基础数据库失败:" + ex);
MessageHelper.Show("选择基础数据库失败:" + ex);
}
}
/// <summary>
/// 选择要素类
/// </summary>
private void SelectFeatureClassFile()
{
try
{
OpenDataDialog pDialog = new OpenDataDialog();
ISpatialDataObjectFilter pOFilter;
pOFilter = new FilterDatasetsAndLayers();
pDialog.AddFilter(pOFilter, false);
pDialog.Title = "选择导入的数据";
pDialog.AllowMultiSelect = false;
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog();
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0)
{
if (Path.GetFileNameWithoutExtension(pDialog.FinalLocation) != "DLTBGXGC" && Path.GetFileNameWithoutExtension(pDialog.FinalLocation) != "DLTBGX")
{
MessageHelper.ShowTips("请选择DLTBGX/DLTBGXGC!");
return;
}
btnImportDataPath.EditValue = pDialog.FinalLocation;
foreach (ISpatialDataObject distObj in pDialog.Selection)
{
if (distObj.DatasetType == esriDatasetType.esriDTFeatureClass)
{
CurrfeatureClass = (distObj.DatasetName as IName).Open() as IFeatureClass;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
/// <summary>
/// 标识码继承方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSure_Click(object sender, RoutedEventArgs e)
{
IFeatureLayer featureLayer_UnionGX = null;
IFeatureLayer featureLayer_UnionGXGC = null;
ICursor pCur = null;
IRow pRow = null;
try
{
this.ShowLoading("正在进行赋值处理...", 0, 0);
dLTBBSMs = new List<DLTBBSM>();
dLTBBSM_ResetBSM = new List<DLTBBSM>();
#region 数据准备
string dir = Path.Combine(SysAppPath.GetCurrentAppPath(), "Temp\\InheritBSMCache");
var path = Path.Combine(dir, DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".mdb");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
DelectDir(dir);//删除上次生成的文件
if (!File.Exists(path))
{
File.Copy(SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\临时文件\\TempMDB.mdb", path, true);
}
IFeatureClass DLTBGX = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGX");
IFeatureClass JC_DLTB = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑").FeatureClass;
IFeatureClass DLTBGXGC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC");
IWorkspaceAPI workspaceAPI = GeoDBAPI.GetWorkspaceByPath(path);
IFeatureClass featureTemp = workspaceAPI.CreateFeatureClass("TempSelectData", (JC_DLTB as IGeoDataset).SpatialReference, DLTBGX.Fields).FeatureClass;
IFeatureClassAPI lassAPI = new FeatureClassAPI(CurrfeatureClass);
lassAPI.FcToFc(featureTemp, null, false);
IQueryDef pQDef = ((featureTemp as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "TempSelectData";
pQDef.WhereClause = " 1=1 GROUP BY BSM having Count(BSM)>1";
pQDef.SubFields = "BSM";
pCur = pQDef.Evaluate();
if (pCur.NextRow() != null)//验证数据的BSM准确性
{
MessageHelper.ShowTips("选择的增量数据BSM不唯一!");
this.CloseLoading();
if (workspaceAPI != null)
workspaceAPI.CloseWorkspace();
if (featureTemp != null)
Marshal.ReleaseComObject(featureTemp);
return;
}
IFeatureClassAPI featureClassAPIGX = s_WsAPI.OpenFeatureClass("DLTBGX");
CurrfeatureClass = featureClassAPIGX.FeatureClass;
if (CurrfeatureClass.AliasName.ToUpper() == "DLTBGX" || CurrfeatureClass.AliasName == "地类图斑更新")
{
//两次更新层进行数据叠加分析
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = new FeatureLayer { FeatureClass = CurrfeatureClass };
gPParamClass.SecondFeatureLayer = new FeatureLayer { FeatureClass = DLTBGX };
gPParamClass.OutFeatureClassPath = Path.Combine(path, "Union_DLTBGX");
gPParamClass.IsGetOutPutFeature = true;
GeoprocessorHelper.UnionAnalysis(gPParamClass, ref featureLayer_UnionGX);
List<string> afterBSMs = new List<string>();
List<string> beforeBSMs = new List<string>();
//string dbPath = Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
#endregion
if (featureLayer_UnionGX != null)//叠加后的前后两次的更新层
{
this.UpdateMsg("BSM继承数据准备~");
pQDef = ((featureLayer_UnionGX.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "Union_DLTBGX";
pQDef.WhereClause = " 1=1 GROUP BY BSM having Count(BSM)>1";
pQDef.SubFields = "BSM";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
beforeBSMs.Add(pRow.get_Value(0).ToString());
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
pQDef.Tables = "Union_DLTBGX";
pQDef.WhereClause = " 1=1 GROUP BY BSM_1 having Count(BSM_1)>1";
pQDef.SubFields = "BSM_1";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
afterBSMs.Add(pRow.get_Value(0).ToString());
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
pQDef.Tables = "Union_DLTBGX";
pQDef.WhereClause = "FID_DLTBGX<>-1 and FID_DLTBGX_1<>-1";
pQDef.SubFields = "BSM,BSM_1,FID_DLTBGX,FID_DLTBGX_1,TBMJ,TBDLMJ,KCMJ";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
if (beforeBSMs.Contains(pRow.get_Value(0).ToString()) || afterBSMs.Contains(pRow.get_Value(1).ToString()))
{
continue;
}
//查询图形没有变化的数据
DLTBBSM dLTBBSM = new DLTBBSM
{
beforeBSM = pRow.get_Value(0).ToString(),
afterBSM = pRow.get_Value(1).ToString(),//当前BSM
beforeFID = pRow.get_Value(2).ToString(),
afterFID = pRow.get_Value(3).ToString(),
OldTBMJ = pRow.get_Value(4).ToString().ToDouble(),
OldTBDLML = string.IsNullOrWhiteSpace(pRow.get_Value(5).ToString()) ? 0 : pRow.get_Value(5).ToString().ToDouble(),
OldKCMJ = string.IsNullOrWhiteSpace(pRow.get_Value(6).ToString()) ? 0 : pRow.get_Value(6).ToString().ToDouble()
};
dLTBBSMs.Add(dLTBBSM);//继承BSM数据准备
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
#region 继承上一次更新层BSM(无图形变化的图斑直接继承)
this.UpdateMsg("继承上一次更新层BSM~");
ITable tableCurrGX = DLTBGX as ITable;
ICursor cursor = tableCurrGX.Update(null, true);
IRow rowCurrGX = null;
int BSMIdx = tableCurrGX.FindField("BSM");//当前更新层字段
int OIDIdx = tableCurrGX.FindField("OBJECTID");
int TBMJIdx = tableCurrGX.FindField("TBMJ");
int TBDLMLIdx = tableCurrGX.FindField("TBDLMJ");
int KCMJIdx = tableCurrGX.FindField("KCMJ");
//重新编BSM,数据记录
Dictionary<string, string> keyValuePairsBSM = new Dictionary<string, string>();
Dictionary<string, string> keyValues = GCBGXWGroup();
while ((rowCurrGX = cursor.NextRow()) != null)
{
//继承上一次BSM
if (dLTBBSMs.FirstOrDefault(x => x.afterFID == rowCurrGX.get_Value(OIDIdx).ToString()) != null)
{
DLTBBSM dLTBBSM = dLTBBSMs.FirstOrDefault(x => x.afterFID == rowCurrGX.get_Value(OIDIdx).ToString());
//LogAPI.Debug("继承标识码和面积:"+ rowCurrGX.Value[BSMIdx] + ":"+ dLTBBSM.beforeBSM+":"+ dLTBBSM.OldTBMJ);
rowCurrGX.Value[BSMIdx] = dLTBBSM.beforeBSM;
if (ckbJCTBMJ.IsChecked == true && dLTBBSM != null)
{
rowCurrGX.Value[TBMJIdx] = dLTBBSM.OldTBMJ;
rowCurrGX.Value[TBDLMLIdx] = dLTBBSM.OldTBDLML;
rowCurrGX.Value[KCMJIdx] = dLTBBSM.OldKCMJ;
}
}
else
{
if (keyValues.ContainsKey(rowCurrGX.get_Value(BSMIdx).ToString())) continue;
//除去继承的,将其余BSM全部重新编
if (string.IsNullOrEmpty(MaxBSM))
{
MaxBSM = GetNewBSM(new List<IFeatureClass>() { JC_DLTB, DLTBGX, DLTBGXGC, CurrfeatureClass });
}
else
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10));
string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
MaxBSM = bghBSM;
}
if (!keyValuePairsBSM.ContainsKey(rowCurrGX.get_Value(BSMIdx).ToString()))//若是包含,则数据错误
keyValuePairsBSM.Add(rowCurrGX.get_Value(BSMIdx).ToString(), MaxBSM);
rowCurrGX.Value[BSMIdx] = MaxBSM;
}
cursor.UpdateRow(rowCurrGX);
}
cursor.Flush();
#endregion
#region 更新过程BSM修改
this.UpdateMsg("修改对应的更新过程层变更后图斑BSM~");
ITable tableCurrGXGC = DLTBGXGC as ITable;
ICursor cursorGC = tableCurrGXGC.Update(null, true);
IRow rowCurrGXGC = null;
int GCBSMIdx = tableCurrGXGC.FindField("BGHTBBSM");//当前更新过程层字段
int GCQBSMIdx = tableCurrGXGC.FindField("BGQTBBSM");
int BGXWIdx = tableCurrGXGC.FindField("BGXW");
int BGHTBBHIdx = tableCurrGXGC.FindField("BGHTBBH");
int BGQTBBHIdx = tableCurrGXGC.FindField("BGQTBBH");
List<string> sqlList = new List<string>();
string sqlBXXXB = string.Empty;
while ((rowCurrGXGC = cursorGC.NextRow()) != null)
{
//继承标识码的更新过程层
if (dLTBBSMs.FirstOrDefault(x => x.afterBSM == rowCurrGXGC.get_Value(GCBSMIdx).ToString()) != null)
{
string QBSM = dLTBBSMs.FirstOrDefault(x => x.afterBSM == rowCurrGXGC.get_Value(GCBSMIdx).ToString()).beforeBSM;
//sqlBXXXB = string.Format("update BHXXB set BGHTBBSM='{0}' where BGHTBBSM='{1}' AND BGQTBBSM='{2}' AND BGHTBBH='{3}' AND BGQTBBH='{4}'", QBSM, rowCurrGXGC.get_Value(GCBSMIdx).ToString(), rowCurrGXGC.get_Value(GCQBSMIdx).ToString(), rowCurrGXGC.get_Value(BGHTBBHIdx).ToString(), rowCurrGXGC.get_Value(BGQTBBHIdx).ToString());
//sqlList.Add(sqlBXXXB);
rowCurrGXGC.Value[GCBSMIdx] = QBSM;
cursorGC.UpdateRow(rowCurrGXGC);
continue;
}
//重新编码BSM的更新过程层
if (keyValuePairsBSM.ContainsKey(rowCurrGXGC.get_Value(GCBSMIdx).ToString()))
{
if (rowCurrGXGC.get_Value(BGXWIdx).ToString() == "1") continue;//继承还是新变更图斑,属性变化数据BGHBSM不变
string XBSM = keyValuePairsBSM.FirstOrDefault(x => x.Key == rowCurrGXGC.get_Value(GCBSMIdx).ToString()).Value;
//sqlBXXXB = string.Format("update BHXXB set BGHTBBSM='{0}' where BGHTBBSM='{1}' AND BGQTBBSM='{2}' AND BGHTBBH='{3}' AND BGQTBBH='{4}'", XBSM, rowCurrGXGC.get_Value(GCBSMIdx).ToString(), rowCurrGXGC.get_Value(GCQBSMIdx).ToString(), rowCurrGXGC.get_Value(BGHTBBHIdx).ToString(), rowCurrGXGC.get_Value(BGQTBBHIdx).ToString());
//sqlList.Add(sqlBXXXB);
rowCurrGXGC.Value[GCBSMIdx] = XBSM;
cursorGC.UpdateRow(rowCurrGXGC);
continue;
}
}
cursorGC.Flush();
//InsertSQLiteData(dbPath, sqlList);//修改变化信息表变更后图斑BSM
#endregion
}
}
CurrfeatureClass = null;
CurrfeatureClass = s_WsAPI.OpenFeatureClass("DLTBGXGC").FeatureClass;
List<DLTBBSM> dLGCTBBSMs = new List<DLTBBSM>();
if (CurrfeatureClass.AliasName.ToUpper() == "DLTBGXGC" || CurrfeatureClass.AliasName == "地类图斑更新过程")
{
//两次更新层进行数据叠加分析
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = new FeatureLayer { FeatureClass = CurrfeatureClass };
gPParamClass.SecondFeatureLayer = new FeatureLayer { FeatureClass = DLTBGXGC };
gPParamClass.OutFeatureClassPath = Path.Combine(path, "Union_DLTBGXGC");
gPParamClass.IsGetOutPutFeature = true;
GeoprocessorHelper.UnionAnalysis(gPParamClass, ref featureLayer_UnionGXGC);
List<string> afterBSMs = new List<string>();
List<string> beforeBSMs = new List<string>();
if (featureLayer_UnionGXGC != null)//叠加后的前后两次的更新过程层
{
this.UpdateMsg("BSM继承数据准备~");
pQDef = ((featureLayer_UnionGXGC.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "Union_DLTBGXGC";
pQDef.WhereClause = " 1=1 GROUP BY BSM having Count(BSM)>1";
pQDef.SubFields = "BSM";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
beforeBSMs.Add(pRow.get_Value(0).ToString());
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
pQDef.Tables = "Union_DLTBGXGC";
pQDef.WhereClause = " 1=1 GROUP BY BSM_1 having Count(BSM_1)>1";
pQDef.SubFields = "BSM_1";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
afterBSMs.Add(pRow.get_Value(0).ToString());
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
pQDef.Tables = "Union_DLTBGXGC";
pQDef.WhereClause = "FID_DLTBGXGC<>-1 and FID_DLTBGXGC_1<>-1";
pQDef.SubFields = "BSM,BSM_1,FID_DLTBGXGC,FID_DLTBGXGC_1,TBBGMJ,BGHTBDLMJ,BGHKCMJ,BGQTBDLMJ,BGQKCMJ";
pCur = pQDef.Evaluate();
while ((pRow = pCur.NextRow()) != null)
{
if (beforeBSMs.Contains(pRow.get_Value(0).ToString()) || afterBSMs.Contains(pRow.get_Value(1).ToString())) continue;
//查询图形没有变化的数据
DLTBBSM dLTBBSM = new DLTBBSM
{
beforeBSM = pRow.get_Value(0).ToString(),
afterBSM = pRow.get_Value(1).ToString(),//当前BSM
beforeFID = pRow.get_Value(2).ToString(),
afterFID = pRow.get_Value(3).ToString(),
OldTBMJ = pRow.get_Value(4).ToString().ToDouble(),
OldTBDLML = string.IsNullOrWhiteSpace(pRow.get_Value(5).ToString()) ? 0 : pRow.get_Value(5).ToString().ToDouble(),
OldKCMJ = string.IsNullOrWhiteSpace(pRow.get_Value(6).ToString()) ? 0 : pRow.get_Value(6).ToString().ToDouble(),
OldBGQTBDLMJ = string.IsNullOrWhiteSpace(pRow.get_Value(7).ToString()) ? 0 : pRow.get_Value(7).ToString().ToDouble(),
OldBGQKCMJ = string.IsNullOrWhiteSpace(pRow.get_Value(8).ToString()) ? 0 : pRow.get_Value(8).ToString().ToDouble()
};
dLGCTBBSMs.Add(dLTBBSM);//继承BSM数据准备
Marshal.ReleaseComObject(pRow);
}
Marshal.ReleaseComObject(pCur);
#region 继承上一次更新层BSM(无图形变化的图斑直接继承)
this.UpdateMsg("继承上一次更新过程层BSM~");
ITable tableCurrGXGC = DLTBGXGC as ITable;
ICursor cursor = tableCurrGXGC.Update(null, true);
IRow rowCurrGXGC = null;
int BSMIdx = tableCurrGXGC.FindField("BSM");//当前更新过程层字段
int OIDIdx = tableCurrGXGC.FindField("OBJECTID");
int TBMJIdx = tableCurrGXGC.FindField("TBBGMJ");
int BGHTBDLMJIdx = tableCurrGXGC.FindField("BGHTBDLMJ");
int BGHTBBSMIdx = tableCurrGXGC.FindField("BGHTBBSM");
int BGHKCMJIdx = tableCurrGXGC.FindField("BGHKCMJ");
int BGQKCMJIdx = tableCurrGXGC.FindField("BGQKCMJ");
int BGQTBDLMJIdx = tableCurrGXGC.FindField("BGQTBDLMJ");
//重新编BSM,数据记录
while ((rowCurrGXGC = cursor.NextRow()) != null)
{
//继承上一次BSM
if (dLGCTBBSMs.FirstOrDefault(x => x.afterFID == rowCurrGXGC.get_Value(OIDIdx).ToString()) != null)
{
//上一次进行更新继承的数据
DLTBBSM dLGXTBBSM = dLTBBSMs.FirstOrDefault(x => x.beforeBSM == rowCurrGXGC.get_Value(BGHTBBSMIdx).ToString());
if (dLGXTBBSM == null)
{
if (string.IsNullOrEmpty(MaxBSM))
{
MaxBSM = GetNewBSM(new List<IFeatureClass>() { JC_DLTB, DLTBGX, DLTBGXGC, CurrfeatureClass });
}
else
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10));
string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
MaxBSM = bghBSM;
}
rowCurrGXGC.Value[BSMIdx] = MaxBSM;
cursor.UpdateRow(rowCurrGXGC);
continue;
}//可能涉及到继承BSM之前,前后增量数据发生了变化;导致面积前后过程面积出现不一致的情况;
DLTBBSM dLTBBSM = dLGCTBBSMs.FirstOrDefault(x => x.afterFID == rowCurrGXGC.get_Value(OIDIdx).ToString());
rowCurrGXGC.Value[BSMIdx] = dLTBBSM.beforeBSM;
if (ckbJCTBMJ.IsChecked == true && dLTBBSM != null)
{
rowCurrGXGC.Value[TBMJIdx] = dLTBBSM.OldTBMJ;
rowCurrGXGC.Value[BGHTBDLMJIdx] = dLTBBSM.OldTBDLML;
rowCurrGXGC.Value[BGHKCMJIdx] = dLTBBSM.OldKCMJ;
rowCurrGXGC.Value[BGQKCMJIdx] = dLTBBSM.OldBGQKCMJ;
rowCurrGXGC.Value[BGQTBDLMJIdx] = dLTBBSM.OldBGQTBDLMJ;
}
}
else
{
//除去继承的,将其余BSM全部重新编
if (string.IsNullOrEmpty(MaxBSM))
{
MaxBSM = GetNewBSM(new List<IFeatureClass>() { JC_DLTB, DLTBGX, DLTBGXGC, CurrfeatureClass });
}
else
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10));
string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
MaxBSM = bghBSM;
}
rowCurrGXGC.Value[BSMIdx] = MaxBSM;
}
cursor.UpdateRow(rowCurrGXGC);
}
cursor.Flush();
#endregion
}
}
MaxBSM = string.Empty;
this.CloseLoading();
if (workspaceAPI != null) workspaceAPI.CloseWorkspace();
if (s_WsAPI != null) s_WsAPI.CloseWorkspace();
if (featureTemp != null) Marshal.ReleaseComObject(featureTemp);
if (CurrfeatureClass != null) Marshal.ReleaseComObject(CurrfeatureClass);
MessageHelper.Show("标识码赋值成功!");
this.Close();
}
catch (Exception ex)
{
MaxBSM = string.Empty;
this.CloseLoading();
MessageHelper.Show("赋值失败!" + ex.Message);
LogAPI.Debug(ex);
}
finally
{
if (pCur != null)
{
Marshal.ReleaseComObject(pCur);
}
this.CloseLoading();
}
}
private void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception)
{ }
}
/// <summary>
/// 验证继承标识码是否重复-测试项
/// </summary>
public void TestGXBSM()
{
IFeatureClass DLTBGX = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGX");
ITable tableCurrGX = DLTBGX as ITable;
ICursor cursor = tableCurrGX.Search(null, true);
IRow rowCurrGX = null;
int BSMIdx = tableCurrGX.FindField("BSM");//当前更新层字段
int OIDIdx = tableCurrGX.FindField("OBJECTID");
//重新编BSM,数据记录
Dictionary<string, string> keyValuePairsBSM = new Dictionary<string, string>();
while ((rowCurrGX = cursor.NextRow()) != null)
{
if (!keyValuePairsBSM.ContainsKey(rowCurrGX.get_Value(BSMIdx).ToString()))
keyValuePairsBSM.Add(rowCurrGX.get_Value(BSMIdx).ToString(), rowCurrGX.get_Value(OIDIdx).ToString());
else
MessageHelper.ShowError("出现重复BSM:" + rowCurrGX.get_Value(BSMIdx).ToString());
}
}
/// <summary>
/// 无需重新编码的数据
/// </summary>
/// <returns></returns>
public Dictionary<string, string> GCBGXWGroup()
{
IFeatureClass DLTBGC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC");
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
ITable table = DLTBGC as ITable;
ICursor cursor = table.Search(null, true);
IRow rowGC = null;
int BGHBSMIndex = table.FindField("BGHTBBSM");
int BGXWIndex = table.FindField("BGXW");
while ((rowGC = cursor.NextRow()) != null)
{
if (rowGC.Value[BGXWIndex].ToString() == "1")
keyValuePairs[rowGC.Value[BGHBSMIndex].ToString()] = rowGC.Value[BGXWIndex].ToString();
}
return keyValuePairs;
}
/// <summary>
/// 批量插入DB数据
/// </summary>
/// <param name="dbPath">DB路径</param>
/// <param name="sqlList">要插入的sql语句集合</param>
public void InsertSQLiteData(string dbPath, List<string> sqlList)
{
try
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteTransaction pTrans = conn.BeginTransaction())
{
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
for (int i = 0; i < sqlList.Count(); i++)
{
cmd.CommandText = sqlList[i];
cmd.ExecuteNonQuery();
}
pTrans.Commit();
}
}
conn.Close();
}
}
catch (Exception ex)
{
LogAPI.Debug("批量插入SQLite数据(地址:" + dbPath + ") 执行失败,异常原因: " + ex.Message + " ; ");
return;
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
#region 获取最新标识码
/// <summary>
/// 从前后的更新层及基础库中获取最新BSM不与当前三个要素类重复
/// </summary>
/// <param name="fcList">要素集合</param>
/// <returns></returns>
public static string GetNewBSM(List<IFeatureClass> fcList)
{
string result = string.Empty;
int xh = 0;
string leftStr = string.Empty;
foreach (var item in fcList)
{
string MaxBSM = GetMaxBSM(item);
if (MaxBSM.Length != 18)
continue;
int xh2 = Convert.ToInt32(MaxBSM.Substring(10));
leftStr = MaxBSM.Substring(0, 10);
if (xh < xh2)
xh = xh2;
}
xh++;
if (string.IsNullOrWhiteSpace(leftStr))
leftStr = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + "1210";
result = leftStr + xh.ToString().PadLeft(8, '0');
return result;
}
private static string GetMaxBSM(IFeatureClass fc)
{
System.Windows.Forms.Application.DoEvents();
string BSM = string.Empty;
int BSMIndex = fc.FindField("BSM");
if (BSMIndex == -1) return BSM;
ITable table = (ITable)fc;
// 创建一个ITableSort接口对象
ITableSort tableSort = new TableSortClass();
tableSort.Table = table;
tableSort.Fields = "BSM";
tableSort.set_Ascending("BSM", false);
tableSort.Sort(null);
ICursor cursor = tableSort.Rows;
IRow row = cursor.NextRow();
if (row != null)
{
int maxBSM = 0;
int currBSM = 0;
string BSMStr = row.Value[BSMIndex].ToString();
if (BSMStr.Length != 18) return BSM;
string subBSMStr = BSMStr.Substring(9);
try
{
currBSM = Convert.ToInt32(subBSMStr);
}
catch (Exception)
{
return BSM;
}
if (currBSM > maxBSM) maxBSM = currBSM;
if (BSMStr.Length != 18) return BSM;
string maxStr = maxBSM.ToString();
int zeroNum = 9 - maxStr.Length;
for (int i = 0; i < zeroNum; i++)
{
maxStr = 0 + maxStr;
}
BSM = BSMStr.Substring(0, 9) + maxStr;
}
return BSM;
}
#endregion
}
/// <summary>
/// Old-上一次增量数据;New本次的增量数据
/// </summary>
public class DLTBBSM
{
/// <summary>
/// 上一次变更更新层BSM
/// </summary>
public string beforeBSM { get; set; }
/// <summary>
/// 当前更新层BSM
/// </summary>
public string afterBSM { get; set; }
/// <summary>
/// 上一次更新层OID
/// </summary>
public string beforeFID { get; set; }
/// <summary>
/// 当前更新层OID
/// </summary>
public string afterFID { get; set; }
/// <summary>
/// 旧的图斑面积
/// </summary>
public double OldTBMJ { get; set; }
/// <summary>
/// 新的图斑面积
/// </summary>
public double NewTBMJ { get; set; }
public double OldTBDLML { get; set; }
public double OldBGQTBDLMJ { get; set; }
public double NewTBDLML { get; set; }
public double OldKCMJ { get; set; }
public double OldBGQKCMJ { get; set; }
public double NewKCMJ { get; set; }
}
}