Function NDW_Main_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_Main_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)
        05/08/18    dmb     Created initial commuter module.

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

#pragma precomp SRP_PreCompiler
#Window NDW_MAIN

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES
$insert ENVIRON_CONSTANTS
$insert NOTIFICATION_EQUATES
$insert REACT_MODE_EQU
$insert REACT_UTIL_EQU
$insert TOOL_EQUATES
$insert RLIST_EQUATES
$insert WO_LOG_EQUATES
$insert REACTOR_CHILD_KEY_IDS_EQUATES

Equ WIDTH$  to 3
Equ HEIGHT$ to 4

Declare function   GetCommandLine, MemberOf, obj_Install, obj_Notes_Sent, FindWindow, ShowWindow, Next_Key
Declare function   Environment_Services, Reactor_Services, Database_Services, obj_Tool, Messaging_Services, SRP_JSON
Declare function   Notes_Services, RTI_Xlate_Controller, Test_Run_Services, LSL_Users_Services, Datetime
Declare subroutine Set_Env, obj_Appwindow, Get_BMP_Info, obj_Login, obj_Calib_List, End_Window, Start_Window, Next_Key
Declare subroutine Database_Services, obj_React_Status, Obj_React_Mode, obj_Tool_Log, RList, Messaging_Services, RTP27
Declare subroutine Notes_Services, Obj_Note_Ptrs, Comm_Note_Ptrs, SRP_Run_Command, PlaceDialog, GetEngineVersion

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)
	
	Version      = ''
	GetEngineVersion(Version)
	MajorVersion = Version[1, 'F.']
	If MajorVersion GE 10 then
		// Stopgap performance fix for OI 10.2.2 RC1. Revelation will re-enable caching by default in 10.2.2 RC2.
		// Do not invoke this in OI 9 as the function does not exist!
		rv = RTI_Xlate_Controller('EnableCache')
	end

    Set_Property(@Window, '@INIT', True$)
    
    Server  = Environment_Services('GetServer')
    Command = GetCommandLine()
    Command = Trim(Command)
    Convert ' ' to @FM in Command
    Convert @Lower_Case to @Upper_Case in Command
    NumArguments = DCount(Command, @FM)
    Done    = False$
    For ArgCnt = 1 to NumArguments
        Argument = Command<ArgCnt>
        If Argument[1, 3] EQ '/UN' then
            @USER4 = Argument[-1, 'B=']
            Done   = True$
        end
    Until Done
    Next ArgCnt


    IF @USER4 = 'INDEXER' THEN
        void = Start_Window( 'IDXSVR', '', '', '', '' )
        Post_Event(@Window, 'CLOSE')
        RETURN 0
    END

    IF @USER4 = 'VISION' THEN
        void = Start_Window( 'VISION_COMM', @WINDOW, '', '', '' )
        RETURN 0
    END

    IF @USER4 = 'ADCSVR' THEN
        void = Start_Window( 'SERVICE_MANAGER', '', '', '', '' )
        Post_Event(@Window, 'CLOSE')
        RETURN 0
    END

    IF @USER4 = 'SAP' THEN
        void = Start_Window( 'DIALOG_SAP_COMM', '', '', '', '')
        Post_Event(@Window, 'CLOSE')
        RETURN 0
    END
    
    IF @USER4 = 'MESSENGER' THEN
        void = Start_Window('NDW_MESSAGE_LISTENER', '', '', '', '')
        Post_Event(@Window, 'CLOSE')
        RETURN 0
    END

    // The messaging port the messaging processor uses isn't open for between the app servers and the DB servers.
    // Don't start the messaging processor on the app server to avoid boot up delays.
    If ( (Server NE 'MESSA005') and (Server NE 'MESSA012') ) then Start_Window('NDW_MESSAGING_PROCESSOR', @Window)

    AccessLevel    = Dialog_Box('LOGON', @Window)

    If (AccessLevel EQ -1) OR (AccessLevel EQ '') then
        Set_Property(@Window, '@CLOSE', 1)
        Post_Event(@Window, 'CLOSE')
        // This prevents OI from throwing an error message if the cancel button is pressed on the LOGON form.
        //If (Server EQ 'MESST5201') or (Server EQ 'MESST5202') then Utility("DESTROY", "SYSTEM")
    end
    
    If AccessLevel GE 0 then

        IF MemberOf(@USER4, 'OI_ADMIN') OR @USER4 = 'MIS' THEN
            Set_Env(ENV_DEBUGGER_ENABLED$, 1, 1)
            Set_Env(ENV_DEBUGGER_INTERCEPT_PROC$,'',1)
            
            * This section added 9/17/2014 JCH for FTPQueueing for manual batch transmits
            
            OPEN 'FTP_QUEUE' TO FTPQueue THEN
                SELECT FTPQueue
                
                RecCnt = 0
                Done = 0
                LOOP
                    READNEXT QueueKey ELSE Done = 1
                UNTIL Done
                    RecCnt += 1
                REPEAT
                
                Set_Property(@Window : '.PUB_SHIP_DATA_QUEUE','DEFPROP',RecCnt:' in Ship Data Queue')
                Set_Property(@Window : '.PUB_SHIP_DATA_QUEUE','VISIBLE',1)
            END
            
        END ELSE
            
            Set_Env(ENV_DEBUGGER_ENABLED$, 2, 1)
            Set_Env(ENV_DEBUGGER_INTERCEPT_PROC$,'EPI_USER_DEBUG',1)

            Set_Property(@Window : '.PUB_SHIP_DATA_QUEUE','VISIBLE',0)
        END


        IF MemberOf(@USER4,'OI_ADMIN') THEN

            * This section added 7/31/2015 JCH for Shipment eMail Queueing for manual batch transmits
            
            OPEN 'SHIP_EMAIL_QUEUE' TO Ship_eMailQueue THEN
                SELECT Ship_eMailQueue
                
                RecCnt = 0
                Done = 0
                LOOP
                    READNEXT QueueKey ELSE Done = 1
                UNTIL Done
                    RecCnt += 1
                REPEAT
                
                Set_Property(@Window : '.PUB_SHIP_DOC_QUEUE','DEFPROP',RecCnt:' in Ship Doc Queue')
                Set_Property(@Window : '.PUB_SHIP_DOC_QUEUE','VISIBLE',1)
            END

        END

        Company     = obj_Install('Get_Prop','CompTitle')
        WinTitle    = Get_Property(@WINDOW,'TEXT')
        Machine     = ''
        If (Server EQ 'MESST5201') or (Server EQ 'MESST5202') then 
            Machine = 'Server - ' : Server
        end else
            Machine = 'Client'
        end

        WinTitle    = Get_Property(@WINDOW,'TEXT')
        LSL2Version = Xlate('LSL_USERS', @User4, 'LSL2_VERSION', 'X')
        OCXVersion  = Xlate('LSL_USERS', @User4, 'OCX_VERSION', 'X')
        OIVersion   = Get_Property('SYSTEM', 'VERSION')
        OIVersion   = OIVersion<2>
        Set_Property(@WINDOW,'TEXT',Company:' ':WinTitle: ' - ':Machine: ' - v':LSL2Version:' - OCX v':OCXVersion:' - OpenInsight v':OIVersion)

        rv  = Set_Property(@WINDOW:'.CURRENT_USER', 'TEXT', 'User: ':oconv( @user4, '[XLATE_CONV,LSL_USERS*FIRST_LAST]' ))
        rv  = Set_Property(@WINDOW:'.OLE_PIC_CURRENT_USER','OLE.Caption','User: ':OCONV( @USER4, '[XLATE_CONV,LSL_USERS*FIRST_LAST]' ))
        rv  = Set_Property(@WINDOW:'.OLE_PIC_CURRENT_USER','OLE.CaptionColor', 'RGB(0,93,169)')
        rv  = Set_Property(@WINDOW:'.GROUP_1', 'VISIBLE', 1)

        Recipients    = XLATE('NOTIFICATION','CONFIG_LIMITED',NOTIFICATION_USER_ID$,'X')

        LOCATE @USER4 IN Recipients USING @VM SETTING Pos THEN
            obj_Login('LateShip')
        END

        NotesSent   = obj_Notes_Sent('GetUserKeys',@USER4)
        NewMessages = XLATE('NOTE_PTRS',@USER4,'NEW_MESSAGES','X')
		
		ShowPTO = XLATE('APP_INFO', 'MATERIAL_SCAN_FORM_SHOW', 1, 'X')

		If ShowPTO NE '1' then
			Set_Property(@WINDOW:'.MENU.MATERIAL.MATERIAL_SCAN','VISIBLE',0)
		end
        
        IF MemberOf(@USER4, 'SPEC_CHANGE') OR MemberOf(@USER4, 'OI_ADMIN') THEN
            Set_Property(@WINDOW:'.MENU.ENGINEERING.TOOL_CLASS_-_RECIPES__PATTERNS','VISIBLE',1)
            Set_Property(@WINDOW:'.MENU.ADM.TOOLS.PRS_STAGE_DEFAULTS','VISIBLE',1)
        END ELSE
            Set_Property(@WINDOW:'.MENU.ENGINEERING.TOOL_CLASS_-_RECIPES__PATTERNS','VISIBLE',0)
            Set_Property(@WINDOW:'.MENU.ADM.TOOLS.PRS_STAGE_DEFAULTS','VISIBLE',0)
        END

        Ctrls  = @WINDOW:'.MENU.ADMIN.FABTIME_SUPPORT':@RM      ; Props  = 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.MAINT.REACTOR_MAINTENANCE':@RM  ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADM.TOOLS':@RM                  ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADM.RAS':@RM                    ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADM.DEVELOPER':@RM              ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADMIN.DEV.ARCHIVE'              ; Props := 'ENABLED'  
        IF Memberof(@user4, 'OI_ADMIN') OR Memberof(@user4, 'BUSINESS_ADMINS') THEN
            Vals = 1
        END ELSE
            Vals = 0
        END
        Set_Property(Ctrls,Props,Vals)                                        ; * Sets the enabled property ON/OFF for the record mark delimited variables Ctrls,Props, and Vals

		If MemberOf(@User4, 'OI_ADMIN') OR MemberOf(@User4, 'BUSINESS_ADMINS') then
			Set_Property(@Window : '.MENU.ADM.SYSTEM_CONFIG', 'ENABLED', 1)
		end else
			Set_Property(@Window : '.MENU.ADM.SYSTEM_CONFIG', 'ENABLED', 0)
		end
		
        Ctrls := @WINDOW:'.MENU.ADMIN.SAP_INTERFACE':@RM        ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADM.WAREHOUSE':@RM              ; Props := 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.ADMIN.SAP_INTERFACE.SAP_COMM_MONITOR':@RM   ; Props := 'VISIBLE':@RM
		
        IF Memberof(@user4, 'OI_ADMIN') OR Memberof(@user4, 'OI_SUPERUSER') THEN     
            Vals = 1
        END ELSE
            Vals = 0
        END
        Set_Property(Ctrls,Props,Vals)                                        ; * Sets the enabled property ON/OFF for the record mark delimited variables Ctrls,Props, and Vals

        Ctrls  = @WINDOW:'.MENU.ADM.THRUPUT_TARGETS':@RM        ; Props  = 'ENABLED':@RM
        Ctrls := @WINDOW:'.MENU.PROD.REACTOR_RUN'               ; Props := 'ENABLED'
        IF Memberof(@user4,'CONFIG_LIMITED') THEN
            Vals = 1
        END ELSE
            Vals = 0
        END
        Set_Property(Ctrls,Props,Vals)                                        ; * Sets the enabled property ON/OFF for the record mark delimited variables Ctrls,Props, and Vals

        If Not(MemberOf(@USER4, 'LEAD')) AND Not(MemberOf(@USER4, 'SUPERVISOR')) AND Not(MemberOf(@USER4, 'MAINTENANCE')) then
            Set_Property(@Window : '.MENU.ADMIN.MASS_TOOL_MODE_CHANGE', 'VISIBLE', 0)
            Set_Property(@Window : '.MENU.ADMIN.MASS_REACTOR_MODE_CHANGE', 'VISIBLE', 0)
        end
        
        UseFQAMatScan = Database_Services('ReadDataRow', 'APP_INFO', 'USE_FQA_MAT_SCAN')
        If UseFQAMatScan EQ 1 OR MemberOf(@User4, 'OI_TEST') then
            Set_Property(@Window:'.MENU.MATERIAL.FQA_MAT_SCAN', 'VISIBLE', 1)
            Set_Property(@Window:'.MENU.MATERIAL.FQA_LABEL_CHECK', 'VISIBLE', 0)
        end else
            Set_Property(@Window:'.MENU.MATERIAL.FQA_MAT_SCAN', 'VISIBLE', 0)
            Set_Property(@Window:'.MENU.MATERIAL.FQA_LABEL_CHECK', 'VISIBLE', 1)
        end
        
        If MemberOf(@User4, 'PRODUCTION_LEADERSHIP') or MemberOf(@User4, 'OI_ADMIN') then
        	Set_Property(@Window:'.MENU.ADMIN.FEATURE_FLAGS', 'ENABLED', True$)
        end
        
        stat = Set_Property(@WINDOW,'TIMER',5000:@FM:1)    ;* Start the Keep Alive Timer event and run every 20 Minutes * * * * * * * * * * * *

        Set_Property(@Window:".OLE_SNOOZE", "OLE.Icon", "BMPS\do-not-disturb-mode.png")
        Set_Property(@Window:".OLE_NOTES", "OLE.Font", @SVM:10)
        Set_Property(@Window:".OLE_SNOOZE", "OLE.Font", @SVM:10)
        Gosub SetSnoozeButtonState
        PlaceDialog(-2, -2)
        Set_Property(@Window, 'VISIBLE', 1)
        Eventflow = 0
        
    end Else
        Set_Property(@Window, 'VISIBLE', 2)
        Post_Event(@Window, 'CLOSE')
    end
    
end event


Event WINDOW.CLOSE(CancelFlag)

    Void = Set_Property(@WINDOW,'TIMER','')
    UNLOCK All

end event


Event WINDOW.TIMER()

    OnInit = Get_Property(@Window, '@INIT')
    If OnInit Then    	
        Gosub Setup_OLE_Controls
        Size            = Get_Property(@Window, 'SIZE')
        ScreenSize      = Get_Property('SYSTEM', 'SIZE')
        TrackingSize    = ''
        TrackingSize<1> = Size<3>
        TrackingSize<2> = Size<4>
        TrackingSize<3> = ScreenSize<1>
        TrackingSize<4> = ScreenSize<2>
        Set_Property(@Window, 'TRACKINGSIZE', TrackingSize)
        Set_Property(@Window, '@INIT', False$)
        Post_Event(@Window, 'OMNIEVENT')
    End
    
    Close   = Get_Property(@Window, '@CLOSE')
    CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')

    OPEN 'SYSLISTS' TO ListsFile THEN
        Station = @STATION
        Station = Station[1,'_']		
        ListKey = Station:'*KEEP_ALIVE'
        ListRec = @USER4:@FM:CurrDTM
        WRITE ListRec ON ListsFile,ListKey ELSE NULL
    END
    
    Snoozed = Notes_Services('CheckForNotificationSnooze', @USER4)
    NotesSentKeys = Notes_Services('GetNewMessages', @User4); *Gets all new messages
    if NotesSentKeys then
        DisplayNotification = False$
        for each NotesSent in NotesSentKeys using @VM
            NotesSentRec = Database_Services('ReadDataRow', 'NOTES_SENT', NotesSent)
            if Not(NotesSentRec<2>) then
                //Messaging_Services('SetPopupMessage', '','','You have new messages!')
                DisplayNotification = True$
                NotesSentRec<2>     = True$
                Database_Services('WriteDataRow', 'NOTES_SENT', NotesSent, NotesSentRec)
            end
        Next NotesSent
        if DisplayNotification and Snoozed EQ FALSE$ then Messaging_Services('SetPopupMessage', '','',"You've got mail! =)")
    end
    
    Notes_Services('UpdateNotes', @User4)
    If Error_Services('HasError') then Error_Services('DisplayError')
    NewMessages = Notes_Services('GetUnreadMessageCount', @User4)
    
    ColorFill   = ''
    if NewMessages then
        Set_Property(@Window:".OLE_NOTES", "OLE.Icon", "BMPS\envelope-regular.png")
        ColorFill<1> = "Vertical(Gradient(RGB(252,212,66), (252,212,66)),Border(RGB(252,212,66)),Rounded(1))"
        ColorFill<2> = "Vertical(Gradient(RGB(252,212,66) L=70, RGB(252,212,66) L=70), Border(RGB(252,212,66)),Rounded(1))"
        ColorFill<3> = "Vertical(Gradient(RGB(252,212,66) L=40, RGB(252,212,66) L=40), Border(RGB(252,212,66)),Rounded(1))"
        ColorFill<5> = "Vertical(Gradient(RGB(252,212,66), (252,212,66)),Border(RGB(252,212,66)),Rounded(1))"
    end else
        Set_Property(@Window:".OLE_NOTES", "OLE.Icon", "BMPS\envelope-open-regular.png")
        ColorFill<1> = "Vertical(Gradient(RGB(155,186,67), (155,186,67)),Border(RGB(155,186,67)),Rounded(1))"
        ColorFill<2> = "Vertical(Gradient(RGB(155,186,67) L=60, RGB(155,186,67) L=60), Border(RGB(155,186,67)),Rounded(1))"
        ColorFill<3> = "Vertical(Gradient(RGB(155,186,67) L=40, RGB(155,186,67) L=40), Border(RGB(155,186,67)),Rounded(1))"
        ColorFill<5> = "Vertical(Gradient(RGB(155,186,67), (155,186,67)),Border(RGB(155,186,67)),Rounded(1))"
    end
    Set_Property(@Window : '.OLE_NOTES', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_NOTES", "OLE.Caption", NewMessages)
    
    IF Get_Property('NOTE_PTRS', 'VISIBLE') then
        Post_Event('NOTE_PTRS', 'OMNIEVENT')
    end
   
    Gosub SetSnoozeButtonState
    
    CurrDtm = Datetime()
    CurrShiftStartDtm = LSL_USERS_SERVICES('GetCurrentShiftStartDtm', CurrDtm)
    
    TWStats = Test_Run_Services('GetTestWaferUsageStats', @USER4, CurrShiftStartDtm, Datetime())
    LastUsed = TWStats<1>
    LastUsed = Oconv(LastUsed, 'DT2/^H')
    QtyUsed = TWStats<2>
    Set_Property(@Window: '.LBL_LAST_TW_USED', 'TEXT', 'TW Last Used by User: ' :LastUsed)
    Set_Property(@Window: '.LBL_TW_USED', 'TEXT', 'TW Used by User: ' :QtyUsed)
    
    Set_Property(@WINDOW:'.CURRENT_TIME','TEXT','Current Time: ':OCONV( TIME(), 'MTHS' ))
    Set_Property(@WINDOW:'.CURRENT_DATE','TEXT','Date: ':OCONV( DATE(), 'D2/' ))
    If Get_Property(@Window, '@CLOSE') then
        Send_Event(@Window, 'CLOSE')
    end

end event


Event PUB_SHIP_DATA_QUEUE.CLICK()

    Start_Window('DIALOG_FTP_QUEUE', @Window)

end event


Event PUB_SHIP_DOC_QUEUE.CLICK()

    Start_Window('DIALOG_EMAIL_SHIPMENT', @Window)
    
end event


Event MENU.REACT_STAT.MENU()
	
    Start_Window('REACT_STATUS_EVEN',@WINDOW,'')
    Start_Window('REACT_STATUS_ODD',@WINDOW,'')
    Start_Window('TOOL_STATUS',@WINDOW,'')

end event


Event MENU.WIN.PROD.RMC.MENU()

    IF MemberOf(@USER4, 'DATA_ENTRY') OR MemberOf(@USER4, 'SUPERVISOR') THEN
        Start_Window('REACT_MODE_CHG', @WINDOW, '*CENTER','','')
    END ELSE
        MsgInfo = ''
        MsgInfo<MCOL$>    = -2
        MsgInfo<MROW$>    = -2
        MsgInfo<MTEXT$> = 'You must be a Supervisor or Technician in order to change reactor modes...'
        MsgInfo<MICON$> = 'H'
        void = Msg('',MsgInfo)
    END

end event


Event MENU.ADMIN.SAP_INTERFACE.SAP_COMM_MONITOR.MENU()

    rv  = Start_Window('DIALOG_SAP_COMM', '')

end event


Event MENU.ADMIN.TOOLS_EVAC.MENU()

    // Require the user to acknowledge using their application password.
    MsgOverride             = ''
    MsgOverride<MDEFBTN$>   = 2 ; // Default to Cancel button.
    Valid                   = Msg(@Window, MsgOverride, 'OK_CANCEL', '', 'Evac Procedures' : @FM : 'Please confirm that you wish to put all tools into Evac mode.')

    If Valid EQ '' then
        UserName    = Oconv(@USER4, '[XLATE_CONV,LSL_USERS*FIRST_LAST]')
        CurrDate    = Date()
        CurrTime    = Time()
        EvacMode    = 'Facilities (UnSched)'
        EvacNotes   = 'Fab Evac'
        NumberTools = 0

        // Step 1 - Update the Reactor Tools. This logic is based on the script event handler in the REACT_MODE_CHG.APPLY
        // pushbutton control.

        ReactorNos  = Reactor_Services('GetReactorNumbers')
        For Each ReactorNo in ReactorNos using @FM
            ReactModeRow    = Database_Services('ReadDataRow', 'CONFIG', 'REACT_MODE' : ReactorNo)
            ReactModeDesc   = ReactModeRow<Mode$>
            If ReactModeDesc _NEC 'Shutdown' then
                ReactUtilID     = ReactModeRow<ReactUtilID$>
                ReactLogID      = ReactModeRow<ReactorLogID$>
                If ReactUtilID NE '' then
                    ReactUtilRow                                = Database_Services('ReadDataRow', 'REACT_UTIL', ReactUtilID)
                    ReactUtilRow<REACT_UTIL_END_DATE$>          = CurrDate
                    ReactUtilRow<REACT_UTIL_END_TIME$>          = CurrTime
                    ReactUtilRow<REACT_UTIL_MODE_FINISH_USER$>  = @USER4
                    Database_Services('WriteDataRow', 'REACT_UTIL', ReactUtilID, ReactUtilRow, True$, '', True$)
                end else
                    ReactUtilRow                                = ''
                end

                hReactUtil                                      = Database_Services('GetTableHandle', 'REACT_UTIL')
                KeyToUse                                        = Next_Key('REACT_UTIL', hReactUtil, 'NEXT', '')
                NewReactUtilRow                                 = ''
                NewReactUtilRow<REACT_UTIL_REACTOR$>            = ReactorNo
                NewReactUtilRow<REACT_UTIL_NOTES$>              = EvacNotes
                NewReactUtilRow<REACT_UTIL_MODE$>               = 'S'
                NewReactUtilRow<REACT_UTIL_START_DATE$>         = CurrDate
                NewReactUtilRow<REACT_UTIL_START_TIME$>         = CurrTime
                NewReactUtilRow<REACT_UTIL_MODE_START_USER$>    = @USER4
                WorkOrderNo                                     = ReactUtilRow<REACT_UTIL_WO$>
                NewReactUtilRow<REACT_UTIL_WO$>                 = WorkOrderNo
                NewReactUtilRow<REACT_UTIL_CUST_NO$>            = Xlate('WO_LOG', WorkOrderNo, WO_LOG_CUST_NO$, 'X')
                NewReactUtilRow<REACT_UTIL_REACTOR_LOG_ID$>     = ''
                Database_Services('WriteDataRow', 'REACT_UTIL', KeyToUse, NewReactUtilRow, True$, '', True$)
                Database_Services('ReleaseKeyIDLock', 'REACT_UTIL', KeyToUse)
                Next_Key('REACT_UTIL', HReactUtil, 'UPDATE', KeyToUse)

                NewReactModeRow                 = ''
                NewReactModeRow<Mode$>          = EvacMode
                NewReactModeRow<Username$>      = UserName
                NewReactModeRow<Date$>          = Oconv(CurrDate, 'D4/')
                NewReactModeRow<Time$>          = Oconv(CurrTime, 'MTH')
                NewReactModeRow<ReactUtilID$>   = KeyToUse
                NewReactModeRow<ReactorLogID$>  = ''
                NewReactModeRow<Note$>          = EvacNotes

                CurrDTM     = NewReactModeRow<Date$> : ' ' : NewReactModeRow<Time$>
                PrevModeKey = Xlate('REACTOR_CHILD_KEY_IDS', ReactorNo, REACTOR_CHILD_KEY_IDS_REACT_MODE_KEY_IDS$, 'X')<1, 1>
                OpenDTM     = Field(PrevModeKey, '*', 2)
                OpenDTM     = Oconv(OpenDTM, 'DT4/^S')
                CurrMode    = Oconv(Xlate('REACTOR', ReactorNo, 'CURR_MODE', 'X'), '[REACT_MODE_CONV]')
                ProdModes   = 'Production':@VM
                ProdModes  := 'Production (incr sampling)'
                Locate CurrMode in ProdModes Using @VM Setting vPos then
                    Locate EvacMode in ProdModes Using @VM Setting vPos else
                        OutOfProdDTM    = NewReactModeRow<Date$> : ' ' : NewReactModeRow<Time$>
                        obj_React_Status('SetOutOfProdDTM', ReactorNo : @RM : OutOfProdDTM)
                    end ; // End of check on New Mode
                end ; // End of check on Current Mode

                Database_Services('WriteDataRow', 'CONFIG', 'REACT_MODE' : ReactorNo, NewReactModeRow, True$, '', True$)
                If Error_Services('NoError') then
                    NumberTools    += 1
                    If CurrMode NE '' then
                        // Close the currently active mode
                        crParms  = ReactorNo
                        crParms := @RM : OpenDTM
                        crParms := @RM : CurrDTM
                        crParms := @RM : @USER4
                        crParms := @RM : NewReactModeRow<Note$>
                        crParms := @RM : NewReactModeRow<ReactUtilID$>
                        crParms := @RM : NewReactModeRow<ReactorLogID$>
                        obj_React_Mode('Close', crParms)
                    end
                    // Create new active mode record
                    crParms  = ReactorNo
                    crParms := @RM : CurrDTM
                    crParms := @RM : @USER4
                    crParms := @RM : NewReactModeRow<Mode$>
                    crParms := @RM : NewReactModeRow<Note$>
                    crParms := @RM : NewReactModeRow<ReactUtilID$>
                    crParms := @RM : NewReactModeRow<ReactorLogID$>
                    obj_React_Mode('Create', crParms)
                end
            end
        Next ReactorNo

        // Step 2 - Update the Silicon Tools. This logic is based on the TBClick gosub in the Comm_Dialog_Tool_Status
        // commuter module. This commuter module supports the TOOL_STATUS form.

        ToolIDs = obj_Tool('KeysByType')    ; // All tool IDs sorted by TOOL_TYPE
        For Each ToolID in ToolIDs using @VM
            ToolRow     = Database_Services('ReadDataRow', 'TOOL', ToolID)
            CurrModeKey = ToolRow<TOOL_CURR_MODE_KEY$>
            CurrMode    = Xlate('TOOL', ToolID, 'CURR_MODE', 'X')<1, 1>
            If CurrMode NE 'OUT' AND CurrMode NE 'FACILITIES (UnSched)' then
                If CurrMode EQ '' then
                    obj_Tool_Log('InitialLog', ToolID)
                    CurrMode    = 'OUT'
                end

                NumberTools    += 1
                CurrModeDTM     = Field(CurrModeKey, '*', 2)
                CurrModeDTM     = Oconv(CurrModeDTM, 'DT4/^S')
                Parms           = ToolID : @RM
                Parms          := CurrModeDTM : @RM
                Parms          := 'FACILITIES (UnSched)' : @RM
                Parms          := EvacNotes
                obj_Tool_Log('SetMode', Parms)
            end
        Next ToolID

        // Step 3 - Update the GaN Tools. This logic is based on the ToolOptions gosub in the GaN_Tool_Status commuter
        // module. This commuter module supports the GAN_TOOL_STATUS form.

        SelectSent  = 'SELECT TOOL WITH TOOL_PROC "G" AND WITH CLASS NE "G_REACT" BY TOOL_WH BY TOOL_TYPE'
        RList(SelectSent, TARGET_ACTIVELIST$, '', '', '')
	    EOF         = False$
	    Loop
	        Readnext ToolID else EOF = True$
        Until EOF
            ToolRow     = Database_Services('ReadDataRow', 'TOOL', ToolID)
            CurrModeKey = ToolRow<TOOL_CURR_MODE_KEY$>
            CurrMode    = Xlate('TOOL', ToolID, 'CURR_MODE', 'X')<1, 1>
            If CurrMode NE 'OUT' AND CurrMode NE 'FACILITIES (UnSched)' then
                If CurrMode EQ '' then
                    obj_Tool_Log('InitialLog', ToolID)
                    CurrMode    = 'OUT'
                end

                NumberTools    += 1
                CurrModeDTM     = Field(CurrModeKey, '*', 2)
                CurrModeDTM     = Oconv(CurrModeDTM, 'DT4/^S')
                Parms           = ToolID : @RM
                Parms          := CurrModeDTM : @RM
                Parms          := 'FACILITIES (UnSched)' : @RM
                Parms          := EvacNotes
                obj_Tool_Log('SetMode', Parms)
            end
	    Repeat
	    Msg(@Window, '', 'OK', '', 'Evac Procedures' : @FM : NumberTools : ' tools have been placed into Evac mode.')
    end

end event


Event MENU.ADMIN.DEVELOPER.SESSION_MANAGER.MENU()

    rv  = Start_Window('NDW_SESSION_MANAGER', '')

end event


Event OLE_NOTES.OnClick(Point, Button, Shift, Ctrl)
    
    rv  = Start_Window('NOTE_PTRS', '')
    
end event


Event OLE_SNOOZE.OnClick(Point, Button, Shift, Ctrl)
	
    Snoozed = Notes_Services('CheckForNotificationSnooze', @USER4)
    If Snoozed then
    	Notes_Services('AllowNewMessageNotifications', @USER4)
    end else
		Notes_Services('SnoozeNewMessageNotifications', @USER4)
	end
    Gosub SetSnoozeButtonState
    
end event


Event OLE_WIP_STATUS.OnClick(Point, Button, Shift, Ctrl)
    
    Start_Window('REACT_STATUS_EVEN',@WINDOW,'')
    Start_Window('REACT_STATUS_ODD',@WINDOW,'')
    Start_Window('TOOL_STATUS',@WINDOW,'')
    
end event


Event OLE_RDS.OnClick(Point, Button, Shift, Ctrl)
    
    rv  = Start_Window('RDS', '')
    
end event

Event OLE_WM_OUT.OnClick(Point, Button, Shift, Ctrl)
    
    rv  = Start_Window('WM_OUT', '')
    
end event

Event OLE_WORK_ORDER.OnClick(Point, Button, Shift, Ctrl)
    
    rv  = Start_Window('NDW_WO_LOG', '')
    
end event

Event OLE_LOG_TEST_RUN.OnClick(Point, Button, Shift, Ctrl)
    
    rv  = Start_Window('NDW_LOG_TEST_WAFER_USAGE', '')
    
end event


Event MENU.MAINTENANCE.0311_OCAP_FORM.MENU()
    
    Command = 'start microsoft-edge:https://messa014.infineon.com:5022/'
    SRP_Run_Command(Command, '', '', '')
    
end event


Event MENU.PROD.NDW_RDS_QUERY.MENU()
    
    SelRDSKeys = Dialog_Box('NDW_RDS_QUERY', @Window)
    IF SelRDSKeys NE '' THEN
        Void = Start_Window( 'RDS', @window, SelRDSKeys:'*CENTER', '', '' )
    END
    
end event


Event WINDOW.OMNIEVENT(Message, Param1, Param2, Param3, Param4)
	
    Gosub FixFont   

End event

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

Setup_OLE_Controls:

	PlaceDialog(-2, -2)

    Qualify     = ''
    Qualify<1>  = 1
    Qualify<4>  = 0

    Ctrl    = @Window : '.OLE_LAUNCHER'
    Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnLaunchAttempt', Qualify)
    Send_Message(@Window : '.OLE_NOTES', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    FontArray = Get_Property(@Window:'.OLE_NOTES', 'OLE.Font')
    FontArray<1, 1, 2> = 14
    Set_Property(@Window:".OLE_NOTES", "OLE.Font", FontArray)
    
    Send_Message(@Window : '.OLE_SNOOZE', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    FontArray<1, 1, 2> = 10
    Set_Property(@Window:".OLE_SNOOZE", "OLE.Font", FontArray)
    
    ColorFill = ''
    FontArray<1, 1, 2> = 11
	Send_Message(@Window : '.OLE_WIP_STATUS', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    Set_Property(@Window:".OLE_WIP_STATUS", "OLE.Font", FontArray)
    ColorFill<1> = "White"
    ColorFill<2> = "White"
    ColorFill<3> = "White"
    ColorFill<5> = "White"
    Set_Property(@Window:".OLE_WIP_STATUS", "OLE.ForeColor", ColorFill)
    ColorFill = ''
    ColorFill<1> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<2> = "Vertical(Gradient(RGB(10, 130, 118) L=40, RGB(10, 130, 118) L=40), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<3> = "Vertical(Gradient(RGB(10, 130, 118) L=20, RGB(10, 130, 118) L=20), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<5> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    Set_Property(@Window : '.OLE_WIP_STATUS', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_WIP_STATUS", "OLE.Caption", "WIP Status")
    
    ColorFill = ''
    Send_Message(@Window : '.OLE_RDS', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    Set_Property(@Window:".OLE_RDS", "OLE.Font", FontArray)
    ColorFill<1> = "White"
    ColorFill<2> = "White"
    ColorFill<3> = "White"
    ColorFill<5> = "White"
    Set_Property(@Window:".OLE_RDS", "OLE.ForeColor", ColorFill)
    ColorFill = ''
    ColorFill<1> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<2> = "Vertical(Gradient(RGB(10, 130, 118) L=40, RGB(10, 130, 118) L=40), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<3> = "Vertical(Gradient(RGB(10, 130, 118) L=20, RGB(10, 130, 118) L=20), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<5> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    Set_Property(@Window : '.OLE_RDS', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_RDS", "OLE.Caption", "RDS")
    
    ColorFill = ''
    Send_Message(@Window : '.OLE_WM_OUT', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    Set_Property(@Window:".OLE_WM_OUT", "OLE.Font", FontArray)
    ColorFill<1> = "White"
    ColorFill<2> = "White"
    ColorFill<3> = "White"
    ColorFill<5> = "White"
    Set_Property(@Window:".OLE_WM_OUT", "OLE.ForeColor", ColorFill)
    ColorFill = ''
    ColorFill<1> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<2> = "Vertical(Gradient(RGB(10, 130, 118) L=40, RGB(10, 130, 118) L=40), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<3> = "Vertical(Gradient(RGB(10, 130, 118) L=20, RGB(10, 130, 118) L=20), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<5> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    Set_Property(@Window : '.OLE_WM_OUT', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_WM_OUT", "OLE.Caption", "WM Out")
    
    ColorFill = ''
    Send_Message(@Window : '.OLE_WORK_ORDER', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    Set_Property(@Window:".OLE_WORK_ORDER", "OLE.Font", FontArray)
    ColorFill<1> = "White"
    ColorFill<2> = "White"
    ColorFill<3> = "White"
    ColorFill<5> = "White"
    Set_Property(@Window:".OLE_WORK_ORDER", "OLE.ForeColor", ColorFill)
    ColorFill = ''
    ColorFill<1> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<2> = "Vertical(Gradient(RGB(10, 130, 118) L=40, RGB(10, 130, 118) L=40), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<3> = "Vertical(Gradient(RGB(10, 130, 118) L=20, RGB(10, 130, 118) L=20), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<5> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    Set_Property(@Window : '.OLE_WORK_ORDER', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_WORK_ORDER", "OLE.Caption", "Work Order")
    
    ColorFill    = ''
    Send_Message(@Window : '.OLE_LOG_TEST_RUN', 'QUALIFY_EVENT', 'OLE.OnClick', Qualify)
    Set_Property(@Window:".OLE_LOG_TEST_RUN", "OLE.Font", FontArray)
    ColorFill<1> = "White"
    ColorFill<2> = "White"
    ColorFill<3> = "White"
    ColorFill<5> = "White"
    Set_Property(@Window:".OLE_LOG_TEST_RUN", "OLE.ForeColor", ColorFill)
    ColorFill    = ''
    ColorFill<1> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<2> = "Vertical(Gradient(RGB(10, 130, 118) L=40, RGB(10, 130, 118) L=40), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<3> = "Vertical(Gradient(RGB(10, 130, 118) L=20, RGB(10, 130, 118) L=20), Border(RGB(10, 130, 118)),Rounded(1))"
    ColorFill<5> = "Vertical(Gradient(RGB(10, 130, 118), (10, 130, 118)),Border(RGB(10, 130, 118)),Rounded(1))"
    Set_Property(@Window : '.OLE_LOG_TEST_RUN', "OLE.Background", ColorFill)
    Set_Property(@Window:".OLE_LOG_TEST_RUN", "OLE.Caption", "Log TW Usage")
    
return


SetSnoozeButtonState:
	
	Snoozed = Notes_Services('CheckForNotificationSnooze', @USER4)
	ColorFill   = ''
	If Snoozed then
		ColorFill<1> = "Vertical(Gradient(RGB(108, 180, 173), (108, 180, 173)),Border(RGB(108, 180, 173)),Rounded(1))"
		ColorFill<2> = "Vertical(Gradient(RGB(108, 180, 173) L=60, RGB(108, 180, 173) L=60), Border(RGB(108, 180, 173)),Rounded(1))"
        ColorFill<3> = "Vertical(Gradient(RGB(108, 180, 173) L=40, RGB(108, 180, 173) L=40), Border(RGB(108, 180, 173)),Rounded(1))"
        ColorFill<5> = "Vertical(Gradient(RGB(108, 180, 173), (108, 180, 173)),Border(RGB(108, 180, 173)),Rounded(1))"
		Set_Property(@Window:".OLE_SNOOZE", "OLE.Caption", "Do Not Disturb On")
	end else
		ColorFill<1> = "Vertical(RGB(141,135,134), Border(RGB(141,135,134)), Rounded(1))"
		ColorFill<2> = "Vertical(Gradient(RGB(141,135,134) L=60,RGB(141,135,134) L=60, Border(RGB(141,135,134)) Rounded(1))"
		ColorFill<3> = "Vertical(Gradient(RGB(141,135,134) L=40,RGB(141,135,134) L=40, Border(RGB(141,135,134)) Rounded(1))"
		ColorFill<5> = "Vertical(RGB(141,135,134), Border(RGB(141,135,134)), Rounded(1))"
		Set_Property(@Window:".OLE_SNOOZE", "OLE.Caption", "Do Not Disturb Off")
	end
	Set_Property(@Window : '.OLE_SNOOZE', "OLE.Background", ColorFill)
	
return


FixFont:
	
    FontArray = Get_Property(@Window:'.OLE_NOTES', 'OLE.Font')
    FontArray<1, 1, 2> = 14
    Set_Property(@Window:".OLE_NOTES", "OLE.Font", FontArray)
    FontArray<1, 1, 2> = 10
    Set_Property(@Window:".OLE_SNOOZE", "OLE.Font", FontArray)
    FontArray<1, 1, 2> = 11
    Set_Property(@Window:".OLE_WIP_STATUS", "OLE.Font", FontArray)
    Set_Property(@Window:".OLE_RDS", "OLE.Font", FontArray)
    Set_Property(@Window:".OLE_WM_OUT", "OLE.Font", FontArray)
    Set_Property(@Window:".OLE_WORK_ORDER", "OLE.Font", FontArray)
    Set_Property(@Window:".OLE_LOG_TEST_RUN", "OLE.Font", FontArray)
    Set_Property(@Window:".OLE_PIC_CURRENT_USER", "OLE.Font", FontArray)
        
return





