using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.Unit
|
{
|
/// <summary>
|
/// 体积单位辅助类
|
/// </summary>
|
public class UnitVolHeper:IUnitHelper
|
{
|
#region 静态
|
|
public static double Convert(eUnitVol fromUnit, eUnitVol toUnit, double fromValue)
|
{
|
var toValue = fromValue;
|
switch (fromUnit)
|
{
|
case eUnitVol.L:
|
{
|
switch (toUnit)
|
{
|
case eUnitVol.L:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitVol.M3:
|
{
|
toValue = fromValue / 1000;
|
}
|
break;
|
default: break;
|
}
|
}
|
break;
|
case eUnitVol.M3:
|
{
|
switch (toUnit)
|
{
|
case eUnitVol.L:
|
{
|
toValue = fromValue * 1000;
|
}
|
break;
|
case eUnitVol.M3:
|
{
|
toValue = fromValue;
|
}
|
break;
|
|
|
default: break;
|
}
|
}
|
break;
|
|
|
default: break;
|
}
|
return toValue;
|
}
|
|
public static string GetCnUnitName(eUnitVol unit)
|
{
|
switch (unit)
|
{
|
case eUnitVol.L: return "升";
|
case eUnitVol.M3: return "立方米";
|
|
default: return string.Empty;
|
}
|
|
}
|
|
public static List<string> GetCnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitVol item in Enum.GetValues(typeof(eUnitVol)))
|
{
|
list.Add(GetCnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitVol, string> GetCnUnitDict()
|
{
|
var dic = new Dictionary<eUnitVol, string>();
|
foreach (eUnitVol item in Enum.GetValues(typeof(eUnitVol)))
|
{
|
dic.Add(item, GetCnUnitName(item));
|
}
|
return dic;
|
}
|
|
public static string GetEnUnitName(eUnitVol unit)
|
{
|
switch (unit)
|
{
|
case eUnitVol.L: return "L";
|
case eUnitVol.M3: return "m³";
|
|
default: return string.Empty;
|
}
|
}
|
|
|
|
|
public static List<string> GetEnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitVol item in Enum.GetValues(typeof(eUnitVol)))
|
{
|
list.Add(GetEnUnitName(item));
|
}
|
return list;
|
}
|
|
|
|
|
public static Dictionary<eUnitVol, string> GetEnUnitDict()
|
{
|
var dic = new Dictionary<eUnitVol, string>();
|
foreach (eUnitVol item in Enum.GetValues(typeof(eUnitVol)))
|
{
|
dic.Add(item, GetEnUnitName(item));
|
}
|
return dic;
|
}
|
|
|
|
|
#endregion
|
|
#region 显示接口
|
|
|
double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
|
{
|
return Convert((eUnitVol)fromUnit, (eUnitVol)toUnit, fromValue);
|
}
|
|
string IUnitHelper.GetCnUnitName(int unit)
|
{
|
return GetCnUnitName((eUnitVol)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((eUnitVol)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
|
}
|
}
|