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 Swashbuckle.AspNetCore.Annotations; namespace rmutr_report.Controllers { [SwaggerTag("แบบรายงานผลการดำเนินงานโครงการ")] public class projectPerformanceForm : Controller { readonly Setting _setting; public projectPerformanceForm(Setting setting) { _setting = setting; } [HttpPost, Route("reports/project_performance_report_form/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetProjectPerformanceReport([FromRoute] string type, [FromBody] project_performance_report_form reportForm) { if (reportForm.national_budget_money==true) { reportForm.check_box1 = "/"; } if (reportForm.income_budget==true) { reportForm.check_box2 = "/"; } if (reportForm.other==true) { reportForm.check_box3 = "/"; } if (reportForm.digital_innovation==true) { reportForm.check_box4 = "/"; } if (reportForm.moral==true) { reportForm.check_box5 = "/"; } if (reportForm.open_mind==true) { reportForm.check_box6 = "/"; } if (reportForm.value==true) { reportForm.check_box7 = "/"; } if (reportForm.entrepreneurship==true) { reportForm.check_box8 = "/"; } if (reportForm.unity==true) { reportForm.check_box9 = "/"; } if (reportForm.porfessional==true) { reportForm.check_box10 = "/"; } if (reportForm.check_twenty_four==true) { reportForm.check_twenty_four1 = "/"; } if (reportForm.check_twenty_four==false) { reportForm.check_twenty_four2 = "/"; } if (reportForm.project_style!=null) { foreach (var projects in reportForm.project_style) { if (projects.check == true) { projects.checkbox = "/"; } if (projects.check == false) { projects.checkbox = null; } } } if (reportForm.twenty_four_table!=null) { var sum1 = reportForm.twenty_four_table.Sum(g => g.amount_1); var sum2 = reportForm.twenty_four_table.Sum(g => g.amount_2); reportForm.total_amount_1 = sum1; reportForm.total_amount_2 = sum2; } var projectPerformance = new List() { reportForm }; Report report = new Report(); report.Load(_setting.report_path + "project_performance_report_form.frx"); report.RegisterData(projectPerformance, "project_performance_report_form"); 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.openxmlformats-officedocument.spreadsheetml.sheet", "project_performance_report_form" + ".xlsx"); } return Ok(); } } }