This commit is contained in:
@@ -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" : "";
|
||||||
}
|
|
||||||
else
|
agencyReport.text_13_1 = agencyReport.bool_13_1 == true ? "X" : "";
|
||||||
{
|
agencyReport.text_13_2 = agencyReport.bool_13_2 == true ? "X" : "";
|
||||||
agencyReport.bool_11_1_text = "";
|
agencyReport.text_13_3 = agencyReport.bool_13_3 == true ? "X" : "";
|
||||||
}
|
agencyReport.text_13_4 = agencyReport.bool_13_4 == true ? "X" : "";
|
||||||
if (agencyReport.bool_11_2==true)
|
agencyReport.text_13_5 = agencyReport.bool_13_5 == true ? "X" : "";
|
||||||
{
|
agencyReport.text_13_6 = agencyReport.bool_13_6 == true ? "X" : "";
|
||||||
agencyReport.bool_11_2_text = "X";
|
agencyReport.text_13_7 = agencyReport.bool_13_7 == true ? "X" : "";
|
||||||
}
|
|
||||||
else
|
agencyReport.text_25_1 = agencyReport.bool_25_1 == true ? "X" : "";
|
||||||
{
|
agencyReport.text_25_2 = agencyReport.bool_25_2 == true ? "X" : "";
|
||||||
agencyReport.bool_11_2_text = "";
|
}
|
||||||
}
|
|
||||||
if (agencyReport.bool_11_3==true)
|
if (_setting == null || string.IsNullOrEmpty(_setting.report_path))
|
||||||
{
|
{
|
||||||
agencyReport.bool_11_3_text = "X";
|
return StatusCode(500, "Report settings are not configured.");
|
||||||
}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();
|
||||||
report.Load(_setting.report_path + "agency_report.frx");
|
try
|
||||||
report.RegisterData(agencyReports, "agency_report");
|
|
||||||
report.Prepare();
|
|
||||||
|
|
||||||
MemoryStream stream = new MemoryStream();
|
|
||||||
switch (type)
|
|
||||||
{
|
{
|
||||||
case "pdf":
|
report.Load(_setting.report_path + "agency_report.frx");
|
||||||
PDFExport pdf = new PDFExport();
|
report.RegisterData(agencyReports, "agency_report");
|
||||||
report.Export(pdf, stream);
|
report.Prepare();
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
}
|
||||||
return File(stream, "application/pdf");
|
catch (Exception ex)
|
||||||
|
{
|
||||||
case "xls":
|
return StatusCode(500, $"Report generation failed: {ex.Message}");
|
||||||
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();
|
MemoryStream stream = new MemoryStream();
|
||||||
}
|
try
|
||||||
|
{
|
||||||
|
switch (type?.ToLower())
|
||||||
|
{
|
||||||
|
case "pdf":
|
||||||
|
PDFExport pdf = new PDFExport();
|
||||||
|
report.Export(pdf, stream);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "xls":
|
||||||
|
case "xlsx":
|
||||||
|
Excel2007Export excel = new Excel2007Export();
|
||||||
|
report.Export(excel, stream);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "mht":
|
||||||
|
MHTExport mht = new MHTExport();
|
||||||
|
report.Export(mht, stream);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "doc":
|
||||||
|
case "docx":
|
||||||
|
Word2007Export word = new Word2007Export();
|
||||||
|
report.Export(word, stream);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return BadRequest("Unsupported export type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0acb8f26062a50e497e3d20f8ebbaf2a2401ca261db2b8a593f3d5291aef38be
|
e563ea69829e73d4ba56ee977869e67c6b68c3d5c86c9a065ecf6a266aae8031
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
17376239754643386
|
17379510230109028
|
||||||
Reference in New Issue
Block a user