Пример #1
0
    private string GetValue(decimal value, string unit, string currency, string currencyUnit)
    {
        if (value == decimal.MinValue)
        {
            return("-");
        }
        if (unit == "TIME")
        {
            try
            {
                KPIDataTime datatime = KPIDataTimeBLL.GetKPIDataTimeFromValue(value);
                return(datatime.TimeDescription);
            }
            catch (Exception ex)
            {
                log.Error("Error getting datatime for measurement value", ex);
            }
            return("-");
        }
        else if (unit == "PERCENT")
        {
            return((value != 0 ? value.ToString("#.##") : "0") + " %");
        }
        else if (unit == "MONEY")
        {
            string lang = LanguageUtilities.GetLanguageFromContext();
            string name = "";
            try
            {
                CurrencyUnitBLL cuBll      = new CurrencyUnitBLL();
                CurrencyBLL     cBll       = new CurrencyBLL();
                List <Currency> currencies = cBll.GetCurrencys(lang);
                CurrencyUnit    cu         = cuBll.GetCurrencyUnitsById(lang, currency, currencyUnit);
                Currency        selected   = null;
                foreach (var item in currencies)
                {
                    if (item.CurrencyID == currency)
                    {
                        selected = item;
                        break;
                    }
                }
                string currencyUnitLabel = currencyUnit == "DOL" ? "" : cu.Name + " " + Resources.KpiStats.OfLabel + " ";

                if (selected != null)
                {
                    name = currencyUnitLabel + selected.Name;
                }
                else
                {
                    name = currencyUnitLabel + currency;
                }
            }
            catch (Exception ex)
            {
                log.Error("Error getting currency data", ex);
            }
            return((value != 0 ? value.ToString("#.##") : "0") + " " + name);
        }
        else if (unit == "INT")
        {
            return(Convert.ToInt32(value).ToString());
        }
        else
        {
            return(value != 0 ? value.ToString("#.##") : "0");
        }
    }