From ba6207f52db76ab47cd6534de0cf1712674ff179 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 13 三月 2025 09:00:46 +0800
Subject: [PATCH] 完善国际化语言;

---
 WPFProject/LoadingWindow.xaml.cs |   96 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 76 insertions(+), 20 deletions(-)

diff --git a/WPFProject/LoadingWindow.xaml.cs b/WPFProject/LoadingWindow.xaml.cs
index b929c03..e9d50a4 100644
--- a/WPFProject/LoadingWindow.xaml.cs
+++ b/WPFProject/LoadingWindow.xaml.cs
@@ -1,9 +1,11 @@
 锘縰sing HMI.Base;
+using HMI.UI.Util;
 using Panuon.WPF.UI;
 using System;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Documents;
+using System.Windows.Media;
 
 namespace WPFProject
 {
@@ -13,12 +15,35 @@
     public partial class LoadingWindow : WindowX
     {
 
-        private string consoleText = "";
+        private string message = "";
 
-        public string ConsoleText
+        public string Message
         {
-            get { return consoleText; }
-            set { Set(ref consoleText, value); }
+            get { return message; }
+            set { Set(ref message, value); }
+        }
+
+        private bool HasErr = false;
+
+        private bool showConsole = false;
+        public bool ShowConsole
+        {
+            get => showConsole;
+            set
+            {
+                Set(ref showConsole, value);
+                NotifyOfPropertyChange("ConsoleVisiable");
+                NotifyOfPropertyChange("BarVisiable");
+            }
+        }
+
+        public Visibility ConsoleVisiable {
+            get => showConsole ? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        public Visibility BarVisiable
+        {
+            get => showConsole ? Visibility.Collapsed : Visibility.Visible;
         }
 
         public LoadingWindow()
@@ -29,11 +54,30 @@
 
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            
+
         }
-        private void Loader_LoadMessageAppend(object sender, string e)
+        private void Loader_LoadMessageAppend(object sender, LoadMsg msg)
         {
-            Add(e);
+            switch (msg.Type)
+            {
+                case LoadMsgType.INIT:
+                    total = msg.NumData;
+                    Add(msg.Message, null);
+                    break;
+                case LoadMsgType.LOADING:
+                    HasErr = msg.Result == false;
+                    if (msg.Result != null)
+                    {
+                        processBar.Value = ++finished / total * 100;
+                    }
+                    Add(msg.Message, msg.Result);
+                    break;
+                case LoadMsgType.FINISHED:
+                    LoadFinished();
+                    break;
+                default:
+                    break;
+            }
         }
 
 
@@ -44,11 +88,13 @@
             this.Close();
         }
 
+        private double total;
+        private double finished;
+
         private void WindowX_ContentRendered(object sender, System.EventArgs e)
         {
             PluginLoader loader = PluginLoader.GetLoader();
             loader.LoadMessageAppend += Loader_LoadMessageAppend;
-            loader.Loaded += Loader_Loaded;
             Task.Run(() =>
             {
                 loader.LoadMenuAndPlugin(Dispatcher);
@@ -56,28 +102,38 @@
             });
         }
 
-        private void Loader_Loaded(object sender, EventArgs e)
+        private void LoadFinished()
         {
-            Dispatcher.Invoke(() =>
+            if (!HasErr)
             {
                 Button_Click(null, null);
-            });
+            }
+            else
+            {
+                WindowXCaption.SetButtons(this, CaptionButtons.Close);
+                ShowConsole = true;
+                BtnNext.Visibility = Visibility.Visible;
+                MsgBoxHelper.Error(this, "鍔犺浇鍑洪敊锛岃纭");
+            }
         }
 
-        public void Add(string text)
+        public void Add(string text, bool? result)
         {
-            string t = string.Format("{0:G}", DateTime.Now);
+            Message = text;
+            string time = string.Format("{0:G}", DateTime.Now);
             Run run = new Run();
-            run.Text = t + " 淇℃伅锛�" + text;
-            //run.Foreground = new Brush();
+            string type = result != false ? "Info" : "Warn";
+            run.Text = $"{time} {type} {text}";
+            run.Foreground = result == null ? Brushes.Black : (result == true ? Brushes.Green : Brushes.Red);
 
-            Paragraph paragraph = new Paragraph(run) {
-                LineHeight =1
+            Paragraph paragraph = new Paragraph(run)
+            {
+                LineHeight = 1
             };
-            //rtxtLog.Document.Blocks.InsertAfter(); ;
-            //鎻掑叆鍒版渶鍓嶉潰
-            Console.Document.Blocks.InsertAfter(Console.Document.Blocks.LastBlock, paragraph);
             //涔熷彲浠ユ彃鍏ュ埌鏈�鍚庨潰
+            Console.Document.Blocks.InsertAfter(Console.Document.Blocks.LastBlock, paragraph);
+            
+            //鎻掑叆鍒版渶鍓嶉潰
             //rtxtLog.Document.Blocks.Add(paragraph);
 
             // 婊氬姩鑷虫渶鍚庤

--
Gitblit v1.9.1