firts commit
This commit is contained in:
168
REPORT_API_ver6/Controllers/ExportAPI.cs
Normal file
168
REPORT_API_ver6/Controllers/ExportAPI.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using REPORT_API_ver6.Services;
|
||||
using REPORT_API_ver6.Models;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Data;
|
||||
|
||||
namespace REPORT_API_ver6.Controllers
|
||||
{
|
||||
[Route("api/v1/export")]
|
||||
[ApiController]
|
||||
public class ExportAPI : ControllerBase
|
||||
{
|
||||
[Route("excel/table")]
|
||||
[HttpPost]
|
||||
[DisableRequestSizeLimit]
|
||||
public IActionResult ExportExcelTable([FromHeader] string token, [FromBody] ExportExcelParam excelParam)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null && String.IsNullOrEmpty(excelParam.ExportTable) == false && excelParam.ExportTable != "[]")
|
||||
{
|
||||
MakeExcel makeExcel = new MakeExcel();
|
||||
string fileName = token + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
string fileType = "application/vnd.ms-excel";
|
||||
|
||||
byte[] excelFile = makeExcel.getTableExcel(excelParam.ExportTable, excelParam.Turn);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
return File(excelFile, fileType, fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("excel/quota")]
|
||||
[HttpPost]
|
||||
[DisableRequestSizeLimit]
|
||||
public IActionResult ExportExcelQuota([FromHeader] string token, [FromBody] ExportExcelParam excelParam)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null && String.IsNullOrEmpty(excelParam.ExportTable) == false && excelParam.ExportTable != "[]")
|
||||
{
|
||||
MakeExcel makeExcel = new MakeExcel();
|
||||
string fileName = token + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
string fileType = "application/vnd.ms-excel";
|
||||
|
||||
byte[] excelFile = makeExcel.getQuotaExcel(excelParam.ExportTable);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
return File(excelFile, fileType, fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("form/data")]
|
||||
[HttpGet]
|
||||
public IActionResult ExportDataForm([FromHeader] string token, [FromHeader] string skey)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null)
|
||||
{
|
||||
Project project = new Project();
|
||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||
|
||||
DataTable headerTable = project.getExportHeader(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
||||
DataTable exportTable = project.makeExportTable(headerTable);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
string fileName = "[Header]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
byte[] fileByteArray = Common.DataTableToExcel(exportTable);
|
||||
return File(fileByteArray, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("form/question")]
|
||||
[HttpGet]
|
||||
public IActionResult ExportQuestionForm([FromHeader] string token)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null)
|
||||
{
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
byte[] fileByteArray = System.IO.File.ReadAllBytes(Common.MapPath("file_forms/KON 문항 등록 양식.xlsx"));
|
||||
return File(fileByteArray, "application/octet-stream", "KON 문항 등록 양식.xlsx");
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("form/title")]
|
||||
[HttpGet]
|
||||
[DisableRequestSizeLimit]
|
||||
public IActionResult ExportTitleForm([FromHeader] string token, [FromHeader] string skey)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null)
|
||||
{
|
||||
Project project = new Project();
|
||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||
|
||||
DataTable titleTable = project.getExportExplain(pkeyInfo.Pkey, pkeyInfo.isKiwi);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
string fileName = "[Explain]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
byte[] fileByteArray = Common.DataTableToExcel(titleTable);
|
||||
return File(fileByteArray, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("data")]
|
||||
[HttpGet]
|
||||
public IActionResult ExportData([FromHeader] string token, [FromHeader] string skey, [FromHeader] string type)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
|
||||
if (userInfo != null)
|
||||
{
|
||||
Project project = new Project();
|
||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||
|
||||
DataTable headerTable = project.getExportHeader(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
||||
DataTable bodyTable = project.getProjectData(pkeyInfo.Pkey, "", "", "", "", pkeyInfo.isKiwi, 1,"", "", type);
|
||||
DataTable exportTable = project.makeExportTable(headerTable, bodyTable);
|
||||
|
||||
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
byte[] fileByteArray = Common.DataTableToExcel(exportTable);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
return File(fileByteArray, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
|
||||
[Route("guide")]
|
||||
[HttpGet]
|
||||
public IActionResult ExportGuide([FromHeader] string token, [FromHeader] string skey)
|
||||
{
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null)
|
||||
{
|
||||
Project project = new Project();
|
||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||
DataTable guideTable = project.makeGuideTable(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
||||
|
||||
string fileName = "[GUIDE]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||
byte[] fileByteArray = Common.DataTableToExcel(guideTable);
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
return File(fileByteArray, "application/octet-stream", fileName);
|
||||
}
|
||||
|
||||
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return Content(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user