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; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kingo.Plugin.DTBZJ.Commands { public class CmdSetDTBZJPackpage : BaseMenuCommand { private IHookHelper m_hookHelper { get; set; } public override void OnClick() { if (AddPackpages(this.m_hookHelper)) { Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "LoadTreeData" }); } } 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); } } /// /// 添加任务包 /// /// public bool AddPackpages(IHookHelper hookHelper) { System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = null; try { if (!(MapsManager.Instance.CurrProjectInfo is ProjectInfo ProjectInfo) || 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; } string folderName = "审核任务目录(" + ProjectInfo.UserName + ")"; string basePath = Path.Combine(folderBrowserDialog.SelectedPath, folderName); if (Path.GetFileNameWithoutExtension(folderBrowserDialog.SelectedPath).Equals(folderName)) { basePath = folderBrowserDialog.SelectedPath; } if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } if (!string.IsNullOrWhiteSpace(ProjectInfo.TaskPath) && Directory.Exists(ProjectInfo.TaskPath) && ProjectInfo.TaskPath.Equals(basePath)) { return false; } List listFolders = new List() { "未完成", "已输出", "临时" }; DirectoryInfo directory = new DirectoryInfo(basePath); bool isFirstLoad = false; foreach (var item in listFolders) { if (directory.GetDirectories(item, SearchOption.TopDirectoryOnly).Length <= 0) { isFirstLoad = true; Directory.CreateDirectory(Path.Combine(basePath, item)); } } FileInfo[] files = null; if (isFirstLoad) { directory = new DirectoryInfo(folderBrowserDialog.SelectedPath); files = directory.GetFiles("*.shrw", SearchOption.TopDirectoryOnly); if (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("*.shrw", SearchOption.AllDirectories); if (files == null || files.Length <= 0) { MessageHelper.Show("所选目录中“未完成”文件夹中不存在“审核任务包”!"); } ProjectInfo.ListTaskPackage = new List(); ProjectInfo.TaskPath = basePath; ProjectInfo.Save(); return true; } catch (Exception ex) { LogAPI.Debug(ex); MessageHelper.ShowError(ex.Message); return false; } finally { if (folderBrowserDialog != null) { folderBrowserDialog.Dispose(); } } } /// /// 湖南地区需求 默认设置图片全选 /// /// 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; rdbHelper = RDBFactory.CreateDbHelper($"{item.FullName}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); rdbHelper.BeginTransaction(); if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK || Platform.Instance.SystemType == SystemTypeEnum.WYZS) { rdbHelper.ExecuteNonQueryWithException("update WYHCFJ set IS_SELECTED=1", CommandType.Text); } } } } if (rdbHelper != null) rdbHelper.Commit(); } catch (Exception ex) { rdbHelper.Rollback(); LogAPI.Debug("设置图片全选异常:" + ex); return; } finally { if (rdbHelper != null) rdbHelper.DisConnect(); } } } }