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.
307 lines
13 KiB
307 lines
13 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using ExcelDataReader; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Views; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.IO; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Input; |
|
|
|
namespace Kingo.Plugin.General.View |
|
{ |
|
/// <summary> |
|
/// UCFeedbackTable.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCFeedbackTable : UserControl, IDockPanel2 |
|
{ |
|
private IHookHelper m_hookHelper = null; |
|
|
|
List<Dictionary<string, string>> FieldsTempData = new List<Dictionary<string, string>>(); |
|
public UCFeedbackTable(string title, IHookHelper _hookHelper = null) |
|
{ |
|
InitializeComponent(); |
|
|
|
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray); |
|
m_hookHelper = _hookHelper; |
|
|
|
this.DockAreas = DockStyle.DockBottom | DockStyle.Float; |
|
this.FloatSize = new System.Drawing.Size(600, 400); |
|
this.DefaultArea = DockStyle.DockBottom; |
|
this.ShowCloseButton = true; |
|
this.ShowAutoHideButton = true; |
|
this.Title = title; |
|
this.IsShowInMap = true; |
|
this.DockHeight = 350; |
|
} |
|
|
|
private void BtnImportData_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
string excelfilePath = string.Empty; |
|
KGIS.Framework.Utils.Dialog.OpenFileDialog openFileDialog = new KGIS.Framework.Utils.Dialog.OpenFileDialog(); |
|
openFileDialog.Title = "导入反馈表EXCEL"; |
|
openFileDialog.Filter = "Excel Files(*.xlsx)| *.xlsx"; |
|
openFileDialog.FileName = string.Empty; |
|
openFileDialog.FilterIndex = 1; |
|
if (openFileDialog.ShowDialog()) |
|
{ |
|
excelfilePath = openFileDialog.FileName; |
|
if (FileIsUsed(excelfilePath)) |
|
{ |
|
MessageHelper.ShowWarning("文件被占用,请关闭占用文件的相关程序,或者选择其他文件!"); |
|
return; |
|
} |
|
using (var streamData = File.Open(excelfilePath, FileMode.Open, FileAccess.Read)) |
|
{ |
|
using (var readerData = ExcelReaderFactory.CreateReader(streamData)) |
|
{ |
|
var result = readerData.AsDataSet(); |
|
DataTable tempDT = result.Tables[0]; |
|
for (int i = 0; i < tempDT.Rows.Count; i++) |
|
{ |
|
if (string.IsNullOrWhiteSpace(tempDT.Rows[0][0].ToString())) |
|
tempDT.Rows.RemoveAt(0);//清除空白行的情况 |
|
else if (tempDT.Rows[0][0].ToString().ToUpper().Equals("OBJECTID")) |
|
break; |
|
} |
|
|
|
int dlbm = -1; |
|
int bsm = -1; |
|
|
|
DataTable feedbackDT = new DataTable(System.IO.Path.GetFileNameWithoutExtension(excelfilePath)); |
|
if (tempDT.Rows.Count <= 0) return; |
|
for (int i = 0; i < tempDT.Columns.Count; i++) |
|
{ |
|
string ColuName = tempDT.Rows[0][i].ToString(); |
|
if (tempDT.Rows[0][i].ToString() == "标识码") bsm = i; |
|
else if (tempDT.Rows[0][i].ToString() == "地类编码") dlbm = i; |
|
if (feedbackDT.Columns.IndexOf(tempDT.Rows[0][i].ToString()) == -1) |
|
feedbackDT.Columns.Add(tempDT.Rows[0][i].ToString()); |
|
} |
|
for (int i = 1; i < tempDT.Rows.Count; i++)//跳过标题与列头 |
|
{ |
|
if (dlbm != -1 && bsm != -1 && tempDT.Rows[i][dlbm].ToString().Contains("/") && tempDT.Rows[i][bsm].ToString().Contains("/")) |
|
{ |
|
string[] dibms = tempDT.Rows[i][dlbm].ToString().Split('/'); |
|
for (int k = 0; k < dibms.Length; k++) |
|
{ |
|
DataRow dataRow = feedbackDT.NewRow(); |
|
for (int m = 0; m < tempDT.Columns.Count; m++) |
|
{ |
|
if (!string.IsNullOrEmpty(tempDT.Rows[i][m].ToString()) && tempDT.Rows[i][m].ToString().Contains("/")) |
|
dataRow[m] = tempDT.Rows[i][m].ToString().Split('/')[k]; |
|
else |
|
dataRow[m] = tempDT.Rows[i][m].ToString(); |
|
} |
|
feedbackDT.Rows.Add(dataRow); |
|
} |
|
} |
|
else |
|
{ |
|
DataRow dataRow = feedbackDT.NewRow(); |
|
for (int m = 0; m < tempDT.Columns.Count; m++) |
|
{ |
|
dataRow[m] = tempDT.Rows[i][m].ToString(); |
|
} |
|
feedbackDT.Rows.Add(dataRow); |
|
} |
|
} |
|
this.dgData.ItemsSource = feedbackDT; |
|
} |
|
} |
|
|
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("导入反馈表异常:" + ex.Message); |
|
LogAPI.Debug("导入反馈表异常:" + ex.StackTrace); |
|
MessageHelper.ShowError("导入反馈表异常:" + ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 返回指示文件是否已被其它程序使用的布尔值 |
|
/// </summary> |
|
public Boolean FileIsUsed(string fileFullName) |
|
{ |
|
Boolean result = false; |
|
//判断文件是否存在,如果不存在,直接返回 false |
|
if (!System.IO.File.Exists(fileFullName)) |
|
{ |
|
result = false; |
|
} |
|
else |
|
{ |
|
//如果文件存在,则继续判断文件是否已被其它程序使用 |
|
//逻辑:尝试执行打开文件的操作,如果文件已经被其它程序使用,则打开失败,抛出异常,根据此类异常可以判断文件是否已被其它程序使用。 |
|
FileStream fileStream = null; |
|
try |
|
{ |
|
fileStream = File.Open(fileFullName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); |
|
result = false; |
|
} |
|
catch (IOException) |
|
{ |
|
result = true; |
|
} |
|
catch (Exception) |
|
{ |
|
result = true; |
|
} |
|
finally |
|
{ |
|
if (fileStream != null) |
|
{ |
|
fileStream.Close(); |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
//双击定位 |
|
private void DgData_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
|
{ |
|
//IFeatureLayer DtbFeatureLayer = null; |
|
IFeatureCursor cursor = null; |
|
IFeature feature = null; |
|
try |
|
{ |
|
DevExpress.Xpf.Grid.GridControl rowq = sender as DevExpress.Xpf.Grid.GridControl; |
|
if (rowq == null || rowq.CurrentItem == null) return; |
|
DataRowView dataRowView = rowq.CurrentItem as DataRowView; |
|
if (dataRowView == null) return; |
|
string bsm = dataRowView["标识码"].ToString(); |
|
if (string.IsNullOrEmpty(bsm)) return; |
|
IQueryFilter queryFilter = new QueryFilterClass() |
|
{ |
|
WhereClause = $"TBBSM='{bsm}'" |
|
}; |
|
//DtbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); |
|
//if (DtbFeatureLayer == null) return; |
|
//cursor = DtbFeatureLayer.FeatureClass.Search(queryFilter, false); |
|
//while ((feature = cursor.NextFeature()) != null) |
|
//{ |
|
// isFind = true; |
|
// MapsManager.Instance.MapService.SelectFeature("DLTBBG", feature.OID.ToString(), true); |
|
// Location(feature); |
|
// break; |
|
//} |
|
List<IFeatureLayer> featureLayers = MapsManager.Instance.MapService.GetAllVisibleLayerInMap<IFeatureLayer>(); |
|
bool isFind = false; |
|
foreach (IFeatureLayer featureLayer in featureLayers) |
|
{ |
|
if (featureLayer == null || featureLayer.FeatureClass == null || (featureLayer.FeatureClass.Fields.FindField("TBBSM") < 0 && featureLayer.FeatureClass.Fields.FindField("BSM") < 0)) continue; |
|
|
|
if (featureLayer.FeatureClass.Fields.FindField("TBBSM") > -1) queryFilter.WhereClause = $"TBBSM='{bsm}'"; |
|
else if (featureLayer.FeatureClass.Fields.FindField("BSM") > -1) queryFilter.WhereClause = $"BSM='{bsm}'"; |
|
|
|
cursor = featureLayer.FeatureClass.Search(queryFilter, false); |
|
while ((feature = cursor.NextFeature()) != null) |
|
{ |
|
isFind = true; |
|
MapsManager.Instance.MapService.SelectFeature(featureLayer.Name, feature.OID.ToString(), true); |
|
Location(feature); |
|
break; |
|
} |
|
|
|
if (isFind) break; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("反馈表定位异常:" + ex.Message); |
|
LogAPI.Debug("反馈表定位异常:" + ex.StackTrace); |
|
} |
|
finally |
|
{ |
|
//if(DtbFeatureLayer != null) |
|
// System.Runtime.InteropServices.Marshal.ReleaseComObject(DtbFeatureLayer); |
|
if (cursor != null) |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); |
|
if (feature != null) |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); |
|
|
|
} |
|
} |
|
|
|
private void Location(IFeature feature) |
|
{ |
|
IPointCollection poly2 = new PolygonClass(); |
|
IGeometry tempgeometry = null; |
|
try |
|
{ |
|
MapsManager.Instance.MapService.ClearFeatureSelection(this.m_hookHelper.Hook as IMapControlDefault); |
|
if (feature.ShapeCopy != null) |
|
{ |
|
IGeometry geometry = feature.ShapeCopy; |
|
geometry.Project(this.m_hookHelper.FocusMap.SpatialReference); |
|
MapsManager.Instance.MapService.DrawGraph(geometry, true); |
|
MapsManager.Instance.MapService.Zoom(geometry); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(poly2); |
|
if (tempgeometry != null) |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(tempgeometry); |
|
} |
|
} |
|
|
|
#region 接口属性 |
|
public bool IsShowInMap { 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; } |
|
|
|
public event EventHandler CloseViewHandler; |
|
|
|
public void ClosePanel() |
|
{ |
|
Platform.Instance.CloseView(this); |
|
} |
|
|
|
public void ClosePanelInvoke() |
|
{ |
|
CloseViewHandler?.Invoke(this, null); |
|
} |
|
|
|
public void ShowPanel() |
|
{ |
|
Platform.Instance.OpenView(this, false); |
|
if (MapsManager.Instance.MapService != null) |
|
{ |
|
MapsManager.Instance.MapService.ProjectClosed += (sender, e) => |
|
{ |
|
ClosePanel(); |
|
}; |
|
} |
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|
|
|
}
|
|
|