แก้รายงาน

This commit is contained in:
Suphonchai Phoonsawat 2023-09-02 22:50:38 +07:00
parent 890c34e0d5
commit 1ebdddaa6a
8 changed files with 175 additions and 10 deletions

View file

@ -87,6 +87,38 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
public async Task<List<dynamic>> GetCommandType02AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var ret = new List<dynamic>();
foreach (var c in raw_data)
{
ret.Add(new
{
FullName = $"{c.Prefix}{c.FirstName} {c.LastName}",
PositionName = ""
});
}
return ret;
}
catch
{
throw;
}
}
#endregion
}
}

View file

@ -61,6 +61,9 @@ namespace BMA.EHR.Report.Service.Controllers
throw new Exception(GlobalMessages.CommandNotFound);
}
//var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
//var positionList = string.Empty;
var command = new
{
CommandNo = raw_data.CommandNo,
@ -72,7 +75,9 @@ namespace BMA.EHR.Report.Service.Controllers
ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
PositionList = "",
Count = raw_data.Receivers.Count,
CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3()
CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
AuthorizedPosition = raw_data.AuthorizedPosition,
};
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp");
@ -162,6 +167,124 @@ namespace BMA.EHR.Report.Service.Controllers
#endregion
#region " C-PM-02 "
private async Task<byte[]> GenerateCommandReportType02_Cover(Guid commandId, string exportType)
{
try
{
var raw_data = await _repository.GetByIdAsync(commandId);
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
//var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
//var positionList = string.Empty;
var command = new
{
CommandNo = raw_data.CommandNo,
CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
IssuerOrganizationName = raw_data.IssuerOrganizationName,
ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
ConclusionResultNo = raw_data.ConclusionResultNo,
ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
PositionList = "",
Count = raw_data.Receivers.Count,
CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
AuthorizedPosition = raw_data.AuthorizedPosition,
};
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.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 = command;
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
if (exportType == "docx")
deviceInfo["OutputFormat"] = "DOCX";
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return content;
}
catch
{
throw;
}
}
private async Task<byte[]> GenerateCommandReportType02_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType02AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.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);
}
var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];
tblData.DataSource = data;
report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
report.ReportParameters["CommandNo"].Value = command.CommandNo;
report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return content;
}
catch
{
throw;
}
}
#endregion
#endregion
#region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ "
@ -266,7 +389,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType02CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType02CoverReportAsync(Guid id, string exportType = "pdf")
{
try
{
@ -278,10 +401,18 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var cmd = await _repository.GetByIdAsync(id);
if (cmd == null)
throw new Exception(GlobalMessages.CommandNotFound);
return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType02_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp");
//var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
//return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}");
}
catch
{
@ -303,10 +434,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType02AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType02AttachmentReportAsync(Guid id, string exportType = "pdf")
{
try
{
var cmd = await _repository.GetByIdAsync(id);
if (cmd == null)
throw new Exception(GlobalMessages.CommandNotFound);
var mimeType = "";
switch (exportType.Trim().ToLower())
{
@ -315,10 +450,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType02_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{