Function WO_Scheduler_Actions_Events(CtrlEntId, Event, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon.

    Name        :   WO_Scheduler_Actions_Events

    Description :   This function acts as a commuter module for all events related to this window.

    Notes       :   Commuter Modules are automatically called from the Promoted_Events function which is called by the
                    application-specific promoted event handler. This makes it possible to add QuickEvents that need to
                    execute Basic+ logic without having use the Form Designer to make the association, although this is
                    limited to the events which are currently promoted.

                    If the form needs to call the commuter module directly then the QuickEvent parameters should be
                    formatted like this:

                        '@SELF','@EVENT',['@PARAM1','@PARAMx']

    Parameters  :
        CtrlEntId   [in] -- The fully qualified name of the control calling the promoted event
        Event       [in] -- The event being executed. See the Notes section regarding "PRE" events
        Param1-15   [in] -- Additional event parameter holders
        EventFlow  [out] -- Set to 1 or 0 so the calling event knows whether or not to chain forward. See comments in
                            EVENT_SETUP insert

    History     :   (Date, Initials, Notes)
        06/12/17    dmb     Created initial commuter module.

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler
#Window WO_SCHEDULER_ACTIONS

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES
$insert SCHED_DET_EQUATES
$insert WO_LOG_EQUATES
$insert WO_SCHEDULE_EQUATES
$insert REACTOR_EQUATES
Equ LightGrey$  TO 239 + (239*256) + (239*65536)

WorkOrderCtrls      = 'OLE_DIV_WORK_ORDER_DETAILS,WO_NO_LABEL,WO_NO,WO_STEP_LABEL,WO_STEP,EPI_PART_LABEL,EPI_PART,DESCRIPTION_LABEL,DESCRIPTION,CUSTOMER_NAME_LABEL,CUSTOMER_NAME,'
WorkOrderCtrls     := 'TOTAL_WAFERS_LABEL,TOTAL_WAFERS,TOTAL_REMAINING_LABEL,TOTAL_REMAINING,PERCENT_COMPLETE_LABEL,PERCENT_COMPLETE'
AddDateCtrls        = 'DATE_LABEL,DATE'
DateRangeCtrls      = 'SCHEDULE_START_DATE_LABEL,SCHEDULE_START_DATE,SCHEDULE_END_DATE_LABEL,SCHEDULE_END_DATE,DAYS_LABEL,DAYS'
BlockOutCtrls       = 'START_BLOCK_OUT_LABEL,START_BLOCK_OUT,END_BLOCK_OUT_LABEL,END_BLOCK_OUT,OLE_DIV_BLOCK_OUT_DETAILS,DESCRIPTION_LABEL,DESCRIPTION'
CancelBlockOutCtrls = 'BLOCK_OUT_DATE_LABEL,BLOCK_OUT_DATE,OLE_DIV_BLOCK_OUT_DETAILS,DESCRIPTION_LABEL,DESCRIPTION'

Declare function    SRP_CodeCombo, SRP_Array, Schedule_Services, Database_Services, Work_Order_Services, SRP_Math, SRP_JSON
Declare subroutine  SRP_CodeCombo, obj_Appwindow, Center_Window, Schedule_Services, Form_Services, SRP_Show_Window, SRP_JSON
Declare function    Scheduling_Services, Reactor_Services

SubclassInfo    = Form_Services('FindSubclassControl')
Subclass        = SubclassInfo<1>

// Update the arguments so that the OpenInsight OLE event will treate the ActiveX event as a native event handler.
If Event EQ 'OLE' then
    Transfer Event to OIEvent
    Transfer Param1 to Event
    Transfer Param2 to Param1
    Transfer Param3 to Param2
    Transfer Param4 to Param3
    Transfer Param5 to Param4
    Transfer Param6 to Param5
    Transfer Param7 to Param6
    Transfer Param8 to Param7
end

GoToEvent Event for CtrlEntID

Return EventFlow else EVENT_CONTINUE$


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Events
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Event WINDOW.CREATE(CreateParam)

    Action  = CreateParam<1>
    ApptID  = CreateParam<2>

    // The ApptID (Appointment ID) from the Schedule control is the same as the Schedule Event Key ID.
    Set_Property(@Window, '@SCHED_DET_KEY_ID', ApptID)
    ReactorNo       = ApptID[1, '*']
    ScheduleDate    = ApptID[Col2() + 1, '*']
    Sequence        = ApptID[Col2() + 1, '*']
    If Sequence NE '' then
        ScheduleEvent   = Scheduling_Services('GetScheduleEvent', ReactorNo, ScheduleDate, Sequence, True$)
        GoSub ParseScheduleEvent
    end else
        WorkOrderNo = ''
        EpiPartNo   = ''
    end

    Set_Property(@Window : '.REACTOR_NO', 'TEXT', ReactorNo)
    Set_Property(@Window : '.DATE', 'INVALUE', ScheduleDate)
    Set_Property(@Window : '.MODIFY_DATE', 'INVALUE', ScheduleDate)
    Set_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE', ScheduleDate)
    Set_Property(@Window : '.START_BLOCK_OUT', 'INVALUE', ScheduleDate)
    Set_Property(@Window : '.END_BLOCK_OUT', 'INVALUE', ScheduleDate)
    Set_Property(@Window : '.BLOCK_OUT_DATE', 'INVALUE', ScheduleDate)
    Set_Property(@Window, '@ORIG_WORK_ORDER_NO', WorkOrderNo)

 	GoSub Setup_OLE_Controls

	Set_Property(@Window : '.CLOSE_BUTTON', 'NEXT', @Window : '.REACTOR_NO')

    Item    = 1 ; // Default item to select from the ShortcutBar.
    Begin Case
        Case Action _EQC 'ADD'
            Group   = 1
        Case Action _EQC 'MODIFY'
            Group   = 2
        Case Action _EQC 'CANCEL'
            Group   = 3
        Case Action _EQC 'ADDBLOCK'
            Group   = 4
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 1 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 2 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 2 : ';' : 2 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 3 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 4 : ';' : 2 : ']', False$)
        Case Action _EQC 'CANCELBLOCK'
            // Since the Cancel Block Out action is very specific, the other options
            // will be disabled.
            Group   = 4
            Item    = 2
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 1 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 2 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 2 : ';' : 2 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 3 : ';' : 1 : ']', False$)
            Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.ItemEnabled[' : 4 : ';' : 1 : ']', False$)
        Case Otherwise$
            Group   = 1
    End Case

    SRP_Show_Window(@Window, '', 'C', 'C', 1, '', False$, False$)
    Set_Property(@Window : '.OLE_SHORTCUTBAR', 'OLE.Selection', Group : ';' : Item)
    Send_Event(@Window : '.OLE_SHORTCUTBAR', 'OLE', 'OnClick', Group, Item)

end event


Event OLE_SHORTCUTBAR.OnClick(Group, Item, Point, Button, Shift, Ctrl)

    PreviousPage    = Get_Property(@Window, '@PREVIOUS_PAGE')
    GroupCaption    = Get_Property(CtrlEntId, 'GroupCaption[' : Group : ']')
    ItemCaption     = Get_Property(CtrlEntId, 'ItemCaption[' : Group : ';' : Item : ']')
    Set_Property(@Window, 'TEXT', 'Work Order Scheduler Actions - ' : GroupCaption : ' - ' : ItemCaption)

    Begin Case
        Case Group EQ 1
            // Add Actions

            Begin Case
                Case Item EQ 1
                    // Add New Work Order to this Reactor
                    Page            = 1
                    ClearControls   = 'WO_NO,EPI_PART,TOTAL_WAFERS,TOTAL_REMAINING,PERCENT_COMPLETE,SCHEDULE_END_DATE,DAYS,CUSTOMER_NAME,DESCRIPTION'
                    GoSub ClearControls
                    HideControls    = AddDateCtrls : @FM : BlockOutCtrls : @FM : CancelBlockOutCtrls
                    GoSub HideControls
                    ShowControls    = WorkOrderCtrls : @FM : DateRangeCtrls
                    GoSub ShowControls
                    EnableControls  = 'WO_NO,SCHEDULE_START_DATE'
                    GoSub EnableControls
                    Set_Property(@Window : '.OLE_SUBCLASS', 'OLE.OptionEnabled[' : @Window : ';WO_NO' : ']', True$)
                    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.SCHEDULE_START_DATE')
                    Set_Property(@Window : '.DESCRIPTION', 'NEXT', @Window : '.REACTOR_NO')
                    Set_Property(@Window : '.WO_NO', 'FOCUS', True$)
                    WorkOrderNo     = ''
                    SchedDetKeyID   = ''
                    GoSub UpdateWorkOrderList
                    GoSub UpdateReactorDetails
                    GoSub UpdateWorkOrderDetails
            End Case

        Case Group EQ 2
            // Modify Actions

            Begin Case
                Case Item EQ 1
                    // Current Work Order Schedule Only
                    Page            = 2
                    HideControls    = DateRangeCtrls : @FM : BlockOutCtrls : @FM : CancelBlockOutCtrls
                    GoSub HideControls
                    ShowControls    = AddDateCtrls : @FM : WorkOrderCtrls
                    GoSub ShowControls
                    DisableConTrols = 'WO_NO'
                    GoSub DisableControls
                    EnableControls  = 'DESCRIPTION'
                    GoSub EnableControls
                    Set_Property(@Window : '.OLE_SUBCLASS', 'OLE.OptionEnabled[' : @Window : ';WO_NO' : ']', False$)
                    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.DATE')
                    Set_Property(@Window : '.DATE', 'NEXT', @Window : '.DESCRIPTION')
                    Set_Property(@Window : '.DESCRIPTION', 'NEXT', @Window : '.REACTOR_NO')
                    SchedDetKeyID   = Get_Property(@Window, '@SCHED_DET_KEY_ID')
                    GoSub UpdateWorkOrderList
                    GoSub UpdateScheduleDetails
                    GoSub UpdateWorkOrderDetails

                Case Item EQ 2
                    // All Work Orders for this Reactor
                    Page    = 3
                    HideControls    = DateRangeCtrls : @FM : BlockOutCtrls  :@FM : CancelBlockOutCtrls
                    GoSub HideControls
                    ShowControls    = AddDateCtrls : @FM : WorkOrderCtrls
                    GoSub ShowControls
                    DisableConTrols = 'WO_NO,DESCRIPTION'
                    GoSub DisableControls
                    Set_Property(@Window : '.OLE_SUBCLASS', 'OLE.OptionEnabled[' : @Window : ';WO_NO' : ']', False$)
                    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.MODIFY_DATE')
                    Set_Property(@Window : '.MODIFY_DATE', 'NEXT', @Window : '.REACTOR_NO')
            End Case

        Case Group EQ 3
            // Cancel Actions

            Begin Case
                Case Item EQ 1
                    // All Work Orders for this Reactor
                    Page            = 4
                    HideControls    = AddDateCtrls : @FM : BlockOutCtrls : @FM : CancelBlockOutCtrls
                    GoSub HideControls
                    ShowControls    = WorkOrderCtrls : @FM : DateRangeCtrls
                    GoSub ShowControls
                    DisableControls = 'SCHEDULE_START_DATE,WO_NO,DESCRIPTION'
                    GoSub DisableControls
                    SchedDetKeyID   = Get_Property(@Window, '@SCHED_DET_KEY_ID')
                    GoSub UpdateScheduleDetails
                    GoSub UpdateWorkOrderDetails

            End Case

        Case Group EQ 4
            // Block Out Actions

            Begin Case
                Case Item EQ 1
                    // Add block out events.
                    Page    = 5
                    HideControls    = WorkOrderCtrls : @FM : DateRangeCtrls : @FM : AddDateCtrls : @FM : CancelBlockOutCtrls
                    GoSub HideControls
                    ShowControls    = BlockOutCtrls
                    GoSub ShowControls
                    EnableControls  = 'SAVE_BUTTON'
                    GoSub EnableControls
                    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.START_BLOCK_OUT')
                    Set_Property(@Window : '.END_BLOCK_OUT', 'NEXT', @Window : '.DESCRIPTION')
                    Set_Property(@Window : '.DESCRIPTION', 'NEXT', @Window : '.REACTOR_NO')
                    GoSub UpdateReactorDetails

                Case Item EQ 2
                    // Remove block out event.
                    Page    = 6
                    HideControls    = WorkOrderCtrls : @FM : DateRangeCtrls : @FM : AddDateCtrls : @FM : BlockOutCtrls
                    GoSub HideControls
                    ShowControls    = CancelBlockOutCtrls
                    GoSub ShowControls
                    DisableControls = 'REACTOR_NO,DESCRIPTION,BLOCK_OUT_DATE'
                    GoSub DisableControls
                    EnableControls  = 'SAVE_BUTTON'
                    GoSub EnableControls
                    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.BLOCK_OUT_DATE')
                    Set_Property(@Window : '.BLOCK_OUT_DATE', 'NEXT', @Window : '.DESCRIPTION')
                    Set_Property(@Window : '.DESCRIPTION', 'NEXT', @Window : '.REACTOR_NO')
                    SchedDetKeyID   = Get_Property(@Window, '@SCHED_DET_KEY_ID')
                    GoSub UpdateReactorDetails
                    GoSub UpdateBlockOutDetails

            End Case
    End Case

    Send_Event(@Window, 'PAGE', Page)
    Set_Property(@Window : '.REACTOR_NO', 'FOCUS', True$)
    Set_Property(@Window, '@PREVIOUS_PAGE', Page)

end event


Event REACTOR_NO.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event REACTOR_NO.LOSTFOCUS(Flag, FocusID)

    GoSub UpdateReactorDetails
    GoSub UpdateWorkOrderList

end event


Event DATE.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event DATE.OPTIONS()

    GoSub DisplayDatePicker

end event


Event SCHEDULE_START_DATE.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event SCHEDULE_START_DATE.LOSTFOCUS(Flag, FocusID)

    WorkOrderNo = Get_Property(@Window : '.WO_NO', 'TEXT')
    If WorkOrderNo NE '' then
        StartDate   = Get_Property(CtrlEntId, 'INVALUE')
        Days        = Get_Property(@Window : '.DAYS', 'DEFPROP')
        // Round up to create a full number of days (i.e., events).
        Days        = SRP_Math('NONE', Days + .49, '', 0)
        EndDate     = StartDate + Days - 1
        Set_Property(@Window : '.SCHEDULE_END_DATE', 'INVALUE', EndDate)
    end else
        Set_Property(@Window : '.SCHEDULE_END_DATE', 'INVALUE', '')
    end

end event


Event SCHEDULE_START_DATE.OPTIONS()

    GoSub DisplayDatePicker

end event


Event SCHEDULE_END_DATE.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event SCHEDULE_END_DATE.LOSTFOCUS(Flag, FocusID)

    StartDate   = Get_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE')
    EndDate     = Get_Property(CtrlEntId, 'INVALUE')
    If StartDate NE '' AND EndDate NE '' then
        Days    = EndDate - StartDate + 1
        Set_Property(@Window : '.DAYS', 'DEFPROP', Days)
    end

end event


Event SCHEDULE_END_DATE.OPTIONS()

    GoSub DisplayDatePicker

end event


Event MODIFY_DATE.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event MODIFY_DATE.OPTIONS()

    GoSub DisplayDatePicker

end event


Event START_BLOCK_OUT.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event START_BLOCK_OUT.OPTIONS()

    GoSub DisplayDatePicker

end event


Event END_BLOCK_OUT.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event END_BLOCK_OUT.OPTIONS()

    GoSub DisplayDatePicker

end event


Event WO_NO.LOSTFOCUS(Flag, FocusID)

    // User changed the value in this control. Update related controls.
    GoSub UpdateWorkOrderDetails

    If Error_Services('HasError') then
*        Error_Services('DisplayError')
    end

end event


Event DAYS.GOTFOCUS(PrevFocusID)

    GoSub SelectAll

end event


Event DAYS.LOSTFOCUS(Flag, FocusID)

    Days        = Get_Property(CtrlEntId, 'DEFPROP')
    Days        = SRP_Math('NONE', Days + .49, '', 0)
    StartDate   = Get_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE')
    EndDate     = Get_Property(CtrlEntId, 'INVALUE')
    If StartDate NE '' AND Days NE '' then
        EndDate = StartDate + Days - 1
        Set_Property(@Window : '.SCHEDULE_END_DATE', 'INVALUE', EndDate)
    end

end event


Event SAVE_BUTTON.CLICK()

    Parent                  = Get_Property(@Window, 'PARENT')
    Page                    = Get_Property(@Window, '@PREVIOUS_PAGE')
    ReactorNo               = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    Description             = Get_Property(@Window : '.DESCRIPTION', 'TEXT')
    ResponseData            = ''    ; // Data relevant to the specific action taken. See below for the actual data being returned.

    Begin Case
        Case Page EQ 1
            // Adding work order events.
            WorkOrderNo     = Get_Property(@Window : '.WO_NO', 'TEXT')
            Days            = Get_Property(@Window : '.DAYS', 'DEFPROP')
            // ** Temp code to contain the auto-adjuster problem with single-day events. **
            If Days LE 1 then Days = 2
            StartDate       = Get_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE')
            Description     = Get_Property(@Window : '.DESCRIPTION', 'INVALUE')
            ResponseData    = ReactorNo : @FM : WorkOrderNo : @FM : Days : @FM : StartDate : @FM : Description

        Case Page EQ 2
            // Modifying the current work order.
            WorkOrderNo     = Get_Property(@Window : '.WO_NO', 'TEXT')
            StartDate       = Get_Property(@Window : '.DATE', 'INVALUE')
            Description     = Get_Property(@Window : '.DESCRIPTION', 'INVALUE')
            ResponseData    = ReactorNo : @FM : WorkOrderNo : @FM : StartDate : @FM : Description

        Case Page EQ 3
            // Modifying the current and following work orders.
            WorkOrderNo     = Get_Property(@Window : '.WO_NO', 'TEXT')
            StartDate       = Get_Property(@Window : '.MODIFY_DATE', 'INVALUE')
            Description     = ''
            ResponseData    = ReactorNo : @FM : WorkOrderNo : @FM : StartDate : @FM : Description

        Case Page EQ 4
            // Cancelling work order events.
            WorkOrderNo     = Get_Property(@Window : '.WO_NO', 'TEXT')
            Transfer WorkOrderNo to ResponseData

        Case Page EQ 5
            // Adding block out events.
            StartDate       = Get_Property(@Window : '.START_BLOCK_OUT', 'INVALUE')
            EndDate         = Get_Property(@Window : '.END_BLOCK_OUT', 'INVALUE')
            If EndDate EQ '' then EndDate = StartDate
            Description     = Get_Property(@Window : '.DESCRIPTION', 'INVALUE')
            ResponseData    = ReactorNo : @FM : StartDate : @FM : EndDate : @FM : Description

        Case Page EQ 6
            // Cancelling block out event. Just return the schedule key passed in.
            ResponseData    = Get_Property(@Window, '@SCHED_DET_KEY_ID')

    End Case

    End_Dialog(@Window, ResponseData)

end event


Event CLOSE_BUTTON.CLICK()

    End_Dialog(@Window, '')
   
end event


Event OLE_SUBCLASS.OnOptionClick(CtrlId)

    Send_Event(CtrlId, 'OPTIONS')

end event


Event OLE_SUBCLASS.OnComboClick(CtrlId)

    Send_Event(CtrlId, 'LOSTFOCUS')

end event


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Setup_OLE_Controls:

    Ctrl        = @Window : '.OLE_SHORTCUTBAR'
    Set_Property(Ctrl, 'OLE.Border', 'XP Flat')
    Set_Property(Ctrl, 'OLE.Theme', 'Office2000')
    Set_Property(Ctrl, 'OLE.SelectBehavior', 'S' : @FM : 'S')
    Set_Property(Ctrl, 'OLE.HotTrackStyle', 'Item')
    Set_Property(Ctrl, 'OLE.GroupCount', 4)
    Set_Property(Ctrl, 'OLE.GroupExpandable[All]', False$)
    Set_Property(Ctrl, 'OLE.GroupEnabled[All]', False$)
    Set_Property(Ctrl, 'OLE.GroupCaption[1]', 'Add Actions')
    Set_Property(Ctrl, 'OLE.GroupItemCount[1]', 1)
    Set_Property(Ctrl, 'OLE.ItemCaption[1;1]', 'Work Order Events')
    Set_Property(Ctrl, 'OLE.GroupCaption[2]', 'Modify Actions')
    Set_Property(Ctrl, 'OLE.GroupItemCount[2]', 2)
    Set_Property(Ctrl, 'OLE.ItemCaption[2;1]', 'Current Work Order Event')
    Set_Property(Ctrl, 'OLE.ItemCaption[2;2]', 'Current+Future Work Order Events')
    Set_Property(Ctrl, 'OLE.GroupCaption[3]', 'Cancel Actions')
    Set_Property(Ctrl, 'OLE.GroupItemCount[3]', 1)
    Set_Property(Ctrl, 'OLE.ItemCaption[3;1]', 'Work Order Event')
    Set_Property(Ctrl, 'OLE.GroupCaption[4]', 'Block Out Actions')
    Set_Property(Ctrl, 'OLE.GroupItemCount[4]', 2)
    Set_Property(Ctrl, 'OLE.ItemCaption[4;1]', 'Add Block Out Events')
    Set_Property(Ctrl, 'OLE.ItemCaption[4;2]', 'Cancel Block Out Event')
    Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnClick', 1)
    Ctrl        = @Window : '.OLE_SUBCLASS'
    DateCtrls   = 'DATE,SCHEDULE_START_DATE,MODIFY_DATE,START_BLOCK_OUT,END_BLOCK_OUT'
    For Each DateCtrl in DateCtrls using ','
        EditLine    = @Window : '.' : DateCtrl
        Handle      = Get_Property(EditLine, 'HANDLE')
        Send_Message(Ctrl, 'OLE.Subclass', Handle, EditLine)
        EditLine    = @Window : ';' : DateCtrl
        Set_Property(Ctrl, 'OLE.OptionButton[' : EditLine : ']', True$)
        Set_Property(Ctrl, 'OLE.OptionImage[' : EditLine : ']', 'bmps\calendar.png')
    Next DateCtrl

    // Get the current reactor type and size so the GetReactor and GetUnscheduledWorkOrders service results can be filtered
    // down to only those items that match the same type and size.
    ReactorNo       = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    ReactorRec      = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
    ReactorType     = ReactorRec<REACTOR_REACT_TYPE$>
    SusceptorSize   = ReactorRec<REACTOR_SUSC_POCKET_SIZE$>
    EditLine    = @Window : '.REACTOR_NO'
    Handle      = Get_Property(EditLine, 'HANDLE')
    Send_Message(Ctrl, 'OLE.Subclass', Handle, EditLine)
    EditLine    = @Window : ';REACTOR_NO'
*    Reactors    = Schedule_Services('GetReactors', ReactorType, SusceptorSize)  ; // This returns an array suited for the SRP Schedule control.
    Reactors    = Schedule_Services('GetReactors', ReactorType)                 ; // This returns an array suited for the SRP Schedule control.
    Reactors    = Reactors[1, @RM]
    Reactors    = SRP_Array('Rotate', Reactors)
    Reactors    = Delete(Reactors, 1, 0, 0)
    Reactors    = Delete(Reactors, 1, 0, 0)
    Reactors    = Delete(Reactors, 1, 0, 0)
    Reactors    = Delete(Reactors, 3, 0, 0)
    Reactors    = Delete(Reactors, 3, 0, 0)
    Convert @FM to @TM in Reactors
    Convert @VM to @STM in Reactors
    Swap \0D0A\ with ' / ' in Reactors
    Combo       = ''
    Combo<1>    = 1
    Combo<2, 1> = 'Reactor No' : @TM : 'Type / Size'
    Combo<2, 2> = 'L' : @STM : 'DYN' : @TM : 'L' : @STM : 'DYN'
    Combo<2, 3> = Reactors
    Combo<2, 4> = 1
    Combo<2, 5> = 1
    Combo<2, 6> = 0
    Combo<2, 9> = 1
    Combo<2,10> = 0
    Combo<2,11> = 0
    Combo<2,12> = 1
    Combo<2,24> = 0
    Set_Property(Ctrl, 'OLE.Combo[' : EditLine : ']', Combo)

    EditLine        = @Window : '.WO_NO'
    Handle          = Get_Property(EditLine, 'HANDLE')
    Send_Message(Ctrl, 'OLE.Subclass', Handle, EditLine)
    Combo       = ''
    Combo<1>    = 1
    Combo<2, 1> = 'Work Order' : @TM : 'Epi Part' : @TM : 'Customer' : @TM : 'Reactor Type'
    Combo<2, 2> = 'L' : @STM : 'DYN' : @TM : 'L' : @STM : 'DYN' : @TM : 'L' : @STM : 'DYN' : @TM : 'L' : @STM : 'DYN'
    Combo<2, 3> = ''
    Combo<2, 4> = 1
    Combo<2, 5> = 1
    Combo<2, 6> = 0
    Combo<2, 9> = 1
    Combo<2,10> = 0
    Combo<2,11> = 0
    Combo<2,12> = 1
    Combo<2,24> = 0
    EditLine        = @Window : ';WO_NO'
    Set_Property(@Window : '.OLE_SUBCLASS', 'OLE.Combo[' : EditLine : ']', Combo)
 	Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnOptionClick', 1)
 	Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnComboClick', 1)

return


SelectAll:

    Set_Property(CtrlEntId, 'SELECTION', 1 : @FM : 999)

return


UpdateScheduleDetails:

    ReactorNo       = SchedDetKeyID[1, '*']
    ScheduleDate    = SchedDetKeyID[Col2() + 1, '*']
    Sequence        = SchedDetKeyID[Col2() + 1, '*']
    ScheduleEvent   = Scheduling_Services('GetScheduleEvent', ReactorNo, ScheduleDate, Sequence, True$)
    GoSub ParseScheduleEvent
    Set_Property(@Window : '.WO_NO', 'TEXT', WorkOrderNo)
    Set_Property(@Window : '.WO_STEP', 'TEXT', WorkOrderStep)
    Set_Property(@Window : '.DESCRIPTION', 'TEXT', Description)
    Begin Case
        Case ReactorType _EQC 'EPP' ; ReactorType = 'EpiPro'
        Case ReactorType _EQC 'GAN' ; ReactorType = 'GaN'
    End Case
    Set_Property(@Window : '.REACTOR_TYPE', 'TEXT', ReactorType)
    Set_Property(@Window : '.REACTOR_SIZE', 'TEXT', SusceptorSize)

return


UpdateReactorDetails:

    ReactorNo   = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    Reactor     = Reactor_Services('GetReactor', ReactorNo)
    GoSub ParseReactor
    Begin Case
        Case ReactorType _EQC 'EPP' ; ReactorType = 'EpiPro'
        Case ReactorType _EQC 'GAN' ; ReactorType = 'GaN'
    End Case
    SRP_JSON(objReactor, 'RELEASE')
    Set_Property(@Window : '.REACTOR_TYPE', 'TEXT', ReactorType)
    Set_Property(@Window : '.REACTOR_SIZE', 'TEXT', SusceptorSize)

return


UpdateWorkOrderDetails:

    If Assigned(Page) else Page = Get_Property(@Window, 'VPOSITION')<1>
    WorkOrderNo     = Get_Property(@Window : '.WO_NO', 'TEXT')
    If WorkOrderNo NE '' then
        WorkOrder   = Work_Order_Services('GetWorkOrder', WorkOrderNo, True$)
        GoSub ParseWorkOrder
        AdjustedDays    = Scheduling_Services('GetAdjustedDays', WorkOrderNo)
        Set_Property(@Window : '.EPI_PART', 'TEXT', EpiPartNo)
        Set_Property(@Window : '.TOTAL_WAFERS', 'TEXT', TotalWafers)
        Set_Property(@Window : '.TOTAL_REMAINING', 'TEXT', WafersRemaining)
        Set_Property(@Window : '.PERCENT_COMPLETE', 'TEXT', Oconv(Complete, 'MD0[ %]S'))
        Set_Property(@Window : '.CUSTOMER_NAME', 'TEXT', CustNameShort)
        If Page EQ 4 then
            // Start Date might not be correct since it defaults to the date the user was viewing from the Scheduler.
            // Cancelled work order events will always use the true start date as it appears in the current reactor.
            // The current end date already on the schedule should be correct so it will be used.
            WOScheduleRow   = Database_Services('ReadDataRow', 'WO_SCHEDULE', WorkOrderNo)
            SchedDetKeys    = WOScheduleRow<WO_SCHEDULE_SCHED_DET_KEY_IDS$>
            If SchedDetKeys NE '' then
                ReactorNo       = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
                NumSchedKeys    = DCount(SchedDetKeys, @VM)
                // Loop through the list of schedule detail keys and remove those belonging
                // to another reactor than the one we are working on.
                For SchedKeyCnt = NumSchedKeys to 1 Step -1
                    SchedDetKey = SchedDetKeys<0, SchedKeyCnt>
                    If Field(SchedDetKey, '*', 1) NE ReactorNo then
                        SchedDetKeys    = Delete(SchedDetKeys, 0, SchedKeyCnt, 0)
                    end
                Next SchedKeyCnt
                // Sort the remaining schedule detail keys so the oldest one is at the top of the list.
                SchedDetKeys    = SRP_Array('SortRows', SchedDetKeys, 'AR2', 'LIST', @VM, '*')
                StartDate       = Field(SchedDetKeys<1, 1>, '*', 2)
                SchedDetKeys    = SRP_Array('SortRows', SchedDetKeys, 'DR2', 'LIST', @VM, '*')
                EndDate         = Field(SchedDetKeys<1, 1>, '*', 2)
                AdjustedDays    = EndDate - StartDate + 1
            end else
                StartDate       = ''
                EndDate         = ''
                AdjustedDays    = ''
            end
            Set_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE', StartDate)
        end else
            // Calculate the end date based on the adjusted days.
            StartDate       = Get_Property(@Window : '.SCHEDULE_START_DATE', 'INVALUE')
            EndDate         = StartDate + AdjustedDays - 1
        end
        Set_Property(@Window : '.SCHEDULE_END_DATE', 'INVALUE', EndDate)
        Set_Property(@Window : '.DAYS', 'DEFPROP', AdjustedDays)
        Set_Property(@Window : '.SAVE_BUTTON', 'ENABLED', True$)
    end else
        Set_Property(@Window : '.EPI_PART', 'TEXT', '')
        Set_Property(@Window : '.TOTAL_WAFERS', 'TEXT', '')
        Set_Property(@Window : '.TOTAL_REMAINING', 'TEXT', '')
        Set_Property(@Window : '.PERCENT_COMPLETE', 'TEXT', '')
        Set_Property(@Window : '.SCHEDULE_END_DATE', 'INVALUE', '')
        Set_Property(@Window : '.DAYS', 'DEFPROP', '')
        Set_Property(@Window : '.SAVE_BUTTON', 'ENABLED', False$)
    end

return


UpdateBlockOutDetails:

    ScheduleDetail  = Schedule_Services('GetScheduleDetail', SchedDetKeyID)
    Set_Property(@Window : '.DESCRIPTION', 'TEXT', ScheduleDetail<SCHED_DET_DESC$>)

return


DisplayDatePicker:

    Date    = Get_Property(CtrlEntId, 'INVALUE')
    NewDate = Dialog_Box('NDW_DATEPICKER', @Window, Date)
    If NewDate NE '' then
        Set_Property(CtrlEntId, 'INVALUE', NewDate)
        Send_Event(CtrlEntId, 'LOSTFOCUS')
    end

return


ClearControls:

    Convert ',' to @FM in ClearControls
    For Each Ctrl in ClearControls using @FM
        Set_Property(@Window : '.' : Ctrl, 'TEXT', '')
    Next Ctrl

return


HideControls:

    Convert ',' to @FM in HideControls
    For Each Ctrl in HideControls using @FM
        Set_Property(@Window : '.' : Ctrl, 'VISIBLE', False$)
    Next Ctrl

return


ShowControls:

    Convert ',' to @FM in ShowControls
    For Each Ctrl in ShowControls using @FM
        Set_Property(@Window : '.' : Ctrl, 'VISIBLE', True$)
    Next Ctrl

return


EnableControls:

    Convert ',' to @FM in EnableControls
    For Each Ctrl in EnableControls using @FM
        Set_Property(@Window : '.' : Ctrl, 'ENABLED', True$)
        If Get_Property(@Window : '.' : Ctrl, 'TYPE') EQ 'EDITFIELD' then
            Set_Property(@Window : '.' : Ctrl, 'BACKCOLOR', White$)
        end
    Next Ctrl

return


DisableControls:

    Convert ',' to @FM in DisableControls
    For Each Ctrl in DisableControls using @FM
        Set_Property(@Window : '.' : Ctrl, 'ENABLED', False$)
        If Get_Property(@Window : '.' : Ctrl, 'TYPE') EQ 'EDITFIELD' then
            Set_Property(@Window : '.' : Ctrl, 'BACKCOLOR', LightGrey$)
        end
    Next Ctrl

return


UpdateWorkOrderList:

    If Assigned(Page) else Page = Get_Property(@Window, 'VPOSITION')<1>
    WorkOrderNos  = ''
    Begin Case
        Case Page EQ 1
            // Adding work order.
            WorkOrderNos  = Get_Property(@Window, '@UNSCHEDULED_WORK_ORDERS')
            If WorkOrderNos EQ '' then
                // Get the current reactor type and size so the GetReactor and GetUnscheduledWorkOrders service results can be filtered
                // down to only those items that match the same type and size.
                ReactorNo       = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
                Reactor         = Reactor_Services('GetReactor', ReactorNo)
                GoSub ParseReactor
                WorkOrderNos    = Work_Order_Services('GetUnscheduledWorkOrders', ReactorType)
                WorkOrderNos    = SRP_Array('Rotate', WorkOrderNos)
                Convert @FM to @TM in WorkOrderNos
                Convert @VM to @STM in WorkOrderNos
                Set_Property(@Window, '@UNSCHEDULED_WORK_ORDERS', WorkOrderNos)
            end

        Case Page EQ 2
            // Modifying work order.
            WorkOrderNo     = Get_Property(@Window, '@ORIG_WORK_ORDER_NO')
            Set_Property(@Window : '.WO_NO', 'TEXT', WorkOrderNo)

        Case Page EQ 3
            // Modifying work order.
            WorkOrderNo     = Get_Property(@Window, '@ORIG_WORK_ORDER_NO')
            Set_Property(@Window : '.WO_NO', 'TEXT', WorkOrderNo)

        Case Page EQ 5
    End Case

    EditLine    = @Window : ';WO_NO'
    Set_Property(@Window : '.OLE_SUBCLASS', 'OLE.ComboData[' : EditLine : ']', WorkOrderNos)

return


ParseScheduleEvent:

    If Assigned(objScheduleEvent) else objScheduleEvent = 0
    If objScheduleEvent LE 0 then
        SRP_JSON(objScheduleEvent, 'PARSE', ScheduleEvent)
    end
    If objScheduleEvent GT 0 then
        objReactor          = SRP_JSON(objScheduleEvent, 'GET', 'Reactor')
        GoSub ParseReactor
        ScheduleDate        = SRP_JSON(objScheduleEvent, 'GETVALUE', 'ScheduleDate')
        ScheduleDate        = Iconv(ScheduleDate, 'D')
        Sequence            = SRP_JSON(objScheduleEvent, 'GETVALUE', 'Sequence')
        BackColor           = SRP_JSON(objScheduleEvent, 'GETVALUE', 'BackColor')
        ForeColor           = SRP_JSON(objScheduleEvent, 'GETVALUE', 'ForeColor')
        ModifiedDTM         = SRP_JSON(objScheduleEvent, 'GETVALUE', 'ModifiedDTM')
        BlockOut            = Iconv(SRP_JSON(objScheduleEvent, 'GETVALUE', 'BlockOut'), 'BYes,No')
        BlockOutType        = SRP_JSON(objScheduleEvent, 'GETVALUE', 'BlockOutType')
        Description         = SRP_JSON(objScheduleEvent, 'GETVALUE', 'Note')
        StartTime           = Iconv(SRP_JSON(objScheduleEvent, 'GETVALUE', 'StartTime'), 'MT')
        EndTime             = Iconv(SRP_JSON(objScheduleEvent, 'GETVALUE', 'EndTime'), 'MT')
        objWorkOrder        = SRP_JSON(objScheduleEvent, 'GET', 'WorkOrder')
        GoSub ParseWorkOrder
        FirstSchedDetKeyID  = SRP_JSON(objScheduleEvent, 'GETVALUE', 'FirstSchedDetKeyID')
        FirstReactorNo      = FirstSchedDetKeyID[1, '*']
        FirstScheduleDate   = Oconv(FirstSchedDetKeyID[Col2() + 1, '*'], 'D4/')
        LastSchedDetKeyID   = SRP_JSON(objScheduleEvent, 'GETVALUE', 'LastSchedDetKeyID')
        LastReactorNo       = LastSchedDetKeyID[1, '*']
        LastScheduleDate    = Oconv(LastSchedDetKeyID[Col2() + 1, '*'], 'D4/')
        TotalScheduledDays  = SRP_JSON(objScheduleEvent, 'GETVALUE', 'TotalScheduledDays')
        SRP_JSON(objScheduleEvent, 'RELEASE')
    end else
        
    end

return


ParseReactor:

    If Assigned(objReactor) else objReactor = 0
    If objReactor LE 0 then
        SRP_JSON(objReactor, 'PARSE', Reactor)
    end
    If objReactor GT 0 then
        ReactorNo       = SRP_JSON(objReactor, 'GETVALUE', 'ReactorNumber')
        ReactorType     = SRP_JSON(objReactor, 'GETVALUE', 'Type')
        SusceptorSize   = SRP_JSON(objReactor, 'GETVALUE', 'SusceptorSize')
        AssignmentCode  = SRP_JSON(objReactor, 'GETVALUE', 'AssignmentCode')
        SecondChamber   = SRP_JSON(objReactor, 'GETVALUE', 'SecondChamber')
        SRP_JSON(objReactor, 'RELEASE')
    end else
        
    end

return


ParseWorkOrder:

    If Assigned(objWorkOrder) else objWorkOrder = 0
    If objWorkOrder LE 0 then
        SRP_JSON(objWorkOrder, 'PARSE', WorkOrder)
    end
    If objWorkOrder GT 0 then
        WorkOrderNo         = SRP_JSON(objWorkOrder, 'GETVALUE', 'WorkOrderNumber')
        EpiPartNo           = SRP_JSON(objWorkOrder, 'GETVALUE', 'EpiPartNumber')
        PSN                 = SRP_JSON(objWorkOrder, 'GETVALUE', 'PSN')
        Recipe              = SRP_JSON(objWorkOrder, 'GETVALUE', 'Recipe')
        HotLot              = Iconv(SRP_JSON(objWorkOrder, 'GETVALUE', 'HotLot'), 'BYes,No')
        Closed              = Iconv(SRP_JSON(objWorkOrder, 'GETVALUE', 'Closed'), 'BYes,No')
        TotalWafers         = SRP_JSON(objWorkOrder, 'GETVALUE', 'TotalWafers')
        WafersRemaining     = SRP_JSON(objWorkOrder, 'GETVALUE', 'WafersRemaining')
        PercentComplete     = SRP_JSON(objWorkOrder, 'GETVALUE', 'PercentComplete')
        CustNameShort       = SRP_JSON(objWorkOrder, 'GETVALUE', 'Company.NameShort')
        SRP_JSON(objWorkOrder, 'RELEASE')
    end else
        
    end

return
