173 lines
5.7 KiB
C#
173 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using ClosedXML.Excel;
|
|
using FastReport;
|
|
using FastReport.Export.Csv;
|
|
using FastReport.Export.Mht;
|
|
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 AgencyReport: Controller
|
|
{
|
|
public readonly Setting _setting;
|
|
|
|
public AgencyReport(Setting setting)
|
|
{
|
|
this._setting = setting;
|
|
}
|
|
[HttpPost, Route("reports/agency_report/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetAgencyReport([FromRoute] string type, [FromBody] List<agency_report> agencyReports)
|
|
{
|
|
foreach (var agencyReport in agencyReports)
|
|
{
|
|
if (agencyReport.start_date!=null && agencyReport.end_date!=null)
|
|
{
|
|
agencyReport.startdate = agencyReport.start_date?.ToString("dd MMMM yyyy",
|
|
CultureInfo.CreateSpecificCulture("th-TH")) ?? "";
|
|
agencyReport.enddate = agencyReport.end_date?.ToString("dd MMMM yyyy",
|
|
CultureInfo.CreateSpecificCulture("th-TH")) ?? "";
|
|
}
|
|
|
|
if (agencyReport.bool_11_1==true)
|
|
{
|
|
agencyReport.bool_11_1_text = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.bool_11_1_text = "";
|
|
}
|
|
if (agencyReport.bool_11_2==true)
|
|
{
|
|
agencyReport.bool_11_2_text = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.bool_11_2_text = "";
|
|
}
|
|
if (agencyReport.bool_11_3==true)
|
|
{
|
|
agencyReport.bool_11_3_text = "X";
|
|
}else
|
|
{
|
|
agencyReport.bool_11_3_text = "";
|
|
}
|
|
//
|
|
if (agencyReport.bool_13_1==true)
|
|
{
|
|
agencyReport.text_13_1 = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.text_13_1 = "";
|
|
}
|
|
if (agencyReport.bool_13_2==true)
|
|
{
|
|
agencyReport.text_13_2 = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.text_13_2 = "";
|
|
}
|
|
if (agencyReport.bool_13_3==true)
|
|
{
|
|
agencyReport.text_13_3 = "X";
|
|
}else
|
|
{
|
|
agencyReport.text_13_3 = "";
|
|
}
|
|
if (agencyReport.bool_13_4==true)
|
|
{
|
|
agencyReport.text_13_4 = "X";
|
|
}else
|
|
{
|
|
agencyReport.text_13_4 = "";
|
|
}
|
|
if (agencyReport.bool_13_5==true)
|
|
{
|
|
agencyReport.text_13_5 = "X";
|
|
}else
|
|
{
|
|
agencyReport.text_13_5 = "";
|
|
}
|
|
if (agencyReport.bool_13_6==true)
|
|
{
|
|
agencyReport.text_13_6 = "X";
|
|
}else
|
|
{
|
|
agencyReport.text_13_6 = "";
|
|
}
|
|
if (agencyReport.bool_13_7==true)
|
|
{
|
|
agencyReport.text_13_7 = "X";
|
|
}else
|
|
{
|
|
agencyReport.text_13_7 = "";
|
|
}
|
|
//
|
|
if (agencyReport.bool_25_1==true)
|
|
{
|
|
agencyReport.text_25_1 = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.text_25_1 = "";
|
|
}
|
|
if (agencyReport.bool_25_2==true)
|
|
{
|
|
agencyReport.text_25_2 = "X";
|
|
}
|
|
else
|
|
{
|
|
agencyReport.text_25_2 = "";
|
|
}
|
|
}
|
|
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "agency_report.frx");
|
|
report.RegisterData(agencyReports, "agency_report");
|
|
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");
|
|
break;
|
|
case "mht":
|
|
MHTExport mht = new MHTExport();
|
|
report.Export(mht, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "multipart/related");
|
|
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();
|
|
}
|
|
|
|
}
|
|
} |