Files
EnvelopeGenerator/EnvelopeGenerator.ReceiverUI/Pages/EnvelopeReceiverPage_DxReportViewer.razor
TekH ecb7f45f14 Refactor report creation and property initialization
Replaced nullable fields with non-nullable properties for `Report`
and `BasePdfBytes` to improve initialization and encapsulation.
Updated `OnInitializedAsync` to use `BasePdfBytes` and added
error handling for missing PDF bytes.

Refactored report creation logic by removing `BuildFreshBaseReport`
and `CreateReportInstance`, consolidating functionality into a
new `CreateReport` method. Enhanced `CreateReport` to support
both predefined and dynamically generated reports, simplifying
the code structure and improving maintainability.
2026-06-11 13:12:40 +02:00

55 lines
2.0 KiB
Plaintext

@page "/envelope/{EnvelopeKey}/DxReportViewer"
@using XtraReport = DevExpress.XtraReports.UI.XtraReport
@using DevExpress.Blazor.Reporting
@using Microsoft.Extensions.Options
@using EnvelopeGenerator.ReceiverUI.Options
@using EnvelopeGenerator.ReceiverUI.Services
@inject InMemoryReportStorageWebExtension ReportStorage
@inject DocumentService DocumentService
@inject IOptions<ApiOptions> AppOptions
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
<link href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.bs5.css" rel="stylesheet" />
@if (Report is not null) {
<DxReportViewer Report="Report" RootCssClasses="w-100 h-100" Zoom="1.3" />
}
@code {
[Parameter] public string EnvelopeKey { get; set; } = string.Empty;
XtraReport Report { get; set; } = null!;
byte[] BasePdfBytes { get; set; } = null!;
protected override async Task OnInitializedAsync() {
if (!AppOptions.Value.UsePredefinedReports) {
var (pdfBytes, _) = await DocumentService.GetDocumentAsync(EnvelopeKey);
if (pdfBytes is { Length: > 0 })
BasePdfBytes = pdfBytes;
else
throw new InvalidOperationException($"No PDF bytes found for EnvelopeKey: {EnvelopeKey}");
}
Report = CreateReport();
}
XtraReport CreateReport()
{
if (AppOptions.Value.UsePredefinedReports)
{
return ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
? savedReport
: PredefinedReports.ReportsFactory.GetReport("LargeDatasetReport");
}
else
{
var report = new XtraReport();
var detail = new DevExpress.XtraReports.UI.DetailBand();
report.Bands.Add(detail);
detail.Controls.Add(new DevExpress.XtraReports.UI.XRPdfContent { Source = BasePdfBytes, GenerateOwnPages = true });
return report;
}
}
}