Page 1 of 1

Get PageNumber after ResetPageNumber at RunTime

Posted: Fri Dec 16, 2016 11:41 am
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

Re: Get PageNumber after ResetPageNumber at RunTime

Posted: Sat Dec 17, 2016 4:54 pm
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.

Re: Get PageNumber after ResetPageNumber at RunTime

Posted: Mon Dec 19, 2016 6:50 am
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

Re: Get PageNumber after ResetPageNumber at RunTime

Posted: Wed Dec 21, 2016 6:33 am
by HighAley
Hello.

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

Thank you.