659 lines
35 KiB
C#
659 lines
35 KiB
C#
using BMA.EHR.Profile.Service.Controllers;
|
||
using BMA.EHR.Report.Service.Data;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using Swashbuckle.AspNetCore.Annotations;
|
||
using Telerik.Reporting.Processing;
|
||
using Telerik.Reporting;
|
||
using BMA.EHR.Report.Service.Responses;
|
||
using BMA.EHR.Organization.Service.Extensions;
|
||
// using BMA.EHR.Core;
|
||
using System.Text;
|
||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||
using System.Net.Http.Headers;
|
||
using Newtonsoft.Json;
|
||
|
||
namespace BMA.EHR.Report.Service.Controllers
|
||
{
|
||
[Route("api/v{version:apiVersion}/report/exam")]
|
||
[ApiVersion("1.0")]
|
||
[ApiController]
|
||
[Produces("application/json")]
|
||
[Authorize]
|
||
[SwaggerTag("รายงานข้อมูลการสอบคัดเลือก")]
|
||
public class ExamReportController : BaseController
|
||
{
|
||
#region " Fields "
|
||
|
||
private readonly ExamDbContext _context;
|
||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||
private readonly IConfiguration _configuration;
|
||
private readonly string space = "ㅤ";
|
||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||
|
||
#endregion
|
||
|
||
#region " Constructor and Destructor "
|
||
|
||
public ExamReportController(ExamDbContext context,
|
||
IWebHostEnvironment hostingEnvironment,
|
||
IHttpContextAccessor httpContextAccessor,
|
||
IConfiguration configuration)
|
||
{
|
||
this._context = context;
|
||
this._hostingEnvironment = hostingEnvironment;
|
||
this._configuration = configuration;
|
||
this._httpContextAccessor = httpContextAccessor;
|
||
}
|
||
|
||
private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
|
||
#endregion
|
||
|
||
#region " Methods "
|
||
|
||
#region " Privates "
|
||
|
||
private int GetExamCountTes(string citizenId)
|
||
{
|
||
try
|
||
{
|
||
var count = _context.Candidates.AsQueryable()
|
||
.Where(x => x.CitizenId == citizenId)
|
||
.Count();
|
||
|
||
return count;
|
||
}
|
||
catch
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
private string ToThaiNumber(string? value)
|
||
{
|
||
if (value == null)
|
||
return "";
|
||
string arabicNumbers = "0123456789";
|
||
string thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||
StringBuilder result = new StringBuilder();
|
||
foreach (char digit in value)
|
||
{
|
||
int index = arabicNumbers.IndexOf(digit);
|
||
if (index >= 0)
|
||
{
|
||
result.Append(thaiNumbers[index]);
|
||
}
|
||
else
|
||
{
|
||
result.Append(digit);
|
||
}
|
||
}
|
||
return result.ToString();
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// แสดงหนังสือรับรอง
|
||
/// </summary>
|
||
/// <param name="id">รหัสรอบการสอบ</param>
|
||
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
||
/// <param name="type">ชนิดของรายงาน</param>
|
||
/// <returns></returns>
|
||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||
|
||
[HttpGet("certificate/{type:int}/{id:length(36)}/{examId}")]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
public async Task<ActionResult<ResponseObject>> GetCertificateReportAsync(Guid id, string examId, int type)
|
||
{
|
||
try
|
||
{
|
||
var _data = await _context.Disables.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.Where(x => x.PeriodExam.Id == id)
|
||
.Where(x => x.ExamId == examId)
|
||
.FirstOrDefaultAsync();
|
||
if (_data == null)
|
||
return Error("ไม่พบข้อมูลในระบบ");
|
||
|
||
// if (_data.AuthName == null || _data.AuthName == "")
|
||
// {
|
||
// var apiUrl = $"{_configuration["API"]}/org/find/head/officer";
|
||
// using (var client = new HttpClient())
|
||
// {
|
||
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||
// client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||
// var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||
// var _res = await client.SendAsync(_req);
|
||
// var _result = await _res.Content.ReadAsStringAsync();
|
||
// if (_res.IsSuccessStatusCode)
|
||
// {
|
||
// var org = JsonConvert.DeserializeObject<dynamic>(_result);
|
||
// _data.AuthName = org.result.name == null ? "" : org.result.name;
|
||
// _data.AuthPosition = org.result.position == null ? "" : org.result.position;
|
||
// await _context.SaveChangesAsync();
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
var data = await _context.Disables.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.Where(x => x.PeriodExam.Id == id)
|
||
.Where(x => x.ExamId == examId)
|
||
.Join(_context.DisableScores.AsQueryable()
|
||
.Include(x => x.ScoreImport),
|
||
rc => new { rc.PeriodExam.Year, rc.ExamId },
|
||
sc => new { sc.ScoreImport.Year, sc.ExamId },
|
||
(p, sr) => new
|
||
{
|
||
ExamID = p.ExamId,
|
||
CitizenId = p.CitizenId == null ? "-" : (p.CitizenId),
|
||
Order = (p.PeriodExam.Round.ToString()),
|
||
Year = (p.PeriodExam.Year.Value.ToThaiYear().ToString()),
|
||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||
EndDate = p.PeriodExam.RegisterEndDate == null ? "" : (p.PeriodExam.RegisterEndDate.Value.ToThaiFullDate3()),
|
||
AuthName = p.PeriodExam.AuthName,
|
||
AuthPosition = p.PeriodExam.AuthPosition
|
||
})
|
||
.FirstOrDefaultAsync();
|
||
|
||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCertificate{type}.trdp");
|
||
|
||
ReportPackager reportPackager = new ReportPackager();
|
||
Telerik.Reporting.Report? report = null;
|
||
using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
{
|
||
report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
}
|
||
|
||
report.DataSource = data;
|
||
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
{
|
||
ReportDocument = report
|
||
};
|
||
|
||
|
||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
var content = result.DocumentBytes;
|
||
return File(content, "application/pdf", $"หนังสือรับรอง_{data.CitizenId}_{data.FullName}.pdf");
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// แสดงเอกสารผลสอบ
|
||
/// </summary>
|
||
/// <param name="id">รหัสรอบการสอบ</param>
|
||
/// <param name="examId">เลขประจำตัวผู้สมัครสอบ</param>
|
||
/// <returns></returns>
|
||
/// <response code="200">เมื่อแสดงรายงานสำเร็จ</response>
|
||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||
[HttpGet("score/{id:length(36)}/{examId}")]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
public async Task<ActionResult<ResponseObject>> GetScoreReportAsync(Guid id, string examId)
|
||
{
|
||
try
|
||
{
|
||
var data = await _context.Disables.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.Include(x => x.Documents)
|
||
.ThenInclude(x => x.DocumentFile)
|
||
.Where(x => x.PeriodExam.Id == id)
|
||
.Where(x => x.ExamId == examId)
|
||
.Join(_context.DisableScores.AsQueryable()
|
||
.Include(x => x.ScoreImport),
|
||
rc => new { rc.PeriodExam.Year, rc.ExamId },
|
||
sc => new { sc.ScoreImport.Year, sc.ExamId },
|
||
(p, sr) => new
|
||
{
|
||
ExamId = p.ExamId,
|
||
CitizenId = p.CitizenId == null ? "-" : (p.CitizenId),
|
||
p.Prefix,
|
||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||
DateOfBirth = (p.DateOfBirth.ToThaiShortDate()),
|
||
Gender = p.Gendor,
|
||
Degree = p.Educations.First().Degree,
|
||
Major = p.Educations.First().Major,
|
||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||
University = p.Educations.First().University,
|
||
PositionName = p.PositionName,
|
||
ExamName = ($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}"),
|
||
Number = sr == null ? "" : (sr.Number),
|
||
// ExamCount = 10,
|
||
// ExamCount = GetExamCountTes(p.CitizenId),
|
||
ScoreExpire = p.PeriodExam.AnnouncementDate == null ? "" : (p.PeriodExam.AnnouncementDate.Value.AddYears(2).ToThaiShortDate()),
|
||
FullA = sr == null ? "๐" : (sr.FullA.ToString()),
|
||
SumA = sr == null ? "๐" : (sr.SumA.ToString()),
|
||
FullB = sr == null ? "๐" : (sr.FullB.ToString()),
|
||
SumB = sr == null ? "๐" : (sr.SumB.ToString()),
|
||
FullC = sr == null ? "๐" : (sr.FullC.ToString()),
|
||
SumC = sr == null ? "๐" : (sr.SumC.ToString()),
|
||
})
|
||
.FirstOrDefaultAsync();
|
||
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptExamResult.trdp");
|
||
ReportPackager reportPackager = new ReportPackager();
|
||
Telerik.Reporting.Report? report = null;
|
||
using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
{
|
||
report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
}
|
||
|
||
report.DataSource = data;
|
||
if (data != null)
|
||
{
|
||
var _data = new
|
||
{
|
||
ExamId = data.ExamId,
|
||
CitizenId = data.CitizenId,
|
||
Prefix = data.Prefix,
|
||
FullName = data.FullName,
|
||
DateOfBirth = data.DateOfBirth,
|
||
Gender = data.Gender,
|
||
Degree = data.Degree,
|
||
Major = data.Major,
|
||
ExamResult = data.ExamResult,
|
||
University = data.University,
|
||
PositionName = data.PositionName,
|
||
ExamName = data.ExamName,
|
||
Number = data.Number,
|
||
ExamCount = GetExamCountTes(data.CitizenId),
|
||
ScoreExpire = data.ScoreExpire,
|
||
FullA = data.FullA,
|
||
SumA = data.SumA,
|
||
FullB = data.FullB,
|
||
SumB = data.SumB,
|
||
FullC = data.FullC,
|
||
SumC = data.SumC,
|
||
};
|
||
report.DataSource = _data;
|
||
}
|
||
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
{
|
||
ReportDocument = report
|
||
};
|
||
|
||
|
||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
var content = result.DocumentBytes;
|
||
return File(content, "application/pdf", $"ผลคะแนนสอบ_{data.CitizenId}_{data.FullName}.pdf");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน");
|
||
}
|
||
}
|
||
|
||
[HttpGet("candidate/{id:length(36)}")]
|
||
[AllowAnonymous]
|
||
public async Task<ActionResult<ResponseObject>> GetCandidateListReportAsync(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var data = await _context.Disables.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.Where(x => x.PeriodExam.Id == id)
|
||
.OrderBy(x => x.ExamId)
|
||
.Select(p => new
|
||
{
|
||
ExamId = p.ExamId == null ? string.Empty : (p.ExamId).ToThaiNumber(),
|
||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||
PositionName = p.PositionName,
|
||
ExamName =
|
||
($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}"),
|
||
}).ToListAsync();
|
||
|
||
if (data.Count == 0) return Error("ไม่พบข้อมูลในระบบ");
|
||
|
||
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.trdp");
|
||
//ReportPackager reportPackager = new ReportPackager();
|
||
//Telerik.Reporting.Report report = null;
|
||
//using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
//{
|
||
// report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
//}
|
||
|
||
////report.DataSource = data;
|
||
//report.ReportParameters["ExamName"].Value = data[0].ExamName.ToThaiNumber();
|
||
//var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
|
||
//tbl.DataSource = data;
|
||
//System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
//InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
//{
|
||
// ReportDocument = report
|
||
//};
|
||
|
||
|
||
//ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
//RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
//var content = result.DocumentBytes;
|
||
//return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf");
|
||
var examName = data[0].ExamName;
|
||
var _data = new
|
||
{
|
||
template = "rptCandidateList",
|
||
reportName = $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}",
|
||
data = new
|
||
{
|
||
examName = examName,
|
||
data = data
|
||
}
|
||
};
|
||
return Success(_data);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
[HttpGet("candidate-exam/{id:length(36)}")]
|
||
[AllowAnonymous]
|
||
public async Task<ActionResult<ResponseObject>> GetCandidateExamListReportAsync(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var periodExam = await _context.PeriodExams.AsQueryable().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||
var data = await _context.Candidates.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.Where(x => x.PeriodExam == periodExam)
|
||
.Where(x => x.Status != "register")
|
||
.Where(x => x.ExamIdenNumber != null || x.ExamIdenNumber != "")
|
||
.OrderBy(x => x.ExamIdenNumber)
|
||
.Select(p => new
|
||
{
|
||
ExamId = p.ExamIdenNumber == null ? null : (p.ExamIdenNumber.ToThaiNumber()),
|
||
FullName = $"{p.PrefixName}{p.FirstName} {p.LastName}",
|
||
PositionName = "",
|
||
ExamName =
|
||
($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}").ToThaiNumber(),
|
||
}).ToListAsync();
|
||
|
||
if (data.Count == 0)
|
||
return Error("ไม่พบข้อมูลในระบบ");
|
||
|
||
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptCandidateList.trdp");
|
||
//ReportPackager reportPackager = new ReportPackager();
|
||
//Telerik.Reporting.Report report = null;
|
||
//using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
//{
|
||
// report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
//}
|
||
//report.ReportParameters["ExamName"].Value = data[0].ExamName;
|
||
//report.DataSource = data[0];
|
||
//var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
|
||
//table.DataSource = data;
|
||
//System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
//InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
//{
|
||
// ReportDocument = report
|
||
//};
|
||
|
||
|
||
//ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
//RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
//var content = result.DocumentBytes;
|
||
//return File(content, "application/pdf", $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}.pdf");
|
||
var examName = data[0].ExamName;
|
||
var _data = new
|
||
{
|
||
template = "rptCandidateList",
|
||
reportName = $"รายชื่อผู้มีสิทธิ์สอบ_{data.First().ExamName}",
|
||
data = new
|
||
{
|
||
examName = examName,
|
||
data = data
|
||
}
|
||
};
|
||
return Success(_data);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex);
|
||
}
|
||
}
|
||
|
||
[HttpGet("pass/{id:length(36)}")]
|
||
[AllowAnonymous]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
public async Task<ActionResult<ResponseObject>> GetPassExamListReportAsync(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var data = await _context.Disables.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.ThenInclude(x => x.ScoreImport)
|
||
.Include(x => x.Documents)
|
||
.ThenInclude(x => x.DocumentFile)
|
||
.Join(_context.DisableScores.AsQueryable()
|
||
.Include(x => x.ScoreImport)
|
||
.Where(x => x.ScoreImport.PeriodExamId == id)
|
||
.Where(x => x.ExamStatus == "ผ่าน"),
|
||
rc => new { id = rc.PeriodExam.Id, examId = rc.ExamId },
|
||
sc => new { id = sc.ScoreImport.PeriodExamId, examId = sc.ExamId },
|
||
(p, sr) => new
|
||
{
|
||
Id = p.PeriodExam.Id,
|
||
ExamId = p.ExamId != null ? p.ExamId.ToThaiNumber() : string.Empty,
|
||
//CitizenId = p.CitizenId == null ? "-" : (p.CitizenId).ToThaiNumber(),
|
||
//p.Prefix,
|
||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||
//DateOfBirth = (p.DateOfBirth.ToThaiShortDate()),
|
||
//Gender = p.Gendor,
|
||
//Degree = p.Educations.First().Degree,
|
||
//Major = p.Educations.First().Major,
|
||
ExamResult = sr == null ? "" : sr.ExamStatus,
|
||
//University = p.Educations.First().University,
|
||
//PositionName = p.PositionName,
|
||
ExamName = $"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round.ToString().ToThaiNumber()}/{p.PeriodExam.Year.Value.ToThaiYear().ToString().ToThaiNumber()}",
|
||
Number = sr == null || sr.Number == null ? 0 : Convert.ToInt32(sr.Number),
|
||
//FullA = sr == null ? "๐" : (sr.FullA.ToString()),
|
||
//SumA = sr == null ? "๐" : (sr.SumA.ToString()),
|
||
//FullB = sr == null ? "๐" : (sr.FullB.ToString()),
|
||
//SumB = sr == null ? "๐" : (sr.SumB.ToString()),
|
||
//FullC = sr == null ? "๐" : (sr.FullC.ToString()),
|
||
//SumC = sr == null ? "๐" : (sr.SumC.ToString()),
|
||
SumScore = sr == null
|
||
? "๐"
|
||
: (((sr.SumA > 0 ? sr.SumA : 0) + (sr.SumB > 0 ? sr.SumB : 0) + (sr.SumC > 0 ? sr.SumC : 0)).ToString()).ToThaiNumber(),
|
||
})
|
||
.OrderBy(x => x.Number)
|
||
.Where(x => x.Id == id)
|
||
.Where(x => x.ExamResult == "ผ่าน")
|
||
.ToListAsync();
|
||
|
||
if (data.Count == 0)
|
||
return Error("ไม่พบข้อมูลในระบบ");
|
||
|
||
var data_ = data.Select(x => new
|
||
{
|
||
x.ExamName,
|
||
Number = x.Number.ToString().ToThaiNumber(),
|
||
x.ExamId,
|
||
x.FullName,
|
||
x.SumScore
|
||
}).ToList();
|
||
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.trdp");
|
||
//ReportPackager reportPackager = new ReportPackager();
|
||
//Telerik.Reporting.Report report = null;
|
||
//using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
//{
|
||
// report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
//}
|
||
|
||
////report.DataSource = data;
|
||
//report.ReportParameters["ExamName"].Value = data_[0].ExamName.ToThaiNumber();
|
||
//var tbl = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
|
||
//tbl.DataSource = data_;
|
||
//System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
//InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
//{
|
||
// ReportDocument = report
|
||
//};
|
||
|
||
|
||
//ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
//RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
//var content = result.DocumentBytes;
|
||
//return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}.pdf");
|
||
var examName = data[0].ExamName;
|
||
var _data = new
|
||
{
|
||
template = "rptPassExamList",
|
||
reportName = $"รายชื่อผู้สอบแข่งขันได้_{data.First().ExamName}",
|
||
data = new
|
||
{
|
||
examName = examName,
|
||
data = data_
|
||
}
|
||
};
|
||
return Success(_data);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน");
|
||
}
|
||
}
|
||
|
||
[HttpGet("pass-exam/{id:length(36)}")]
|
||
[AllowAnonymous]
|
||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||
public async Task<ActionResult<ResponseObject>> GetPassExam2ListReportAsync(Guid id)
|
||
{
|
||
try
|
||
{
|
||
var periodExam = await _context.PeriodExams.AsQueryable().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||
var candidates = await _context.Candidates.AsQueryable()
|
||
.Include(x => x.PeriodExam)
|
||
.ThenInclude(x => x.ScoreImport)
|
||
.Where(x => x.PeriodExam == periodExam)
|
||
.Where(x => x.Status != "register")
|
||
//.Select((p, idx) => new
|
||
//{
|
||
// ExamId = p.SeatNumber == null ? "-" : (p.SeatNumber.ToThaiNumber()),
|
||
// CitizenId = p.CitizenId == null ? "-" : (p.CitizenId.ToThaiNumber()),
|
||
// FullName = $"{p.FirstName} {p.LastName}",
|
||
// DateOfBirth = p.DateOfBirth == null ? "-" : (p.DateOfBirth.Value.ToThaiShortDate()),
|
||
// ExamName = ($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}").ToThaiNumber(),
|
||
// Number = p.Number == null ? 99999 : Convert.ToInt32(p.Number),
|
||
// FullA = ("๐"),
|
||
// SumA = ("๐"),
|
||
// FullB = p.PointTotalB == null ? "-" : (p.PointTotalB.ToString()),
|
||
// SumB = p.PointB == null ? "-" : (p.PointB.ToString()),
|
||
// FullC = p.PointTotalC == null ? "-" : (p.PointTotalC.ToString()),
|
||
// SumC = p.PointC == null ? "-" : (p.PointC.ToString()),
|
||
// SumScore = ((Convert.ToInt32(p.PointB ?? "0") + Convert.ToInt32(p.PointC ?? "0")).ToString()).ToThaiNumber(),
|
||
// ExamResult = p.Pass
|
||
//})
|
||
//.OrderBy(x => x.Number)
|
||
//.Where(x => x.ExamResult == "ได้")
|
||
.ToListAsync();
|
||
|
||
var data = candidates.Select((p, idx) => new
|
||
{
|
||
SeatNumber = p.SeatNumber == null ? "-" : (p.SeatNumber.ToThaiNumber()),
|
||
CitizenId = p.CitizenId == null ? "-" : (p.CitizenId.ToThaiNumber()),
|
||
FullName = $"{p.PrefixName}{p.FirstName} {p.LastName}",
|
||
DateOfBirth = p.DateOfBirth == null ? "-" : (p.DateOfBirth.Value.ToThaiShortDate()),
|
||
ExamName = ($"{p.PeriodExam.Name} ครั้งที่ {p.PeriodExam.Round}/{p.PeriodExam.Year.Value.ToThaiYear()}").ToThaiNumber(),
|
||
Number = p.Number == null ? (idx + 1).ToString().ToThaiNumber() : p.Number.ToThaiNumber(),
|
||
FullA = "๐",
|
||
SumA = "๐",
|
||
FullB = p.PointTotalB == null ? "-" : p.PointTotalB.ToString(),
|
||
SumB = p.PointB == null ? "-" : p.PointB.ToString(),
|
||
FullC = p.PointTotalC == null ? "-" : p.PointTotalC.ToString(),
|
||
SumC = p.PointC == null ? "-" : p.PointC.ToString(),
|
||
SumScore = ((Convert.ToInt32(p.PointB ?? "0") + Convert.ToInt32(p.PointC ?? "0")).ToString()).ToThaiNumber(),
|
||
ExamResult = p.Pass,
|
||
ExamThaiId = p.ExamIdenNumber == null ? "-" : p.ExamIdenNumber.ToThaiNumber(),
|
||
ExamId = p.ExamIdenNumber,
|
||
})
|
||
.OrderBy(x => x.ExamId)
|
||
.Where(x => x.ExamResult?.Trim() == "ได้")
|
||
.ToList();
|
||
|
||
if (data.Count == 0)
|
||
return Error("ไม่พบข้อมูลในระบบ");
|
||
|
||
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Recruit", $"rptPassExamList.trdp");
|
||
//ReportPackager reportPackager = new ReportPackager();
|
||
//Telerik.Reporting.Report report = null;
|
||
//using (var sourceStream = System.IO.File.OpenRead(rptFile))
|
||
//{
|
||
// report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||
//}
|
||
//report.ReportParameters["ExamName"].Value = data[0].ExamName;
|
||
//report.DataSource = data[0];
|
||
//var table = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
|
||
//table.DataSource = data;
|
||
//System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||
|
||
//InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||
//{
|
||
// ReportDocument = report
|
||
//};
|
||
|
||
|
||
//ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||
//RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||
|
||
//var content = result.DocumentBytes;
|
||
//return File(content, "application/pdf", $"รายชื่อผู้สอบแข่งขันได้_{periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}.pdf");
|
||
var examName = data[0].ExamName;
|
||
var _data = new
|
||
{
|
||
template = "rptPassExamList",
|
||
reportName = $"รายชื่อผู้สอบแข่งขันได้_{periodExam.Name} ครั้งที่ {periodExam.Round}/{periodExam.Year.Value.ToThaiYear()}",
|
||
data = new
|
||
{
|
||
examName = examName,
|
||
data = data
|
||
}
|
||
};
|
||
return Success(_data);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Error(ex, "เกิดข้อผิดพลาดในการแสดงรายงาน");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|