Ejemplo n.º 1
0
        public static KPIDataTime GetKPIDataTimeFromValue(decimal value)
        {
            if (value <= 0)
            {
                throw new ArgumentException("The value cannor be zero.");
            }

            KPIDataTime theData = null;

            try
            {
                KPIDataTimeTableAdapter            localAdapter = new KPIDataTimeTableAdapter();
                KPIDataTimeDS.KPIDataTimeDataTable theTable     = localAdapter.GetKPIDataTimeFromValue(value);
                if (theTable != null && theTable.Rows.Count > 0)
                {
                    KPIDataTimeDS.KPIDataTimeRow theRow = theTable[0];
                    theData = FillRecord(theRow);
                }
            }
            catch (Exception exc)
            {
                log.Error("Error en GetKPIDataTimeFromValue para value: " + value, exc);
                throw exc;
            }

            return(theData);
        }
Ejemplo n.º 2
0
        private static KPIDataTime FillRecord(KPIDataTimeDS.KPIDataTimeRow row)
        {
            KPIDataTime theNewRecord = new KPIDataTime(
                row.IsyearNull() ? 0 : row.year,
                row.IsmonthNull() ? 0 : row.month,
                row.IsdayNull() ? 0 : row.day,
                row.IshourNull() ? 0 : row.hour,
                row.IsminuteNull() ? 0 : row.minute);

            return(theNewRecord);
        }
Ejemplo n.º 3
0
    private KPIDataTime GetMeasurementTime(string value, Regex regexTime)
    {
        KPIDataTime theData  = new KPIDataTime();
        Match       matches  = regexTime.Match(value);
        bool        haveTime = false;

        if (matches.Success)
        {
            for (int g = 1; g <= matches.Groups.Count; g++)
            {
                if (string.IsNullOrEmpty(matches.Groups[g].Value))
                {
                    continue;
                }
                else if (matches.Groups[g].Value.Contains("T"))
                {
                    haveTime = true;
                }
                else if (matches.Groups[g].Value.Contains("Y"))
                {
                    theData.Year = Convert.ToInt32(matches.Groups[g].Value.Replace("Y", ""));
                }
                else if (matches.Groups[g].Value.Contains("M"))
                {
                    if (haveTime)
                    {
                        theData.Minute = Convert.ToInt32(matches.Groups[g].Value.Replace("M", ""));
                    }
                    else
                    {
                        theData.Month = Convert.ToInt32(matches.Groups[g].Value.Replace("M", ""));
                    }
                }
                else if (matches.Groups[g].Value.Contains("D"))
                {
                    theData.Day = Convert.ToInt32(matches.Groups[g].Value.Replace("D", ""));
                }
                else if (matches.Groups[g].Value.Contains("H"))
                {
                    theData.Hour = Convert.ToInt32(matches.Groups[g].Value.Replace("H", ""));
                }
            }
        }

        return(theData);
    }
Ejemplo n.º 4
0
        public static decimal GetValueFromKPIDataTime(KPIDataTime theData)
        {
            if (theData.Year <= 0 && theData.Month <= 0 && theData.Day <= 0 && theData.Hour <= 0 && theData.Minute <= 0)
            {
                throw new ArgumentException("The data cannot be zero.");
            }

            decimal?valor = 0;

            try
            {
                KPIDataTimeTableAdapter localAdapter = new KPIDataTimeTableAdapter();
                localAdapter.GetValueFromKPIDataTime(theData.Year, theData.Month, theData.Day, theData.Hour, theData.Minute, ref valor);
            }
            catch (Exception ex)
            {
                log.Error("Error en GetValueFromKPIDataTime para los datos year: " + theData.Year + ", month: " + theData.Month +
                          ", day: " + theData.Day + ", hour: " + theData.Hour + " y minute: " + theData.Minute, ex);
                throw ex;
            }

            return(Convert.ToDecimal(valor));
        }
Ejemplo n.º 5
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");
        }
    }