Compile function NDW_PACKAGING_EVENTS_DELETEME(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_Packaging_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)
        10/11/19    djs     Created initial commuter module.
                                            
***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
#window NDW_PACKAGING

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES
$insert LSL_USERS_EQUATES
$insert MESSAGE_BOX_EQUATES

Equ MSG_WIDTH$ to 600

Declare subroutine  SRP_Show_Window, ErrMsg, Packaging_Services
Declare function    Database_Services, Security_Services, MemberOf, Form_Services, Scan_Services, Packaging_Services
Declare function    Message_Box

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
end

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

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

Event WINDOW.CREATE(CreateParam)
    
    EventFlow = 1
    
End Event


Event EDL_USER_ID_SCAN.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'EMPLOYEE')
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_CASS_SCAN_1', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_CASS_SCAN_1', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                GoSub ClearForm
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
            end
        end
    end
    
end event


Event EDL_CASS_SCAN_1.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'CASSETTE_1')
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_CASS_SCAN_2', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_CASS_SCAN_2', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                GoSub ClearForm
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)                
            end
        end
    end
    
end event


Event EDL_CASS_SCAN_2.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            FirstCassID = Get_Property(@Window:'.EDL_CASS_SCAN_1', 'TEXT')
            OperatorID  = Get_Property(@Window:'.EDL_USER_ID_SCAN', 'TEXT')

            ScanData    = Packaging_Services('ProcessScanData', ScanData, 'CASSETTE_2', FirstCassID, OperatorID)
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_POLY_SCAN', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_POLY_SCAN', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                GoSub ClearForm
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)                
            end
        end
    end
    
end event


Event EDL_POLY_SCAN.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'POLY')
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_TRILAM_SCAN', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_TRILAM_SCAN', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                ScanData = Get_Property(CtrlEntID, 'TEXT')
                If ScanData[1, 3] EQ 'PWD' then Set_Property(CtrlEntID, 'TEXT', '')
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
                Set_Property(CtrlEntID, 'FOCUS', True$)
                SelectAll = 1:@FM:65534
                Set_Property(CtrlEntID, 'SELECTION', SelectAll)
            end
        end
    end
    
end event


Event EDL_TRILAM_SCAN.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'TRILAM')
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_PASSWORD_SCAN', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_PASSWORD_SCAN', 'FOCUS', True$)
                ! Replace above two lines with below two lines when ready to enable supplier lot scan.
*                Set_Property(@Window:'.EDL_SUPPLIER_LOT_SCAN', 'ENABLED', True$)
*                Set_Property(@Window:'.EDL_SUPPLIER_LOT_SCAN', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                ScanData = Get_Property(CtrlEntID, 'TEXT')
                If ScanData[1, 3] EQ 'PWD' then Set_Property(CtrlEntID, 'TEXT', '')
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
                Set_Property(CtrlEntID, 'FOCUS', True$)
                SelectAll = 1:@FM:65534
                Set_Property(CtrlEntID, 'SELECTION', SelectAll)
            end
        end
    end
    
end event


Event EDL_SUPPLIER_LOT_SCAN.LOSTFOCUS(Flag, FocusID)
    
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            OperatorID   = Get_Property(@Window:'.EDL_USER_ID_SCAN', 'TEXT')
            FirstCassID  = Get_Property(@Window:'.EDL_CASS_SCAN_1', 'TEXT')
            SecondCassID = Get_Property(@Window:'.EDL_CASS_SCAN_2', 'TEXT')
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'SUPPLIER', FirstCassID, SecondCassID, OperatorID)
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                Set_Property(@Window:'.EDL_PASSWORD_SCAN', 'ENABLED', True$)
                Set_Property(@Window:'.EDL_PASSWORD_SCAN', 'FOCUS', True$)
                Set_Property(CtrlEntID, 'ENABLED', False$)
            end else
                GoSub ClearForm
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
                
            end
        end
    end
     
end event


Event EDL_PASSWORD_SCAN.LOSTFOCUS(Flag, FocusID)
    If Flag EQ 1 then
        ScanData = Get_Property(CtrlEntID, 'TEXT')
        If ScanData NE '' then
            Username = Get_Property(@Window:'.EDL_USER_ID_SCAN', 'TEXT')
            ScanData = Packaging_Services('ProcessScanData', ScanData, 'PASSWORD', Username)
            If Error_Services('NoError') then
                Set_Property(CtrlEntID, 'TEXT', ScanData)
                
                // Complete packaging
                CassetteID = Get_Property(@Window:'.EDL_CASS_SCAN_1', 'TEXT')
                //replace period with asterisk for GaN cassettes
                Convert '.' to '*' in CassetteID
                OperatorID   = Get_Property(@Window:'.EDL_USER_ID_SCAN', 'TEXT')
                Packaging_Services('CompletePackaging', CassetteID, OperatorID)

                If Error_Services('NoError') then
                    SuccessMessage = 'Bagging process complete!'
                    MsgStruct = "" 
                    MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                    Msg(@Window, MsgStruct, 'PROCESS_COMPLETE', '', SuccessMessage)       
                end else        
                    ErrorMessage = Error_Services('GetMessage')        
                    MsgStruct = "" 
                    MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                    Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
                end
               
                GoSub ClearForm
                
            end else
                ErrorMessage = Error_Services('GetMessage')
                MsgStruct = "" 
                MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
                Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', ErrorMessage)
                Set_Property(CtrlEntID, 'FOCUS', True$)
                SelectAll = 1:@FM:65534
                Set_Property(CtrlEntID, 'SELECTION', SelectAll)
            end
        end
    end
    
end event


Event PUB_CLEAR_FORM.CLICK()
	
    GoSub ClearForm
  
end event


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

ClearForm:

    Set_Property(@Window:'.EDL_USER_ID_SCAN'     , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_CASS_SCAN_1'      , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_CASS_SCAN_2'      , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_POLY_SCAN'        , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_TRILAM_SCAN'      , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_SUPPLIER_LOT_SCAN', 'TEXT'   , '')
    Set_Property(@Window:'.EDL_PASSWORD_SCAN'    , 'TEXT'   , '')
    Set_Property(@Window:'.EDL_USER_ID_SCAN'     , 'ENABLED', True$)
    Set_Property(@Window:'.EDL_CASS_SCAN_1'      , 'ENABLED', -1)
    Set_Property(@Window:'.EDL_CASS_SCAN_2'      , 'ENABLED', -1)
    Set_Property(@Window:'.EDL_POLY_SCAN'        , 'ENABLED', -1)
    Set_Property(@Window:'.EDL_TRILAM_SCAN'      , 'ENABLED', -1)
    Set_Property(@Window:'.EDL_SUPPLIER_LOT_SCAN', 'ENABLED', -1)
    Set_Property(@Window:'.EDL_PASSWORD_SCAN'    , 'ENABLED', -1)
    Set_Property(@Window:'.PUB_COMPLETE_BAGGING' , 'ENABLED', -1)
    Set_Property(@Window:'.EDL_USER_ID_SCAN', 'FOCUS', True$)

return

