Пример #1
0
        private void GenerateGroup(IReportWriter writer, Dictionary <Category, CashFlowColumns> columns, CashFlowColumns columnTotals, string groupName, Func <Category, bool> inGroup)
        {
            List <Category> rootCategories = new List <Category>(columns.Keys);

            rootCategories.Sort(new Comparison <Category>((a, b) =>
            {
                return(string.Compare(GetCategoryCaption(a), GetCategoryCaption(b)));
            }));

            // start the group
            writer.StartExpandableRowGroup();

            CashFlowColumns groupTotals = new CashFlowColumns();

            // compute group totals;
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    foreach (string columnName in this.columns)
                    {
                        CashFlowColumns cc     = columns[c];
                        decimal         amount = cc.GetValue(columnName);
                        columnTotals.AddValue(columnName, null, amount);
                        groupTotals.AddValue(columnName, null, amount);
                    }
                }
            }

            WriteRow(writer, true, false, groupName, FormatValues(groupTotals.GetOrderedValues(this.columns)).ToArray());

            // now add the detail rows of the group
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    List <CashFlowCell> cells = new List <CashFlowCell>();
                    CashFlowColumns     cc    = columns[c];

                    foreach (string columnName in this.columns)
                    {
                        CashFlowCell cell = cc.GetCell(columnName);
                        cells.Add(cell);
                    }

                    WriteRow(writer, false, false, GetCategoryCaption(c), cells);
                }
            }

            writer.EndExpandableRowGroup();
        }
Пример #2
0
        private void GenerateCsvGroup(StreamWriter writer, Dictionary <Category, CashFlowColumns> byCategory, string groupTitle, Func <Category, bool> inGroup, Func <decimal, decimal> scaleFunc)
        {
            writer.Write(groupTitle);
            foreach (string columnName in this.columns)
            {
                writer.Write(",");
                writer.Write(columnName);
            }
            writer.WriteLine();

            List <Category> rootCategories = new List <Category>(byCategory.Keys);

            rootCategories.Sort(new Comparison <Category>((a, b) =>
            {
                return(string.Compare(GetCategoryCaption(a), GetCategoryCaption(b)));
            }));

            // now add the detail rows of the group
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    List <CashFlowCell> cells = new List <CashFlowCell>();
                    CashFlowColumns     cc    = byCategory[c];

                    foreach (string columnName in this.columns)
                    {
                        CashFlowCell cell = cc.GetCell(columnName);
                        cells.Add(cell);
                    }

                    writer.Write(GetCategoryCaption(c));

                    foreach (CashFlowCell cell in cells)
                    {
                        writer.Write(",");
                        writer.Write(scaleFunc(cell.Value));
                    }
                    writer.WriteLine();
                }
            }
            writer.WriteLine();
        }