private void FillDictionary(OleDbCommand command, OleDbConnection connection, Dictionary<int, AdminLevelIndicators> dic, ReportOptions options, Func<OleDbDataReader, bool, ReportOptions, string> getKey, Func<OleDbDataReader, string> getName, Func<OleDbDataReader, string> getColTypeName, Action<CreateAggParams> addStaticIndicators, bool isCalcRelated, bool isDemoOrDistro, int entityTypeId, List<IndicatorDropdownValue> dropdownOptions) { using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string indicatorName = getName(reader); string indicatorKey = getKey(reader, options.IsNoAggregation, options) + isCalcRelated; int adminLevelId = reader.GetValueOrDefault<int>("AID"); int dataType = reader.GetValueOrDefault<int>("DataTypeId"); if (!dic.ContainsKey(adminLevelId)) continue; string val = reader.GetValueOrDefault<string>("DynamicValue"); if (dataType == (int)IndicatorDataType.LargeText && !string.IsNullOrEmpty(reader.GetValueOrDefault<string>("MemoValue"))) val = reader.GetValueOrDefault<string>("MemoValue"); var newIndicator = new AggregateIndicator { IndicatorId = reader.GetValueOrDefault<int>("IndicatorId"), Name = indicatorName, Key = reader.GetValueOrDefault<string>("IndicatorName"), DataType = dataType, Value = val, AggType = reader.GetValueOrDefault<int>("AggTypeId"), Year = Util.GetYearReported(options.MonthYearStarts, reader.GetValueOrDefault<DateTime>("DateReported")), ReportedDate = reader.GetValueOrDefault<DateTime>("DateReported"), IsCalcRelated = isCalcRelated, ColumnTypeName = getColTypeName(reader), TypeId = reader.GetValueOrDefault<int>("Tid"), TypeName = reader.GetValueOrDefault<string>("TName"), FormId = reader.GetValueOrDefault<int>("ID"), EntityTypeId = entityTypeId }; // if the adminlevel already contains the indicator for that year, aggregate if (dic[adminLevelId].Indicators.ContainsKey(indicatorKey) && !isDemoOrDistro) { dic[adminLevelId].Indicators[indicatorKey] = IndicatorAggregator.Aggregate(newIndicator, dic[adminLevelId].Indicators[indicatorKey], dropdownOptions); } else if (dic[adminLevelId].Indicators.ContainsKey(indicatorKey) && isDemoOrDistro) { if (newIndicator.ReportedDate > dic[adminLevelId].Indicators[indicatorKey].ReportedDate) dic[adminLevelId].Indicators[indicatorKey] = newIndicator; } else { dic[adminLevelId].Indicators.Add(indicatorKey, newIndicator); // Add Column if (!options.Columns.ContainsKey(indicatorKey)) options.Columns.Add(indicatorKey, newIndicator); if (!isCalcRelated) addStaticIndicators(new CreateAggParams { AdminLevel = dic[adminLevelId], Reader = reader, Options = options, }); } } reader.Close(); } }
private void AddIndicator(OleDbDataReader reader, Dictionary<int, AdminLevelIndicators> dic, Func<AggregateIndicator, object, object> customAggRule) { int indicatorId = reader.GetValueOrDefault<int>("iid"); string key = reader.GetValueOrDefault<string>("iname") + indicatorId; int adminLevelId = reader.GetValueOrDefault<int>("aid"); int indicatorDataType = reader.GetValueOrDefault<int>("DataTypeId"); int indicatorAggType = reader.GetValueOrDefault<int>("AggTypeId"); string indicatorValue = reader.GetValueOrDefault<string>("DynamicValue"); if (dic.ContainsKey(adminLevelId)) { var newIndicator = new AggregateIndicator { IndicatorId = indicatorId, DataType = indicatorDataType, Value = indicatorValue, AggType = indicatorAggType }; if (dic[adminLevelId].Indicators.ContainsKey(key)) { // only used in CM JRF doesn't need to aggregate the dropdownlists weighted values dic[adminLevelId].Indicators[key] = IndicatorAggregator.Aggregate(newIndicator, dic[adminLevelId].Indicators[key], new List<IndicatorDropdownValue>()); } else dic[adminLevelId].Indicators.Add(key, newIndicator); } }