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.
403 lines
17 KiB
403 lines
17 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ExcelDataReader; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.OpenData.Control; |
|
using KGIS.Framework.OpenData.Filter; |
|
using KGIS.Framework.OpenData.InterFace; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Dialog; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Collections.ObjectModel; |
|
using System.Data; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Input; |
|
using UIShell.OSGi; |
|
using KGIS.Framework.Utils.Helper; |
|
using KUI.Windows; |
|
using Kingo.PluginServiceInterface.Model; |
|
using KGIS.Framework.Maps; |
|
using System.Xml.Linq; |
|
|
|
namespace Kingo.Plugin.YJJK.View |
|
{ |
|
/// <summary> |
|
/// 一键建库 的交互逻辑 |
|
/// </summary> |
|
public partial class UnifiedBuildDataBase : BaseWindow |
|
{ |
|
/// <summary> |
|
/// 地类图斑数据提取-选择范围-图层 |
|
/// </summary> |
|
private IFeatureLayer SelLocation_Layer = null; |
|
|
|
/// <summary> |
|
/// 字典集合 |
|
/// </summary> |
|
List<DataDicTionary> Dics = null; |
|
/// <summary> |
|
/// 权属字典 |
|
/// </summary> |
|
List<DataDicTionary> Dics_QS = null; |
|
|
|
/// <summary> |
|
/// 建库函数接口 |
|
/// </summary> |
|
public List<IDataChange> dataChanges = null; |
|
public DataChangeParameter pParm = null; |
|
public ObservableCollection<ZLXXInfo> ListZLXXInfo = null; |
|
public IDataChange dataChange_DLTB = null; |
|
public IDataChange dataChange_XZQ = null; |
|
public IDataChange dataChange_CZC = null; |
|
public IDataChange dataChange_Attr = null; |
|
public IDataChange dataChange_ZLHZ = null; |
|
|
|
public UnifiedBuildDataBase() |
|
{ |
|
InitializeComponent(); |
|
//if (pParm == null) |
|
// pParm = new DataChangeParameter(); |
|
Dics = Platform.Instance.DicHelper.GetAllDic(); |
|
//避免二次加载字典-50 |
|
Dics_QS = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM, Dics);// Dics.Where(x => (x.OWNERDIC == "1" || Convert.ToInt32(x.OWNERDIC) >= 50) && x.CODE.Length >= 19).ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList(); |
|
|
|
//ListZLXXInfo = new ObservableCollection<ZLXXInfo>(); |
|
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
ListZLXXInfo = prj.ListZLXXInfo; |
|
gvCtrl.ItemsSource = ListZLXXInfo; |
|
} |
|
|
|
/// <summary> |
|
/// 地类图斑数据提取-选择范围 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnSelTB_Click(object sender, RoutedEventArgs e) |
|
{ |
|
string xzdltbPaths = ""; |
|
IFeatureClass dltbFc = GetFeatureClass("请选择新增的地类图斑数据", ref xzdltbPaths); |
|
if (dltbFc != null) |
|
{ |
|
//btnNewData.Text = xzdltbPaths; |
|
SelLocation_Layer = GeoDBAPI.CreateFeatureLayerInmemeory("SelLocation", "选择范围图斑数据", (dltbFc as IGeoDataset).SpatialReference, dltbFc.ShapeType, dltbFc.Fields); |
|
(SelLocation_Layer.FeatureClass as ITable).DeleteSearchedRows(null); |
|
InsertDataToMemeoryLayer(dltbFc, SelLocation_Layer.FeatureClass, null); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 地类图斑数据提取-打开文件 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnOpenFile_Click(object sender, RoutedEventArgs e) |
|
{ |
|
string filePath = string.Empty; |
|
OpenFileDialog dialog = new OpenFileDialog(); |
|
dialog.DefaultExt = "xls"; |
|
dialog.Filter = "Excel文件|*.xls;*.xlsx"; |
|
if (dialog.ShowDialog()) |
|
{ |
|
filePath = dialog.FileName; |
|
using (var streamData = File.Open(filePath, FileMode.Open, FileAccess.Read)) |
|
{ |
|
using (var readerData = ExcelReaderFactory.CreateReader(streamData)) |
|
{ |
|
var result = readerData.AsDataSet(); |
|
DataTable tempDT = result.Tables[0]; |
|
tempDT.Columns[0].ColumnName = "变更前代码"; |
|
tempDT.Columns[1].ColumnName = "变更前名称"; |
|
tempDT.Columns[2].ColumnName = "变更后代码"; |
|
tempDT.Columns[3].ColumnName = "变更后名称"; |
|
tempDT.Rows.RemoveAt(0); |
|
if (tempDT != null && tempDT.Rows.Count > 0) |
|
{ |
|
var Index = -1; |
|
foreach (DataRow row in tempDT.Rows) |
|
{ |
|
var QS = Dics_QS.Where(x => x.CODE == row["变更后代码"].ToString()).FirstOrDefault(); |
|
if (QS != null) |
|
Index = Dics_QS.IndexOf(QS); |
|
if (Index > 0) |
|
ListZLXXInfo.Add(new Kingo.PluginServiceInterface.ZLXXInfo() |
|
{ |
|
ID = ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault() == null ? 0 : ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault().ID + 1, |
|
BGQDM = row["变更前代码"].ToString(), |
|
BGQMC = row["变更前名称"].ToString(), |
|
BGHDM = row["变更后代码"].ToString(), |
|
BGHMC = row["变更后名称"].ToString(), |
|
Data = Dics_QS, |
|
DataDicTionary = QS |
|
}); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 地类图斑数据提取-添 加 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void Txt_Add_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
|
{ |
|
ListZLXXInfo.Add(new ZLXXInfo() |
|
{ |
|
ID = ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault() == null ? 0 : ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault().ID + 1, |
|
Data = Dics_QS, |
|
}); |
|
//gvCtrl.ItemsSource = pParm.ListZLXXInfo; |
|
} |
|
|
|
/// <summary> |
|
/// 地类图斑数据提取-右键删除 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void Txt_Delete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
try |
|
{ |
|
var TextBlock = sender as TextBlock; |
|
if (TextBlock != null) |
|
{ |
|
ZLXXInfo Info = ListZLXXInfo.FirstOrDefault(f => f.ID == TextBlock.Tag.ToInt()); |
|
ListZLXXInfo.Remove(Info); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("删除坐落信息失败:" + ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 地类图斑数据提取-选择改变事件 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
KUI.ComboBox.AutoCompleteBox sender1 = sender as KUI.ComboBox.AutoCompleteBox; |
|
if (sender1 != null && !string.IsNullOrEmpty(sender1.Text) && sender1.Text.Contains("-")) |
|
{ |
|
var Default = ListZLXXInfo.Where(x => x.ID == sender1.Tag.ToInt()).FirstOrDefault(); |
|
if (Default != null) |
|
{ |
|
Default.BGHMC = sender1.Text.Split('-')[1]; |
|
Default.BGHDM = sender1.Text.Split('-')[0]; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("ComboBox_SelectionChanged失败:" + ex.Message.ToString()); |
|
} |
|
} |
|
|
|
private void BtnOK_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
btnOK.IsEnabled = false; |
|
btnCancel.IsEnabled = false; |
|
ProjectInfo projInfo = MapsManager.Instance.CurrProjectInfo as ProjectInfo; |
|
if (projInfo == null) |
|
return; |
|
IFeatureLayer jcDLTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑"); |
|
if (jcDLTBLayer == null) |
|
{ |
|
MessageHelper.Show("未找到基础库地类图斑图层"); |
|
return; |
|
} |
|
//Dictionary<string, decimal> _kcxsDic = new Dictionary<string, decimal>();//《字符串-数字》字典集合 |
|
//string strPath = SysAppPath.GetBGGDLXConfigPath();//获取配置文件路径 |
|
//XDocument xDoc = XDocument.Load(strPath); |
|
//foreach (XElement xElement in xDoc.Descendants("Item")) |
|
//{ |
|
// string gdlx = xElement.Attributes("GDLX").Single().Value; |
|
// string gdpdjb = xElement.Attributes("GDPDJB").Single().Value; |
|
// string strKcdlxs = xElement.Attributes("KCDLXS").Single().Value; |
|
// decimal kcdlxs = Convert.ToDecimal(xElement.Attributes("KCDLXS").Single().Value == "" ? "0" : xElement.Attributes("KCDLXS").Single().Value); |
|
// string key = string.Format("{0}-{1}", gdlx, gdpdjb); |
|
// _kcxsDic.Add(key, kcdlxs); |
|
//} |
|
|
|
this.ShowLoading("正在生成增量数据……", 0, 0); |
|
IDGParameter _Parm = new IDGParameter(); |
|
//_Parm.ProjDir = projInfo.ProjDir; |
|
//_Parm.XZQDM = projInfo.CODE; |
|
//_Parm.BgDbPath = Path.Combine(projInfo.ProjDir, "BGDB" + ".gdb"); |
|
//_Parm.ZLDbPath = Path.Combine(projInfo.ProjDir, "ZLDB" + ".gdb"); |
|
//_Parm.NmDbPath = Path.Combine(projInfo.ProjDir, "NMDB" + ".gdb"); |
|
//_Parm.JcDbPath = (jcDLTBLayer.FeatureClass as FeatureClass).Workspace.PathName; |
|
//_Parm.PrjInfo = MapsManager.Instance.CurrProjectInfo as ProjectInfo; |
|
ProjectInfo prjInfo = MapsManager.Instance.CurrProjectInfo as ProjectInfo; |
|
_Parm.StrProjInfo = Path.Combine(prjInfo.ProjDir, prjInfo.ProjName + prjInfo.ProjSuffix); |
|
_Parm.ExeDLTB = CheckBox_DLTB.IsChecked == true; |
|
_Parm.ExeCJDCQ = CheckBox_CJDCQ.IsChecked == true; |
|
_Parm.ExeXZQ = CheckBox_XZQ.IsChecked == true; |
|
_Parm.ExeCZC = CheckBox_CZCData.IsChecked == true; |
|
_Parm.ExeZLHZ = CheckBox_ZLHZ.IsChecked == true; |
|
_Parm.ExeGDDB = false; |
|
//_Parm.ListZLXXInfo = ListZLXXInfo; |
|
//_Parm.KCXSDic = _kcxsDic; |
|
//_Parm.ListZLXXInfo[0].Data = null; |
|
//_Parm.ListZLXXInfo[1].Data = null; |
|
|
|
|
|
ProcesHelper.Instance.ProgressHandle = (o) => |
|
{ |
|
this.UpdateMsg(o.ToString()); |
|
}; |
|
string result = ProcesHelper.Instance.ExeGPForProces(_Parm); |
|
if (result.Contains("Err")) |
|
{ |
|
MessageHelper.ShowTips("一键建库 执行失败,失败信息请查看系统日志!"); |
|
} |
|
else |
|
{ |
|
MessageHelper.ShowTips("一键建库 执行成功!"); |
|
} |
|
|
|
//if (dataChanges == null || dataChanges.Count == 0) |
|
// dataChanges = BundleRuntime.Instance.GetService<IDataChange>(); |
|
//if (dataChanges == null || dataChanges.Count == 0) return; |
|
//this.ShowLoading("正在进行增量数据提取,请稍后……", 0, 0); |
|
////增量数据提取 |
|
//dataChange_DLTB = dataChanges.FirstOrDefault(x => x.IDataChangeName == "DLTB_IDGHelper"); |
|
//if (dataChange_DLTB != null && CheckBox_DLTB.IsChecked == true) |
|
//{ |
|
// dataChange_DLTB.ExecuteDataChange(pParm); |
|
//} |
|
////行政区提取 |
|
//dataChange_XZQ = dataChanges.FirstOrDefault(x => x.IDataChangeName == "XZQ_IDGHelper"); |
|
//if (dataChange_XZQ != null && (CheckBox_GDDB.IsChecked == true || CheckBox_CJDCQ.IsChecked == true || CheckBox_XZQ.IsChecked == true)) |
|
//{ |
|
// pParm.Check_gddb = CheckBox_GDDB.IsChecked == true; |
|
// pParm.Check_cjdcq = CheckBox_CJDCQ.IsChecked == true; |
|
// pParm.Check_xzq = CheckBox_XZQ.IsChecked == true; |
|
// dataChange_XZQ.ExecuteDataChange(pParm); |
|
//} |
|
////城镇村提取 |
|
//dataChange_CZC = dataChanges.FirstOrDefault(x => x.IDataChangeName == "CZCDYDHelper"); |
|
//if (dataChange_CZC != null && CheckBox_CZCData.IsChecked == true) |
|
//{ |
|
// dataChange_CZC.ExecuteDataChange(null); |
|
//} |
|
////属性维护 |
|
//dataChange_Attr = dataChanges.FirstOrDefault(x => x.IDataChangeName == "SXWHHelper"); |
|
//if (dataChange_Attr != null && CheckBox_SXWH.IsChecked == true) |
|
//{ |
|
// dataChange_Attr.ExecuteDataChange(null); |
|
//} |
|
////增量汇总 |
|
//dataChange_ZLHZ = dataChanges.FirstOrDefault(x => x.IDataChangeName == "ZLHZHelper"); |
|
//if (dataChange_ZLHZ != null && CheckBox_ZLHZ.IsChecked == true) |
|
//{ |
|
// dataChange_ZLHZ.ExecuteDataChange(null); |
|
//} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
finally |
|
{ |
|
btnOK.IsEnabled = true; |
|
btnCancel.IsEnabled = true; |
|
this.CloseLoading(); |
|
} |
|
} |
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
#region Common Methods |
|
/// <summary> |
|
/// 插入数据 |
|
/// </summary> |
|
/// <param name="pSource">数据源</param> |
|
/// <param name="pTarget">目标要素类</param> |
|
/// <param name="pFilter">过滤条件</param> |
|
private void InsertDataToMemeoryLayer(IFeatureClass pSource, IFeatureClass pTarget, IQueryFilter pFilter = null) |
|
{ |
|
try |
|
{ |
|
if (pSource == null || pTarget == null) return; |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(pSource); |
|
if (pTarget != null) |
|
fcAPI.FcToFc(pTarget, pFilter, false); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("插入数据失败:"); |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 得到要素类集合 |
|
/// </summary> |
|
/// <param name="title"></param> |
|
/// <param name="paths">路径集合</param> |
|
public static IFeatureClass GetFeatureClass(string title, ref string paths) |
|
{ |
|
IFeatureClass result = null; |
|
try |
|
{ |
|
// 获取源数据 |
|
OpenDataDialog pDialog = new OpenDataDialog(); |
|
ISpatialDataObjectFilter pOFilter; |
|
pOFilter = new FilterFeatureDatasetsAndFeatureClasses(); |
|
pDialog.AddFilter(pOFilter, true); |
|
if (!string.IsNullOrWhiteSpace(title)) |
|
pDialog.Title = title; |
|
else |
|
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 featureclass = (obj.DatasetName as IName).Open() as IFeatureClass; |
|
result = featureclass; |
|
paths += obj.FullName;//展示完整路径 |
|
//paths = featureclass.AliasName;//展示文件名 |
|
} |
|
} |
|
} |
|
return result; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("选择数据失败:" + ex.Message.ToString()); |
|
return result; |
|
} |
|
} |
|
#endregion |
|
|
|
#region Common Class |
|
|
|
#endregion |
|
} |
|
}
|
|
|