From 5692fde956c48d12d984ee18535e7470130cf109 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Wed, 3 Jun 2026 20:17:19 +0800 Subject: [PATCH] feat: rename export button, support multi-file import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename '导出选中路径' to '导出', move before '导出全部' - Import dialog: enable MultiSelect, loop through all selected files - Aggregate import results across files --- src/UI/WPF/ViewModels/PathEditingViewModel.cs | 116 +++++++++--------- src/UI/WPF/Views/PathEditingView.xaml | 8 +- 2 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index 7ab11c4..53f3dfd 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -5727,85 +5727,83 @@ namespace NavisworksTransport.UI.WPF.ViewModels Filter = "路径文件 (*.xml;*.json)|*.xml;*.json|XML文件 (*.xml)|*.xml|JSON文件 (*.json)|*.json|所有文件 (*.*)|*.*", FilterIndex = 1, CheckFileExists = true, - CheckPathExists = true + CheckPathExists = true, + Multiselect = true }; if (openFileDialog.ShowDialog() == true) { - var filePath = openFileDialog.FileName; - var extension = Path.GetExtension(filePath).ToLower(); + var filePaths = openFileDialog.FileNames; + int totalImported = 0; + int totalFailed = 0; - // 确定导入格式 - ExportFormat importFormat; - switch (extension) + foreach (var filePath in filePaths) { - case ".json": - importFormat = ExportFormat.Json; - break; - case ".csv": - importFormat = ExportFormat.Csv; - break; - default: - importFormat = ExportFormat.Xml; - break; - } + var extension = Path.GetExtension(filePath).ToLower(); - // 创建导入参数 - var importParameters = new ImportPathParameters - { - FilePath = filePath, - ImportFormat = importFormat, - MergeWithExisting = true, - CreateBackup = true, - DuplicateHandling = DuplicateNameHandling.Rename, - ValidateImportedData = true, - AutoSelectFirstRoute = true, - Description = $"导入路径文件: {Path.GetFileName(filePath)}" - }; - - // 创建并执行导入命令 - var importCommand = new ImportPathCommand(importParameters, _pathPlanningManager); - var result = await importCommand.ExecuteAsync(); - - if (result.IsSuccess) - { - // 更新UI状态 - RefreshPathRoutes(); - - // 如果需要自动选择第一个导入的路径,通过专门的选择逻辑处理 - if (importParameters.AutoSelectFirstRoute && PathRoutes.Count > 0) + ExportFormat importFormat; + switch (extension) { - var firstRoute = PathRoutes.FirstOrDefault(); - if (firstRoute != null) - { - SelectedPathRoute = firstRoute; - LogManager.Info($"导入完成后自动选择路径: {firstRoute.Name}"); - } + case ".json": + importFormat = ExportFormat.Json; + break; + case ".csv": + importFormat = ExportFormat.Csv; + break; + default: + importFormat = ExportFormat.Xml; + break; } - var importResult = (result as PathPlanningResult)?.Data; - if (importResult != null) + var importParameters = new ImportPathParameters { - var statusMessage = $"✅ 导入成功: {importResult.ImportedCount}/{importResult.TotalInFile} 个路径"; - if (importResult.FailedCount > 0) + FilePath = filePath, + ImportFormat = importFormat, + MergeWithExisting = true, + CreateBackup = true, + DuplicateHandling = DuplicateNameHandling.Rename, + ValidateImportedData = true, + AutoSelectFirstRoute = false, + Description = $"导入路径文件: {Path.GetFileName(filePath)}" + }; + + var importCommand = new ImportPathCommand(importParameters, _pathPlanningManager); + var result = await importCommand.ExecuteAsync(); + + if (result.IsSuccess) + { + var importResult = (result as PathPlanningResult)?.Data; + if (importResult != null) { - statusMessage += $" (失败 {importResult.FailedCount} 个)"; - } - UpdateMainStatus(statusMessage); - if (!string.IsNullOrEmpty(importResult.BackupFilePath)) - { - LogManager.Info($"导入前备份已创建: {importResult.BackupFilePath}"); + totalImported += importResult.ImportedCount; + totalFailed += importResult.FailedCount; } } else { - UpdateMainStatus($"✅ 路径导入完成: {Path.GetFileName(filePath)}"); + totalFailed++; + LogManager.Error($"路径导入失败 [{Path.GetFileName(filePath)}]: {result.ErrorMessage}"); } } + + RefreshPathRoutes(); + + // 自动选择第一个路径 + if (PathRoutes.Count > 0) + { + SelectedPathRoute = PathRoutes.FirstOrDefault(); + } + + if (totalImported > 0) + { + var statusMsg = $"✅ 导入成功: {totalImported} 个路径"; + if (totalFailed > 0) + statusMsg += $" (失败 {totalFailed} 个)"; + UpdateMainStatus(statusMsg); + } else { - UpdateMainStatus($"❌ 导入失败: {result.ErrorMessage}"); - LogManager.Error($"路径导入失败: {result.ErrorMessage}"); + UpdateMainStatus($"❌ 导入失败: 所有文件导入失败"); } } } diff --git a/src/UI/WPF/Views/PathEditingView.xaml b/src/UI/WPF/Views/PathEditingView.xaml index 5e7c403..d5826ef 100644 --- a/src/UI/WPF/Views/PathEditingView.xaml +++ b/src/UI/WPF/Views/PathEditingView.xaml @@ -692,14 +692,14 @@ NavisworksTransport 路径编辑页签视图 - 采用与动画控制和分层管