/// <summary> /// Gets an enumerator to a list of fields that meet the test of being added at the indicated position and this is visible. /// </summary> /// <param name="location">Table position</param> /// <returns> /// Enumerator that contains list of fields that meet the condition and is visible. /// </returns> public IEnumerable <BaseDataFieldModel> GetRange(KnownAggregateLocation location) { SentinelHelper.IsEnumValid(location); return(this.Where(field => field.Aggregate.Show == YesNo.Yes && field.Aggregate.Location == location).ToList()); }
/// <summary> /// Gets a value indicating whether there is a field with a visible aggregate and at specified position. /// </summary> /// <param name="location">Aggregate location</param> /// <returns> /// <strong>true</strong> if there is a field with a visible aggregate and at the specified location; otherwise, <strong>false</strong>. /// </returns> public bool HasVisibleAggregatesByLocation(KnownAggregateLocation location) { SentinelHelper.IsEnumValid(location); return(GetRange(location).Any()); }
/// <summary> /// Adds aggregate to specified table from export model. /// </summary> /// <param name="table">Destination table for headers</param> /// <param name="model">Export table model</param> /// <param name="rows">Source data for calculate the aggregate</param> /// <param name="specialChars">The special chars</param> /// <param name="aggregateLocation">The aggregate location</param> /// <returns> /// table with /// </returns> public static PdfPTable AddAggregateByLocation(this PdfPTable table, TableModel model, XElement[] rows, char[] specialChars, KnownAggregateLocation aggregateLocation) { SentinelHelper.ArgumentNull(table); SentinelHelper.ArgumentNull(model); var hasAnyAggregate = model.Fields.Any(field => field.Aggregate.Show == YesNo.Yes && field.Aggregate.Location == aggregateLocation); if (!hasAnyAggregate) { return(table); } var fix = model.Parent.Resources.Fixed; var rowsCount = rows.Length; var fields = model.Fields; var attributes = rows.Attributes().ToList(); foreach (var field in fields) { var aggregate = field.Aggregate; if (aggregate.AggregateType == KnownAggregateType.None) { continue; } var style = field.Aggregate.GetStyle(); if (field.Aggregate.Show == YesNo.Yes && field.Aggregate.Location == aggregateLocation) { var formula = new NonTabularFormulaResolver(field.Aggregate); switch (field.FieldType) { #region Field: Field case KnownFieldType.Field: BaseDataFieldModel field1 = field; formula.Data = attributes.Where( attr => attr.Name.LocalName.ToUpperInvariant() .Equals( BaseDataFieldModel.GetFieldNameFrom(field1).ToUpperInvariant())) .Select(n => n.Value); break; #endregion #region Field: Fixed case KnownFieldType.Fixed: var fixedFieldModel = (FixedFieldModel)field; var piecesModel = fix[fixedFieldModel.Pieces]; BaseDataFieldModel field2 = field; var dataList = rows.Select(row => piecesModel.DataSource = row) .Select(entries => piecesModel.ToDictionary()) .Select(entry => entry[BaseDataFieldModel.GetFieldNameFrom(field2)]); formula.Data = dataList; break; #endregion #region Field: Gap case KnownFieldType.Gap: var datalist = new List <string>(); for (var i = 0; i <= rowsCount - 1; i++) { datalist.Add(" "); } formula.Data = datalist; break; #endregion #region Field: Group case KnownFieldType.Group: var groupFieldModel = (GroupFieldModel)field; var groupDataList = new List <string>(); foreach (var row in rows) { groupFieldModel.DataSource = row; var group = groupFieldModel.Value.GetValue(specialChars); groupDataList.Add(@group.FormattedValue); } formula.Data = groupDataList; break; #endregion } table.AddCell(PdfHelper.CreateCell(style.Content.DataType.GetFormattedDataValue(formula.Resolve()))); } else { var emptyStyle = StyleModel.Empty; emptyStyle.Content = style.Content; emptyStyle.Content.DataType = new TextDataTypeModel(); ////emptyStyle.SetOwner(model.Styles); table.AddCell(PdfHelper.CreateCell(style.Content.DataType.GetFormattedDataValue(string.Empty))); } } return(table); }