123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- using FastReport.Utils;
- using System;
- namespace FastReport.Engine
- {
- public partial class ReportEngine
- {
- #region Fields
- private ReportPage page;
- private float columnStartY;
- private string pageNameForRecalc;
- #endregion Fields
- #region Private Methods
- private DataBand FindDeepmostDataBand(ReportPage page)
- {
- DataBand result = null;
- foreach (Base c in page.AllObjects)
- {
- if (c is DataBand)
- result = c as DataBand;
- }
- return result;
- }
- private void RunReportPage(ReportPage page)
- {
- this.page = page;
- InitReprint();
- pageNameForRecalc = null;
- this.page.OnStartPage(EventArgs.Empty);
- bool previousPage = StartFirstPage();
- OnStateChanged(this.page, EngineState.ReportPageStarted);
- OnStateChanged(this.page, EngineState.PageStarted);
- DataBand keepSummaryBand = FindDeepmostDataBand(page);
- if (keepSummaryBand != null)
- keepSummaryBand.KeepSummary = true;
- if (this.page.IsManualBuild)
- this.page.OnManualBuild(EventArgs.Empty);
- else
- RunBands(page.Bands);
- OnStateChanged(this.page, EngineState.PageFinished);
- OnStateChanged(this.page, EngineState.ReportPageFinished);
- EndLastPage();
- //recalculate unlimited
- if (page.UnlimitedHeight || page.UnlimitedWidth)
- {
- PreparedPages.ModifyPageSize(page.Name);
- if (previousPage && pageNameForRecalc != null)
- PreparedPages.ModifyPageSize(pageNameForRecalc);
- }
- //recalculate unlimited
- this.page.OnFinishPage(EventArgs.Empty);
- if (this.page.BackPage)
- {
- PreparedPages.InterleaveWithBackPage(PreparedPages.CurPage);
- }
- }
- private bool CalcVisibleExpression(string expression)
- {
- bool result = true;
- object expressionObj = null;
- // Calculate expressions with TotalPages only on FinalPass.
- if (!expression.Contains("TotalPages") || (Report.DoublePass && FinalPass))
- {
- expressionObj = Report.Calc(Code.CodeUtils.FixExpressionWithBrackets(expression));
- }
- if (expressionObj != null && expressionObj is bool)
- {
- if (!expression.Contains("TotalPages"))
- {
- result = (bool)expressionObj;
- }
- else if (FirstPass)
- {
- result = true;
- }
- else
- {
- result = (bool)expressionObj;
- }
- }
- return result;
- }
- private void RunReportPages()
- {
- #if TIMETRIAL
- if (new DateTime($YEAR, $MONTH, $DAY) < System.DateTime.Now)
- throw new Exception("The trial version is now expired!");
- #endif
- for (int i = 0; i < Report.Pages.Count; i++)
- {
- ReportPage page = Report.Pages[i] as ReportPage;
- // Calc and apply visible expression if needed.
- if (page != null && !String.IsNullOrEmpty(page.VisibleExpression))
- {
- page.Visible = CalcVisibleExpression(page.VisibleExpression);
- }
- if (page != null && page.Visible && page.Subreport == null)
- RunReportPage(page);
- if (Report.Aborted)
- break;
- }
- }
- private void RunBands(BandCollection bands)
- {
- for (int i = 0; i < bands.Count; i++)
- {
- BandBase band = bands[i];
- if (band is DataBand)
- RunDataBand(band as DataBand);
- else if (band is GroupHeaderBand)
- RunGroup(band as GroupHeaderBand);
- if (Report.Aborted)
- break;
- }
- }
- private void ShowPageHeader()
- {
- ShowBand(page.PageHeader);
- }
- private void ShowPageFooter(bool startPage)
- {
- if (!FirstPass &&
- CurPage == TotalPages - 1 &&
- page.PageFooter != null &&
- (page.PageFooter.PrintOn & PrintOn.LastPage) > 0 &&
- (page.PageFooter.PrintOn & PrintOn.FirstPage) == 0 &&
- startPage)
- {
- ShiftLastPage();
- }
- else
- ShowBand(page.PageFooter);
- }
- private bool StartFirstPage()
- {
- page.InitializeComponents();
- CurX = 0;
- CurY = 0;
- curColumn = 0;
- if (page.ResetPageNumber)
- ResetLogicalPageNumber();
- bool previousPage = page.PrintOnPreviousPage && PreparedPages.Count > 0;
- // check that previous page has the same size
- if (previousPage)
- {
- using (ReportPage page0 = PreparedPages.GetPage(PreparedPages.Count - 1))
- {
- if (page0.PaperWidth == this.page.PaperWidth)
- {
- if (page0.UnlimitedWidth == this.page.UnlimitedWidth)
- {
- previousPage = true;
- if (this.page.UnlimitedWidth)
- pageNameForRecalc = page0.Name;
- }
- else
- {
- previousPage = false;
- }
- }
- else if (page0.UnlimitedWidth && this.page.UnlimitedWidth)
- {
- previousPage = true;
- pageNameForRecalc = page0.Name;
- }
- else
- {
- previousPage = false;
- }
- if (previousPage)
- {
- if (page0.PaperHeight == this.page.PaperHeight)
- {
- if (page0.UnlimitedHeight == this.page.UnlimitedHeight)
- {
- previousPage = true;
- if (this.page.UnlimitedHeight)
- pageNameForRecalc = page0.Name;
- }
- else
- {
- previousPage = false;
- }
- }
- else if (page0.UnlimitedHeight && this.page.UnlimitedHeight)
- {
- previousPage = true;
- }
- else
- {
- previousPage = false;
- }
- }
- }
- }
- // update CurY or add new page
- if (previousPage)
- CurY = PreparedPages.GetLastY();
- else
- {
- PreparedPages.AddPage(page);
- if (page.StartOnOddPage && (CurPage % 2) == 1)
- PreparedPages.AddPage(page);
- }
- // page numbers
- if (isFirstReportPage)
- firstReportPage = CurPage;
- if (isFirstReportPage && previousPage)
- IncLogicalPageNumber();
- isFirstReportPage = false;
- OutlineRoot();
- AddPageOutline();
- // show report title and page header
- if (previousPage)
- ShowBand(page.ReportTitle);
- else
- {
- if (page.Overlay != null)
- ShowBand(page.Overlay);
- if (page.TitleBeforeHeader)
- {
- ShowBand(page.ReportTitle);
- ShowPageHeader();
- }
- else
- {
- ShowPageHeader();
- ShowBand(page.ReportTitle);
- }
- }
- // show column header
- columnStartY = CurY;
- ShowBand(page.ColumnHeader);
- // calculate CurX before starting column event depending on Right to Left or Left to Right layout
- if (Config.RightToLeft)
- {
- CurX = page.Columns.Positions[page.Columns.Positions.Count - 1] * Units.Millimeters;
- }
- else
- {
- CurX = 0;
- }
- // start column event
- OnStateChanged(page, EngineState.ColumnStarted);
- ShowProgress();
- return previousPage;
- }
- private void EndLastPage()
- {
- // end column event
- OnStateChanged(page, EngineState.ColumnFinished);
- if (page.ReportSummary != null)
- {
- // do not show column footer here! It's a special case and is handled in the ShowBand.
- ShowBand(page.ReportSummary);
- }
- else
- {
- ShowBand(page.ColumnFooter);
- }
- ShowPageFooter(false);
- OutlineRoot();
- page.FinalizeComponents();
- }
- internal void EndColumn()
- {
- EndColumn(true);
- }
- private void EndColumn(bool showColumnFooter)
- {
- // end column event
- OnStateChanged(page, EngineState.ColumnFinished);
- // check keep
- if (keeping)
- CutObjects();
- ShowReprintFooters();
- if (showColumnFooter)
- ShowBand(page.ColumnFooter);
- curColumn++;
- if (curColumn >= page.Columns.Count)
- curColumn = 0;
- // apply Right to Left layot if needed
- if (Config.RightToLeft)
- {
- curX = page.Columns.Positions[page.Columns.Count - curColumn - 1] * Units.Millimeters;
- }
- else
- {
- curX = curColumn == 0 ? 0 : page.Columns.Positions[curColumn] * Units.Millimeters;
- }
- if (CurColumn == 0)
- {
- EndPage();
- }
- else
- {
- StartColumn();
- }
- // end keep
- if (keeping)
- PasteObjects();
- }
- private void StartColumn()
- {
- curY = columnStartY;
- ShowBand(page.ColumnHeader);
- ShowReprintHeaders();
- // start column event
- OnStateChanged(page, EngineState.ColumnStarted);
- }
- private void EndPage()
- {
- EndPage(true);
- }
- private void StartPage()
- {
- // apply Right to Left layout if needed
- if (Config.RightToLeft)
- {
- CurX = page.Columns.Positions[page.Columns.Positions.Count - 1] * Units.Millimeters;
- }
- else
- {
- CurX = 0;
- }
- CurY = 0;
- curColumn = 0;
- PreparedPages.AddPage(page);
- AddPageOutline();
- if (page.Overlay != null)
- ShowBand(page.Overlay);
- ShowPageHeader();
- OnStateChanged(page, EngineState.PageStarted);
- columnStartY = CurY;
- StartColumn();
- ShowProgress();
- }
- #endregion Private Methods
- #region Internal Methods
- internal void EndPage(bool startPage)
- {
- OnStateChanged(page, EngineState.PageFinished);
- ShowPageFooter(startPage);
- if (pagesLimit > 0 && PreparedPages.Count >= pagesLimit)
- Report.Abort();
- if (Report.MaxPages > 0 && PreparedPages.Count >= Report.MaxPages)
- Report.Abort();
- if (startPage)
- StartPage();
- }
- #endregion Internal Methods
- #region Public Methods
- /// <summary>
- /// Starts a new page.
- /// </summary>
- public void StartNewPage()
- {
- EndPage();
- }
- /// <summary>
- /// Starts a new column.
- /// </summary>
- public void StartNewColumn()
- {
- EndColumn();
- }
- #endregion Public Methods
- }
- }
|