Files
rmutr_report/Controllers/RoThree.Controller.cs
kamonwan taengsuk 7d5a2fdfc3 update
2023-06-12 19:14:33 +07:00

172 lines
6.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ClosedXML;
using FastReport;
using FastReport.Export.OoXML;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Mvc;
using rmutr_report.Models;
using rmutr_report.Models.RoThree;
using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers
{
[SwaggerTag("สำหรับรายงาน ร.3 คำชี้แจงงบดำเนินงาน")]
public class RoThree : Controller
{
readonly Setting _setting;
public RoThree(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/operating_budget_ro_three/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetRoThreeReport([FromRoute] string type, [FromBody] operating_budget_ro_three three)
{
var threes = new List<operating_budget_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "operating_budget_ro_three.frx");
report.RegisterData(threes, "operating_budget_ro_three");
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",
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();
}
[HttpPost, Route("reports/compensation_head_department/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetComReport([FromRoute] string type, [FromBody] compensation_head three)
{
if (three.data!=null)
{
var s = three.data.Sum(f => f.budget_amount);
three.total_amount = s;
}
var threes = new List<compensation_head>() { three };
Report report = new Report();
report.Load(_setting.report_path + "compensation_head_department.frx");
report.RegisterData(threes, "compensation_head");
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",
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();
}
[HttpPost, Route("reports/compensation_head_major/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetCom2Report([FromRoute] string type, [FromBody] compensation_head three)
{
if (three.data!=null)
{
var s = three.data.Sum(f => f.budget_amount);
three.total_amount = s;
}
var threes = new List<compensation_head>() { three };
Report report = new Report();
report.Load(_setting.report_path + "compensation_head_major.frx");
report.RegisterData(threes, "compensation_head");
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",
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();
}
}
}