diff --git a/src/LineTraceabilitySystem/ViewModels/MainWindowViewModel.cs b/src/LineTraceabilitySystem/ViewModels/MainWindowViewModel.cs
index 06c6907..f376c8a 100644
--- a/src/LineTraceabilitySystem/ViewModels/MainWindowViewModel.cs
+++ b/src/LineTraceabilitySystem/ViewModels/MainWindowViewModel.cs
@@ -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}");
diff --git a/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml b/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml
new file mode 100644
index 0000000..b0fc18a
--- /dev/null
+++ b/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml.cs b/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml.cs
new file mode 100644
index 0000000..ddd0ca6
--- /dev/null
+++ b/src/LineTraceabilitySystem/Views/AutoCloseMessageWindow.xaml.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Windows;
+using System.Windows.Threading;
+
+namespace LineTraceabilitySystem.Views
+{
+ ///
+ /// Զرչܵʾ
+ ///
+ 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();
+ }
+ }
+}