using System; using System.Collections.Generic; using System.Text; using FastReport.Utils; namespace FastReport.Data { /// /// Represents the collection of objects. /// public class TotalCollection : FRCollectionBase { /// /// Gets or sets a total. /// /// The index of a total in this collection. /// The total with specified index. public Total this[int index] { get { return List[index] as Total; } set { List[index] = value; } } /// /// Finds a total by its name. /// /// The name of a total. /// The object if found; otherwise null. public Total FindByName(string name) { foreach (Total c in this) { // check complete match or match without case sensitivity if (c.Name == name || c.Name.ToLower() == name.ToLower()) return c; } return null; } /// /// Returns an unique total name based on given name. /// /// The base name. /// The unique name. public string CreateUniqueName(string name) { string baseName = name; int i = 1; while (FindByName(name) != null) { name = baseName + i.ToString(); i++; } return name; } internal object GetValue(string name) { Total t = FindByName(name); if (t == null) throw new UnknownNameException(name); return t.Value; } internal void ProcessBand(BandBase band) { foreach (Total total in this) { if (total.Evaluator == band) total.AddValue(); else if (total.PrintOn == band && total.ResetAfterPrint) { if (!band.Repeated || total.ResetOnReprint) total.ResetValue(); } } } internal void ClearValues() { foreach (Total total in this) { total.Clear(); } } internal void StartKeep() { foreach (Total total in this) { total.StartKeep(); } } internal void EndKeep() { foreach (Total total in this) { total.EndKeep(); } } /// /// Initializes a new instance of the class with default settings. /// /// The owner of this collection. public TotalCollection(Base owner) : base(owner) { } } }