Created
September 30, 2015 06:29
-
-
Save smarenich/818569f1a418ca6cad90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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