using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.Unit
|
{
|
/// <summary>
|
/// 压力单位辅助类
|
/// </summary>
|
public class UnitPRHelper : IUnitHelper
|
{
|
#region 静态
|
|
public static double Convert(eUnitPR fromUnit, eUnitPR toUnit, double fromValue)
|
{
|
var toValue = fromValue;
|
switch (fromUnit)
|
{
|
case eUnitPR.Pa:
|
{
|
switch (toUnit)
|
{
|
case eUnitPR.Pa:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitPR.MPa:
|
{
|
toValue = fromValue / 1000000;
|
}
|
break;
|
case eUnitPR.KPa:
|
{
|
toValue = fromValue / 1000;
|
}
|
break;
|
case eUnitPR.Bar:
|
{
|
toValue = fromValue / 100000;
|
}
|
break;
|
|
default: break;
|
}
|
|
}
|
break;
|
case eUnitPR.MPa:
|
{
|
switch (toUnit)
|
{
|
case eUnitPR.Pa:
|
{
|
toValue = fromValue * 1000000;
|
}
|
break;
|
case eUnitPR.MPa:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitPR.KPa:
|
{
|
toValue = fromValue * 1000;
|
}
|
break;
|
case eUnitPR.Bar:
|
{
|
toValue = fromValue * 10;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
case eUnitPR.KPa:
|
{
|
switch (toUnit)
|
{
|
case eUnitPR.Pa:
|
{
|
toValue = fromValue * 1000;
|
}
|
break;
|
case eUnitPR.MPa:
|
{
|
toValue = fromValue / 1000;
|
}
|
break;
|
case eUnitPR.KPa:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitPR.Bar:
|
{
|
toValue = fromValue / 100;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
case eUnitPR.Bar:
|
{
|
switch (toUnit)
|
{
|
case eUnitPR.Pa:
|
{
|
|
toValue = fromValue * 100000;
|
}
|
break;
|
case eUnitPR.MPa:
|
{
|
toValue = fromValue / 10;
|
}
|
break;
|
case eUnitPR.KPa:
|
{
|
toValue = fromValue * 100;
|
}
|
break;
|
case eUnitPR.Bar:
|
{
|
toValue = fromValue;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
|
default: break;
|
}
|
return toValue;
|
}
|
|
public static string GetCnUnitName(eUnitPR unit)
|
{
|
switch (unit)
|
{
|
case eUnitPR.Pa: return "帕斯卡";
|
case eUnitPR.MPa: return "兆帕";
|
case eUnitPR.KPa: return "千帕";
|
case eUnitPR.Bar: return "巴";
|
default: return string.Empty;
|
}
|
|
}
|
|
public static List<string> GetCnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
|
{
|
list.Add(GetCnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitPR, string> GetCnUnitDict()
|
{
|
var dic = new Dictionary<eUnitPR, string>();
|
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
|
{
|
dic.Add(item, GetCnUnitName(item));
|
}
|
return dic;
|
}
|
|
public static string GetEnUnitName(eUnitPR unit)
|
{
|
switch (unit)
|
{
|
case eUnitPR.Pa: return "Pa";
|
case eUnitPR.MPa: return "MPa";
|
case eUnitPR.KPa: return "KPa";
|
case eUnitPR.Bar: return "bar";
|
default: return string.Empty;
|
}
|
}
|
|
|
|
|
public static List<string> GetEnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
|
{
|
list.Add(GetEnUnitName(item));
|
}
|
return list;
|
}
|
|
|
|
|
public static Dictionary<eUnitPR, string> GetEnUnitDict()
|
{
|
var dic = new Dictionary<eUnitPR, string>();
|
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
|
{
|
dic.Add(item, GetEnUnitName(item));
|
}
|
return dic;
|
}
|
|
|
|
|
#endregion
|
|
#region 显示接口
|
|
|
double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
|
{
|
return Convert((eUnitPR)fromUnit, (eUnitPR)toUnit, fromValue);
|
}
|
|
string IUnitHelper.GetCnUnitName(int unit)
|
{
|
return GetCnUnitName((eUnitPR)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((eUnitPR)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
|
}
|
}
|