141 lines
5.3 KiB
C#
141 lines
5.3 KiB
C#
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
|
|
}
|
|
} |