MatrixData.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using FastReport.Data;
  5. namespace FastReport.AdvMatrix
  6. {
  7. /// <summary>
  8. /// Contains a set of properties and methods to hold and manipulate the matrix descriptors.
  9. /// </summary>
  10. /// <remarks>
  11. /// This class contains two collections of descriptors such as <see cref="Columns"/> and
  12. /// <see cref="Rows"/>. Use collections' methods to add/remove descriptors.
  13. /// When you are done, call the <see cref="AdvMatrixObject.BuildTemplate"/> method to refresh the matrix.
  14. /// </remarks>
  15. public class MatrixData
  16. {
  17. internal AdvMatrixObject Matrix { get; private set; }
  18. internal bool Completed { get; private set; }
  19. /// <summary>
  20. /// Gets a collection of column descriptors.
  21. /// </summary>
  22. /// <remarks>
  23. /// Note: after you add or remove items in this collection, call the
  24. /// <see cref="AdvMatrixObject.BuildTemplate"/> method to refresh the matrix.
  25. /// </remarks>
  26. public MatrixHeader Columns { get; private set; }
  27. /// <summary>
  28. /// Gets a collection of row descriptors.
  29. /// </summary>
  30. /// <remarks>
  31. /// Note: after you add or remove items in this collection, call the
  32. /// <see cref="AdvMatrixObject.BuildTemplate"/> method to refresh the matrix.
  33. /// </remarks>
  34. public MatrixHeader Rows { get; private set; }
  35. internal CellData CellData { get; private set; }
  36. /// <summary>
  37. /// Gets context required for aggregate calculation.
  38. /// </summary>
  39. public Context Context { get; private set; }
  40. internal InteractiveSortInfo InteractiveSort { get; private set; }
  41. internal bool IsEmpty { get { return Columns.Data.Items.Count == 0; } }
  42. internal string[] GetExpressions()
  43. {
  44. List<string> expressions = new List<string>();
  45. Columns.GetExpressions(expressions);
  46. Rows.GetExpressions(expressions);
  47. CellData.GetExpressions(expressions);
  48. return expressions.ToArray();
  49. }
  50. internal void Init()
  51. {
  52. Columns.Init();
  53. Rows.Init();
  54. CellData.Init();
  55. }
  56. internal void Done()
  57. {
  58. if (!Completed)
  59. {
  60. if (IsEmpty && Matrix.PrintIfEmpty)
  61. ProcessDataRow();
  62. TopNBuilder.Process(Matrix);
  63. Completed = true;
  64. }
  65. if (!IsEmpty)
  66. ResultBuilder.BuildResult(Matrix);
  67. }
  68. internal void ProcessDataRows()
  69. {
  70. DataSourceBase dataSource = Matrix.DataSource;
  71. if (dataSource != null)
  72. {
  73. dataSource.Init(Matrix.Filter);
  74. while (dataSource.HasMoreRows)
  75. {
  76. ProcessDataRow();
  77. dataSource.Next();
  78. }
  79. }
  80. else
  81. {
  82. Matrix.OnManualBuild(EventArgs.Empty);
  83. }
  84. }
  85. /// <summary>
  86. /// Processes single data row.
  87. /// </summary>
  88. /// <remarks>
  89. /// This method is used internally to process current data row. The matrix fills the column, row and cell data.
  90. /// You should use this method if you fill a matrix in code using <b>ManualBuild</b> event.
  91. /// </remarks>
  92. public void ProcessDataRow()
  93. {
  94. CellData.ProcessDataRow(Columns.ProcessDataRow(), Rows.ProcessDataRow());
  95. }
  96. /// <summary>
  97. /// Resets the data from the previous report run.
  98. /// </summary>
  99. public void Reset()
  100. {
  101. Completed = false;
  102. }
  103. /// <summary>
  104. /// Initializes a new instance of the <see cref="MatrixData"/> class.
  105. /// </summary>
  106. /// <param name="matrix">Reference to owner matrix.</param>
  107. public MatrixData(AdvMatrixObject matrix)
  108. {
  109. Matrix = matrix;
  110. Columns = new MatrixHeader(matrix, "Columns");
  111. Rows = new MatrixHeader(matrix, "Rows");
  112. CellData = new CellData(matrix);
  113. Context = new Context();
  114. InteractiveSort = new InteractiveSortInfo(this);
  115. }
  116. }
  117. }