This commit is contained in:
GukSang.Jin
2026-03-16 19:10:33 +08:00
parent 34083df6de
commit 88a65233a7
26 changed files with 839 additions and 235 deletions

View File

@@ -37,6 +37,10 @@ namespace 自救器呼吸器综合检验仪
private bool _wasRunning = false; // 上次检验的运行状态
private bool _recordAdded = false; // 本轮测试是否已插入记录
private DateTime _testStartTime; // 测试开始时间
private Button _selectedParameterButton;
private static readonly Brush ParameterButtonDefaultBrush = CreateParameterButtonBrush("#3498DB");
private static readonly Brush ParameterButtonSelectedBrush = CreateParameterButtonBrush("#F39C12");
int retryCount = 0; // 连接失败重试次数
private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient;
@@ -225,6 +229,7 @@ namespace 自救器呼吸器综合检验仪
{
_modbusMaster.WriteSingleCoil(1, 75, true);
isReset = true;
UpdateParameterButtonSelection(sender as Button);
}
@@ -236,6 +241,39 @@ namespace 自救器呼吸器综合检验仪
});
}
private static Brush CreateParameterButtonBrush(string colorCode)
{
return new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorCode));
}
private void UpdateParameterButtonSelection(Button selectedButton)
{
if (selectedButton == null)
{
return;
}
if (_selectedParameterButton != null && !ReferenceEquals(_selectedParameterButton, selectedButton))
{
ApplyParameterButtonStyle(_selectedParameterButton, false);
}
_selectedParameterButton = selectedButton;
ApplyParameterButtonStyle(_selectedParameterButton, true);
}
private void ApplyParameterButtonStyle(Button button, bool isSelected)
{
if (button == null)
{
return;
}
button.Background = isSelected ? ParameterButtonSelectedBrush : ParameterButtonDefaultBrush;
button.BorderBrush = Brushes.Transparent;
button.BorderThickness = new Thickness(0);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//ma.BtnClickFunctionForNew(Function.ButtonType.切换型, 170);
@@ -261,22 +299,22 @@ namespace 自救器呼吸器综合检验仪
private void Button_Click_4(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _mainWindow, () => new MainWindow());
SwitchWindow(ref _mainWindow, () => new MainWindow(), "正在进入定量供应检验", "正在准备定量供应检验页面...");
}
private void Button_Click_5(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _mainWindow2, () => new MainWindow2());
SwitchWindow(ref _mainWindow2, () => new MainWindow2(), "正在进入负压气密性检验", "正在切换到负压气密性检验页面...");
}
private void Button_Click_6(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _mainWindow3, () => new MainWindow3());
SwitchWindow(ref _mainWindow3, () => new MainWindow3(), "正在进入正压气密性检验", "正在切换到正压气密性检验页面...");
}
private void Button_Click_7(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _mainWindow4, () => new MainWindow4());
SwitchWindow(ref _mainWindow4, () => new MainWindow4(), "正在进入排气阀压力测试", "正在切换到排气阀压力测试页面...");
}
private void Window_Loaded(object sender, RoutedEventArgs e)
@@ -319,11 +357,6 @@ namespace 自救器呼吸器综合检验仪
pressureDiff2.Text = ConfigurationManager.AppSettings["No"]?.ToString();
string imagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/sleep2.jpg");
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
this.Background = brush;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@@ -340,18 +373,12 @@ namespace 自救器呼吸器综合检验仪
// 释放Modbus资源
ModbusResourceManager.Instance?.Dispose();
// 确保应用程序完全退出
Application.Current.Shutdown();
// 延后到当前窗口完成关闭后再统一关停,避免关闭重入。
AppShutdownCoordinator.RequestShutdown();
}
private void Window_Closed(object sender, EventArgs e)
{
// 清理其他窗口实例
//_mainWindow?.Close();
_mainWindow2?.Close();
_mainWindow3?.Close();
_mainWindow4?.Close();
_mainWindow5?.Close();
_reportWindow?.Close();
// 由应用级关停统一处理其他窗口,避免关闭链路重入。
}
private void BtnWrite401_Click(object sender, RoutedEventArgs e)
{
@@ -373,6 +400,7 @@ namespace 自救器呼吸器综合检验仪
System.Threading.Tasks.Task.Delay(50);
_isManualInput = false; // 写入后恢复读取
UpdateParameterButtonSelection(sender as Button);
//await ReadAddr400DataAsync(); // 刷新显示(确认写入成功)
}
@@ -382,7 +410,7 @@ namespace 自救器呼吸器综合检验仪
}
}
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc, string loadingTitle = null, string loadingSubtitle = null) where T : Window, new()
{
// 1. 停止当前窗口的定时器(不释放资源)
_readTimer?.Stop();
@@ -406,22 +434,12 @@ namespace 自救器呼吸器综合检验仪
// 添加窗口关闭事件处理
windowInstance.Closed += (s, args) =>
{
// 窗口关闭时重新启动定时器并显示当前窗口
_readTimer?.Start();
//this.Show();
this.Activate();
WindowNavigationHelper.RestoreWindow(this, () => _readTimer?.Start());
};
}
else
{
// 激活已存在的窗口(前置显示)
windowInstance.Activate();
//return;
}
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
this.Hide();
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
// 4. 目标窗口完成首帧渲染后再切换,避免白屏
WindowNavigationHelper.ShowWithoutWhiteFlash(this, windowInstance, loadingTitle, loadingSubtitle);
}
// 添加重连方法
@@ -572,6 +590,7 @@ namespace 自救器呼吸器综合检验仪
{
_modbusMaster.WriteSingleCoil(1, 75, false);
isReset = false;
UpdateParameterButtonSelection(sender as Button);
}
//private void pressureDiff2_GotFocus(object sender, RoutedEventArgs e)