ReportEngine.KeepWithData.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System.Collections.Generic;
  2. namespace FastReport.Engine
  3. {
  4. public partial class ReportEngine
  5. {
  6. #region Private Methods
  7. private void EnumHeaders(BandBase band, List<BandBase> list)
  8. {
  9. if (band != null)
  10. {
  11. list.Add(band);
  12. EnumHeaders(band.Parent as BandBase, list);
  13. }
  14. }
  15. // get a list of the footers that must be kept with the dataBand row
  16. private List<HeaderFooterBandBase> GetAllFooters(DataBand dataBand)
  17. {
  18. // get all parent databands/groups
  19. List<BandBase> list = new List<BandBase>();
  20. EnumHeaders(dataBand, list);
  21. // add report summary if required
  22. ReportSummaryBand summaryBand = (dataBand.Page as ReportPage).ReportSummary;
  23. if (dataBand.KeepSummary && summaryBand != null)
  24. list.Add(summaryBand);
  25. // make footers list
  26. List<HeaderFooterBandBase> footers = new List<HeaderFooterBandBase>();
  27. foreach (BandBase band in list)
  28. {
  29. HeaderFooterBandBase footer = null;
  30. if (band is DataBand)
  31. footer = (band as DataBand).Footer;
  32. else if (band is GroupHeaderBand)
  33. footer = (band as GroupHeaderBand).GroupFooter;
  34. else if (band is ReportSummaryBand)
  35. footer = band as ReportSummaryBand;
  36. if (footer != null)
  37. footers.Add(footer);
  38. // skip non-last data rows. Keep the dataBand to allow
  39. // calling this method from the beginning of RunDataBand
  40. if (band != dataBand && !band.IsLastRow)
  41. break;
  42. }
  43. // remove all footers at the end which have no KeepWithData flag
  44. for (int i = footers.Count - 1; i >= 0; i--)
  45. {
  46. if (!footers[i].KeepWithData)
  47. footers.RemoveAt(i);
  48. else
  49. break;
  50. }
  51. return footers;
  52. }
  53. private bool NeedKeepFirstRow(DataBand dataBand)
  54. {
  55. return dataBand.Header != null && dataBand.Header.KeepWithData;
  56. }
  57. private bool NeedKeepFirstRow(GroupHeaderBand groupBand)
  58. {
  59. if (groupBand == null)
  60. return false;
  61. if (groupBand.KeepWithData)
  62. return true;
  63. DataBand dataBand = groupBand.GroupDataBand;
  64. if (dataBand.Header != null && dataBand.Header.KeepWithData)
  65. return true;
  66. if (groupBand.IsFirstRow)
  67. return NeedKeepFirstRow(groupBand.Parent as GroupHeaderBand);
  68. return false;
  69. }
  70. private bool NeedKeepLastRow(DataBand dataBand)
  71. {
  72. List<HeaderFooterBandBase> footers = GetAllFooters(dataBand);
  73. return footers.Count > 0;
  74. }
  75. private float GetFootersHeight(DataBand dataBand)
  76. {
  77. List<HeaderFooterBandBase> footers = GetAllFooters(dataBand);
  78. float height = 0;
  79. foreach (HeaderFooterBandBase band in footers)
  80. {
  81. // skip bands with RepeatOnEveryPage flag: its height is already
  82. // included in the FreeSpace property
  83. if (!band.RepeatOnEveryPage)
  84. height += GetBandHeightWithChildren(band);
  85. }
  86. return height;
  87. }
  88. private void CheckKeepFooter(DataBand dataBand)
  89. {
  90. if (FreeSpace < GetFootersHeight(dataBand))
  91. EndColumn();
  92. else
  93. EndKeep();
  94. }
  95. #endregion Private Methods
  96. }
  97. }