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 { /// /// UCInheritBSM.xaml 的交互逻辑 /// public partial class FrmInheritBSM : BaseWindow { private IWorkspaceAPI s_WsAPI = null; public FrmInheritBSM() { InitializeComponent(); } /// /// 当前正在执行的图层 /// public IFeatureClass CurrfeatureClass = null; /// /// 继承BSM无图形变化 /// public List dLTBBSMs = new List(); /// /// 重编BSM图形变化 /// public List dLTBBSM_ResetBSM = new List(); public string MaxBSM = string.Empty; private void btnSelectedImportDataPath_Click(object sender, RoutedEventArgs e) { try { List baseDataPathList = new List(); 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); } } /// /// 选择要素类 /// 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); } } /// /// 标识码继承方法 /// /// /// 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_ResetBSM = new List(); #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 afterBSMs = new List(); List beforeBSMs = new List(); //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 keyValuePairsBSM = new Dictionary(); Dictionary 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() { 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 sqlList = new List(); 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 dLGCTBBSMs = new List(); 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 afterBSMs = new List(); List beforeBSMs = new List(); 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() { 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() { 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) { } } /// /// 验证继承标识码是否重复-测试项 /// 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 keyValuePairsBSM = new Dictionary(); 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()); } } /// /// 无需重新编码的数据 /// /// public Dictionary GCBGXWGroup() { IFeatureClass DLTBGC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC"); Dictionary keyValuePairs = new Dictionary(); 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; } /// /// 批量插入DB数据 /// /// DB路径 /// 要插入的sql语句集合 public void InsertSQLiteData(string dbPath, List 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 获取最新标识码 /// /// 从前后的更新层及基础库中获取最新BSM不与当前三个要素类重复 /// /// 要素集合 /// public static string GetNewBSM(List 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 } /// /// Old-上一次增量数据;New本次的增量数据 /// public class DLTBBSM { /// /// 上一次变更更新层BSM /// public string beforeBSM { get; set; } /// /// 当前更新层BSM /// public string afterBSM { get; set; } /// /// 上一次更新层OID /// public string beforeFID { get; set; } /// /// 当前更新层OID /// public string afterFID { get; set; } /// /// 旧的图斑面积 /// public double OldTBMJ { get; set; } /// /// 新的图斑面积 /// 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; } } }