This commit is contained in:
Bright 2025-07-15 15:54:50 +07:00
parent 86e594df09
commit a352ec6578
2 changed files with 79 additions and 3 deletions

View file

@ -1081,7 +1081,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? ""; r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? "";
r.Race = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.Race = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? ""; r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? "";
r.DateOfBirth = DateTime.TryParseExact(workSheet?.Cells[row, 11]?.GetValue<string>()?.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dob) && dob.Year > 2500 ? dob.AddYears(-543) : DateTime.MinValue; //r.DateOfBirth = DateTime.TryParseExact(workSheet?.Cells[row, 11]?.GetValue<string>()?.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dob) && dob.Year > 2500 ? dob.AddYears(-543) : DateTime.MinValue;
r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue;
r.Marry = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.Marry = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.Isspecial = "N"; r.Isspecial = "N";
r.CitizenCardIssuer = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.CitizenCardIssuer = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
@ -1108,7 +1109,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(), GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(),
Specialist = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", Specialist = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "", HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "",
BachelorDate = DateTime.TryParseExact(workSheet?.Cells[row, 25]?.GetValue<string>()?.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var bachelorDob) && bachelorDob.Year > 2500 ? bachelorDob.AddYears(-543) : DateTime.MinValue, BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue,
CreatedAt = DateTime.Now, CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "", CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator", CreatedFullName = FullName ?? "System Administrator",
@ -1494,7 +1495,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
majorgroup = dr["majorgroup"].ToString(), majorgroup = dr["majorgroup"].ToString(),
certificateNo = dr["certificateno"].ToString(), certificateNo = dr["certificateno"].ToString(),
certificateIssueDate = dr["certificateIssueDate"] == null || Convert.ToDateTime(dr["certificateIssueDate"]) == DateTime.MinValue ? "" : Convert.ToDateTime(dr["certificateIssueDate"]).ToThaiShortDate(), certificateIssueDate = dr["certificateIssueDate"] == null || Convert.ToDateTime(dr["certificateIssueDate"]) == DateTime.MinValue ? "" : Convert.ToDateTime(dr["certificateIssueDate"]).ToThaiShortDate(),
ExamScore = dr["score"] == null ? 0 : dr["score"].ToString().ToInteger(), //ExamScore = dr["score"] == null ? 0 : dr["score"].ToString().ToInteger(),
ExamScore = string.IsNullOrWhiteSpace(dr["score"]?.ToString()) ? 0 : decimal.Parse(dr["score"]?.ToString()),
ExamResult = dr["result"].ToString(), ExamResult = dr["result"].ToString(),
ExamAttribute = dr["examAttribute"].ToString(), ExamAttribute = dr["examAttribute"].ToString(),
Remark = dr["remark"].ToString(), Remark = dr["remark"].ToString(),

View file

@ -12,6 +12,7 @@ using BMA.EHR.Recurit.Service.Data;
using System.Security.Claims; using System.Security.Claims;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Globalization;
namespace BMA.EHR.Recruit.Service.Services namespace BMA.EHR.Recruit.Service.Services
{ {
@ -388,6 +389,79 @@ namespace BMA.EHR.Recruit.Service.Services
throw; throw;
} }
} }
public DateTime CheckDateTime(string Date, string Formate)
{
// ตอนนี้ทำไว้ให้รองรับแค่ "dd/MM/yyyy", "yyyy-MM-dd"
if (string.IsNullOrWhiteSpace(Date))
return DateTime.MinValue;
string[] parts = Date.Trim().Replace("-", "/").Split("/");
if (parts.Length != 3)
return DateTime.MinValue;
int year;
int month;
int day;
switch (Formate)
{
case "dd/MM/yyyy":
if (int.TryParse(parts[2], out year) && year > 2500)
{
year -= 543;
}
else if (!int.TryParse(parts[2], out year))
{
return DateTime.MinValue;
}
if (!int.TryParse(parts[1], out month))
return DateTime.MinValue;
if (!int.TryParse(parts[0], out day))
return DateTime.MinValue;
break;
case "yyyy-MM-dd":
if (int.TryParse(parts[0], out year) && year > 2500)
{
year -= 543;
}
else if (!int.TryParse(parts[0], out year))
{
return DateTime.MinValue;
}
if (!int.TryParse(parts[1], out month))
return DateTime.MinValue;
if (!int.TryParse(parts[2], out day))
return DateTime.MinValue;
break;
default:
return DateTime.MinValue;
}
if (month < 1 || month > 12)
month = 1;
int maxDay = DateTime.DaysInMonth(year, month);
if (day < 1)
day = 1;
else if (day > maxDay)
day = maxDay;
var normalDate = $"{day}/{(month >= 1 && month <= 9 ? $"0{month}" : month)}/{year}";
if (DateTime.TryParseExact(normalDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate))
{
return parsedDate;
}
return DateTime.MinValue;
}
} }
} }