From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 SimpleUtil/HMI.Simple.Util/ProductUtil.cs |  147 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/SimpleUtil/HMI.Simple.Util/ProductUtil.cs b/SimpleUtil/HMI.Simple.Util/ProductUtil.cs
new file mode 100644
index 0000000..fe8c631
--- /dev/null
+++ b/SimpleUtil/HMI.Simple.Util/ProductUtil.cs
@@ -0,0 +1,147 @@
+锘縰sing NationalInstruments.TestStand.Interop.API;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace HMI.Simple.Util
+{
+    public class ProductUtil
+    {
+        private static void WriteParameterData(object instance, ParameterData data)
+        {
+            SequenceContext context = (SequenceContext)instance;
+            string name = $"DUTSetting.{data.Name}";
+
+            if (data.IsArray)
+            {
+                PropertyValueTypes type;
+                if (data.Type == "Bool")
+                {
+                    type = PropertyValueTypes.PropValType_Boolean;
+                }
+                else if (data.Type == "Int")
+                {
+                    type = PropertyValueTypes.PropValType_Number;
+                }
+                else if (data.Type == "Double")
+                {
+                    type = PropertyValueTypes.PropValType_Number;
+                }
+                else
+                {
+                    type = PropertyValueTypes.PropValType_String;
+                }
+                string[] arr = data.Value?.Split(',') ?? new string[0];
+                if (arr.Length > 0)
+                {
+                    context.FileGlobals.DeleteSubProperty(name, 2);
+
+                    context.FileGlobals.NewSubProperty(name, type, true, null, 1);
+                    context.FileGlobals.GetPropertyObject(name, 0).SetNumElements(arr.Length);
+                    for (int i = 0; i < arr.Length; i++)
+                    {
+                        if (type == PropertyValueTypes.PropValType_String)
+                        {
+                            context.FileGlobals.SetValString($"{name}[{i}]", 0, arr[i]);
+                        }
+                        if (data.Type == "Int")
+                        {
+                            context.FileGlobals.SetValNumber($"{name}[{i}]", 0, int.Parse(arr[i]));
+                        }
+                        if (data.Type == "Double")
+                        {
+                            context.FileGlobals.SetValNumber($"{name}[{i}]", 0, double.Parse(arr[i]));
+                        }
+                        if (data.Type == "Bool")
+                        {
+                            context.FileGlobals.SetValBoolean($"{name}[{i}]", 0, bool.Parse(arr[i]));
+                        }
+                    }
+                }
+            }
+            else
+            {
+                if (data.Type == "Bool")
+                {
+                    context.FileGlobals.SetValBoolean(name, 1, bool.Parse(data.Value));
+                }
+                else if (data.Type == "Int")
+                {
+                    context.FileGlobals.SetValNumber(name, 1, int.Parse(data.Value));
+                }
+                else if (data.Type == "Double")
+                {
+                    context.FileGlobals.SetValNumber(name, 1, double.Parse(data.Value));
+                }
+                else
+                {
+                    context.FileGlobals.SetValString(name, 1, data.Value);
+                }
+            }
+
+
+        }
+
+        private static string GetDataFilePath()
+        {
+            string path = ParameterUtil.GetCommonParameterValue("ShareConfig", out _);
+            if (path == null)
+            {
+                path = Path.Combine(RegUtil.GetLocaltion(), "Config");
+            }
+            return path;
+        }
+
+        /// <summary>
+        /// 鏍规嵁浜у搧鍨嬪彿鍐欓厤缃�
+        /// </summary>
+        /// <param name="model">浜у搧鍨嬪彿</param>
+        /// <param name="instance">TestStand涓婁笅鏂�</param>
+        /// <param name="errMsg">寮傚父淇℃伅</param>
+        /// <returns>鏄惁鎴愬姛</returns>
+        public static bool WriteConfigToContextByModel(string model, object instance, out string errMsg)
+        {
+            errMsg = string.Empty;
+            try
+            {
+                string path = Path.Combine(GetDataFilePath(), "Product", "Parameter", $"Parameter_{model}.data");
+                return WriteConfigToContextByPath(path, instance, out errMsg);
+            }
+            catch (Exception ex)
+            {
+                errMsg = ex.Message;
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 鏍规嵁璺緞鍐欓厤缃�
+        /// </summary>
+        /// <param name="path">缁濆璺緞</param>
+        /// <param name="instance">TestStand涓婁笅鏂�</param>
+        /// <param name="errMsg">寮傚父淇℃伅</param>
+        /// <returns>鏄惁鎴愬姛</returns>
+        public static bool WriteConfigToContextByPath(string path, object instance, out string errMsg)
+        {
+            errMsg = string.Empty;
+            try
+            {
+                if (!File.Exists(path))
+                {
+                    throw new Exception($"鏈壘鍒拌閰嶇疆[{path}]锛岃妫�鏌�");
+                }
+                List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(path);
+                foreach (var data in datas)
+                {
+                    WriteParameterData(instance, data);
+                }
+                return true;
+            }
+            catch (Exception ex)
+            {
+                errMsg = ex.Message;
+                return false;
+            }
+        }
+    }
+}

--
Gitblit v1.9.1