From 1afe548ac40cc7f975917ef9bf2e156595cf81f3 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 16 四月 2026 08:58:04 +0800
Subject: [PATCH] 优化;
---
HMI.ParameterManage/SettingModal.xaml.cs | 204 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 193 insertions(+), 11 deletions(-)
diff --git a/HMI.ParameterManage/SettingModal.xaml.cs b/HMI.ParameterManage/SettingModal.xaml.cs
index 98f2993..22569d6 100644
--- a/HMI.ParameterManage/SettingModal.xaml.cs
+++ b/HMI.ParameterManage/SettingModal.xaml.cs
@@ -3,17 +3,62 @@
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.Text.RegularExpressions;
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>
@@ -93,6 +138,9 @@
{
Data.Name = TbName.Text;
Data.Type = CbType.Text;
+ Data.IsArray = CbIsArray.IsChecked == true;
+ Data.Length = int.Parse(NiLength.Text);
+
Data.Value = GetTargetValue();
Data.Unit = TbUnit.Text;
Data.Description = TbDescription.Text;
@@ -102,14 +150,23 @@
return flag;
}
- public bool? Open(ParameterData data, ObservableCollection<ParameterData> datasource, List<string> groups)
+ 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;
+ CbIsArray.IsChecked = Data.IsArray;
+ NiLength.Text = Data.Length.ToString();
+
UpdateWindow(Data.Type);
UpdateForm(Data);
@@ -122,11 +179,18 @@
private string GetTargetValue()
{
- if (CbType.Text == "Int" || Data.Type == "Double")
+ 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 (CbType.Text == "Bool")
+ else if (type == "Bool")
{
return CbBoolValue.Text;
}
@@ -138,17 +202,25 @@
private void UpdateForm(ParameterData data)
{
- if (Data.Type == "Int" || Data.Type == "Int")
+ if (data.IsArray)
{
- NiNumberValue.Text = Data.Value;
- }
- else if (Data.Type == "Bool")
- {
- CbBoolValue.SelectedValue = Data.Value;
+ string[] arr = data.Value.Split(',');
+ arrayInput.ItemsSource = RefreshArray(arr, Data.Type);
}
else
{
- TbStringValue.Text = Data.Value;
+ 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;
+ }
}
}
@@ -182,6 +254,10 @@
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)
@@ -192,5 +268,111 @@
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