Fix Report
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kamonwan taengsuk
2025-01-27 12:01:44 +07:00
parent 9a4f0e95ea
commit 5abb0843e4
4 changed files with 85 additions and 129 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@@ -15,7 +16,7 @@ using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers namespace rmutr_report.Controllers
{ {
[SwaggerTag("สำหรับรายงานผลการดำเนินงานโครงการ")] [SwaggerTag("สำหรับรายงานผลการดำเนินงานโครงการ")]
public class AgencyReport: Controller public class AgencyReport : Controller
{ {
public readonly Setting _setting; public readonly Setting _setting;
@@ -23,13 +24,24 @@ namespace rmutr_report.Controllers
{ {
this._setting = setting; this._setting = setting;
} }
[HttpPost, Route("reports/agency_result_report/{type}")] [HttpPost, Route("reports/agency_result_report/{type}")]
[ApiExplorerSettings(GroupName = "reports")] [ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetAgencyReport([FromRoute] string type, [FromBody] List<agency_report> agencyReports) public IActionResult GetAgencyReport([FromRoute] string type, [FromBody] List<agency_report> agencyReports)
{ {
if (agencyReports == null || agencyReports.Count == 0)
{
return BadRequest("Agency reports cannot be null or empty.");
}
foreach (var agencyReport in agencyReports) foreach (var agencyReport in agencyReports)
{ {
if (agencyReport.start_date!=null && agencyReport.end_date!=null) if (agencyReport == null)
{
continue;
}
if (agencyReport.start_date != null && agencyReport.end_date != null)
{ {
agencyReport.startdate = agencyReport.start_date?.ToString("dd MMMM yyyy", agencyReport.startdate = agencyReport.start_date?.ToString("dd MMMM yyyy",
CultureInfo.CreateSpecificCulture("th-TH")) ?? ""; CultureInfo.CreateSpecificCulture("th-TH")) ?? "";
@@ -37,137 +49,81 @@ namespace rmutr_report.Controllers
CultureInfo.CreateSpecificCulture("th-TH")) ?? ""; CultureInfo.CreateSpecificCulture("th-TH")) ?? "";
} }
if (agencyReport.bool_11_1==true) agencyReport.bool_11_1_text = agencyReport.bool_11_1 == true ? "X" : "";
{ agencyReport.bool_11_2_text = agencyReport.bool_11_2 == true ? "X" : "";
agencyReport.bool_11_1_text = "X"; agencyReport.bool_11_3_text = agencyReport.bool_11_3 == true ? "X" : "";
agencyReport.text_13_1 = agencyReport.bool_13_1 == true ? "X" : "";
agencyReport.text_13_2 = agencyReport.bool_13_2 == true ? "X" : "";
agencyReport.text_13_3 = agencyReport.bool_13_3 == true ? "X" : "";
agencyReport.text_13_4 = agencyReport.bool_13_4 == true ? "X" : "";
agencyReport.text_13_5 = agencyReport.bool_13_5 == true ? "X" : "";
agencyReport.text_13_6 = agencyReport.bool_13_6 == true ? "X" : "";
agencyReport.text_13_7 = agencyReport.bool_13_7 == true ? "X" : "";
agencyReport.text_25_1 = agencyReport.bool_25_1 == true ? "X" : "";
agencyReport.text_25_2 = agencyReport.bool_25_2 == true ? "X" : "";
} }
else
if (_setting == null || string.IsNullOrEmpty(_setting.report_path))
{ {
agencyReport.bool_11_1_text = ""; return StatusCode(500, "Report settings are not configured.");
}
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 report = new Report();
try
{
report.Load(_setting.report_path + "agency_report.frx"); report.Load(_setting.report_path + "agency_report.frx");
report.RegisterData(agencyReports, "agency_report"); report.RegisterData(agencyReports, "agency_report");
report.Prepare(); report.Prepare();
}
catch (Exception ex)
{
return StatusCode(500, $"Report generation failed: {ex.Message}");
}
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
switch (type) try
{
switch (type?.ToLower())
{ {
case "pdf": case "pdf":
PDFExport pdf = new PDFExport(); PDFExport pdf = new PDFExport();
report.Export(pdf, stream); report.Export(pdf, stream);
stream.Seek(0, SeekOrigin.Begin); break;
return File(stream, "application/pdf");
case "xls": case "xls":
case "xlsx": case "xlsx":
Excel2007Export excel = new Excel2007Export(); Excel2007Export excel = new Excel2007Export();
report.Export(excel, stream); report.Export(excel, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.ms-excel");
break; break;
case "mht": case "mht":
MHTExport mht = new MHTExport(); MHTExport mht = new MHTExport();
report.Export(mht, stream); report.Export(mht, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "multipart/related");
break; break;
case "doc": case "docx":
case "doc":
case "docx":
Word2007Export word = new Word2007Export(); Word2007Export word = new Word2007Export();
report.Export(word, stream); report.Export(word, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "appllication/vnd.ms-word");
break; break;
default:
return BadRequest("Unsupported export type.");
} }
return Ok(); stream.Seek(0, SeekOrigin.Begin);
string contentType = type == "pdf" ? "application/pdf" :
type == "xls" || type == "xlsx" ? "application/vnd.ms-excel" :
type == "mht" ? "multipart/related" :
"application/vnd.ms-word";
return File(stream, contentType);
}
catch (Exception ex)
{
return StatusCode(500, $"File export failed: {ex.Message}");
}
} }
} }
} }

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyCompanyAttribute("rmutr_report")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+91cff19bff1260866d947163111eb8dd29ad5077")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9a4f0e95eaab3a2fdfc849b0360aca819504bede")]
[assembly: System.Reflection.AssemblyProductAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyProductAttribute("rmutr_report")]
[assembly: System.Reflection.AssemblyTitleAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyTitleAttribute("rmutr_report")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
0acb8f26062a50e497e3d20f8ebbaf2a2401ca261db2b8a593f3d5291aef38be e563ea69829e73d4ba56ee977869e67c6b68c3d5c86c9a065ecf6a266aae8031

View File

@@ -1 +1 @@
17376239754643386 17379510230109028