首頁‎ > ‎電子期刊‎ > ‎2005 年 第 11 期‎ > ‎

多角調課演算法初探(六)


摘要

  • 文章編號:20050804
  • 投稿日期:2005/07/25
  • 作者:董世尊、廖韋傑、陳冠廷、陳雅鳳
  • 備註:


壹、前言

在Sunset的排課系統中,從表單以及物件類別模組的程式運作上,在調課部份的表單主要為frmLPView,而在物件類別模組為 Scheduler、Appointments、who、Variables…等,利用裡面的Function、參數、函數的傳遞,構成了一個較單純的一 對一調課作業,本研究將解析表單、模組、程式間在調課部份的義意。

貳、調課之frmLPView表單解析

當畫面進入課表,在右上角會顯示「調課查詢」的按鈕,當使用者選擇課表中的某節次時,可以按此按鈕進行調課查詢,查詢是否有可調課節次與所選擇節次 進行調換作業,則程式流程也會擷取所選擇節次的所在地方,即時間表(例如:一般日校班、日校實驗班…等)、課表(資二仁、國一忠…等班級),當課表所在地 方確認後,則會對使用者所選擇的節次進行星期、節次的開始時間、上課時間、單雙週(單週-1、雙週-2、單雙週-3)的設定,之後利用上述資料判斷所選擇 節次的ID值,然後把值傳給IsEventExchangable,以便之後其他Function的運作。(表一)

Private Sub UpdateContent() 更新格子內容並重新整理

…………………………

For Each prdMember In ttCur.Periods 迴圈方式-For

    …………………………

If idXchgEvent <> 0 Then 給予cmdXchgEvent_Click中的idXchgEvent

                    If idXchgEvent = appTest.RefID Then                       

fgLPView.CellBackColor = &HC00000 格子背景為深藍色(調課本身)           

fgLPView.CellForeColor = &H80000005 字為白色

                    ElseIf idLast = appTest.RefID Then

                        If bLastXchgable Then

                            fgLPView.CellBackColor = &HFF8080 格子背景為紫色

                            fgLPView.CellForeColor = &H80000005 字為白色

                        End If

           ElseIf schLocal.IsEventExchangable(idXchgEvent, appTest.RefID) Then

           與原本的節次做比對作業,此時將函數值複製一份至Scheduler中的IsEventExchangable

                        fgLPView.CellBackColor = &HFF8080 格子背景為紫色

                        fgLPView.CellForeColor = &H80000005 字為白色

                        bLastXchgable = True

                    Else

                        bLastXchgable = False

                    End If

                End If

            End If

            idLast = appTest.RefID

        End If

        …………………………

Next prdMember迴圈方式-Next

…………………………

End Sub
  • 表二 frmLPView- UpdateContent

參、調課之物件類別模組解析

在Appointments的模組中,會有兩個Function,分別為GetAppointment和GetAppointments,在這兩個 地方主要是傳參數值回去給之前frmLPView中cmdXchgEvent_Click的 apsCur.GetAppointment(.WeekDay, .BeginTime, .Duration, nWeekFlag)的四個參數。(表三、表四)

Public Function GetAppointment(ByVal TestWeekDay As Integer, ByVal TestTime As Date, ByVal TestDuration As Integer, ByVal TestWeekFlag As Byte) As Appointment

    Dim apsResult As Appointments

     Set apsResult = GetAppointments(TestWeekDay, TestTime, TestDuration, TestWeekFlag)

     從班級課表的第一節課開始,複製一份星期、起始時間、上課時間、單雙週至GetAppointments

Function

     If apsResult.Count > 0 Then

        Set GetAppointment = apsResult(1) 第一個索引鍵的值為1

    Else

        Set GetAppointment = Nothing

    End If

End Function
  • 表三Appointments-GetAppointment

Public Function GetAppointments(ByVal TestWeekDay As Integer, ByVal TestTime As Date, ByVal TestDuration As Integer, ByVal TestWeekFlag As Byte) As Appointments

   …………………………

   Set apsResult = New Appointments

    For Each apMember In mCol

        With apMember

        If .WeekDay > TestWeekDay Then Exit For

        If (TestWeekDay = .WeekDay) And ((TestWeekFlag And .WeekFlag) > 0) Then

            nTimeDif = CInt((.BeginTime - TestTime) / CDate("0:1"))

            If nTimeDif >= TestDuration Then Exit For

            If nTimeDif >= 0 Then

                apsResult.Add apMember

            ElseIf -nTimeDif < .Duration Then

                apsResult.Add apMember

            End If

        End If

        End With

    Next

    Set GetAppointments = apsResult

End Function
  • 表四 Appointments-GetAppointments

在Scheduler模組中的IsEventExchangable Function是frmLPViewidXchgEvent中UpdateContent()的Function在做比對作業時會呼叫到的程式,主要是 將要調課的節次以及要比對的節次動作,會先比對節次長度,再進行呼叫另外一個TestSchedule Function去進行限制條件的判斷。(表五)

Public Function IsEventExchangable(ByVal EventIDA As Long, ByVal EventIDB As Long) As Boolean

   …………………………

  Dim nSaveWeekDay As Integer

  Dim nSavePeriodA As Integer 要調課的節次

  Dim nSaveWeekDayB As Integer

  Dim nSavePeriodB As Integer 要比對的節次

…………………………

Set evtA=mCEvents(CStr(EventIDA)) Ex1320280,要調課的節次ID

Set evtB=mCEvents(CStr(EventIDB)) Ex1320274,從第一節開始的節次ID

If evtA.Length <> evtB.Length Then Exit Function 節次長度判斷

   …………………………

    If nSaveWeekDayA <> 0 Then ReleaseEvent evtA 儲存原本的星期及節次

    If nSaveWeekDayB <> 0 Then ReleaseEvent evtB 儲存原本的星期及節次

    If nSaveWeekDayB <> 0 Then

        If TestSchedule(evtA, nSaveWeekDayB, nSavePeriodB) = 0 Then IsEventExchangable = True

    End If

    If IsEventExchangable And nSaveWeekDayA <> 0 Then

    If TestSchedule(evtB, nSaveWeekDayA, nSavePeriodA) <> 0 Then IsEventExchangable = False

    End If

   If nSaveWeekDayA <> 0 Then

   If TestSchedule(evtA, nSaveWeekDayA, nSavePeriodA) = 0 Then AllocEvent

    End If

    If nSaveWeekDayB <> 0 Then

        If TestSchedule(evtB, nSaveWeekDayB, nSavePeriodB) = 0 Then AllocEvent

    End If

End Function
  • 表五 Scheduler-IsEventExchangable

肆、結論

本期主要介紹frmLPView表單和Appointments、Scheduler模組的部份Function,未來將會釐清更多模組中的Function應用,並陸續刊至期刊中。以完整的介紹Sunset中調課部份程式

Comments