Kyle_Forward wrote:
...The users should only be able to schedule "M-F - 8a-4p"
So, i'd suggest to create
BusinessDay
class:
Public Class BusinessDay
Private dt As DateTime = DateTime.Now
Public Sub New(initialDate As DateTime)
Init(initialDate)
End Sub
Private Sub Init(selectedDT As DateTime)
dt = selectedDT
Dim daysToAdd As Integer = If(dt.DayOfWeek = DayOfWeek.Saturday, 2, If(dt.DayOfWeek = DayOfWeek.Sunday, 1, 0))
dt = dt.AddDays(daysToAdd)
Dim minDate As DateTime = dt.AddHours(-dt.Hour+8).AddMinutes(-dt.Minute)
Dim maxDate As DateTime = minDate.AddHours(8)
If dt> maxDate Or dt<minDate
Throw New Exception($"Selected date {dt.ToString("yyyy-MM-dd HH:mm")} is out out working hours (8AM - 4PM)!")
End If
End Sub
Public Overrides Function ToString() As String
Return dt.ToString("yyyy-MM-dd HH:mm")
End Function
End Class
Usage:
Dim selectedDT As DateTime = DateTimePick.Value
Dim bd As BusinessDay
Try
bd = New BusinessDay(selectedDT)
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
If bd Is Nothing Then
Exit Sub
End If