Skip to content

Commit e099c06

Browse files
authored
Update example vite (#1)
1 parent 706102e commit e099c06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2320
-2338
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ BenchmarkDotNet.Artifacts/
4848
project.lock.json
4949
project.fragment.lock.json
5050
artifacts/
51-
**/Properties/launchSettings.json
5251

5352
*_i.c
5453
*_p.c

Images/screenshot.png

14.5 KB
Loading

Readme.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/274919030/24.2.1%2B)
32
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T902911)
43
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
54
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
@@ -10,30 +9,52 @@ This example prints and exports a report in a browser without previewing it on a
109

1110
![Screenshot](Images/screenshot.png)
1211

13-
## Print
12+
## Run the Project
13+
14+
Run the following command from the *ServerApp* folder:
15+
16+
```cmd
17+
dotnet run
18+
```
19+
20+
Run the following commands from the *react-app* folder:
21+
22+
```cmd
23+
npm install
24+
mpm run dev
25+
```
26+
27+
Open your browser and navigate to the URL specified in the command output to see the result.
28+
29+
## Implementation Details
30+
31+
### Export Operations
32+
33+
The user selects the format from the drop-down list and clicks the **Export the report** button to send the format to the server-side controller. The controller calls the export method for the selected format and sends the file back to the browser.
34+
35+
### Print Operations
1436

1537
On the **server side**, a controller performs the following actions:
16-
- [creates a report](https://docs.devexpress.com/XtraReports/2440/get-started-with-devexpress-reporting/create-a-report-from-a-to-z);
17-
- [exports the report to PDF](https://docs.devexpress.com/XtraReports/2574/detailed-guide-to-devexpress-reporting/store-and-distribute-reports/export-reports/export-to-pdf) with the [XtraReport.ExportToPdfAsync](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToPdfAsync.overloads) method;
18-
- sends the PDF file back to the client.
38+
- [Creates a report](https://docs.devexpress.com/XtraReports/2440/get-started-with-devexpress-reporting/create-a-report-from-a-to-z).
39+
- [Exports the report to PDF](https://docs.devexpress.com/XtraReports/2574/detailed-guide-to-devexpress-reporting/store-and-distribute-reports/export-reports/export-to-pdf) with the [XtraReport.ExportToPdfAsync](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToPdfAsync.overloads) method.
40+
- Sends the PDF file back to the client.
41+
42+
On the **client side**, a user can do one of the following:
1943

20-
On the **client-side**, a user can do one of the following:
2144

2245
* Print a report in a new tab.
23-
Click a button to call the client-side `window.Open(url, "_blank")` method to open a new window that contains a PDF file and print the window content.
2446

25-
* Print a report in iFrame.
26-
Click a button to load a PDF file in the `HTMLIFrameElement` and print its content.
47+
Click the **Print the report in a new tab** button to call the client-side `window.Open(url, "_blank")` method to open a new window that contains a PDF file and print the window content.
2748

49+
* Print a report in iFrame.
2850

29-
## Export
51+
Click the **Print via iFrame** button to load a PDF file in the `HTMLIFrameElement` and print its content.
3052

31-
The user selects the format and clicks a button to send the format to the server-side controller. The controller calls the export method for the selected format and sends the file back to the browser.
3253

3354
## Files to Review
3455

35-
- [HomeComponent.jsx](dxSampleReactReportingPrintWithoutPreview/ClientApp/src/components/HomeComponent.jsx)
36-
- [HomeController.cs](dxSampleReactReportingPrintWithoutPreview/Controllers/HomeController.cs)
56+
- [HomeComponent.jsx](react-app/src/components/HomeComponent.jsx)
57+
- [HomeController.cs](ServerApp/Controllers/HomeController.cs)
3758

3859
## Documentation
3960

@@ -46,9 +67,9 @@ The user selects the format and clicks a button to send the format to the server
4667
- [Reporting for Web (React) - Document Viewer](https://github.com/DevExpress-Examples/reporting-document-viewer-in-javascript-with-react)
4768
- [How to Print and Export a Report in the ASP.NET Core Application without the Document Viewer](https://github.com/DevExpress-Examples/Reporting-AspNetCore-Print-Without-Preview)
4869
<!-- feedback -->
49-
## Does this example address your development requirements/objectives?
50-
51-
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=no)
52-
70+
## Does this example address your development requirements/objectives?
71+
72+
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=no)
73+
5374
(you will be redirected to DevExpress.com to submit your response)
5475
<!-- feedback end -->

Reporting-React-Print-Without-Preview.sln

Lines changed: 0 additions & 25 deletions
This file was deleted.

dxSampleReactReportingPrintWithoutPreview/Controllers/HomeController.cs renamed to ServerApp/Controllers/HomeController.cs

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.IO;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using DevExpress.XtraPrinting;
8-
using DevExpress.XtraReports.UI;
9-
using dxSampleReactReportingPrintWithoutPreview.Model;
10-
using dxSampleReactReportingPrintWithoutPreview.PredefinedReports;
11-
using Microsoft.AspNetCore.Mvc;
12-
13-
namespace dxSampleReactReportingPrintWithoutPreview.Controllers
14-
{
15-
[Route("api/[controller]")]
16-
public class HomeController : Controller
17-
{
18-
public IActionResult Index()
19-
{
20-
return View();
21-
}
22-
23-
public IActionResult Error()
24-
{
25-
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
26-
return View();
27-
}
28-
[HttpGet("[action]")]
29-
public async Task<object> Print()
30-
{
31-
var report = new TestReport();
32-
using (var ms = new MemoryStream())
33-
{
34-
await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true });
35-
return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf);
36-
}
37-
}
38-
[HttpGet("[action]")]
39-
public ActionResult Export(string format = "pdf")
40-
{
41-
format = format.ToLower();
42-
XtraReport report = new TestReport();
43-
string contentType = string.Format("application/{0}", format);
44-
using (MemoryStream ms = new MemoryStream())
45-
{
46-
switch (format)
47-
{
48-
case "pdf":
49-
contentType = "application/pdf";
50-
report.ExportToPdf(ms);
51-
break;
52-
case "docx":
53-
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
54-
report.ExportToDocx(ms);
55-
break;
56-
case "xls":
57-
contentType = "application/vnd.ms-excel";
58-
report.ExportToXls(ms);
59-
break;
60-
case "xlsx":
61-
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
62-
report.ExportToXlsx(ms);
63-
break;
64-
case "rtf":
65-
report.ExportToRtf(ms);
66-
break;
67-
case "mht":
68-
contentType = "message/rfc822";
69-
report.ExportToMht(ms);
70-
break;
71-
case "html":
72-
contentType = "text/html";
73-
report.ExportToHtml(ms);
74-
break;
75-
case "txt":
76-
contentType = "text/plain";
77-
report.ExportToText(ms);
78-
break;
79-
case "csv":
80-
contentType = "text/plain";
81-
report.ExportToCsv(ms);
82-
break;
83-
case "png":
84-
contentType = "image/png";
85-
report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png });
86-
break;
87-
}
88-
return File(ms.ToArray(), contentType);
89-
}
90-
}
91-
}
92-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using DevExpress.XtraPrinting;
8+
using DevExpress.XtraReports.UI;
9+
using ServerApp.Model;
10+
using ServerApp.PredefinedReports;
11+
using Microsoft.AspNetCore.Mvc;
12+
13+
namespace ServerApp.Controllers
14+
{
15+
[Route("api/[controller]")]
16+
public class HomeController : Controller
17+
{
18+
public IActionResult Index()
19+
{
20+
return View();
21+
}
22+
23+
public IActionResult Error()
24+
{
25+
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
26+
return View();
27+
}
28+
[HttpGet("[action]")]
29+
public async Task<object> Print()
30+
{
31+
var report = new TestReport();
32+
using (var ms = new MemoryStream())
33+
{
34+
await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true });
35+
return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf);
36+
}
37+
}
38+
[HttpGet("[action]")]
39+
public ActionResult Export(string format = "pdf")
40+
{
41+
format = format.ToLower();
42+
XtraReport report = new TestReport();
43+
string contentType = string.Format("application/{0}", format);
44+
using (MemoryStream ms = new MemoryStream())
45+
{
46+
switch (format)
47+
{
48+
case "pdf":
49+
contentType = "application/pdf";
50+
report.ExportToPdf(ms);
51+
break;
52+
case "docx":
53+
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
54+
report.ExportToDocx(ms);
55+
break;
56+
case "xls":
57+
contentType = "application/vnd.ms-excel";
58+
report.ExportToXls(ms);
59+
break;
60+
case "xlsx":
61+
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
62+
report.ExportToXlsx(ms);
63+
break;
64+
case "rtf":
65+
report.ExportToRtf(ms);
66+
break;
67+
case "mht":
68+
contentType = "message/rfc822";
69+
report.ExportToMht(ms);
70+
break;
71+
case "html":
72+
contentType = "text/html";
73+
report.ExportToHtml(ms);
74+
break;
75+
case "txt":
76+
contentType = "text/plain";
77+
report.ExportToText(ms);
78+
break;
79+
case "csv":
80+
contentType = "text/plain";
81+
report.ExportToCsv(ms);
82+
break;
83+
case "png":
84+
contentType = "image/png";
85+
report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png });
86+
break;
87+
}
88+
return File(ms.ToArray(), contentType);
89+
}
90+
}
91+
}
92+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using DevExpress.DataAccess.Sql;
2+
using System.Collections.Generic;
3+
using DevExpress.AspNetCore.Reporting.QueryBuilder;
4+
using DevExpress.AspNetCore.Reporting.ReportDesigner;
5+
using DevExpress.AspNetCore.Reporting.ReportDesigner.Native.Services;
6+
using DevExpress.AspNetCore.Reporting.QueryBuilder.Native.Services;
7+
using DevExpress.XtraReports.Web.ReportDesigner;
8+
using DevExpress.XtraReports.Web.ReportDesigner.Services;
9+
using DevExpress.AspNetCore.Reporting.WebDocumentViewer;
10+
using DevExpress.AspNetCore.Reporting.WebDocumentViewer.Native.Services;
11+
using Microsoft.AspNetCore.Mvc;
12+
13+
namespace ServerApp.Controllers {
14+
public class CustomWebDocumentViewerController : WebDocumentViewerController {
15+
public CustomWebDocumentViewerController(IWebDocumentViewerMvcControllerService controllerService) : base(controllerService) {
16+
}
17+
}
18+
public class CustomReportDesignerController : ReportDesignerController {
19+
public CustomReportDesignerController(IReportDesignerMvcControllerService controllerService) : base(controllerService) {
20+
}
21+
22+
[HttpPost("[action]")]
23+
public IActionResult GetDesignerModel([FromForm]string reportUrl, [FromServices] IReportDesignerModelBuilder designerModelBuilder, [FromForm] ReportDesignerSettingsBase designerModelSettings) {
24+
var ds = new SqlDataSource("NWindConnectionString");
25+
26+
// Create a SQL query to access the Products data table.
27+
SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products");
28+
ds.Queries.Add(query);
29+
ds.RebuildResultSchema();
30+
31+
var designerModel = designerModelBuilder.Report(reportUrl)
32+
.DataSources(dataSources => {
33+
dataSources.Add("Northwind", ds);
34+
})
35+
.BuildModel();
36+
designerModel.Assign(designerModelSettings);
37+
return DesignerModel(designerModel);
38+
}
39+
}
40+
41+
public class CustomQueryBuilderController : QueryBuilderController {
42+
public CustomQueryBuilderController(IQueryBuilderMvcControllerService controllerService) : base(controllerService) {
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)