追溯上传成功后弹出自动关闭提示窗口
优化日志记录方式,移除部分Debug输出,新增AutoCloseMessageWindow用于追溯上传成功时自动弹出3秒后关闭的提示窗口,提升用户体验。建议后续修正窗口标题和按钮的中文乱码问题。
This commit is contained in:
@@ -218,7 +218,7 @@ namespace LineTraceabilitySystem.ViewModels
|
||||
)
|
||||
{
|
||||
//IRegionManager regionManager,
|
||||
Debug.WriteLine("程序初始化");
|
||||
// 程序初始化记录
|
||||
AddToOperationHistory($"程序初始化");
|
||||
// 初始化
|
||||
_scanService = scanService;
|
||||
@@ -280,7 +280,7 @@ namespace LineTraceabilitySystem.ViewModels
|
||||
}
|
||||
private void ComboxSelectionChanged(object mode)
|
||||
{
|
||||
Debug.Write(mode.ToString());
|
||||
// 记录下拉选择变化(如需详细日志可改为 AddToOperationHistory)
|
||||
if (mode is ComboBoxItem combo)
|
||||
{
|
||||
if (combo.Content.ToString() == "单机")
|
||||
@@ -506,7 +506,6 @@ namespace LineTraceabilitySystem.ViewModels
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
ScanResult = data;
|
||||
Debug.WriteLine($"步骤:{CurrentStep}");
|
||||
// 根据当前步骤处理扫描数据
|
||||
switch (CurrentStep)
|
||||
{
|
||||
@@ -700,7 +699,7 @@ namespace LineTraceabilitySystem.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine($"追溯数据上传服务器");
|
||||
// 记录开始上传追溯数据
|
||||
AddToOperationHistory($"追溯数据上传服务器");
|
||||
|
||||
// 在后台线程中执行数据库操作
|
||||
@@ -759,21 +758,33 @@ namespace LineTraceabilitySystem.ViewModels
|
||||
};
|
||||
// 插入数据
|
||||
db.Insertable(logRecord).ExecuteCommand();
|
||||
Debug.WriteLine($"追溯上传成功");
|
||||
|
||||
// 追溯上传成功日志
|
||||
});
|
||||
|
||||
// 在UI线程中更新操作历史
|
||||
// 在UI线程中更新操作历史并显示自动关闭的成功提示窗口
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
AddToOperationHistory($"追溯上传成功");
|
||||
try
|
||||
{
|
||||
// 显示提示窗口,3 秒后自动关闭
|
||||
var win = new LineTraceabilitySystem.Views.AutoCloseMessageWindow("追溯上传成功", TimeSpan.FromSeconds(3));
|
||||
// 设置主窗口为 Owner(如果存在)以保证窗口居中
|
||||
if (Application.Current.MainWindow != null)
|
||||
{
|
||||
win.Owner = Application.Current.MainWindow;
|
||||
}
|
||||
win.Show();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 若显示窗口失败则只记录日志,不影响主流程
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"追溯上传失败: {ex.Message}");
|
||||
|
||||
// 在UI线程中更新操作历史和显示错误信息
|
||||
// 上传失败,记录并提示
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
AddToOperationHistory($"追溯上传失败: {ex.Message}");
|
||||
|
||||
30
src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml
Normal file
30
src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml
Normal file
@@ -0,0 +1,30 @@
|
||||
<Window x:Class="LineTraceabilitySystem.Views.AutoCloseMessageWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="<22><>ʾ"
|
||||
Width="320"
|
||||
Height="140"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="MessageTextBlock"
|
||||
Grid.Row="0"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="14"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Text="" />
|
||||
<Button Grid.Row="1"
|
||||
Margin="0,10,0,0"
|
||||
Width="80"
|
||||
Height="28"
|
||||
HorizontalAlignment="Center"
|
||||
Content="<22>ر<EFBFBD>"
|
||||
Click="CloseButton_Click" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace LineTraceabilitySystem.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>Զ<EFBFBD><D4B6>رչ<D8B1><D5B9>ܵ<EFBFBD><DCB5><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public partial class AutoCloseMessageWindow : Window
|
||||
{
|
||||
private DispatcherTimer _timer;
|
||||
|
||||
public AutoCloseMessageWindow(string message, TimeSpan? autoClose = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
MessageTextBlock.Text = message;
|
||||
|
||||
if (autoClose.HasValue && autoClose.Value > TimeSpan.Zero)
|
||||
{
|
||||
_timer = new DispatcherTimer();
|
||||
_timer.Interval = autoClose.Value;
|
||||
_timer.Tick += (s, e) => { _timer.Stop(); this.Close(); };
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_timer?.Stop();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user