-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.cs
78 lines (65 loc) · 2.62 KB
/
HomeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using DevExpress.DataAccess.Sql;
using DevExpress.Drawing;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DocumentViewerApp.PredefinedReports;
using DocumentViewerApp.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace DocumentViewerApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Error()
{
Models.ErrorModel model = new Models.ErrorModel();
return View(model);
}
public async Task<IActionResult> Designer(
[FromServices] IReportDesignerModelBuilder reportDesignerModelBuilder,
[FromQuery] string reportName)
{
// Create a SQL data source with the specified connection string.
SqlDataSource ds = new SqlDataSource("NWindConnectionString");
// Create a SQL query to access the Products data table.
SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products");
ds.Queries.Add(query);
ds.RebuildResultSchema();
reportName = string.IsNullOrEmpty(reportName) ? "TestReport" : reportName;
var designerModel = await reportDesignerModelBuilder
.Report(reportName)
.DataSources(x =>
{
x.Add("Northwind", ds);
})
.BuildModelAsync();
return View(designerModel);
}
public async Task< IActionResult> Viewer(
[FromServices] IWebDocumentViewerClientSideModelGenerator viewerModelGenerator,
[FromQuery] string reportName)
{
reportName = string.IsNullOrEmpty(reportName) ? "TestReport" : reportName;
var viewerModel = await viewerModelGenerator.GetModelAsync(reportName, CustomWebDocumentViewerController.DefaultUri);
return View(viewerModel);
}
public async Task<ActionResult> CollectAndLoadFonts([FromServices] FontCollectorService fontCollectorService)
{
using var report = new TestReport();
await fontCollectorService.ProcessReport(report);
using var stream = new MemoryStream();
await report.ExportToPdfAsync(stream);
return File(stream.ToArray(), "application/pdf", "Report.pdf");
}
}
}