CrossViewCellDescriptor.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 CrossView data cell.
  10. /// </summary>
  11. /// <remarks>
  12. /// The <see cref="CrossViewCellDescriptor"/> class is used to define one data cell of the CrossView.
  13. /// To set visual appearance of the data cell, use the <see cref="CrossViewDescriptor.TemplateCell"/>
  14. /// property.
  15. /// <para/>The collection of descriptors used to represent the CrossView data cells is stored
  16. /// in the <b>CrossViewObject.Data.Cells</b> property.
  17. /// </remarks>
  18. public class CrossViewCellDescriptor : CrossViewDescriptor
  19. {
  20. #region Fields
  21. internal string xFieldName;
  22. internal string yFieldName;
  23. internal string measureName;
  24. internal bool isXGrandTotal;
  25. internal bool isYGrandTotal;
  26. internal bool isXTotal;
  27. internal bool isYTotal;
  28. #pragma warning disable FR0001 // Field names must be longer than 2 characters.
  29. internal int x;
  30. internal int y;
  31. #pragma warning restore FR0001 // Field names must be longer than 2 characters.
  32. #endregion
  33. #region Properties
  34. /// <summary>
  35. /// Gets a value indicating that this is the "GrandTotal" element on X axis.
  36. /// </summary>
  37. public bool IsXGrandTotal
  38. {
  39. set { isXGrandTotal = value; }
  40. get { return isXGrandTotal; }
  41. }
  42. /// <summary>
  43. /// Gets a value indicating that this is the "GrandTotal" element on Y axis.
  44. /// </summary>
  45. public bool IsYGrandTotal
  46. {
  47. set { isYGrandTotal = value; }
  48. get { return isYGrandTotal; }
  49. }
  50. /// <summary>
  51. /// Gets a value indicating that this is the "Total" element on X axis.
  52. /// </summary>
  53. public bool IsXTotal
  54. {
  55. set { isXTotal = value; }
  56. get { return isXTotal; }
  57. }
  58. /// <summary>
  59. /// Gets a value indicating that this is the "Total" element on Y axis.
  60. /// </summary>
  61. public bool IsYTotal
  62. {
  63. set { isYTotal = value; }
  64. get { return isYTotal; }
  65. }
  66. /// <summary>
  67. /// Gets the name of field in X axis.
  68. /// </summary>
  69. public string XFieldName
  70. {
  71. set { xFieldName = value; }
  72. get { return xFieldName; }
  73. }
  74. /// <summary>
  75. /// Gets the name of field in Y axis.
  76. /// </summary>
  77. public string YFieldName
  78. {
  79. set { yFieldName = value; }
  80. get { return yFieldName; }
  81. }
  82. /// <summary>
  83. /// Gets the name of measure in cube.
  84. /// </summary>
  85. public string MeasureName
  86. {
  87. set { measureName = value; }
  88. get { return measureName; }
  89. }
  90. /// <summary>
  91. /// Gets the x coordinate.
  92. /// </summary>
  93. public int X
  94. {
  95. set { x = value; }
  96. get { return x; }
  97. }
  98. /// <summary>
  99. /// Gets the y coordinate.
  100. /// </summary>
  101. public int Y
  102. {
  103. set { y = value; }
  104. get { return y; }
  105. }
  106. #endregion
  107. #region Public Methods
  108. /// <inheritdoc/>
  109. public override void Assign(CrossViewDescriptor source)
  110. {
  111. base.Assign(source);
  112. CrossViewCellDescriptor src = source as CrossViewCellDescriptor;
  113. if (src != null)
  114. {
  115. isXTotal = src.isXTotal;
  116. isYTotal = src.isYTotal;
  117. isXGrandTotal = src.isXGrandTotal;
  118. isYGrandTotal = src.isYGrandTotal;
  119. xFieldName = src.xFieldName;
  120. yFieldName = src.yFieldName;
  121. measureName = src.measureName;
  122. x = src.x;
  123. y = src.y;
  124. }
  125. }
  126. /// <inheritdoc/>
  127. public override void Serialize(FRWriter writer)
  128. {
  129. CrossViewCellDescriptor c = writer.DiffObject as CrossViewCellDescriptor;
  130. base.Serialize(writer);
  131. writer.ItemName = "Cell";
  132. if (IsXTotal != c.IsXTotal)
  133. writer.WriteBool("IsXTotal", IsXTotal);
  134. if (IsYTotal != c.IsYTotal)
  135. writer.WriteBool("IsYTotal", IsYTotal);
  136. if (IsXGrandTotal != c.IsXGrandTotal)
  137. writer.WriteBool("IsXGrandTotal", IsXGrandTotal);
  138. if (IsYGrandTotal != c.IsYGrandTotal)
  139. writer.WriteBool("IsYGrandTotal", IsYGrandTotal);
  140. if (XFieldName != c.XFieldName)
  141. writer.WriteStr("XFieldName", XFieldName);
  142. if (YFieldName != c.YFieldName)
  143. writer.WriteStr("YFieldName", YFieldName);
  144. if (MeasureName != c.MeasureName)
  145. writer.WriteStr("MeasureName", MeasureName);
  146. if (X != c.X)
  147. writer.WriteInt("X", X);
  148. if (Y != c.Y)
  149. writer.WriteInt("Y", Y);
  150. }
  151. #endregion
  152. /// <summary>
  153. /// Initializes a new instance of the <see cref="CrossViewCellDescriptor"/> class
  154. /// </summary>
  155. /// <param name="xFieldName">The Field Name in X axis.</param>
  156. /// <param name="yFieldName">The Field Name in Y axis.</param>
  157. /// <param name="measureName">The Measure Name.</param>
  158. /// <param name="isXTotal">Indicates the "XTotal" element.</param>
  159. /// <param name="isYTotal">Indicates the "YTotal" element.</param>
  160. /// <param name="isXGrandTotal">Indicates the "XGrandTotal" element.</param>
  161. /// <param name="isYGrandTotal">Indicates the "YGrandTotal" element.</param>
  162. public CrossViewCellDescriptor(string xFieldName, string yFieldName, string measureName, bool isXTotal, bool isYTotal, bool isXGrandTotal, bool isYGrandTotal)
  163. {
  164. this.isXGrandTotal = isXGrandTotal;
  165. this.isYGrandTotal = isYGrandTotal;
  166. this.measureName = measureName;
  167. if (isXGrandTotal)
  168. {
  169. this.xFieldName = "";
  170. this.isXTotal = false;
  171. }
  172. else
  173. {
  174. this.xFieldName = xFieldName;
  175. this.isXTotal = isXTotal;
  176. }
  177. if (isYGrandTotal)
  178. {
  179. this.yFieldName = "";
  180. this.isYTotal = false;
  181. }
  182. else
  183. {
  184. this.yFieldName = yFieldName;
  185. this.isYTotal = isYTotal;
  186. }
  187. }
  188. /// <summary>
  189. /// Initializes a new instance of the <see cref="CrossViewCellDescriptor"/> class
  190. /// </summary>
  191. public CrossViewCellDescriptor()
  192. : this("", "", "", false, false, false, false)
  193. {
  194. }
  195. }
  196. }