How to use FastReport .frx file in .NET WinUI3 App?
-
Good day, i have a report being designed in FastReport App, jus to use it in .NET MAUI or WinUI3 desktop App, it seems there is not visual designer for MAUI or WinUI3 for creating reports, and FastReport doesn't offer native support:
My problem is that it shows only the first record in the dataset i had created in C#:
Here is my code:
private async void ImprimirRecibo(object obj) { try { using (FastReport.Report reporte = new FastReport.Report()) { string path = Path.Combine(AppContext.BaseDirectory, "Assets", "report1.frx"); reporte.Load(path); int numeroRecibo = _recibo.idrecibos; reporte.SetParameterValue("nro_recibo", numeroRecibo); System.Diagnostics.Debug.WriteLine($"recibo: " + numeroRecibo); DataTable dt = await _reciboService.ListadoRecdAsync(numeroRecibo); dt.TableName = "Item"; foreach (DataColumn col in dt.Columns) { System.Diagnostics.Debug.WriteLine($"Columna disponible: {col.ColumnName}"); } // Registrar DataTable con el mismo nombre que en el XSD reporte.RegisterData(dt, "Item"); // Obtener el DataSource específico y asignarlo a la DataBand var dataSource = reporte.GetDataSource("Item"); // Habilitar el datasource dataSource.Enabled = true; // Preparar reporte reporte.Prepare(); using (MemoryStream ms = new MemoryStream()) { var export = new PDFSimpleExport(); reporte.Export(export, ms); ms.Position = 0; string tempFile = Path.Combine(Path.GetTempPath(), $"recibo_{numeroRecibo}.pdf"); await File.WriteAllBytesAsync(tempFile, ms.ToArray()); var ventanaPdf = new PdfViewerWindow(tempFile); ventanaPdf.Activate(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error al imprimir: {ex.Message}"); } }
-
Good day, i have a report being designed in FastReport App, jus to use it in .NET MAUI or WinUI3 desktop App, it seems there is not visual designer for MAUI or WinUI3 for creating reports, and FastReport doesn't offer native support:
My problem is that it shows only the first record in the dataset i had created in C#:
Here is my code:
private async void ImprimirRecibo(object obj) { try { using (FastReport.Report reporte = new FastReport.Report()) { string path = Path.Combine(AppContext.BaseDirectory, "Assets", "report1.frx"); reporte.Load(path); int numeroRecibo = _recibo.idrecibos; reporte.SetParameterValue("nro_recibo", numeroRecibo); System.Diagnostics.Debug.WriteLine($"recibo: " + numeroRecibo); DataTable dt = await _reciboService.ListadoRecdAsync(numeroRecibo); dt.TableName = "Item"; foreach (DataColumn col in dt.Columns) { System.Diagnostics.Debug.WriteLine($"Columna disponible: {col.ColumnName}"); } // Registrar DataTable con el mismo nombre que en el XSD reporte.RegisterData(dt, "Item"); // Obtener el DataSource específico y asignarlo a la DataBand var dataSource = reporte.GetDataSource("Item"); // Habilitar el datasource dataSource.Enabled = true; // Preparar reporte reporte.Prepare(); using (MemoryStream ms = new MemoryStream()) { var export = new PDFSimpleExport(); reporte.Export(export, ms); ms.Position = 0; string tempFile = Path.Combine(Path.GetTempPath(), $"recibo_{numeroRecibo}.pdf"); await File.WriteAllBytesAsync(tempFile, ms.ToArray()); var ventanaPdf = new PdfViewerWindow(tempFile); ventanaPdf.Activate(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error al imprimir: {ex.Message}"); } }
@User-10147035 said in How to use FastReport .frx file in .NET WinUI3 App?:
ms.Position = 0;
Before resetting the position, have you set a breakpoint to check that the stream has data? ie:Position > 0
?