public void Test1()
        {
            var dc = new DataContext();

            dc.AddTable("data", new[] {
                new Item {
                    Col1 = "A", Col2 = 2
                }
            });

            var flow = new Flow {
                Orientation = FlowOrientation.Vertical
            };

            flow.AddTable <Item>("data");

            var          rep = Report.CreateReport(flow, dc);
            StringWriter sw  = new StringWriter();

            TextReportWriter.WriteTo(rep, sw);

            var lines = sw.ToString().Split('\n').Select(a => a.TrimEnd('\r')).ToArray();

            Assert.AreEqual(lines[1], "=========");
            Assert.AreEqual(lines[2], "Col1 Col2");
            Assert.AreEqual(lines[3], "---- ----");
            Assert.AreEqual(lines[4], "A       2");
            Assert.AreEqual(lines[5], "---------");
        }
Beispiel #2
0
        public static String RenderTextReport(Report rep)
        {
            StringWriter sw = new StringWriter();

            TextReportWriter.WriteTo(rep, sw);
            return(sw.ToString());
        }
Beispiel #3
0
        void RenderReport(HttpContext context)
        {
            var type = context.Request.QueryString["type"];

            Report report;

            switch (type)
            {
            case "GdpByYear":
                report = Reports.GdpByYearReport.Generate();
                break;

            case "GdpByCountry":
                report = Reports.GdpByCountryReport.Generate();
                break;

            case "BiggestCountries":
                report = Reports.GdpYearColumnReport.BiggestCountries();
                break;

            case "FastestGrowingCountries":
                report = Reports.GdpYearColumnReport.FastestGrowingCountries();
                break;

            case "BestCountries":
                report = Reports.GdpYearColumnReport.BestCountries();
                break;

            default:
                throw new InvalidOperationException("Invalid report type.");
            }


            try
            {
                switch (context.Request.QueryString["format"])
                {
                case "pdf":
                    var url = context.Request.Url.ToString().Replace("format=pdf", "print=1");
                    PdfConvert.ConvertHtmlToPdf(new PdfDocument {
                        Url = url
                    }, new PdfOutput {
                        OutputStream = context.Response.OutputStream
                    });
                    context.Response.SetFileDownloadHeaders(String.Format("Report{0}.pdf", DateTime.Now.Ticks));
                    break;

                case "text":
                    context.Response.SetFileDownloadHeaders(String.Format("Report{0}.txt", DateTime.Now.Ticks));
                    TextReportWriter.WriteTo(report, context.Response.Output);
                    break;

                case "xlsx":
                    context.Response.SetFileDownloadHeaders(String.Format("Report{0}.xlsx", DateTime.Now.Ticks));
                    XlsxReportWriter.WriteToStream(report, Themes.Default, context.Response.OutputStream);
                    break;

                default:
                    var output     = new HtmlTextWriter(context.Response.Output);
                    var htmlWriter = new HtmlReportWriter(output);
                    htmlWriter.RegisterCss(DextopUtil.AbsolutePath("client/css/report.css"));
                    if (context.Request.QueryString["print"] == null)
                    {
                        htmlWriter.RegisterCss(DextopUtil.AbsolutePath("client/css/report-preview.css"));
                    }
                    htmlWriter.Write(report, new DefaultHtmlReportTheme());
                    break;
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.ToString());
            }
        }