113 lines
4.1 KiB
C#
113 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using FastReport;
|
|
using FastReport.Export.OoXML;
|
|
using FastReport.Export.Pdf;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using rmutr_report.Models;
|
|
using rmutr_report.Models.Personnel;
|
|
using rmutr_report.Models.RoThree;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
namespace rmutr_report.Controllers
|
|
{
|
|
[SwaggerTag("สำหรับรายงาน ร.2 คำขอชี้แจงงบบุคลากร")]
|
|
public class RoTwo : Controller
|
|
{
|
|
readonly Setting _setting;
|
|
|
|
public RoTwo(Setting setting)
|
|
{
|
|
this._setting = setting;
|
|
}
|
|
|
|
[HttpPost, Route("reports/personnel_statement/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetRoThreeReport([FromRoute] string type,
|
|
[FromBody] personnel_statement personnel_statements)
|
|
{
|
|
int no = 1;
|
|
int no_2 = 1;
|
|
|
|
foreach (var personnelStatementDetail in personnel_statements.personnel_statement_details)
|
|
{
|
|
if (personnelStatementDetail.start_date != null)
|
|
{
|
|
personnelStatementDetail.start_dates =
|
|
personnelStatementDetail.start_date.Value.ToString("dd/MM/yyyy",
|
|
CultureInfo.CreateSpecificCulture("th-TH"));
|
|
}
|
|
else
|
|
{
|
|
personnelStatementDetail.start_dates = "";
|
|
}
|
|
|
|
if (personnelStatementDetail.topic_type == 2)
|
|
{
|
|
personnelStatementDetail.row_no = no;
|
|
no++;
|
|
}
|
|
}
|
|
|
|
foreach (var personnelStatementDetail2 in personnel_statements.personnel_statement_details_2)
|
|
{
|
|
if (personnelStatementDetail2.start_date != null)
|
|
{
|
|
personnelStatementDetail2.start_dates =
|
|
personnelStatementDetail2.start_date.Value.ToString("dd/MM/yyyy",
|
|
CultureInfo.CreateSpecificCulture("th-TH"));
|
|
}
|
|
else
|
|
{
|
|
personnelStatementDetail2.start_dates = "";
|
|
}
|
|
|
|
if (personnelStatementDetail2.topic_type == 2)
|
|
{
|
|
personnelStatementDetail2.row_no = no_2;
|
|
no_2++;
|
|
}
|
|
}
|
|
|
|
var personnelstatements = new List<personnel_statement>() { personnel_statements };
|
|
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "personnel_statement.frx");
|
|
report.RegisterData(personnelstatements, "personnel_statement");
|
|
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",
|
|
"personnel_statement_" + 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();
|
|
}
|
|
}
|
|
} |