This commit is contained in:
geh 2025-09-11 10:27:45 +08:00
parent f132593c5b
commit c0d8d8e63b
1 changed files with 16 additions and 11 deletions

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
@ -307,7 +308,7 @@ namespace FineUIPro.Web.HSSE.SitePerson
//根据身份证号码获取出生日期
if (!string.IsNullOrEmpty(idCard))
{
string birthDateStr = "";
string birthDateStr = string.Empty;
if (idCard.Length == 18)
{
// 18位身份证号码出生日期在第7位到第14位
@ -318,14 +319,15 @@ namespace FineUIPro.Web.HSSE.SitePerson
// 15位身份证号码出生日期在第7位到第12位需要加上"19"前缀
birthDateStr = "19" + idCard.Substring(6, 6);
}
// 解析日期字符串为DateTime对象
var birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
if (birthDate.AddYears(60) < DateTime.Now)
if (!string.IsNullOrEmpty(birthDateStr))
{
Grid1.Rows[i].RowCssClass = "Yellow";
// 解析日期字符串为DateTime对象
var birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
if (birthDate.AddYears(60) < DateTime.Now)
{
Grid1.Rows[i].RowCssClass = "Yellow";
}
}
}
// if (person.IsUsedType=="2") //待审批
// {
@ -816,7 +818,7 @@ namespace FineUIPro.Web.HSSE.SitePerson
if (rirthday != null)
{
var idCard = rirthday.ToString();
string birthDateStr = "";
string birthDateStr = string.Empty;
if (idCard.Length == 18)
{
// 18位身份证号码出生日期在第7位到第14位
@ -827,10 +829,13 @@ namespace FineUIPro.Web.HSSE.SitePerson
// 15位身份证号码出生日期在第7位到第12位需要加上"19"前缀
birthDateStr = "19" + idCard.Substring(6, 6);
}
var birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
if (birthDate != null)
if (!string.IsNullOrEmpty(birthDateStr))
{
age = CommonService.CalculateAgeCorrect(birthDate).ToString();
// 使用TryParseExact安全地解析日期
if (DateTime.TryParseExact(birthDateStr, "yyyyMMdd", null, DateTimeStyles.None, out DateTime birthDate))
{
age = CommonService.CalculateAgeCorrect(birthDate).ToString();
}
}
}
return age;