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

222 lines
8.8 KiB

6 months ago
using ESRI.ArcGIS.Controls;
using KGIS.Framework.Commands;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
namespace Kingo.Plugin.DTBJK.Commands
{
/// <summary>
/// 设置单图斑建库任务包
/// </summary>
public class CmdSetDTBJKPackpage : BaseMenuCommand
{
private IHookHelper m_hookHelper { get; set; }
public override void OnClick()
{
try
{
if (AddPackpages(this.m_hookHelper))
{
Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "LoadTreeData" });
}
this.CloseLoading();
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
finally
{
this.CloseLoading();
}
}
public override void OnCreate(object Hook)
{
try
{
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = Hook;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
/// <summary>
/// 添加任务包
/// </summary>
/// <param name="hookHelper"></param>
public bool AddPackpages(IHookHelper hookHelper)
{
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = null;
try
{
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (string.IsNullOrWhiteSpace(projectInfo.JCKPath))
{
MessageHelper.Show("请先使用“基础数据加载”功能设置基础库数据!");
return false;
}
if (string.IsNullOrWhiteSpace(projectInfo.UserName))
{
MessageHelper.ShowTips("请先使用“用户信息设置”功能设置用户名!");
return false;
}
folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
if (!string.IsNullOrWhiteSpace(projectInfo.TaskPath) && Directory.Exists(projectInfo.TaskPath))
{
folderBrowserDialog.SelectedPath = Path.GetDirectoryName(projectInfo.TaskPath);
}
System.Windows.Forms.DialogResult dialogResult = folderBrowserDialog.ShowDialog();
if (dialogResult != System.Windows.Forms.DialogResult.OK)
{
return false;
}
this.ShowLoading("任务目录设置中.......", 0, 0);
string folderName = "建库任务目录(" + projectInfo.UserName + ")";
string basePath = Path.Combine(folderBrowserDialog.SelectedPath, folderName);
if (Path.GetFileNameWithoutExtension(folderBrowserDialog.SelectedPath).Equals(folderName))
{
basePath = folderBrowserDialog.SelectedPath;
}
else if (folderBrowserDialog.SelectedPath.Contains(folderName) && Path.GetFileNameWithoutExtension(folderBrowserDialog.SelectedPath).Equals("未完成"))
{
MessageHelper.ShowTips("请选择“建库任务目录(用户名)”目录文件夹!");
return false;
}
if (!string.IsNullOrWhiteSpace(projectInfo.TaskPath) && Directory.Exists(projectInfo.TaskPath) && projectInfo.TaskPath.Equals(basePath))
{
return false;
}
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
List<string> listFolders = new List<string>() { "未完成", "已输出", "临时" };
DirectoryInfo directory = new DirectoryInfo(basePath);
foreach (var item in listFolders)
{
if (directory.GetDirectories(item, SearchOption.TopDirectoryOnly).Length <= 0)
{
Directory.CreateDirectory(Path.Combine(basePath, item));
}
}
FileInfo[] files = null;
directory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
files = directory.GetFiles("*.jkrw", SearchOption.TopDirectoryOnly);
if (projectInfo.TaskPath != null && (files == null || files.Length <= 0))
{
directory = new DirectoryInfo(basePath);
if (directory.Exists && directory.GetFiles("*.*", SearchOption.AllDirectories).Length <= 0)
{
directory.Delete(true);
}
}
foreach (var item in files)
{
item.MoveTo(Path.Combine(basePath, "未完成", item.Name));
}
directory = new DirectoryInfo(Path.Combine(basePath, "未完成"));
files = directory.GetFiles("*.jkrw", SearchOption.AllDirectories);
if (files == null || files.Length <= 0)
{
MessageHelper.Show("所选目录“未完成”文件夹中不存在建库任务包!");
}
projectInfo.ListTaskPackage = new List<TaskPackage>();
projectInfo.TaskPath = basePath;//(建库任务目录(ProjUserName))
projectInfo.Save();
SetPictureChecked(basePath);
return true;
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug("CmdSetDTBJKPackpage.AddPackpages 异常:" + ex.Message);
LogAPI.Debug("CmdSetDTBJKPackpage.AddPackpages 异常:" + ex.StackTrace);
MessageHelper.ShowError(ex.Message);
return false;
}
finally
{
if (folderBrowserDialog != null)
{
folderBrowserDialog.Dispose();
}
this.CloseLoading();
}
}
/// <summary>
/// 湖南 新疆 地区需求 默认设置图片全选
/// </summary>
/// <param name="basePath"></param>
private static void SetPictureChecked(string basePath)
{
IRDBHelper rdbHelper = null;
try
{
DirectoryInfo directory = new DirectoryInfo(Path.Combine(basePath, "临时"));
DirectoryInfo[] fileinfo = directory.GetDirectories(); //返回目录中所有文件和子目录
foreach (DirectoryInfo i in fileinfo)
{
FileInfo[] files = i.GetFiles("*.jkrw", SearchOption.AllDirectories);
if (files != null && files.Length > 0)
{
foreach (FileInfo item in files)
{
if (item == null || string.IsNullOrWhiteSpace(item.FullName)) continue;
try
{
rdbHelper = RDBFactory.CreateDbHelper($"{item.FullName}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS)
{
rdbHelper.ExecuteNonQueryWithException("update WYHCFJ set IS_SELECTED=1 where IS_SELECTED is null or IS_SELECTED = '' or IS_SELECTED <> 1", CommandType.Text);
}
}
catch (Exception)
{
continue;
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("设置图片全选异常:" + ex);
return;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
public override bool Enabled
{
get
{
return (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo) == null ? false : true;
}
}
}
}