FastReport

Форк
0
322 строки · 9.2 Кб
1
using System;
2
using System.ComponentModel;
3
using System.Collections.Generic;
4
using FastReport.Utils;
5
using System.Drawing;
6
using System.Drawing.Design;
7

8
namespace FastReport.Gauge
9
{
10
    /// <summary>
11
    /// Represents a gauge object.
12
    /// </summary>
13
    public partial class GaugeObject : ReportComponentBase
14
    {
15
        #region Fields
16

17
        private double maximum;
18
        private double minimum;
19
        private double value;
20
        private GaugeScale scale;
21
        private GaugePointer pointer;
22
        private GaugeLabel label;
23
        private string expression;
24

25
        #endregion // Fields
26

27
        #region Properties
28

29
        /// <summary>
30
        /// Gets or sets the minimal value of gauge.
31
        /// </summary>
32
        [Category("Layout")]
33
        public double Minimum
34
        {
35
            get { return minimum; }
36
            set
37
            {
38
                if (value < maximum)
39
                {
40
                    minimum = value;
41
                    if (this.value < minimum)
42
                    {
43
                        this.value = minimum;
44
                    }
45
                }
46
            }
47
        }
48

49
        /// <summary>
50
        /// Gets or sets the maximal value of gauge.
51
        /// </summary>
52
        [Category("Layout")]
53
        public double Maximum
54
        {
55
            get { return maximum; }
56
            set
57
            {
58
                if (value > minimum)
59
                {
60
                    maximum = value;
61
                    if (this.value > maximum)
62
                    {
63
                        this.value = maximum;
64
                    }
65
                }
66
            }
67
        }
68

69
        /// <summary>
70
        /// Gets or sets the current value of gauge.
71
        /// </summary>
72
        [Category("Layout")]
73
        public double Value
74
        {
75
            get { return value; }
76
            set
77
            {
78
                if ((value >= minimum) && (value <= maximum))
79
                {
80
                    this.value = value;
81
                }
82
                else if (value < minimum)
83
                {
84
                    this.value = minimum;
85
                }
86
                else if (value > maximum)
87
                {
88
                    this.value = maximum;
89
                }
90
            }
91
        }
92

93
        /// <summary>
94
        /// Gets or sets scale of gauge.
95
        /// </summary>
96
        [Category("Appearance")]
97
        [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
98
        [Editor("FastReport.TypeEditors.ScaleEditor, FastReport", typeof(UITypeEditor))]
99
        public GaugeScale Scale
100
        {
101
            get { return scale; }
102
            set { scale = value; }
103
        }
104

105
        /// <summary>
106
        /// Gets or sets pointer of gauge.
107
        /// </summary>
108
        [Category("Appearance")]
109
        [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
110
        [Editor("FastReport.TypeEditors.PointerEditor, FastReport", typeof(UITypeEditor))]
111
        public GaugePointer Pointer
112
        {
113
            get { return pointer; }
114
            set { pointer = value; }
115
        }
116

117
        /// <summary>
118
        /// Gets or sets gauge label.
119
        /// </summary>
120
        [Category("Appearance")]
121
        [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
122
        [Editor("FastReport.TypeEditors.LabelEditor, FastReport", typeof(UITypeEditor))]
123
        public virtual GaugeLabel Label
124
        {
125
            get { return label; }
126
            set { label = value; }
127
        }
128

129
        /// <summary>
130
        /// Gets or sets an expression that determines the value of gauge object.
131
        /// </summary>
132
        [Category("Data")]
133
        [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
134
        public string Expression
135
        {
136
            get { return expression; }
137
            set { expression = value; }
138
        }
139

140
        /// <summary>
141
        /// Gets a value that specifies is gauge vertical or not.
142
        /// </summary>
143
        [Browsable(false)]
144
        public bool Vertical
145
        {
146
            get { return Width < Height; }
147
        }
148

149
        #endregion // Properties
150

151
        #region Constructors
152

153
        /// <summary>
154
        /// Initializes a new instance of the <see cref="GaugeObject"/> class.
155
        /// </summary>
156
        public GaugeObject()
157
        {
158
            minimum = 0;
159
            maximum = 100;
160
            value = 10;
161
            scale = new GaugeScale(this);
162
            pointer = new GaugePointer(this);
163
            label = new GaugeLabel(this);
164
            expression = "";
165
        }
166

167
        /// <summary>
168
        /// Initializes a new instance of the <see cref="GaugeObject"/> class.
169
        /// </summary>
170
        /// <param name="minimum">Minimum value of gauge.</param>
171
        /// <param name="maximum">Maximum value of gauge.</param>
172
        /// <param name="value">Current value of gauge.</param>
173
        public GaugeObject(double minimum, double maximum, double value)
174
        {
175
            this.minimum = minimum;
176
            this.maximum = maximum;
177
            this.value = value;
178
            scale = new GaugeScale(this);
179
            pointer = new GaugePointer(this);
180
            label = new GaugeLabel(this);
181
            expression = "";
182
        }
183

184
        /// <summary>
185
        /// Initializes a new instance of the <see cref="GaugeObject"/> class.
186
        /// </summary>
187
        /// <param name="minimum">Minimum value of gauge.</param>
188
        /// <param name="maximum">Maximum value of gauge.</param>
189
        /// <param name="value">Current value of gauge.</param>
190
        /// <param name="scale">Scale of gauge.</param>
191
        /// <param name="pointer">Pointer of gauge.</param>
192
        public GaugeObject(double minimum, double maximum, double value, GaugeScale scale, GaugePointer pointer)
193
        {
194
            this.minimum = minimum;
195
            this.maximum = maximum;
196
            this.value = value;
197
            this.scale = scale;
198
            this.pointer = pointer;
199
            label = new GaugeLabel(this);
200
            expression = "";
201
        }
202

203
        #endregion // Constructors
204

205
        #region Report Engine
206

207
        /// <inheritdoc/>
208
        public override string[] GetExpressions()
209
        {
210
            List<string> expressions = new List<string>();
211
            expressions.AddRange(base.GetExpressions());
212

213
            if (!String.IsNullOrEmpty(Expression))
214
            {
215
                expressions.Add(Expression);
216
            }
217
            return expressions.ToArray();
218
        }
219

220
        /// <inheritdoc/>
221
        public override void GetData()
222
        {
223
            base.GetData();
224

225
            if (!String.IsNullOrEmpty(Expression))
226
            {
227
                object val = Report.Calc(Expression);
228
                if (val != null)
229
                {
230
                    try
231
                    {
232
                        Value = Converter.StringToFloat(val.ToString());
233
                    }
234
                    catch
235
                    {
236
                        Value = 0.0;
237
                    }
238
                }
239
            }
240
        }
241

242
        #endregion // Report Engine
243

244
        #region Public Methods
245

246
        /// <inheritdoc/>
247
        public override void Assign(Base source)
248
        {
249
            base.Assign(source);
250

251
            GaugeObject src = source as GaugeObject;
252
            Maximum = src.Maximum;
253
            Minimum = src.Minimum;
254
            Value = src.Value;
255
            Expression = src.Expression;
256
            Scale.Assign(src.Scale);
257
            Pointer.Assign(src.Pointer);
258
            Label.Assign(src.Label);
259
        }
260

261
        /// <summary>
262
        /// Draws the gauge.
263
        /// </summary>
264
        /// <param name="e">Draw event arguments.</param>
265
        public override void Draw(FRPaintEventArgs e)
266
        {
267
            base.Draw(e);
268
            scale.Draw(e);
269
            pointer.Draw(e);
270
            Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
271
        }
272

273
        /// <inheritdoc/>
274
        public override void Serialize(FRWriter writer)
275
        {
276
            GaugeObject c = writer.DiffObject as GaugeObject;
277
            base.Serialize(writer);
278

279
            if (Maximum != c.Maximum)
280
            {
281
                writer.WriteDouble("Maximum", Maximum);
282
            }
283
            if (Minimum != c.Minimum)
284
            {
285
                writer.WriteDouble("Minimum", Minimum);
286
            }
287
            if (Value != c.Value)
288
            {
289
                writer.WriteDouble("Value", Value);
290
            }
291
            if (Expression != c.Expression)
292
            {
293
                writer.WriteStr("Expression", Expression);
294
            }
295
            if (Scale != c.Scale)
296
            {
297
                Scale.Serialize(writer, "Scale", c.Scale);
298
            }
299
            if (Pointer != c.Pointer)
300
            {
301
                Pointer.Serialize(writer, "Pointer", c.Pointer);
302
            }
303
            if (Label != c.Label)
304
            {
305
                Label.Serialize(writer, "Label", c.Label);
306
            }
307
        }
308

309
        /// <summary>
310
        /// Clone Gauge Object
311
        /// </summary>
312
        /// <returns> clone of this object</returns>
313
        public GaugeObject Clone()
314
        {
315
            var clone = Activator.CreateInstance(this.GetType()) as GaugeObject;
316
            clone.Assign(this);
317
            return clone;
318
        }
319

320
        #endregion // Public Methods
321
    }
322
}
323

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

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

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

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