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