Files
lux/TestDevExpress/Components/Pages/TestReportViewer.razor.cs
2026-04-07 14:36:24 +02:00

100 lines
3.5 KiB
C#

using DevExpress.Blazor.Reporting;
using DevExpress.DataAccess;
using DevExpress.DataAccess.Json;
using DevExpress.DataAccess.ObjectBinding;
using DevExpress.Drawing.Internal.Fonts.Interop;
using DevExpress.Security;
using DevExpress.XtraPrinting.Native.Properties;
using DevExpress.XtraReports;
using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.Services;
using DevExpress.XtraReports.UI;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.WebUtilities;
using System;
using System.Security.Cryptography;
using TestDevExpress.Components.Reports;
namespace TestDevExpress.Components.Pages
{
public partial class TestReportViewer
{
#region Protected Methods
private string pdfUrl
{
get => $"download-offer?id={oID}";
}
private int oID = 0;
protected override void OnInitialized()
{
// calcolo i parametri x IMG e Json da conf
string apiUrl = _config.GetValue<string>("ServerConf:ApiBaseUrl") ?? "https://iis01.egalware.com/lux/srv/api";
string imgUrl = _config.GetValue<string>("ServerConf:ImageUrl") ?? "image";
string dataUrl = _config.GetValue<string>("ServerConf:DataUrl") ?? "report/offert/";
string imgFullUrl = $"{apiUrl}/{imgUrl}/";
string dataFullUrl = $"{apiUrl}/{dataUrl}";
//cerco id da URL x offerta da mostrare
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
//if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("OfferId", out var offerId))
//{
// int.TryParse(offerId, out oID);
// currReport = new OfferReport(dataFullUrl, oID);
// currReport.Parameters["pImgPath"].Value = imgFullUrl;
//}
// Costruzione report viewer con import report
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("OfferId", out var offerId))
{
int.TryParse(offerId, out oID);
Report = reportProvider.GetReport("TestReport1?URL=" + dataFullUrl + "?pOfferId=" + offerId + "&pImgPath=" + imgFullUrl, null);
var ds = CreateDataSourceFromWeb(oID, dataFullUrl);
ds.Fill();
Report.DataSource = ds;
Report.DataMember = "";
Report.Parameters["pImgPath"].Value = imgFullUrl;
}
}
public JsonDataSource CreateDataSourceFromWeb(int oID, string dataFullUrl)
{
// Create a new JSON source.
var jsonSource = new UriJsonSource()
{
Uri = new Uri(dataFullUrl)
};
jsonSource.PathParameters.Add(new PathParameter("OfferId", typeof(int), oID));
// Assign the JSON source to the data source.
var datasource = new JsonDataSource()
{
JsonSource = jsonSource
};
return datasource;
}
#endregion Protected Methods
#region Private Fields
private OfferReport currReport = new();
private DxReportViewer? reportViewer;
private XtraReport Report = new XtraReport1();
#endregion Private Fields
#region Private Properties
[Inject]
private IConfiguration _config { get; set; } = null!;
[Inject]
private NavigationManager NavManager { get; set; } = null!;
[Inject]
public IReportProvider reportProvider { get; set; }
#endregion Private Properties
}
}