public List <T> GetPeriodsForRegularAmount(RMDataSourceGL dsGL, Dictionary <string, T> periodsForKey) { if (dsGL.StartPeriod != null) { var periods = new List <T>(); string per = RMReportWildcard.EnsureWildcard(dsGL.StartPeriod, _perWildcard); if (!per.Contains(_perWildcard) && dsGL.StartPeriodOffset != null && dsGL.StartPeriodOffset != 0 || dsGL.StartPeriodYearOffset != 0) { per = GetFinPeriod(per, dsGL.StartPeriodYearOffset, dsGL.StartPeriodOffset); } if (dsGL.EndPeriod == null) { if (!per.Contains(_perWildcard)) { T v; if (periodsForKey.TryGetValue(per, out v)) { periods.Add(v); } } else { foreach (var p in periodsForKey) { if (RMReportWildcard.IsLike(per, p.Key)) { periods.Add(p.Value); } } } } else { string toper = RMReportWildcard.EnsureWildcard(dsGL.EndPeriod, _perWildcard); if (!toper.Contains(RMReportConstants.DefaultWildcardChar) && dsGL.EndPeriodOffset != null && dsGL.EndPeriodOffset != 0 || dsGL.EndPeriodYearOffset != 0) { toper = GetFinPeriod(toper, dsGL.EndPeriodYearOffset, dsGL.EndPeriodOffset); } toper = toper.Replace(RMReportConstants.DefaultWildcardChar, '9'); foreach (var p in periodsForKey) { if (RMReportWildcard.IsBetween(per, toper, p.Key)) { periods.Add(p.Value); } } } return(periods); } else { return(periodsForKey.Values.ToList <T>()); } }
private HashSet <T> GetItems(string range, Func <T, string> getValuePredicate, Action <T, string> prepareForLocatePredicate) { var items = new HashSet <T>(); string[] pairs = range.Split(RMReportConstants.RangeUnionChar); foreach (string pair in pairs) { string start, end; ParseRangeStartEndPair(pair, out start, out end); if (!String.IsNullOrEmpty(start)) { if (String.IsNullOrEmpty(end) || end == start) { string itemCode = String.Empty; if (_wildcardMode == RMReportConstants.WildcardMode.Fixed) { itemCode = RMReportWildcard.EnsureWildcardForFixed(start, _wildcard); } else if (_wildcardMode == RMReportConstants.WildcardMode.Normal) { itemCode = RMReportWildcard.EnsureWildcard(start, _wildcard); } else { throw new ArgumentException(Messages.InvalidWildcardMode); } if (itemCode.Contains(RMReportConstants.DefaultWildcardChar)) { items.UnionWith(from T x in _cache.Cached where RMReportWildcard.IsLike(itemCode, getValuePredicate(x)) select x); } else { prepareForLocatePredicate(_instance, itemCode); if (_cache.IsKeysFilled(_instance)) { T x = (T)_cache.Locate(_instance); if (x != null) { items.Add(x); } } else // composite key { items.UnionWith(from T x in _cache.Cached where String.Equals(itemCode, getValuePredicate(x), StringComparison.Ordinal) select x); } } } else { if (_betweenMode == RMReportConstants.BetweenMode.ByChar) { items.UnionWith(from T x in _cache.Cached where RMReportWildcard.IsBetweenByChar(start, end, getValuePredicate(x)) select x); } else if (_betweenMode == RMReportConstants.BetweenMode.Fixed) { items.UnionWith(RMReportWildcard.GetBetweenForFixed <T>(start, end, _wildcard, _cache.Cached, getValuePredicate)); } else { throw new ArgumentException(Messages.InvalidBetweenMode); } } } else { items.UnionWith(_cache.Cached.Cast <T>()); } } return(items); }