using System;
|
using System.Collections.Generic;
|
|
namespace IStation.Unit
|
{
|
/// <summary>
|
/// 效率单位辅助类
|
/// </summary>
|
public class UnitEHelper : IUnitHelper
|
{
|
|
#region 静态
|
|
public static double Convert(eUnitE fromUnit, eUnitE toUnit, double fromValue)
|
{
|
var toValue = fromValue;
|
switch (fromUnit)
|
{
|
case eUnitE.Percent:
|
{
|
switch (toUnit)
|
{
|
case eUnitE.Percent: break;
|
case eUnitE.Ratio: toValue = fromValue / 100; break;
|
default: break;
|
}
|
}
|
break;
|
case eUnitE.Ratio:
|
{
|
switch (toUnit)
|
{
|
case eUnitE.Percent: toValue = fromValue * 100; break;
|
case eUnitE.Ratio: break;
|
default: break;
|
}
|
}
|
break;
|
default: break;
|
}
|
return toValue;
|
}
|
|
public static string GetCnUnitName(eUnitE unit)
|
{
|
switch (unit)
|
{
|
case eUnitE.Percent: return "百分率";
|
case eUnitE.Ratio: return "比值";
|
default: return string.Empty;
|
}
|
|
}
|
|
public static List<string> GetCnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitE item in Enum.GetValues(typeof(eUnitE)))
|
{
|
list.Add(GetCnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitE, string> GetCnUnitDict()
|
{
|
var dic = new Dictionary<eUnitE, string>();
|
foreach (eUnitE item in Enum.GetValues(typeof(eUnitE)))
|
{
|
dic.Add(item, GetCnUnitName(item));
|
}
|
return dic;
|
}
|
|
public static string GetEnUnitName(eUnitE unit)
|
{
|
switch (unit)
|
{
|
case eUnitE.Percent: return "%";
|
case eUnitE.Ratio: return "";
|
default: return string.Empty;
|
}
|
}
|
|
|
|
|
public static List<string> GetEnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitE item in Enum.GetValues(typeof(eUnitE)))
|
{
|
list.Add(GetEnUnitName(item));
|
}
|
return list;
|
}
|
|
|
|
|
public static Dictionary<eUnitE, string> GetEnUnitDict()
|
{
|
var dic = new Dictionary<eUnitE, string>();
|
foreach (eUnitE item in Enum.GetValues(typeof(eUnitE)))
|
{
|
dic.Add(item, GetEnUnitName(item));
|
}
|
return dic;
|
}
|
|
|
|
|
#endregion
|
|
#region 显示接口
|
|
|
double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
|
{
|
return Convert((eUnitE)fromUnit, (eUnitE)toUnit, fromValue);
|
}
|
|
string IUnitHelper.GetCnUnitName(int unit)
|
{
|
return GetCnUnitName((eUnitE)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((eUnitE)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
|
}
|
}
|