CrossViewHeaderDescriptor.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Table;
  5. using FastReport.Utils;
  6. namespace FastReport.CrossView
  7. {
  8. /// <summary>
  9. /// The descriptor that is used to describe one element of the CrossView header.
  10. /// </summary>
  11. /// <remarks>
  12. /// The <see cref="CrossViewHeaderDescriptor"/> class is used to define one header element of the CrossView
  13. /// (either the column element or row element).
  14. /// <para/>To set visual appearance of the element, use the <see cref="CrossViewDescriptor.TemplateCell"/>
  15. /// property.
  16. /// <para/>The collection of descriptors used to represent the CrossView header is stored
  17. /// in the <b>CrossViewObject.Data.Columns</b> and <b>CrossViewObject.Data.Rows</b> properties.
  18. /// </remarks>
  19. public class CrossViewHeaderDescriptor : CrossViewDescriptor
  20. {
  21. #region Fields
  22. internal string fieldName = "";
  23. internal string measureName = "";
  24. internal bool isGrandTotal;
  25. internal bool isTotal;
  26. internal bool isMeasure;
  27. internal int level = 0;
  28. internal int cell = 0;
  29. internal int levelsize = 1;
  30. internal int cellsize = 1;
  31. #endregion
  32. #region Properties
  33. /// <summary>
  34. /// Gets a value indicating that this is the "GrandTotal" element.
  35. /// </summary>
  36. public bool IsGrandTotal
  37. {
  38. set { isGrandTotal = value; }
  39. get { return isGrandTotal; }
  40. }
  41. /// <summary>
  42. /// Gets a value indicating that this is the "Total" element.
  43. /// </summary>
  44. public bool IsTotal
  45. {
  46. set { isTotal = value; }
  47. get { return isTotal; }
  48. }
  49. /// <summary>
  50. /// Gets a value indicating that this is the "Measure" element.
  51. /// </summary>
  52. public bool IsMeasure
  53. {
  54. set { isMeasure = value; }
  55. get { return isMeasure; }
  56. }
  57. /// <summary>
  58. /// Gets the name of field in cube.
  59. /// </summary>
  60. public string FieldName
  61. {
  62. set { fieldName = value; }
  63. get { return fieldName; }
  64. }
  65. /// <summary>
  66. /// Gets the name of measure in cube.
  67. /// </summary>
  68. public string MeasureName
  69. {
  70. set { measureName = value; }
  71. get { return measureName; }
  72. }
  73. /// <summary>
  74. /// Gets the cell coordinate.
  75. /// </summary>
  76. public int Cell
  77. {
  78. set { cell = value; }
  79. get { return cell; }
  80. }
  81. /// <summary>
  82. /// Gets the size in cell coordinate.
  83. /// </summary>
  84. public int CellSize
  85. {
  86. set { cellsize = value; }
  87. get { return cellsize; }
  88. }
  89. /// <summary>
  90. /// Gets the level coordinate.
  91. /// </summary>
  92. public int Level
  93. {
  94. set { level = value; }
  95. get { return level; }
  96. }
  97. /// <summary>
  98. /// Gets the size in level coordinate.
  99. /// </summary>
  100. public int LevelSize
  101. {
  102. set { levelsize = value; }
  103. get { return levelsize; }
  104. }
  105. #endregion
  106. #region Public Methods
  107. /// <inheritdoc/>
  108. public override void Assign(CrossViewDescriptor source)
  109. {
  110. base.Assign(source);
  111. CrossViewHeaderDescriptor src = source as CrossViewHeaderDescriptor;
  112. if (src != null)
  113. {
  114. isTotal = src.isTotal;
  115. isGrandTotal = src.isGrandTotal;
  116. fieldName = src.fieldName;
  117. measureName = src.measureName;
  118. isMeasure = src.isMeasure;
  119. level = src.level;
  120. levelsize = src.levelsize;
  121. cell = src.cell;
  122. cellsize = src.cellsize;
  123. }
  124. }
  125. /// <inheritdoc/>
  126. public override void Serialize(FRWriter writer)
  127. {
  128. CrossViewHeaderDescriptor c = writer.DiffObject as CrossViewHeaderDescriptor;
  129. base.Serialize(writer);
  130. writer.ItemName = "Header";
  131. if (IsTotal != c.IsTotal)
  132. writer.WriteBool("IsTotal", IsTotal);
  133. if (IsGrandTotal != c.IsGrandTotal)
  134. writer.WriteBool("IsGrandTotal", IsGrandTotal);
  135. if (FieldName != c.FieldName)
  136. writer.WriteStr("FieldName", FieldName);
  137. if (MeasureName != c.MeasureName)
  138. writer.WriteStr("MeasureName", MeasureName);
  139. if (IsMeasure != c.IsMeasure)
  140. writer.WriteBool("IsMeasure", IsMeasure);
  141. if (Cell != c.Cell)
  142. writer.WriteInt("Cell", Cell);
  143. if (CellSize != c.CellSize)
  144. writer.WriteInt("CellSize", CellSize);
  145. if (Level != c.Level)
  146. writer.WriteInt("Level", Level);
  147. if (LevelSize != c.LevelSize)
  148. writer.WriteInt("LevelSize", LevelSize);
  149. }
  150. internal string GetName()
  151. {
  152. if (isGrandTotal)
  153. {
  154. return "GrandTotal";
  155. };
  156. if (IsMeasure)
  157. {
  158. return measureName;
  159. };
  160. if (isTotal)
  161. {
  162. return "Total of " + fieldName;
  163. };
  164. return fieldName;
  165. }
  166. #endregion
  167. /// <summary>
  168. /// Initializes a new instance of the <see cref="CrossViewHeaderDescriptor"/> class
  169. /// </summary>
  170. /// <param name="fieldName">The Field Name.</param>
  171. /// <param name="measureName">The Measure Name.</param>
  172. /// <param name="isTotal">Indicates the "Total" element.</param>
  173. /// <param name="isGrandTotal">Indicates the "GrandTotal" element.</param>
  174. /// <param name="isMeasure">Indicates the "Measure" element.</param>
  175. public CrossViewHeaderDescriptor(string fieldName, string measureName, bool isTotal, bool isGrandTotal, bool isMeasure)
  176. {
  177. this.isGrandTotal = isGrandTotal;
  178. this.fieldName = fieldName;
  179. this.measureName = measureName;
  180. this.isTotal = isTotal;
  181. this.isMeasure = isMeasure;
  182. }
  183. /// <summary>
  184. /// Initializes a new instance of the <see cref="CrossViewHeaderDescriptor"/> class
  185. /// </summary>
  186. public CrossViewHeaderDescriptor()
  187. : this("", "", false, false, false)
  188. {
  189. }
  190. }
  191. }