using DevExpress.Blazor.Reporting; using DevExpress.DataAccess; using DevExpress.DataAccess.Json; using DevExpress.XtraReports; using DevExpress.XtraReports.UI; using Microsoft.AspNetCore.Components; using TestDevExpress.Components.Reports; namespace TestDevExpress.Components.Pages { public partial class ReportViewer { // Recupera il parametro "id" dalla Query String (?id=7) [SupplyParameterFromQuery(Name = "id")] public int? OfferId { get; set; } //// Variabile che conterrā l'istanza del report DevExpress //public XtraReport OfferReportInstance = new XtraReport(); private DxReportViewer? reportViewer; //private TestReport Report = new TestReport(); private OfferReport currReport = new(); //private int IDOffert = 10283; protected override void OnInitialized() { //// 2. Assicurati che il report abbia il parametro //currReport.Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter() //{ // Name = "p_IdSorgente", // Type = typeof(int), // Value = 1, // Visible = false //}); //// 3. Crea la configurazione dell'URL con il placeholder {id} //UriJsonSource uriJsonSource = new UriJsonSource(new Uri("https://iis01.egalware.com/lux/srv/api/report/offert/{id}")); //// 4. Crea il PathParameter e collegalo tramite un'espressione al parametro del report //PathParameter idParameter = new PathParameter( // "id", // typeof(int), // new Expression("?p_IdSorgente") // Il '?' indica che si tratta di un parametro del report //); //uriJsonSource.PathParameters.Add(idParameter); //// 5. Crea il DataSource e assegnalo al report //JsonDataSource jsonDataSource = new JsonDataSource(); //jsonDataSource.JsonSource = uriJsonSource; //// (Opzionale) Compila lo schema se devi disegnare il report a runtime //// jsonDataSource.Fill(); //// 6. Assegna la sorgente al report //currReport.DataSource = jsonDataSource; //// Create a new JSON source. //var jsonSource = new UriJsonSource() //{ // Uri = new Uri(@"https://iis01.egalware.com/lux/srv/api/report/offert") //}; //// Create the "id" path parameters that are appended to the JSON URI //jsonSource.PathParameters.AddRange(new[] { // new PathParameter("id", typeof(int), new Expression("?ID")) //}); //// Assign the JSON source to the data source. //var datasource = new JsonDataSource() //{ // JsonSource = jsonSource //}; //currReport.DataSource = datasource; ////// Imposta il parametro PRIMA che il viewer renderizzi ////Report.Parameters["orderID"].Value = IDOffert; ////Report.Parameters["orderID"].Visible = false; } protected override void OnParametersSet() { //// Inizializza la classe del tuo report (creata con il designer DevExpress) //OfferReportInstance = new TestReport(); //// Verifica se il parametro č stato passato nell'URL //if (OfferId.HasValue) //{ // // Cerca il parametro all'interno del report DevExpress (assicurati che il nome corrisponda) // var parametroDx = OfferReportInstance.Parameters["offerID"]; // if (parametroDx != null) // { // // Assegna il valore recuperato dall'URL // parametroDx.Value = OfferId.Value; // // (Opzionale) Nascondi il parametro nell'interfaccia utente se non vuoi che l'utente lo modifichi // parametroDx.Visible = false; // } //} //else //{ // // Cerca il parametro all'interno del report DevExpress (assicurati che il nome corrisponda) // var parametroDx = OfferReportInstance.Parameters["offerID"]; // if (parametroDx != null) // { // // Assegna il valore recuperato dall'URL // parametroDx.Value = 7; // // (Opzionale) Nascondi il parametro nell'interfaccia utente se non vuoi che l'utente lo modifichi // parametroDx.Visible = false; // } //} ////base.OnParametersSet(); } } }