This commit is contained in:
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace 自救器呼吸器综合检验仪
|
||||
{
|
||||
@@ -250,6 +251,12 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void BtnPrint_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 判断是否有数据可打印
|
||||
if (_records == null || _records.Count == 0)
|
||||
{
|
||||
MessageBox.Show("当前没有可打印的数据。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
ma.BtnClickFunctionForNew(Function.ButtonType.切换型, 15);
|
||||
}
|
||||
|
||||
@@ -274,42 +281,53 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
{
|
||||
|
||||
// 2. 检查资源是否可用(添加重连机制)
|
||||
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
|
||||
{
|
||||
// 尝试重新连接
|
||||
bool reconnectSuccess = TryReconnect();
|
||||
if (!reconnectSuccess)
|
||||
if (!TryReconnect())
|
||||
{
|
||||
MessageBox.Show("TCP连接已断开,请重新连接!", "提示");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 复用窗口实例:不存在则创建,存在则激活
|
||||
void ShowTargetWindow(T target)
|
||||
{
|
||||
if (target.IsVisible)
|
||||
{
|
||||
target.Activate();
|
||||
this.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
target.Opacity = 0;
|
||||
void OnContentRendered(object s, EventArgs e)
|
||||
{
|
||||
target.ContentRendered -= OnContentRendered;
|
||||
var anim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
|
||||
target.BeginAnimation(Window.OpacityProperty, anim);
|
||||
this.Hide();
|
||||
target.Activate();
|
||||
}
|
||||
|
||||
target.ContentRendered += OnContentRendered;
|
||||
target.Show();
|
||||
}
|
||||
|
||||
if (windowInstance == null)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
return;
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
}
|
||||
|
||||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user