ดิง api จาก org
This commit is contained in:
parent
e75d532ac0
commit
fe804ed6a0
1 changed files with 131 additions and 132 deletions
|
|
@ -277,7 +277,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
|
||||
if (org == null || org.result == null)
|
||||
{
|
||||
return Error("ไม่ะบข้อมูลนี้ในระบบ", 404);
|
||||
return Error("ไม่พบข้อมูลนี้ในระบบ", 404);
|
||||
}
|
||||
report.DataSource = org.result;
|
||||
CitizenId = org.result.CitizenId;
|
||||
|
|
@ -496,7 +496,6 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
var CitizenId = "";
|
||||
var FullName = "";
|
||||
var OcFullPath = "";
|
||||
var salary = new List<dynamic>();
|
||||
var apiUrl = $"{_configuration["API"]}org/profile/kk1/{id}";
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
|
|
@ -509,7 +508,7 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
|
||||
if (org == null || org.result == null)
|
||||
{
|
||||
return Error("ไม่ะบข้อมูลนี้ในระบบ", 404);
|
||||
return Error("ไม่พบข้อมูลนี้ในระบบ", 404);
|
||||
}
|
||||
report.DataSource = org.result.Profile;
|
||||
// binding to table
|
||||
|
|
@ -524,141 +523,126 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
|
||||
var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"];
|
||||
tblEducation.DataSource = org.result.Education;
|
||||
salary = org.result.Salary;
|
||||
var salary = org.result.Salary;
|
||||
CitizenId = org.result.Profile.CitizenId;
|
||||
FullName = org.result.Profile.FullName;
|
||||
OcFullPath = org.result.Profile.OcFullPath;
|
||||
}
|
||||
|
||||
// if (profile.First().AvatarId != "")
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// // Get avatar Image
|
||||
// var picContent = (await _minioService.DownloadFileAsync(Guid.Parse(profile.First().AvatarId))).FileContent;
|
||||
// var pictureBox = (Telerik.Reporting.PictureBox)report.Items["pageFooterSection1"].Items["picAvatar"];
|
||||
// pictureBox.Value = Image.FromStream(new MemoryStream(picContent));
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
|
||||
// if (profile.First().AvatarId != "")
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// // Get avatar Image
|
||||
// var picContent = (await _minioService.DownloadFileAsync(Guid.Parse(profile.First().AvatarId))).FileContent;
|
||||
// var pictureBox = (Telerik.Reporting.PictureBox)report.Items["pageFooterSection1"].Items["picAvatar"];
|
||||
// pictureBox.Value = Image.FromStream(new MemoryStream(picContent));
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
|
||||
|
||||
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);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content = result.DocumentBytes;
|
||||
|
||||
// // page2
|
||||
// var profile2 = (from p in _context.Profiles
|
||||
// join pf in _context.Prefixes on p.PrefixId equals pf.Id
|
||||
// where p.Id == id
|
||||
// select new
|
||||
// {
|
||||
// FullName = $"{pf.Name}{p.FirstName} {p.LastName}",
|
||||
// OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false),
|
||||
// }).FirstOrDefault();
|
||||
|
||||
// var salary = (from s in _context.ProfileSalaries
|
||||
// .Include(x => x.PositionLevel)
|
||||
// join pos in _context.PositionPaths.AsQueryable()
|
||||
// on s.PositionId equals pos.Id
|
||||
// join pos_no in _context.PositionNumbers on s.PosNoId equals pos_no.Id
|
||||
// // join pos_lv in _context.PositionLevels on s.PositionLevelId equals pos_lv.Id
|
||||
// join pos_type in _context.PositionTypes on s.PositionTypeId equals pos_type.Id
|
||||
// where s.Profile.Id == id
|
||||
// orderby s.Date.Value
|
||||
// select new
|
||||
// {
|
||||
// SalaryDate = s.Date == null ? "" : s.Date == new DateTime(1, 1, 1) ? "" : s.Date.Value.ToThaiShortDate(),
|
||||
// Position = $"{pos.Name} ประเภท{pos_type.Name} ระดับ{s.PositionLevel.Name}",
|
||||
// PosNo = pos_no.Name,
|
||||
// Rank = s.PositionLevel == null ? null : s.PositionLevel.Name,
|
||||
// Salary = s.Amount == null ? "" : s.Amount == 0 ? "-" : s.Amount.ToString().ToInteger().ToNumericText(),
|
||||
// RefAll = s.SalaryRef,
|
||||
// PositionType = pos_type.Name,
|
||||
// PositionLevel = s.PositionLevel == null ? null : s.PositionLevel.Name,
|
||||
// PositionAmount = s.PositionSalaryAmount == null ? "" : s.PositionSalaryAmount.Value == 0 ? "-" : s.PositionSalaryAmount.Value.ToString().ToInteger().ToNumericText(),
|
||||
// FullName = profile2.FullName,
|
||||
// OcFullPath = profile2.OcFullPath
|
||||
// }).ToList();
|
||||
|
||||
//while (salary.Count < 60)
|
||||
//{
|
||||
// salary.Add(new
|
||||
// {
|
||||
// SalaryDate = "",
|
||||
// Position = "",
|
||||
// PosNo = "",
|
||||
// Rank = "",
|
||||
// Salary = "",
|
||||
// RefAll = "",
|
||||
// PositionType = "",
|
||||
// PositionLevel = "",
|
||||
// PositionAmount = "",
|
||||
// FullName = profile2.FullName,
|
||||
// OcFullPath = profile2.OcFullPath
|
||||
// });
|
||||
//}
|
||||
|
||||
var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page2.trdp");
|
||||
|
||||
ReportPackager reportPackager2 = new ReportPackager();
|
||||
Telerik.Reporting.Report? report2 = null;
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile2))
|
||||
{
|
||||
report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||||
}
|
||||
|
||||
report2.ReportParameters["FullName"].Value = FullName;
|
||||
report2.ReportParameters["OcFullPath"].Value = OcFullPath;
|
||||
|
||||
// binding to table
|
||||
var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"];
|
||||
tblSalary.DataSource = salary;
|
||||
|
||||
System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable();
|
||||
|
||||
InstanceReportSource instanceReportSource2 = new InstanceReportSource()
|
||||
{
|
||||
ReportDocument = report2
|
||||
};
|
||||
|
||||
|
||||
ReportProcessor reportProcessor2 = new ReportProcessor(_configuration);
|
||||
RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content2 = result2.DocumentBytes;
|
||||
|
||||
// merge pdf
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true)))
|
||||
InstanceReportSource instanceReportSource = new InstanceReportSource()
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (MemoryStream memoryStream = new MemoryStream(content))
|
||||
ReportDocument = report
|
||||
};
|
||||
|
||||
|
||||
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
|
||||
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content = result.DocumentBytes;
|
||||
|
||||
// // page2
|
||||
// var profile2 = (from p in _context.Profiles
|
||||
// join pf in _context.Prefixes on p.PrefixId equals pf.Id
|
||||
// where p.Id == id
|
||||
// select new
|
||||
// {
|
||||
// FullName = $"{pf.Name}{p.FirstName} {p.LastName}",
|
||||
// OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false),
|
||||
// }).FirstOrDefault();
|
||||
|
||||
// var salary = (from s in _context.ProfileSalaries
|
||||
// .Include(x => x.PositionLevel)
|
||||
// join pos in _context.PositionPaths.AsQueryable()
|
||||
// on s.PositionId equals pos.Id
|
||||
// join pos_no in _context.PositionNumbers on s.PosNoId equals pos_no.Id
|
||||
// // join pos_lv in _context.PositionLevels on s.PositionLevelId equals pos_lv.Id
|
||||
// join pos_type in _context.PositionTypes on s.PositionTypeId equals pos_type.Id
|
||||
// where s.Profile.Id == id
|
||||
// orderby s.Date.Value
|
||||
// select new
|
||||
// {
|
||||
// SalaryDate = s.Date == null ? "" : s.Date == new DateTime(1, 1, 1) ? "" : s.Date.Value.ToThaiShortDate(),
|
||||
// Position = $"{pos.Name} ประเภท{pos_type.Name} ระดับ{s.PositionLevel.Name}",
|
||||
// PosNo = pos_no.Name,
|
||||
// Rank = s.PositionLevel == null ? null : s.PositionLevel.Name,
|
||||
// Salary = s.Amount == null ? "" : s.Amount == 0 ? "-" : s.Amount.ToString().ToInteger().ToNumericText(),
|
||||
// RefAll = s.SalaryRef,
|
||||
// PositionType = pos_type.Name,
|
||||
// PositionLevel = s.PositionLevel == null ? null : s.PositionLevel.Name,
|
||||
// PositionAmount = s.PositionSalaryAmount == null ? "" : s.PositionSalaryAmount.Value == 0 ? "-" : s.PositionSalaryAmount.Value.ToString().ToInteger().ToNumericText(),
|
||||
// FullName = profile2.FullName,
|
||||
// OcFullPath = profile2.OcFullPath
|
||||
// }).ToList();
|
||||
|
||||
//while (salary.Count < 60)
|
||||
//{
|
||||
// salary.Add(new
|
||||
// {
|
||||
// SalaryDate = "",
|
||||
// Position = "",
|
||||
// PosNo = "",
|
||||
// Rank = "",
|
||||
// Salary = "",
|
||||
// RefAll = "",
|
||||
// PositionType = "",
|
||||
// PositionLevel = "",
|
||||
// PositionAmount = "",
|
||||
// FullName = profile2.FullName,
|
||||
// OcFullPath = profile2.OcFullPath
|
||||
// });
|
||||
//}
|
||||
|
||||
var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page2.trdp");
|
||||
|
||||
ReportPackager reportPackager2 = new ReportPackager();
|
||||
Telerik.Reporting.Report? report2 = null;
|
||||
using (var sourceStream = System.IO.File.OpenRead(rptFile2))
|
||||
{
|
||||
report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
|
||||
}
|
||||
|
||||
report2.ReportParameters["FullName"].Value = FullName;
|
||||
report2.ReportParameters["OcFullPath"].Value = OcFullPath;
|
||||
|
||||
// binding to table
|
||||
var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"];
|
||||
tblSalary.DataSource = salary;
|
||||
|
||||
System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable();
|
||||
|
||||
InstanceReportSource instanceReportSource2 = new InstanceReportSource()
|
||||
{
|
||||
ReportDocument = report2
|
||||
};
|
||||
|
||||
|
||||
ReportProcessor reportProcessor2 = new ReportProcessor(_configuration);
|
||||
RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2);
|
||||
|
||||
// byte array waiting for merge pdf
|
||||
var content2 = result2.DocumentBytes;
|
||||
|
||||
// merge pdf
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true)))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (PdfReader reader = new PdfReader(memoryStream))
|
||||
{
|
||||
PdfDocument srcDoc = new PdfDocument(reader);
|
||||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
|
||||
}
|
||||
}
|
||||
|
||||
// Create reader from bytes
|
||||
if (content2 != null)
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(content2))
|
||||
using (MemoryStream memoryStream = new MemoryStream(content))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (PdfReader reader = new PdfReader(memoryStream))
|
||||
|
|
@ -667,13 +651,28 @@ namespace BMA.EHR.Report.Service.Controllers
|
|||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
|
||||
}
|
||||
}
|
||||
|
||||
// Create reader from bytes
|
||||
if (content2 != null)
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(content2))
|
||||
{
|
||||
// Create reader from bytes
|
||||
using (PdfReader reader = new PdfReader(memoryStream))
|
||||
{
|
||||
PdfDocument srcDoc = new PdfDocument(reader);
|
||||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pdf.Close();
|
||||
}
|
||||
|
||||
pdf.Close();
|
||||
var fileContent = ms.ToArray();
|
||||
return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf");
|
||||
}
|
||||
|
||||
var fileContent = ms.ToArray();
|
||||
return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue