TopN.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using FastReport.Utils;
  3. namespace FastReport.AdvMatrix
  4. {
  5. /// <summary>
  6. /// Stores the TopN settings of the matrix header item.
  7. /// </summary>
  8. public class TopNInfo
  9. {
  10. /// <summary>
  11. /// Gets or sets the TopN count. 0 means no TopN grouping will be performed.
  12. /// </summary>
  13. public int Count { get; set; }
  14. /// <summary>
  15. /// Gets the properties of TopN total item.
  16. /// </summary>
  17. public ItemInfo Total { get; private set; }
  18. /// <summary>
  19. /// Gets the properties of Others item.
  20. /// </summary>
  21. public ItemInfo Others { get; private set; }
  22. /// <summary>
  23. /// Gets the properties of Others total item.
  24. /// </summary>
  25. public ItemInfo OthersTotal { get; private set; }
  26. internal void Serialize(FRWriter writer, string prefix, TopNInfo c)
  27. {
  28. if (Count != c.Count)
  29. writer.WriteInt(prefix + ".Count", Count);
  30. Total.Serialize(writer, prefix + ".Total", c.Total);
  31. Others.Serialize(writer, prefix + ".Others", c.Others);
  32. OthersTotal.Serialize(writer, prefix + ".OthersTotal", c.OthersTotal);
  33. }
  34. internal TopNInfo(HeaderDescriptor descr)
  35. {
  36. Total = new ItemInfo(descr) { Text = "Total" };
  37. Others = new ItemInfo(descr) { Visible = false };
  38. OthersTotal = new ItemInfo(descr) { Text = "Others" };
  39. }
  40. /// <summary>
  41. /// Stores the properties of TopN item.
  42. /// </summary>
  43. public class ItemInfo
  44. {
  45. private HeaderDescriptor descr;
  46. /// <summary>
  47. /// Gets or sets the Name of the header descriptor item.
  48. /// </summary>
  49. public string Name { get; set; }
  50. /// <summary>
  51. /// Gets or set the initial visibility of this item.
  52. /// </summary>
  53. public bool Visible { get; set; }
  54. /// <summary>
  55. /// Gets or set the text of this item. Applicable to "Total" items.
  56. /// </summary>
  57. public string Text { get; set; }
  58. internal HeaderDescriptor Descriptor
  59. {
  60. get
  61. {
  62. HeaderDescriptor result = FindDescriptorInternal(descr.Parent);
  63. if (result == null && descr.Parent != null)
  64. result = FindDescriptorInternal(descr.Parent.Parent);
  65. return result;
  66. }
  67. }
  68. private HeaderDescriptor FindDescriptorInternal(HeaderDescriptor root)
  69. {
  70. if (root == null || String.IsNullOrEmpty(Name))
  71. return null;
  72. if (root.Name == Name)
  73. return root;
  74. foreach (HeaderDescriptor d in root.Items)
  75. {
  76. HeaderDescriptor result = FindDescriptorInternal(d);
  77. if (result != null)
  78. return result;
  79. }
  80. return null;
  81. }
  82. internal void Serialize(FRWriter writer, string prefix, ItemInfo c)
  83. {
  84. if (Name != c.Name)
  85. writer.WriteStr(prefix + ".Name", Name);
  86. if (Visible != c.Visible)
  87. writer.WriteBool(prefix + ".Visible", Visible);
  88. if (Text != c.Text)
  89. writer.WriteStr(prefix + ".Text", Text);
  90. }
  91. internal ItemInfo(HeaderDescriptor descr)
  92. {
  93. this.descr = descr;
  94. Name = "";
  95. Visible = true;
  96. Text = "";
  97. }
  98. }
  99. }
  100. }