123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using FastReport.Table;
- using FastReport.Utils;
- namespace FastReport.Matrix
- {
- /// <summary>
- /// Specifies the aggregate function used in the <see cref="MatrixObject"/>.
- /// </summary>
- public enum MatrixAggregateFunction
- {
- /// <summary>
- /// No aggregates are used.
- /// </summary>
- None,
- /// <summary>
- /// Specifies the sum of values.
- /// </summary>
- Sum,
- /// <summary>
- /// Specifies the minimum of values.
- /// </summary>
- Min,
- /// <summary>
- /// Specifies the maximum of values.
- /// </summary>
- Max,
- /// <summary>
- /// Specifies the average of values.
- /// </summary>
- Avg,
- /// <summary>
- /// Specifies the count of values.
- /// </summary>
- Count,
- /// <summary>
- /// Specifies the count of distinct values.
- /// </summary>
- CountDistinct,
- /// <summary>
- /// Specifies the custom function.
- /// </summary>
- Custom
- }
- /// <summary>
- /// Determines how matrix percents are calculated.
- /// </summary>
- public enum MatrixPercent
- {
- /// <summary>
- /// Do not calculate percent value.
- /// </summary>
- None,
- /// <summary>
- /// Calculate percent of the column total value.
- /// </summary>
- ColumnTotal,
-
- /// <summary>
- /// Calculate percent of the row total value.
- /// </summary>
- RowTotal,
-
- /// <summary>
- /// Calculate percent of the grand total value.
- /// </summary>
- GrandTotal
- }
- /// <summary>
- /// The descriptor that is used to describe one matrix data cell.
- /// </summary>
- /// <remarks>
- /// The <see cref="MatrixCellDescriptor"/> class is used to define one data cell of the matrix.
- /// The key properties are <see cref="MatrixDescriptor.Expression"/> and <see cref="Function"/>.
- /// To set visual appearance of the data cell, use the <see cref="MatrixDescriptor.TemplateCell"/>
- /// property.
- /// <para/>The collection of descriptors used to represent the matrix data cells is stored
- /// in the <b>MatrixObject.Data.Cells</b> property.
- /// </remarks>
- public class MatrixCellDescriptor : MatrixDescriptor
- {
- private MatrixAggregateFunction function;
- private MatrixPercent percent;
-
- #region Properties
- /// <summary>
- /// Gets or sets an aggregate function used to calculate totals for this cell.
- /// </summary>
- public MatrixAggregateFunction Function
- {
- get { return function; }
- set { function = value; }
- }
- /// <summary>
- /// Gets or sets a value that determines how to calculate the percent value for this cell.
- /// </summary>
- public MatrixPercent Percent
- {
- get { return percent; }
- set { percent = value; }
- }
- #endregion
- #region Public Methods
- /// <inheritdoc/>
- public override void Assign(MatrixDescriptor source)
- {
- base.Assign(source);
- MatrixCellDescriptor src = source as MatrixCellDescriptor;
- if (src != null)
- {
- Function = src.Function;
- Percent = src.Percent;
- }
- }
- /// <inheritdoc/>
- public override void Serialize(FRWriter writer)
- {
- MatrixCellDescriptor c = writer.DiffObject as MatrixCellDescriptor;
- base.Serialize(writer);
- writer.ItemName = "Cell";
- if (Function != c.Function)
- writer.WriteValue("Function", Function);
- if (Percent != c.Percent)
- writer.WriteValue("Percent", Percent);
- }
- #endregion
- /// <summary>
- /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
- /// with default settings.
- /// </summary>
- public MatrixCellDescriptor() : this("", MatrixAggregateFunction.Sum)
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
- /// with specified expression.
- /// </summary>
- /// <param name="expression">The descriptor's expression.</param>
- public MatrixCellDescriptor(string expression) : this(expression, MatrixAggregateFunction.Sum)
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
- /// with specified expression and aggregate function.
- /// </summary>
- /// <param name="expression">The descriptor's expression.</param>
- /// <param name="function">The aggregate function.</param>
- public MatrixCellDescriptor(string expression, MatrixAggregateFunction function) : this(expression, function, MatrixPercent.None)
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class
- /// with specified expression, aggregate function, and a percent.
- /// </summary>
- /// <param name="expression">The descriptor's expression.</param>
- /// <param name="function">The aggregate function.</param>
- /// <param name="percent">The percent setting.</param>
- public MatrixCellDescriptor(string expression, MatrixAggregateFunction function, MatrixPercent percent)
- {
- Expression = expression;
- this.function = function;
- this.percent = percent;
- }
- }
- }
|