using System; using System.Collections.Generic; using System.IO; using System.Linq; using FastReport; using FastReport.Export.OoXML; using FastReport.Export.Pdf; using Microsoft.AspNetCore.Mvc; using rmutr_report.Models; using rmutr_report.Models.RoThree; using Swashbuckle.AspNetCore.Annotations; namespace rmutr_report.Controllers { [SwaggerTag("สำหรับรายงาน ร.3 คำชี้แจงงบดำเนินงาน")] public class RoThree : Controller { readonly Setting _setting; public RoThree(Setting setting) { this._setting = setting; } [HttpPost, Route("reports/operating_budget_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetRoThreeReport([FromRoute] string type, [FromBody] operating_budget_ro_three three) { var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "operating_budget_ro_three.frx"); report.RegisterData(threes, "operating_budget_ro_three"); report.Prepare(); MemoryStream stream = new MemoryStream(); switch (type) { case "pdf": PDFExport pdf = new PDFExport(); report.Export(pdf, stream); stream.Seek(0, SeekOrigin.Begin); return File(stream, "application/pdf"); case "xls": case "xlsx": Excel2007Export excel = new Excel2007Export(); report.Export(excel, stream); stream.Seek(0, SeekOrigin.Begin); //return File(stream, "application/vnd.ms-excel"); string date = DateTime.Now.ToString("yyyyMMddHHmmss"); return File( stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", date + ".xlsx"); break; case "doc": case "docx": Word2007Export word = new Word2007Export(); report.Export(word, stream); stream.Seek(0, SeekOrigin.Begin); return File(stream, "appllication/vnd.ms-word"); break; } return Ok(); } } }