add graph report
This commit is contained in:
186
Controllers/Graph.Controller.cs
Normal file
186
Controllers/Graph.Controller.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FastReport;
|
||||
using FastReport.Export.Csv;
|
||||
using FastReport.Export.Mht;
|
||||
using FastReport.Export.OoXML;
|
||||
using FastReport.Export.Pdf;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using rmutr_report.Models;
|
||||
using rmutr_report.Models.Graph;
|
||||
using rmutr_report.Models.Hr;
|
||||
using rmutr_report.Models.HrDevelopment;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace rmutr_report.Controllers
|
||||
{
|
||||
[SwaggerTag("สำหรับรายงานแบบกราฟ งานพัฒนา")]
|
||||
public class Graph: Controller
|
||||
{
|
||||
readonly Setting _setting;
|
||||
|
||||
public Graph(Setting setting)
|
||||
{
|
||||
this._setting = setting;
|
||||
}
|
||||
|
||||
[HttpPost, Route("graph/passer_join_project_graph/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "graph")]
|
||||
public IActionResult GetSum1Report([FromRoute] string type, [FromBody] List<passer_join_project_graph> reports)
|
||||
{
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "passer_join_project_graph_year.frx");
|
||||
report.RegisterData(reports, "passer_join_project_graph");
|
||||
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":
|
||||
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();
|
||||
}
|
||||
[HttpPost, Route("graph/train_graph/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "graph")]
|
||||
public IActionResult GetSum2Report([FromRoute] string type, [FromBody] List<train_graph> graph)
|
||||
{
|
||||
|
||||
//var graph = new List<passer_join_project_agency_graph>() {reports};
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "train_graph.frx");
|
||||
report.RegisterData(graph, "train_graph");
|
||||
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":
|
||||
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();
|
||||
}
|
||||
// [HttpPost, Route("graph/passer_join_project_person_graph/{type}")]
|
||||
// [ApiExplorerSettings(GroupName = "graph")]
|
||||
// public IActionResult GetSum3Report([FromRoute] string type, [FromBody] List<passer_join_project_agency_graph> graph)
|
||||
// {
|
||||
// var a = graph.ToArray();
|
||||
// foreach (var v in a)
|
||||
// {
|
||||
// foreach (var vv in v.data)
|
||||
// {
|
||||
// if (vv.pertype != null)
|
||||
// {
|
||||
// v.pertype = vv.pertype;
|
||||
// v.count_person_pertype = vv.data_detail.Select(g => g.display_name_th).Count();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// foreach (var detail in vv.data_detail)
|
||||
// {
|
||||
// if (detail.quantity_project != null)
|
||||
// {
|
||||
// v.quantity_project = detail.quantity_project;
|
||||
// }
|
||||
// if (detail.registration_fee != null)
|
||||
// {
|
||||
// v.registration_fee = detail.registration_fee;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// //var graph = new List<passer_join_project_agency_graph>() {reports};
|
||||
// Report report = new Report();
|
||||
// report.Load(_setting.report_path + "passer_join_project_person_graph.frx");
|
||||
// report.RegisterData(graph, "passer_join_project_agency_graph");
|
||||
// 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":
|
||||
// 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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user