public virtual void PMEnsureInitialized() { if (_historyLoaded == null) { _reportPeriods = new RMReportPeriods <PMHistory>(this.Base); var accountGroupSelect = new PXSelect <PMAccountGroup>(this.Base); accountGroupSelect.View.Clear(); accountGroupSelect.Cache.Clear(); var projectSelect = new PXSelect <PMProject, Where <PMProject.isTemplate, Equal <False>, And <PMProject.nonProject, Equal <False>, And <PMProject.baseType, Equal <PMProject.ProjectBaseType> > > > >(this.Base); projectSelect.View.Clear(); projectSelect.Cache.Clear(); var taskSelect = new PXSelectJoin <PMTask, InnerJoin <PMProject, On <PMTask.projectID, Equal <PMProject.contractID> > >, Where <PMProject.isTemplate, Equal <False>, And <PMProject.nonProject, Equal <False> > > >(this.Base); taskSelect.View.Clear(); taskSelect.Cache.Clear(); var itemSelect = new PXSelectJoinGroupBy <InventoryItem, InnerJoin <PMHistory, On <InventoryItem.inventoryID, Equal <PMHistory.inventoryID> > >, Aggregate <GroupBy <InventoryItem.inventoryID> > >(this.Base); itemSelect.View.Clear(); itemSelect.Cache.Clear(); if (Base.Report.Current.ApplyRestrictionGroups == true) { projectSelect.WhereAnd <Where <Match <Current <AccessInfo.userName> > > >(); taskSelect.WhereAnd <Where <Match <Current <AccessInfo.userName> > > >(); itemSelect.WhereAnd <Where <Match <Current <AccessInfo.userName> > > >(); } accountGroupSelect.Select(); projectSelect.Select(); taskSelect.Select(); foreach (InventoryItem item in itemSelect.Select()) { //The PXSelectJoinGroupBy is read-only, and Inventory items won't be added to the cache. Add them manually. itemSelect.Cache.SetStatus(item, PXEntryStatus.Notchanged); } _historySegments = new HashSet <PMHistoryKeyTuple>(); _pmhistoryPeriodsByKey = new Dictionary <PMHistoryKeyTuple, Dictionary <string, PMHistory> >(); _historyLoaded = new HashSet <int>(); _accountGroupsRangeCache = new RMReportRange <PMAccountGroup>(Base, PM.AccountGroupAttribute.DimensionName, RMReportConstants.WildcardMode.Fixed, RMReportConstants.BetweenMode.Fixed); _projectsRangeCache = new RMReportRange <PMProject>(Base, PM.ProjectAttribute.DimensionName, RMReportConstants.WildcardMode.Fixed, RMReportConstants.BetweenMode.Fixed); _tasksRangeCache = new RMReportRange <PMTask>(Base, PM.ProjectTaskAttribute.DimensionName, RMReportConstants.WildcardMode.Normal, RMReportConstants.BetweenMode.Fixed); _itemRangeCache = new RMReportRange <InventoryItem>(Base, IN.InventoryAttribute.DimensionName, RMReportConstants.WildcardMode.Fixed, RMReportConstants.BetweenMode.Fixed); //Add Inventory <OTHER> with InventoryID=0 InventoryItem other = new InventoryItem { InventoryCD = RMReportWildcard.EnsureWildcardForFixed(Messages.OtherItem, _itemRangeCache.Wildcard), InventoryID = PMInventorySelectorAttribute.EmptyInventoryID, Descr = Messages.OtherItemDescription }; itemSelect.Cache.SetStatus(other, PXEntryStatus.Notchanged); } }
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); }