// 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; using System.IO.Compression; namespace Lux.Report.Server.Components.Compo { public partial class ReportViewer { #region Public Properties [Parameter] public ReportViewConfDto RepViewConf { get; set; } = null!; [Parameter] public Dictionary RequestDict { get; set; } = null!; #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { if (RepViewConf != null && RequestDict != null) { doShow = false; Report = null; //string reqRep = "\\\\stor01\\TEAM DRIVES\\40_FileUpload\\LuxUploads\\reports\\Offerta\\Offerta_01.repx"; string repPath = Path.Combine("reports", RepViewConf.ReportType, RepViewConf.ReportFile); // recupero da DB e URL conf parametri e valori correnti... List paramsConfig = new(); // se esiste il file... if (FService.FileExists(repPath)) { // lettura file report var repData = FService.ReadAllBytes(repPath); using (MemoryStream ms = new MemoryStream(repData)) { Report = XtraReport.FromStream(ms); var ds = ComposeJsonDataSource(RepViewConf.DataFullUrl, paramsConfig, RequestDict); ds.Fill(); Report.DataSource = ds; Report.DataMember = ""; // deve diventare dinamico da paramsConfig + ParamsVal +... foreach (DevExpress.XtraReports.Parameters.Parameter param in Report.Parameters) { if(param.Name.Equals("pImgPath")) Report.Parameters["pImgPath"].Value = RepViewConf.ImgFullUrl; } doShow = true; } } } //base.OnParametersSet(); } #endregion Protected Methods #region Private Fields private bool doShow = false; private string pdfUrl = ""; private XtraReport? Report = null; #endregion Private Fields #region Private Properties [Inject] private IFileService FService { get; set; } = null!; [Inject] private NavigationManager NavManager { get; set; } = null!; [Inject] private IReportProvider reportProvider { get; set; } #endregion Private Properties #region Private Methods /// /// 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) }; int reqID = 7; string codGroup = ""; if (paramsVal.ContainsKey("ReqID")) { var rawData = paramsVal["ReqID"]; int.TryParse(rawData, out reqID); } if (paramsVal.ContainsKey("codGroup")) { codGroup = paramsVal["codGroup"]; } jsonSource.PathParameters.Add(new PathParameter("ReqId", typeof(int), reqID)); if (!string.IsNullOrEmpty(codGroup) && rawDataUrl.Contains("matreq-sale-ord")) { jsonSource.QueryParameters.Add(new QueryParameter("codGroup", typeof(string), codGroup)); } // Assign the JSON source to the data source. var datasource = new JsonDataSource() { JsonSource = jsonSource }; return datasource; } #endregion Private Methods } }