ReportEngine.Keep.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using FastReport.Utils;
  2. namespace FastReport.Engine
  3. {
  4. public partial class ReportEngine
  5. {
  6. #region Fields
  7. private bool keeping;
  8. private int keepPosition;
  9. private XmlItem keepOutline;
  10. private int keepBookmarks;
  11. private float keepCurX;
  12. private float keepCurY;
  13. private float keepDeltaY;
  14. #endregion Fields
  15. #region Properties
  16. /// <summary>
  17. /// Returns true of keeping is enabled
  18. /// </summary>
  19. public bool IsKeeping
  20. {
  21. get { return keeping; }
  22. }
  23. /// <summary>
  24. /// Returns keeping position
  25. /// </summary>
  26. public float KeepCurY
  27. {
  28. get { return keepCurY; }
  29. }
  30. #endregion Properties
  31. #region Private Methods
  32. private void StartKeep(BandBase band)
  33. {
  34. // do not keep the first row on a page, avoid empty first page
  35. if (keeping || (band != null && band.AbsRowNo == 1 && !band.FirstRowStartsNewPage))
  36. return;
  37. keeping = true;
  38. keepPosition = PreparedPages.CurPosition;
  39. keepOutline = PreparedPages.Outline.CurPosition;
  40. keepBookmarks = PreparedPages.Bookmarks.CurPosition;
  41. keepCurY = CurY;
  42. Report.Dictionary.Totals.StartKeep();
  43. StartKeepReprint();
  44. }
  45. private void CutObjects()
  46. {
  47. keepCurX = CurX;
  48. keepDeltaY = CurY - keepCurY;
  49. PreparedPages.CutObjects(keepPosition);
  50. CurY = keepCurY;
  51. }
  52. private void PasteObjects()
  53. {
  54. PreparedPages.PasteObjects(CurX - keepCurX, CurY - keepCurY);
  55. PreparedPages.Outline.Shift(keepOutline, CurY);
  56. PreparedPages.Bookmarks.Shift(keepBookmarks, CurY);
  57. EndKeep();
  58. CurY += keepDeltaY;
  59. }
  60. #endregion Private Methods
  61. #region Public Methods
  62. /// <summary>
  63. /// Starts the keep mechanism.
  64. /// </summary>
  65. /// <remarks>
  66. /// Use this method along with the <see cref="EndKeep"/> method if you want to keep
  67. /// several bands together. Call <b>StartKeep</b> method before printing the first band
  68. /// you want to keep, then call the <b>EndKeep</b> method after printing the last band you want to keep.
  69. /// </remarks>
  70. public void StartKeep()
  71. {
  72. StartKeep(null);
  73. }
  74. /// <summary>
  75. /// Ends the keep mechanism.
  76. /// </summary>
  77. /// <remarks>
  78. /// Use this method along with the <see cref="StartKeep()"/> method if you want to keep
  79. /// several bands together. Call <b>StartKeep</b> method before printing the first band
  80. /// you want to keep, then call the <b>EndKeep</b> method after printing the last band you want to keep.
  81. /// </remarks>
  82. public void EndKeep()
  83. {
  84. if (keeping)
  85. {
  86. Report.Dictionary.Totals.EndKeep();
  87. EndKeepReprint();
  88. keeping = false;
  89. }
  90. }
  91. #endregion Public Methods
  92. }
  93. }