using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows; using System.Windows.Input; using DevExpress.Xpf.Editors.Settings; using DevExpress.Xpf.Grid; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.esriSystem; using KGIS.Framework.DBOperator; using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Views; using KGIS.Framework.Utils.Helper; using KGIS.Framework.Utils.Interface; using KGIS.Framework.AE; using KGIS.Framework.AE.ExtensionMethod; using ReactiveUI; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.DataSourcesGDB; using System.IO; using System.Runtime.InteropServices; using KGIS.Framework.AE.GPHelper; using KGIS.Framework.Platform.Helper; using System.Windows.Forms; using Kingo.Plugin.ResultsOfProof.Model; using Kingo.Plugin.ResultsOfProof.View.JZTBXX; using KGIS.Framework.Utils.ExtensionMethod; using Kingo.PluginServiceInterface; using Kingo.Plugin.ResultsOfProof.View.JZTBXX; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using KUI.Windows; namespace Kingo.Plugin.ResultsOfProof.ViewModel { public class BGJZTBListViewModel : ReactiveObject { #region 变量 //切换工程后关闭Panel public Action ClosePanel; //用于定位 public IHookHelper m_hookHelper { get; set; } /// /// 刷新数据Timer /// private System.Timers.Timer RefreshTimer; // public IPlatform Platform { get; set; } /// /// 记录属性表是否正在刷新状态 /// private bool IsLoading = false; //Dictionary dicFiled = new Dictionary(); //选中数据总数 int SelectCount = 0; //用于导出Excel private List lstDataColumnEx { get; set; } /// /// 是否显示选中数据 /// private bool IsShowSelectData = false; /// /// 当前图层 /// private IFeatureClass SourceFeature { get; set; } private DataTable _Data; /// /// 数据源集合 /// public DataTable Data { get { return _Data; } set { this.RaiseAndSetIfChanged(ref _Data, value); } } /// /// 主键字段名称 /// private string KeyIDName = "OBJECTID"; /// /// 控件加载全部按钮是否可操作 /// private bool IsLoadComplate { get { return IsLoadComplate; } set { //btnAll.IsEnabled = !value; } } private int count; /// /// 总数 /// public int Count { get { return count; } set { this.RaiseAndSetIfChanged(ref count, value); } } private int showNum; /// /// 当前显示数 /// public int ShowNum { get { return showNum; } set { this.RaiseAndSetIfChanged(ref showNum, value); } } private bool _f_gjdlbyz; /// /// 挂接地类不一致 /// public bool f_gjdlbyz { get { return _f_gjdlbyz; } set { this.RaiseAndSetIfChanged(ref _f_gjdlbyz, value); } } private bool _f_wgj; /// /// 未挂接 /// public bool f_wgj { get { return _f_wgj; } set { this.RaiseAndSetIfChanged(ref _f_wgj, value); } } private bool _f_gjdtb; /// /// 挂接多图斑 /// public bool f_gjdtb { get { return _f_gjdtb; } set { this.RaiseAndSetIfChanged(ref _f_gjdtb, value); } } private string queryWhere = string.Empty; /// /// 右键选中列名字 /// private string selectedFieldName = string.Empty; private IFeatureLayer JZTBFeatureLayer = null; private IFeatureLayer DLTBFeatureLayer = null; private IFeatureClassAPI DLTBAPI = null; private DataTable Data_WYHCFJ = null; private DataTable Data_NYHS = null; private IList currentSelectedItems = null; public IList CurrentSelectedItems { get { return currentSelectedItems; } set { this.RaiseAndSetIfChanged(ref currentSelectedItems, value); } } public DataRowView currentItem = null; public DataRowView CurrentItem { get { return currentItem; } set { this.RaiseAndSetIfChanged(ref currentItem, value); } } public bool IsMouseOver { get; set; } private int cmbTypeSelectedIndex = 0; public int CmbTypeSelectedIndex { get { return cmbTypeSelectedIndex; } set { this.RaiseAndSetIfChanged(ref cmbTypeSelectedIndex, value); } } private bool tableViewPrintSelectedRowsOnly = false; public bool TableViewPrintSelectedRowsOnly { get { return tableViewPrintSelectedRowsOnly; } set { this.RaiseAndSetIfChanged(ref tableViewPrintSelectedRowsOnly, value); } } #endregion #region GridControl命令 #region 输出Excel文档 public ReactiveCommand ExportRelationCG { get; private set; } public ReactiveCommand TBFJGetRelation { get; private set; } /// /// 关联图斑标识码 /// public ReactiveCommand RelationTBBSMCmd { get; private set; } /// /// 人工校验 /// public ReactiveCommand RGJYCmd { get; private set; } /// /// 导出举证图斑信息表 /// public ReactiveCommand ExportJZTBXXBCmd { get; private set; } /// /// 条件过滤 /// public ReactiveCommand FilterDataCmd { get; private set; } //public ReactiveCommand ExportToXlsx { get; private set; } private string outputXlsxFilePath = null; public string OutputXlsxFilePath { get { return outputXlsxFilePath; } set { this.RaiseAndSetIfChanged(ref outputXlsxFilePath, value); } } #endregion 输出Excel文档 //public ReactiveCommand GridControlSelectAll { get; private set; } public ReactiveCommand GridControlUnSelectAll { get; private set; } public ReactiveCommand GridControlRefreshData { get; private set; } public ReactiveCommand FilterChangedCommand { get; private set; } public ReactiveCommand GridControlAutoGeneratedColumns { get; set; } public ReactiveCommand CurrentItemChangedCommand { get; private set; } public ReactiveCommand SelectionChangedCommand { get; private set; } public ReactiveCommand EndSortingCommand { get; private set; } public ReactiveCommand TableViewMouseLeftButtonUpCommand { get; private set; } #region 定位GridControl里面选中的图斑数据行 private int[] objectIDArray = null; public int[] ObjectIDArray { get { return objectIDArray; } set { this.RaiseAndSetIfChanged(ref objectIDArray, value); } } public ReactiveCommand GridControlFocusRow { get; private set; } #endregion 定位GridControl里面选中的图斑数据行 #endregion GridControl命令 private IRDBHelper dbHelper = null; public bool IsNotByPerson = false; /// /// 数据行总个数 /// public int RowCount = 0; /// /// 当前选中行索引 /// public int RowHandle = 1; private DataTable dtJZFJSource = null; private DataTable dtJZFJSource2 = null; private IRDBHelper sqlitehelper = null; private object Hook = null; public BGFrmJZTBXXBRelation frmJZTBXXB_RGJX = null; /// /// 上一条数据 /// public ReactiveCommand PrevDataCmd { get; set; } /// /// 下一条数据 /// public ReactiveCommand NextDataCmd { get; set; } /// /// 刷新数据 /// public ReactiveCommand RefreshDataCmd { get; set; } public BGFrmGLBSMParameter frmGLBSMParameter = null; public decimal AreaRatio { get; set; } private int _PageSize; public int PageSize { get { return _PageSize; } set { this.RaiseAndSetIfChanged(ref _PageSize, value); } } private int _CurrentIndex = -1; public int CurrentIndex { get { return _CurrentIndex; } set { this.RaiseAndSetIfChanged(ref _CurrentIndex, value); } } private ICursor _Cursor = null; string mdbconnStr = ""; private IMapService _MapService { get; set; } IFeatureLayer dltbgxLayer = null; //IFeatureLayer dltbhrLayer = null; IFeatureLayer jcdltbLayer = null; private bool isRelationTBBSM = false; public BGJZTBListViewModel(object pHook) { try { PageSize = 200; Platform.Instance.NotifyMsgEven2 += NotifyMsg_NotifyMsgEven; Hook = pHook; _MapService = MapsManager.Instance.MapService; dltbgxLayer = _MapService.GetFeatureLayerByName("DLTBGX"); //dltbhrLayer = _MapService.GetFeatureLayerByName("DLTBHR"); jcdltbLayer = _MapService.GetFeatureLayerByLayerName("地类图斑"); JZTBFeatureLayer = _MapService.GetFeatureLayerByName("JCTB"); if (JZTBFeatureLayer != null) { SourceFeature = JZTBFeatureLayer.FeatureClass; if (SourceFeature.Fields.FindField("JZDLBM") == -1) { IFieldEdit _field = new FieldClass(); _field.Name_2 = "JZDLBM"; _field.AliasName_2 = "举证地类编码"; _field.Type_2 = esriFieldType.esriFieldTypeString; _field.Length_2 = 500; SourceFeature.AddField(_field); } if (SourceFeature.Fields.FindField("DYTBBSM") == -1) { IFieldEdit _field = new FieldClass(); _field.Name_2 = "DYTBBSM"; _field.AliasName_2 = "对应图斑标识码"; _field.Type_2 = esriFieldType.esriFieldTypeString; _field.Length_2 = 255; SourceFeature.AddField(_field); } //if (SourceFeature.Fields.FindField("JZDKBH") == -1) //{ // IFieldEdit _field = new FieldClass(); // _field.Name_2 = "JZDKBH"; // _field.AliasName_2 = "举证地块编号"; // _field.Type_2 = esriFieldType.esriFieldTypeString; // SourceFeature.AddField(_field); //} if (SourceFeature.Fields.FindField("LJBZ") == -1) { IFieldEdit _field = new FieldClass(); _field.Name_2 = "LJBZ"; _field.AliasName_2 = "类举标注"; _field.Type_2 = esriFieldType.esriFieldTypeString; _field.Length_2 = 255; SourceFeature.AddField(_field); } //ShowAddFileld(fields.FieldCount, "DYTBBSM", "对应图斑标识码"); //ShowAddFileld(fields.FieldCount + 1, "JZDKBH", "举证地块编号"); //ShowAddFileld(fields.FieldCount, "LJBZ", "类举标注"); if (Data == null) { Data = new DataTable(); ConstructColumn(JZTBFeatureLayer.FeatureClass.Fields); } } isRelationTBBSM = false; //创建命令 CreateCommand(); InitTableView(); SelectFirstRow(); } catch (Exception ex) { LogAPI.Debug(ex); } finally { //this.CloseLoading(); } } private void SelectFirstRow() { try { DataView view = new DataView(Data); DataRowView rowview = Data.DefaultView.Cast().Where(a => a.Row.Table.Columns.Contains(KeyIDName)).FirstOrDefault(); CurrentItem = rowview; } catch (Exception eee) { } } private void CopyFeatureClass(IFeatureClass pFromFeatureClass, IFeatureClass pToFeatureClass) { try { IFeatureCursor pFromFeatureCursor = pFromFeatureClass.Search(null, false); IFeatureCursor pToFeatureCursor = pToFeatureClass.Insert(true); IFeatureBuffer pFeatureBuffer = pToFeatureClass.CreateFeatureBuffer(); IFeature pFromFeature = pFromFeatureCursor.NextFeature(); while (pFromFeature != null) { int IndexShape = pFeatureBuffer.Fields.FindField("Shape"); pFeatureBuffer.set_Value(IndexShape, pFromFeature); pFeatureBuffer.Shape = pFromFeature.Shape; pToFeatureCursor.InsertFeature(pFeatureBuffer); pFromFeature = pFromFeatureCursor.NextFeature(); pFeatureBuffer = pToFeatureClass.CreateFeatureBuffer(); } pToFeatureCursor.Flush(); } catch (Exception ex) { throw ex; } } private string TempGDBPath { get { string path = string.Empty; try { string toDir = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "TempCache"); path = System.IO.Path.Combine(toDir, "TempGDB.gdb"); if (!Directory.Exists(path)) { string sourceDir = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\临时文件\\TempGDB.gdb"); CopyDirectInfo(sourceDir, path); } } catch { } return path; } } #region 数据筛选 private string CreateTempPath() { //var Path = Directory.GetCurrentDirectory() + "\\Temp\\举证图斑临时数据.gdb"; string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\举证成果临时数据"; if (!System.IO.Directory.Exists(gdbFolder)) { System.IO.Directory.CreateDirectory(gdbFolder); } try { DelectDir(gdbFolder);//能删除就删除 删除报错不处理 } catch { } string mdbFileName = Guid.NewGuid().ToString() + ".gdb"; var Path = System.IO.Path.Combine(gdbFolder, mdbFileName); var TempGDBPath = System.IO.Path.Combine(SysAppPath.GetTemplatePath(), "TempGDB.gdb"); // var TempGDBPath = Env.Instance.TempMDB.TempGDBPath;//模板 if (Directory.Exists(Path)) { Directory.Delete(Path, true); } Directory.CreateDirectory(Path); CopyDirectInfo(TempGDBPath, Path); return Path; } 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 static void CopyDirectInfo(string sourceDir, string toDir) { if (!Directory.Exists(sourceDir)) { throw new ApplicationException("未找到文件:" + sourceDir); } if (!Directory.Exists(toDir)) { Directory.CreateDirectory(toDir); } DirectoryInfo directInfo = new DirectoryInfo(sourceDir); FileInfo[] filesInfos = directInfo.GetFiles(); foreach (FileInfo fileinfo in filesInfos) { string fileName = fileinfo.Name; File.Copy(fileinfo.FullName, toDir + @"/" + fileName, true); } } /// /// 数据筛选 /// /// 基础数据 /// 更新数据 /// 更新过程层数据 /// 变更前标识码 /// 变更后标识码 /// private void DLTB_Screen(string JC, string GX, string GXGC, string TempPath, string filePath) { IFeatureLayer TempErase = null; IFeatureClass JCFC = null; IFeatureClass GXFC = null; IFeatureClass GXGCFC = null; IWorkspaceAPI wsAPI = null; IFeatureClassAPI sourceFcAPI = null; try { JCFC = MapsManager.Instance.MapService.GetFeatureClassByName(JC);//基础数据 mdb GXGCFC = MapsManager.Instance.MapService.GetFeatureClassByName(GXGC);//变更过程gdb GXFC = MapsManager.Instance.MapService.GetFeatureClassByName(GX);//变更层gdb #region 擦除 GPParamClass paramClass = new GPParamClass() { FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = JCFC }, SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = GXGCFC }, OutFeatureClassPath = $"{TempPath}\\{GXGC}", IsGetOutPutFeature = true, PreserveAttributes = "ALL" }; GeoprocessorHelper.EraseAnalysis(paramClass, ref TempErase); #endregion #region 合并 wsAPI = new WorkspaceAPI(TempPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile); sourceFcAPI = wsAPI.OpenFeatureClass(GXGC); LoadFeatureClass(GXFC, sourceFcAPI.FeatureClass, null); #endregion } catch (Exception ex) { LogAPI.Debug(ex); } finally { if (TempErase != null) Marshal.ReleaseComObject(TempErase); if (JCFC != null) Marshal.ReleaseComObject(JCFC); if (GXFC != null) Marshal.ReleaseComObject(GXFC); if (GXGCFC != null) Marshal.ReleaseComObject(GXGCFC); if (wsAPI != null) wsAPI.CloseWorkspace(); if (sourceFcAPI != null) sourceFcAPI.CloseFeatureClass(); } } public bool LoadFeatureClass(IFeatureClass inFeatureClass, IFeatureClass saveFeatureClass, IQueryFilter pQueryFilter) { //生成两个要素类字段的对应表 Dictionary pFieldsDict = new Dictionary(); this.GetFCFieldsDirectory(inFeatureClass, saveFeatureClass, ref pFieldsDict); IFeatureCursor pinFeatCursor = inFeatureClass.Search(pQueryFilter, false); long nCount = inFeatureClass.FeatureCount(pQueryFilter); IFeature pinFeat = pinFeatCursor.NextFeature(); IFeatureCursor psaveFeatCursor = saveFeatureClass.Insert(true); //使用IFeatureBuffer在内存中产生缓存避免多次打开,关闭数据库 IFeatureBuffer psaveFeatBuf = null; IFeature psaveFeat = null; long n = 0; while (pinFeat != null) { try { psaveFeatBuf = saveFeatureClass.CreateFeatureBuffer(); psaveFeat = psaveFeatBuf as IFeature; if (inFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { IAnnotationFeature pAF = (IAnnotationFeature)pinFeat; IAnnotationFeature pNAF = (IAnnotationFeature)psaveFeat; if (pAF.Annotation != null) { pNAF.Annotation = pAF.Annotation; } } psaveFeat.Shape = pinFeat.Shape; foreach (KeyValuePair keyvalue in pFieldsDict) { if (pinFeat.get_Value(keyvalue.Key).ToString() == "") { if (psaveFeat.Fields.get_Field(keyvalue.Value).Type == esriFieldType.esriFieldTypeString) { psaveFeat.set_Value(keyvalue.Value, ""); } else { psaveFeat.set_Value(keyvalue.Value, 0); } } else { psaveFeat.set_Value(keyvalue.Value, pinFeat.get_Value(keyvalue.Key)); } } psaveFeatCursor.InsertFeature(psaveFeatBuf); } catch (Exception ex) { LogAPI.Debug(ex); } finally { psaveFeat = null; n++; if (n % 2000 == 0) { psaveFeatCursor.Flush(); } pinFeat = pinFeatCursor.NextFeature(); } } psaveFeatCursor.Flush(); Marshal.ReleaseComObject(psaveFeatCursor); Marshal.ReleaseComObject(psaveFeatBuf); Marshal.ReleaseComObject(pinFeatCursor); if (pinFeat != null) { Marshal.ReleaseComObject(pinFeat); } if (psaveFeat != null) { Marshal.ReleaseComObject(psaveFeat); } return true; } private void GetFCFieldsDirectory(IFeatureClass pFCold, IFeatureClass pFCnew, ref Dictionary FieldsDictionary) { for (int i = 0; i < pFCold.Fields.FieldCount; i++) { string tmpstrold = pFCold.Fields.get_Field(i).Name.ToUpper(); switch (tmpstrold) { case "OBJECTID": case "SHAPE": case "SHAPE_LENGTH": case "SHAPE_AREA": case "FID": { //以上字段由系统自动生成 break; } default: { for (int j = 0; j < pFCnew.Fields.FieldCount; j++) { string tmpstrnew = pFCnew.Fields.get_Field(j).Name.ToUpper(); if (tmpstrold == tmpstrnew) { FieldsDictionary.Add(i, j); break; } } break; } } } } #endregion private void NotifyMsg_NotifyMsgEven(NotifyMsgPackage obj) { try { //接收来自内业会审详情视图的消息 if (obj.MsgType == "JZTBXXBRelationView") { switch (obj.Content.ToString()) { case "NextData": //下一条 NextDataCmd.Execute(null); break; case "PrevData": //上一条 PrevDataCmd.Execute(null); break; case "RefreshListData": RefreshDataCmd.Execute(null); RefreshSource(); break; default: break; } } } catch (Exception ex) { LogAPI.Debug(ex.Message); throw; } } /// /// 构造列获取记录条数 /// /// /// private void ConstructColumn(IFields fields) { if (fields != null) { for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); if (field.Name.ToUpper().StartsWith("SHAPE") || field.Name.ToUpper() == "TBFW") continue; if(field.Name.ToUpper() != "OBJECTID" && field.Name.ToUpper() != "XZQDM" && field.Name.ToUpper() != "BGDL" && field.Name.ToUpper() != "BSM" && field.Name.ToUpper() != "TBBH" && field.Name.ToUpper() != "DYTBBSM" && field.Name.ToUpper() != "JZDKBH" && field.Name.ToUpper() != "LJBZ" && field.Name.ToUpper() != "JZDLBM") continue; DataColumn col = new DataColumn(); col.ExtendedProperties.Add("index", i); col.ColumnName = field.Name; col.Caption = field.AliasName; switch (field.Type) { case esriFieldType.esriFieldTypeSmallInteger: col.DataType = typeof(short); break; case esriFieldType.esriFieldTypeInteger: col.DataType = typeof(int); break; case esriFieldType.esriFieldTypeSingle: break; case esriFieldType.esriFieldTypeDouble: col.DataType = typeof(double); break; case esriFieldType.esriFieldTypeString: col.DataType = typeof(string); break; case esriFieldType.esriFieldTypeDate: col.DataType = typeof(DateTime); break; case esriFieldType.esriFieldTypeOID: col.DataType = typeof(Int32); break; case esriFieldType.esriFieldTypeGeometry: break; case esriFieldType.esriFieldTypeBlob: break; case esriFieldType.esriFieldTypeRaster: break; case esriFieldType.esriFieldTypeGUID: break; case esriFieldType.esriFieldTypeGlobalID: break; case esriFieldType.esriFieldTypeXML: break; default: break; } col.ReadOnly = !field.Editable;//编辑状态启用默认是否可以编辑 Data.Columns.Add(col); Marshal.ReleaseComObject(field); } //ShowAddFileld(fields.FieldCount, "DYTBBSM", "对应图斑标识码"); //ShowAddFileld(fields.FieldCount + 1, "JZDKBH", "举证地块编号"); //ShowAddFileld(fields.FieldCount, "LJBZ", "类举标注"); } } private void ShowAddFileld(int index, string name, string aliasName) { DataColumn newColumn = new DataColumn(); newColumn.ExtendedProperties.Add("index", index); newColumn.ColumnName = name; newColumn.Caption = aliasName; Data.Columns.Add(newColumn); } public void InitTableView() { if (JZTBFeatureLayer == null) return; try { Data.Rows.Clear(); string where = string.Empty; //if (f_gjdtb) //where += "& DYTBBSM like '%/%' "; if (f_gjdlbyz) where += "& JZDLBM <> BGDL "; if (f_wgj) where += "& DYTBBSM is null or DYTBBSM = '' "; where = where.Trim('&'); where = where.Replace("&", "or"); if (string.IsNullOrWhiteSpace(where)) where = "1=1"; IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = where; using (ESRI.ArcGIS.ADF.ComReleaser com = new ESRI.ArcGIS.ADF.ComReleaser()) { var index = 0; IFeatureClass pCurrentFeatureClass = JZTBFeatureLayer.FeatureClass; _Cursor = (pCurrentFeatureClass as ITable).Search(pFilter, true); IRow feature = null; int selectCount = 0; IDictionary dicTBBH_DYTBBSMs = new Dictionary(); int jztbybhIndex = pCurrentFeatureClass.Fields.FindField("TBBH"); int jzbsmIndex = pCurrentFeatureClass.Fields.FindField("DYTBBSM"); while ((feature = _Cursor.NextRow()) != null) { if (f_gjdtb) { GetSelectMoreDicTB(feature, jztbybhIndex, jzbsmIndex, out dicTBBH_DYTBBSMs, out selectCount); } } if (f_gjdtb) Count = selectCount; else Count = pCurrentFeatureClass.FeatureCount(pFilter); if (Count < PageSize) { com.ManageLifetime(_Cursor); } _Cursor = (pCurrentFeatureClass as ITable).Search(pFilter, true); while ((feature = _Cursor.NextRow()) != null) { if (f_gjdtb && !dicTBBH_DYTBBSMs[feature.Value[jztbybhIndex].ToString()].Contains("/")) continue;//筛选多个图斑 DataRow dr = Data.NewRow(); for (int i = 0; i < Data.Columns.Count; i++) { object obj = feature.get_Value(pCurrentFeatureClass.FindField(Data.Columns[i].ColumnName)); if (obj == null) continue; else { if ((obj.ToString()).Contains("1899/12/30 0:00:00")) { obj = System.DBNull.Value; } } //字符串时,去空格,对应bug10473 if (obj is string) { obj = obj.ToString().Trim(); } dr[i] = obj; } System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); index++; //if (PageSize != -1) //{ // if (index > PageSize) // break; //} CurrentIndex = 0; Data.Rows.Add(dr); } ShowNum = Data.Rows.Count; ShowLabContent(Data.Rows.Count); RowCount = Data.Rows.Count; if (RowCount > 0) { RowHandle++;//初始化,默认第一行 //SetDetailViewData(Data.Rows[0]);//设置第一个举证信息选中 ISelectionSet pSelectionSet = (JZTBFeatureLayer as IFeatureSelection).SelectionSet; if (pSelectionSet.Count > 0 && m_hookHelper != null)//兼容空值 肖芮 2020-09-25 { m_hookHelper.FocusMap.ClearSelection(); } List oids = new List(); oids.Add(Int32.Parse(Data.Rows[0]["OBJECTID"].ToString())); pSelectionSet.AddList(oids.Count, ref oids.ToArray()[0]); IMapControlDefault mapcontrol = MapsManager.Instance.MapService.Hook as IMapControlDefault; if (mapcontrol != null) { mapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, mapcontrol.ActiveView.Extent); } } } } catch (Exception ex) { throw ex; } finally { } } private void GetSelectMoreDicTB(IRow feature, int jztbybhIndex, int jzbsmIndex, out IDictionary dicTBBH_DYTBBSMs, out int selectCount) { selectCount = 0; dicTBBH_DYTBBSMs = new Dictionary(); string jztbybh = feature.Value[jztbybhIndex].ToString(); string jzbsm = feature.Value[jzbsmIndex].ToString(); if (!dicTBBH_DYTBBSMs.Keys.Contains(jztbybh)) { dicTBBH_DYTBBSMs.Add(jztbybh, jzbsm); } else { if (!dicTBBH_DYTBBSMs[jztbybh].Contains(jzbsm) && !string.IsNullOrWhiteSpace(jzbsm)) { selectCount++; dicTBBH_DYTBBSMs[jztbybh] = string.Format(@"{0}/{1}", dicTBBH_DYTBBSMs[jztbybh], jzbsm); } } } /// /// 显示查询数据量LabContent /// /// 当前查询到的数据量 private void ShowLabContent(int CurrentFindCount) { try { IQueryFilter pQueryFilter = new QueryFilterClass() { WhereClause = "1=1 ", SubFields = KeyIDName }; if (this.SourceFeature != null) { Count = (this.SourceFeature as ITable).RowCount(pQueryFilter); } else if (JZTBFeatureLayer.FeatureClass is ITable) { Count = (JZTBFeatureLayer.FeatureClass as ITable).RowCount(pQueryFilter); } } catch (Exception ex) { LogAPI.Debug(ex.Message.ToString()); MessageHelper.ShowError(ex.Message.ToString()); } } /// /// 创建命令 /// private void CreateCommand() { try { PrevDataCmd = ReactiveCommand.Create(); NextDataCmd = ReactiveCommand.Create(); RefreshDataCmd = ReactiveCommand.Create(); GridControlUnSelectAll = ReactiveCommand.Create(); GridControlRefreshData = ReactiveCommand.Create(); GridControlFocusRow = ReactiveCommand.Create(); GridControlAutoGeneratedColumns = ReactiveCommand.Create(); GridControlAutoGeneratedColumns.Subscribe(_ => { var grid = (_.Source as GridControl); DataTable table = grid.ItemsSource as DataTable; if (table == null) return; foreach (GridColumn column in grid.Columns) { if (table.Columns.Contains(column.FieldName)) { string caption = table.Columns[column.FieldName].Caption; if (caption != null) { column.EditSettings = new TextEditSettings() { HorizontalContentAlignment = EditSettingsHorizontalAlignment.Left }; column.Header = caption; } } } }); CurrentItemChangedCommand = ReactiveCommand.Create(); CurrentItemChangedCommand.Subscribe(_ => { GridControlCurrentItemChanged(_); }); SelectionChangedCommand = ReactiveCommand.Create(); SelectionChangedCommand.Subscribe(_ => { GridControlSelectionChanged(_); }); EndSortingCommand = ReactiveCommand.Create(); EndSortingCommand.Subscribe(_ => { GridControlEndSorting(_); }); //关联图斑标识码 RelationTBBSMCmd = ReactiveCommand.Create(); RelationTBBSMCmd.Subscribe(_ => { if (frmGLBSMParameter == null) { frmGLBSMParameter = new BGFrmGLBSMParameter(); frmGLBSMParameter.Closed += FrmGLBSMParameter_Closed; } if (frmGLBSMParameter.ShowInMainWindow(true) == true) { RelationTBBSM(); } }); //人机交互 RGJYCmd = ReactiveCommand.Create(); RGJYCmd.Subscribe(_ => { if (CurrentItem != null) { DataRow dr = CurrentItem.Row; int OID = (int)dr["OBJECTID"]; if (frmJZTBXXB_RGJX == null) { frmJZTBXXB_RGJX = new BGFrmJZTBXXBRelation(Hook); frmJZTBXXB_RGJX.Closed += FrmJZTBXXB_RGJX_Closed; } frmJZTBXXB_RGJX.SetData(OID); frmJZTBXXB_RGJX.ShowInMainWindow(); } }); //导出举证图斑信息表 ExportJZTBXXBCmd = ReactiveCommand.Create(); ExportJZTBXXBCmd.Subscribe(_ => { ExportJZTBXXB(); }); //导出举证图斑信息表 FilterDataCmd = ReactiveCommand.Create(); FilterDataCmd.Subscribe(_ => { InitTableView(); }); } catch (Exception ex) { MessageHelper.ShowError(ex.Message); LogAPI.Debug(ex); } } private void FrmGLBSMParameter_Closed(object sender, EventArgs e) { if (frmGLBSMParameter != null) { AreaRatio = frmGLBSMParameter.AreaRatio; frmGLBSMParameter = null; } } private void FrmJZTBXXB_RGJX_Closed(object sender, EventArgs e) { frmJZTBXXB_RGJX = null; } public void GridControlCurrentItemChanged(CurrentItemChangedEventArgs e) { try { if (IsNotByPerson) { return; } if (CurrentItem == null) { return; } if (!(CurrentItem as DataRowView).Row.Table.Columns.Contains(KeyIDName) && !(CurrentItem as DataRowView).Row.Table.Columns.Contains(KeyIDName)) return; List oids = new List(); DataRowView drv = CurrentItem as DataRowView; int oid = -1; if ((CurrentItem as DataRowView).Row.Table.Columns.Contains(KeyIDName)) { int.TryParse(drv.Row[KeyIDName].ToString(), out oid); } ISelectionSet pSelectionSet = (JZTBFeatureLayer as IFeatureSelection).SelectionSet; if (pSelectionSet == null) { return; } if (pSelectionSet.Count > 10000) { m_hookHelper.FocusMap.ClearSelection(); } if (pSelectionSet.Count > 0 || oids.Count > 0) { List listRemoveObjectID = new List(); IEnumIDs enumIDs = pSelectionSet.IDs; enumIDs.Reset(); int objectid = 0; while ((objectid = enumIDs.Next()) >= 0) { if (oids.Contains(objectid)) { oids.Remove(objectid); continue; } listRemoveObjectID.Add(objectid); } if (listRemoveObjectID.Count > 0) { pSelectionSet.RemoveList(listRemoveObjectID.Count, ref listRemoveObjectID.ToArray()[0]); } } if (oids.Count > 0) { pSelectionSet.AddList(oids.Count, ref oids.ToArray()[0]); } IFeature pfeature = JZTBFeatureLayer.FeatureClass.GetFeature(oid); if (pfeature != null) { MoveToCenterBySelectFeature(m_hookHelper.Hook as IMapControlDefault, JZTBFeatureLayer as ILayer, pfeature, true); } //清空元素 m_hookHelper.ActiveView.GraphicsContainer.DeleteAllElements(); m_hookHelper.ActiveView.GraphicsContainer.Reset(); #region 高亮显示关联的三调图斑 int jkbsm_index = pfeature.Fields.FindField("BSM"); if (jkbsm_index != -1) { string jkbsm = pfeature.Value[jkbsm_index].ToString(); IQueryFilter filter = new QueryFilterClass() { WhereClause = string.Format(" bsm in ('{0}')", jkbsm.Replace(",", "','")) }; List bsmlist = new List(); IFeatureCursor cursor = dltbgxLayer.FeatureClass.Search(filter, true); IFeature f = null; int bsmIndex = dltbgxLayer.FeatureClass.Fields.FindField("BSM"); while ((f = cursor.NextFeature()) != null) { string bsm = string.Empty; if (bsmIndex != -1) { bsm = f.Value[bsmIndex].ToString(); bsmlist.Add(bsm); } DrawPolygonElement(f.ShapeCopy, bsm); } IFeatureCursor jccursor = jcdltbLayer.FeatureClass.Search(filter, true); IFeature jcf = null; int jcbsmIndex = jcdltbLayer.FeatureClass.Fields.FindField("BSM"); while ((jcf = jccursor.NextFeature()) != null) { string bsm = string.Empty; if (jcbsmIndex != -1) { bsm = jcf.Value[jcbsmIndex].ToString(); if (bsmlist.Contains(bsm)) { continue; } } DrawPolygonElement(jcf.ShapeCopy, bsm); } } #endregion if (frmJZTBXXB_RGJX != null) frmJZTBXXB_RGJX.SetData((int)drv.Row["OBJECTID"]); string tbbh = drv.Row["TBBH"].ToString(); ProjectInfo project = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; string dbpath = project.DBPath; string SourcePath = dbpath; if (!Directory.Exists(SourcePath)) { LogAPI.Debug("举证标注信息文件, 不存在该路径:" + SourcePath); } DirectoryInfo FileDir = new DirectoryInfo(SourcePath); List listFile = new List(); listFile.AddRange(FileDir.GetFiles("*.db", SearchOption.AllDirectories)); if (listFile == null || listFile.Count == 0) return; List qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); if (qsDic != null) { string code = project.CODE; string xianName = qsDic.FirstOrDefault(f => f.CODE == code).NAME; foreach (FileInfo item in listFile) { if (item.Name.Contains("xianName")) { dbpath = item.FullName; break; } } } if (!dbpath.EndsWith(".db")) return; if (!File.Exists(dbpath)) { LogAPI.Debug("附件路径不存在:" + dbpath); MessageHelper.ShowError("附件路径异常!"); return; } //string where = string.Format("TBYBH = '{0}'", tbbh); DataTable dtFJ = SQLiteDBOperate.Instance.ExceDataTable(dbpath, string.Format("select longitude XZB,latitude YZB,psjd,fjmc,fjlx from FJ where tbbsm=(select bsm from tbjbxx where tbbh='{0}')", tbbh)); if (dtFJ == null) { MessageHelper.ShowError("连接db数据库异常!"); return; } //添加方位角 if (dtFJ.Rows.Count != 0) { foreach (DataRow dr in dtFJ.Rows) { IPoint point = new PointClass() { X = dr["XZB"].ToDouble(), Y = dr["YZB"].ToDouble() }; ISpatialReferenceFactory NewSpatialReference = new SpatialReferenceEnvironmentClass(); point.SpatialReference = NewSpatialReference.CreateGeographicCoordinateSystem(4490); point.Project((JZTBFeatureLayer as IGeoDataset).SpatialReference); double psjd = dr["PSJD"].ToDouble(); string fjmc = dr["FJMC"].ToString(); string fjlx = dr["FJLX"].ToString(); DrawAnglePoint(point, psjd, fjmc, fjlx); } } m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_hookHelper.ActiveView.Extent); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_hookHelper.ActiveView.Extent); } catch (Exception ex) { LogAPI.Debug(ex); } } public static void MoveToCenterBySelectFeature(IMapControlDefault mapControl, ILayer pLayer, IFeature feature, bool enlarge = true) { try { if (mapControl.Map.SelectionCount > 0) { mapControl.Map.ClearSelection(); } MoveToCenter(feature, mapControl, enlarge); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, feature, mapControl.ActiveView.Extent); mapControl.Map.SelectFeature(pLayer, feature); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, feature, mapControl.ActiveView.Extent); } catch (Exception ex) { MessageHelper.ShowError("操作异常!异常信息:" + ex.Message); LogAPI.Debug(ex); } } public static void MoveToCenter(IFeature pFeature, IMapControlDefault mapControl, bool enlarge = true) { try { //Bug-13836 霍岩 2018-12-21 实例化ArcGIS的EnvelopeClass EnvelopeClass pEnvelope = new EnvelopeClass(); IEnvelope pEnvOfFeat = pFeature.Shape.Envelope; //投影到当前地图坐标系定位缩放到当前要素 pEnvOfFeat.Project(mapControl.SpatialReference); IUnitConverter pUnitConverter = new UnitConverterClass(); double dScale = pUnitConverter.ConvertUnits(50, esriUnits.esriMeters, mapControl.MapUnits); pEnvelope.PutCoords(pEnvOfFeat.XMin - dScale, pEnvOfFeat.YMin - dScale, pEnvOfFeat.XMax + dScale, pEnvOfFeat.YMax + dScale); if (enlarge) { mapControl.ActiveView.Extent = pEnvelope; } mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, mapControl.ActiveView.Extent); } catch (Exception ex) { MessageHelper.ShowError("操作异常!异常信息:" + ex.Message); LogAPI.Debug(ex); } } private void DrawPolygonElement(IGeometry pGeo, string pName) { ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; //设置线宽和线的颜色 ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = Symbol.GetRGBColor(255, 0, 0); pLineSymbol.Width = 1; pSimpleFillSymbol.Outline = pLineSymbol; PolygonElementClass element = new PolygonElementClass(); element.Name = pName; element.Symbol = pSimpleFillSymbol; element.Geometry = pGeo; IGraphicsLayer grapLayer = AddSubGraphicsLayer("TempDLTBGrapLayer"); (grapLayer as IGraphicsContainer).AddElement(element, 0); MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, MapsManager.Instance.MapService.getAxMapControl().ActiveView.Extent); } public IGraphicsLayer AddSubGraphicsLayer(string subgraphicsLayername) { ICompositeGraphicsLayer pCompositeGLayer = MapsManager.Instance.MapService.getAxMapControl().Map.BasicGraphicsLayer as ICompositeGraphicsLayer; IGraphicsLayer pGLayer = null; try { //查找是否已存在,如果不存在,跳转到catch内容. //如果查到不到,说明集合中并没有指定名称的graphicslayer pGLayer = pCompositeGLayer.FindLayer(subgraphicsLayername); } catch { //若不存在,则添加一个指定名称的GraphicsLayer pGLayer = pCompositeGLayer.AddLayer(subgraphicsLayername, null); } return pGLayer; } public void GridControlSelectionChanged(DevExpress.Xpf.Grid.GridSelectionChangedEventArgs e) { } public void GridControlEndSorting(RoutedEventArgs e) { try { //Bug-16125 霍岩 2019-06-14 判断GridControl的SortInfo数量是否为0 GridControl gc = e.OriginalSource as GridControl; if (gc == null) return; if (gc.SortInfo.Count == 0) return; GridSortInfo sortInfo = gc.SortInfo[0]; DataColumn column = Data.Columns[sortInfo.FieldName]; if (column == null) { throw new Exception("未获取到列!"); } string sort = " ASC"; if (sortInfo.SortOrder.ToString() == "Ascending") { sort = " ASC"; } else { sort = " DESC"; } Data.Select("1=1", sortInfo.FieldName + sort); e.Handled = false; return; } catch (Exception ex) { MessageHelper.ShowError("数据排序失败:" + ex.Message); LogAPI.Debug(ex); } } public void RefreshSource() { try { InitTableView(); } catch (Exception ex) { MessageHelper.ShowError("刷新属性表数据异常:" + ex.Message); } finally { IsLoading = false; } } /// /// 绘制方位角 /// /// /// private void DrawAnglePoint(IPoint point, double angle, string picName, string fjlx = "") { try { PictureMarkerSymbolClass picMarkerSymbol = new PictureMarkerSymbolClass(); picMarkerSymbol.Angle = -angle; picMarkerSymbol.Size = 28; string name = null; switch (fjlx) { case "Y": name = "远景"; break; case "J": name = "近景"; break; case "T": name = "利用特征"; break; case "S": name = "扫描件"; break; default: name = "远景"; break; } picMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, System.Windows.Forms.Application.StartupPath + "\\Images\\" + name + ".bmp"); IColor newColor = new RgbColorClass(); IRgbColor rgbColor = newColor as IRgbColor; rgbColor.Red = 255; rgbColor.Blue = 255; rgbColor.Green = 255; newColor.Transparency = 100; picMarkerSymbol.BackgroundColor = null; picMarkerSymbol.BitmapTransparencyColor = newColor; MarkerElementClass pMarkerAngleElement = new MarkerElementClass(); pMarkerAngleElement.Symbol = picMarkerSymbol; pMarkerAngleElement.Name = picName; IElement pElement; pElement = pMarkerAngleElement as IElement; pElement.Geometry = point; (this.m_hookHelper.ActiveView.GraphicsContainer as IGraphicsContainer).AddElement(pMarkerAngleElement, 2); } catch (Exception ex) { LogAPI.Debug("绘制方位角失败:" + ex); } } IDictionary dicJCBSM = new Dictionary(); IDictionary dicBSM = new Dictionary(); /// /// 关联图斑标识码 /// private void RelationTBBSM() { try { isRelationTBBSM = true; bool isCreateNMK = false; if (jcdltbLayer == null || jcdltbLayer.FeatureClass == null || jcdltbLayer.FeatureClass.FeatureCount(null) == 0) { MessageHelper.Show("未找到基础地类图斑层或基础地类图斑层为空!!"); return; } if (dltbgxLayer == null || dltbgxLayer.FeatureClass == null) { MessageHelper.Show("未找到地类图斑更新层!!"); return; } if (JZTBFeatureLayer == null || JZTBFeatureLayer.FeatureClass == null || JZTBFeatureLayer.FeatureClass.FeatureCount(null) == 0) { MessageHelper.Show("未找到举证成果层或举证成果层为空!!"); return; } dicJCBSM.Clear(); dicBSM.Clear(); this.ShowLoading("正在重算举证图斑面积……", 0, 0); ClearDataFields(); ExtensionShowWindow.MainWinForm.Enabled = false; IFeatureCursor up_cursor = JZTBFeatureLayer.FeatureClass.Update(null, true); IFeature feature = null; int tbmjIndex = JZTBFeatureLayer.FeatureClass.Fields.FindField("TBMJ"); int num = 0; int rowcount = JZTBFeatureLayer.FeatureClass.FeatureCount(null); if (tbmjIndex != -1) { while ((feature = up_cursor.NextFeature()) != null) { num++; if (num % 1000 != 0 || num != rowcount) { this.UpdateMsg($"正在重算举证图斑面积中...【{num}/{rowcount}】"); } double area = feature.ShapeCopy.GetEllipseArea(); feature.set_Value(tbmjIndex, area * 0.0015); up_cursor.UpdateFeature(feature); Marshal.ReleaseComObject(feature); } } this.UpdateMsg("正在分析数据……"); #region 数据提取 string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\BGJZTB"; if (!System.IO.Directory.Exists(gdbFolder)) { System.IO.Directory.CreateDirectory(gdbFolder); } try { DelectDir(gdbFolder);//能删除就删除 删除报错不处理 } catch { } ProjectInfo prj = (ProjectInfo)MapsManager.Instance.CurrProjectInfo; string SourcePath = prj.NMDatabase; IWorkspaceAPI NmWsAPI = new WorkspaceAPI(SourcePath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile); IFeatureLayer nmkFeatureLayer = null; if (NmWsAPI != null && NmWsAPI.CurrentWorkspace != null) { try { IFeatureClassAPI fcAPI = NmWsAPI.OpenFeatureClass("DLTB_NMK"); if (fcAPI != null) nmkFeatureLayer = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName }; } catch { } } if (nmkFeatureLayer == null) { GPParamClass nmgPParamClass = new GPParamClass(); nmgPParamClass.FirstFeatureLayer = jcdltbLayer;//基础地类图斑要素类 nmgPParamClass.SecondFeatureLayer = dltbgxLayer;//地类图斑更新要素类 nmgPParamClass.OutFeatureClassPath = SourcePath + "\\" + "DLTB_NMK";//要添加的要素类图层 nmgPParamClass.IsGetOutPutFeature = true; GeoprocessorHelper.EraseAnalysis(nmgPParamClass, ref nmkFeatureLayer); IFeatureClassAPI fcAPI = new FeatureClassAPI(dltbgxLayer.FeatureClass); fcAPI.FcToFc(nmkFeatureLayer.FeatureClass, null, false); isCreateNMK = true; } //修复几何 try { GeoprocessorHelper.RepairGeo(JZTBFeatureLayer.FeatureClass, true); } catch { } IFeatureLayer nmkdltbAndjzcgLayey = null; GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = nmkFeatureLayer; gPParamClass.GPType = EnumGPType.Intersect; gPParamClass.SecondFeatureLayer = JZTBFeatureLayer; gPParamClass.IsGetOutPutFeature = true; GeoprocessorHelper.IntersectAnalysis(gPParamClass, ref nmkdltbAndjzcgLayey); #endregion if (nmkdltbAndjzcgLayey != null) { //按照压盖面积降序排列,目的:当一个举证图斑压盖多个三调图斑时,默认取压盖面积最大的图斑进行关联 IQueryFilter filter = new QueryFilterClass(); int dltbgxIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("FID_DLTB_NMK"); int jctbIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("FID_JCTB"); filter.WhereClause = "1=1 order by shape_area desc"; ICursor cursor = (nmkdltbAndjzcgLayey.FeatureClass as ITable).Search(filter, true); IRow row = null; IDictionary dicJZDLBM = new Dictionary(); int tbbsmIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("BSM"); int jztbybhIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("TBBH_1"); int sdtbmjIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("TBMJ"); int jztbmjIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("TBMJ_1"); int dlbmIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("DLBM"); int shapeAreaIndex = nmkdltbAndjzcgLayey.FeatureClass.Fields.FindField("SHAPE_AREA");//不确定 string tbbsm = string.Empty; double sdtbmj = 0.00; double shapeArea = 0.00; if (tbbsmIndex != -1 && jztbybhIndex != -1) { while ((row = cursor.NextRow()) != null) { if (row.Value[dltbgxIndex].ToString() == "-1" || row.Value[jctbIndex].ToString() == "-1") continue; tbbsm = row.Value[tbbsmIndex].ToString(); sdtbmj = row.Value[sdtbmjIndex].ToDouble() * 0.0015; shapeArea = row.Value[shapeAreaIndex].ToDouble() * 0.0015; double jztbmj = row.Value[jztbmjIndex].ToDouble(); string jztbybh = row.Value[jztbybhIndex].ToString(); string dlbm = row.Value[dlbmIndex].ToString(); //当压盖多个三调图斑时,如果压盖面积大于举证/三调图斑总面的百分之四十,则关联 if (shapeArea > (double)AreaRatio / 100 * jztbmj || shapeArea > (double)AreaRatio / 100 * sdtbmj) { if (!dicBSM.Keys.Contains(tbbsm)) { dicBSM.Add(tbbsm, jztbybh); } else { if (!dicBSM[tbbsm].Contains(jztbybh) && !string.IsNullOrWhiteSpace(jztbybh)) { dicBSM[tbbsm] = string.Format(@"{0}/{1}", dicBSM[tbbsm], jztbybh); } } if (!dicJZDLBM.Keys.Contains(jztbybh)) { dicJZDLBM.Add(jztbybh, dlbm); } else { if (!dicJZDLBM[jztbybh].Contains(dlbm) && !string.IsNullOrWhiteSpace(dlbm)) { dicJZDLBM[jztbybh] = string.Format(@"{0}/{1}", dicJZDLBM[jztbybh], dlbm); } } } } } this.UpdateMsg("正在关联图斑标识码……"); int jcbhIndex = this.SourceFeature.Fields.FindField("TBBH"); int jkbsmIndex = this.SourceFeature.Fields.FindField("DYTBBSM"); int bsmIndex = this.SourceFeature.Fields.FindField("BSM"); int jzdlbmIndex = this.SourceFeature.Fields.FindField("JZDLBM"); int bzIndex = this.SourceFeature.Fields.FindField("LJBZ"); IFeatureCursor upjz_cursor = this.SourceFeature.Update(null, false); IFeature jzfeature = null; IFeature jzfeatureTemp = null; while ((jzfeatureTemp = upjz_cursor.NextFeature()) != null) { string jcbh = jzfeatureTemp.get_Value(jcbhIndex).ToString(); string jkbsm = jzfeatureTemp.get_Value(jkbsmIndex).ToString(); string bsm = jzfeatureTemp.get_Value(bsmIndex).ToString(); if (!dicJCBSM.Keys.Contains(bsm)) { dicJCBSM.Add(bsm, jcbh); } Marshal.ReleaseComObject(jzfeatureTemp); } upjz_cursor = this.SourceFeature.Update(null, false); //获取类举标注json信息 IDictionary dicLJBZ = GetLJBZs(); while ((jzfeature = upjz_cursor.NextFeature()) != null) { string jcbh = jzfeature.get_Value(jcbhIndex).ToString(); string jkbsm = jzfeature.get_Value(jkbsmIndex).ToString(); if (!dicBSM.Values.Contains(jcbh)) continue; var firstKey = dicBSM.FirstOrDefault(q => q.Value.Contains(jcbh)).Key; jzfeature.set_Value(jkbsmIndex, firstKey);//更新建库标识码 jzfeature.set_Value(jzdlbmIndex, dicJZDLBM[jcbh]);//更新举证地类编码 更新层地类编码 if (dicLJBZ != null && dicJCBSM != null) { var firstKey1 = dicJCBSM.FirstOrDefault(q => dicBSM[firstKey].Contains(q.Value)).Key; string jubzValue = dicLJBZ.FirstOrDefault(a => a.Key == firstKey1).Value; string bz = ""; try { if (jubzValue != null) { JObject jo = (JObject)JsonConvert.DeserializeObject(jubzValue); bz = jo["BZ"].ToString(); } } catch (Exception e) { } jzfeature.set_Value(bzIndex, bz); } else jzfeature.set_Value(bzIndex, null); upjz_cursor.UpdateFeature(jzfeature); Marshal.ReleaseComObject(jzfeature); } this.CloseLoading(); ExtensionShowWindow.MainWinForm.Enabled = true; MessageHelper.Show("关联图斑标识码成功。"); InitTableView();//刷新界面 DeleteTempFeatureLayer(nmkdltbAndjzcgLayey); if (isCreateNMK) DeleteTempFeatureLayer(nmkFeatureLayer); } } catch (Exception ex) { LogAPI.Debug("关联图斑标识码失败:" + ex.Message); MessageHelper.ShowError("关联图斑标识码失败!" + ex.Message); } finally { this.CloseLoading(); ExtensionShowWindow.MainWinForm.Enabled = true; } } //删除临时文件 public static void DeleteTempFeatureLayer(IFeatureLayer pFeatureLayer) { if (pFeatureLayer == null) return; try { ITable tempTable = pFeatureLayer.FeatureClass as ITable; if (tempTable == null) return; IFeatureWorkspaceManage pWorkspaceManager = (pFeatureLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace as IFeatureWorkspaceManage; pWorkspaceManager.DeleteByName((IDatasetName)((IDataset)tempTable).FullName); } catch (Exception ex) { LogAPI.Debug("删除临时文件异常:" + ex); } } private void ClearDataFields() { try { IFeatureCursor upjz_cursor = this.SourceFeature.Update(null, false); IFeature jzfeature = null; int dlbmIndex = this.SourceFeature.Fields.FindField("JZDLBM"); int bsmIndex = this.SourceFeature.Fields.FindField("DYTBBSM"); int bzIndex = this.SourceFeature.Fields.FindField("LJBZ"); while ((jzfeature = upjz_cursor.NextFeature()) != null) { if (dlbmIndex != -1) jzfeature.set_Value(dlbmIndex, null); if (bsmIndex != -1) jzfeature.set_Value(bsmIndex, null); if (bzIndex != -1) jzfeature.set_Value(bzIndex, null); upjz_cursor.UpdateFeature(jzfeature); Marshal.ReleaseComObject(jzfeature); } InitTableView();//刷新界面 } catch (Exception ex) { LogAPI.Debug("清除字段信息异常:" + ex.Message); LogAPI.Debug(ex); return; } } private IDictionary GetLJBZs() { IDictionary dic_BSMBZ = new Dictionary(); try { ProjectInfo prj = (ProjectInfo)MapsManager.Instance.CurrProjectInfo; string SourcePath = prj.DBPath; //string dirPath = System.IO.Path.Combine(prj.DBPath, "举证成果"); if (!Directory.Exists(SourcePath)) { LogAPI.Debug("举证标注信息文件, 不存在该路径:" + SourcePath); return null; } DirectoryInfo FileDir = new DirectoryInfo(SourcePath); List listFile = new List(); listFile.AddRange(FileDir.GetFiles("*.db", SearchOption.AllDirectories)); DataTable DbPathdataTab = null; foreach (var file in listFile) { DbPathdataTab = SQLiteDBOperate.Instance.ExceDataTable(file.FullName, $"select * from 'DCHSXX' "); if (DbPathdataTab != null) { foreach (DataRow row in DbPathdataTab.Rows) { string bsm = row["TBBSM"].ToTrim().ToString(); string KZXX = row["KZXX"].ToTrim().ToString(); dic_BSMBZ.Add(bsm, KZXX); } } } return dic_BSMBZ; } catch (Exception ex) { LogAPI.Debug("读取举证标注信息文件 " + ex.Message); return null; } } private void ExportJZTBXXB() { if (!isRelationTBBSM) { MessageHelper.ShowWarning("请先执行挂接关联标识码后导出举证信息表!"); return; } try { string code = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE; string ExportPath = ""; FolderBrowserDialog dialog = new FolderBrowserDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { ExportPath = dialog.SelectedPath; } else return; string sheng = ""; string shi = ""; string xian = ""; #region 获取省市县 List qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); if (qsDic == null) { MessageHelper.ShowTips("请先生成权属单位代码字典,在进行导出!"); return; } DataDicTionary dic = qsDic.FirstOrDefault(f => f.CODE.Length == 2); if (dic != null) { sheng = dic.NAME; } dic = qsDic.FirstOrDefault(f => f.CODE.Length == 4); if (dic != null) { shi = dic.NAME; } dic = qsDic.FirstOrDefault(f => f.CODE == code); if (dic != null) { xian = dic.NAME; } #endregion this.ShowLoading("正在导出举证图斑信息表,请稍等……", 0, 0); ExtensionShowWindow.MainWinForm.Enabled = false; string MDBTemplatePath = string.Format(@"{0}{1}\{2}\{3}\县举证信息表.mdb", SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "电子手簿"); ExportPath = string.Format(string.Format(@"{0}\({1}){2}举证信息表.mdb", ExportPath, code, xian)); if (File.Exists(ExportPath)) { File.Delete(ExportPath); } File.Copy(MDBTemplatePath, ExportPath); string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); string SourcePath = string.Format(connStr, ExportPath); //创建数据库连接 IRDBHelper dbHelper2 = RDBFactory.CreateDbHelper(SourcePath, DatabaseType.MSAccess); DataTable dtRST = dbHelper2.ExecuteDatatable("RST", "SELECT * FROM 举证信息表 WHERE 0 = 1", false); int id = 1; this.UpdateMsg("正在记录表格数据……"); int dlbmIndex = this.SourceFeature.Fields.FindField("TBBH"); int bsmIndex = this.SourceFeature.Fields.FindField("DYTBBSM"); int bzIndex = this.SourceFeature.Fields.FindField("LJBZ"); ICursor cursor = (this.SourceFeature as ITable).Search(null, true); IRow row = null; while ((row = cursor.NextRow()) != null) { string jkbsm = row.get_Value(bsmIndex).ToString(); if (string.IsNullOrEmpty(jkbsm)) continue; string dkbh = null; if(dicBSM.Keys.Contains(jkbsm)) dkbh = dicBSM[jkbsm]; else dkbh = row.get_Value(dlbmIndex).ToString(); //类举标注 string ljbz = row.get_Value(bzIndex).ToString(); //写入表数据 DataRow dr = dtRST.NewRow(); dr["序号"] = id; dr["行政区划代码"] = code; dr["省名"] = sheng; dr["地市名"] = shi; dr["县名"] = xian; dr["对应图斑标识码"] = jkbsm; dr["举证地块编号"] = dkbh; dr["类举标注"] = ljbz; dtRST.Rows.Add(dr); id++; } this.UpdateMsg("正在写入表格数据……"); dbHelper2.SaveTable("RST", true); this.CloseLoading(); ExtensionShowWindow.MainWinForm.Enabled = true; MessageHelper.Show("导出成功。"); } catch (Exception ex) { LogAPI.Debug("导出举证图斑信息表失败:" + ex.Message); LogAPI.Debug(ex); MessageHelper.ShowError("导出举证图斑信息表失败!" + ex.Message); } finally { this.CloseLoading(); ExtensionShowWindow.MainWinForm.Enabled = true; } } } }