Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Development
  4. How to use FastReport .frx file in .NET WinUI3 App?

How to use FastReport .frx file in .NET WinUI3 App?

Scheduled Pinned Locked Moved Windows Development
2 Posts 2 Posters 111 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10147035
    wrote last edited by
    #1

    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:

    example report

    My problem is that it shows only the first record in the dataset i had created in C#:

    Result

    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}");
        }
    }
    
    Graeme_GrantG 1 Reply Last reply
    0
    • U User 10147035

      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:

      example report

      My problem is that it shows only the first record in the dataset i had created in C#:

      Result

      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}");
          }
      }
      
      Graeme_GrantG Offline
      Graeme_GrantG Offline
      Graeme_Grant
      wrote last edited by
      #2

      @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?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups