From 0940f31b7eba1cf6b6a8c1fca72d97cf686e79f2 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 04 七月 2025 10:43:00 +0800
Subject: [PATCH] 优化插件,完善TreeListView

---
 HMI.LogViewer/LogViewer.xaml.cs |   53 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/HMI.LogViewer/LogViewer.xaml.cs b/HMI.LogViewer/LogViewer.xaml.cs
index 508aecf..bc54659 100644
--- a/HMI.LogViewer/LogViewer.xaml.cs
+++ b/HMI.LogViewer/LogViewer.xaml.cs
@@ -1,6 +1,7 @@
 锘縰sing HMI.Base;
 using HMI.Core.Util;
 using HMI.UI.Util;
+using log4net.Core;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -9,6 +10,7 @@
 using System.Timers;
 using System.Windows;
 using System.Windows.Controls;
+using static System.Net.Mime.MediaTypeNames;
 
 namespace HMI.LogViewer
 {
@@ -36,6 +38,13 @@
         public LogViewer()
         {
             DataContext = this;
+            autoRfhTimer = new Timer
+            {
+                Enabled = false,
+                Interval = 1000,
+                AutoReset = false
+            };
+            autoRfhTimer.Elapsed += AutoRfhTimer_Elapsed;
             InitializeComponent();
         }
 
@@ -68,12 +77,6 @@
 
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
-            autoRfhTimer = new Timer
-            {
-                Enabled = false,
-                Interval = 1000
-            };
-            autoRfhTimer.Elapsed += AutoRfhTimer_Elapsed;
             Loaded -= UserControl_Loaded;
         }
 
@@ -222,22 +225,28 @@
         /// </summary>
         private void Refresh100items()
         {
-            //try
-            //{
-            //    if (!File.Exists(todayLogFile)) return;
-            //    string str = "select type,time,source,text from log order by time desc limit 100";
-            //    SqliteHelper sql = new SqliteHelper(todayLogFile);
-            //    var dt = sql.GetDataTable(str);
-            //    this.Dispatcher.BeginInvoke((Action)delegate ()
-            //    {
-            //        table.ItemsSource = dt.DefaultView;
-            //    });
-            //}
-            //catch (Exception ex)
-            //{
-            //    log.Error("Log Auto Refresh Failed.", ex);
-            //    this.Error($"鑷姩鍒锋柊澶辫触锛亄ex.Message}");
-            //}
+            try
+            {
+                autoRfhTimer.Enabled = false;
+                string todayLogFile = Path.Combine(PathHelper.LogViewerDir, $"log_{DateTime.Today:yyyy-MM-dd}.db");
+                if (!File.Exists(todayLogFile)) return;
+                string str = "select level,time,source,text from log order by time desc limit 100";
+                SqliteHelper sql = new SqliteHelper(todayLogFile);
+                var dt = sql.GetDataTable(str);
+                this.Dispatcher.BeginInvoke((Action)delegate ()
+                {
+                    table.ItemsSource = dt.DefaultView;
+                });
+            }
+            catch (Exception ex)
+            {
+                log.Error("Log Auto Refresh Failed.", ex);
+                this.Error($"鑷姩鍒锋柊澶辫触锛亄ex.Message}");
+            }
+            finally
+            {
+                autoRfhTimer.Enabled = AutoRfh;
+            }
         }
     }
 }

--
Gitblit v1.9.1