예제 #1
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);
        }
예제 #2
0
        public FinanceReportTable(string name, string rowDefinition, string[] columnDefinitions)
        {
            if (columnDefinitions == null || columnDefinitions.Length == 0)
            {
                throw new ArgumentNullException("columnDefinitions");
            }

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

            Name = name;

            string  cleanedRowDefinition;
            decimal unit;

            FinanceReportHelper.ParseDefinitionAndUnit(rowDefinition, 1.0M, out cleanedRowDefinition, out unit);

            Unit          = unit;
            RowDefinition = cleanedRowDefinition;
        }