Function Scheduler_Actions_Add_Block_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        :   Scheduler_Actions_Add_Block_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)
        01/18/2021    djs     Created initial commuter module.

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

#pragma precomp SRP_PreCompiler
#Window SCHEDULER_ACTIONS_ADD_BLOCK

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES
$insert SCHED_DET_NG_EQUATES
$insert WO_LOG_EQUATES
$insert WO_SCHEDULE_NG_EQUATES
$insert REACTOR_EQUATES

Equ OI_DISABLED_GREY$   to  239 + (239*256) + (239*65536)
Equ DEFAULT_DURATION$   to  8

WorkOrderCtrls      = 'OLE_DIV_WORK_ORDER_DETAILS,WO_NO_LABEL,WO_NO,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'
DateRangeCtrls      = 'SCHEDULE_START_DTM_LABEL,SCHEDULE_START_DTM,SCHEDULE_END_DTM_LABEL,SCHEDULE_END_DTM,DAYS_LABEL,DAYS'

Declare function    SRP_Array, Schedule_Services_Dev, Database_Services, Work_Order_Services, SRP_Math, Datetime
Declare function    Epi_Part_Services
Declare subroutine  obj_Appwindow, Center_Window, Schedule_Services_Dev, Form_Services, SRP_Show_Window
Declare subroutine  Form_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

Type = Get_Property(CtrlEntId, 'TYPE')

If ( (Type EQ 'RADIOBUTTON') or (Type EQ 'CHECKBOX') ) then
    Convert ' ' to '_' in CtrlEntID
end

If Type EQ 'RADIOBUTTON' then GoSub RadioButton
If Type EQ 'CHECKBOX' then GoSub UpdateChkBoxes

GoToEvent Event for CtrlEntID

Return EventFlow else EVENT_CONTINUE$


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

Event WINDOW.CREATE(CreateParam)

    ReactorNo     = CreateParam<1>
    SchedStartDTM = CreateParam<2>
    SchedDetNGKey = CreateParam<3>
    Set_Property(@Window, '@SCHED_START_DTM', SchedStartDTM)
    Set_Property(@Window : '.REACTOR_NO', 'TEXT', ReactorNo)
    NextStartDTM = '' 

    If SchedDetNGKey EQ '' then
        // Get last work order on schedule for this reactor
        ReactSchedEvents = Xlate('REACTOR', ReactorNo, 'SCHED_EVENTS', 'X')
        LastEventKey     = ReactSchedEvents[-1, 'B':@VM]
        Set_Property(@Window, '@SCHED_EVENT_KEY', LastEventKey)
        If LastEventKey NE '' then
            WONo = Xlate('SCHED_DET_NG', LastEventKey, 'WO_NO', 'X')
            NextStartDTM = Xlate('SCHED_DET_NG', LastEventKey, 'STOP_DTM', 'X')
            Set_Property(@Window : '.WO_NO', 'TEXT', WONo)
        end
    end else
        Set_Property(@Window, '@SCHED_EVENT_KEY', SchedDetNGKey)
        WONo         = Xlate('SCHED_DET_NG', SchedDetNGKey, 'WO_NO', 'X')
        NextStartDTM = Xlate('SCHED_DET_NG', SchedDetNGKey, 'STOP_DTM', 'X')
        Set_Property(@Window : '.WO_NO', 'TEXT', WONo)
    end
    
    Set_Property(@Window, '@NEXT_START_DTM', NextStartDTM)
    If NextStartDTM NE '' then
        StartDTM  = NextStartDTM
    end else
        StartDTM  = SchedStartDTM
    end
    Set_Property(@Window : '.EDL_BLOCK_START_DTM', 'INVALUE', StartDTM)
    
    ChkBoxControls  = 'CHK_GATE_VALVE_CHG,CHK_TUBE_CHG_6_MONTHS,CHK_TUBE_CHG_1_YEAR,CHK_TUBE_CHG_5_YEARS,'
    ChkBoxControls := 'CHK_TUBE_CHG_10_YEARS,CHK_SCRUBBER_WORK,CHK_OTHER,CHK_QUAL_PLAN,CHK_OUT_OF_SERVICE,'
    ChkBoxControls := 'CHK_DOWN_NO_MATERIAL,CHK_DOWN_TIME'
    Swap ',' with @VM in ChkBoxControls
    Set_Property(@Window, '@CHKBOX_CONTROLS', ChkBoxControls)
    
    GoSub PopulateControls
    GoSub EnableRadioButton
    
    SRP_Show_Window(@Window, '', 'C', 'C', 1, '', False$, False$)
    
end event


Event WINDOW.CLOSE(CancelFlag)
    
end event


Event SAVE_BUTTON.CLICK()

    ResponseData   = ''
    WorkOrder      = Get_Property(@Window : '.WO_NO', 'TEXT')
    ReactorNo      = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    // Get block out type
    ChkBoxControl  = ''
    ChkBoxControls = Get_Property(@Window, '@CHKBOX_CONTROLS')
    For each ChkBoxControl in ChkBoxControls using @VM setting vPos
        Checkmark = Get_Property(@Window : '.' : ChkBoxControl, 'CHECK')
    Until Checkmark EQ True$
    Next ChkBoxControl
    If ChkBoxControl NE '' then
        Comment      = ''
        Duration     = ''
        Option       = ''
        BlockComment = Get_Property(@Window : '.EDL_COMMENT', 'TEXT')            
        BlockType    = Get_Property(@Window : '.' : ChkBoxControl, 'TEXT')
        If ( (BlockType EQ 'Out of Service (OOS)') or (BlockType EQ 'Down No Material (DNM)') or (BlockType EQ 'Factory Down Time') ) then
            // Hard block
            If BlockType EQ 'Factory Down Time' then
                BlockOption = Get_Property(@Window:'.RDO_REACTORS', 'VALUE')
            end else
                BlockOption = ''
            end
            BlockStartDTM = Get_Property(@Window : '.EDL_BLOCK_START_DTM', 'INVALUE')
            BlockDuration = Get_Property(@Window : '.EDL_BLOCK_DURATION', 'INVALUE')
            // Convert duration (hours) to internal datetime
            // e.g. 8 hours * 1 day / 24 hours = 0.333333333 
            BlockDuration = BlockDuration / 24
            BlockStopDTM  = BlockStartDTM + BlockDuration
            ResponseData  = @RM:ReactorNo:@FM:BlockStartDTM:@FM:BlockStopDTM:@FM:BlockComment:@FM:BlockType:@FM:BlockOption:@RM
        end else
            // Soft block
            BlockOption    = Get_Property(@Window : '.RDO_SOFT_CONTROLS', 'VALUE')
            BlockDuration  = Get_Property(@Window : '.EDL_BLOCK_DURATION', 'TEXT')
            // Convert duration (hours) to internal datetime
            // e.g. 8 hours * 1 day / 24 hours = 0.333333333 
            BlockDuration  = BlockDuration / 24
            ModifyStartDTM = IConv(Get_Property(@Window:'.SCHEDULE_START_DTM', 'TEXT'), 'DT')
            ModifyStopDTM  = IConv(Get_Property(@Window:'.SCHEDULE_END_DTM', 'TEXT'), 'DT')
            ModifyWONo     = Get_Property(@Window:'.WO_NO', 'TEXT')
            Begin Case
                Case ModifyWONo EQ ''
                    // No event currently engaged, so use the start datetime set by the user.
                    BlockStartDTM = Get_Property(@Window:'.EDL_BLOCK_START_DTM', 'INVALUE')
                    BlockStopDTM  = BlockStartDTM + BlockDuration
                    ResponseData  = @RM:ReactorNo:@FM:BlockStartDTM:@FM:BlockStopDTM:@FM:BlockComment:@FM:BlockType:@FM:'':@RM
                Case BlockOption EQ 'END_OF_WORK_ORDER'
                    // Get event ID
                    BlockStartDTM = ModifyStopDTM
                    BlockStopDTM  = BlockStartDTM + BlockDuration
                    ResponseData  = @RM:ReactorNo:@FM:BlockStartDTM:@FM:BlockStopDTM:@FM:BlockComment:@FM:BlockType:@FM:BlockOption:@RM
                Case BlockOption EQ 'CASSETTE'
                    ModifyWaferQty       = Get_Property(@Window, '@MODIFY_CASS_QTY') * 25
                    OrigWaferQty         = Get_Property(@Window, '@TOTAL_EVENT_QTY')
                    StopCass             = Get_Property(@Window:'.CMB_STOP_AFTER', 'TEXT')
                    ApptID               = Get_Property(@Window, '@SCHED_EVENT_KEY')
                    // Modify event data
                    ModifyDescription    = Get_Property(@Window:'.DESCRIPTION', 'TEXT')
                    NewWaferQty          = OrigWaferQty - ModifyWaferQty
                    ResponseData        := ReactorNo:@FM:WorkOrder:@FM:ModifyStartDTM:@FM:ModifyStopDTM:@FM:ModifyDescription:@FM:NewWaferQty:@RM
                    // Block event data
                    BlockStartDTM        = ModifyStopDTM
                    BlockStopDTM         = BlockStartDTM + BlockDuration
                    ResponseData        := ReactorNo:@FM:BlockStartDTM:@FM:BlockStopDTM:@FM:BlockComment:@FM:BlockType:@FM:BlockOption:@RM
                    // Add/New event data
                    AddWaferQty          = ModifyWaferQty
                    AddStartDTM          = BlockStopDTM
                    AddDurationEstimate  = Schedule_Services_Dev('GetEventDuration', WorkOrder, AddWaferQty)
                    AddStopDTM           = AddStartDTM + AddDurationEstimate
                    AddDescription       = ModifyDescription
                    ResponseData        := ReactorNo:@FM:WorkOrder:@FM:AddStartDTM:@FM:AddStopDTM:@FM:AddDescription:@FM:AddWaferQty
            End Case 
        end
        
        End_Dialog(@Window, ResponseData)
    end
    
end event


Event CLOSE_BUTTON.CLICK()
    
    End_Dialog(@Window, '')
    
end event


Event CHK_OTHER.CLICK()
    
    Checkmark = Get_Property(CtrlEntID, 'CHECK')
    If Checkmark EQ True$ then
        Set_Property(@Window:'.EDL_SOFT_DURATION', 'ENABLED', True$)
        Set_Property(@Window:'.EDL_COMMENT', 'ENABLED', True$)
    end else
        Set_Property(@Window:'.EDL_SOFT_DURATION', 'TEXT', '')
        Set_Property(@Window:'.EDL_SOFT_DURATION', 'ENABLED', -1)
        Set_Property(@Window:'.EDL_COMMENT', 'TEXT', '')
        Set_Property(@Window:'.EDL_COMMENT', 'ENABLED', -1)
    end
    
end event


Event EDL_BLOCK_DURATION.CHAR(VirtCode, ScanCode, CtrlKey, ShiftKey, AltKey)
    
    GoSub EnableSaveButton
    
end event


Event CMB_STOP_AFTER.CHANGED(NewData)
    
    GoSub UpdateWorkOrderDetails
    GoSub EnableSaveButton
    
end event


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


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


UpdateScheduleDetails:
    
    LastEventKey   = Get_Property(@Window, '@SCHED_EVENT_KEY')
    ScheduleDetail = Schedule_Services_Dev('GetScheduleDetail', LastEventKey)
    Set_Property(@Window, '@ORIG_SCHEDULEDETAIL', ScheduleDetail)
    WorkOrder      = Get_Property(@Window : '.WO_NO', 'TEXT')
    If WorkOrder NE '' then
        Set_Property(@Window : '.DESCRIPTION', 'TEXT', ScheduleDetail<SCHED_DET_NG.DESC$>)
        Set_Property(@Window : '.SCHEDULE_START_DTM', 'TEXT', OConv(ScheduleDetail<SCHED_DET_NG.START_DTM$>, 'DT/^3H'))
        Set_Property(@Window : '.SCHEDULE_END_DTM', 'TEXT', OConv(ScheduleDetail<SCHED_DET_NG.STOP_DTM$>, 'DT/^3H'))
    end else
        Set_Property(@Window : '.DESCRIPTION', 'TEXT', '')
    end
    
return


UpdateCustomerName:
    
    WoNo            = Get_Property(@Window : '.WO_NO', 'TEXT')
    If WoNo NE '' then
        WorkOrderDetail = Work_Order_Services('GetWorkOrderLogDetail', WONo)
        CustNo          = WorkOrderDetail<WO_LOG_CUST_NO$>
        CompanyRow      = Database_Services('ReadDataRow', 'COMPANY', CustNo)
        CustName        = CompanyRow<42>
    end else
        CustName        = ''
    end
    Set_Property(@Window : '.CUSTOMER_NAME', 'TEXT', CustName)
    
return


UpdateReactorDetails:
    
    ReactorNo       = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    If Index(ReactorNo, '/', 1) then
        // EpiPro reactors formatted as such, "40/42". We must truncate the reactor number to the first reactor.
        ReactorNo = Field(ReactorNo, '/', 1, 1)
        Set_Property(@Window : '.REACTOR_NO', 'TEXT', ReactorNo)
    end
    ReactorDetails  = Schedule_Services_Dev('GetReactorDetails', ReactorNo)
    ReactorType     = ReactorDetails<REACTOR_REACT_TYPE$>
    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', ReactorDetails<REACTOR_SUSC_POCKET_SIZE$>)
    FutureEvents    = Schedule_Services_Dev('GetScheduleEvents', Date() + 1, '', ReactorNo, '', False$)
    Set_Property(@Window, '@FUTURE_EVENTS', FutureEvents)
    
return


UpdateWorkOrderDetails:

    SchedDetNGKey = Get_Property(@Window, '@SCHED_EVENT_KEY')
    If SchedDetNGKey NE '' then
        CurrDTM             = Datetime()
        SchedDetNGRec       = Database_Services('ReadDataRow', 'SCHED_DET_NG', SchedDetNGKey)
        WorkOrder           = Get_Property(@Window : '.WO_NO', 'TEXT')
        If WorkOrder NE '' then
            ReactNo             = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
            WorkOrderDetail     = Get_Property(@Window, '@WORK_ORDER_DETAIL')
            EpiPart             = WorkOrderDetail<WO_LOG_EPI_PART_NO$>
            TotalWafers         = SchedDetNGRec<SCHED_DET_NG.EVENT_TOTAL_WFRS$>
            RemainingToProcess  = Get_Property(@Window, '@REMAINING_TO_PROCESS')
            RemainingToSchedule = Get_Property(@Window, '@REMAINING_TO_SCHEDULE')
            If TotalWafers GT 0 then
                Complete = ( (TotalWafers - RemainingToProcess) / TotalWafers) * 100
            end else
                Complete = 0
            end
            ReactorType             = Get_Property(@Window : '.REACTOR_TYPE', 'TEXT')
            MinutesPerWaferAdjusted = Get_Property(@Window, '@MINUTES_PER_WAFER_ADJUSTED')
            ScheduledWfrQty         = Get_Property(@Window, '@SCHEDULED_WFR_QTY')
            AvailableWfrQty         = RemainingToSchedule
            EventCurrCass           = Get_Property(@Window, '@EVENT_CURR_CASS')
            Set_Property(@Window:'.EDL_CURR_CASS', 'TEXT', EventCurrCass)
            EventProcCass           = SchedDetNGRec<SCHED_DET_NG.PROCESSED_CASS$>
            EventUnprocCass         = SchedDetNGRec<SCHED_DET_NG.UNPROCESSED_CASS$>
            CassList                = Get_Property(@Window:'.CMB_STOP_AFTER', 'LIST')
            If CassList EQ '' then
                StopAfterList = SRP_Array('Join', EventCurrCass, EventUnprocCass, 'OR', @VM)
                StopAfterList = SRP_Array('SortSimpleList', StopAfterList, 'AscendingNumbers', @VM)
                Convert @VM to @FM in StopAfterList
                Set_Property(@Window:'.CMB_STOP_AFTER', 'LIST', StopAfterList)
                CassList      = StopAfterList
            end
            
            NumStopCass       = DCount(CassList, @FM)
            StopCass          = Get_Property(@Window:'.CMB_STOP_AFTER', 'TEXT')
            ModifyCassQty     = 0
            ScheduleOption    = Get_Property(@Window:'.RDO_SOFT_CONTROLS', 'DEFPROP')
            If ScheduleOption EQ 'CASSETTE' then
                Locate StopCass in CassList using @FM setting fPos then
                    For CassIndex = (fPos + 1) to NumStopCass
                        ModifyCassQty += 1
                    Next CassIndex
                end
            end
            NewEventQty = TotalWafers - (ModifyCassQty * 25)
            Set_Property(@Window, '@NEW_QTY', NewEventQty)
            StartDTM    = SchedDetNGRec<SCHED_DET_NG.START_DTM$>
            If StopCass NE '' then
                Set_Property(@Window, '@MODIFY_CASS_QTY', ModifyCassQty)
                Set_Property(@Window, '@TOTAL_EVENT_QTY', TotalWafers)
                NewRemainingToProcess = (DCount(EventUnprocCass, @VM) - ModifyCassQty) * 25
                DurationEstimate = Schedule_Services_Dev('GetEventDuration', WorkOrder, NewRemainingToProcess)
                EndDTM           = CurrDTM + DurationEstimate
            end else
                EndDTM = SchedDetNGRec<SCHED_DET_NG.STOP_DTM$>
            end
            TotalRunTime = EndDTM - StartDTM
            If MinutesPerWaferAdjusted EQ '' then
                Msg(@Window, 'Warning: ' : EpiPart : ' appears to be missing minutes per wafer values for ' : ReactorType)
            end
        end
    end

    If (SchedDetNGKey NE '') then
        Set_Property(@Window : '.EPI_PART', 'TEXT', EpiPart)
        Set_Property(@Window : '.TOTAL_WAFERS', 'TEXT', TotalWafers)
        Set_Property(@Window : '.TOTAL_REMAINING', 'TEXT', RemainingToProcess)
        Set_Property(@Window : '.PERCENT_COMPLETE', 'TEXT', Oconv(Complete, 'MD0[ %]S'))
        Set_Property(@Window : '.SCHEDULE_END_DTM', 'INVALUE', EndDTM)
        Set_Property(@Window : '.EDL_BLOCK_START_DTM', 'INVALUE', EndDTM)
        RunTimeRounded = SRP_Math('ROUND', TotalRunTime, 1)
        Set_Property(@Window : '.DAYS', 'DEFPROP', RunTimeRounded)
        Set_Property(@Window : '.AVAILABLE_QTY', 'TEXT', AvailableWfrQty)
        Set_Property(@Window : '.OPTIONS_NEW_QTY', 'TEXT', NewQtyLabel)
    end else
        Error_Services('DisplayError')
        Set_Property(@Window : '.EPI_PART', 'TEXT', '')
        Set_Property(@Window : '.TOTAL_WAFERS', 'TEXT', '')
        Set_Property(@Window : '.TOTAL_REMAINING', 'TEXT', '')
        Set_Property(@Window : '.SCHEDULE_WAFERS', 'TEXT', '')
        Set_Property(@Window : '.PERCENT_COMPLETE', 'TEXT', '')
        Set_Property(@Window : '.SCHEDULE_END_DTM', 'INVALUE', '')
        Set_Property(@Window : '.DAYS', 'DEFPROP', '')
    end
    GoSub EnableSaveButton
    
return


PopulateControls:
    
    Set_Property(@Window, 'TEXT', 'Scheduler Actions - Add Block Out Event - 2.0')
    Set_Property(@Window : '.REACTOR_NO', 'NEXT', @Window : '.SCHEDULE_START_DTM')
    Set_Property(@Window : '.DESCRIPTION', 'NEXT', @Window : '.REACTOR_NO')
    Set_Property(@Window : '.EDL_BLOCK_DURATION', 'TEXT', DEFAULT_DURATION$)
    WONo           = ''
    ScheduleKeyID  = ''
    GoSub UpdateScheduleDetails
    GoSub UpdateReactorDetails
    GoSub UpdateCustomerName
    GoSub InitializeProperties
    GoSub UpdateWorkOrderDetails
    Set_Property(@Window : '.REACTOR_NO', 'FOCUS', True$)
    
return


ClearControls:
    
    For Each Ctrl in ClearControls using @VM
        Type = Get_Property(CtrlEntId, 'TYPE')
        If Type EQ 'CHECKBOX' then
            Set_Property(@Window : '.' : Ctrl, 'CHECK', False$)
        end else
            Set_Property(@Window : '.' : Ctrl, 'TEXT', '')
        end
    Next Ctrl
    
return


UpdateChkBoxes:

    ChkBoxControls = Get_Property(@Window, '@CHKBOX_CONTROLS')
    ThisControl    = Field(CtrlEntID, '.', 2, 1)
    Begin Case
        Case ThisControl EQ 'CHK_GATE_VALVE_CHG'
            Duration = 3
            
        Case ThisControl EQ 'CHK_TUBE_CHG_6_MONTHS'
            Duration = 48
            
        Case ThisControl EQ 'CHK_TUBE_CHG_1_YEAR'
            Duration = 72
        
        Case ThisControl EQ 'CHK_TUBE_CHG_5_YEARS'
            Duration = 120
        
        Case ThisControl EQ 'CHK_TUBE_CHG_10_YEARS'
            Duration = 48
            
        Case ThisControl EQ 'CHK_SCRUBBER_WORK'
            Duration = '0.5'
            
        Case ThisControl EQ 'CHK_QUAL_PLAN'
            Duration = 168
            
        Case Otherwise$
            Duration = ''
            
    End Case
    
    Set_Property(@Window:'.EDL_BLOCK_DURATION', 'TEXT', Duration)
    Locate ThisControl in ChkBoxControls using @VM setting vPos then
        ChkBoxControls = Delete(ChkBoxControls, 0, vPos, 0)
    end
    ClearControls = ChkBoxControls
    GoSub ClearControls
    DownTimeCheck = Get_Property(@Window:'.CHK_DOWN_TIME', 'CHECK')
    Set_Property(@Window:'.RDO_REACTORS', 'ENABLED', DownTimeCheck)
    GoSub EnableSaveButton
    GoSub EnableRadioButton
    
return


EnableSaveButton:

    Duration       = Get_Property(@Window:'.EDL_BLOCK_DURATION', 'TEXT')
    ChkBoxControls = Get_Property(@Window, '@CHKBOX_CONTROLS')
    Ctrls          = ''
    Props          = ''
    For each Ctrl in ChkBoxControls using @VM setting vPos
        Ctrls  := @WINDOW:'.':Ctrl:@RM				; Props  := 'CHECK':@RM
    Next Ctrl
    Ctrls[-1, 1] = ''
    Props[-1, 1] = ''
    ChkVals           = Get_Property(Ctrls,Props)
    ChkBoxSelected    = (Sum(ChkVals) GT 0)
    SaveButtonEnabled = ( (Duration NE '') and ChkBoxSelected )
    Set_Property(@Window:'.SAVE_BUTTON', 'ENABLED', SaveButtonEnabled)
    
return


InitializeProperties:
    
    SchedDetNGKey           = Get_Property(@Window, '@SCHED_EVENT_KEY')
    WorkOrder               = Get_Property(@Window : '.WO_NO', 'TEXT')
    ReactNo                 = Get_Property(@Window : '.REACTOR_NO', 'TEXT')
    ReactorType             = Get_Property(@Window : '.REACTOR_TYPE', 'TEXT')
    WorkOrderDetail         = Work_Order_Services('GetWorkOrderLogDetail', WorkOrder)
    RemainingToProcess      = Work_Order_Services('GetUnprocessedWafers', WorkOrder)
    RemainingToSchedule     = Schedule_Services_Dev('GetUnscheduledWfrQty', WorkOrder)
    EpiPart                 = WorkOrderDetail<WO_LOG_EPI_PART_NO$>
    MinutesPerWaferAdjusted = Epi_Part_Services('GetAdjustedWafersPerDayScheduler', EpiPart, ReactorType)
    ScheduledWfrQty         = Schedule_Services_Dev('GetScheduledWfrQty', WorkOrder)
    EventCurrCass           = Schedule_Services_Dev('GetEventCurrCass', SchedDetNGKey)
    Set_Property(@Window, '@WORK_ORDER_DETAIL', WorkOrderDetail)
    Set_Property(@Window, '@REMAINING_TO_PROCESS', RemainingToProcess)
    Set_Property(@Window, '@REMAINING_TO_SCHEDULE', RemainingToSchedule)
    Set_Property(@Window, '@MINUTES_PER_WAFER_ADJUSTED', MinutesPerWaferAdjusted)
    Set_Property(@Window, '@SCHEDULED_WFR_QTY', ScheduledWfrQty)
    Set_Property(@Window, '@EVENT_CURR_CASS', EventCurrCass)
    
return


RadioButton:
    
    GoSub UpdateWorkOrderDetails
    GoSub EnableSaveButton
    
return


EnableRadioButton:

    ChkBoxControl  = ''
    ChkBoxControls = Get_Property(@Window, '@CHKBOX_CONTROLS')
    For each ChkBoxControl in ChkBoxControls using @VM setting vPos
        Checkmark = Get_Property(@Window : '.' : ChkBoxControl, 'CHECK')
    Until Checkmark EQ True$
    Next ChkBoxControl
    If ChkBoxControl NE '' then
        BlockType = Get_Property(@Window : '.' : ChkBoxControl, 'TEXT')
        SoftBlock = ( (BlockType NE 'Out of Service (OOS)') and (BlockType NE 'Down No Material (DNM)') and (BlockType NE 'Factory Down Time') )
        WONo      = Get_Property(@Window:'.WO_NO', 'TEXT')
        If ( (SoftBlock) and (WONo NE '') ) then
            Set_Property(@Window:'.RDO_SOFT_CONTROLS', 'ENABLED', True$)
            Set_Property(@Window:'.EDL_BLOCK_START_DTM', 'ENABLED', -1)
            Set_Property(@Window:'.CMB_STOP_AFTER', 'ENABLED', True$)            
        end else
            Set_Property(@Window:'.RDO_SOFT_CONTROLS', 'ENABLED', False$)
            Set_Property(@Window:'.EDL_BLOCK_START_DTM', 'ENABLED', True$)
            Set_Property(@Window:'.CMB_STOP_AFTER', 'ENABLED', False$)            
        end
    end
    
return


