FastReport

Форк
0
/
MatrixCellDescriptor.cs 
186 строк · 5.6 Кб
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using FastReport.Table;
5
using FastReport.Utils;
6

7
namespace FastReport.Matrix
8
{
9
    /// <summary>
10
    /// Specifies the aggregate function used in the <see cref="MatrixObject"/>.
11
    /// </summary>
12
    public enum MatrixAggregateFunction
13
    {
14
        /// <summary>
15
        /// No aggregates are used.
16
        /// </summary>
17
        None,
18

19
        /// <summary>
20
        /// Specifies the sum of values.
21
        /// </summary>
22
        Sum,
23

24
        /// <summary>
25
        /// Specifies the minimum of values.
26
        /// </summary>
27
        Min,
28

29
        /// <summary>
30
        /// Specifies the maximum of values.
31
        /// </summary>
32
        Max,
33

34
        /// <summary>
35
        /// Specifies the average of values.
36
        /// </summary>
37
        Avg,
38

39
        /// <summary>
40
        /// Specifies the count of values.
41
        /// </summary>
42
        Count,
43

44
        /// <summary>
45
        /// Specifies the count of distinct values.
46
        /// </summary>
47
        CountDistinct,
48

49
        /// <summary>
50
        /// Specifies the custom function.
51
        /// </summary>
52
        Custom
53
    }
54

55
    /// <summary>
56
    /// Determines how matrix percents are calculated.
57
    /// </summary>
58
    public enum MatrixPercent
59
    {
60
        /// <summary>
61
        /// Do not calculate percent value.
62
        /// </summary>
63
        None,
64

65
        /// <summary>
66
        /// Calculate percent of the column total value.
67
        /// </summary>
68
        ColumnTotal,
69

70
        /// <summary>
71
        /// Calculate percent of the row total value.
72
        /// </summary>
73
        RowTotal,
74

75
        /// <summary>
76
        /// Calculate percent of the grand total value.
77
        /// </summary>
78
        GrandTotal
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>
93
    public class MatrixCellDescriptor : MatrixDescriptor
94
    {
95
        private MatrixAggregateFunction function;
96
        private MatrixPercent percent;
97

98
        #region Properties
99
        /// <summary>
100
        /// Gets or sets an aggregate function used to calculate totals for this cell.
101
        /// </summary>
102
        public MatrixAggregateFunction Function
103
        {
104
            get { return function; }
105
            set { 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>
111
        public MatrixPercent Percent
112
        {
113
            get { return percent; }
114
            set { percent = value; }
115
        }
116
        #endregion
117

118
        #region Public Methods
119
        /// <inheritdoc/>
120
        public override void Assign(MatrixDescriptor source)
121
        {
122
            base.Assign(source);
123
            MatrixCellDescriptor src = source as MatrixCellDescriptor;
124
            if (src != null)
125
            {
126
                Function = src.Function;
127
                Percent = src.Percent;
128
            }
129
        }
130

131
        /// <inheritdoc/>
132
        public override void Serialize(FRWriter writer)
133
        {
134
            MatrixCellDescriptor c = writer.DiffObject as MatrixCellDescriptor;
135
            base.Serialize(writer);
136

137
            writer.ItemName = "Cell";
138
            if (Function != c.Function)
139
                writer.WriteValue("Function", Function);
140
            if (Percent != c.Percent)
141
                writer.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>
149
        public 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>
158
        public 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>
168
        public 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>
179
        public MatrixCellDescriptor(string expression, MatrixAggregateFunction function, MatrixPercent percent)
180
        {
181
            Expression = expression;
182
            this.function = function;
183
            this.percent = percent;
184
        }
185
    }
186
}
187

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.