BandColumns.cs 4.2 KB

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