新增启动菜单
This commit is contained in:
70
App.xaml.cs
70
App.xaml.cs
@@ -17,20 +17,44 @@ namespace DrillTools
|
||||
base.OnStartup(e);
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
// 运行孔位数据功能测试
|
||||
//MainWindowViewModel.TestHoleLocationsFunctionality();
|
||||
|
||||
// 检查是否有命令行参数(拖拽文件到exe上)
|
||||
string? filePath = null;
|
||||
if (e.Args.Length > 0)
|
||||
{
|
||||
// 获取第一个参数作为文件路径
|
||||
filePath = e.Args[0];
|
||||
// 验证文件是否存在且为有效的钻带文件
|
||||
if (!IsValidDrillTapeFile(filePath))
|
||||
filePath = null; // 重置为null,按正常启动流程
|
||||
filePath = null;
|
||||
}
|
||||
|
||||
if (filePath == null)
|
||||
{
|
||||
ShowMainWindow(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止选择窗口关闭后触发 OnLastWindowClose 导致应用退出
|
||||
ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||||
|
||||
var selectionWindow = new StartupSelectionWindow(filePath);
|
||||
selectionWindow.ShowDialog();
|
||||
|
||||
switch (selectionWindow.SelectedAction)
|
||||
{
|
||||
case StartupAction.AdjustToolOrder:
|
||||
ShutdownMode = ShutdownMode.OnLastWindowClose;
|
||||
ShowMainWindow(filePath);
|
||||
break;
|
||||
case StartupAction.ExportHoleCount:
|
||||
PerformHeadlessExport(filePath);
|
||||
Shutdown();
|
||||
break;
|
||||
default:
|
||||
Shutdown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowMainWindow(string? filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
MainWindow mainWindow = new MainWindow(filePath);
|
||||
@@ -38,13 +62,41 @@ namespace DrillTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 显示错误消息
|
||||
System.Windows.MessageBox.Show($"创建MainWindow时发生异常:\n{ex.GetType().Name} - {ex.Message}\n\n{ex.StackTrace}",
|
||||
"启动失败", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
|
||||
"启动失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static void PerformHeadlessExport(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var viewModel = new MainWindowViewModel();
|
||||
|
||||
string content = CommandTypeFileReader.ReadAllText(filePath);
|
||||
viewModel.OriginalFilePath = filePath;
|
||||
viewModel.LoadToolsFromDrillTape(content);
|
||||
|
||||
if (viewModel.Tools.Count == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("钻带文件中未找到有效的刀具数据,无法导出孔数报表。",
|
||||
"提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.ExportDrillUsageReport();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show($"导出孔数报表失败:\n{ex.Message}",
|
||||
"错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证是否为有效的钻带文件
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user