MatrixCellDescriptor.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Table;
  5. using FastReport.Utils;
  6. namespace FastReport.Matrix
  7. {
  8. /// <summary>
  9. /// Specifies the aggregate function used in the <see cref="MatrixObject"/>.
  10. /// </summary>
  11. public enum MatrixAggregateFunction
  12. {
  13. /// <summary>
  14. /// No aggregates are used.
  15. /// </summary>
  16. None,
  17. /// <summary>
  18. /// Specifies the sum of values.
  19. /// </summary>
  20. Sum,
  21. /// <summary>
  22. /// Specifies the minimum of values.
  23. /// </summary>
  24. Min,
  25. /// <summary>
  26. /// Specifies the maximum of values.
  27. /// </summary>
  28. Max,
  29. /// <summary>
  30. /// Specifies the average of values.
  31. /// </summary>
  32. Avg,
  33. /// <summary>
  34. /// Specifies the count of values.
  35. /// </summary>
  36. Count,
  37. /// <summary>
  38. /// Specifies the count of distinct values.
  39. /// </summary>
  40. CountDistinct,
  41. /// <summary>
  42. /// Specifies the custom function.
  43. /// </summary>
  44. Custom
  45. }
  46. /// <summary>
  47. /// Determines how matrix percents are calculated.
  48. /// </summary>
  49. public enum MatrixPercent
  50. {
  51. /// <summary>
  52. /// Do not calculate percent value.
  53. /// </summary>
  54. None,
  55. /// <summary>
  56. /// Calculate percent of the column total value.
  57. /// </summary>
  58. ColumnTotal,
  59. /// <summary>
  60. /// Calculate percent of the row total value.
  61. /// </summary>
  62. RowTotal,
  63. /// <summary>
  64. /// Calculate percent of the grand total value.
  65. /// </summary>
  66. GrandTotal
  67. }
  68. /// <summary>
  69. /// The descriptor that is used to describe one matrix data cell.
  70. /// </summary>
  71. /// <remarks>
  72. /// The <see cref="MatrixCellDescriptor"/> class is used to define one data cell of the matrix.
  73. /// The key properties are <see cref="MatrixDescriptor.Expression"/> and <see cref="Function"/>.
  74. /// To set visual appearance of the data cell, use the <see cref="MatrixDescriptor.TemplateCell"/>
  75. /// property.
  76. /// <para/>The collection of descriptors used to represent the matrix data cells is stored
  77. /// in the <b>MatrixObject.Data.Cells</b> property.
  78. /// </remarks>
  79. public class MatrixCellDescriptor : MatrixDescriptor
  80. {
  81. private MatrixAggregateFunction function;
  82. private MatrixPercent percent;
  83. #region Properties
  84. /// <summary>
  85. /// Gets or sets an aggregate function used to calculate totals for this cell.
  86. /// </summary>
  87. public MatrixAggregateFunction Function
  88. {
  89. get { return function; }
  90. set { function = value; }
  91. }
  92. /// <summary>
  93. /// Gets or sets a value that determines how to calculate the percent value for this cell.
  94. /// </summary>
  95. public MatrixPercent Percent
  96. {
  97. get { return percent; }
  98. set { percent = value; }
  99. }
  100. #endregion
  101. #region Public Methods
  102. /// <inheritdoc/>
  103. public override void Assign(MatrixDescriptor source)
  104. {
  105. base.Assign(source);
  106. MatrixCellDescriptor src = source as MatrixCellDescriptor;
  107. if (src != null)
  108. {
  109. Function = src.Function;
  110. Percent = src.Percent;
  111. }
  112. }
  113. /// <inheritdoc/>
  114. public override void Serialize(FRWriter writer)
  115. {
  116. MatrixCellDescriptor c = writer.DiffObject as MatrixCellDescriptor;
  117. base.Serialize(writer);
  118. writer.ItemName = "Cell";
  119. if (Function != c.Function)
  120. writer.WriteValue("Function", Function);
  121. if (Percent != c.Percent)
  122. writer.WriteValue("Percent", Percent);
  123. }
  124. #endregion
  125. /// <summary>
  126. /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
  127. /// with default settings.
  128. /// </summary>
  129. public MatrixCellDescriptor() : this("", MatrixAggregateFunction.Sum)
  130. {
  131. }
  132. /// <summary>
  133. /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
  134. /// with specified expression.
  135. /// </summary>
  136. /// <param name="expression">The descriptor's expression.</param>
  137. public MatrixCellDescriptor(string expression) : this(expression, MatrixAggregateFunction.Sum)
  138. {
  139. }
  140. /// <summary>
  141. /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
  142. /// with specified expression and aggregate function.
  143. /// </summary>
  144. /// <param name="expression">The descriptor's expression.</param>
  145. /// <param name="function">The aggregate function.</param>
  146. public MatrixCellDescriptor(string expression, MatrixAggregateFunction function) : this(expression, function, MatrixPercent.None)
  147. {
  148. }
  149. /// <summary>
  150. /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
  151. /// with specified expression, aggregate function, and a percent.
  152. /// </summary>
  153. /// <param name="expression">The descriptor's expression.</param>
  154. /// <param name="function">The aggregate function.</param>
  155. /// <param name="percent">The percent setting.</param>
  156. public MatrixCellDescriptor(string expression, MatrixAggregateFunction function, MatrixPercent percent)
  157. {
  158. Expression = expression;
  159. this.function = function;
  160. this.percent = percent;
  161. }
  162. }
  163. }