using DevExpress.Spreadsheet;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE;
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.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using Worksheet = DevExpress.Spreadsheet.Worksheet;
using KUI.Windows;
using System.Linq;
namespace Kingo.Plugin.DLTB_IDG.View
{
///
/// 核查记录挂接.xaml 的交互逻辑
///
public partial class HCRecordConnectionView : UserControl, IDockPanel2
{
///
/// 提取图斑视图数据
///
private DataTable IntoData { get; set; }
private IFeatureLayer DLTBBG_Layer_Temp = null;
private string BGBSMs = string.Empty;
private string excelPath = string.Empty;
private IFeatureLayer featureBGLayer = null;
Dictionary> fieldValueDict = null;
Dictionary keyValuePairs = null;
public HCRecordConnectionView()
{
InitializeComponent();
Title = "核查记录挂接";
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray);
DockAreas = DockStyle.DockRight | DockStyle.DockBottom | DockStyle.DockLeft;
FloatSize = new System.Drawing.Size(1030, 660);
DockWidth = 660;
DockHeight = 380;
DefaultArea = DockStyle.DockBottom;
ShowCloseButton = true;
ShowAutoHideButton = false;
IsShowInMap = true;
}
#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;
#endregion
///
/// 数据提取
///
///
///
private void BtnDataExtract_Click(object sender, RoutedEventArgs e)
{
try
{
excelPath = string.Empty; //@"E:\软件产品测试总目录\普陀区\浙江扣除系数问题\(330903)浙江省舟山市普陀区问题图斑核实记录表.xlsx";
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())
{
excelPath = openFileDialog.FileName;
}
if (featureBGLayer == null)
featureBGLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
if (featureBGLayer == null || string.IsNullOrWhiteSpace(excelPath)) return;
this.ShowLoading("正在进行核查记录挂接数据提取.........", 0, 0);
// 打开 Excel 文件
FileStream stream = new FileStream(excelPath, FileMode.Open);
Workbook workbook = new Workbook();
workbook.LoadDocument(stream, DocumentFormat.OpenXml);
Worksheet sheet = workbook.Worksheets[0];
// 获取 Excel 表格中的数据范围
Range usedRange = sheet.GetUsedRange();
int rowCount = usedRange.RowCount;
int columnCount = usedRange.ColumnCount;
// 获取 Excel 表格中的字段名和值
List fieldNames = new List();
fieldValueDict = new Dictionary>();
int indexValue = 1;
for (int i = 0; i < columnCount; i++)
{
string fieldName = sheet.Rows[indexValue][i].DisplayText.ToString();
while (i == 0 && fieldName != "省代码")
{
indexValue++;
fieldName = sheet.Rows[indexValue][i].DisplayText.ToString();
}
fieldNames.Add(fieldName);
}
for (int j = 2; j <= rowCount; j++)
{
string BSMValue = sheet.Rows[j][4].DisplayText.ToString();
if (string.IsNullOrWhiteSpace(BSMValue)) continue;
List