Private Function TestSchedule(ByVal NewEvent As CEvent, ByVal WeekDay As Integer, ByVal PeriodNo As Integer) As Integer
Dim intTempVal As Integer
Dim bPass As Boolean
Dim prdBreak As Period
Dim prdTest As Period
Dim prdsTest As Periods
Set evtTested = Nothing
With NewEvent
Set whrTest = IIf(IsNullValue(.WhereID), Nothing, mWheres(CStr(.WhereID)))
Set whmTest = IIf(IsNullValue(.WhomID), Nothing, mWhoms(CStr(.WhomID)))
Set whoTest = IIf(IsNullValue(.WhoID), Nothing, mWhos(CStr(.WhoID)))
à判斷場地、班級、教師是否有值
Set prdsTest = mTimeTables(CStr(.TimeTableID)).Periods
à取得時間表的值
Set prdBreak = prdsTest.GetBreakPeriod(WeekDay) à取得某星期午休時段
Set prdTest = prdsTest.GetPeriod(WeekDay, PeriodNo)
If prdTest Is Nothing Then
TestSchedule = tsCannotFità傳入參數=8,在其他模組需要時傳入其值並顯示「太胖了,塞不下」字樣
Exit Function
End If
Set prdsUse = New Periods
prdsUse.Add prdTest
bPass = ((Not (prdBreak Is Nothing)) And (Not .AllowLongBreak)) And (.Length > 1)
If bPass Then bPass = ((prdTest.BeginTime - prdBreak.BeginTime) < 0)
à利用bPass的判斷,來檢查是否有跨中午的情況
For intTempVal = PeriodNo + 1 To PeriodNo + .Length - 1
Set prdTest = prdsTest.GetPeriod(WeekDay, intTempVal)
If prdTest Is Nothing Then
TestSchedule = tsCannotFit
Exit Function
End If
If Not whrTest Is Nothing Then
If Not (IsNullValue(prdTest.LocID) Or IsNullValue(whrTest.LocID)) Then
If prdTest.LocID <> whrTest.LocID Then
TestSchedule = tsLocConflict
Exit Function
End If
End If
End If
prdsUse.Add prdTest
Next intTempVal à檢查場地與節次之間的有效性,並讓三節連續課程,一節一節的陸續加入做檢查。
If bPass Then
If (prdTest.BeginTime - prdBreak.BeginTime) > 0 Then
TestSchedule = tsLongBreak
Exit Function
End If
End Ifà檢查跨中午條件
If .WeekDayOp > 0 Then
If IsNumeric(.WeekDayVar) Then
Select Case .WeekDayOp
Case opEqual
bPass = (WeekDay = CInt(.WeekDayVar))
Case opGreater
bPass = (WeekDay > CInt(.WeekDayVar))
Case opGreaterOrEqual
bPass = (WeekDay >= CInt(.WeekDayVar))
Case opLess
bPass = (WeekDay < CInt(.WeekDayVar))
Case opLessOrEqual
bPass = (WeekDay <= CInt(.WeekDayVar))
Case opNotEqual
bPass = (WeekDay <> CInt(.WeekDayVar))
Case Else
bPass = True
End Select
If Not bPass Then
TestSchedule = tsWeekDayConflictà傳入參數1,星期條件不符。
Exit Function
End If
ElseIf .WeekDayOp = opEqual Then
If mWVar.Exists(.WeekDayVar) Then
If Not mWVar(.WeekDayVar).Fit(WeekDay) Then
TestSchedule = tsWeekDayConflictà傳入參數1,星期條件不符。
Exit Function
End If
End If
End If
End Ifà判斷是否有星期條件
………
……
………
If Not whmTest Is Nothing Then
If .AllowDuplicate Then
intTempVal=whmTest.Appointments.CheckWhom(prdsUse, NullValue, .WeekFlag)
Else
intTempVal=whmTest.Appointments.CheckWhom(prdsUse, .WhatID, .WeekFlag)
End If
If intTempVal <> 0 Then
Select Case intTempVal
Case 1
TestSchedule = tsWhomConflictà傳入參數5,已排其他科目,請勿插隊。
Case 3
TestSchedule = tsDupWhatà傳入參數6,科目重覆。
Case Else
TestSchedule = tsWhomConflictà傳入參數5,已排其他科目,請勿插隊。
End Select
Exit Function
End If
End Ifà檢查班級及科目是否允許重覆排課之情況發生。
If Not whrTest Is Nothing Then
If Not whrTest.LocOnly Then
If whrTest.Capacity > 1 Then à whrTest.Capacity是指此場地的容納量。
intTempVal = 1
bPass = False
Do Until intTempVal > whrTest.Capacity
whrTest.UseAppointments intTempVal
If whrTest.Appointments.IsFreePeriods(prdsUse, .WeekFlag) Then
nWhereAvailable = intTempVal
bPass = True
Exit Do
End If
intTempVal = intTempVal + 1
Loop
If Not bPass Then
TestSchedule = tsWhereConflictà傳入參數7;場地已滿。
Exit Function
End If
ElseIf Not whrTest.Appointments.IsFreePeriods(prdsUse, .WeekFlag) Then
TestSchedule = tsWhereConflictà傳入參數7;場地已滿。
Exit Function
End If
End If
End If
If Not whoTest Is Nothing Then
If whoTest.Capacity > 1 ThenàwhoTest.Capacity是指某位老師所教的班級數量
intTempVal = 1
bPass = False
Do Until intTempVal > whoTest.Capacity
whoTest.UseAppointments intTempVal
If whoTest.Appointments.CheckWho(prdsUse, mDistances, .WeekFlag) = 0 Then
nWhoAvailable = intTempVal
bPass = True
Exit Do
End If
intTempVal = intTempVal + 1
Loop
If Not bPass Then
TestSchedule = tsWhoConflictà傳入參數3;本尊太忙,分身乏術。
Exit Function
End If
Else
………
……
………
End Function
|