Foxtable(狐表)用户栏目专家坐堂 → [求助如何校验登记时的年龄的准确性?(已解决)


  共有10638人关注过本帖树形打印复制链接

主题:[求助如何校验登记时的年龄的准确性?(已解决)

帅哥,在线噢!
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251054 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/8/7 7:51:00 [显示全部帖子]

DataColChanging使用刚刚输入的值,必须使用e.NewValue表示,如果使用e.DataRow("列名"),是输入前的值,就是旧值。

 

正确代码:

 

If e.DataCol.Name = "身份证号码" Then
        If e.NewValue IsNot Nothing Then
            Dim d As Date = ReadBirthDay(e.NewValue)
            Dim s As String = ReadSex(e.NewValue)
            If s = "" OrElse d < #1/1/1900# Then
                e.Cancel = True '取消输入
                MessageBox.Show("身份证无效输入")
            End If
        End If
End If
If e.DataCol.Name = "登记日期" Then
    If e.DataRow.IsNull("出生日期") = True OrElse e.NewValue Is Nothing Then
        Return
    Else
        Dim n As Integer = e.NewValue.Year - e.DataRow("出生日期").Year
        If e.DataRow("出生日期").AddMonths(n*12) > e.NewValue Then
            n = n -1
        End If
        If e.DataRow("登记时年龄") <> n Then
            e.Cancel = True
            MessageBox.Show("年龄与身份证不符!")
        End If
    End If
End If

 

建议仔细看看这两个事件的差别:

http://www.foxtable.net/help/topics/0624.htm

http://www.foxtable.net/help/topics/0625.htm

 


 回到顶部