namespace IStation.Unit
{
///
/// 压力单位辅助类
///
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 GetCnUnitNameList()
{
var list = new List();
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
{
list.Add(GetCnUnitName(item));
}
return list;
}
public static Dictionary GetCnUnitDict()
{
var dic = new Dictionary();
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 GetEnUnitNameList()
{
var list = new List();
foreach (eUnitPR item in Enum.GetValues(typeof(eUnitPR)))
{
list.Add(GetEnUnitName(item));
}
return list;
}
public static Dictionary GetEnUnitDict()
{
var dic = new Dictionary();
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 IUnitHelper.GetCnUnitNameList()
{
return GetCnUnitNameList();
}
Dictionary IUnitHelper.GetCnUnitDict()
{
var dic = new Dictionary();
foreach (var item in GetCnUnitDict())
{
dic.Add((int)item.Key, item.Value);
}
return dic;
}
string IUnitHelper.GetEnUnitName(int unit)
{
return GetEnUnitName((eUnitPR)unit);
}
List IUnitHelper.GetEnUnitNameList()
{
return GetEnUnitNameList();
}
Dictionary IUnitHelper.GetEnUnitDict()
{
var dic = new Dictionary();
foreach (var item in GetEnUnitDict())
{
dic.Add((int)item.Key, item.Value);
}
return dic;
}
#endregion
}
}