FastReport: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
  Oracle.ManagedDataAccess.dll
  Oracle.ManagedDataAccess.dll


<source lang="C#">
<source lang="csharp">
using FastReport.Export.Pdf;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
Line 61: Line 61:
</source>
</source>


==Employee==
<source lang="csharp">
using ChorkeAcademiaPersis.Entity;
using ChorkeAcademiaPersis.Utility;
using Microsoft.AspNetCore.Mvc;
using NHibernate;
using System.Collections.Generic;
using FastReport.Export.PdfSimple;
using System.IO;
using System.Linq;
namespace ChorkeAcademiaPersis.Controllers
{
    [Route("api/rest/[controller]")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        // GET: api/rest/<EmployeeController>/pdf
        [HttpGet("pdf")]
        public IActionResult Get()
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var employees = session.Query<Employee>().ToList();
                var data = DataTableUtil.ToDataTable<Employee>(employees);
                data.TableName = "Employee";
                data.WriteXmlSchema("./Generated/Employee.xml");
                using (var report = new FastReport.Report())
                {
                    report.Load("./FastReports/Employee.frx");
                    report.RegisterData(data, "Employee");
                    report.Prepare();
                    using (var ms = new MemoryStream())
                    {
                        var pdfExport = new PDFSimpleExport();
                        report.Export(pdfExport, ms);
                        return File(ms.ToArray(), "application/pdf");
                    }
                }
            }
        }
    }
}
</source>


==References==
==References==
{|
| valign="top" |
* [https://opensource.fast-report.com/2019/06/pdf-export-in-fastreportopensource.html PDF Export in FastReport Open Source using ASP .Net Core]
* [https://opensource.fast-report.com/2019/06/pdf-export-in-fastreportopensource.html PDF Export in FastReport Open Source using ASP .Net Core]
* [https://stackoverflow.com/questions/40486431/ Return PDF to the Browser using ASP.NET Core]
* [https://stackoverflow.com/questions/40486431/ Return PDF to the Browser using ASP.NET Core]
Line 73: Line 121:
* [https://www.fast-report.com/en/download/fast-report-net/ FastReport .NET Download]
* [https://www.fast-report.com/en/download/fast-report-net/ FastReport .NET Download]
* [https://www.fast-report.com/en/download/fast-cube-net/ FastCube .NET Download]
* [https://www.fast-report.com/en/download/fast-cube-net/ FastCube .NET Download]
| valign="top |
* [https://www.fast-report.com/en/blog/show/creating-pdf-on-raspberry-pi/ Fast Report on Raspberry PI]
* [https://www.nuget.org/packages/FastReport.Core/ Nuget FastReport.Core]
* [https://www.nuget.org/packages/FastReport.Core/ Nuget FastReport.Core]
|}

Latest revision as of 08:35, 24 September 2021

FastReport.dll
FastReport.Bars.dll
FastReport.Json.dll
FastReport.Editor.dll
Oracle.ManagedDataAccess.dll
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace ChorkeAcademiaReport.Controllers.Report
{
    public class ReportController : Controller
    {
        //private readonly ReportDao reportDao;
        private readonly IWebHostEnvironment hostingEnvironment;
        public ReportController(IConfiguration configuration, IWebHostEnvironment _hostingEnvironment)
        {
            //this.reportDao = new ReportDao(configuration);
            this.hostingEnvironment = _hostingEnvironment;
        }

        [HttpGet("/api/rest/report")]
        public IActionResult GetData(string FromDate, string ToDate)
        {
            try
            {
                using (var report = new FastReport.Report())
                {
                    report.Load($"{hostingEnvironment.WebRootPath}/reports/R0TM00X00.frx");
                    var data = reportDao.GetData("EN", FromDate, ToDate);
                    report.SetParameterValue("FromDate", FromDate);
                    report.SetParameterValue("ToDate", ToDate);
                    report.RegisterData(data, "M00TM00X00");
                    report.Prepare();
                    using (var ms = new MemoryStream())
                    {
                        var pdfExport = new PDFExport();
                        report.Export(pdfExport, ms);
                        return File(ms.ToArray(), "Application/PDF");
                    }
                }
            }
            catch (Exception e)
            {
                string text = e.Message;
                Console.WriteLine(e.Message);
                return BadRequest(new { msg = "No data found!" });
            }
        }
    }
}

Employee

using ChorkeAcademiaPersis.Entity;
using ChorkeAcademiaPersis.Utility;
using Microsoft.AspNetCore.Mvc;
using NHibernate;
using System.Collections.Generic;
using FastReport.Export.PdfSimple;
using System.IO;
using System.Linq;

namespace ChorkeAcademiaPersis.Controllers
{
    [Route("api/rest/[controller]")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        // GET: api/rest/<EmployeeController>/pdf
        [HttpGet("pdf")]
        public IActionResult Get()
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var employees = session.Query<Employee>().ToList();
                var data = DataTableUtil.ToDataTable<Employee>(employees);

                data.TableName = "Employee";
                data.WriteXmlSchema("./Generated/Employee.xml");
                using (var report = new FastReport.Report())
                {
                    report.Load("./FastReports/Employee.frx");
                    report.RegisterData(data, "Employee");
                    report.Prepare();

                    using (var ms = new MemoryStream())
                    {
                        var pdfExport = new PDFSimpleExport();
                        report.Export(pdfExport, ms);
                        return File(ms.ToArray(), "application/pdf");
                    }
                }
            }
        }
    }
}

References