当用户选择超过 1 天然后单击半天的复选框时如何显示错误消息?
How to display error message when user pick more than 1 day then click the checkbox for halfday?
我有两个日期选择器,分别是 datepickerFrom 和 datepickerto。我想在用户选择超过 1 天并选中半天复选框然后单击按钮提交时显示错误消息,它将显示错误消息。
例如:A 选择 1/6/2022 - 3/6/2022,然后点击复选框选择半天。当 A 单击提交按钮时,它会显示一条错误消息,例如“抱歉,半天不能选择超过 1 个日期!”
这是我检查错误的代码
Private Function ErrorFree() As Boolean
If datepickerFrom.Date > datepickerto.Date Then
If chkHalfDay.Checked = True Then
DisplayMessage("error", "ERROR", "Sorry, You can't pick more than 1 date for half day!")
Return False
Exit Function
End If
End If
Return True
End Function
终于找到答案了!所以这是代码。然后我调用 datepickerFrom_DateChanged 和 datepickerto_DateChanged 中的函数。
Private Function CalculateDaysBetweenDates() As Integer
Dim dateFrom As DateTime = Convert.ToDateTime(datepickerFrom.Date)
Dim dateTo As DateTime = Convert.ToDateTime(datepickerto.Date)
Dim ts As TimeSpan = dateTo.Subtract(dateFrom)
If Convert.ToInt32(ts.Days) > 0 Then
radHalfday.Enabled = False
Else
radHalfday.Enabled = True
End If
Return 1
End Function
我有两个日期选择器,分别是 datepickerFrom 和 datepickerto。我想在用户选择超过 1 天并选中半天复选框然后单击按钮提交时显示错误消息,它将显示错误消息。
例如:A 选择 1/6/2022 - 3/6/2022,然后点击复选框选择半天。当 A 单击提交按钮时,它会显示一条错误消息,例如“抱歉,半天不能选择超过 1 个日期!”
这是我检查错误的代码
Private Function ErrorFree() As Boolean
If datepickerFrom.Date > datepickerto.Date Then
If chkHalfDay.Checked = True Then
DisplayMessage("error", "ERROR", "Sorry, You can't pick more than 1 date for half day!")
Return False
Exit Function
End If
End If
Return True
End Function
终于找到答案了!所以这是代码。然后我调用 datepickerFrom_DateChanged 和 datepickerto_DateChanged 中的函数。
Private Function CalculateDaysBetweenDates() As Integer
Dim dateFrom As DateTime = Convert.ToDateTime(datepickerFrom.Date)
Dim dateTo As DateTime = Convert.ToDateTime(datepickerto.Date)
Dim ts As TimeSpan = dateTo.Subtract(dateFrom)
If Convert.ToInt32(ts.Days) > 0 Then
radHalfday.Enabled = False
Else
radHalfday.Enabled = True
End If
Return 1
End Function