Пример #1
0
        public void Merge(FinanceReportTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            if (!table._rows.Select(r => r.Name).SequenceEqual(_rows.Select(r => r.Name)))
            {
                throw new InvalidOperationException("table's rows are inconsistent");
            }

            if (!table._columnDefinitions.SequenceEqual(_columnDefinitions, new ColumnDefinitionEqualityComparer()))
            {
                throw new InvalidOperationException("table's columns are inconsistent");
            }

            for (int i = 0; i < _rows.Count; ++i)
            {
                for (int j = 0; j < _columnDefinitions.Length; ++j)
                {
                    _rows[i][j].Merge(table._rows[i][j]);
                }
            }
        }
Пример #2
0
        public FinanceReportTable Expand(IList <string> orderedRowNames, IList <string> orderedColumnText, IList <DateTime> orderedColumnDate)
        {
            var columnDefinitions = new FinanceReportColumnDefinition[orderedColumnDate.Count + orderedColumnText.Count];

            for (int i = 0; i < orderedColumnDate.Count; ++i)
            {
                columnDefinitions[i] = new FinanceReportColumnDefinition(orderedColumnDate[i]);
            }

            for (int i = 0; i < orderedColumnText.Count; ++i)
            {
                columnDefinitions[i + orderedColumnDate.Count] = new FinanceReportColumnDefinition(orderedColumnText[i]);
            }

            FinanceReportTable table = new FinanceReportTable(Name, RowDefinition, Unit, columnDefinitions);

            table._rows = new List <FinanceReportRow>();

            for (int i = 0; i < orderedRowNames.Count; ++i)
            {
                table._rows.Add(new FinanceReportRow(orderedRowNames[i], table._columnDefinitions, table.Unit));
            }

            // build old row index to new row index map and old column index to new column index
            int[] rowMap = new int[_rows.Count];
            for (int i = 0; i < _rows.Count; ++i)
            {
                rowMap[i] = orderedRowNames.IndexOf(_rows[i].Name);
            }

            int[] columnMap = new int[_columnDefinitions.Length];
            for (int i = 0; i < _columnDefinitions.Length; ++i)
            {
                if (_columnDefinitions[i].Type == FinanceReportColumnDefinition.ColumnType.Date)
                {
                    columnMap[i] = orderedColumnDate.IndexOf(_columnDefinitions[i].Date);
                }
                else
                {
                    columnMap[i] = orderedColumnText.IndexOf(_columnDefinitions[i].Text);
                    if (columnMap[i] >= 0)
                    {
                        columnMap[i] += orderedColumnDate.Count;
                    }
                }
            }

            // copy data from old table to new table
            for (int i = 0; i < _rows.Count; ++i)
            {
                for (int j = 0; j < _columnDefinitions.Length; ++j)
                {
                    table._rows[rowMap[i]][columnMap[j]].Copy(_rows[i][j]);
                }
            }

            return(table);
        }
Пример #3
0
        public void AddTable(FinanceReportTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            _tables.Add(table);
        }