fix ระบบสรรหาฯ #876
This commit is contained in:
parent
5be7ad401a
commit
8b9bdf84f9
1 changed files with 294 additions and 221 deletions
|
|
@ -1813,69 +1813,91 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
|
||||
var header = $"{data.Name} ครั้งที่ {data.Round}/{data.Year.Value.ToThaiYear()}";
|
||||
|
||||
var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
var template_file = Path.Combine(template_dir, "ExamList.xlsx");
|
||||
|
||||
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
if (!Directory.Exists(tmpDir))
|
||||
Directory.CreateDirectory(tmpDir);
|
||||
|
||||
var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
try
|
||||
{
|
||||
// copy template
|
||||
System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
var disables = data.Disables
|
||||
.OrderBy(x => x.ExamId)
|
||||
.Select(x => new
|
||||
{
|
||||
var workSheet = excel.Workbook.Worksheets[0];
|
||||
ExamId = x.ExamId,
|
||||
CitizenId = x.CitizenId,
|
||||
Fullname = $"{x.Prefix}{x.FirstName} {x.LastName}",
|
||||
PositionName = x.PositionName
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
workSheet.Cells[1, 2].Value = header;
|
||||
var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
var row = 4; // start at row 4
|
||||
foreach (var item in disables)
|
||||
{
|
||||
workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
workSheet.Cells[row, 4].Value = item.PositionName;
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
excel.Save();
|
||||
|
||||
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
fs.Close();
|
||||
|
||||
var fname = Path.GetFileName(exportFile);
|
||||
|
||||
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = fname
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
var _data = new
|
||||
{
|
||||
template = "ExamList",
|
||||
reportName = $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
||||
data = new
|
||||
{
|
||||
header = header,
|
||||
data = disables
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(exportFile))
|
||||
System.IO.File.Delete(exportFile);
|
||||
}
|
||||
};
|
||||
return Success(_data);
|
||||
//var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
//var template_file = Path.Combine(template_dir, "ExamList.xlsx");
|
||||
|
||||
//var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
//if (!Directory.Exists(tmpDir))
|
||||
// Directory.CreateDirectory(tmpDir);
|
||||
|
||||
//var exportFile = Path.Combine(tmpDir, $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
//try
|
||||
//{
|
||||
// // copy template
|
||||
// System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
// using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
// {
|
||||
// var workSheet = excel.Workbook.Worksheets[0];
|
||||
|
||||
|
||||
// workSheet.Cells[1, 2].Value = header;
|
||||
// var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
// var row = 4; // start at row 4
|
||||
// foreach (var item in disables)
|
||||
// {
|
||||
// workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
// workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
// workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
// workSheet.Cells[row, 4].Value = item.PositionName;
|
||||
|
||||
// row++;
|
||||
// }
|
||||
|
||||
// excel.Save();
|
||||
|
||||
// using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
// {
|
||||
// byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
// fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
// fs.Close();
|
||||
|
||||
// var fname = Path.GetFileName(exportFile);
|
||||
|
||||
// Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
// var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
// {
|
||||
// FileDownloadName = fname
|
||||
// };
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์สอบได้!!");
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// if (System.IO.File.Exists(exportFile))
|
||||
// System.IO.File.Delete(exportFile);
|
||||
//}
|
||||
}
|
||||
|
||||
[HttpGet("export/pass-exam/{id:length(36)}")]
|
||||
|
|
@ -1899,88 +1921,112 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
|
||||
var header = $"{data.Name} ครั้งที่ {data.Round}/{data.Year.Value.ToThaiYear()}";
|
||||
|
||||
var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
var template_file = Path.Combine(template_dir, "PassAExamList.xlsx");
|
||||
|
||||
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
if (!Directory.Exists(tmpDir))
|
||||
Directory.CreateDirectory(tmpDir);
|
||||
|
||||
var exportFile = Path.Combine(tmpDir, $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
|
||||
try
|
||||
var result = (from r in data.Disables.ToList()
|
||||
join s in data_pass.ScoreImport.Scores.Where(x => x.AStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
orderby r.ExamId ascending, s.SumA descending
|
||||
select new
|
||||
{
|
||||
r.ExamId,
|
||||
r.CitizenId,
|
||||
r.Prefix,
|
||||
r.FirstName,
|
||||
r.LastName,
|
||||
s.FullA,
|
||||
s.SumA,
|
||||
s.AStatus,
|
||||
}).ToList();
|
||||
var _data = new
|
||||
{
|
||||
var result = (from r in data.Disables.ToList()
|
||||
join s in data_pass.ScoreImport.Scores.Where(x => x.AStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
select new
|
||||
{
|
||||
r.ExamId,
|
||||
r.CitizenId,
|
||||
r.Prefix,
|
||||
r.FirstName,
|
||||
r.LastName,
|
||||
s.FullA,
|
||||
s.SumA,
|
||||
s.AStatus,
|
||||
|
||||
}).ToList();
|
||||
|
||||
// copy template
|
||||
System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
template = "PassAExamList",
|
||||
reportName = $"PassAExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
||||
data = new
|
||||
{
|
||||
var workSheet = excel.Workbook.Worksheets[0];
|
||||
|
||||
|
||||
workSheet.Cells[1, 2].Value = header;
|
||||
var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
var row = 4; // start at row 4
|
||||
foreach (var item in result)
|
||||
{
|
||||
workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
workSheet.Cells[row, 4].Value = item.FullA;
|
||||
workSheet.Cells[row, 5].Value = item.SumA;
|
||||
workSheet.Cells[row, 6].Value = item.AStatus;
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
excel.Save();
|
||||
|
||||
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
fs.Close();
|
||||
|
||||
var fname = Path.GetFileName(exportFile);
|
||||
|
||||
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = fname
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
header = header,
|
||||
data = result
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้สอบผ่านได้!!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(exportFile))
|
||||
System.IO.File.Delete(exportFile);
|
||||
}
|
||||
};
|
||||
return Success(_data);
|
||||
//var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
//var template_file = Path.Combine(template_dir, "PassAExamList.xlsx");
|
||||
|
||||
//var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
//if (!Directory.Exists(tmpDir))
|
||||
// Directory.CreateDirectory(tmpDir);
|
||||
|
||||
//var exportFile = Path.Combine(tmpDir, $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
|
||||
//try
|
||||
//{
|
||||
// var result = (from r in data.Disables.ToList()
|
||||
// join s in data_pass.ScoreImport.Scores.Where(x => x.AStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
// select new
|
||||
// {
|
||||
// r.ExamId,
|
||||
// r.CitizenId,
|
||||
// r.Prefix,
|
||||
// r.FirstName,
|
||||
// r.LastName,
|
||||
// s.FullA,
|
||||
// s.SumA,
|
||||
// s.AStatus,
|
||||
|
||||
// }).ToList();
|
||||
|
||||
// // copy template
|
||||
// System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
// using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
// {
|
||||
// var workSheet = excel.Workbook.Worksheets[0];
|
||||
|
||||
|
||||
// workSheet.Cells[1, 2].Value = header;
|
||||
// var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
// var row = 4; // start at row 4
|
||||
// foreach (var item in result)
|
||||
// {
|
||||
// workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
// workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
// workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
// workSheet.Cells[row, 4].Value = item.FullA;
|
||||
// workSheet.Cells[row, 5].Value = item.SumA;
|
||||
// workSheet.Cells[row, 6].Value = item.AStatus;
|
||||
|
||||
// row++;
|
||||
// }
|
||||
|
||||
// excel.Save();
|
||||
|
||||
// using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
// {
|
||||
// byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
// fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
// fs.Close();
|
||||
|
||||
// var fname = Path.GetFileName(exportFile);
|
||||
|
||||
// Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
// var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
// {
|
||||
// FileDownloadName = fname
|
||||
// };
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้สอบผ่านได้!!");
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// if (System.IO.File.Exists(exportFile))
|
||||
// System.IO.File.Delete(exportFile);
|
||||
//}
|
||||
}
|
||||
|
||||
[HttpGet("export/pass/{id:length(36)}")]
|
||||
|
|
@ -2004,91 +2050,118 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
|
||||
var header = $"{data.Name} ครั้งที่ {data.Round}/{data.Year.Value.ToThaiYear()}";
|
||||
|
||||
var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
var template_file = Path.Combine(template_dir, "PassExamList.xlsx");
|
||||
|
||||
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
if (!Directory.Exists(tmpDir))
|
||||
Directory.CreateDirectory(tmpDir);
|
||||
|
||||
var exportFile = Path.Combine(tmpDir, $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
|
||||
try
|
||||
var result = (from r in data.Disables.ToList()
|
||||
join s in data_pass.ScoreImport.Scores.Where(x => x.ExamStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
select new
|
||||
{
|
||||
ExamId = r.ExamId,
|
||||
CitizenId = r.CitizenId,
|
||||
Fullname = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
||||
Full = s.FullA + s.FullB + s.FullC,
|
||||
Sum = s.SumA + s.SumB + s.SumC,
|
||||
Status = s.ExamStatus,
|
||||
Number = s.Number,
|
||||
PositionName = r.PositionName,
|
||||
}).ToList()
|
||||
.OrderBy(x => x.ExamId)
|
||||
.ThenBy(x => x.PositionName)
|
||||
.ThenByDescending(x => x.Sum)
|
||||
.ToList();
|
||||
var _data = new
|
||||
{
|
||||
var result = (from r in data.Disables.ToList()
|
||||
join s in data_pass.ScoreImport.Scores.Where(x => x.ExamStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
select new
|
||||
{
|
||||
r.ExamId,
|
||||
r.CitizenId,
|
||||
r.Prefix,
|
||||
r.FirstName,
|
||||
r.LastName,
|
||||
Full = s.FullA + s.FullB + s.FullC,
|
||||
Sum = s.SumA + s.SumB + s.SumC,
|
||||
Status = s.ExamStatus,
|
||||
r.PositionName,
|
||||
s.Number
|
||||
}).ToList();
|
||||
|
||||
// copy template
|
||||
System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
template = "PassExamList",
|
||||
reportName = $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
||||
data = new
|
||||
{
|
||||
var workSheet = excel.Workbook.Worksheets[0];
|
||||
|
||||
|
||||
workSheet.Cells[1, 2].Value = header;
|
||||
var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
var row = 4; // start at row 4
|
||||
foreach (var item in result)
|
||||
{
|
||||
workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
workSheet.Cells[row, 4].Value = item.Full;
|
||||
workSheet.Cells[row, 5].Value = item.Sum;
|
||||
workSheet.Cells[row, 6].Value = item.Status;
|
||||
workSheet.Cells[row, 7].Value = item.Number;
|
||||
workSheet.Cells[row, 8].Value = item.PositionName;
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
excel.Save();
|
||||
|
||||
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
fs.Close();
|
||||
|
||||
var fname = Path.GetFileName(exportFile);
|
||||
|
||||
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
{
|
||||
FileDownloadName = fname
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
header = header,
|
||||
data = result
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้สอบผ่านได้!!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(exportFile))
|
||||
System.IO.File.Delete(exportFile);
|
||||
}
|
||||
};
|
||||
return Success(_data);
|
||||
//var template_dir = Path.Combine(_webHostEnvironment.ContentRootPath, "Templates");
|
||||
|
||||
//var template_file = Path.Combine(template_dir, "PassExamList.xlsx");
|
||||
|
||||
//var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
||||
//if (!Directory.Exists(tmpDir))
|
||||
// Directory.CreateDirectory(tmpDir);
|
||||
|
||||
//var exportFile = Path.Combine(tmpDir, $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
|
||||
//try
|
||||
//{
|
||||
// var result = (from r in data.Disables.ToList()
|
||||
// join s in data_pass.ScoreImport.Scores.Where(x => x.ExamStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
||||
// select new
|
||||
// {
|
||||
// r.ExamId,
|
||||
// r.CitizenId,
|
||||
// r.Prefix,
|
||||
// r.FirstName,
|
||||
// r.LastName,
|
||||
// Full = s.FullA + s.FullB + s.FullC,
|
||||
// Sum = s.SumA + s.SumB + s.SumC,
|
||||
// Status = s.ExamStatus,
|
||||
// r.PositionName,
|
||||
// s.Number
|
||||
// }).ToList();
|
||||
|
||||
// // copy template
|
||||
// System.IO.File.Copy(template_file, exportFile);
|
||||
|
||||
// using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
||||
// {
|
||||
// var workSheet = excel.Workbook.Worksheets[0];
|
||||
|
||||
|
||||
// workSheet.Cells[1, 2].Value = header;
|
||||
// var disables = data.Disables.OrderBy(x => x.ExamId).ToList();
|
||||
|
||||
// var row = 4; // start at row 4
|
||||
// foreach (var item in result)
|
||||
// {
|
||||
// workSheet.Cells[row, 1].Value = item.ExamId;
|
||||
// workSheet.Cells[row, 2].Value = item.CitizenId;
|
||||
// workSheet.Cells[row, 3].Value = $"{item.Prefix}{item.FirstName} {item.LastName}";
|
||||
// workSheet.Cells[row, 4].Value = item.Full;
|
||||
// workSheet.Cells[row, 5].Value = item.Sum;
|
||||
// workSheet.Cells[row, 6].Value = item.Status;
|
||||
// workSheet.Cells[row, 7].Value = item.Number;
|
||||
// workSheet.Cells[row, 8].Value = item.PositionName;
|
||||
|
||||
// row++;
|
||||
// }
|
||||
|
||||
// excel.Save();
|
||||
|
||||
// using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
||||
// {
|
||||
// byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
||||
// fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
||||
// fs.Close();
|
||||
|
||||
// var fname = Path.GetFileName(exportFile);
|
||||
|
||||
// Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
||||
|
||||
// var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
// {
|
||||
// FileDownloadName = fname
|
||||
// };
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้สอบผ่านได้!!");
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// if (System.IO.File.Exists(exportFile))
|
||||
// System.IO.File.Delete(exportFile);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue