需要关于这个逻辑的帮助......(.NET)

时间:2009-10-29 18:45:29

标签: .net errorprovider

这是我在表单中的代码,用于检查用户选择的日期是提前14天还是过去。

If (dtpDate.Value > DateTime.Today.AddDays(14)) Then
    frmBookErr.SetError(dtpDate, "You cannot book more than two weeks in advance.")
Else
    frmBookErr.SetError(dtpDate, "")
End If
If (dtpDate.Value < DateTime.Today) Then
    frmBookErr.SetError(dtpDate, "You cannot book a room for the past.")
Else
    frmBookErr.SetError(dtpDate, "")
End If

它可以工作,但如果我提前14天选择一个日期,它将不会显示错误消息,因为第二个IF检查它是否在过去并消隐。

除了让另一个文本框位于用户键入的文本框后面,并将第二条错误消息显示在该文本框之外,我真的想不到另一种方法。

有人有什么好主意吗?谢谢:))

2 个答案:

答案 0 :(得分:8)

试试这个

If (dtpDate.Value > DateTime.Today.AddDays(14)) Then
    frmBookErr.SetError(dtpDate, "You cannot book more than two weeks in advance.")
Else If (dtpDate.Value < DateTime.Today) Then
    frmBookErr.SetError(dtpDate, "You cannot book a room for the past.")
Else
    frmBookErr.SetError(dtpDate, "")
End If

答案 1 :(得分:1)

你非常接近!只需将支票放入else if块即可。

If (dtpDate.Value > DateTime.Today.AddDays(14)) Then
    frmBookErr.SetError(dtpDate, "You cannot book more than two weeks in advance.")
Else If (dtpDate.Value < DateTime.Today) Then
    frmBookErr.SetError(dtpDate, "You cannot book a room for the past.")
Else
    frmBookErr.SetError(dtpDate, "")
End If
相关问题