年龄处理

This commit is contained in:
geh 2025-09-08 10:39:44 +08:00
parent 8c5c602487
commit f132593c5b
2 changed files with 43 additions and 8 deletions

View File

@ -115,9 +115,9 @@
FieldType="String" HeaderText="姓名" HeaderTextAlign="Center"
TextAlign="Center">
</f:RenderField>
<f:TemplateField ColumnID="tfAge" Width="80px" HeaderText="年龄" HeaderTextAlign="Center" TextAlign="Left">
<f:TemplateField ColumnID="tfAge" Width="80px" HeaderText="年龄" HeaderTextAlign="Center" TextAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAge" runat="server" Text='<%# ConvertAge(Eval("Birthday")) %>'></asp:Label>
<asp:Label ID="lblAge" runat="server" Text='<%# ConvertAge(Eval("IdentityCard")) %>'></asp:Label>
</ItemTemplate>
</f:TemplateField>
<%-- <f:RenderField HeaderText="卡号" ColumnID="CardNo" DataField="CardNo" SortField="CardNo"

View File

@ -303,11 +303,34 @@ namespace FineUIPro.Web.HSSE.SitePerson
{
string personId = Grid1.Rows[i].DataKeys[0].ToString();
var person = BLL.PersonService.GetPersonById(personId);
var idCard = person.IdentityCard;
//根据身份证号码获取出生日期
if (!string.IsNullOrEmpty(idCard))
{
string birthDateStr = "";
if (idCard.Length == 18)
{
// 18位身份证号码出生日期在第7位到第14位
birthDateStr = idCard.Substring(6, 8);
}
else if (idCard.Length == 15)
{
// 15位身份证号码出生日期在第7位到第12位需要加上"19"前缀
birthDateStr = "19" + idCard.Substring(6, 6);
}
if (person.IsUsedType=="2") //待审批
// 解析日期字符串为DateTime对象
var birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
if (birthDate.AddYears(60) < DateTime.Now)
{
Grid1.Rows[i].RowCssClass = "Yellow";
}
}
// if (person.IsUsedType=="2") //待审批
// {
// Grid1.Rows[i].RowCssClass = "Yellow";
// }
}
}
@ -792,10 +815,22 @@ namespace FineUIPro.Web.HSSE.SitePerson
string age = string.Empty;
if (rirthday != null)
{
DateTime? bDate = Funs.GetNewDateTime(rirthday.ToString());
if (bDate.HasValue)
var idCard = rirthday.ToString();
string birthDateStr = "";
if (idCard.Length == 18)
{
age = CommonService.CalculateAgeCorrect(bDate.Value).ToString();
// 18位身份证号码出生日期在第7位到第14位
birthDateStr = idCard.Substring(6, 8);
}
else if (idCard.Length == 15)
{
// 15位身份证号码出生日期在第7位到第12位需要加上"19"前缀
birthDateStr = "19" + idCard.Substring(6, 6);
}
var birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
if (birthDate != null)
{
age = CommonService.CalculateAgeCorrect(birthDate).ToString();
}
}
return age;