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.
1537 lines
80 KiB
1537 lines
80 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.DataSourcesGDB; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Platform.Helper; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using ReactiveUI; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
using System.Text; |
|
using System.Windows; |
|
using System.Data; |
|
using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using Path = System.IO.Path; |
|
using KGIS.Framework.OpenData.Control; |
|
using KGIS.Framework.OpenData.Filter; |
|
using KGIS.Framework.OpenData.InterFace; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geometry; |
|
using Kingo.PluginServiceInterface; |
|
using Kingo.Plugin.BGResultManager.View; |
|
using KGIS.Framework.AE.Enum; |
|
|
|
namespace Kingo.Plugin.BGResultManager.ViewModel |
|
{ |
|
class ImportBGDataViewModel : ReactiveObject, IScreen |
|
{ |
|
public ImportBGDataViewModel(FrmBGDataImport frmBGDataImport) |
|
{ |
|
ComBoxInit(); |
|
SelectedFWDataClick = ReactiveCommand.Create(); |
|
SelectedFWDataClick.Subscribe(x => |
|
{ |
|
// 获取源数据 |
|
OpenDataDialog pDialog = new OpenDataDialog(); |
|
ISpatialDataObjectFilter pOFilter; |
|
pOFilter = new FilterFeatureDatasetsAndFeatureClasses(); |
|
pDialog.AddFilter(pOFilter, true); |
|
pDialog.Title = "选择划入范围数据"; |
|
pDialog.AllowMultiSelect = false; |
|
pDialog.RestoreLocation = true; |
|
pDialog.StartLocation = pDialog.FinalLocation; |
|
if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count > 0) |
|
{ |
|
List<ISpatialDataObject> distObj = pDialog.Selection; |
|
foreach (var obj in distObj) |
|
{ |
|
if (obj.DatasetType == esriDatasetType.esriDTFeatureClass) |
|
{ |
|
IFeatureClass fc = (obj.DatasetName as IName).Open() as IFeatureClass; |
|
if (fc != null) |
|
{ |
|
IFeatureCursor cur = fc.Search(null, true); |
|
IFeature f = null; |
|
while ((f = cur.NextFeature()) != null) |
|
{ |
|
_SelectedGeo = f.ShapeCopy; |
|
break; |
|
} |
|
} |
|
xjkzjxPath = obj.FullName; |
|
} |
|
} |
|
} |
|
}); |
|
SelectedTemplateClick = ReactiveCommand.Create(); |
|
SelectedTemplateClick.Subscribe(x => |
|
{ |
|
if (CurrentTemplateIndex == -1) |
|
{ |
|
MessageHelper.ShowTips("请选择或创建成果数据模板!"); |
|
return; |
|
} |
|
ImportBGData(); |
|
MessageHelper.Show("导入完成 !"); |
|
frmBGDataImport.Close(); |
|
}); |
|
} |
|
private bool _IsBL;//是否补充0至19位 |
|
public bool IsBL |
|
{ |
|
get { return _IsBL; } |
|
set { this.RaiseAndSetIfChanged(ref _IsBL, value); } |
|
} |
|
|
|
|
|
private List<ResultsCatalog> _Items; |
|
public List<ResultsCatalog> Items |
|
{ |
|
get { return _Items; } |
|
set { this.RaiseAndSetIfChanged(ref _Items, value); } |
|
} |
|
/// <summary> |
|
/// 输出成果根目录 |
|
/// </summary> |
|
//public string OutDataRootDir { get; set; } |
|
public RoutingState Router |
|
{ |
|
get; |
|
} |
|
public ReactiveCommand<object> SelectedTemplateClick { get; protected set; } |
|
public ReactiveCommand<object> SelectedFWDataClick { get; protected set; } |
|
private List<string> _TemplateList; |
|
public List<string> TemplateList |
|
{ |
|
get { return _TemplateList; } |
|
set { this.RaiseAndSetIfChanged(ref _TemplateList, value); } |
|
} |
|
private int _CurrentTemplateIndex; |
|
public int CurrentTemplateIndex |
|
{ |
|
get { return _CurrentTemplateIndex; } |
|
set |
|
{ |
|
this.RaiseAndSetIfChanged(ref _CurrentTemplateIndex, value); |
|
ReadTemplateLayerInfo(); |
|
} |
|
} |
|
|
|
private List<BGVCTEntity> _LayerSource; |
|
public List<BGVCTEntity> LayerSource |
|
{ |
|
get { return _LayerSource; } |
|
set { this.RaiseAndSetIfChanged(ref _LayerSource, value); } |
|
} |
|
|
|
private List<BGVCTEntity> _IncrementalUpdatingSource; |
|
public List<BGVCTEntity> IncrementalUpdatingSource |
|
{ |
|
get { return _IncrementalUpdatingSource; } |
|
set { this.RaiseAndSetIfChanged(ref _IncrementalUpdatingSource, value); } |
|
} |
|
private BGVCTEntity GXVCTEntity = null; |
|
private BGVCTEntity GXGCVCTEntity = null; |
|
private Visibility _SelectTemplate; |
|
public Visibility SelectTemplate |
|
{ |
|
get { return _SelectTemplate; } |
|
set { this.RaiseAndSetIfChanged(ref _SelectTemplate, value); } |
|
} |
|
|
|
private IMapService _MapService { get; set; } |
|
|
|
private string _xjkzjxPath; |
|
public string xjkzjxPath |
|
{ |
|
get { return _xjkzjxPath; } |
|
set { this.RaiseAndSetIfChanged(ref _xjkzjxPath, value); } |
|
} |
|
private IGeometry _SelectedGeo { get; set; } |
|
private void ReadTemplateLayerInfo() |
|
{ |
|
IWorkspaceAPI s_WsAPI = null; |
|
IncrementalUpdatingSource = new List<BGVCTEntity>(); |
|
LayerSource = new List<BGVCTEntity>(); |
|
|
|
try |
|
{ |
|
if (CurrentTemplateIndex != -1) |
|
{ |
|
string templatePath = Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板"); |
|
string vctPath_GX = Path.Combine(templatePath, TemplateList[CurrentTemplateIndex], "VCTTemplate3ForBG.VCT"); |
|
string vctPath_GXGC = Path.Combine(templatePath, TemplateList[CurrentTemplateIndex], "VCTTemplate3ForBG2.VCT"); |
|
Dictionary<string, string> layers = GetLayersForVCT(vctPath_GX, vctPath_GXGC); |
|
string currentGDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath(); |
|
s_WsAPI = new WorkspaceAPI(currentGDBPath, WorkspaceTypeEnum.GDBFile); |
|
foreach (KeyValuePair<string, string> kvp in layers) |
|
{ |
|
if ("DLTBGX,DLTBGXGC,XZQGX,XZQGXGC,CJDCQGX,CJDCQGXGC,XZQJXGX,CJDCQJXGX".Contains(kvp.Value)) |
|
{ |
|
IFeatureClassAPI fcAPI = s_WsAPI.OpenFeatureClass(kvp.Value); |
|
if (fcAPI != null) |
|
{ |
|
IFeatureClass fc = fcAPI.FeatureClass; |
|
BGVCTEntity bGVCT = new BGVCTEntity() { Name = fc.AliasName, FeatureClassName = kvp.Value, ParentEntity = GXVCTEntity }; |
|
IncrementalUpdatingSource.Add(bGVCT); |
|
} |
|
continue; |
|
} |
|
else |
|
{ |
|
|
|
IFeatureClassAPI fcAPI = s_WsAPI.OpenFeatureClass(kvp.Value); |
|
if (fcAPI != null) |
|
{ |
|
IFeatureClass fc = fcAPI.FeatureClass; |
|
BGVCTEntity bGVCT = new BGVCTEntity() { Name = fc.AliasName, FeatureClassName = kvp.Value, ParentEntity = GXGCVCTEntity }; |
|
LayerSource.Add(bGVCT); |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally |
|
{ |
|
if (s_WsAPI != null) |
|
{ |
|
s_WsAPI.CloseWorkspace(); |
|
} |
|
} |
|
} |
|
private Dictionary<string, string> GetLayersForVCT(string pVCTPath, string pVCTPath2) |
|
{ |
|
Dictionary<string, string> dic = new Dictionary<string, string>(); |
|
StreamReader sr = new StreamReader(pVCTPath, Encoding.GetEncoding("GB18030")); |
|
string line = null; |
|
bool BeginLoad = false; |
|
while ((line = sr.ReadLine()) != null) |
|
{ |
|
if (line == "FeatureCodeBegin") |
|
{ |
|
BeginLoad = true; |
|
} |
|
if (BeginLoad && line != "FeatureCodeBegin") |
|
{ |
|
string[] strs = line.Split(','); |
|
if (strs.Length == 4) |
|
{ |
|
dic.Add(strs[1], strs[3]); |
|
} |
|
} |
|
if (line == "FeatureCodeEnd") |
|
{ |
|
BeginLoad = false; |
|
break; |
|
} |
|
} |
|
sr.Close(); |
|
sr.Dispose(); |
|
StreamReader sr2 = new StreamReader(pVCTPath2, Encoding.GetEncoding("GB18030")); |
|
line = null; |
|
BeginLoad = false; |
|
while ((line = sr2.ReadLine()) != null) |
|
{ |
|
if (line == "FeatureCodeBegin") |
|
{ |
|
BeginLoad = true; |
|
} |
|
if (BeginLoad && line != "FeatureCodeBegin") |
|
{ |
|
string[] strs = line.Split(','); |
|
if (strs.Length == 4) |
|
{ |
|
dic.Add(strs[1], strs[3]); |
|
} |
|
} |
|
if (line == "FeatureCodeEnd") |
|
{ |
|
BeginLoad = false; |
|
break; |
|
} |
|
} |
|
sr2.Close(); |
|
sr2.Dispose(); |
|
return dic; |
|
} |
|
private void ComBoxInit() |
|
{ |
|
try |
|
{ |
|
string templatePath = Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板"); |
|
if (!Directory.Exists(templatePath)) |
|
Directory.CreateDirectory(templatePath); |
|
string[] temps = System.IO.Directory.GetDirectories(Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板")); |
|
TemplateList = new List<string>(); |
|
foreach (var item in temps) |
|
{ |
|
DirectoryInfo f = new DirectoryInfo(item); |
|
TemplateList.Add(f.Name); |
|
} |
|
if (TemplateList.Count > 0) |
|
{ |
|
if (CurrentTemplateIndex == -1) |
|
CurrentTemplateIndex = 0; |
|
} |
|
else |
|
{ |
|
CurrentTemplateIndex = -1; |
|
} |
|
ReadTemplateLayerInfo(); |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
} |
|
|
|
|
|
private void ImportBGData() |
|
{ |
|
IQueryFilter Temp = new QueryFilterClass(); |
|
IFeatureLayer dltbnmkLayer = null; |
|
IFeatureLayer dltbgxLayer = null; |
|
IFeatureLayer dltbgxgcLayer = null; |
|
IFeatureLayer dltbhrLayer = null; |
|
IFeatureLayer jcdltbLayer = null; |
|
IFeatureLayer dltbTempNMKLayer = null; |
|
IFeatureLayer cjdcqnmkLayer = null; |
|
IFeatureLayer cjdcqgxLayer = null; |
|
IFeatureLayer jccjdcqLayer = null; |
|
IFeatureLayer cjdcqTempNMKLayer = null; |
|
IFeatureLayer xzqnmkLayer = null; |
|
IFeatureLayer xzqgxLayer = null; |
|
IFeatureLayer jcxzqLayer = null; |
|
IFeatureLayer xzqTempNMKLayer = null; |
|
IFeatureLayer cjdcqjxnmkLayer = null; |
|
IFeatureLayer cjdcqjxgxLayer = null; |
|
IFeatureLayer jccjdcqjxLayer = null; |
|
IFeatureLayer cjdcqjxTempNMKLayer = null; |
|
IFeatureLayer xzqjxnmkLayer = null; |
|
IFeatureLayer xzqjxgxLayer = null; |
|
IFeatureLayer jcxzqjxLayer = null; |
|
IFeatureLayer xzqjxTempNMKLayer = null; |
|
try |
|
{ |
|
_MapService = MapsManager.Instance.MapService; |
|
//-------------第一步 将数据从基础数据里导入到年末数据里 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 基础数据 ...")); |
|
List<IFeatureLayer> featureLayers = MapsManager.Instance.MapService.GetAllLayerInMap<IFeatureLayer>(); |
|
foreach (IFeatureLayer featureLayer in featureLayers) |
|
{ |
|
IFeatureClass fcSource = (featureLayer.FeatureClass as IFeatureClass); |
|
if (fcSource.FeatureDataset != null && fcSource.FeatureDataset.Name == "基础数据" && LayerSource.Where(x => x.Name == fcSource.AliasName).ToList().Count < 1) |
|
{ |
|
if (fcSource.AliasName == "基础_地类图斑" || fcSource.AliasName == "基础_行政区" || fcSource.AliasName == "基础_村级调查区") |
|
{ |
|
continue; |
|
} |
|
var featurelayerlist = featureLayers.Where(x => x.FeatureClass.AliasName == fcSource.AliasName.Substring(fcSource.AliasName.Contains('_') ? fcSource.AliasName.IndexOf('_') + 1 : 0)).ToList<IFeatureLayer>(); |
|
if (featurelayerlist.Count != 0) |
|
{ |
|
IFeatureClassAPI fcTargetAPI = new FeatureClassAPI(featureLayers.Where(x => x.FeatureClass.AliasName == fcSource.AliasName.Substring(fcSource.AliasName.Contains('_') ? fcSource.AliasName.IndexOf('_') + 1 : 0)).ToList<IFeatureLayer>()[0].FeatureClass); |
|
|
|
(fcTargetAPI.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
IFeatureClassAPI fcSourceAPI = new FeatureClassAPI(fcSource); |
|
fcSourceAPI.FcToFc(fcTargetAPI.FeatureClass, null, false); |
|
} |
|
} |
|
} |
|
//---------------第二部整层更新 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 整层更新数据 ...")); |
|
foreach (BGVCTEntity entity in LayerSource) |
|
{ |
|
List<IFeatureLayer> featureLayerZC = featureLayers.Where(x => x.Name == entity.Name || x.Name == entity.FeatureClassName).ToList<IFeatureLayer>(); |
|
|
|
foreach (IFeatureLayer item in featureLayerZC) |
|
{ |
|
if (featureLayers.Where(x => x.FeatureClass.AliasName == item.FeatureClass.AliasName.Substring(0, item.FeatureClass.AliasName.Contains("更新") ? item.FeatureClass.AliasName.IndexOf("更新") : item.FeatureClass.AliasName.Length)).ToList<IFeatureLayer>().Count < 1) |
|
{ |
|
LogAPI.Debug("没有找到图层:" + item.Name); |
|
continue; |
|
} |
|
IFeatureClassAPI fcTargetAPI = new FeatureClassAPI(featureLayers.Where(x => x.FeatureClass.AliasName == item.FeatureClass.AliasName.Substring(0, item.FeatureClass.AliasName.Contains("更新") ? item.FeatureClass.AliasName.IndexOf("更新") : item.FeatureClass.AliasName.Length)).ToList<IFeatureLayer>()[0].FeatureClass); |
|
if (fcTargetAPI != null) |
|
{ |
|
(fcTargetAPI.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
if (item.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
continue; |
|
} |
|
else |
|
{ |
|
IFeatureClassAPI fcSourceAPI = new FeatureClassAPI(item.FeatureClass); |
|
fcSourceAPI.FcToFc(fcTargetAPI.FeatureClass, null, false); |
|
} |
|
} |
|
} |
|
} |
|
//---------------第三部增量过程数据更新与增量过程界限更新 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 更新数据 ...")); |
|
if (IncrementalUpdatingSource.Count != 0) |
|
{ |
|
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\BGCGRK"; |
|
if (!System.IO.Directory.Exists(gdbFolder)) |
|
{ |
|
System.IO.Directory.CreateDirectory(gdbFolder); |
|
} |
|
try |
|
{ |
|
DelectDir(gdbFolder);//能删除就删除 删除报错不处理 |
|
} |
|
catch |
|
{ } |
|
string gdbFileName = Guid.NewGuid().ToString() + ".gdb"; |
|
string path = System.IO.Path.Combine(gdbFolder, gdbFileName); |
|
IWorkspaceFactory pFtWsFct = new FileGDBWorkspaceFactory(); |
|
IWorkspaceName workspaceName = pFtWsFct.Create(gdbFolder, gdbFileName, null, 0); |
|
foreach (BGVCTEntity item in IncrementalUpdatingSource) |
|
{ |
|
|
|
if (item.FeatureClassName == "DLTBGX") |
|
{ |
|
dltbnmkLayer = _MapService.GetFeatureLayerByName("DLTB"); |
|
dltbgxLayer = _MapService.GetFeatureLayerByName("DLTBGX"); |
|
dltbgxgcLayer = _MapService.GetFeatureLayerByName("DLTBGXGC"); |
|
dltbhrLayer = _MapService.GetFeatureLayerByName("DLTBHR"); |
|
jcdltbLayer = _MapService.GetFeatureLayerByName("JC_DLTB"); |
|
(dltbnmkLayer.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
|
|
//获取地类图斑更新过程层变更前图标标识码 |
|
List<string> bgqtbbsmList = new List<string>(); |
|
int bgqbsmIndex = dltbgxgcLayer.FeatureClass.FindField("BGQTBBSM"); |
|
if (bgqbsmIndex != -1) |
|
{ |
|
IFeatureCursor dltbgxgcCursor = dltbgxgcLayer.FeatureClass.Search(null, true); |
|
IFeature gxgcFeature = null; |
|
while ((gxgcFeature = dltbgxgcCursor.NextFeature()) != null) |
|
{ |
|
string bgqtbbsm = gxgcFeature.Value[bgqbsmIndex].ToString(); |
|
if (!string.IsNullOrWhiteSpace(bgqtbbsm) && !bgqtbbsmList.Contains(bgqtbbsm)) |
|
{ |
|
bgqtbbsmList.Add(bgqtbbsm); |
|
} |
|
} |
|
} |
|
|
|
//将基础地类图斑导入到临时数据库,根据地类图斑更新过程层变更前图斑标识码删除基础地类图斑 |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jcdltbLayer; |
|
gPParamClass.OutFeatureClassPath = path; |
|
gPParamClass.FcName = "JC_DLTB"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.FeatureClassToFeatureClass(gPParamClass, ref dltbTempNMKLayer); |
|
|
|
int bsmIndex = dltbTempNMKLayer.FeatureClass.FindField("BSM"); |
|
if (bgqtbbsmList.Count != 0 && bsmIndex != -1) |
|
{ |
|
List<int> delOIDs = new List<int>(); |
|
IFeatureCursor nmkdltbCursor = dltbTempNMKLayer.FeatureClass.Search(null, true); |
|
IFeature nmkFeature = null; |
|
while ((nmkFeature = nmkdltbCursor.NextFeature()) != null) |
|
{ |
|
string nmkbsm = nmkFeature.Value[bsmIndex].ToString(); |
|
if (bgqtbbsmList.Contains(nmkbsm)) |
|
{ |
|
(dltbTempNMKLayer.FeatureClass as ITable).GetRow(nmkFeature.OID).Delete(); |
|
} |
|
} |
|
} |
|
|
|
|
|
//GPParamClass gPParamClass = new GPParamClass(); |
|
//gPParamClass.FirstFeatureLayer = jcdltbLayer; |
|
//gPParamClass.SecondFeatureLayer = dltbgxLayer; |
|
//gPParamClass.OutFeatureClassPath = path + "\\" + "DLTB_NMK"; |
|
//gPParamClass.IsGetOutPutFeature = true; |
|
//GeoprocessorHelper.EraseAnalysis(gPParamClass, ref dltbTempNMKLayer); |
|
|
|
//删掉因擦除产生的小于0.01的线条数据 |
|
//(dltbTempNMKLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("delete from DLTB_NMK where SHAPE_Area<0.01"); |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(dltbTempNMKLayer.FeatureClass); |
|
fcAPI.FcToFc(dltbnmkLayer.FeatureClass, null, false); |
|
fcAPI = new FeatureClassAPI(dltbgxLayer.FeatureClass); |
|
fcAPI.FcToFc(dltbnmkLayer.FeatureClass, null, false); |
|
fcAPI = new FeatureClassAPI(dltbhrLayer.FeatureClass); |
|
fcAPI.FcToFc(dltbnmkLayer.FeatureClass, null, false); |
|
fcAPI = new FeatureClassAPI(dltbnmkLayer.FeatureClass); |
|
|
|
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite"; |
|
KGIS.Framework.DBOperator.IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite); |
|
DataTable bhxxbDt = new DataTable(); |
|
Dictionary<string, DataRow> bhxxDic = new Dictionary<string, DataRow>(); |
|
List<string> hcbghbsmList = new List<string>(); |
|
if (rdbHelper.TableIsExist("BHXXB")) |
|
{ |
|
bhxxbDt = rdbHelper.ExecuteDatatable("BHXXB", "select * from BHXXB", true); |
|
if (bhxxbDt != null) |
|
{ |
|
foreach (DataRow row in bhxxbDt.Rows) |
|
{ |
|
string bghBSM = row["BGHTBBSM"].ToTrim(); |
|
if (row["BGXW"].ToTrim() == "1") |
|
{ |
|
bghBSM = row["BGQTBBSM"].ToTrim(); |
|
} |
|
if (bhxxDic.ContainsKey(bghBSM)) |
|
continue; |
|
bhxxDic.Add(bghBSM, row); |
|
string xzqtzlx = row["XZQTZLX"].ToTrim(); |
|
|
|
if (xzqtzlx == "2" && !string.IsNullOrWhiteSpace(bghBSM)) |
|
{ |
|
hcbghbsmList.Add(bghBSM); |
|
} |
|
} |
|
} |
|
} |
|
|
|
ITable nmkTable = dltbnmkLayer.FeatureClass as ITable; |
|
IQueryFilter filter = new QueryFilterClass(); |
|
foreach (string bsm in hcbghbsmList) |
|
{ |
|
filter.WhereClause = string.Format("BSM ='{0}' ", bsm); |
|
nmkTable.DeleteSearchedRows(filter); |
|
} |
|
|
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int sjnfIdx = nmkTable.FindField("SJNF");//数据年份 |
|
int num = 0; |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
num++; |
|
string bsm = nmkRow.Value[bsmIdx].ToTrim(); |
|
if (bhxxDic.ContainsKey(bsm)) |
|
{ |
|
for (int i = 0; i < nmkRow.Fields.FieldCount; i++) |
|
{ |
|
IField field = nmkRow.Fields.Field[i]; |
|
if (field.Name == "KCMJ") |
|
{ |
|
continue; |
|
} |
|
string bghField = "BGH" + field.Name; |
|
DataRow dr = bhxxDic[bsm]; |
|
if (!dr.Table.Columns.Contains(bghField)) |
|
bghField = "BGHTB" + field.Name; |
|
if (dr.Table.Columns.Contains(bghField)) |
|
{ |
|
if (field.Type == esriFieldType.esriFieldTypeString) |
|
nmkRow.Value[i] = dr[bghField]; |
|
else if (field.Type == esriFieldType.esriFieldTypeDouble) |
|
{ |
|
if (field.Name == "KCXS") |
|
{ |
|
nmkRow.Value[i] = dr[bghField].ToDouble(); |
|
nmkRow.Value[nmkRow.Fields.FindField("KCMJ")] = (nmkRow.Value[i].ToDouble() * nmkRow.Value[nmkRow.Fields.FindField("TBMJ")].ToDouble()).ToDecimal(2); |
|
} |
|
else |
|
{ |
|
nmkRow.Value[i] = dr[bghField].ToDouble(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (sjnfIdx != -1) |
|
{ |
|
nmkRow.Value[sjnfIdx] = "2020"; |
|
} |
|
nmkCur.UpdateRow(nmkRow); |
|
|
|
if (num % 1000 == 0) |
|
{ |
|
nmkCur.Flush(); |
|
} |
|
} |
|
nmkCur.Flush(); |
|
} |
|
else if (item.FeatureClassName == "CJDCQGX") |
|
{ |
|
cjdcqnmkLayer = _MapService.GetFeatureLayerByName("CJDCQ"); |
|
cjdcqgxLayer = _MapService.GetFeatureLayerByName("CJDCQGX"); |
|
jccjdcqLayer = _MapService.GetFeatureLayerByName("JC_CJDCQ"); |
|
(cjdcqnmkLayer.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jccjdcqLayer; |
|
gPParamClass.SecondFeatureLayer = cjdcqgxLayer; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "CJDCQ_NMK"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref cjdcqTempNMKLayer); |
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(cjdcqgxLayer.FeatureClass); |
|
fcAPI.FcToFc(cjdcqTempNMKLayer.FeatureClass, null, false); |
|
|
|
if (_SelectedGeo != null) |
|
{ |
|
IFeatureClass xzqFc = _MapService.GetFeatureClassByName("JC_CJDCQ"); |
|
fcAPI = new FeatureClassAPI(xzqFc); |
|
List<IFeature> xzqList = fcAPI.QueryFeatures(null); |
|
IFeature jcxjXZQ = FeatureAPI.MergeFeature(xzqList); |
|
IGeometry tempGeo = FeatureAPI.Difference(jcxjXZQ.ShapeCopy, _SelectedGeo); |
|
|
|
List<IFeature> features = FeatureAPI.Identify2(tempGeo, cjdcqTempNMKLayer); |
|
|
|
for (int i = 0; i < features.Count; i++) |
|
{ |
|
features[i].Delete(); |
|
} |
|
} |
|
|
|
fcAPI = new FeatureClassAPI(cjdcqTempNMKLayer.FeatureClass); |
|
fcAPI.FcToFc(cjdcqnmkLayer.FeatureClass, null, false); |
|
} |
|
else if (item.FeatureClassName == "XZQGX") |
|
{ |
|
xzqnmkLayer = _MapService.GetFeatureLayerByName("XZQ"); |
|
xzqgxLayer = _MapService.GetFeatureLayerByName("XZQGX"); |
|
jcxzqLayer = _MapService.GetFeatureLayerByName("JC_XZQ"); |
|
(xzqnmkLayer.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
|
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jcxzqLayer; |
|
gPParamClass.SecondFeatureLayer = xzqgxLayer; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "XZQ_NMK"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref xzqTempNMKLayer); |
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(xzqgxLayer.FeatureClass); |
|
fcAPI.FcToFc(xzqTempNMKLayer.FeatureClass, null, false); |
|
|
|
if (_SelectedGeo != null) |
|
{ |
|
IFeatureClass xzqFc = _MapService.GetFeatureClassByName("JC_XZQ"); |
|
fcAPI = new FeatureClassAPI(xzqFc); |
|
List<IFeature> xzqList = fcAPI.QueryFeatures(null); |
|
IFeature jcXZQ = FeatureAPI.MergeFeature(xzqList); |
|
IGeometry tempGeo = FeatureAPI.Difference(jcXZQ.ShapeCopy, _SelectedGeo); |
|
|
|
List<IFeature> features = FeatureAPI.Identify2(tempGeo, xzqTempNMKLayer); |
|
|
|
for (int i = 0; i < features.Count; i++) |
|
{ |
|
features[i].Delete(); |
|
} |
|
} |
|
fcAPI = new FeatureClassAPI(xzqTempNMKLayer.FeatureClass); |
|
fcAPI.FcToFc(xzqnmkLayer.FeatureClass, null, false); |
|
} |
|
else if (item.FeatureClassName == "CJDCQJXGX") |
|
{ |
|
|
|
cjdcqjxnmkLayer = _MapService.GetFeatureLayerByName("CJDCQJX"); |
|
cjdcqjxgxLayer = _MapService.GetFeatureLayerByName("CJDCQJXGX"); |
|
jccjdcqjxLayer = _MapService.GetFeatureLayerByName("JC_CJDCQJX"); |
|
|
|
(cjdcqjxnmkLayer.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
|
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jccjdcqjxLayer; |
|
gPParamClass.SecondFeatureLayer = cjdcqjxgxLayer; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "CJDCQJX_NMK"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref cjdcqjxTempNMKLayer); |
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(cjdcqjxTempNMKLayer.FeatureClass); |
|
fcAPI.AddField("BGXW", esriFieldType.esriFieldTypeInteger, "变更行为"); |
|
fcAPI = new FeatureClassAPI(cjdcqjxgxLayer.FeatureClass); |
|
fcAPI.FcToFc(cjdcqjxTempNMKLayer.FeatureClass, null, false); |
|
if (_SelectedGeo != null) |
|
{ |
|
fcAPI = new FeatureClassAPI(jccjdcqjxLayer.FeatureClass); |
|
List<IFeature> xzqjxList = fcAPI.QueryFeatures(null); |
|
IFeature jcCJDCQJX = FeatureAPI.MergeFeature(xzqjxList); |
|
IGeometry tempGeo = FeatureAPI.Difference(jcCJDCQJX.ShapeCopy, _SelectedGeo); |
|
|
|
List<IFeature> features = FeatureAPI.Identify2(tempGeo, cjdcqjxTempNMKLayer); |
|
|
|
for (int i = 0; i < features.Count; i++) |
|
{ |
|
features[i].Delete(); |
|
} |
|
} |
|
|
|
IQueryFilter filter = new QueryFilterClass(); |
|
filter.WhereClause = string.Format("BGXW=0");//删除灭失界线 |
|
(cjdcqjxTempNMKLayer.FeatureClass as ITable).DeleteSearchedRows(filter); |
|
|
|
fcAPI = new FeatureClassAPI(cjdcqjxTempNMKLayer.FeatureClass); |
|
fcAPI.FcToFc(cjdcqjxnmkLayer.FeatureClass, null, false); |
|
} |
|
else if (item.FeatureClassName == "XZQJXGX") |
|
{ |
|
xzqjxnmkLayer = _MapService.GetFeatureLayerByName("XZQJX"); |
|
xzqjxgxLayer = _MapService.GetFeatureLayerByName("XZQJXGX"); |
|
jcxzqjxLayer = _MapService.GetFeatureLayerByName("JC_XZQJX"); |
|
(xzqjxnmkLayer.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
|
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jcxzqjxLayer; |
|
gPParamClass.SecondFeatureLayer = xzqjxgxLayer; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "XZQJX_NMK"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref xzqjxTempNMKLayer); |
|
|
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(xzqjxTempNMKLayer.FeatureClass); |
|
fcAPI.AddField("BGXW", esriFieldType.esriFieldTypeInteger, "变更行为"); |
|
fcAPI = new FeatureClassAPI(xzqjxgxLayer.FeatureClass); |
|
fcAPI.FcToFc(xzqjxTempNMKLayer.FeatureClass, null, false); |
|
if (_SelectedGeo != null) |
|
{ |
|
fcAPI = new FeatureClassAPI(jcxzqjxLayer.FeatureClass); |
|
List<IFeature> xzqjxList = fcAPI.QueryFeatures(null); |
|
IFeature jcXZQJX = FeatureAPI.MergeFeature(xzqjxList); |
|
IGeometry tempGeo = FeatureAPI.Difference(jcXZQJX.ShapeCopy, _SelectedGeo); |
|
|
|
List<IFeature> features = FeatureAPI.Identify2(tempGeo, xzqjxTempNMKLayer); |
|
|
|
for (int i = 0; i < features.Count; i++) |
|
{ |
|
features[i].Delete(); |
|
} |
|
} |
|
|
|
IQueryFilter filter = new QueryFilterClass(); |
|
filter.WhereClause = string.Format("BGXW=0");//删除灭失界线 |
|
(xzqjxTempNMKLayer.FeatureClass as ITable).DeleteSearchedRows(filter); |
|
|
|
fcAPI = new FeatureClassAPI(xzqjxTempNMKLayer.FeatureClass); |
|
fcAPI.FcToFc(xzqjxnmkLayer.FeatureClass, null, false); |
|
} |
|
} |
|
} |
|
ProgressHelper.CloseProcessBar(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
ProgressHelper.CloseProcessBar(); |
|
LogAPI.Debug("成果导入失败:" + ex); |
|
MessageHelper.ShowError("成果导入失败:" + ex); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
ProgressHelper.CloseProcessBar(); |
|
if (dltbnmkLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbnmkLayer); |
|
} |
|
if (dltbgxLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbgxLayer); |
|
} |
|
if (dltbhrLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbhrLayer); |
|
} |
|
if (jcdltbLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(jcdltbLayer); |
|
} |
|
if (dltbTempNMKLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbTempNMKLayer); |
|
} |
|
if (cjdcqnmkLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(cjdcqnmkLayer); |
|
} |
|
if (cjdcqgxLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(cjdcqgxLayer); |
|
} |
|
if (jccjdcqLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(jccjdcqLayer); |
|
} |
|
if (cjdcqTempNMKLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(cjdcqTempNMKLayer); |
|
} |
|
if (xzqnmkLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(xzqnmkLayer); |
|
} |
|
if (xzqgxLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(xzqgxLayer); |
|
} |
|
if (jcxzqLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(jcxzqLayer); |
|
} |
|
if (xzqTempNMKLayer != null) |
|
{ |
|
Marshal.ReleaseComObject(xzqTempNMKLayer); |
|
} |
|
} |
|
} |
|
|
|
|
|
public static 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 e) |
|
{ |
|
throw; |
|
} |
|
} |
|
|
|
private void ImportBGData1() |
|
{ |
|
IQueryFilter Temp = new QueryFilterClass(); |
|
|
|
try |
|
{ |
|
//-------------第一步 将数据从基础数据里导入到年末数据里 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 基础数据 ...")); |
|
List<IFeatureLayer> featureLayers = MapsManager.Instance.MapService.GetAllLayerInMap<IFeatureLayer>(); |
|
foreach (IFeatureLayer featureLayer in featureLayers) |
|
{ |
|
IFeatureClass fcSource = (featureLayer.FeatureClass as IFeatureClass); |
|
if (fcSource.FeatureDataset != null && fcSource.FeatureDataset.Name == "基础数据" && LayerSource.Where(x => x.Name == fcSource.AliasName).ToList().Count < 1) |
|
{ |
|
var featurelayerlist = featureLayers.Where(x => x.FeatureClass.AliasName == fcSource.AliasName.Substring(fcSource.AliasName.Contains('_') ? fcSource.AliasName.IndexOf('_') + 1 : 0)).ToList<IFeatureLayer>(); |
|
if (featurelayerlist.Count != 0) |
|
{ |
|
IFeatureClassAPI fcTargetAPI = new FeatureClassAPI(featureLayers.Where(x => x.FeatureClass.AliasName == fcSource.AliasName.Substring(fcSource.AliasName.Contains('_') ? fcSource.AliasName.IndexOf('_') + 1 : 0)).ToList<IFeatureLayer>()[0].FeatureClass); |
|
(fcTargetAPI.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
IFeatureClassAPI fcSourceAPI = new FeatureClassAPI(fcSource); |
|
fcSourceAPI.FcToFc(fcTargetAPI.FeatureClass, null, false); |
|
} |
|
} |
|
} |
|
//---------------第二部整层更新 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 整层更新数据 ...")); |
|
foreach (BGVCTEntity entity in LayerSource) |
|
{ |
|
List<IFeatureLayer> featureLayerZC = featureLayers.Where(x => x.Name == entity.Name || x.Name == entity.FeatureClassName).ToList<IFeatureLayer>(); |
|
|
|
foreach (IFeatureLayer item in featureLayerZC) |
|
{ |
|
if (featureLayers.Where(x => x.FeatureClass.AliasName == item.FeatureClass.AliasName.Substring(0, item.FeatureClass.AliasName.Contains("更新") ? item.FeatureClass.AliasName.IndexOf("更新") : item.FeatureClass.AliasName.Length)).ToList<IFeatureLayer>().Count < 1) |
|
{ |
|
LogAPI.Debug("没有找到图层:" + item.Name); |
|
continue; |
|
} |
|
IFeatureClassAPI fcTargetAPI = new FeatureClassAPI(featureLayers.Where(x => x.FeatureClass.AliasName == item.FeatureClass.AliasName.Substring(0, item.FeatureClass.AliasName.Contains("更新") ? item.FeatureClass.AliasName.IndexOf("更新") : item.FeatureClass.AliasName.Length)).ToList<IFeatureLayer>()[0].FeatureClass); |
|
if (fcTargetAPI != null) |
|
{ |
|
(fcTargetAPI.FeatureClass as ITable).DeleteSearchedRows(Temp); |
|
if (item.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
continue; |
|
} |
|
else |
|
{ |
|
IFeatureClassAPI fcSourceAPI = new FeatureClassAPI(item.FeatureClass); |
|
fcSourceAPI.FcToFc(fcTargetAPI.FeatureClass, null, false); |
|
} |
|
} |
|
} |
|
} |
|
|
|
//---------------第三部增量过程数据更新与增量过程界限更新 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 更新数据 ...")); |
|
IFeatureClass tempFC_3 = null; |
|
string sFCNameTemp_3 = ""; |
|
foreach (BGVCTEntity item in IncrementalUpdatingSource) |
|
{ |
|
sFCNameTemp_3 = ""; |
|
List<IFeatureLayer> featureLayerZC = featureLayers.Where(x => x.FeatureClass.AliasName == item.Name || x.Name == item.FeatureClassName).ToList<IFeatureLayer>(); |
|
if (item.FeatureClassName == "XZQGX" || item.FeatureClassName == "CJDCQGX" || item.FeatureClassName == "DLTBGX") |
|
{ |
|
foreach (IFeatureLayer layer in featureLayerZC) |
|
{ |
|
if (featureLayers.Where(x => x.Name == item.FeatureClassName + "GC" || x.FeatureClass.AliasName == item.Name + "过程").ToList<IFeatureLayer>().Count < 1 || featureLayers.Where(x => x.Name + "GX" == item.FeatureClassName || x.FeatureClass.AliasName + "更新" == item.Name).ToList<IFeatureLayer>().Count < 1) |
|
{ |
|
LogAPI.Debug("没有找到图层:" + item.Name); |
|
continue; |
|
} |
|
IFeatureClassAPI fcGXAPI = new FeatureClassAPI(layer.FeatureClass); |
|
IFeatureClassAPI fcGCAPI = new FeatureClassAPI(featureLayers.Where(x => x.Name == item.FeatureClassName + "GC" || x.FeatureClass.AliasName == item.Name + "过程").ToList<IFeatureLayer>()[0].FeatureClass); |
|
IFeatureClassAPI fcJCAPI = new FeatureClassAPI(featureLayers.Where(x => x.Name + "GX" == item.FeatureClassName || x.FeatureClass.AliasName + "更新" == item.Name).ToList<IFeatureLayer>()[0].FeatureClass); |
|
tempFC_3 = fcJCAPI.FeatureClass; |
|
sFCNameTemp_3 = item.FeatureClassName; |
|
if (sFCNameTemp_3.EndsWith("GX") == true) |
|
{ |
|
sFCNameTemp_3 = sFCNameTemp_3.Substring(0, sFCNameTemp_3.Length - 2); |
|
} |
|
#region 提速版 |
|
string sFileName_Del = "delMark"; |
|
string sFileName_DelT = "delMarkT"; |
|
string sFileName_Add = "addMark"; |
|
|
|
string sTheDelBSM = ""; |
|
System.Data.DataTable dt_Del = new System.Data.DataTable(); |
|
dt_Del.Columns.Add("TheDelBSM", Type.GetType("System.String")); |
|
System.Data.DataRow dr_Del = null; |
|
|
|
string sTheAddBSM = ""; |
|
System.Data.DataTable dt_Add = new System.Data.DataTable(); |
|
dt_Add.Columns.Add("TheAddBSM", Type.GetType("System.String")); |
|
System.Data.DataRow dr_Add = null; |
|
|
|
string sTheHasBSM = ""; |
|
System.Data.DataTable dt_Has = new System.Data.DataTable(); |
|
dt_Has.Columns.Add("TheHasBSM", Type.GetType("System.String")); |
|
System.Data.DataRow dr_Has = null; |
|
|
|
string sTheDelBSM_PartTwo = ""; |
|
System.Data.DataTable dt_DelPartTwo = new System.Data.DataTable(); |
|
dt_DelPartTwo.Columns.Add("TheDelPartTwoBSM", Type.GetType("System.String")); |
|
System.Data.DataRow dr_DelPartTwo = null; |
|
|
|
int iIndex_BGQBSM_GC = fcGCAPI.FeatureClass.Fields.FindField("BGQTBBSM"); |
|
int iIndex_BGHBSM_GC = fcGCAPI.FeatureClass.Fields.FindField("BGHTBBSM"); |
|
|
|
if (iIndex_BGQBSM_GC < 0) |
|
{ |
|
iIndex_BGQBSM_GC = fcGCAPI.FeatureClass.Fields.FindField("BGQBSM"); |
|
iIndex_BGHBSM_GC = fcGCAPI.FeatureClass.Fields.FindField("BGHBSM"); |
|
} |
|
|
|
int iIndex_BSM_GX = fcGXAPI.FeatureClass.Fields.FindField("BSM"); |
|
|
|
int iIndex_BSM_NMK = fcJCAPI.FeatureClass.Fields.FindField("BSM"); |
|
|
|
//NMK 中 新增字段(delMark) 用于标记是否删除(0不删除 1删除) |
|
FeatureClassAPI nmk_FCAPI = null; |
|
nmk_FCAPI = new FeatureClassAPI(tempFC_3); |
|
bool addField_1 = nmk_FCAPI.AddField(sFileName_Del, esriFieldType.esriFieldTypeInteger, sFileName_Del); |
|
if (addField_1 == false) |
|
{ |
|
throw new Exception("年末库 中创建字段【" + sFileName_Del + "】失败!"); |
|
} |
|
int iIndex_DelMark_NMK = fcJCAPI.FeatureClass.Fields.FindField(sFileName_Del); |
|
|
|
string updateSQL_1 = string.Format("UPDATE {0} SET {1}={2} ", (tempFC_3 as FeatureClass).BrowseName, sFileName_Del, 0); |
|
(tempFC_3 as FeatureClass).Workspace.ExecuteSQL(updateSQL_1); |
|
|
|
//NMK 中 新增字段(delMarkT) 用于标记是否二次删除(0不删除 1删除) |
|
bool addField_3 = nmk_FCAPI.AddField(sFileName_DelT, esriFieldType.esriFieldTypeInteger, sFileName_DelT); |
|
if (addField_3 == false) |
|
{ |
|
throw new Exception("年末库 中创建字段【" + sFileName_DelT + "】失败!"); |
|
} |
|
int iIndex_DelMarkT_NMK = fcJCAPI.FeatureClass.Fields.FindField(sFileName_DelT); |
|
|
|
string updateSQL_3 = string.Format("UPDATE {0} SET {1}={2} ", (tempFC_3 as FeatureClass).BrowseName, sFileName_DelT, 0); |
|
(tempFC_3 as FeatureClass).Workspace.ExecuteSQL(updateSQL_3); |
|
|
|
//GX 中 新增字段(addMark) 用于标记是否拷贝(0不拷贝 1拷贝) |
|
FeatureClassAPI gx_FCAPI = null; |
|
gx_FCAPI = new FeatureClassAPI(layer.FeatureClass); |
|
bool addField_2 = gx_FCAPI.AddField(sFileName_Add, esriFieldType.esriFieldTypeInteger, sFileName_Add); |
|
if (addField_2 == false) |
|
{ |
|
throw new Exception("更新层 中创建字段【" + sFileName_Add + "】失败!"); |
|
} |
|
int iIndex_AddMark_GX = layer.FeatureClass.Fields.FindField(sFileName_Add); |
|
|
|
string updateSQL_2 = string.Format("UPDATE {0} SET {1}={2} ", (layer.FeatureClass as FeatureClass).BrowseName, sFileName_Add, 0); |
|
(layer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(updateSQL_2); |
|
|
|
//获取 GXGC 中所有需要 删除的 BGQTBBSM 的 DataTable(dt_Del),和 需要添加的 BGHTBBSM 的 DataTable(dt_Add); |
|
List<IFeature> gc_FCList = new List<IFeature>(); |
|
gc_FCList = fcGCAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter($" OBJECTID>0 ")); |
|
foreach (var fcTemp_gc in gc_FCList) |
|
{ |
|
sTheDelBSM = fcTemp_gc.Value[iIndex_BGQBSM_GC].ToString(); |
|
dr_Del = dt_Del.NewRow(); |
|
dr_Del["TheDelBSM"] = sTheDelBSM; |
|
dt_Del.Rows.Add(dr_Del); |
|
|
|
sTheAddBSM = fcTemp_gc.Value[iIndex_BGHBSM_GC].ToString(); |
|
dr_Add = dt_Add.NewRow(); |
|
dr_Add["TheAddBSM"] = sTheAddBSM; |
|
dt_Add.Rows.Add(dr_Add); |
|
} |
|
dt_Del = GetDistinctTable(dt_Del); |
|
|
|
dt_Add = GetDistinctTable(dt_Add); |
|
if (dt_Add == null || dt_Add.Rows.Count <= 0) |
|
{ |
|
LogAPI.Debug("没有可以操作的 年末库(" + sFCNameTemp_3 + ")数据 ; "); |
|
continue; |
|
} |
|
//遍历 NMK 版的 List<IFeature> 判断是否存在于 dt_Del 中,以便修改字段 delMark |
|
List<IFeature> nmk_FCList = new List<IFeature>(); |
|
nmk_FCList = fcJCAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter($" OBJECTID>0 ")); |
|
System.Data.DataRow[] drArray_nmk = null; |
|
string sBSM_nmk = ""; |
|
int iCount_D1 = 0;// |
|
int iCount_D2 = 0;// |
|
int iCount_D3 = 0;// |
|
foreach (var fcTemp_nmk in nmk_FCList) |
|
{ |
|
iCount_D1 += 1;// |
|
sBSM_nmk = fcTemp_nmk.Value[iIndex_BSM_NMK].ToString(); |
|
drArray_nmk = dt_Del.Select(" TheDelBSM='" + sBSM_nmk + "' "); |
|
if (drArray_nmk != null && drArray_nmk.Count() > 0)//能找到 |
|
{//删除 |
|
if (drArray_nmk.Count() > 1) |
|
{ |
|
LogAPI.Debug("错误:年末库过渡数据 dt_Del 中存在多个 " + sBSM_nmk + " TheDelBSM 记录; "); |
|
} |
|
fcTemp_nmk.Value[iIndex_DelMark_NMK] = 1; |
|
fcTemp_nmk.Store(); |
|
iCount_D2 += 1;// |
|
} |
|
else |
|
{//不用删除 |
|
//fcTemp_nmk.Value[iIndex_DelMark_NMK] = 0; |
|
iCount_D3 += 1;// |
|
} |
|
sBSM_nmk = ""; |
|
} |
|
IQueryFilter iQF_Count = new QueryFilterClass(); |
|
iQF_Count.WhereClause = " OBJECTID>0 "; |
|
int iNMKCount_1 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count);// |
|
//依据字段 delMark 删除 NMK 中对应的数据 |
|
IQueryFilter queryDel_nmk = new QueryFilterClass(); |
|
queryDel_nmk.WhereClause = sFileName_Del + "=1 "; |
|
|
|
(fcJCAPI.FeatureClass as ITable).DeleteSearchedRows(queryDel_nmk); |
|
int iNMKCount_2 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count);// |
|
//获取 NMK 中 中已有数据的 BSM 的 DataTable(dt_Has) |
|
List<IFeature> nmk2_FCList = new List<IFeature>(); |
|
nmk2_FCList = fcJCAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter($" OBJECTID>0 ")); |
|
foreach (var fcTemp_nmk_2 in nmk2_FCList) |
|
{ |
|
sTheHasBSM = fcTemp_nmk_2.Value[iIndex_BSM_NMK].ToString(); |
|
dr_Has = dt_Has.NewRow(); |
|
dr_Has["TheHasBSM"] = sTheHasBSM; |
|
dt_Has.Rows.Add(dr_Has); |
|
sTheHasBSM = ""; |
|
} |
|
|
|
System.Data.DataRow[] drArray_Temp = null; |
|
if (dt_Has != null && dt_Has.Rows.Count > 0) |
|
{ |
|
dt_Has = GetDistinctTable(dt_Has); |
|
//去掉 NMK 中在 dt_Add 和 dt_Has 中都存在的数据 得到 DataTable(dt_DelPartTwo) |
|
for (int f = 0; f < dt_Add.Rows.Count; f++) |
|
{ |
|
sTheDelBSM_PartTwo = dt_Add.Rows[f]["TheAddBSM"].ToString(); |
|
drArray_Temp = dt_Has.Select(" TheHasBSM='" + sTheDelBSM_PartTwo + "' "); |
|
if (drArray_Temp != null && drArray_Temp.Count() > 0) |
|
{//需要二次删除 |
|
dr_DelPartTwo = dt_DelPartTwo.NewRow(); |
|
dr_DelPartTwo["TheDelPartTwoBSM"] = sTheDelBSM_PartTwo; |
|
dt_DelPartTwo.Rows.Add(dr_DelPartTwo); |
|
LogAPI.Debug("NMK 中需要二次删除 " + sTheDelBSM_PartTwo + " ;\r\n "); |
|
} |
|
else |
|
{//不用二次删除 |
|
continue; |
|
} |
|
} |
|
dt_DelPartTwo = GetDistinctTable(dt_DelPartTwo); |
|
} |
|
else |
|
{ |
|
dt_DelPartTwo = null; |
|
} |
|
|
|
List<IFeature> nmk3_FCList = new List<IFeature>(); |
|
nmk3_FCList = fcJCAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter($" OBJECTID>0 ")); |
|
string sBSM_nmk_2 = ""; |
|
System.Data.DataRow[] drArray_nmk_2 = null; |
|
int iCount_D7 = 0;// |
|
int iCount_D8 = 0;// |
|
int iCount_D9 = 0;// |
|
|
|
if (dt_DelPartTwo != null && dt_DelPartTwo.Rows.Count > 0) |
|
{ |
|
foreach (var fcTemp_nmk_3 in nmk3_FCList) |
|
{ |
|
iCount_D7 += 1;// |
|
sBSM_nmk_2 = fcTemp_nmk_3.Value[iIndex_BSM_NMK].ToString(); |
|
drArray_nmk_2 = dt_DelPartTwo.Select(" TheDelPartTwoBSM='" + sBSM_nmk_2 + "' "); |
|
if (drArray_nmk_2 != null && drArray_nmk_2.Count() > 0)//能找到 |
|
{//删除 |
|
if (drArray_nmk_2.Count() > 1) |
|
{ |
|
LogAPI.Debug("年末库过渡数据 dt_DelPartTwo 中存在多个 " + sBSM_nmk_2 + " TheDelPartTwoBSM 记录; "); |
|
} |
|
fcTemp_nmk_3.Value[iIndex_DelMarkT_NMK] = 1; |
|
fcTemp_nmk_3.Store(); |
|
iCount_D8 += 1; |
|
} |
|
else |
|
{ |
|
iCount_D9 += 1; |
|
} |
|
sBSM_nmk_2 = ""; |
|
} |
|
} |
|
IQueryFilter iQF_Count6 = new QueryFilterClass(); |
|
iQF_Count6.WhereClause = " OBJECTID>0 "; |
|
int iNMKCount_11 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count6); |
|
//依据字段 delMarkT 删除 NMK 中对应的数据 |
|
IQueryFilter queryDelT_nmk = new QueryFilterClass(); |
|
queryDelT_nmk.WhereClause = sFileName_DelT + "=1 "; |
|
|
|
(fcJCAPI.FeatureClass as ITable).DeleteSearchedRows(queryDelT_nmk); |
|
int iNMKCount_12 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count6);// |
|
|
|
//遍历 GX 版的 List<IFeature> 判断是否存在于 dt_Add 中,以便修改字段 addMark |
|
List<IFeature> gx_FCList = new List<IFeature>(); |
|
gx_FCList = fcGXAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter($" OBJECTID>0 ")); |
|
System.Data.DataRow[] drArray_gx = null; |
|
string sBSM_gx = ""; |
|
int iCount_D4 = 0;// |
|
int iCount_D5 = 0;// |
|
int iCount_D6 = 0;// |
|
foreach (var fcTemp_gx in gx_FCList) |
|
{ |
|
iCount_D4 += 1;// |
|
sBSM_gx = fcTemp_gx.Value[iIndex_BSM_GX].ToString(); |
|
drArray_gx = dt_Add.Select(" TheAddBSM='" + sBSM_gx + "' "); |
|
if (drArray_gx != null && drArray_gx.Count() > 0)//需要拷贝 |
|
{ |
|
if (drArray_gx.Count() > 1) |
|
{ |
|
LogAPI.Debug("年末库过渡数据 dt_Add 中存在多个 " + sBSM_gx + " TheAddBSM 记录; "); |
|
} |
|
fcTemp_gx.Value[iIndex_AddMark_GX] = 1; |
|
fcTemp_gx.Store(); |
|
iCount_D5 += 1;// |
|
} |
|
else//不需要拷贝 |
|
{ |
|
//fcTemp_gx.Value[iIndex_AddMark_GX] = 0; |
|
iCount_D6 += 1;// |
|
LogAPI.Debug("GX 中没有拷入 NMK 记录,GX 的 BSM= " + sBSM_gx + " ;( GXGC 中的 BGHTBBSM 没能在 GX 中的 BSM 中对应的情况) \r\n "); |
|
} |
|
sBSM_gx = ""; |
|
} |
|
IQueryFilter iQF_Count3 = new QueryFilterClass();// |
|
iQF_Count3.WhereClause = " OBJECTID>0 ";// |
|
int iNMKCount_3 = (fcGXAPI.FeatureClass as ITable).RowCount(iQF_Count3);// |
|
//依据字段 addMark 将 GX 中对应的数据拷贝到 NMK 中 |
|
|
|
IQueryFilter iQF_Count4 = new QueryFilterClass();// |
|
iQF_Count4.WhereClause = " OBJECTID>0 ";// |
|
int iNMKCount_4 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count4);// |
|
|
|
IQueryFilter queryCopyToNMK_gx = new QueryFilterClass(); |
|
queryCopyToNMK_gx.WhereClause = sFileName_Add + "=1 "; |
|
fcGXAPI.FcToFc(fcJCAPI.FeatureClass, queryCopyToNMK_gx, false); |
|
|
|
IQueryFilter iQF_Count5 = new QueryFilterClass();// |
|
iQF_Count5.WhereClause = " OBJECTID>0 ";// |
|
int iNMKCount_5 = (fcJCAPI.FeatureClass as ITable).RowCount(iQF_Count5);// |
|
|
|
//删除 NMK 中的字段 delMark、delMarkT 和 GX 中的字段 addMark |
|
if (nmk_FCAPI != null) |
|
{ |
|
nmk_FCAPI.DeleteField(sFileName_Del); |
|
} |
|
if (nmk_FCAPI != null) |
|
{ |
|
nmk_FCAPI.DeleteField(sFileName_DelT); |
|
} |
|
if (gx_FCAPI != null) |
|
{ |
|
gx_FCAPI.DeleteField(sFileName_Add); |
|
} |
|
//释放 |
|
if (gc_FCList != null && gc_FCList.Count() > 0) |
|
{ |
|
gc_FCList = null; |
|
} |
|
if (nmk_FCList != null && nmk_FCList.Count() > 0) |
|
{ |
|
nmk_FCList = null; |
|
} |
|
if (gx_FCList != null && gx_FCList.Count() > 0) |
|
{ |
|
gx_FCList = null; |
|
} |
|
if (nmk2_FCList != null && nmk2_FCList.Count() > 0) |
|
{ |
|
nmk2_FCList = null; |
|
} |
|
if (nmk3_FCList != null && nmk3_FCList.Count() > 0) |
|
{ |
|
nmk3_FCList = null; |
|
} |
|
|
|
if (iQF_Count != null) |
|
{ |
|
while (Marshal.ReleaseComObject(iQF_Count) > 0) { }; |
|
} |
|
if (queryDel_nmk != null) |
|
{ |
|
while (Marshal.ReleaseComObject(queryDel_nmk) > 0) { }; |
|
} |
|
if (queryDelT_nmk != null) |
|
{ |
|
while (Marshal.ReleaseComObject(queryDelT_nmk) > 0) { }; |
|
} |
|
if (iQF_Count3 != null) |
|
{ |
|
while (Marshal.ReleaseComObject(iQF_Count3) > 0) { }; |
|
} |
|
if (iQF_Count4 != null) |
|
{ |
|
while (Marshal.ReleaseComObject(iQF_Count4) > 0) { }; |
|
} |
|
if (iQF_Count5 != null) |
|
{ |
|
while (Marshal.ReleaseComObject(iQF_Count5) > 0) { }; |
|
} |
|
if (iQF_Count6 != null) |
|
{ |
|
while (Marshal.ReleaseComObject(iQF_Count6) > 0) { }; |
|
} |
|
if (queryCopyToNMK_gx != null) |
|
{ |
|
while (Marshal.ReleaseComObject(queryCopyToNMK_gx) > 0) { }; |
|
} |
|
|
|
if (dt_Del != null && dt_Del.Rows.Count > 0) |
|
{ |
|
dt_Del = null; |
|
} |
|
if (dt_Add != null && dt_Add.Rows.Count > 0) |
|
{ |
|
dt_Add = null; |
|
} |
|
if (dt_Has != null && dt_Has.Rows.Count > 0) |
|
{ |
|
dt_Has = null; |
|
} |
|
if (dt_DelPartTwo != null && dt_DelPartTwo.Rows.Count > 0) |
|
{ |
|
dt_DelPartTwo = null; |
|
} |
|
|
|
if (dr_Del != null) |
|
{ |
|
dr_Del = null; |
|
} |
|
if (dr_Add != null) |
|
{ |
|
dr_Add = null; |
|
} |
|
if (dr_Has != null) |
|
{ |
|
dr_Has = null; |
|
} |
|
if (dr_DelPartTwo != null) |
|
{ |
|
dr_DelPartTwo = null; |
|
} |
|
|
|
if (drArray_nmk != null) |
|
{ |
|
drArray_nmk = null; |
|
} |
|
if (drArray_nmk_2 != null) |
|
{ |
|
drArray_nmk_2 = null; |
|
} |
|
if (drArray_Temp != null) |
|
{ |
|
drArray_Temp = null; |
|
} |
|
if (drArray_gx != null) |
|
{ |
|
drArray_gx = null; |
|
} |
|
#endregion |
|
} |
|
} |
|
else if (item.FeatureClassName == "XZQJXGX" || item.FeatureClassName == "CJDCQGX") |
|
{ |
|
foreach (IFeatureLayer layer in featureLayerZC) |
|
{ |
|
if (featureLayers.Where(x => x.Name + "GX" == item.FeatureClassName || x.Name + "更新" == item.Name).ToList<IFeatureLayer>().Count < 1) |
|
{ |
|
LogAPI.Debug("没有找到图层:" + item.Name); |
|
continue; |
|
} |
|
|
|
IFeatureClassAPI fcBGAPI = new FeatureClassAPI(layer.FeatureClass); |
|
IFeatureClass JC_featureClass = featureLayers.Where(x => x.Name + "GX" == item.FeatureClassName || x.Name + "更新" == item.Name).ToList<IFeatureLayer>()[0].FeatureClass; |
|
IFeatureCursor cursor = layer.FeatureClass.Search(null, true); |
|
ISpatialFilter filter = new SpatialFilterClass(); |
|
IFeature feature = null; |
|
while ((feature = cursor.NextFeature()) != null) |
|
{ |
|
|
|
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; |
|
filter.Geometry = feature.ShapeCopy; |
|
(JC_featureClass as ITable).DeleteSearchedRows(filter); |
|
} |
|
if (cursor != null) |
|
{ |
|
while (Marshal.ReleaseComObject(cursor) > 0) { }; |
|
} |
|
if (filter != null) |
|
{ |
|
while (Marshal.ReleaseComObject(filter) > 0) { }; |
|
} |
|
if (feature != null) |
|
{ |
|
while (Marshal.ReleaseComObject(feature) > 0) { }; |
|
} |
|
fcBGAPI.FcToFc(JC_featureClass, null, false); |
|
|
|
} |
|
|
|
} |
|
} |
|
|
|
//---------------第四步地类图斑划入层更新 |
|
ProgressHelper.ShowProcessBar(string.Format("正在处理 地类图斑划入层 ...")); |
|
IWorkspaceFactory pFtWsFct = null; |
|
IFeatureClass newdltbhrFC = null; |
|
IFeatureClass dltbnmkFC = null; |
|
IFeatureCursor dltbhrCursor = null; |
|
IFeature dltbhrFeature = null; |
|
IFeatureCursor dltbnmkCursor = null; |
|
try |
|
{ |
|
List<IFeatureLayer> featureLayerDLTBHR = featureLayers.Where(x => x.FeatureClass.AliasName == "地类图斑划入层" || x.Name == "DLTBHR").ToList<IFeatureLayer>(); |
|
if (featureLayers.Where(x => x.Name == "DLTB" || x.FeatureClass.AliasName == "地类图斑").ToList<IFeatureLayer>().Count < 1) |
|
{ |
|
LogAPI.Debug("没有找到图层:DLTB"); |
|
} |
|
else |
|
{ |
|
dltbnmkFC = featureLayers.Where(x => x.Name == "DLTB" || x.FeatureClass.AliasName == "地类图斑").ToList<IFeatureLayer>()[0].FeatureClass;//年末库地类图斑 |
|
foreach (IFeatureLayer dltbhrlayer in featureLayerDLTBHR) |
|
{ |
|
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\TempBGFile"; |
|
if (!System.IO.Directory.Exists(gdbFolder)) |
|
{ |
|
System.IO.Directory.CreateDirectory(gdbFolder); |
|
} |
|
string mdbFileName = Guid.NewGuid().ToString(); |
|
string path = System.IO.Path.Combine(gdbFolder, mdbFileName); |
|
pFtWsFct = new FileGDBWorkspaceFactory(); |
|
pFtWsFct.Create(path, "TempGDB", null, 0); |
|
string TempmdbPath = System.IO.Path.Combine(path, "TempGDB.gdb"); |
|
IFeatureLayer DLTNHR_featureLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = dltbhrlayer; |
|
gPParamClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = dltbnmkFC }; |
|
gPParamClass.OutFeatureClassPath = TempmdbPath + "\\DLTBHR"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref DLTNHR_featureLayer); |
|
if (DLTNHR_featureLayer != null) |
|
{ |
|
newdltbhrFC = DLTNHR_featureLayer.FeatureClass; |
|
if (newdltbhrFC.FeatureCount(null) != 0) |
|
{ |
|
Dictionary<int, int> fieldDic = new Dictionary<int, int>(); |
|
for (int i = 0; i < dltbnmkFC.Fields.FieldCount; i++) |
|
{ |
|
IField field = dltbnmkFC.Fields.Field[i]; |
|
string fileName = field.Name; |
|
string fileAliasName = field.AliasName; |
|
if (fileName == dltbnmkFC.ShapeFieldName || fileName.Contains(dltbnmkFC.ShapeFieldName) || fileName == dltbnmkFC.OIDFieldName || !field.Editable) continue; |
|
|
|
|
|
if (fileName.ToUpper() == "BSM") |
|
{ |
|
fileName = "BGHTBBSM"; |
|
fileAliasName = "变更后图斑标识码"; |
|
} |
|
else |
|
{ |
|
fileName = "BGH" + fileName; |
|
fileAliasName = "变更后" + fileAliasName; |
|
|
|
} |
|
int index = newdltbhrFC.Fields.FindField(fileName); |
|
if (index == -1) |
|
index = newdltbhrFC.Fields.FindFieldByAliasName(fileAliasName); |
|
if (index == -1) |
|
continue; |
|
fieldDic.Add(i, index); |
|
} |
|
int tbmjIndex = dltbnmkFC.Fields.FindField("TBMJ"); |
|
int bghkcmjIndex = newdltbhrFC.Fields.FindField("BGHKCMJ"); |
|
int bghdltbmjIndex = newdltbhrFC.Fields.FindField("BGHTBDLMJ"); |
|
IFeatureBuffer buffer = dltbnmkFC.CreateFeatureBuffer(); |
|
dltbnmkCursor = dltbnmkFC.Insert(true); |
|
dltbhrCursor = newdltbhrFC.Search(null, true); |
|
while ((dltbhrFeature = dltbhrCursor.NextFeature()) != null) |
|
{ |
|
buffer.Shape = dltbhrFeature.ShapeCopy; |
|
foreach (int item in fieldDic.Keys) |
|
{ |
|
buffer.Value[item] = dltbhrFeature.Value[fieldDic[item]]; |
|
} |
|
string bghkcmj = dltbhrFeature.Value[bghkcmjIndex].ToString() == "" ? "0" : dltbhrFeature.Value[bghkcmjIndex].ToString(); |
|
string bghtbdlmj = dltbhrFeature.Value[bghdltbmjIndex].ToString() == "" ? "0" : dltbhrFeature.Value[bghdltbmjIndex].ToString(); |
|
double tbmj = double.Parse(bghkcmj) + double.Parse(bghtbdlmj); |
|
buffer.Value[tbmjIndex] = tbmj; |
|
dltbnmkCursor.InsertFeature(buffer); |
|
Marshal.ReleaseComObject(dltbhrFeature); |
|
} |
|
dltbhrCursor.Flush(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
ProgressHelper.CloseProcessBar(); |
|
LogAPI.Debug(ex); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (pFtWsFct != null) |
|
{ |
|
Marshal.ReleaseComObject(pFtWsFct); |
|
} |
|
if (newdltbhrFC != null) |
|
{ |
|
Marshal.ReleaseComObject(newdltbhrFC); |
|
} |
|
if (dltbnmkFC != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbnmkFC); |
|
} |
|
if (dltbhrCursor != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbhrCursor); |
|
} |
|
if (dltbnmkCursor != null) |
|
{ |
|
Marshal.ReleaseComObject(dltbnmkCursor); |
|
} |
|
} |
|
ProgressHelper.CloseProcessBar(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
ProgressHelper.CloseProcessBar(); |
|
LogAPI.Debug(ex); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
|
|
} |
|
} |
|
#region datatable去重 |
|
public string[] dtColumnsNameArray; |
|
public string[] dtColumnsCaptionArray; |
|
/// <summary> |
|
/// datatable去重 |
|
/// </summary> |
|
/// <param name="dtSource">需要去重的datatable</param> |
|
/// <returns></returns> |
|
public System.Data.DataTable GetDistinctTable(System.Data.DataTable dtSource) |
|
{ |
|
System.Data.DataTable distinctTable = null; |
|
try |
|
{ |
|
GetTableColumnNameAndCaption(dtSource); |
|
|
|
if (dtColumnsNameArray == null || dtColumnsNameArray.Count() <= 0) |
|
{ |
|
return null; |
|
} |
|
|
|
if (dtSource != null && dtSource.Rows.Count > 0) |
|
{ |
|
string[] columnNames = dtColumnsNameArray; |
|
System.Data.DataView dv = new System.Data.DataView(dtSource); |
|
distinctTable = dv.ToTable(true, columnNames);//OBJECTID |
|
} |
|
|
|
return distinctTable; |
|
} |
|
catch (Exception ex) |
|
{ |
|
//MessageBox.Show("datatable去重 异常:"+ee.ToString()+" ; "); |
|
LogAPI.Debug("datatable去重 异常:" + ex + " ; "); |
|
return null; |
|
} |
|
} |
|
/// <summary> |
|
/// 获取表中所有列名和标题 |
|
/// </summary> |
|
/// <param name="dt"></param> |
|
/// <returns></returns> |
|
public void GetTableColumnNameAndCaption(System.Data.DataTable dt) |
|
{ |
|
try |
|
{ |
|
dtColumnsNameArray = null; |
|
dtColumnsCaptionArray = null; |
|
|
|
string colsName = string.Empty; |
|
string colsCaption = string.Empty; |
|
for (int i = 0; i < dt.Columns.Count; i++) |
|
{ |
|
colsName += (dt.Columns[i].ColumnName + ","); |
|
colsCaption += (dt.Columns[i].Caption + ","); |
|
} |
|
colsName = colsName.TrimEnd(','); |
|
dtColumnsNameArray = colsName.Split(','); |
|
|
|
colsCaption = colsCaption.TrimEnd(','); |
|
dtColumnsCaptionArray = colsCaption.Split(','); |
|
|
|
return; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取表中所有列名和标题 时失败,异常原因: " + ex + " ; "); |
|
dtColumnsNameArray = null; |
|
dtColumnsCaptionArray = null; |
|
return; |
|
} |
|
} |
|
|
|
#endregion |
|
} |
|
}
|
|
|