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