feat: rename export button, support multi-file import
- Rename '导出选中路径' to '导出', move before '导出全部' - Import dialog: enable MultiSelect, loop through all selected files - Aggregate import results across files
This commit is contained in:
parent
b3a8364e7e
commit
5692fde956
@ -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<ImportPathResult>)?.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<ImportPathResult>)?.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($"❌ 导入失败: 所有文件导入失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -692,14 +692,14 @@ NavisworksTransport 路径编辑页签视图 - 采用与动画控制和分层管
|
||||
<Button Content="导入"
|
||||
Command="{Binding ImportPathCommand}"
|
||||
Style="{StaticResource SecondaryButtonStyle}"/>
|
||||
<Button Content="导出"
|
||||
Command="{Binding SaveAsPathCommand}"
|
||||
Style="{StaticResource SecondaryButtonStyle}"
|
||||
IsEnabled="{Binding CanExecuteSaveAsPath}"/>
|
||||
<Button Content="导出全部"
|
||||
Command="{Binding ExportPathCommand}"
|
||||
Style="{StaticResource SecondaryButtonStyle}"
|
||||
IsEnabled="{Binding CanExecuteExportPath}"/>
|
||||
<Button Content="导出选中路径"
|
||||
Command="{Binding SaveAsPathCommand}"
|
||||
Style="{StaticResource SecondaryButtonStyle}"
|
||||
IsEnabled="{Binding CanExecuteSaveAsPath}"/>
|
||||
<Button Content="生成导航地图"
|
||||
Click="OnGenerateNavigationMapButtonClick"
|
||||
Style="{StaticResource SecondaryButtonStyle}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user