我只是在员工表事件中写了这样的代码,窗体控件我只是邦定到这表中的对应列,没有代码
If e.DataCol.Name = "身份证号码" Then '如果更改的是身份证号码列
If e.DataRow.IsNull("身份证号码") Then '身份证号码是否为空
e.DataRow("出生日期") = Nothing '如果为空,则清除出生日期
e.DataRow("姓别") = Nothing
e.DataRow("年龄") = Nothing
e.DataRow("籍贯") = Nothing
e.DataRow("服务天数") = Nothing
Else If ValidPIN(e.DataRow("身份证号码")) = True Then
'否则从身份证号码列中提取出生日期
e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号码"))
e.DataRow("姓别") = ReadSex(e.DataRow("身份证号码"))
Dim st1 As String = Tables("员工表").Current("身份证号码")
Dim st2 As String = st1.SubString(0,6)
Dim dr As DataRow = DataTables("地区信息").Find("身份证区位码 = '" & st2 & "'")
e.DataRow("籍贯") = dr("各地省市区")
Else
MessageBox.Show("您输入的身份证有误 , 或身份证可能是假的 !","警告",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Error)
e.DataRow("出生日期") = Nothing '如果为空,则清除出生日期
e.DataRow("姓别") = Nothing
e.DataRow("身份证号码") = Nothing
End If
End If
Select Case e.DataCol.name
Case "入职日期","离职日期"
If e.DataRow.IsNull("入职日期") Then
e.DataRow("服务天数") = Nothing
Else
Dim tl As TimeSpan = Date.today - CDate(e.DataRow("出生日期"))
e.DataRow("年龄") = (Math.Round(tl.TotalDays)/365)
If e.DataRow.Isnull("离职日期") Then
Dim tp As TimeSpan = Date.today - CDate(e.DataRow("入职日期"))
e.DataRow("服务天数") = Math.Round(tp.TotalDays)
Else
Dim tt As TimeSpan = cdate(e.DataRow("离职日期")) - cdate(e.DataRow("入职日期"))
e.DataRow("服务天数") = math.round(tt.Totaldays)
End If
End If
End Select