TotalCollection.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Utils;
  5. namespace FastReport.Data
  6. {
  7. /// <summary>
  8. /// Represents the collection of <see cref="Total"/> objects.
  9. /// </summary>
  10. public class TotalCollection : FRCollectionBase
  11. {
  12. /// <summary>
  13. /// Gets or sets a total.
  14. /// </summary>
  15. /// <param name="index">The index of a total in this collection.</param>
  16. /// <returns>The total with specified index.</returns>
  17. public Total this[int index]
  18. {
  19. get { return List[index] as Total; }
  20. set { List[index] = value; }
  21. }
  22. /// <summary>
  23. /// Finds a total by its name.
  24. /// </summary>
  25. /// <param name="name">The name of a total.</param>
  26. /// <returns>The <see cref="Total"/> object if found; otherwise <b>null</b>.</returns>
  27. public Total FindByName(string name)
  28. {
  29. foreach (Total c in this)
  30. {
  31. // check complete match or match without case sensitivity
  32. if (c.Name == name || c.Name.ToLower() == name.ToLower())
  33. return c;
  34. }
  35. return null;
  36. }
  37. /// <summary>
  38. /// Returns an unique total name based on given name.
  39. /// </summary>
  40. /// <param name="name">The base name.</param>
  41. /// <returns>The unique name.</returns>
  42. public string CreateUniqueName(string name)
  43. {
  44. string baseName = name;
  45. int i = 1;
  46. while (FindByName(name) != null)
  47. {
  48. name = baseName + i.ToString();
  49. i++;
  50. }
  51. return name;
  52. }
  53. internal object GetValue(string name)
  54. {
  55. Total t = FindByName(name);
  56. if (t == null)
  57. throw new UnknownNameException(name);
  58. return t.Value;
  59. }
  60. internal void ProcessBand(BandBase band)
  61. {
  62. foreach (Total total in this)
  63. {
  64. if (total.Evaluator == band)
  65. total.AddValue();
  66. else if (total.PrintOn == band && total.ResetAfterPrint)
  67. {
  68. if (!band.Repeated || total.ResetOnReprint)
  69. total.ResetValue();
  70. }
  71. }
  72. }
  73. internal void ClearValues()
  74. {
  75. foreach (Total total in this)
  76. {
  77. total.Clear();
  78. }
  79. }
  80. internal void StartKeep()
  81. {
  82. foreach (Total total in this)
  83. {
  84. total.StartKeep();
  85. }
  86. }
  87. internal void EndKeep()
  88. {
  89. foreach (Total total in this)
  90. {
  91. total.EndKeep();
  92. }
  93. }
  94. /// <summary>
  95. /// Initializes a new instance of the <see cref="TotalCollection"/> class with default settings.
  96. /// </summary>
  97. /// <param name="owner">The owner of this collection.</param>
  98. public TotalCollection(Base owner) : base(owner)
  99. {
  100. }
  101. }
  102. }