I'm using a query to generate a report using the: Server.CreateObject("DPDF_RptWtr.Report")
I have a Header, Footer and Body area and the report looks fine. I want to add total record count on the last page of the report. I've looked at the Invoice sample and saw to get the page total, SQL Count() function was used and displayed on the page. I tried to use this as a starting point and added the Count field to my SQL and then my footer. The Count value is correct but it prints on every page, not just the last page. This sounds like an easy thing to do - put the number of records on the last page. Am I going about this all wrong?
Calculating Report Totals
Re: Calculating Report Totals
Support · Aug 3, 2006Typically, what ever is added to the footer will be displayed on every page (this is why your total value is getting placed on every footer). In your case, the way you will go about getting the total to show up on just the last page will be to use the "OnDraw" event in the label in the footer (the one you will want to display your total value on). Then in your event set a variable equal to that TextArea (at this point that variable will not be defined). Once everything else in the Report is set up then call the "Run" method on the Report object. Then set the same variable used above equal to the Count value that you have already calculated. The run the Report.DrawToASP.
Your code might look something like this:
Dim Report, etc...
Set Report...
Set Header...
Set Body...
Set Footer...included here the line for outputting the Count:
Set objLabel = .AddLabel( "", x, y, h, w, align, )
Set objLabel.OnDraw = GetRef("Total_OnDraw")
objReport.Run
myTotal.Text = "100"
objReport.DrawToASP
And the OnDraw function would look something like this:
Function Total_OnDraw( TextArea )
Set myTotal = TextArea
End Function
Thanks,
ceTe Software Support Team
Re: Calculating Report Totals
Forum member · Aug 8, 2007I am trying to add a total to the last page of the report.
The main content of my report is setup in a .dplx page, and I am calling it from a web application. (using v. 4.03.20).
I've added my total as a RecordBox in the Footer section of the page, and basically want it blank when it's not the last page of the report. I've added a LayingOut event handler, but am not sure how to determine the current page.
This is what I have so far:
...
RecordArea recordTotalAmount = (RecordArea)doc.GetElementById("recordTotalAmount");
recordTotalAmount.LayingOut += new LayingOutEventHandler(recordTotalAmount_LayingOut);
Document report = doc.Run(parameters);
byte[] buffer = report.Draw();
recordTotalAmount.LayingOut -= new LayingOutEventHandler(recordTotalAmount_LayingOut);
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.BinaryWrite(buffer);
Response.End();
}
void recordTotalAmount_LayingOut(object sender, LayingOutEventArgs e)
{
int totalPages = report.Pages.Count;
RecordArea lblTotalAmount = (RecordArea)sender;
//now at this point I want to say:
// if (currentPage == totalPages)
// lblTotalAmount.Text = "";
// else
// lblTotalAmount.Text = "1000";
}
Am I on the right track or is there another way to do this?
Re: Calculating Report Totals
Support · Aug 8, 2007Hello,
The feature of displaying the sum on the last page alone is will be added in v5.0 of our ReportWriter for .NET product which will likely be available by the end of the year.
However, the workaround to display the sum in the last page is:
You will have to keep a counter variable that adds the value each time data is retrieved from the database and then using the Generator for .NET product add the final total to the last page using a Label page element.
Thanks,
ceTe Software Support Team.