SystemVariables.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. namespace FastReport.Data
  6. {
  7. /// <summary>
  8. /// Represents the collection of system variables.
  9. /// </summary>
  10. public class SystemVariables : ParameterCollection
  11. {
  12. internal SystemVariables(Base owner) : base(owner)
  13. {
  14. Add(new DateVariable());
  15. Add(new PageVariable());
  16. Add(new TotalPagesVariable());
  17. Add(new PageNVariable());
  18. Add(new PageNofMVariable());
  19. Add(new RowVariable());
  20. Add(new AbsRowVariable());
  21. Add(new PageMacroVariable());
  22. Add(new TotalPagesMacroVariable());
  23. Add(new CopyNameMacroVariable());
  24. Add(new HierarchyLevelVariable());
  25. Add(new HierarchyRowNoVariable());
  26. }
  27. }
  28. /// <summary>
  29. /// Represents the base class for system variables.
  30. /// </summary>
  31. public class SystemVariable : Parameter
  32. {
  33. /// <summary>
  34. /// This property is not relevant to this class.
  35. /// </summary>
  36. [Browsable(false)]
  37. public new string Expression
  38. {
  39. get { return base.Expression; }
  40. set { base.Expression = value; }
  41. }
  42. /// <summary>
  43. /// This property is not relevant to this class.
  44. /// </summary>
  45. [Browsable(false)]
  46. public new string Description
  47. {
  48. get { return base.Description; }
  49. set { base.Description = value; }
  50. }
  51. /// <inheritdoc/>
  52. public override bool CanContain(Base child)
  53. {
  54. return false;
  55. }
  56. }
  57. /// <summary>
  58. /// Returns date and time of the report's start.
  59. /// </summary>
  60. public class DateVariable : SystemVariable
  61. {
  62. /// <inheritdoc/>
  63. public override object Value
  64. {
  65. get { return Report.Engine.Date; }
  66. }
  67. internal DateVariable()
  68. {
  69. Name = "Date";
  70. DataType = typeof(DateTime);
  71. }
  72. }
  73. /// <summary>
  74. /// Returns current page number.
  75. /// </summary>
  76. public class PageVariable : SystemVariable
  77. {
  78. /// <inheritdoc/>
  79. public override object Value
  80. {
  81. get { return Report.Engine.PageNo; }
  82. }
  83. internal PageVariable()
  84. {
  85. Name = "Page";
  86. DataType = typeof(int);
  87. }
  88. }
  89. /// <summary>
  90. /// Returns total number of pages in the report. To use this variable, you need
  91. /// to enable the report's double pass.
  92. /// </summary>
  93. public class TotalPagesVariable : SystemVariable
  94. {
  95. /// <inheritdoc/>
  96. public override object Value
  97. {
  98. get { return Report.Engine.TotalPages; }
  99. }
  100. internal TotalPagesVariable()
  101. {
  102. Name = "TotalPages";
  103. DataType = typeof(int);
  104. }
  105. }
  106. /// <summary>
  107. /// Returns a string containing the current page number in a form "Page N".
  108. /// </summary>
  109. public class PageNVariable : SystemVariable
  110. {
  111. /// <inheritdoc/>
  112. public override object Value
  113. {
  114. get { return Report.Engine.PageN; }
  115. }
  116. internal PageNVariable()
  117. {
  118. Name = "PageN";
  119. DataType = typeof(string);
  120. }
  121. }
  122. /// <summary>
  123. /// Returns a string containing the current page number and total pages in a form "Page N of M".
  124. /// To use this variable, you need to enable the report's double pass.
  125. /// </summary>
  126. public class PageNofMVariable : SystemVariable
  127. {
  128. /// <inheritdoc/>
  129. public override object Value
  130. {
  131. get { return Report.Engine.PageNofM; }
  132. }
  133. internal PageNofMVariable()
  134. {
  135. Name = "PageNofM";
  136. DataType = typeof(string);
  137. }
  138. }
  139. /// <summary>
  140. /// Returns data row number inside the group. This value is reset at the start of a new group.
  141. /// </summary>
  142. public class RowVariable : SystemVariable
  143. {
  144. /// <inheritdoc/>
  145. public override object Value
  146. {
  147. get { return Report.Engine.RowNo; }
  148. }
  149. internal RowVariable()
  150. {
  151. Name = "Row#";
  152. DataType = typeof(int);
  153. }
  154. }
  155. /// <summary>
  156. /// Returns absolute number of data row. This value is never reset at the start of a new group.
  157. /// </summary>
  158. public class AbsRowVariable : SystemVariable
  159. {
  160. /// <inheritdoc/>
  161. public override object Value
  162. {
  163. get { return Report.Engine.AbsRowNo; }
  164. }
  165. internal AbsRowVariable()
  166. {
  167. Name = "AbsRow#";
  168. DataType = typeof(int);
  169. }
  170. }
  171. /// <summary>
  172. /// Returns current page number.
  173. /// <para/>This variable is actually a macro. Its value is substituted when the component is viewed in
  174. /// the preview window. That means you cannot use it in an expression.
  175. /// </summary>
  176. public class PageMacroVariable : SystemVariable
  177. {
  178. /// <inheritdoc/>
  179. public override object Value
  180. {
  181. get { return "[PAGE#]"; }
  182. }
  183. internal PageMacroVariable()
  184. {
  185. Name = "Page#";
  186. DataType = typeof(int);
  187. }
  188. }
  189. /// <summary>
  190. /// Returns the number of total pages in the report.
  191. /// <para/>This variable is actually a macro. Its value is substituted when the component is viewed in
  192. /// the preview window. That means you cannot use it in an expression.
  193. /// </summary>
  194. public class TotalPagesMacroVariable : SystemVariable
  195. {
  196. /// <inheritdoc/>
  197. public override object Value
  198. {
  199. get { return "[TOTALPAGES#]"; }
  200. }
  201. internal TotalPagesMacroVariable()
  202. {
  203. Name = "TotalPages#";
  204. DataType = typeof(int);
  205. }
  206. }
  207. /// <summary>
  208. /// Returns the name of the printed copy.
  209. /// <para/>This variable is actually a macro. Its value is substituted when the component is viewed in
  210. /// the preview window. That means you cannot use it in an expression.
  211. /// </summary>
  212. public class CopyNameMacroVariable : SystemVariable
  213. {
  214. /// <inheritdoc/>
  215. public override object Value
  216. {
  217. get { return "[COPYNAME#]"; }
  218. }
  219. internal CopyNameMacroVariable()
  220. {
  221. Name = "CopyName#";
  222. DataType = typeof(string);
  223. }
  224. }
  225. /// <summary>
  226. /// Returns a level of hierarchy in the hierarchical report.
  227. /// </summary>
  228. public class HierarchyLevelVariable : SystemVariable
  229. {
  230. /// <inheritdoc/>
  231. public override object Value
  232. {
  233. get { return Report.Engine.HierarchyLevel; }
  234. }
  235. internal HierarchyLevelVariable()
  236. {
  237. Name = "HierarchyLevel";
  238. DataType = typeof(int);
  239. }
  240. }
  241. /// <summary>
  242. /// Returns the row number like "1.2.1" in the hierarchical report.
  243. /// </summary>
  244. public class HierarchyRowNoVariable : SystemVariable
  245. {
  246. /// <inheritdoc/>
  247. public override object Value
  248. {
  249. get { return Report.Engine.HierarchyRowNo; }
  250. }
  251. internal HierarchyRowNoVariable()
  252. {
  253. Name = "HierarchyRow#";
  254. DataType = typeof(string);
  255. }
  256. }
  257. }