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

79 lines
2.8 KiB

using KGIS.Framework.Commands;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using System;
using System.IO;
using KUI.Windows;
using KGIS.Framework.Maps;
namespace Kingo.Plugin.DTBJK.Commands
{
public class CmdCopySLDB : BaseMenuCommand
{
private ProjectInfo ProtInfo => MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
public override void OnClick()
{
try
{
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog
{
Title = "选择外业DB文件",
Filter = "外业成果文件(*.*)|*.*",
RestoreDirectory = true,
Multiselect = false
};
//打开文件对话框选择的文件
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
this.ShowLoading("正在设置DB矢量........", 0, 0);
if (!Directory.Exists(Path.Combine(ProtInfo.ProjDir, "SLDB")))
{
Directory.CreateDirectory(Path.Combine(ProtInfo.ProjDir, "SLDB"));
}
PluginServiceInterface.CommonHelper.DelectDir(Path.Combine(ProtInfo.ProjDir, "SLDB"));
string DBName = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 9);
if (ProtInfo != null && openFileDialog.FileName.Contains(".db"))
File.Copy(openFileDialog.FileName, Path.Combine(ProtInfo.ProjDir, "SLDB", $"SLDB{DBName}.db"));
this.CloseLoading();
MessageHelper.ShowTips("设置成功!");
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug("设置矢量DB失败:" + ex.Message);
MessageHelper.ShowTips("设置矢量DB失败:" + ex.Message);
}
finally
{
this.CloseLoading();
}
}
public override void OnCreate(object Hook)
{
}
public override bool Enabled => JudgeIsHaveTargetPath();
private bool JudgeIsHaveTargetPath()
{
try
{
if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo ProtInfo))
{
return false;
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug("判定 检测数据加载 按钮是否有效时失败,异常原因: " + ex + " ; ");
return false;
}
}
}
}