Files
rmutr_report/Controllers/project_request_thailand.Controller.cs
kamonwan taengsuk 54ecb6cf9c
All checks were successful
continuous-integration/drone/push Build is passing
bug fixed
2023-12-07 15:15:17 +07:00

438 lines
18 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Linq;
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("สำหรับรายงานคำขอโครงการ Thailand 4.0 (ง.5-2.2)")]
public class project_request_thailand : Controller
{
readonly Setting _setting;
public project_request_thailand(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/project_request_thailand/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetRequestProjectReport([FromRoute] string type,
[FromBody] project_principle_rationale project)
{
// foreach (var v in project.five)
// {
// string na = "ประเด็นยุทธศาสตร์ที่ " ;
// v.strategic_issues = na + v.strategic_issues;
// string na2 = "กลยุทธ์ที่ " ;
// v.measure = na2 + v.measure;
// }
// foreach (var v in project.eleventh)
// {
// foreach (var vv in v.elevenths)
// {
// string na = "ครั้งที่ ";
// vv.the_time = na + vv.the_time;
//
// }
// }
if (project != null)
{
if (project.activity.Any())
{
if (project.activity == null)
{
foreach (var detail in project.activity)
{
detail.activity = null;
}
}
}
else
{
project.activity.Add(new activity_data()
{
activity = ""
});
}
if (project.ninth != null)
{
foreach (var vv in project.ninth)
{
if (vv.clause == "9.1 ตัวชี้วัดผลสัมฤทธิ์")
{
vv.clause = "11.1 ตัวชี้วัดผลสัมฤทธิ์";
}
if (vv.clause == "9.2 ตัวชี้วัดเชิงนโยบาย")
{
vv.clause = "11.2 ตัวชี้วัดเชิงนโยบาย";
}
if (vv.ninths.Any())
{
if (vv.ninths == null)
{
foreach (var detail6 in vv.ninths)
{
detail6.detail = null;
}
}
}
else
{
vv.ninths.Add(new ninth_data_detail()
{
detail = ""
});
}
}
}
if (project.sixteenths != null)
{
int t = 1;
foreach (var sixteenthData in project.sixteenths)
{
string a = "กิจกรรมที่ " + t + " ";
var sum1 = sixteenthData.sixteenths2.Sum(d => d.salaya);
var sum2 = sixteenthData.sixteenths2.Sum(d => d.bophitphimuk);
var sum3 = sixteenthData.sixteenths2.Sum(d => d.pohchang);
var sum4 = sixteenthData.sixteenths2.Sum(d => d.klai_kangwon);
sixteenthData.salaya_total = sum1;
sixteenthData.bophitphimuk_total = sum2;
sixteenthData.pohchang_total = sum3;
sixteenthData.klai_kangwon_total = sum4;
if (sixteenthData.activity_table != null)
{
sixteenthData.activity_table = a + sixteenthData.activity_table;
}
if (sixteenthData.activity_table == null)
{
sixteenthData.activity_table = null;
}
if (sixteenthData.total_target != null)
{
project.text1 = "ผลรวมกลุ่มเป้าหมาย " + sixteenthData.total_target;
}
if (sixteenthData.total_target == null)
{
project.text1 = "ผลรวมกลุ่มเป้าหมาย -";
}
if (sixteenthData.total_board != null)
{
project.text2 = "ผลรวมคณะกรรมการ " + sixteenthData.total_board;
}
if (sixteenthData.total_board == null)
{
project.text2 = "ผลรวมคณะกรรมการ -";
}
t++;
}
}
if (project.seventeenth != null)
{
int t = 1;
//int ti= 1;
foreach (var v in project.seventeenth)
{
string a = "กิจกรรมที่ " + t + " ";
if (v.activity != null)
{
v.activity = a + v.activity;
}
if (v.activity == null)
{
v.activity = null;
}
t++;
foreach (var vv in v.seventeenths)
{
string na = "ครั้งที่ ";
vv.the_time = na + "1";
//ti++;
foreach (var detail in vv.seventeenths2)
{
string in1 = "พื้นที่ (ภายในมหาวิทยาลัย) ";
string in2 = "ระบุสถานที่ ";
string out1 = "จังหวัด (ภายนอกมหาวิทยาลัย) ";
if (detail.internal_external1 == "ภายในมหาวิทยาลัย")
{
detail.text1 = "ภายในมหาวิทยาลัย";
detail.area_province1 = in1 + detail.area_province1;
detail.location1 = in2 + detail.location1;
}
if (detail.internal_external2 == "ภายนอกมหาวิทยาลัย")
{
detail.text2 = "ภายนอกมหาวิทยาลัย";
detail.area_province2 = out1 + detail.area_province2;
detail.location2 = in2 + detail.location2;
}
}
}
}
}
if (project.eighteenth != null)
{
int t = 1;
//int ti = 1;
foreach (var v in project.eighteenth)
{
string a = "กิจกรรมที่ " + t + " ";
if (v.activity != null)
{
v.activity = a + v.activity;
}
if (v.activity == null)
{
v.activity = null;
}
t++;
foreach (var vv in v.eighteenths)
{
string na = "ครั้งที่ ";
vv.the_time = na + vv.the_time;
//ti++;
string na2 = " จำนวน ";
vv.count_day = na2 + vv.count_day + " วัน";
if (project.count_day != null)
{
project.text3 = "จำนวน " + project.count_day + " วัน";
}
}
}
}
if (project.nineteenth != null)
{
int t = 1;
foreach (var v in project.nineteenth)
{
foreach (var vv in v.nineteenth_data_header)
{
string a = "กิจกรรมที่ " + t + " ";
if (vv.activity != null)
{
vv.activity = a + vv.activity;
}
if (vv.activity == null)
{
vv.activity = null;
}
t++;
}
}
}
if (project.twenty_one != null)
{
int t = 1;
foreach (var v in project.twenty_one)
{
string a = "กิจกรรมที่ " + t + " ";
if (v.activity != null)
{
v.activity = a + v.activity;
}
if (v.activity == null)
{
v.activity = null;
}
t++;
foreach (var vv in v.twenty_ones)
{
if (vv.count_quantitative != null)
{
string na = " หน่วยนับ";
vv.khrang1 = na;
}
if (vv.count_unit != null)
{
string na = "ผู้เข้าร่วมโครงการ ";
string na1 = " จำนวน ";
string na2 = " คน";
vv.text1 = na;
vv.text11 = na1;
vv.nuai_nap = na2;
}
if (vv.count_project != null)
{
vv.clause1 = "23.1 เชิงปริมาณ";
string na = "จำนวนครั้งที่ดำเนินโครงการ ";
string na2 = " ครั้ง";
vv.text2 = na;
vv.khrang2 = na2;
vv.text12 = "หน่วยนับ";
}
if (vv.count_training != null)
{
string na = "จำนวนการจัดอบรมและสัมมนา ";
string na2 = " เรื่อง";
vv.text3 = na;
vv.rueang = na2;
}
if (vv.count_knowledge != null)
{
string na = "จำนวนเผยแพร่ความรู้บริการวิชาการ ";
string na2 = " ครั้ง";
vv.text4 = na;
vv.khrang3 = na2;
}
if (vv.percentage_finish != null)
{
vv.clause2 = "23.2 เชิงเวลา";
// string na3 = "วัน/เดือน/ปี ที่จะดำเนินโครงการ ";
// string na4 = " ถึง ";
// vv.range = na4;
// vv.text5 = na3;
string na5 = "โครงการแล้วเสร็จตามเวลาที่กำหนด (ร้อยละ) ";
vv.text6 = na5;
}
if (vv.percentage1 != null || vv.percentage2 != null)
{
vv.clause3 = "23.3 เชิงคุณภาพ";
string na = "ผู้เข้าร่วมโครงการมีความรู้ความเข้าใจเพิ่มขึ้น (ร้อยละ) ";
string na1 = "ความพึงพอใจของผู้เข้ารับบริการในกระบวนการให้บริการ (ร้อยละ) ";
string na2 = "โครงการที่บรรลุผลตามวัตถุประสงค์ของโครงการ (ร้อยละ) ";
vv.text7 = na;
vv.text8 = na1;
vv.text9 = "ผู้เข้าร่วมโครงการสามารถนำความรู้ที่ได้รับไปบูรณาการอย่างไรบ้าง";
vv.text10 = na2;
}
if (vv.expenses != null)
{
vv.clause4 = "23.4 เชิงค่าใช้จ่าย";
vv.bath = " บาท";
}
}
}
}
}
if (project.twenty_four != null)
{
int t = 1;
foreach (var v in project.twenty_four)
{
string a = "กิจกรรมที่ " + t + " ";
if (v.activity != null)
{
v.activity = a + v.activity;
}
if (v.activity == null)
{
v.activity = null;
}
t++;
}
}
if (project.twenty_fifth != null)
{
int t = 1;
foreach (var v in project.twenty_fifth)
{
foreach (var acti in v.activity)
{
v.activitys = acti;
}
foreach (var locat in v.location)
{
v.locations = locat;
}
string a = "กิจกรรมที่ " + t + " ";
if (v.activity_display_name != null)
{
v.activity_display_name = a + v.activity_display_name;
}
if (v.activity_display_name == null)
{
v.activity_display_name = null;
}
t++;
}
}
var _project = new List<project_principle_rationale>() { project };
Report report = new Report();
report.Load(_setting.report_path + "project_request_thailands.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");
break;
case "xls":
Excel2007Export excel = new Excel2007Export();
report.Export(excel, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.ms-excel");
break;
case "xlsx":
Excel2007Export excel1 = new Excel2007Export();
report.Export(excel1, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
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();
}
}
}