From 3a471ae651b228231bebb3a2d438baa1d4ac0261 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 21 十一月 2025 08:57:52 +0800
Subject: [PATCH] 优化

---
 HMI.ParameterManage/SettingModal.xaml.cs |   92 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/HMI.ParameterManage/SettingModal.xaml.cs b/HMI.ParameterManage/SettingModal.xaml.cs
index edd574b..308485e 100644
--- a/HMI.ParameterManage/SettingModal.xaml.cs
+++ b/HMI.ParameterManage/SettingModal.xaml.cs
@@ -2,11 +2,15 @@
 using HMI.Core.Util;
 using HMI.UI.DpUtil;
 using HMI.UI.Util;
+using Microsoft.Win32;
 using Panuon.WPF.UI;
 using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Linq;
+using System.Text.RegularExpressions;
+using System.Windows.Controls;
 
 namespace HMI.ParameterManage
 {
@@ -82,12 +86,14 @@
 
         private bool ValidateForm()
         {
-            bool flag = FormGroupHelper.ValidateForm(formPanel);
+            bool flag = FormGroupHelper.ValidateForm(formPanel, new Dictionary<string, object> {
+                { "FgValue",GetTargetValue()}
+            });
             if (flag)
             {
                 Data.Name = TbName.Text;
                 Data.Type = CbType.Text;
-                Data.Value = TbValue.Text;
+                Data.Value = GetTargetValue();
                 Data.Unit = TbUnit.Text;
                 Data.Description = TbDescription.Text;
                 Data.PGroup = TbGroup.Text;
@@ -96,18 +102,96 @@
             return flag;
         }
 
-        public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource)
+        public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource, List<string> groups)
         {
             Datasource = datasource;
             Data = data;
+            TbGroup.ItemsSource = groups;
+
             TbName.Text = Data.Name;
             CbType.SelectedValue = Data.Type;
-            TbValue.Text = Data.Value;
+            UpdateWindow(Data.Type);
+            UpdateForm(Data);
+
             TbUnit.Text = Data.Unit;
             TbDescription.Text = Data.Description;
             TbGroup.Text = Data.PGroup;
             TbSource.Text = Data.Source;
             return this.ShowDialog();
         }
+
+        private string GetTargetValue()
+        {
+            var type = CbType.Text;
+            if (type == "Int" || type == "Double")
+            {
+                return NiNumberValue.Text;
+            }
+            else if (type == "Bool")
+            {
+                return CbBoolValue.Text;
+            }
+            else
+            {
+                return TbStringValue.Text;
+            }
+        }
+
+        private void UpdateForm(ParameterData data)
+        {
+            if (Data.Type == "Int" || Data.Type == "Int")
+            {
+                NiNumberValue.Text = Data.Value;
+            }
+            else if (Data.Type == "Bool")
+            {
+                CbBoolValue.SelectedValue = Data.Value;
+            }
+            else
+            {
+                TbStringValue.Text = Data.Value;
+            }
+        }
+
+        private void UpdateWindow(string type)
+        {
+            if (type == "Int" || type == "Double")
+            {
+                NiNumberValue.Visibility = System.Windows.Visibility.Visible;
+                StringValueGrid.Visibility = System.Windows.Visibility.Collapsed;
+                CbBoolValue.Visibility = System.Windows.Visibility.Collapsed;
+            }
+            else if (type == "Bool")
+            {
+                NiNumberValue.Visibility = System.Windows.Visibility.Collapsed;
+                StringValueGrid.Visibility = System.Windows.Visibility.Collapsed;
+                CbBoolValue.Visibility = System.Windows.Visibility.Visible;
+            }
+            else
+            {
+                NiNumberValue.Visibility = System.Windows.Visibility.Collapsed;
+                StringValueGrid.Visibility = System.Windows.Visibility.Visible;
+                CbBoolValue.Visibility = System.Windows.Visibility.Collapsed;
+            }
+        }
+
+        private void CbType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
+        {
+            string val = null;
+            if (e.AddedItems != null && e.AddedItems.Count > 0)
+            {
+                val = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
+            }
+            UpdateWindow(val);
+        }
+
+        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
+        {
+            OpenFileDialog ofd = new OpenFileDialog();
+            if (ofd.ShowDialog() == true)
+            {
+                TbStringValue.Text = ofd.FileName;
+            }
+        }
     }
 }

--
Gitblit v1.9.1