diff --git a/Lux.Report.Data/Reports/CustomReportStorageWebExtension.cs b/Lux.Report.Data/Reports/CustomReportStorageWebExtension.cs index 461fb4cc..6d6b4557 100644 --- a/Lux.Report.Data/Reports/CustomReportStorageWebExtension.cs +++ b/Lux.Report.Data/Reports/CustomReportStorageWebExtension.cs @@ -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); diff --git a/Lux.Report.Data/Services/FileService.cs b/Lux.Report.Data/Services/FileService.cs index a1028342..6aa13bc9 100644 --- a/Lux.Report.Data/Services/FileService.cs +++ b/Lux.Report.Data/Services/FileService.cs @@ -50,6 +50,7 @@ namespace Lux.Report.Data.Services return answ; } + /// public bool FileCopy(string origPath, string destPath) { bool done = false; @@ -63,6 +64,8 @@ namespace Lux.Report.Data.Services } return done; } + + /// public bool FileDelete(string origPath) { bool done = false; @@ -76,6 +79,7 @@ namespace Lux.Report.Data.Services return done; } + /// public bool FileExists(string filePath) { // calcolo path file... @@ -110,6 +114,14 @@ namespace Lux.Report.Data.Services return answ; } + /// + public byte[] ReadAllBytes(string filePath) + { + string fullPath = Path.Combine(basePath, filePath); + var rawData = File.ReadAllBytes(fullPath); + return rawData; + } + #endregion Public Methods #region Private Fields diff --git a/Lux.Report.Data/Services/IFileService.cs b/Lux.Report.Data/Services/IFileService.cs index 084abc67..4b0ff2ec 100644 --- a/Lux.Report.Data/Services/IFileService.cs +++ b/Lux.Report.Data/Services/IFileService.cs @@ -53,6 +53,13 @@ namespace Lux.Report.Data.Services /// Elenco file trovati List ListFile(string folderPath, string pattern, bool hideDot); + /// + /// Restituisce contenuto file come byte array + /// + /// + /// + byte[] ReadAllBytes(string filePath); + #endregion Public Methods ///// diff --git a/Lux.Report.Manager/Components/Compo/RepoFileList.razor.cs b/Lux.Report.Manager/Components/Compo/RepoFileList.razor.cs index 9be15783..58c21b40 100644 --- a/Lux.Report.Manager/Components/Compo/RepoFileList.razor.cs +++ b/Lux.Report.Manager/Components/Compo/RepoFileList.razor.cs @@ -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 ListReports = new List(); + + #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 + /// /// Creazione nuovo report duplicando il file template /// @@ -75,15 +87,12 @@ namespace Lux.Report.Manager.Components.Compo await EC_ReqUpdate.InvokeAsync(true); } - #region Private Fields - - private List ListReports = new List(); - - #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 } } \ No newline at end of file diff --git a/Lux.Report.Manager/Lux.Report.Manager.csproj b/Lux.Report.Manager/Lux.Report.Manager.csproj index 4a9e96e5..cd1e77ad 100644 --- a/Lux.Report.Manager/Lux.Report.Manager.csproj +++ b/Lux.Report.Manager/Lux.Report.Manager.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2604.0818 + 1.1.2604.0909 diff --git a/Lux.Report.Server/Components/App.razor b/Lux.Report.Server/Components/App.razor index 01cd172b..9fa5c487 100644 --- a/Lux.Report.Server/Components/App.razor +++ b/Lux.Report.Server/Components/App.razor @@ -21,5 +21,4 @@ - diff --git a/Lux.Report.Server/Components/Pages/ReportViewer.razor b/Lux.Report.Server/Components/Pages/ReportViewer.razor index 7e3488ed..49096584 100644 --- a/Lux.Report.Server/Components/Pages/ReportViewer.razor +++ b/Lux.Report.Server/Components/Pages/ReportViewer.razor @@ -1,6 +1,21 @@ @page "/report-view" + + +@using DevExpress.Blazor.Reporting +@using DevExpress.XtraReports.UI; +

ReportViewer

-@code { + + + + + + + +Download PDF + + + +@* *@ -} diff --git a/Lux.Report.Server/Components/Pages/ReportViewer.razor.cs b/Lux.Report.Server/Components/Pages/ReportViewer.razor.cs new file mode 100644 index 00000000..afaf5ad4 --- /dev/null +++ b/Lux.Report.Server/Components/Pages/ReportViewer.razor.cs @@ -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("ServerConf:ApiBaseUrl") ?? "https://iis01.egalware.com/lux/srv/api"; + string imgUrl = _config.GetValue("ServerConf:ImageUrl") ?? "image"; + string dataUrl = _config.GetValue("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 paramsConfig = new(); + Dictionary 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("ServerConf:ApiBaseUrl") ?? "https://iis01.egalware.com/lux/srv/api"; + string imgUrl = _config.GetValue("ServerConf:ImageUrl") ?? "image"; + string dataUrl = _config.GetValue("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 + } + + /// + /// Composizione DataSource Json + /// + /// URL di partenza + /// Configurazione dei parametri da applicare + /// Valore corrente parametri + /// + private JsonDataSource ComposeJsonDataSource(string rawDataUrl, List paramsConfig, Dictionary 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 + } +} \ No newline at end of file diff --git a/Lux.Report.Server/Components/_Imports.razor b/Lux.Report.Server/Components/_Imports.razor index 80133f52..28a5d623 100644 --- a/Lux.Report.Server/Components/_Imports.razor +++ b/Lux.Report.Server/Components/_Imports.razor @@ -8,3 +8,4 @@ @using Microsoft.JSInterop @using Lux.Report.Server @using Lux.Report.Server.Components +@using Lux.Report.Server.Components.Compo diff --git a/Lux.Report.Server/Lux.Report.Server.csproj b/Lux.Report.Server/Lux.Report.Server.csproj index 9e542688..c144e7de 100644 --- a/Lux.Report.Server/Lux.Report.Server.csproj +++ b/Lux.Report.Server/Lux.Report.Server.csproj @@ -1,4 +1,4 @@ - + net8.0 diff --git a/Lux.Report.Server/Program.cs b/Lux.Report.Server/Program.cs index 8c4e17aa..5b030e75 100644 --- a/Lux.Report.Server/Program.cs +++ b/Lux.Report.Server/Program.cs @@ -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(); + +// aggiunta servizi DevExpress +builder.Services.AddDevExpressServerSideBlazorReportViewer(); + +builder.Services.AddMvc(); +builder.Services.AddDevExpressBlazorReporting(); + +// build applicazione var app = builder.Build(); // aggiunt base URL x routing corretto