using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace IStation.Unit { /// /// 单位辅助类 /// public class UnitHelper { /// /// 获取单位辅助类接口对象 /// public static IUnitHelper GetUnitHelper(eUnitType unitType) { IUnitHelper helper = null; switch (unitType) { case eUnitType.未知: break; case eUnitType.流量:helper = new UnitQHelper();break; case eUnitType.压力:helper = new UnitPRHelper();break; case eUnitType.扬程:helper = new UnitHHelper();break; case eUnitType.体积:helper = new UnitVolHeper();break; case eUnitType.频率:helper = new UnitHZHelper();break; case eUnitType.电流:helper = new UnitCurrentHelper();break; case eUnitType.电压:helper = new UnitVoltageHelper();break; case eUnitType.转速:helper = new UnitNHelper();break; case eUnitType.效率:helper = new UnitEHelper();break; case eUnitType.有功功率:helper = new UnitPHelper();break; case eUnitType.无功功率:helper = new UnitPQHelper();break; case eUnitType.视在功率:helper = new UnitPsHelper();break; case eUnitType.有功电度:helper = new UnitDegreeHelper();break; case eUnitType.无功电度:helper = new UnitDegreeQHelper();break; case eUnitType.长度:helper = new UnitLHelper();break; case eUnitType.温度:helper = new UnitTPHelper();break; case eUnitType.浊度:helper = new UnitTUHelper();break; case eUnitType.浓度:helper = new UnitCOHelper();break; case eUnitType.湿度:helper = new UnitHMHelper();break; case eUnitType.电导率:helper = new UnitCondHelper();break; case eUnitType.音量:helper = new UnitSouHelper();break; case eUnitType.累积时间:helper = new UnitSumTimeHelper();break; case eUnitType.千吨能耗:helper = new UnitWPHelper();break; case eUnitType.单位能耗:helper = new UnitUWPHelper();break; case eUnitType.速度:helper = new UnitSpeedHelper();break; case eUnitType.加速度:helper = new UnitGSpeedHelper();break; case eUnitType.自定义: break; default: break; } return helper; } /// /// 获取英文字典 /// public static Dictionary GetEnUnitDict(eUnitType unitType) { var helper = GetUnitHelper(unitType); return helper?.GetEnUnitDict(); } /// /// 获取英文名称 /// public static string GetEnUnitName(eUnitType unitType, int unitValue) { var helper = GetUnitHelper(unitType); if (helper == null) return unitValue.ToString(); var name = helper.GetEnUnitName(unitValue); if (string.IsNullOrEmpty(name)) return unitValue.ToString(); else return name; } /// /// 获取英文名称 /// public static string GetEnUnitName(eUnitType unitType, string unitValue) { switch (unitType) { case eUnitType.未知: return unitValue; case eUnitType.自定义: return unitValue; default: break; } if (!int.TryParse(unitValue, out int unitValue_int)) return string.Empty; var helper = GetUnitHelper(unitType); if (helper == null) return string.Empty; var name = helper.GetEnUnitName(unitValue_int); if (name == null) return string.Empty; else return name; } /// /// 获取中文字典 /// public static Dictionary GetCnUnitDict(eUnitType unitType) { var helper = GetUnitHelper(unitType); return helper?.GetCnUnitDict(); } /// /// 获取中文名称 /// public static string GetCnUnitName(eUnitType unitType, int unitValue) { var helper = GetUnitHelper(unitType); if (helper == null) return string.Empty; var name = helper.GetCnUnitName(unitValue); if (name == null) return string.Empty; else return name; } /// /// 获取中文名称 /// public static string GetCnUnitName(eUnitType unitType, string unitValue) { switch (unitType) { case eUnitType.未知: return unitValue; case eUnitType.自定义: return unitValue; default: break; } if (!int.TryParse(unitValue, out int unitValue_int)) return string.Empty; var helper = GetUnitHelper(unitType); if (helper == null) return string.Empty; var name = helper.GetCnUnitName(unitValue_int); if (name == null) return string.Empty; else return name; } } }