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