예제 #1
0
        /// <summary>
        /// Generates the totals for a collection of query rows
        /// </summary>
        /// <param name="tableDefinition">The table definition</param>
        /// <param name="filter">The report filter</param>
        /// <param name="rows">The query rows</param>
        /// <returns>The totals as table cells</returns>
        private IEnumerable <TableCell> GenerateTotals
        (
            TableDefinition tableDefinition,
            ReportFilter filter,
            IEnumerable <QueryRow> rows
        )
        {
            var cells = new List <TableCell>();

            var columnDefinitions = GetColumnsDynamically
                                    (
                tableDefinition,
                filter
                                    );

            foreach (var columnDefinition in columnDefinitions)
            {
                var cell = default(TableCell);

                if (columnDefinition.HasTotal)
                {
                    var total = default(double);

                    if (columnDefinition.IsDynamic)
                    {
                        var cellValues = _columnValueCache[columnDefinition.Name];
                        var numbers    = new List <double>();

                        // Convert the cell values into their double equivalent
                        foreach (var value in cellValues)
                        {
                            if (value == null)
                            {
                                numbers.Add(0);
                            }
                            else
                            {
                                Double.TryParse
                                (
                                    value.ToString(),
                                    out double number
                                );

                                numbers.Add(number);
                            }
                        }

                        total = columnDefinition.TotalAggregator.Execute
                                (
                            numbers.ToArray()
                                );
                    }
                    else
                    {
                        total = columnDefinition.TotalAggregator.Execute
                                (
                            rows.ToArray()
                                );
                    }

                    var format = columnDefinition.TotalFormat;

                    if (format == null)
                    {
                        cell = CreateTableCell
                               (
                            columnDefinition,
                            total
                               );
                    }
                    else
                    {
                        var formattedTotal = String.Format
                                             (
                            format,
                            total
                                             );

                        cell = CreateTableCell
                               (
                            columnDefinition,
                            formattedTotal
                               );
                    }
                }
                else
                {
                    cell = CreateTableCell
                           (
                        columnDefinition,
                        null
                           );
                }

                cells.Add(cell);
            }

            return(cells);
        }
예제 #2
0
        /// <summary>
        /// Builds a collection of table rows from a collection of query rows
        /// </summary>
        /// <param name="tableDefinition">The table definition</param>
        /// <param name="sectionType">The report section type</param>
        /// <param name="filter">The report filter</param>
        /// <param name="queryRows">The query rows</param>
        /// <returns>A collection of table rows</returns>
        private IEnumerable <TableRow> BuildTableRows
        (
            TableDefinition tableDefinition,
            ReportSectionType sectionType,
            ReportFilter filter,
            IEnumerable <QueryRow> queryRows
        )
        {
            var tableRows        = new List <TableRow>();
            var actionDefinition = tableDefinition.RowAction;

            var columnDefinitions = GetColumnsDynamically
                                    (
                tableDefinition,
                filter
                                    );

            foreach (var queryRow in queryRows)
            {
                var tableCells = new List <TableCell>();

                foreach (var columnDefinition in columnDefinitions)
                {
                    var value = ResolveColumnValue
                                (
                        columnDefinition,
                        queryRow
                                );

                    var action = default(ReportAction);

                    if (columnDefinition.CellAction != null)
                    {
                        action = columnDefinition.CellAction.Resolve
                                 (
                            queryRow
                                 );
                    }

                    var cell = CreateTableCell
                               (
                        columnDefinition,
                        value,
                        action
                               );

                    tableCells.Add(cell);
                }

                var importance = DataImportance.Default;

                if (tableDefinition.RowImportanceRules.Any())
                {
                    foreach (var rule in tableDefinition.RowImportanceRules)
                    {
                        var columnName     = rule.ColumnName;
                        var candidateValue = queryRow[columnName].Value;

                        if (rule.Matches(candidateValue))
                        {
                            importance = rule.ImportanceOnMatch;
                        }
                    }
                }

                var tableRow = new TableRow
                               (
                    importance,
                    tableCells.ToArray()
                               );

                if (tableDefinition.RowAction != null)
                {
                    var action = actionDefinition.Resolve
                                 (
                        queryRow
                                 );

                    tableRow = tableRow.WithAction
                               (
                        action
                               );
                }

                tableRows.Add(tableRow);
            }

            if (false == tableDefinition.DisableSorting)
            {
                var sortingRules = filter.GetSortingRules
                                   (
                    sectionType,
                    tableDefinition.Name
                                   );

                tableRows = SortRows(tableRows, sortingRules).ToList();
            }

            return(tableRows);
        }