ningshuxia
2023-04-13 13aeccc4305083d2d61274709a0066511fae42a1
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
using IStation.Unit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Model
{
    /// <summary>
    /// 单位系数换算
    /// </summary>
    public class UnitRatioMatrix : JsonModel<UnitRatioMatrix>
    {
        /// <summary>
        /// 单位类型
        /// </summary>
        public eUnitType UnitType { get; set; }
 
        /// <summary>
        /// 原始单位
        /// </summary>
        public int FromUnit { get; set; }
 
        /// <summary>
        /// 目标单位
        /// </summary>
        public int ToUnit { get; set; }
 
 
        /// <summary>
        /// 转换
        /// </summary>
        public double Matrix(double value)
        {
            var helper = UnitHelper.GetUnitHelper(UnitType);
            return helper.Convert(FromUnit, ToUnit, value);
        }
 
        /// <summary>
        /// 获取表达式
        /// </summary>
        public string GetExpression()
        {
            return $"{UnitHelper.GetEnUnitName(UnitType, FromUnit)}=>{UnitHelper.GetEnUnitName(UnitType, ToUnit)}";
        }
    }
}