From ef52fd6fd07508883dce4eb002acda59f0169e59 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 23 四月 2026 10:19:33 +0800
Subject: [PATCH] 优化;

---
 HMI.ParameterManage/SettingModal.xaml.cs |  288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 277 insertions(+), 11 deletions(-)

diff --git a/HMI.ParameterManage/SettingModal.xaml.cs b/HMI.ParameterManage/SettingModal.xaml.cs
index 4c19f6b..22569d6 100644
--- a/HMI.ParameterManage/SettingModal.xaml.cs
+++ b/HMI.ParameterManage/SettingModal.xaml.cs
@@ -1,15 +1,64 @@
-锘縰sing HMI.Core.Util;
-using HMI.ParameterManage.Entity;
+锘縰sing HMI.Core.Entity;
+using HMI.Core.Util;
 using HMI.UI.DpUtil;
 using HMI.UI.Util;
+using Microsoft.Win32;
+using NPOI.SS.Formula.Functions;
+using NPOI.SS.Formula.PTG;
 using Panuon.WPF.UI;
 using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Linq;
+using System.Windows.Controls;
 
 namespace HMI.ParameterManage
 {
+    public class BoolData
+    {
+        public int Index { get; }
+        public bool Value { get; set; }
+
+        public BoolData(int index)
+        {
+            this.Index = index;
+        }
+    }
+
+    public class IntData
+    {
+        public int Index { get; }
+        public int Value { get; set; }
+
+        public IntData(int index)
+        {
+            this.Index = index;
+        }
+    }
+
+    public class DoubleData
+    {
+        public int Index { get; }
+        public double Value { get; set; }
+
+        public DoubleData(int index)
+        {
+            this.Index = index;
+        }
+    }
+
+    public class StringData
+    {
+        public int Index { get; }
+        public string Value { get; set; } = string.Empty;
+
+        public StringData(int index)
+        {
+            this.Index = index;
+        }
+    }
+
     /// <summary>
     /// ModalWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
@@ -67,7 +116,8 @@
         public bool ValidateName(object value, out string err)
         {
             err = null;
-            if (Datasource?.FirstOrDefault(e => e.Name == value.ToString()) != null)
+            var data = Datasource?.FirstOrDefault(e => e.Name == value.ToString());
+            if (data != null && data != Data)
             {
                 err = this.lang("App.MustBeUnique", this.lang("Pm.Parameter.Name"));
                 return false;
@@ -81,32 +131,248 @@
 
         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.IsArray = CbIsArray.IsChecked == true;
+                Data.Length = int.Parse(NiLength.Text);
+
+                Data.Value = GetTargetValue();
                 Data.Unit = TbUnit.Text;
                 Data.Description = TbDescription.Text;
-                Data.PGroup = CbGroup.Text;
-                Data.Source = CbSource.Text;
+                Data.PGroup = TbGroup.Text;
+                Data.Source = TbSource.Text;
             }
             return flag;
         }
 
-        public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource)
+        public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource, List<string> groups,string productName = null)
         {
+            if (!string.IsNullOrEmpty(productName))
+            {
+                FgProductName.Visibility = System.Windows.Visibility.Visible;
+                TbProductName.Text = productName;
+            }
+
             Datasource = datasource;
             Data = data;
+            TbGroup.ItemsSource = groups;
+
             TbName.Text = Data.Name;
             CbType.SelectedValue = Data.Type;
-            TbValue.Text = Data.Value;
+            CbIsArray.IsChecked = Data.IsArray;
+            NiLength.Text = Data.Length.ToString();
+
+            UpdateWindow(Data.Type);
+            UpdateForm(Data);
+
             TbUnit.Text = Data.Unit;
             TbDescription.Text = Data.Description;
-            CbGroup.SelectedValue = Data.PGroup;
-            CbSource.SelectedValue = Data.Source;
+            TbGroup.Text = Data.PGroup;
+            TbSource.Text = Data.Source;
             return this.ShowDialog();
         }
+
+        private string GetTargetValue()
+        {
+            var type = CbType.Text;
+            if (CbIsArray.IsChecked == true)
+            {
+                var arr = (object[])arrayInput.ItemsSource;
+                return string.Join(",", arr.Select(e => e.GetType().GetProperty("Value").GetValue(e).ToString()).ToArray());
+            }
+
+            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.IsArray)
+            {
+                string[] arr = data.Value.Split(',');
+                arrayInput.ItemsSource = RefreshArray(arr, Data.Type);
+            }
+            else
+            {
+                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);
+            if (CbIsArray.IsChecked == true)
+            {
+                arrayInput.ItemsSource = RefreshArray(GetLength(), val);
+            }
+        }
+
+        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
+        {
+            OpenFileDialog ofd = new OpenFileDialog();
+            if (ofd.ShowDialog() == true)
+            {
+                TbStringValue.Text = ofd.FileName;
+            }
+        }
+
+        private void CbIsArray_Checked(object sender, System.Windows.RoutedEventArgs e)
+        {
+            bool isChecked = ((CheckBox)sender).IsChecked == true;
+            if (isChecked)
+            {
+                FgLength.Visibility = System.Windows.Visibility.Visible;
+                arrayInput.Visibility = System.Windows.Visibility.Visible;
+                arrayInput.ItemsSource = RefreshArray(GetLength(), CbType.Text);
+            }
+            else
+            {
+                FgLength.Visibility = System.Windows.Visibility.Collapsed;
+                arrayInput.Visibility = System.Windows.Visibility.Collapsed;
+            }
+        }
+
+        private object[] RefreshArray(int length, string type)
+        {
+            var arr = new object[length];
+            for (int i = 0; i < length; i++)
+            {
+                if (type == "Int")
+                {
+                    arr[i] = new IntData(i);
+                }
+                else if (type == "Double")
+                {
+                    arr[i] = new DoubleData(i);
+                }
+                else if (type == "Bool")
+                {
+                    arr[i] = new BoolData(i);
+                }
+                else
+                {
+                    arr[i] = new StringData(i);
+                }
+            }
+            return arr;
+        }
+
+        private object[] RefreshArray(string[] source, string type)
+        {
+            var arr = new object[source.Length];
+            type = string.IsNullOrEmpty(type) ? "String" : type;
+            for (int i = 0; i < arr.Length; i++)
+            {
+                if (type == "Int")
+                {
+                    arr[i] = new IntData(i)
+                    {
+                        Value = int.Parse(source[i])
+                    };
+                }
+                else if (type == "Double")
+                {
+                    arr[i] = new DoubleData(i)
+                    {
+                        Value = double.Parse(source[i])
+                    };
+                }
+                else if (type == "Bool")
+                {
+                    arr[i] = new BoolData(i)
+                    {
+                        Value = bool.Parse(source[i])
+                    };
+                }
+                else
+                {
+                    arr[i] = new StringData(i)
+                    {
+                        Value = source[i]
+                    };
+                }
+            }
+            return arr;
+        }
+
+        private int GetLength()
+        {
+            try
+            {
+                string text = NiLength.Text;
+                if (text.Contains("."))
+                {
+                    text = text.Split('.')[0];
+                }
+                int length = int.Parse(text);
+                return length > 0 ? length : 1;
+            }
+            catch
+            {
+                return 1;
+            }
+        }
+
+        private void NiLength_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (CbIsArray.IsChecked != true)
+            {
+                return;
+            }
+            arrayInput.ItemsSource = RefreshArray(GetLength(), CbType.Text);
+        }
     }
 }

--
Gitblit v1.9.1