using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using KGIS.Framework.DBOperator; using KGIS.Framework.Maps; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Helper; using KGIS.Framework.Views; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Model; using System; using System.Data; using System.Windows.Controls; namespace Kingo.Plugin.General.View { /// /// UCWYInfo.xaml 的交互逻辑 /// public partial class UC_DTB_WYSketch : UserControl, IElementInfo { private IHookHelper hookHelper { get; set; } private NYYSInfo NYYSInfo { get; set; } private TaskPackage taskPackage { get; set; } private DataTable Data { get; set; } public UC_DTB_WYSketch() { InitializeComponent(); Title = "外业草图_单图斑"; DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray); NYYSInfo = new NYYSInfo(); this.DataContext = NYYSInfo; this.Loaded += (s, e) => { hookHelper = new HookHelperClass(); hookHelper.Hook = MapsManager.Instance.MapService.Hook; }; } public bool IsShow { get; set; } public int ShowIndex { get; set; } public bool ResetSize { get; set; } public bool AllowEdit { get; set; } public Guid ID { get; set; } public DockStyle DockAreas { get; set; } public System.Drawing.Size FloatSize { get; set; } public int DockWidth { get; set; } public int DockHeight { get; set; } public DockStyle DefaultArea { get; set; } public bool ShowCloseButton { get; set; } public bool ShowAutoHideButton { get; set; } public string Title { get; set; } private void LoadData(IWorkspace workspace, string tableName) { ICursor cursor = null; ITable table = null; try { table = (workspace as IFeatureWorkspace).OpenTable(tableName); if (Data == null) { Data = new DataTable(); ConstructColumn(table.Fields); } IQueryFilter queryFilter = new QueryFilterClass() { WhereClause = $"TBBSM='{this.NYYSInfo.WYRWTB.TBBSM }' and BID='{this.taskPackage.BID}'" }; cursor = table.Search(queryFilter, true); IRow row = null; while ((row = cursor.NextRow()) != null) { DataRow dr = Data.NewRow(); for (int i = 0; i < Data.Columns.Count; i++) { object obj = row.get_Value((int)Data.Columns[i].ExtendedProperties["index"]); if (obj == null) { continue; } else { if ((obj.ToString()).Contains("1899/12/30 0:00:00")) { obj = System.DBNull.Value; } } if (obj is string) obj = obj.ToString().Trim(); dr[i] = obj; } Data.Rows.Add(dr); System.Runtime.InteropServices.Marshal.ReleaseComObject(row); } } catch (Exception ex) { LogAPI.Debug("加载" + tableName + "数据异常:" + ex.Message); MessageHelper.ShowError("加载" + tableName + "数据异常:" + ex.Message); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); } } } 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().EndsWith("SHAPE")) 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); System.Runtime.InteropServices.Marshal.ReleaseComObject(field); } } } public void BindData(object obj) { IRDBHelper rdbHelper = null; try { NYYSInfo nYYSInfo = obj as NYYSInfo; if (nYYSInfo == null) { this.dgWYSketch.ItemsSource = null; return; } this.NYYSInfo = nYYSInfo; this.taskPackage = nYYSInfo.TaskPackages; if (taskPackage == null || taskPackage.PackageTempPath == null || !System.IO.File.Exists(taskPackage.PackageTempPath)) return; rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); DataTable dataTable1 = rdbHelper.ExecuteDatatable("label", $"select (case when type=0 then '点' when type=1 then '线' else '面' end) as BZLX,bz,cast(createtime as text) as createtime,cast(userid as text) as userid,shape,ATTACHMENT,{NYYSInfo.WYRWTB.ObjectID} ObjectID from label where tbbsm='{NYYSInfo.WYRWTB.TBBSM}'", true); dgWYSketch.ItemsSource = null; if (dataTable1 != null) { this.dgWYSketch.ItemsSource = dataTable1.DefaultView; } } catch (Exception ex) { throw ex; } finally { if (rdbHelper != null) rdbHelper.DisConnect(); } } public void SaveEdit() { return; } } }