alielie
2025-03-17 c401a2f2fd1a509cdeb33e850bb5c2827074af48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using HMI.Core.Util;
using HMI.ParameterManage.Entity;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
 
namespace HMI.ParameterManage.Util
{
    /// <summary>
    /// TODO 优化数据源,需要支持sqlite和xml
    /// </summary>
    public class ParameterManager
    {
        /// <summary>
        /// 获取保存的产品
        /// </summary>
        /// <returns></returns>
        public static T GetProducts<T>() where T : IList<ProductData>
        {
            string path = Path.Combine(ParameterManage.FileFolder, "Product.setting");
            if (!File.Exists(path)) return default(T);
            T datas = XmlHelper.DeserializeFromXml<T>(path);
            return datas;
        }
 
        /// <summary>
        /// 根据产品名称获取产品参数
        /// </summary>
        /// <param name="productName"></param>
        /// <returns></returns>
        public static List<ParameterData> GetParametersByProductName(string productName)
        {
            string path = Path.Combine(ParameterManage.FileFolder, "Parameter", $"Parameter_{productName}.setting");
            if (!File.Exists(path)) return new List<ParameterData>();
            List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(path);
            return datas;
        }
 
        /// <summary>
        /// 获取通用参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetCommonParameter<T>() where T : IList<ParameterData>
        {
            string path = Path.Combine(ParameterManage.FileFolder, "CommonParameter.setting");
            if (!File.Exists(path)) return default(T);
            T datas = XmlHelper.DeserializeFromXml<T>(path);
            return datas;
        }
 
        /// <summary>
        /// 保存通用参数
        /// </summary>
        /// <param name="datas"></param>
        /// <exception cref="Exception"></exception>
        public static void SaveCommonParameter(IList<ParameterData> datas)
        {
            if (datas == null)
            {
                throw new Exception("不能为null");
            }
            string path = Path.Combine(ParameterManage.FileFolder, "CommonParameter.setting");
            XmlHelper.SerializeToXml(path, datas);
        }
 
    }
}