Prima bozza visualizzatore reports

This commit is contained in:
Samuele Locatelli
2026-04-09 09:54:31 +02:00
parent 0723f607ab
commit 29b8b2982d
11 changed files with 225 additions and 28 deletions
@@ -69,7 +69,8 @@ namespace Lux.Report.Data.Reports
// Create a report instance.
XtraReport report = null;
byte[] reportBytes = File.ReadAllBytes(Path.Combine(reportFolder, reportName));
byte[] reportBytes = File.ReadAllBytes(url);
//byte[] reportBytes = File.ReadAllBytes(Path.Combine(reportFolder, reportName));
using (MemoryStream ms = new MemoryStream(reportBytes))
report = XtraReport.FromStream(ms);
+12
View File
@@ -50,6 +50,7 @@ namespace Lux.Report.Data.Services
return answ;
}
/// <inheritdoc />
public bool FileCopy(string origPath, string destPath)
{
bool done = false;
@@ -63,6 +64,8 @@ namespace Lux.Report.Data.Services
}
return done;
}
/// <inheritdoc />
public bool FileDelete(string origPath)
{
bool done = false;
@@ -76,6 +79,7 @@ namespace Lux.Report.Data.Services
return done;
}
/// <inheritdoc />
public bool FileExists(string filePath)
{
// calcolo path file...
@@ -110,6 +114,14 @@ namespace Lux.Report.Data.Services
return answ;
}
/// <inheritdoc />
public byte[] ReadAllBytes(string filePath)
{
string fullPath = Path.Combine(basePath, filePath);
var rawData = File.ReadAllBytes(fullPath);
return rawData;
}
#endregion Public Methods
#region Private Fields
+7
View File
@@ -53,6 +53,13 @@ namespace Lux.Report.Data.Services
/// <returns>Elenco file trovati</returns>
List<string> ListFile(string folderPath, string pattern, bool hideDot);
/// <summary>
/// Restituisce contenuto file come byte array
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
byte[] ReadAllBytes(string filePath);
#endregion Public Methods
///// <summary>
@@ -23,24 +23,36 @@ namespace Lux.Report.Manager.Components.Compo
#region Protected Methods
protected string FileName(string fullName)
{
return Path.GetFileName(fullName);
}
protected override void OnParametersSet()
{
ReloadData();
}
private void ReloadData()
{
//base.OnParametersSet();
string repPath = Path.Combine("reports", CurrReport.Name);
// elenco file esclusi quelli nascosti (template)
ListReports = FService.ListFile(repPath, "*.repx", true);
}
#endregion Protected Methods
#region Private Fields
private List<string> ListReports = new List<string>();
#endregion Private Fields
#region Private Properties
[Inject]
private IFileService FService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
#endregion Private Properties
#region Private Methods
/// <summary>
/// Creazione nuovo report duplicando il file template
/// </summary>
@@ -75,15 +87,12 @@ namespace Lux.Report.Manager.Components.Compo
await EC_ReqUpdate.InvokeAsync(true);
}
#region Private Fields
private List<string> ListReports = new List<string>();
#endregion Private Fields
protected string FileName(string fullName)
private void ReloadData()
{
return Path.GetFileName(fullName);
//base.OnParametersSet();
string repPath = Path.Combine("reports", CurrReport.Name);
// elenco file esclusi quelli nascosti (template)
ListReports = FService.ListFile(repPath, "*.repx", true);
}
private async Task ReqEdit(string fullPath)
@@ -91,11 +100,6 @@ namespace Lux.Report.Manager.Components.Compo
await EC_ReqEdit.InvokeAsync(fullPath);
}
#region Private Properties
[Inject]
private IFileService FService { get; set; } = null!;
#endregion Private Properties
#endregion Private Methods
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.2604.0818</Version>
<Version>1.1.2604.0909</Version>
</PropertyGroup>
<ItemGroup>
-1
View File
@@ -21,5 +21,4 @@
<script src="_framework/blazor.web.js"></script>
<script type="text/javascript" src="lib/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
@@ -1,6 +1,21 @@
@page "/report-view"
@using DevExpress.Blazor.Reporting
@using DevExpress.XtraReports.UI;
<h3>ReportViewer</h3>
@code {
<link href="_content/DevExpress.Blazor.Themes.Fluent/core.min.css" rel="stylesheet" />
<link href="_content/DevExpress.Blazor.Themes.Fluent/global.min.css" rel="stylesheet" />
<link href="_content/DevExpress.Blazor.Themes.Fluent/modes/light.min.css" rel="stylesheet" />
<link href="_content/DevExpress.Blazor.Themes.Fluent/accents/blue.min.css" rel="stylesheet" />
<link href="_content/DevExpress.Blazor.Reporting.Viewer/css/dx-blazor-reporting-components.fluent.css" rel="stylesheet" />
<a target="_blank" class="btn btn-primary" href="@pdfUrl">Download PDF</a>
<DxReportViewer Report="@Report"></DxReportViewer>
@* <DxReportViewer @ref="reportViewer" Report="@Report"></DxReportViewer> *@
}
@@ -0,0 +1,141 @@
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.Services;
using DevExpress.XtraReports.UI;
using Lux.Report.Data.DTO;
using Lux.Report.Data.Services;
using Microsoft.AspNetCore.Components;
namespace Lux.Report.Server.Components.Pages
{
public partial class ReportViewer
{
#region Protected Methods
protected override void OnInitialized()
{
// recupero da conf i parametri dabse
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";
/*-----------------------
* FixMe Todo Da rivedere !!!
* - recuperare dati da URL
* - popolare dati dinamici
* - interagire con setup DB per parametri & co
*-----------------------*/
// recupero da URL i dati del report
string repType = "Offerta"; // da URL/DB?
string repFile = "Offerta_01.repx"; // da URL
string dataReportUrl = "offert"; // da recuperare dal DB
// calcolo valori specifici del report
string imgFullUrl = $"{apiUrl}/{imgUrl}/";
string dataFullUrl = $"{apiUrl}/{dataUrl}/{dataReportUrl}";
//string reqRep = "\\\\stor01\\TEAM DRIVES\\40_FileUpload\\LuxUploads\\reports\\Offerta\\Offerta_01.repx";
string repPath = Path.Combine("reports", repType, repFile);
// recupero da DB e URL conf parametri e valori correnti...
List<ParamConfigDto> paramsConfig = new();
Dictionary<string, string> paramsVal = new();
// lettura file report
var repData = FService.ReadAllBytes(repPath);
using (MemoryStream ms = new MemoryStream(repData))
{
Report = XtraReport.FromStream(ms);
var ds = ComposeJsonDataSource(dataFullUrl, paramsConfig, paramsVal);
ds.Fill();
Report.DataSource = ds;
Report.DataMember = "";
// deve diventare dinamico da paramsConfig + ParamsVal +...
Report.Parameters["pImgPath"].Value = imgFullUrl;
}
#if false
// 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;
//}
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
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);
}
#endif
}
/// <summary>
/// Composizione DataSource Json
/// </summary>
/// <param name="rawDataUrl">URL di partenza</param>
/// <param name="paramsConfig">Configurazione dei parametri da applicare</param>
/// <param name="paramsVal">Valore corrente parametri</param>
/// <returns></returns>
private JsonDataSource ComposeJsonDataSource(string rawDataUrl, List<ParamConfigDto> paramsConfig, Dictionary<string, string> paramsVal)
{
// Create a new JSON source.
var jsonSource = new UriJsonSource()
{
Uri = new Uri(rawDataUrl)
};
// per ora fisso, poi da rivedere...
int currID = 7;
jsonSource.PathParameters.Add(new PathParameter("OfferId", typeof(int), currID));
// Assign the JSON source to the data source.
var datasource = new JsonDataSource()
{
JsonSource = jsonSource
};
return datasource;
}
#endregion Protected Methods
#region Private Fields
private int oID = 0;
//private DxReportViewer? reportViewer;
private XtraReport Report;
#endregion Private Fields
#region Private Properties
[Inject]
private IConfiguration _config { get; set; } = null!;
[Inject]
private IFileService FService { get; set; } = null!;
[Inject]
private NavigationManager NavManager { get; set; } = null!;
private string pdfUrl
{
get => $"download-offer?id={oID}";
}
[Inject]
private IReportProvider reportProvider { get; set; }
#endregion Private Properties
}
}
@@ -8,3 +8,4 @@
@using Microsoft.JSInterop
@using Lux.Report.Server
@using Lux.Report.Server.Components
@using Lux.Report.Server.Components.Compo
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
+17
View File
@@ -1,5 +1,11 @@
using DevExpress.Blazor.Reporting;
using Lux.Report.Data;
using Lux.Report.Data.Reports;
using Lux.Report.Data.Repository;
using Lux.Report.Data.Services;
using Lux.Report.Server.Components;
using Microsoft.AspNetCore.Localization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
using NLog;
using NLog.Targets;
@@ -25,6 +31,17 @@ logger.Info($"Current ASPNETCORE_ENVIRONMENT: {env.EnvironmentName}");
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// aggiungo servizi "interni"
builder.Services.AddSingleton<IFileService, FileService>();
// aggiunta servizi DevExpress
builder.Services.AddDevExpressServerSideBlazorReportViewer();
builder.Services.AddMvc();
builder.Services.AddDevExpressBlazorReporting();
// build applicazione
var app = builder.Build();
// aggiunt base URL x routing corretto