using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.Unit
|
{
|
/// <summary>
|
/// 长度单位枚举
|
/// </summary>
|
public class UnitLHelper:IUnitHelper
|
{
|
#region 静态
|
|
public static double Convert(eUnitL fromUnit, eUnitL toUnit, double fromValue)
|
{
|
var toValue = fromValue;
|
switch (fromUnit)
|
{
|
case eUnitL.m:
|
{
|
switch (toUnit)
|
{
|
case eUnitL.m:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitL.dm:
|
{
|
toValue = fromValue *10;
|
}
|
break;
|
case eUnitL.cm:
|
{
|
toValue = fromValue *100;
|
}
|
break;
|
case eUnitL.mm:
|
{
|
toValue = fromValue *1000;
|
}
|
break;
|
|
default: break;
|
}
|
|
}
|
break;
|
case eUnitL.dm:
|
{
|
switch (toUnit)
|
{
|
case eUnitL.m:
|
{
|
toValue = fromValue/10;
|
}
|
break;
|
case eUnitL.dm:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitL.cm:
|
{
|
toValue = fromValue * 10;
|
}
|
break;
|
case eUnitL.mm:
|
{
|
toValue = fromValue * 100;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
case eUnitL.cm:
|
{
|
switch (toUnit)
|
{
|
case eUnitL.m:
|
{
|
toValue = fromValue / 100;
|
}
|
break;
|
case eUnitL.dm:
|
{
|
toValue = fromValue/10;
|
}
|
break;
|
case eUnitL.cm:
|
{
|
toValue = fromValue;
|
}
|
break;
|
case eUnitL.mm:
|
{
|
toValue = fromValue * 10;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
case eUnitL.mm:
|
{
|
switch (toUnit)
|
{
|
case eUnitL.m:
|
{
|
toValue = fromValue / 1000;
|
}
|
break;
|
case eUnitL.dm:
|
{
|
toValue = fromValue / 100;
|
}
|
break;
|
case eUnitL.cm:
|
{
|
toValue = fromValue/10;
|
}
|
break;
|
case eUnitL.mm:
|
{
|
toValue = fromValue;
|
}
|
break;
|
|
default: break;
|
}
|
}
|
break;
|
|
default: break;
|
}
|
return toValue;
|
}
|
|
public static string GetCnUnitName(eUnitL unit)
|
{
|
switch (unit)
|
{
|
case eUnitL.m: return "米";
|
case eUnitL.dm: return "分米";
|
case eUnitL.cm: return "厘米";
|
case eUnitL.mm: return "毫米";
|
default: return string.Empty;
|
}
|
}
|
|
public static List<string> GetCnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitL item in Enum.GetValues(typeof(eUnitL)))
|
{
|
list.Add(GetCnUnitName(item));
|
}
|
return list;
|
}
|
|
public static Dictionary<eUnitL, string> GetCnUnitDict()
|
{
|
var dic = new Dictionary<eUnitL, string>();
|
foreach (eUnitL item in Enum.GetValues(typeof(eUnitL)))
|
{
|
dic.Add(item, GetCnUnitName(item));
|
}
|
return dic;
|
}
|
|
public static string GetEnUnitName(eUnitL unit)
|
{
|
switch (unit)
|
{
|
case eUnitL.m: return "m";
|
case eUnitL.dm: return "dm";
|
case eUnitL.cm: return "cm";
|
case eUnitL.mm: return "mm";
|
default: return string.Empty;
|
}
|
}
|
|
|
|
|
public static List<string> GetEnUnitNameList()
|
{
|
var list = new List<string>();
|
foreach (eUnitL item in Enum.GetValues(typeof(eUnitL)))
|
{
|
list.Add(GetEnUnitName(item));
|
}
|
return list;
|
}
|
|
|
|
|
public static Dictionary<eUnitL, string> GetEnUnitDict()
|
{
|
var dic = new Dictionary<eUnitL, string>();
|
foreach (eUnitL item in Enum.GetValues(typeof(eUnitL)))
|
{
|
dic.Add(item, GetEnUnitName(item));
|
}
|
return dic;
|
}
|
|
|
|
|
#endregion
|
|
#region 显示接口
|
|
|
double IUnitHelper.Convert(int fromUnit, int toUnit, double fromValue)
|
{
|
return Convert((eUnitL)fromUnit, (eUnitL)toUnit, fromValue);
|
}
|
|
string IUnitHelper.GetCnUnitName(int unit)
|
{
|
return GetCnUnitName((eUnitL)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((eUnitL)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
|
}
|
}
|