/// <summary> /// Filling the FiveYearDataModels type list /// </summary> /// <param name="CurrentYear">Value of Current System Year</param> public void AddDataToFiveYearModels(int CurrentYear) { if (FiveYearMacroCountryData != null) { FiveYearMacroCountryData.Clear(); } if (CurrentYear >= 2024 || CurrentYear <= 1989) { return; } List <FiveYearDataModels> result = new List <FiveYearDataModels>(); for (int i = 0; i < macroCountryData.Count; i++) { int valueOfCurrentYear = DateTime.Now.Year; MacroDatabaseKeyAnnualReportData m = new MacroDatabaseKeyAnnualReportData(); FiveYearDataModels entry = new FiveYearDataModels(); entry.CategoryName = macroCountryData[i].CATEGORY_NAME; entry.CountryName = macroCountryData[i].COUNTRY_NAME; entry.Description = macroCountryData[i].DESCRIPTION; entry.DisplayType = macroCountryData[i].DISPLAY_TYPE; entry.SortOrder = macroCountryData[i].SORT_ORDER; entry.YearOne = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear - 3)); entry.YearTwo = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear - 2)); entry.YearThree = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear - 1)); entry.YearFour = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear)); entry.YearFive = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear + 1)); entry.YearSix = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (CurrentYear + 2)); Decimal?Value1 = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (valueOfCurrentYear - 4)); Decimal?Value2 = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (valueOfCurrentYear - 3)); Decimal?Value3 = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (valueOfCurrentYear - 2)); Decimal?Value4 = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (valueOfCurrentYear - 1)); Decimal?Value5 = GetProperty <Decimal?>(macroCountryData[i], "YEAR_" + (valueOfCurrentYear)); if (Value1 == null) { Value1 = 0; } if (Value2 == null) { Value2 = 0; } if (Value3 == null) { Value3 = 0; } if (Value4 == null) { Value4 = 0; } if (Value5 == null) { Value5 = 0; } entry.FiveYearAvg = (Value1 + Value2 + Value3 + Value4 + Value5) / 5; result.Add(entry); } FiveYearMacroCountryData = result; }
/// <summary> /// Gets the property value by name /// </summary> /// <typeparam name="T"></typeparam> /// <param name="m"></param> /// <param name="propertyName">Name of the property</param> /// <returns></returns> public static T GetProperty <T>(MacroDatabaseKeyAnnualReportData m, string propertyName) { var theProperty = m.GetType().GetProperty(propertyName); if (theProperty == null) { throw new ArgumentException("object does not have an " + propertyName + " property", "m"); } if (theProperty.PropertyType.FullName != typeof(T).FullName) { throw new ArgumentException("object has an Id property, but it is not of type " + typeof(T).FullName, "m"); } return((T)theProperty.GetValue(m, null)); }