コード例 #1
0
        public ExcelTableReport(string reportName, IEnumerable <Doc> docs, BizTableReport reportData)
        {
            _report         = new ExcelReport(reportName, "Empty", "Отчет");
            _enumRepository = new EnumRepository();

            CreateReport(reportName, docs, reportData);
        }
コード例 #2
0
        public void TableReportTestWithAgregate()
        {
            using (var dataContext = new DataContext())
            {
                var            repo        = new ReportRepository(dataContext);
                var            reportId    = Guid.Parse("{771E695E-2379-4E61-8F9E-F2E28E2D8933}");
                BizTableReport tableReport = repo.GetReport(reportId);

                var         docDefId  = Guid.Parse("{846B1B55-F110-452F-B08F-8CEB0A112BE0}");
                var         docRepo   = new DocRepository(dataContext, _userId);
                int         pageCount = 0;
                List <Guid> docIds    = docRepo.List(out pageCount, docDefId, 1, 0);

                List <Doc> docs = docIds.Select(id => docRepo.LoadById(id)).ToList();

                var report = new ExcelTableReport("Отчет с агрегатами", docs, tableReport);

                report.SaveToExcelFile(@"c:\TableReportAggregates.xls");
            }
        }
コード例 #3
0
        public void TableReportTest3()
        {
            using (var dataContext = new DataContext())
            {
                var            repo        = new ReportRepository(dataContext);
                var            reportId    = Guid.Parse("{DFBE1017-A975-4A46-9FB3-970B4DC1C67E}");
                BizTableReport tableReport = repo.GetReport(reportId);

                var         docDefId  = Guid.Parse("{50E90782-110C-4AA0-B4CE-7CB233766F99}");
                var         docRepo   = new DocRepository(dataContext, _userId);
                int         pageCount = 0;
                List <Guid> docIds    = docRepo.List(out pageCount, docDefId, 1, 0);

                List <Doc> docs = docIds.Select(id => docRepo.LoadById(id)).ToList();

                var report = new ExcelTableReport("Тестовое название отчета", docs, tableReport);

                report.SaveToExcelFile(@"c:\TableReportTest3.xls");
            }
        }
コード例 #4
0
        public void TableReportTest()
        {
            using (var dataContext = new DataContext())
            {
                var            repo        = new ReportRepository(dataContext);
                var            reportId    = Guid.Parse("295690be-7d94-43f4-bfc8-37b2fcc936c5");
                BizTableReport tableReport = repo.GetReport(reportId);

                var         docDefId  = Guid.Parse("{4455B9CB-2564-4A92-A295-E3C0BEDB7AC2}");
                var         docRepo   = new DocRepository(dataContext, _userId);
                int         pageCount = 0;
                List <Guid> docIds    = docRepo.List(out pageCount, docDefId, 1, 0);

                List <Doc> docs = docIds.Select(id => docRepo.LoadById(id)).ToList();

                var report = new ExcelTableReport("Тестовое название отчета", docs, tableReport);

                report.SaveToExcelFile(@"c:\TableReportTest.xls");
            }
        }
コード例 #5
0
        private void CreateReport(string reportName, IEnumerable <Doc> docs, BizTableReport reportData)
        {
            // adding page header
            var pageHeaderString = reportData.PageHeaders.Aggregate("", (current, pageHeader) => current + pageHeader + "\n");

            _report.AddPageHeader(pageHeaderString, Position.Centre);

            // adding page footer
            var pageFooterString = reportData.PageFooters.Aggregate("", (current, pageFooter) => current + pageFooter + "\n");

            _report.AddPageFooter(pageFooterString, Position.Centre);

            // adding empty rows for logo
            _report.AddEmptyRows(6);

            // report header
            foreach (string reportHeader in reportData.ReportHeaders)
            {
                var headerRow = _report.GetNextRow();
                _report.AddCell(reportHeader, 0, headerRow, TextStyle.Header2);
            }

            // Report table
            Row row = _report.GetNextRow();

            _report.AddCell(reportName, 0, row, TextStyle.Header1);
            _report.SetRowHeight(row, 22);

            if (reportData.ReportDetails != null)
            {
                foreach (BizReportDetail repDetail in reportData.ReportDetails)
                {
                    int rowShift = _report.CurrentRowIndex + 2;
                    for (int rowIndex = 0; rowIndex < repDetail.ChildrenCountLevels; rowIndex++)
                    {
                        for (int columnIndex = 0; columnIndex < repDetail.LeafCount; columnIndex++)
                        {
                            _report.AddCell("", columnIndex, rowShift + rowIndex, TextStyle.TableHeaderGreyCenterdBorder);
                        }
                    }
                    WriteReportDetail(repDetail, rowShift - 1, repDetail.ChildrenCountLevels, 0);

                    foreach (Doc doc in docs)
                    {
                        Row tableRow = _report.GetNextRow();

                        int colIndex = 0;
                        foreach (ReportColumn col in GetColumns(repDetail))
                        {
                            Guid attrId = col.AttributeId;
                            IEnumerable <AttributeBase> findAttrQuery = from a in doc.Attributes
                                                                        where a.AttrDef.Id == attrId
                                                                        select a;
                            if (findAttrQuery.Any())
                            {
                                AttributeBase findedAttr = findAttrQuery.First();
                                if (findedAttr is EnumAttribute)
                                {
                                    var enumAttribute = findedAttr as EnumAttribute;
                                    if (enumAttribute.Value.HasValue)
                                    {
                                        string enumValue =
                                            _enumRepository.GetEnumValue(enumAttribute.AttrDef.EnumDefType.Id,
                                                                         enumAttribute.Value.Value);
                                        _report.AddCell(enumValue, colIndex, tableRow, TextStyle.TableRowNormal);
                                    }
                                }
                                else
                                {
                                    _report.AddCell(findedAttr.ObjectValue, colIndex, tableRow, TextStyle.TableRowNormal);
                                }
                            }
                            else
                            {
                                _report.AddCell("", colIndex, tableRow, TextStyle.TableRowNormal);
                            }
                            colIndex++;
                        }
                    }

                    Row aggregatesRow = _report.GetNextRow();
                    int aggrColIndex  = 0;
                    foreach (ReportColumn col in GetColumns(repDetail))
                    {
                        /*  atr.AttrDef.Type.Id
                         *  1	Int
                         *  2	Currency
                         *  3	Text
                         *  4	Float
                         *  5	Enum
                         *  6	Doc
                         *  7	DocList
                         *  8	Bool
                         *  9	DateTime
                         */
                        Guid attrId = col.AttributeId;
                        IEnumerable <AttributeBase> attrQuery = from atr in docs.SelectMany(d => d.Attributes)
                                                                where atr.AttrDef.Id == attrId
                                                                select atr;

                        object aggregateValue;
                        switch (col.AggregateOperation)
                        {
                        case AggregateOperation.Count:
                            aggregateValue = attrQuery.Count();
                            break;

                        case AggregateOperation.Avg:
                            var q1 = attrQuery.Where(atr => (new[] { 1, 2, 4 }).Contains(atr.AttrDef.Type.Id));
                            aggregateValue = q1.Any() ? q1.Average(a => double.Parse((a.ObjectValue ?? 0).ToString())) : 0;
                            break;

                        case AggregateOperation.Sum:
                            var q2 = attrQuery.Where(atr => (new[] { 1, 2, 4 }).Contains(atr.AttrDef.Type.Id));
                            aggregateValue = q2.Any() ? q2.Sum(a => double.Parse((a.ObjectValue ?? 0).ToString())) : 0;
                            break;

                        case AggregateOperation.Max:
                            aggregateValue =
                                attrQuery.Where(atr => (new[] { 1, 2, 4, 9 }).Contains(atr.AttrDef.Type.Id)).Max(
                                    a => a.ObjectValue);
                            break;

                        case AggregateOperation.Min:
                            aggregateValue =
                                attrQuery.Where(atr => (new[] { 1, 2, 4, 9 }).Contains(atr.AttrDef.Type.Id)).Min(
                                    a => a.ObjectValue);
                            break;

                        default:
                            aggregateValue = "";
                            break;
                        }

                        _report.AddCell(aggrColIndex == 0 ? "Итог" : aggregateValue,
                                        aggrColIndex, aggregatesRow, TextStyle.TableTotal);

                        aggrColIndex++;
                    }
                }
            }

            _report.AddEmptyRow();
            // report footer
            foreach (string reportFooter in reportData.ReportFooters)
            {
                var headerRow = _report.GetNextRow();
                _report.AddCell(reportFooter, 0, headerRow, TextStyle.Header2);
            }

            // report logo
            // adding logo after all other operations, because it can be resized.
            _report.AddLogo(0, 0);
        }