Get PageNumber after ResetPageNumber at RunTime

Stimulsoft Reports.WPF discussion
Post Reply
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Get PageNumber after ResetPageNumber at RunTime

Post by Prandl33 »

Hello,
I have to read the current PageNumber respectively the TotalPageCount of one Report of many.
I set the ResetPageNumber on a StiGroupHeaderBand.
When I take SinglePass it works wrong, but on the printed pages it is correct.
PageNofM, PageNumber, PageTotalCount all these SystemVariables are pinted correct on the renderd report in the view.
For Example, it is printed PageTotalCount and PageNumber 1, 1, 4 on the view with NumberOfPass = SinglePass correct.
But with the code you see below, the Report.CompiledReport.PageNumber and TotalPageCount after print GroupFooter
I get 1, 1, 6, when I use SinglePass. When I use DoublePass it works correct. But I have to render up to 35.000 pages. So
I can't render the Report a second time.

Code: Select all

          ...
          if (Report.CompiledReport.NumberOfPass == StiNumberOfPass.SinglePass) {
               //Report.CompiledReport.NumberOfPass = StiNumberOfPass.DoublePass;
          }
          StiGroupFooterBand stiGroupFooterZahlschein = (StiGroupFooterBand) Report.CompiledReport.GetComponents()["GroupFooterZahlschein"];
          if (stiGroupFooterZahlschein != null) {
               stiGroupFooterZahlschein.AfterPrint += new EventHandler(OnGroupFooterZahlschein_AfterPrint);
          }
          StiGroupHeaderBand stiGroupHeaderZahlschein = (StiGroupHeaderBand) Report.CompiledReport.GetComponents()["GroupHeaderZahlschein"];
          if (stiGroupHeaderZahlschein != null) {
              stiGroupHeaderZahlschein.ResetPageNumber = true;
          }
          ...

        private void OnGroupFooterZahlschein_AfterPrint(object sender, EventArgs e) {
            //if (Report.CompiledReport.IsSecondPass) {
                int pNr = Report.CompiledReport.PageNumber;
                int pNrTotal = Report.CompiledReport.TotalPageCount;
            //}
        }
How do you print the correct pagenumber with SinglePass?
Tank you
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Get PageNumber after ResetPageNumber at RunTime

Post by Ivan »

Hello,

PageNofM, PageNumber, PageTotalCount variables are finally calculated and stored after the report rendering.
So you can get right values only in the EndRender event of the report.
We can make recommendations if you describe your task in more details.

Thank you.
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Re: Get PageNumber after ResetPageNumber at RunTime

Post by Prandl33 »

Hello,
I have read the PageTotalCount or PageNumber after the rendering in the past.
But I have to save time when I build the report. Now I have a solution.
In the StiPage_BeforePrint event I installed a pagecounter. In the OnGroupFooterZahlschein_AfterPrint Event
it is the last page of the report and I have the pagenumber which is in pagecounter. Then
I reset the pagecounter to 0.

Code: Select all

        ....
        private int pagecounter = 0;
    
        protected override void SetEvents() {

            if (ReportKey.ReportName == "SaZahlscheinVorschreibung" || ReportKey.ReportName == "SaZahlscheinMahnung") {
                StiGroupFooterBand stiGroupFooterZahlschein = (StiGroupFooterBand) Report.CompiledReport.GetComponents()["GroupFooterZahlschein"];
                if (stiGroupFooterZahlschein != null) {
                    stiGroupFooterZahlschein.AfterPrint += new EventHandler(OnGroupFooterZahlschein_AfterPrint);
                }
                StiPage stiPage = (StiPage) Report.CompiledReport.GetComponents()["Seite1"];
                if (stiPage != null) {
                    stiPage.BeforePrint += StiPage_BeforePrint;
                }
            }
        }

        private void StiPage_BeforePrint(object sender, EventArgs e) {
            pagecounter++;
        }

        private void OnGroupFooterZahlschein_AfterPrint(object sender, EventArgs e) {
            int pNr = Report.CompiledReport.PageNumber;
            int pNrTotal = Report.CompiledReport.TotalPageCount;
            pagecounter= 0;
        }
        ...
This only works fine when your take NumberOfPass=SinglePass. When you need DoublePass,
you can use PageNumber or PageTotalCount after the GroupFooter print.
Thank you
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Get PageNumber after ResetPageNumber at RunTime

Post by HighAley »

Hello.

Thank you for you solution.
Let us know if you need our help.

Thank you.
Post Reply