Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Description: This tutorial illustrates how create a PixelPerfect Report with C# Scripts. This Report calculates previous page totals using macros. You can use C#, Visual Basic or JavaScript to develop PixelPerfect Scripts. For a Visual Basic version of this tutorial refer to "How to Create Previous Page Totals with PixelPerfect Visual Basic Scripts".
using System.Collections.Generic; double currentPageTotal = 0; double runningPagesTotal = 0; int PageNumber = 0; List<double>PageTotal=new List<double>();
Add the System.Collections.Generic namespace to use Lists.
private void OnSummaryReset_currentPageTotal(object sender, System.EventArgs e) { PageTotal.Add(currentPageTotal); currentPageTotal=0; }
This sub-routine is executed at the beginning of each new page.
Code:
private void OnSummaryRowChanged_currentPageTotal(object sender, System.EventArgs e) { currentPageTotal+=(double)DetailReport.GetCurrentColumnValue("Total Sales"); }
This code is executed for each row on the page. It retrieves the value of the Total Sales field and adds it to the previous total. Remember to change the field name if you want to re-use the code in another field.
Add this code below the previous code.
private void OnSummaryGetResult_currentPageTotal(object sender, DevExpress.XtraReports.UI.SummaryGetResultEventArgs e) { e.Result=currentPageTotal; e.Handled=true; }
This code returns the sum for the current page. It is executed when changing pages. Add this code below the previous code.
private void OnSummaryGetResult_previousPageTotal(object sender, DevExpress.XtraReports.UI.SummaryGetResultEventArgs e) { e.Result=PageTotal[PageNumber]; e.Handled=true; PageNumber+=1; }
This code returns the total for the previous page. Add this code below the previous code.
private void OnSummaryGetResult_runningPagesTotal(object sender, DevExpress.XtraReports.UI.SummaryGetResultEventArgs e) { runningPagesTotal+=currentPageTotal; e.Result=runningPagesTotal; e.Handled=true; }
This code increases the value of runningPagesTotal by the currentPageTotal and returns the value of the Total Sales for each preceding page. Add this code below the previous code.
Now we associate sub-routines to the events specified on the left column.
Do these steps also for the last Label. Insert OnSummaryGetResult_runningPagesTotal on Summary Get Result field.
Select Preview in the Actions group in the Reports window