Files
rmutr_report/Controllers/RoThree.Controller.cs
kamonwan taengsuk 3756864fca update
2023-06-13 13:17:16 +07:00

399 lines
16 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();
}
[HttpPost, Route("reports/teaching_fee_extra_ro_three/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetTeachExReport([FromRoute] string type, [FromBody] teaching_fee_ro_three three)
{
var threes = new List<teaching_fee_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "teaching_fee_extra.frx");
report.RegisterData(threes, "teaching_fee_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/teaching_fee_ro_three/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetTeachReport([FromRoute] string type, [FromBody] teaching_fee_ro_three three)
{
var threes = new List<teaching_fee_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "teaching_fee.frx");
report.RegisterData(threes, "teaching_fee_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/teaching_fee_workload/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetTeachWorkloadReport([FromRoute] string type, [FromBody] teaching_fee_ro_three three)
{
var threes = new List<teaching_fee_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "teaching_fee_workload.frx");
report.RegisterData(threes, "teaching_fee_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/material_office/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetMaterial1Report([FromRoute] string type, [FromBody] material_ro_three three)
{
if (three.data != null)
{
var s = three.data.Sum(f => f.material_amount);
three.total_amount = s;
}
var threes = new List<material_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "material_office.frx");
report.RegisterData(threes, "material_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/material_computer/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetMaterial2Report([FromRoute] string type, [FromBody] material_ro_three three)
{
if (three.data != null)
{
var s = three.data.Sum(f => f.material_amount);
three.total_amount = s;
}
var threes = new List<material_ro_three>() { three };
Report report = new Report();
report.Load(_setting.report_path + "material_computer.frx");
report.RegisterData(threes, "material_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();
}
}
}