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

341 lines
15 KiB

using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using EncryptionHelper = Kingo.PluginServiceInterface.EncryptionHelper;
namespace Kingo.Plugin.General.View
{
/// <summary>
/// UCDecompressionDB.xaml 的交互逻辑
/// </summary>
public partial class UCDecompressionDB : BaseWindow
{
private List<DBFile> ListFiles { get; set; }
public UCDecompressionDB()
{
InitializeComponent();
ListFiles = new List<DBFile>();
}
/// <summary>
/// 解压
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnDecompression_Click(object sender, RoutedEventArgs e)
{
try
{
if (ListFiles == null || ListFiles.Count <= 0)
{
MessageHelper.ShowTips("请添加需要解压的任务包!");
return;
}
if (gridPaths.SelectedItems == null || gridPaths.SelectedItems.Count <= 0)
{
MessageHelper.Show("请勾选需要解压的数据!");
return;
}
if (string.IsNullOrWhiteSpace(btnSavePath.Text))
{
MessageHelper.ShowTips("请选择保存路径!");
return;
}
ProjectInfo projectInfo = (MapsManager.Instance.CurrProjectInfo as ProjectInfo);
string dogKey = EncryptionHelper.GetDogKey(1, projectInfo.CODE);
if (string.IsNullOrWhiteSpace(dogKey))
{
MessageHelper.ShowTips("请插入加密狗!");
return;
}
this.ShowLoading("开始解压......", 0, 0);
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("开始解压......");
if (!System.IO.Directory.Exists(this.btnSavePath.Text))
{
System.IO.Directory.CreateDirectory(this.btnSavePath.Text);
}
//string tempPath = KGIS.Framework.Utils.SysAppPath.GetTempPath();
//try
//{
// System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(tempPath);
// directoryInfo.Delete(true);
// System.IO.Directory.CreateDirectory(tempPath);
//}
//catch
//{
//}
int wkid = -1;
if (projectInfo.GetCurentProjectedCoordinate() != null)
{
wkid = projectInfo.GetCurentProjectedCoordinate().FactoryCode;
}
if (wkid <= 0)
{
GaussCalculateLibrary.CoordinateReferenceMapping coordinateReferenceMapping = GaussCalculateLibrary.CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (projectInfo.ZYJD > x.MinX && projectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(projectInfo.ZYJD));
if (coordinateReferenceMapping != null)
{
wkid = coordinateReferenceMapping.WKID;
}
}
int i = 0;
foreach (DBFile item in gridPaths.SelectedItems)
{
try
{
i++;
this.UpdateMsg($"进度[{i}/{gridPaths.SelectedItems.Count}]" + System.IO.Path.GetFileName(item.FilePath) + "......");
//KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar($"进度[{i}/{gridPaths.SelectedItems.Count}]" + System.IO.Path.GetFileName(item.FilePath) + "......");
string fileNameWithExtension = System.IO.Path.GetFileName(item.FilePath);
string fileName = fileNameWithExtension.Substring(0, fileNameWithExtension.IndexOf("."));
string savePath = System.IO.Path.Combine(this.btnSavePath.Text, fileName + "_解压");
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
string saveGDB = System.IO.Path.Combine(savePath, fileName + ".gdb");
DecompressionDB decompressionDB = new DecompressionDB();
if (System.IO.Path.GetExtension(item.FilePath).Equals(".ysrw", StringComparison.CurrentCultureIgnoreCase) || System.IO.Path.GetExtension(item.FilePath).Equals(".jkrw", StringComparison.CurrentCultureIgnoreCase))
{
string tempDB = System.IO.Path.Combine(savePath, fileName + ".db");
System.IO.File.Copy(item.FilePath, tempDB, true);
decompressionDB.DBToGDB(tempDB, saveGDB, wkid, dogKey);
//将解压解密后的db包修改后缀,变为预审任务包或建库任务包
string tempTaskPackage = System.IO.Path.Combine(savePath, fileName + System.IO.Path.GetExtension(item.FilePath));
System.IO.File.Copy(tempDB, tempTaskPackage, true);
}
else
{
decompressionDB.BGFWToGDB(item.FilePath, saveGDB, dogKey, wkid);
}
}
catch (Exception ex)
{
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
MessageHelper.ShowError(item.FilePath + "解压失败:" + ex.Message);
}
}
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
if (MessageHelper.ShowYesNoAndTips("执行完成,是否查看结果?") == System.Windows.Forms.DialogResult.Yes)
{
System.Diagnostics.Process.Start("explorer.exe", this.btnSavePath.Text);
}
this.Close();
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug("解压异常:" + ex.Message);
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
MessageHelper.ShowError("解压异常:" + ex.Message);
}
finally
{
this.CloseLoading();
//KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
}
}
/// <summary>
/// 选择保存路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnSavePath_DefaultButtonClick(object sender, RoutedEventArgs e)
{
FolderBrowserDialog folderBrowserDialog = null;
try
{
folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowNewFolderButton = true;
DialogResult dialogResult = folderBrowserDialog.ShowDialog();
if (dialogResult != System.Windows.Forms.DialogResult.OK)
{
this.btnSavePath.Text = string.Empty;
return;
}
this.btnSavePath.Text = folderBrowserDialog.SelectedPath;
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug("选择保存路径异常:" + ex.Message);
KGIS.Framework.Utils.Helper.MessageHelper.ShowError("选择保存路径异常:" + ex.Message);
}
finally
{
if (folderBrowserDialog != null)
{
folderBrowserDialog.Dispose();
}
}
}
/// <summary>
/// 选择文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnSelectFolder_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog folderBrowserDialog = null;
try
{
folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowNewFolderButton = false;
ProjectInfo projectInfo = (MapsManager.Instance.CurrProjectInfo as ProjectInfo);
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.TaskPath))
{
folderBrowserDialog.SelectedPath = projectInfo.TaskPath;
}
if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(folderBrowserDialog.SelectedPath);
System.IO.FileInfo[] files = directoryInfo.GetFiles("*.ysrw", System.IO.SearchOption.AllDirectories);
foreach (var item in files)
{
if (ListFiles.FirstOrDefault(x => x.FilePath.Equals(item.FullName)) != null || System.IO.Path.GetDirectoryName(item.FullName).EndsWith("_work", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
ListFiles.Add(new DBFile() { FilePath = item.FullName });
}
files = directoryInfo.GetFiles("*.jkrw", System.IO.SearchOption.AllDirectories);
foreach (var item in files)
{
if (ListFiles.FirstOrDefault(x => x.FilePath.Equals(item.FullName)) != null || System.IO.Path.GetDirectoryName(item.FullName).EndsWith("_work", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
ListFiles.Add(new DBFile() { FilePath = item.FullName });
}
files = directoryInfo.GetFiles("*.bgfw", System.IO.SearchOption.AllDirectories);
foreach (var item in files)
{
if (ListFiles.FirstOrDefault(x => x.FilePath.Equals(item.FullName)) != null || System.IO.Path.GetDirectoryName(item.FullName).EndsWith("_work", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
ListFiles.Add(new DBFile() { FilePath = item.FullName });
}
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug("选择文件夹异常:" + ex.Message);
KGIS.Framework.Utils.Helper.MessageHelper.ShowError("选择文件夹异常:" + ex.Message);
}
finally
{
gridPaths.ItemsSource = null;
gridPaths.ItemsSource = ListFiles;
if (folderBrowserDialog != null)
{
folderBrowserDialog.Dispose();
}
}
}
/// <summary>
/// 选择文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnSelectFiles_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = null;
try
{
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "选择任务包文件";
openFileDialog.Filter = "预处理任务包(*.ysrw)|*.ysrw|单图斑建库任务包(*.jkrw)|*.jkrw|变更范围(*.bgfw)|*.bgfw";
ProjectInfo projectInfo = (MapsManager.Instance.CurrProjectInfo as ProjectInfo);
if (projectInfo != null && !string.IsNullOrWhiteSpace(projectInfo.TaskPath))
{
openFileDialog.InitialDirectory = projectInfo.TaskPath;
}
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
//打开文件对话框选择的文件
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
foreach (var item in openFileDialog.FileNames)
{
if (ListFiles.FirstOrDefault(x => x.FilePath.Equals(item)) != null)
{
continue;
}
ListFiles.Add(new DBFile() { FilePath = item });
}
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug("选择文件异常:" + ex.Message);
KGIS.Framework.Utils.Helper.MessageHelper.ShowError("选择文件异常:" + ex.Message);
}
finally
{
gridPaths.ItemsSource = null;
gridPaths.ItemsSource = ListFiles;
if (openFileDialog != null)
{
openFileDialog.Dispose();
}
}
}
private void BtnClear_Click(object sender, RoutedEventArgs e)
{
try
{
ListFiles.Clear();
gridPaths.ItemsSource = null;
gridPaths.ItemsSource = ListFiles;
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug(ex);
}
}
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
try
{
if (gridPaths.SelectedItems == null || gridPaths.SelectedItems.Count <= 0)
{
return;
}
foreach (var item in gridPaths.SelectedItems)
{
if (ListFiles.Contains(item))
{
ListFiles.Remove(item as DBFile);
}
}
gridPaths.ItemsSource = null;
gridPaths.ItemsSource = ListFiles;
}
catch (Exception ex)
{
KGIS.Framework.Utils.LogAPI.Debug(ex);
}
}
}
public class DBFile
{
public string FilePath { get; set; }
}
}