This commit is contained in:
@@ -287,7 +287,7 @@
|
||||
|
||||
<Button Content="🔬 定量供应检验"
|
||||
Background="#3498DB" Foreground="White" FontSize="12" FontWeight="Bold"
|
||||
Width="140" Height="40" BorderThickness="0" Margin="8,5" Cursor="Hand"/>
|
||||
Width="140" Height="40" BorderThickness="0" Margin="8,5" Cursor="Hand" Click="Button_Click_8"/>
|
||||
|
||||
<Button Content="📉 负压气密性检验" Click="Button_Click_5"
|
||||
Background="White" Foreground="#2C3E50" FontSize="12" FontWeight="Bold"
|
||||
@@ -306,5 +306,6 @@
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -14,6 +14,7 @@ using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
@@ -636,6 +637,11 @@ namespace 自救器呼吸器综合检验仪
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Button_Click_8(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:自救器呼吸器综合检验仪"
|
||||
Title="自救器呼吸器综合检验仪" Height="768" Width="1024"
|
||||
Title="自救器呼吸器综合检验仪" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Background="Transparent"
|
||||
FontFamily="Microsoft YaHeui" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing">
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Media.Animation;
|
||||
using 自救器呼吸器综合检验仪;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
|
||||
@@ -478,44 +479,55 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
{
|
||||
// 1. 停止当前窗口的定时器(不释放资源)
|
||||
_readTimer?.Stop();
|
||||
|
||||
// 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) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
_readTimer?.Start();
|
||||
//this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
//return;
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
}
|
||||
// 添加重连方法
|
||||
private bool TryReconnect()
|
||||
@@ -643,7 +655,7 @@ namespace 自救器呼吸器综合检验仪
|
||||
}
|
||||
string No = ConfigurationManager.AppSettings["No"]?.ToString();
|
||||
// 添加记录到窗口(无论窗口是否显示)
|
||||
_reportWindow2.AddRecord(currentTime, currentDate, startPress, endPress, diffPress, ProtectTime,No);
|
||||
_reportWindow2.AddRecord(currentTime, currentDate, startPress, endPress, diffPress, ProtectTime, No);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:自救器呼吸器综合检验仪"
|
||||
Title="自救器呼吸器综合检验仪" Height="768" Width="1024"
|
||||
Title="自救器呼吸器综合检验仪" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Background="Transparent"
|
||||
FontFamily="Microsoft YaHeui"
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Media.Animation;
|
||||
using 自救器呼吸器综合检验仪;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
|
||||
@@ -451,44 +452,55 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
{
|
||||
// 1. 停止当前窗口的定时器(不释放资源)
|
||||
_readTimer?.Stop();
|
||||
|
||||
// 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) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
_readTimer?.Start();
|
||||
//this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
//return;
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
}
|
||||
// 添加重连方法
|
||||
private bool TryReconnect()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:自救器呼吸器综合检验仪"
|
||||
Title="自救器呼吸器综合检验仪" Height="768" Width="1024"
|
||||
Title="自救器呼吸器综合检验仪" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Background="Transparent"
|
||||
FontFamily="Microsoft YaHeui"
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Media.Animation;
|
||||
using 自救器呼吸器综合检验仪;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
|
||||
@@ -296,44 +297,55 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
{
|
||||
// 1. 停止当前窗口的定时器(不释放资源)
|
||||
_readTimer?.Stop();
|
||||
|
||||
// 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) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
_readTimer?.Start();
|
||||
//this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
//return;
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
}
|
||||
private bool TryReconnect()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="自救器呼吸器综合检验仪.ParameterSettingsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="参数设置" Height="768" Width="1024"
|
||||
Title="参数设置" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ResizeMode="NoResize" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing">
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows.Media.Animation;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
|
||||
namespace 自救器呼吸器综合检验仪
|
||||
@@ -118,44 +119,57 @@ namespace 自救器呼吸器综合检验仪
|
||||
|
||||
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
|
||||
{
|
||||
// 1. 停止当前窗口的定时器(不释放资源)
|
||||
// 停止当前窗口的定时器(不释放资源)
|
||||
_readTimer?.Stop();
|
||||
|
||||
// 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) =>
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
_readTimer?.Start();
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
return;
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
this.Hide();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="自救器呼吸器综合检验仪.ReportWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="定量供氧检验报表" Height="768" Width="1024"
|
||||
Title="定量供氧检验报表" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing" >
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace 自救器呼吸器综合检验仪
|
||||
{
|
||||
@@ -230,6 +231,14 @@ 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);
|
||||
}
|
||||
|
||||
@@ -254,42 +263,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. 复用窗口实例:不存在则创建,存在则激活
|
||||
if (windowInstance == null)
|
||||
void ShowTargetWindow(T target)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
if (target.IsVisible)
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
target.Activate();
|
||||
this.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
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();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
target.Activate();
|
||||
}
|
||||
|
||||
target.ContentRendered += OnContentRendered;
|
||||
target.Show();
|
||||
}
|
||||
|
||||
if (windowInstance == null)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="自救器呼吸器综合检验仪.ReportWindow2"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="负压气密性检验报表" Height="768" Width="1024"
|
||||
Title="负压气密性检验报表" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -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. 复用窗口实例:不存在则创建,存在则激活
|
||||
if (windowInstance == null)
|
||||
void ShowTargetWindow(T target)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
if (target.IsVisible)
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
target.Activate();
|
||||
this.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
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();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
target.Activate();
|
||||
}
|
||||
|
||||
target.ContentRendered += OnContentRendered;
|
||||
target.Show();
|
||||
}
|
||||
|
||||
if (windowInstance == null)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="自救器呼吸器综合检验仪.ReportWindow3"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="正压气密性检验报表" Height="768" Width="1024"
|
||||
Title="正压气密性检验报表" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace 自救器呼吸器综合检验仪
|
||||
{
|
||||
@@ -191,6 +192,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);
|
||||
}
|
||||
|
||||
@@ -272,42 +279,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. 复用窗口实例:不存在则创建,存在则激活
|
||||
if (windowInstance == null)
|
||||
void ShowTargetWindow(T target)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
if (target.IsVisible)
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
target.Activate();
|
||||
this.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
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();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
target.Activate();
|
||||
}
|
||||
|
||||
target.ContentRendered += OnContentRendered;
|
||||
target.Show();
|
||||
}
|
||||
|
||||
if (windowInstance == null)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Window x:Class="自救器呼吸器综合检验仪.ReportWindow4"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="排气阀检验报表" Height="768" Width="1024"
|
||||
Title="排气阀检验报表" Height="730" Width="1024"
|
||||
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closed="Window_Closed" Closing="Window_Closing" >
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using 自救器呼吸器综合检验仪.Data;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace 自救器呼吸器综合检验仪
|
||||
{
|
||||
@@ -233,6 +234,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);
|
||||
}
|
||||
|
||||
@@ -313,42 +320,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. 复用窗口实例:不存在则创建,存在则激活
|
||||
if (windowInstance == null)
|
||||
void ShowTargetWindow(T target)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
// 添加窗口关闭事件处理
|
||||
windowInstance.Closed += (s, args) =>
|
||||
if (target.IsVisible)
|
||||
{
|
||||
// 窗口关闭时重新启动定时器并显示当前窗口
|
||||
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活已存在的窗口(前置显示)
|
||||
windowInstance.Activate();
|
||||
target.Activate();
|
||||
this.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 切换窗口:隐藏当前窗口,显示目标窗口(非模态)
|
||||
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();
|
||||
windowInstance.Show(); // 使用 Show() 而不是 ShowDialog()
|
||||
target.Activate();
|
||||
}
|
||||
|
||||
target.ContentRendered += OnContentRendered;
|
||||
target.Show();
|
||||
}
|
||||
|
||||
if (windowInstance == null)
|
||||
{
|
||||
windowInstance = createFunc();
|
||||
windowInstance.Closed += (s, args) =>
|
||||
{
|
||||
this.Show();
|
||||
this.Activate();
|
||||
};
|
||||
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowTargetWindow(windowInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user