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

263 lines
10 KiB

4 months ago
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.YJJK.ModelEntity;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Kingo.Plugin.YJJK.View
{
/// <summary>
/// FrmResultsExportForBG.xaml 的交互逻辑
/// </summary>
public partial class ViewCGDC_CG : UserControl, IWizardFramework
{
public object Parameter
{
get;
set;
}
private string m_strDescription = "按照国家数据库提交规则,生成相应的增量成果数据包";
public string Description
{
get { return m_strDescription; }
set { m_strDescription = value; }
}
private string m_strCaption = "成果导出";
public string Caption
{
get { return m_strCaption; }
set { m_strCaption = value; }
}
private bool m_bIsFinalSuccess = false;
public bool IsFinalSuccess
{
get { return m_bIsFinalSuccess; }
set { m_bIsFinalSuccess = value; }
}
private bool m_IsSkip = false;
public bool IsSkip
{
get { return m_IsSkip; }
set { m_IsSkip = value; }
}
ExportBGViewModel exportBGViewModel = null;
public ViewCGDC_CG()
{
try
{
InitializeComponent();
if ((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjSuffix == ".KBG")
{
exportBGViewModel = new ExportBGViewModel();
DataContext = exportBGViewModel;
if (MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo project)
{
if (System.IO.Directory.Exists(project.BGResultPath))
{
//PluginServiceInterface.CommonHelper.DelectDir(project.BGResultPath);
exportBGViewModel.OutDir = project.BGResultPath;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("一键成果导出 异常: " + ex + " ; ");
}
}
private void btnSelectDir_Click(object sender, RoutedEventArgs e)
{
try
{
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
folderBrowserDialog.Description = "请选择文件夹路径";
folderBrowserDialog.ShowNewFolderButton = true;
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LastSelectedFolder) && System.IO.Directory.Exists(Properties.Settings.Default.LastSelectedFolder))
{
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastSelectedFolder;
}
else
{
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
}
if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
Properties.Settings.Default.LastSelectedFolder = folderBrowserDialog.SelectedPath.ToString();
Properties.Settings.Default.Save();
if (string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
{
return;
}
txtOutDir.Text = folderBrowserDialog.SelectedPath;
}
catch (System.Exception ex)
{
LogAPI.Debug("一键变更成果导出 期间 选择保存目录 时失败,异常原因: " + ex + " ; ");
}
}
private void btnSelectNCData_Click(object sender, RoutedEventArgs e)
{
try
{
MessageHelper.ShowTips("请选择基础数据汇总表格,如:.../基础数据包/汇总表格");
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
folderBrowserDialog.Description = "请选择文件夹路径";
folderBrowserDialog.ShowNewFolderButton = true;
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.LastSelectedFolder) && System.IO.Directory.Exists(Properties.Settings.Default.LastSelectedFolder))
{
folderBrowserDialog.SelectedPath = Properties.Settings.Default.LastSelectedFolder;
}
else
{
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
}
if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
Properties.Settings.Default.LastSelectedFolder = folderBrowserDialog.SelectedPath.ToString();
Properties.Settings.Default.Save();
if (string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
{
return;
}
txtNCData.Text = folderBrowserDialog.SelectedPath;
}
catch (System.Exception ex)
{
LogAPI.Debug("一键变更成果导出 期间 选择基础数据 时失败,异常原因: " + ex + " ; ");
}
}
public bool Execute()
{
try
{
if (exportBGViewModel.Items == null)
return false;
exportBGViewModel.ExcelToDataTable();
exportBGViewModel.OutDataRootDir = exportBGViewModel.Items[0].Name;
if (!string.IsNullOrEmpty(exportBGViewModel.OutDir))
{
string path = Path.Combine(exportBGViewModel.OutDir, DateTime.Now.ToString("yyyyMMddHHmmssfff"));
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
exportBGViewModel.OutDir = path;
}
exportBGViewModel.CreateCatalogDir(exportBGViewModel.Items);
if (exportBGViewModel.Items[0] != null && exportBGViewModel.Items[0].SubCatalog != null)
{
ResultsCatalog resultsCatalog = exportBGViewModel.Items[0].SubCatalog.FirstOrDefault(a => a.Name == "基础数据包");
if (resultsCatalog != null)
CopyBasePackage(resultsCatalog.Path);
}
}
catch (Exception ex)
{
LogAPI.Debug("导出失败:" + ex.Message);
return false;
}
return true;
}
private void CopyBasePackage(string basePackagePath)
{
try
{
if (string.IsNullOrEmpty(txtNCData.Text) || string.IsNullOrEmpty(exportBGViewModel.OutDir)) return;
//CopyFolder(txtNCData.Text, Path.Combine(exportBGViewModel.OutDir, basePackagePath, "汇总表格"));
CopyFolder(txtNCData.Text, Path.Combine(exportBGViewModel.OutDir, basePackagePath));
}
catch (Exception ex)
{
//LogAPI.Debug("复制汇总表格 异常:" + ex);
LogAPI.Debug("复制基础数据包 异常:" + ex);
}
}
private void CopyFolder(string sourceFolderPath, string destinationFolderPath)
{
if (!Directory.Exists(destinationFolderPath))
{
Directory.CreateDirectory(destinationFolderPath);
}
string[] files = Directory.GetFiles(sourceFolderPath);
foreach (string file in files)
{
string destinationFilePath = Path.Combine(destinationFolderPath, Path.GetFileName(file));
File.Copy(file, destinationFilePath, true);
}
string[] subFolders = Directory.GetDirectories(sourceFolderPath);
foreach (string subFolder in subFolders)
{
string destinationSubFolderPath = Path.Combine(destinationFolderPath, Path.GetFileName(subFolder));
CopyFolder(subFolder, destinationSubFolderPath);
}
}
public void Intializing(bool IsSkip = false)
{
if (IsSkip)
{
m_IsSkip = IsSkip;
if (Parameter is IDGParameter)
{
if ((Parameter as IDGParameter).ExtParam.Contains(this))
(Parameter as IDGParameter).ExtParam.Remove(this);
}
}
else
{
if (Parameter is IDGParameter)
{
if (!(Parameter as IDGParameter).ExtParam.Contains(this))
(Parameter as IDGParameter).ExtParam.Add(this);
}
}
}
public bool Validating()
{
try
{
if (string.IsNullOrWhiteSpace(txtOutDir.Text))
{
MessageHelper.ShowWarning("请选择输出目录!");
m_bIsFinalSuccess = false;
return m_bIsFinalSuccess;
}
if (string.IsNullOrWhiteSpace(txtNCData.Text))
{
if (MessageHelper.ShowYesNoAndTips("年初报表数据未选择,将不会生成报表数据,是否继续执行?") != System.Windows.Forms.DialogResult.Yes)
{
m_bIsFinalSuccess = false;
return m_bIsFinalSuccess;
}
}
m_bIsFinalSuccess = true;
}
catch (Exception ex)
{
LogAPI.Debug("一键变更成果导出 期间 选择基础数据 时失败,异常原因: " + ex + " ; ");
}
return m_bIsFinalSuccess;
}
public void Back()
{
}
}
}