8 | DoddleReport - turn any IEnumerable set of data into pluggable reports!
9 |
10 |
11 |
12 | Usage
13 |
14 | public ReportResult ProductReport()
15 | {
16 | // Get the data for the report (any IEnumerable will work)
17 | var query = ProductRepository.GetAll();
18 | var totalProducts = query.Count;
19 | var totalOrders = query.Sum(p => p.OrderCount);
20 |
21 |
22 | // Create the report and turn our query into a ReportSource
23 | var report = new Report(query.ToReportSource());
24 |
25 |
26 | // Customize the Text Fields
27 | report.TextFields.Title = "Products Report";
28 | report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
29 | report.TextFields.Footer = "Copyright 2011 © The Doddle Project";
30 | report.TextFields.Header = string.Format(@"
31 | Report Generated: {0}
32 | Total Products: {1}
33 | Total Orders: {2}
34 | Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);
35 |
36 |
37 | // Render hints allow you to pass additional hints to the reports as they are being rendered
38 | report.RenderHints.BooleanCheckboxes = true;
39 |
40 |
41 | // Customize the data fields
42 | report.DataFields["Id"].Hidden = true;
43 | report.DataFields["Price"].DataFormatString = "{0:c}";
44 | report.DataFields["LastPurchase"].DataFormatString = "{0:d}";
45 |
46 |
47 |
48 | // Return the ReportResult
49 | // the type of report that is rendered will be determined by the extension in the URL (.pdf, .xls, .html, etc)
50 | return new ReportResult(report);
51 | }
52 |
53 |
54 | Samples!
55 |
56 |
57 |
58 |
59 | Excel Report - using OpenXML
60 | <%: Html.ActionLink("See it Live!", "ProductReport", "Doddle", new { extension = "xlsx"}, null) %>
61 |
62 | |
63 |
64 |
65 | PDF Report - using iTextSharp - headers repeat on every page
66 | <%: Html.ActionLink("See Live!", "ProductReport", "Doddle", new { extension = "pdf" }, null)%>
67 | |
68 |
69 |
70 |
71 | ">
72 | " width="500" alt="Excel Report" />
73 |
74 | |
75 |
76 |
77 | ">
78 | " width="500" alt="PDF Report" />
79 |
80 | |
81 |
82 |
83 |
84 | HTML Report
85 | <%: Html.ActionLink("See Live!", "ProductReport", "Doddle", new { extension = "html" }, null)%>
86 | |
87 |
88 | CSV/Delimited Output
89 | <%: Html.ActionLink("See Live!", "ProductReport", "Doddle", new { extension = "txt" }, null)%>
90 | |
91 |
92 |
93 |
94 | ">
95 | " width="500" alt="HTML Report" />
96 |
97 | |
98 |
99 |
100 | ">
101 | " width="500" alt="CSV Report" />
102 |
103 | |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/src/DoddleReport.Sample.Web/Views/Shared/Error.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage