Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class YearGroupMaint : PXGraph<YearGroupMaint>
{
public PXFilter<YearFilter> Filter;
//[PXVirtualDAC]
public PXSelect<VirtualComparasion> Comparasions;
public PXSelect<YearGroup, Where<YearGroup.year, Equal<Required<YearGroup.year>>, Or<YearGroup.year, Equal<Required<YearGroup.year>>>>> YearGroups;
public PXCancel<YearFilter> Cancel;
public IEnumerable comparasions()
{
YearFilter filter = Filter.Current;
if(filter.Year == null) yield break;
Boolean found = false;
//Checking cache for existing items
foreach (VirtualComparasion row in Comparasions.Cache.Cached)
{
found = true;
yield return row;
}
if (!found) //if not found - Select from DB
{
Comparasions.Cache.Clear();
foreach (YearGroup row in YearGroups.Select(filter.Year, Accessinfo.BusinessDate.Value.Year))
{
VirtualComparasion key = new VirtualComparasion() { Group = row.Group, ComparasionYear = 0, CurrentYear = 0 };
VirtualComparasion value = (Comparasions.Cache.Locate(key) ?? Comparasions.Cache.Insert(key)) as VirtualComparasion;
if (row.Year == filter.Year) value.ComparasionYear += row.Value.Value;
if (row.Year == Accessinfo.BusinessDate.Value.Year) value.CurrentYear += row.Value.Value;
value = Comparasions.Update(value);
Comparasions.Cache.SetStatus(value, PXEntryStatus.Held);
}
foreach (VirtualComparasion row in Comparasions.Cache.Cached)
yield return row;
Comparasions.Cache.IsDirty = false;
}
}
public virtual void YearFilter_Year_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
Comparasions.Cache.Clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.