Compile function NDW_PM_OVERRIDE_EVENTS(CtrlEntId, Event, @PARAMS)
/***********************************************************************************************************************

    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        :   NDW_PM_Override_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/25/24    djs     Created initial commuter module.                   

***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
#window NDW_PM_OVERRIDE

$Insert APP_INSERTS
$Insert EVENT_SETUP
$Insert REACTOR_LOG_EQUATES
$insert MESSAGE_BOX_EQUATES

Declare subroutine Placedialog, Message_Box

// 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 else
    // Event not implemented
end

Return EventFlow or 1

//-----------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------

Event WINDOW.CREATE(CreateParam)
	
	RlNo         = CreateParam
    PmOrderTypes = Xlate('REACTOR_LOG', RLNo, REACTOR_LOG_CHECKLIST_TYPE$, 'X')
    for each PmOrderType in PmOrderTypes using @VM setting dummy
    	Begin Case
    		Case PmOrderType _EQC 'ASM_HTR_TUBE_CHANGE'
    			Set_Property(@Window:'.CHB_ASM_HTR_TUBE_CHANGE', 'ENABLED', True$)
    		Case PmOrderType _EQC 'SEMIANNUAL_PM'
    			Set_Property(@Window:'.CHB_SEMIANNUAL_PM', 'ENABLED', True$)
    		Case PmOrderType _EQC 'ANNUAL_PM'
    			Set_Property(@Window:'.CHB_ANNUAL_PM', 'ENABLED', True$)
    		Case Otherwise$
    			Null
    	End Case
    Next PmOrderType
    
    Placedialog(-2, -2)
    
End Event


Event PUB_SUBMIT.CLICK()
	
	OverrideData  = ''
	SelectedTypes = ''
	If Get_Property(@Window:'.CHB_ASM_HTR_TUBE_CHANGE', 'CHECK') then SelectedTypes<0, -1> = "ASM_HTR_TUBE_CHANGE"	
	If Get_Property(@Window:'.CHB_SEMIANNUAL_PM', 'CHECK')  	 then SelectedTypes<0, -1> = 'SEMIANNUAL_PM'	
	If Get_Property(@Window:'.CHB_ANNUAL_PM', 'CHECK')  		 then SelectedTypes<0, -1> = 'ANNUAL_PM'		
	
	If SelectedTypes EQ '' then
		Message_Box(@Window, "You must select at least one PM type!", "Error", MSG_ICON_EXCLAM$)
		return
	end else
		OverrideData<1, 1> = SelectedTypes
	end
	
	OverrideData<2, 1> = Get_Property(@Window:'.EDB_COMMENT', 'TEXT')
	
	If OverrideData<2, 1> EQ '' or Len(OverrideData<2, 1>) LT 4 then
		Message_Box(@Window, "Your comment must be at least 4 characters!", "Error", MSG_ICON_EXCLAM$)
		return
	end	
	
	End_Dialog(@Window, OverrideData)
	
end event


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


