using System; using FastReport.Utils; namespace FastReport.AdvMatrix { /// /// Stores the TopN settings of the matrix header item. /// public class TopNInfo { /// /// Gets or sets the TopN count. 0 means no TopN grouping will be performed. /// public int Count { get; set; } /// /// Gets the properties of TopN total item. /// public ItemInfo Total { get; private set; } /// /// Gets the properties of Others item. /// public ItemInfo Others { get; private set; } /// /// Gets the properties of Others total item. /// public ItemInfo OthersTotal { get; private set; } internal void Serialize(FRWriter writer, string prefix, TopNInfo c) { if (Count != c.Count) writer.WriteInt(prefix + ".Count", Count); Total.Serialize(writer, prefix + ".Total", c.Total); Others.Serialize(writer, prefix + ".Others", c.Others); OthersTotal.Serialize(writer, prefix + ".OthersTotal", c.OthersTotal); } internal TopNInfo(HeaderDescriptor descr) { Total = new ItemInfo(descr) { Text = "Total" }; Others = new ItemInfo(descr) { Visible = false }; OthersTotal = new ItemInfo(descr) { Text = "Others" }; } /// /// Stores the properties of TopN item. /// public class ItemInfo { private HeaderDescriptor descr; /// /// Gets or sets the Name of the header descriptor item. /// public string Name { get; set; } /// /// Gets or set the initial visibility of this item. /// public bool Visible { get; set; } /// /// Gets or set the text of this item. Applicable to "Total" items. /// public string Text { get; set; } internal HeaderDescriptor Descriptor { get { HeaderDescriptor result = FindDescriptorInternal(descr.Parent); if (result == null && descr.Parent != null) result = FindDescriptorInternal(descr.Parent.Parent); return result; } } private HeaderDescriptor FindDescriptorInternal(HeaderDescriptor root) { if (root == null || String.IsNullOrEmpty(Name)) return null; if (root.Name == Name) return root; foreach (HeaderDescriptor d in root.Items) { HeaderDescriptor result = FindDescriptorInternal(d); if (result != null) return result; } return null; } internal void Serialize(FRWriter writer, string prefix, ItemInfo c) { if (Name != c.Name) writer.WriteStr(prefix + ".Name", Name); if (Visible != c.Visible) writer.WriteBool(prefix + ".Visible", Visible); if (Text != c.Text) writer.WriteStr(prefix + ".Text", Text); } internal ItemInfo(HeaderDescriptor descr) { this.descr = descr; Name = ""; Visible = true; Text = ""; } } } }