tangxu
2023-04-10 7f8ba13a353ed3da5efbbbf623d586428f4bce96
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IStation.Formula;
 
namespace IStation.Unit
{
    /// <summary>
    /// 扬程单位辅助类
    /// </summary>
    public class UnitHHelper : IUnitHelper
    {
 
        #region 静态
 
        public static double Convert(eUnitH fromUnit, eUnitH toUnit, double fromValue)
        {
            var toValue = fromValue;
            switch (fromUnit)
            {
                case eUnitH.M:
                    {
                        switch (toUnit)
                        {
                            case eUnitH.M: break;
                            case eUnitH.MPa:toValue=CalcuHelper.M2Mpa(fromValue); break;
                            default: break;
                        }
                    }
                    break;
                case eUnitH.MPa:
                    {
                        switch (toUnit)
                        {
                            case eUnitH.M: toValue =CalcuHelper.Mpa2M(fromValue); break;
                            case eUnitH.MPa: break;
                            default: break;
                        }
                    }
                    break;
                default: break;
            }
            return toValue;
        }
 
        public static string GetCnUnitName(eUnitH unit)
        {
            switch (unit)
            {
                case eUnitH.M: return "米";
                case eUnitH.MPa: return "兆帕";
                default: return string.Empty;
            }
 
        }
 
        public static List<string> GetCnUnitNameList()
        {
            var list = new List<string>();
            foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
            {
                list.Add(GetCnUnitName(item));
            }
            return list;
        }
 
        public static Dictionary<eUnitH, string> GetCnUnitDict()
        {
            var dic = new Dictionary<eUnitH, string>();
            foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
            {
                dic.Add(item, GetCnUnitName(item));
            }
            return dic;
        }
 
        public static string GetEnUnitName(eUnitH unit)
        {
            switch (unit)
            {
                case eUnitH.M: return "m";
                case eUnitH.MPa: return "MPa";
                default: return string.Empty;
            }
        }
 
        public static List<string> GetEnUnitNameList()
        {
            var list = new List<string>();
            foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
            {
                list.Add(GetEnUnitName(item));
            }
            return list;
        }
 
        public static Dictionary<eUnitH, string> GetEnUnitDict()
        {
            var dic = new Dictionary<eUnitH, string>();
            foreach (eUnitH item in Enum.GetValues(typeof(eUnitH)))
            {
                dic.Add(item, GetEnUnitName(item));
            }
            return dic;
        }
 
 
 
 
        #endregion
 
        #region 显示接口
 
 
        double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
        {
            return Convert((eUnitH)fromUnit, (eUnitH)toUnit, fromValue);
        }
 
        string IUnitHelper.GetCnUnitName(int unit)
        {
            return GetCnUnitName((eUnitH)unit);
        }
 
        List<string> IUnitHelper.GetCnUnitNameList()
        {
            return GetCnUnitNameList();
        }
 
        Dictionary<int, string> IUnitHelper.GetCnUnitDict()
        {
            var dic = new Dictionary<int, string>();
            foreach (var item in GetCnUnitDict())
            {
                dic.Add((int)item.Key, item.Value);
            }
            return dic;
        }
 
        string IUnitHelper.GetEnUnitName(int unit)
        {
            return GetEnUnitName((eUnitH)unit);
        }
 
        List<string> IUnitHelper.GetEnUnitNameList()
        {
            return GetEnUnitNameList();
        }
 
        Dictionary<int, string> IUnitHelper.GetEnUnitDict()
        {
            var dic = new Dictionary<int, string>();
            foreach (var item in GetEnUnitDict())
            {
                dic.Add((int)item.Key, item.Value);
            }
            return dic;
        }
 
 
 
 
        #endregion
    }
}