|
1 |
| -using System.Collections.Generic; |
2 |
| -using System.ComponentModel.Design; |
3 |
| -using System.IO; |
4 |
| -using System.Threading.Tasks; |
5 |
| -using DevExpress.AspNetCore.Reporting.QueryBuilder; |
6 |
| -using DevExpress.AspNetCore.Reporting.ReportDesigner; |
7 |
| -using DevExpress.AspNetCore.Reporting.WebDocumentViewer; |
8 |
| -using DevExpress.DataAccess.Sql; |
9 |
| -using DevExpress.XtraReports.Services; |
10 |
| -using DevExpress.XtraReports.Web.ReportDesigner; |
11 |
| -using DevExpress.XtraReports.Web.WebDocumentViewer; |
12 |
| -using Microsoft.AspNetCore.Mvc; |
13 |
| - |
14 |
| -namespace ReportingAppAsyncServices.Controllers |
15 |
| -{ |
16 |
| - public class HomeController : Controller |
17 |
| - { |
18 |
| - public IActionResult Index() |
19 |
| - { |
20 |
| - return View(); |
21 |
| - } |
22 |
| - |
23 |
| - public async Task<IActionResult> Designer([FromQuery] string reportName = "RootReport") |
24 |
| - { |
25 |
| - var dataSources = new Dictionary<string, object> |
26 |
| - { |
27 |
| - ["Northwind"] = GetNorthwindSqlDataSource() |
28 |
| - }; |
29 |
| - var modelGenerator = new ReportDesignerClientSideModelGenerator(HttpContext.RequestServices); |
30 |
| - var model = await modelGenerator.GetModelAsync(reportName, dataSources, ReportDesignerController.DefaultUri, WebDocumentViewerController.DefaultUri, QueryBuilderController.DefaultUri); |
31 |
| - return View(model); |
32 |
| - } |
33 |
| - |
34 |
| - public async Task<IActionResult> Viewer([FromQuery] string reportName = "RootReport") |
35 |
| - { |
36 |
| - var modelGenerator = new WebDocumentViewerClientSideModelGenerator(HttpContext.RequestServices); |
37 |
| - var model = await modelGenerator.GetModelAsync(reportName, WebDocumentViewerController.DefaultUri); |
38 |
| - return View(model); |
39 |
| - } |
40 |
| - public async Task<IActionResult> ExportToPdf([FromServices] IReportProviderAsync reportProviderAsync, [FromQuery] string reportName = "RootReport") |
41 |
| - { |
42 |
| - var report = await reportProviderAsync.GetReportAsync(reportName, null); |
43 |
| - var reportServiceContainer = (IServiceContainer)report; |
44 |
| - reportServiceContainer.RemoveService(typeof(IReportProviderAsync)); |
45 |
| - reportServiceContainer.AddService(typeof(IReportProviderAsync), reportProviderAsync); |
46 |
| - using (var stream = new MemoryStream()) { |
47 |
| - await report.CreateDocumentAsync(); |
48 |
| - await report.ExportToPdfAsync(stream); |
49 |
| - return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf); |
50 |
| - } |
51 |
| - } |
52 |
| - |
53 |
| - |
54 |
| - SqlDataSource GetNorthwindSqlDataSource() |
55 |
| - { |
56 |
| - // Create a SQL data source with the specified connection string. |
57 |
| - SqlDataSource ds = new SqlDataSource("NWindConnectionString"); |
58 |
| - // Create a SQL query to access the Products data table. |
59 |
| - SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products"); |
60 |
| - ds.Queries.Add(query); |
61 |
| - ds.RebuildResultSchema(); |
62 |
| - return ds; |
63 |
| - } |
64 |
| - } |
65 |
| -} |
| 1 | +using System.Collections.Generic; |
| 2 | +using System.ComponentModel.Design; |
| 3 | +using System.IO; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using DevExpress.AspNetCore.Reporting.QueryBuilder; |
| 6 | +using DevExpress.AspNetCore.Reporting.ReportDesigner; |
| 7 | +using DevExpress.AspNetCore.Reporting.WebDocumentViewer; |
| 8 | +using DevExpress.DataAccess.Sql; |
| 9 | +using DevExpress.XtraReports.Services; |
| 10 | +using DevExpress.XtraReports.Web.ReportDesigner; |
| 11 | +using DevExpress.XtraReports.Web.WebDocumentViewer; |
| 12 | +using Microsoft.AspNetCore.Mvc; |
| 13 | + |
| 14 | +namespace ReportingAppAsyncServices.Controllers |
| 15 | +{ |
| 16 | + public class HomeController : Controller |
| 17 | + { |
| 18 | + public IActionResult Index() |
| 19 | + { |
| 20 | + return View(); |
| 21 | + } |
| 22 | + |
| 23 | + public async Task<IActionResult> Designer([FromQuery] string reportName = "RootReport") |
| 24 | + { |
| 25 | + var dataSources = new Dictionary<string, object> |
| 26 | + { |
| 27 | + ["Northwind"] = GetNorthwindSqlDataSource() |
| 28 | + }; |
| 29 | + var modelGenerator = new ReportDesignerClientSideModelGenerator(HttpContext.RequestServices); |
| 30 | + var model = await modelGenerator.GetModelAsync(reportName, dataSources, ReportDesignerController.DefaultUri, WebDocumentViewerController.DefaultUri, QueryBuilderController.DefaultUri); |
| 31 | + return View(model); |
| 32 | + } |
| 33 | + |
| 34 | + public async Task<IActionResult> Viewer([FromQuery] string reportName = "RootReport") |
| 35 | + { |
| 36 | + var modelGenerator = new WebDocumentViewerClientSideModelGenerator(HttpContext.RequestServices); |
| 37 | + var model = await modelGenerator.GetModelAsync(reportName, WebDocumentViewerController.DefaultUri); |
| 38 | + return View(model); |
| 39 | + } |
| 40 | + public async Task<IActionResult> ExportToPdf([FromServices] IReportProviderAsync reportProviderAsync, [FromQuery] string reportName = "RootReport") |
| 41 | + { |
| 42 | + var report = await reportProviderAsync.GetReportAsync(reportName, null); |
| 43 | + var reportServiceContainer = (IServiceContainer)report; |
| 44 | + reportServiceContainer.RemoveService(typeof(IReportProviderAsync)); |
| 45 | + reportServiceContainer.AddService(typeof(IReportProviderAsync), reportProviderAsync); |
| 46 | + using (var stream = new MemoryStream()) { |
| 47 | + await report.CreateDocumentAsync(); |
| 48 | + await report.ExportToPdfAsync(stream); |
| 49 | + return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + SqlDataSource GetNorthwindSqlDataSource() |
| 55 | + { |
| 56 | + // Create a SQL data source with the specified connection string. |
| 57 | + SqlDataSource ds = new SqlDataSource("NWindConnectionString"); |
| 58 | + // Create a SQL query to access the Products data table. |
| 59 | + SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products"); |
| 60 | + ds.Queries.Add(query); |
| 61 | + ds.RebuildResultSchema(); |
| 62 | + return ds; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments