Files
rmutr_report/Controllers/project_principle_rationale.Controller.cs
kamonwan taengsuk 60836ddc96 add ง5
2023-02-17 22:40:08 +07:00

137 lines
5.6 KiB
C#

using System.Collections.Generic;
using System.IO;
using ClosedXML.Excel;
using FastReport;
using FastReport.Export.Csv;
using FastReport.Export.Mht;
using FastReport.Export.OoXML;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Mvc;
using rmutr_report.Models;
using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers
{
[SwaggerTag("สำหรับรายงาน ง.5")]
public class ProjectPrincipleRationale: Controller
{
readonly Setting _setting;
public ProjectPrincipleRationale(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/project_principle_rationale/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetProjectReport([FromRoute] string type, [FromBody] project_principle_rationale project)
{
var total = project.activity.Count;
var total2 = project.sixteenth.Count;
foreach (var v in project.activity)
{
if (v.activity != null)
{
//var total = project.activity.Select(r => r.count).Sum(t => t.Value);
project.together_with = "ประกอบด้วยกิจกรรมหรือโครงการย่อย " + total +" โครงการดังนี้คือ";
}
else
{
project.together_with = null;
}
}
foreach (var v in project.eighth)
{
string na = "ประเด็นยุทธศาสตร์ที่ " ;
v.strategic_issues = na + v.strategic_issues;
string na2 = "มาตรการที่ " ;
v.measure = na2 + v.measure;
}
foreach (var v in project.fourteenth)
{
string na = "องค์ประกอบที่ " ;
v.component = na + v.component;
string na2 = "ตัวบ่งชี้ที่ " ;
v.indicator = na2 + v.indicator;
}
project.count_activity = total2;
foreach (var v in project.eighteenth)
{
foreach (var vv in v.eighteenths)
{
string na = "ครั้งที่ ";
vv.the_time = na + vv.the_time;
string na2 = " จำนวน ";
vv.count_day = na2 + vv.count_day + " วัน";
}
}
// foreach (var a in project.seventeenth)
// {
// foreach (var aa in a.seventeenths)
// {
// foreach (var a2 in aa.seventeenths2)
// {
// if (aa.type == "1")
// {
// a2.internal_external = "ภายในมหาวิทยาลัย";
// a2.area_province = "พื้นที่" + a2.area_province;
// a2.location = "ระบุสถานที่" + a2.location;
// }
// if (aa.type == "2")
// {
// a2.internal_external = "ภายนอกมหาวิทยาลัย";
// a2.area_province = "จังหวัด" + a2.area_province;
// a2.location = "ระบุสถานที่" + a2.location;
// }
// if (aa.type == "3")
// {
// a2.internal_external = "ภายนอกมหาวิทยาลัย";
// a2.area_province = "จังหวัด" + a2.area_province;
// a2.location = "ระบุสถานที่" + a2.location;
// }
// }
// }
// }
var _project = new List<project_principle_rationale>() {project};
Report report = new Report();
report.Load(_setting.report_path + "project_principle_rationale.frx");
report.RegisterData(_project, "project_principle_rationale");
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");
break;
case "mht":
MHTExport mht = new MHTExport();
report.Export(mht, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "multipart/related");
break;
case "csv":
CSVExport csv = new CSVExport();
report.Export(csv, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "text/csv");
break;
}
return Ok();
}
}
}