Compile function NDW_MANUAL_WAFER_COUNT_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_Manual_Wafer_Count_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)
        04/12/24    djs     Created initial commuter module.

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

#pragma precomp SRP_PreCompiler
#window NDW_MANUAL_WAFER_COUNT

$Insert EVENT_SETUP
$Insert APP_INSERTS
$Insert MSG_EQUATES

Equ MSG_WIDTH$ to 650
Equ Comma$     to ','

Declare function   Environment_Services, Logging_Services, Datetime
Declare subroutine Set_Property, Logging_Services, PlaceDialog

LogPath     = Environment_Services('GetApplicationRootPath') : '\LogFiles\WaferCounter'
LogDate     = Oconv(Date(), 'D4/')
LogTime     = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Wafer Counter Verify Log.csv'
Headers     = 'Logging DTM':@FM:'Logging Text'
objLog      = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, Comma$, Headers, '', False$, False$)
LoggingDTM  = LogDate : ' ' : LogTime   ; // Logging DTM

// 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$

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

Event WINDOW.CREATE(CreateParam)
    
    If CreateParam NE '' then
        
        Set_Property(@Window, '@EXPECTED_QTY', CreateParam)
        List        = ''
        For SlotIndex = 0 to 25
            List<SlotIndex + 1> = SlotIndex
        Next SlotIndex
        Set_Property(@Window:'.CBO_WAFER_COUNT', 'LIST', List)
        PlaceDialog(-2, -2)
        
    end else
        
        ErrorMsg   = 'Wafer counter error. Null expected quantity passed in.'
        LogData    = ''
        LogData<1> = OConv(Datetime(), 'DT2/^H')
        LogData<2> = @User4
        LogData<3> = ErrorMsg
        Logging_Services('AppendLog', objLog, LogData, @RM, @FM)          
        
        MsgStruct              = ''
        MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
        Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMsg)
        End_Dialog(@Window, '')
    end
    
End Event


Event CBO_WAFER_COUNT.CHANGED(NewData)
    
    Set_Property(@Window:'.PUB_OK', 'ENABLED', (NewData NE '') )
    
end event


Event PUB_OK.CLICK()
    
    ExpectedQty = Get_Property(@Window, '@EXPECTED_QTY')
    WaferCount  = Get_Property(@Window:'.CBO_WAFER_COUNT', 'TEXT')
    If ExpectedQty EQ WaferCount then
        LogData    = ''
        LogData<1> = OConv(Datetime(), 'DT2/^H')
        LogData<2> = @User4
        LogData<3> = 'Expected quantity equals entered quantity. Proceeding...'
        Logging_Services('AppendLog', objLog, LogData, @RM, @FM)          
        
        End_Dialog(@Window, WaferCount)
    end else
        ErrorMsg               = 'Wafer counter error. Expected quantity "':ExpectedQty:'" does not match entered quantity "':WaferCount:'".'
        LogData                = ''
        LogData<1>             = OConv(Datetime(), 'DT2/^H')
        LogData<2>             = @User4
        LogData<3>             = ErrorMsg
        Logging_Services('AppendLog', objLog, LogData, @RM, @FM)          
        MsgStruct              = ''
        MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
        Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMsg)
    end
    
end event


Event PUB_CANCEL.CLICK()
    
    LogData    = ''
    LogData<1> = OConv(Datetime(), 'DT2/^H')
    LogData<2> = @User4
    LogData<3> = 'Manual verification process canceled'
    Logging_Services('AppendLog', objLog, LogData, @RM, @FM)    
    End_Dialog(@Window, '')
    
end event

