FastReport
145 строк · 4.2 Кб
1using System;
2using System.ComponentModel;
3using FastReport.Utils;
4
5namespace FastReport
6{
7/// <summary>
8/// The layout of the data band columns.
9/// </summary>
10public enum ColumnLayout
11{
12/// <summary>
13/// Print columns across then down.
14/// </summary>
15AcrossThenDown,
16
17/// <summary>
18/// Print columns down then across.
19/// </summary>
20DownThenAcross
21}
22
23/// <summary>
24/// This class holds the band columns settings. It is used in the <see cref="DataBand.Columns"/> property.
25/// </summary>
26[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
27public class BandColumns
28{
29private int count;
30private float width;
31private ColumnLayout layout;
32private int minRowCount;
33private DataBand band;
34
35/// <summary>
36/// Gets or sets the number of columns.
37/// </summary>
38/// <remarks>
39/// Set this property to 0 or 1 if you don't want to use columns.
40/// </remarks>
41[DefaultValue(0)]
42public int Count
43{
44get { return count; }
45set
46{
47if (value < 0)
48throw new ArgumentOutOfRangeException("Count", "Value must be >= 0");
49count = value;
50}
51}
52
53/// <summary>
54/// The column width, in pixels.
55/// </summary>
56[DefaultValue(0f)]
57[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
58public float Width
59{
60get { return width; }
61set { width = value; }
62}
63
64/// <summary>
65/// Gets or sets the layout of the columns.
66/// </summary>
67[DefaultValue(ColumnLayout.AcrossThenDown)]
68public ColumnLayout Layout
69{
70get { return layout; }
71set { layout = value; }
72}
73
74/// <summary>
75/// Gets or sets the minimum row count that must be printed.
76/// </summary>
77/// <remarks>
78/// This property is used if the <b>Layout</b> property is set to <b>DownThenAcross</b>. 0 means that
79/// FastReport should calculate the optimal number of rows.
80/// </remarks>
81[DefaultValue(0)]
82public int MinRowCount
83{
84get { return minRowCount; }
85set { minRowCount = value; }
86}
87
88internal float ActualWidth
89{
90get
91{
92ReportPage page = band.Page as ReportPage;
93if (Width == 0 && page != null)
94return (page.PaperWidth - page.LeftMargin - page.RightMargin) * Units.Millimeters / (Count == 0 ? 1 : Count);
95return Width;
96}
97}
98
99internal FloatCollection Positions
100{
101get
102{
103FloatCollection positions = new FloatCollection();
104float columnWidth = ActualWidth;
105for (int i = 0; i < Count; i++)
106{
107positions.Add(i * columnWidth);
108}
109return positions;
110}
111}
112
113/// <summary>
114/// Assigns values from another source.
115/// </summary>
116/// <param name="source">Source to assign from.</param>
117public void Assign(BandColumns source)
118{
119Count = source.Count;
120Width = source.Width;
121Layout = source.Layout;
122MinRowCount = source.MinRowCount;
123}
124
125internal void Serialize(FRWriter writer, BandColumns c)
126{
127if (Count != c.Count)
128writer.WriteInt("Columns.Count", Count);
129if (Width != c.Width)
130writer.WriteFloat("Columns.Width", Width);
131if (Layout != c.Layout)
132writer.WriteValue("Columns.Layout", Layout);
133if (MinRowCount != c.MinRowCount)
134writer.WriteInt("Columns.MinRowCount", MinRowCount);
135}
136
137/// <summary>
138/// Initializes a new instance of the <b>BandColumns</b> class with default settings.
139/// </summary>
140public BandColumns(DataBand band)
141{
142this.band = band;
143}
144}
145}
146