年度变更建库软件5.0版本
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.

136 lines
5.9 KiB

6 months ago
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using Kingo.Plugin.DTBJKLoadData.Model;
using Kingo.Plugin.DTBJKLoadData.View;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Kingo.Plugin.DTBJKLoadData
{
public class DTBJKLoadData_Default
{
#region 初始化数据加载界面
public virtual List<TableMapping> DTBJKInitialization(List<MatchingRegionMapping> mappings)
{
List<TableMapping> tableMappings = new List<TableMapping>();
try
{
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (mappings != null && mappings.Count > 0)
{
foreach (var item in mappings)
{
Type type = typeof(ProjectInfo);
PropertyInfo property = type.GetProperty(item.PropertyName);
object value = property.GetValue(projectInfo);
tableMappings.Add(new TableMapping() { S_TableAliasName = item.Name, S_TablePath = value.ToTrim() ?? "" });
}
}
}
catch (Exception ex)
{
LogAPI.Debug("DTBJKInitialization异常:" + ex.Message);
LogAPI.Debug("DTBJKInitialization异常:" + ex.StackTrace);
}
return tableMappings;
}
#endregion
#region 选择基础数据
private Dictionary<string, int> JCKFiles { get; set; }
public virtual List<TableMapping> btnSelectedBaseData_Click(UCLoadDTBJKData uCLoadDTBJKData)
{
if (uCLoadDTBJKData == null || uCLoadDTBJKData.tableMappings == null || uCLoadDTBJKData.tableMappings.Count == 0) return null;
List<TableMapping> tableMappings = uCLoadDTBJKData.tableMappings;
try
{
string JKInPath = string.Empty;
KGIS.Framework.Utils.Dialog.FolderBrowserDialog pBrowser = new KGIS.Framework.Utils.Dialog.FolderBrowserDialog
{
ShowNewFolderButton = true
};
if (pBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
JKInPath = pBrowser.SelectedPath;
if (string.IsNullOrWhiteSpace(JKInPath))
{
return tableMappings;
}
uCLoadDTBJKData.cobDataBase.Text = JKInPath;
}
else
{
return tableMappings;
}
JCKFiles = new Dictionary<string, int>();
tableMappings.ForEach(x => x.S_TablePath = "");
DirectoryInfo folder = new DirectoryInfo(JKInPath.Trim());
FileInfo[] finfoList = folder.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo fileInfo in finfoList)
{
if (fileInfo.Name.EndsWith(".shp", StringComparison.CurrentCultureIgnoreCase))
{
string diretoryPath = System.IO.Path.GetDirectoryName(fileInfo.FullName);
if (!JCKFiles.Keys.Contains(diretoryPath))
{
JCKFiles.Add(diretoryPath, 1);
}
}
else if (fileInfo.Name.EndsWith(".mdb", StringComparison.CurrentCultureIgnoreCase))
{
JCKFiles.Add(fileInfo.FullName, 2);
}
else
{
//获取文件的上级文件夹:对于gdb文件来说,上级文件夹是以.gdb结尾
string dirtoryPath = System.IO.Path.GetDirectoryName(fileInfo.FullName);
if (dirtoryPath.EndsWith(".gdb", StringComparison.CurrentCultureIgnoreCase) && !JCKFiles.ContainsKey(dirtoryPath))
{
JCKFiles.Add(dirtoryPath, 3);
}
}
}
TableMapping mapping = null;
foreach (var PathSouce in JCKFiles.Keys)
{
mapping = tableMappings.FirstOrDefault(x => PathSouce.Contains(x.S_TableAliasName));
if (mapping != null)
{
string[] subDirs = Directory.GetDirectories(folder.FullName);
if (mapping.S_TableAliasName == "参考影像目录")
{
mapping.S_TablePath = subDirs.FirstOrDefault(x => x.Contains("参考影像目录"));
}
else if (mapping.S_TableAliasName == "坡度图" && PathSouce.Contains("5级坡度图"))
{
mapping.S_TablePath = PathSouce;
mapping = tableMappings.FirstOrDefault(x => PathSouce.IndexOf(x.S_TableAliasName) != -1 && !x.S_TablePath.Contains("5级坡度图"));
if (mapping != null)
{
mapping.S_TablePath = PathSouce;
}
}
else
{
mapping.S_TablePath = PathSouce;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("btnSelectedBaseData_Click:" + ex.Message);
LogAPI.Debug("btnSelectedBaseData_Click:" + ex.StackTrace);
throw ex;
}
return tableMappings;
}
#endregion
}
}