ReportEngine.Subreports.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using FastReport.Preview;
  3. namespace FastReport.Engine
  4. {
  5. public partial class ReportEngine
  6. {
  7. #region Private Methods
  8. private void RenderSubreport(SubreportObject subreport)
  9. {
  10. if (subreport.ReportPage != null)
  11. RunBands(subreport.ReportPage.Bands);
  12. }
  13. private void RenderInnerSubreport(BandBase parentBand, SubreportObject subreport)
  14. {
  15. BandBase saveOutputBand = outputBand;
  16. float saveCurX = CurX;
  17. float saveCurY = CurY;
  18. try
  19. {
  20. outputBand = parentBand;
  21. CurX = subreport.Left;
  22. CurY = subreport.Top;
  23. RenderSubreport(subreport);
  24. }
  25. finally
  26. {
  27. outputBand = saveOutputBand;
  28. CurX = saveCurX;
  29. CurY = saveCurY;
  30. }
  31. }
  32. private void RenderInnerSubreports(BandBase parentBand)
  33. {
  34. int originalObjectsCount = parentBand.Objects.Count;
  35. for (int i = 0; i < originalObjectsCount; i++)
  36. {
  37. SubreportObject subreport = parentBand.Objects[i] as SubreportObject;
  38. // Apply visible expression if needed.
  39. if (subreport != null && !String.IsNullOrEmpty(subreport.VisibleExpression))
  40. {
  41. subreport.Visible = CalcVisibleExpression(subreport.VisibleExpression);
  42. }
  43. if (subreport != null && subreport.Visible && subreport.PrintOnParent)
  44. RenderInnerSubreport(parentBand, subreport);
  45. }
  46. }
  47. private void RenderOuterSubreports(BandBase parentBand)
  48. {
  49. float saveCurY = CurY;
  50. float saveOriginX = originX;
  51. int saveCurPage = CurPage;
  52. float maxY = 0;
  53. int maxPage = CurPage;
  54. bool hasSubreports = false;
  55. try
  56. {
  57. for (int i = 0; i < parentBand.Objects.Count; i++)
  58. {
  59. SubreportObject subreport = parentBand.Objects[i] as SubreportObject;
  60. // Apply visible expression if needed.
  61. if (subreport != null && !String.IsNullOrEmpty(subreport.VisibleExpression))
  62. {
  63. subreport.Visible = CalcVisibleExpression(subreport.VisibleExpression);
  64. }
  65. if (subreport != null && subreport.Visible && !subreport.PrintOnParent)
  66. {
  67. hasSubreports = true;
  68. // restore start position
  69. CurPage = saveCurPage;
  70. CurY = saveCurY - subreport.Height;
  71. originX = saveOriginX + subreport.Left;
  72. // do not upload generated pages to the file cache
  73. PreparedPages.CanUploadToCache = false;
  74. RenderSubreport(subreport);
  75. // find maxY. We will continue from maxY when all subreports finished.
  76. if (CurPage == maxPage)
  77. {
  78. if (CurY > maxY)
  79. maxY = CurY;
  80. }
  81. else if (CurPage > maxPage)
  82. {
  83. maxPage = CurPage;
  84. maxY = CurY;
  85. }
  86. }
  87. }
  88. }
  89. finally
  90. {
  91. if (hasSubreports)
  92. {
  93. CurPage = maxPage;
  94. CurY = maxY;
  95. }
  96. originX = saveOriginX;
  97. PreparedPages.CanUploadToCache = true;
  98. }
  99. }
  100. #endregion Private Methods
  101. }
  102. }