Function NDW_Session_Manager_Left_Menu_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_Session_Manager_Left_Menu_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/17/18    dmb     Created initial commuter module.

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

#pragma precomp SRP_PreCompiler
#Window NDW_SESSION_MANAGER

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES

Declare subroutine  SRP_Show_Window, Placedialog, Messaging_Services
Declare function    Database_Services, Messaging_Services, GetCurrentProcessId

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)

    GoSub Setup_OLE_Controls

    Set_Property(@Window : '.PUB_CLOSE', 'NEXT', @Window : '.PUB_CLOSE')
    Set_Property(@Window : '.PUB_REFRESH', 'NEXT', @Window : '.PUB_REFRESH')
    Set_Property(@Window : '.PUB_FIND_LOCK_OWNER', 'NEXT', @Window : '.EDL_TABLE_NAME')
    

    SRP_Show_Window(@Window, 'SYSTEM', 'C', 'C', 1, '', False$, False$)
    Placedialog(-2, -2)

end event


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

    Begin Case
        Case Message _EQC 'GetLoggedInUsers'
            Transfer Param1 to SessionInfo
            Station         = SessionInfo<1, 2>
            OIUserName      = SessionInfo<2, 2>
            SSOUserName     = SessionInfo<3, 2>
            ProcessID       = SessionInfo<4, 2>
            Send_Message(@Window : '.OLE_RPT_USER_SESSIONS', 'OLE.Insert', -1, Station : @VM : OIUserName : @VM : SSOUserName : @VM : ProcessID)
            NumOfSessions   = Get_Property(@Window : '.EDL_NUMBER_OF_SESSIONS', 'TEXT')
            NumOfSessions  += 1
            Set_Property(@Window : '.EDL_NUMBER_OF_SESSIONS', 'TEXT', NumOfSessions)

        Case Message _EQC 'GetLockOwner'
            Transfer Param1 to LockInfo
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;1]', LockInfo<1>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;2]', LockInfo<2>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;3]', LockInfo<3>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;4]', LockInfo<4>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;5]', LockInfo<5>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;6]', LockInfo<6>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;7]', 'Lock owner found.')

        Case Message _EQC 'ReleaseLock'
            Transfer Param1 to LockInfo
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;1]', LockInfo<1>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;2]', LockInfo<2>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;3]', LockInfo<3>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;4]', LockInfo<4>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;5]', LockInfo<5>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;6]', LockInfo<6>[-1, 'B '])
            Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;7]', 'Lock was released.')
            
    End Case

end event


Event PUB_REFRESH.CLICK()

    Set_Property(@Window : '.OLE_RPT_USER_SESSIONS', 'OLE.List', '')
    Set_Property(@Window : '.EDL_NUMBER_OF_SESSIONS', 'TEXT', 0)
    Messaging_Services('SendMessage', 'GetLoggedInUsers', 'Request', '', 'All', '', 'EventHandler', @Window : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')

end event


Event PUB_FIND_LOCK_OWNER.CLICK()

    TableName   = Get_Property(@Window : '.EDL_TABLE_NAME', 'TEXT')
    KeyID       = Get_Property(@Window : '.EDL_KEY_ID', 'TEXT')
    If (TableName NE '') AND (KeyID NE '') then
        Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;All]', '')
        Messaging_Services('SendMessage', 'GetLockOwner', 'Request', '', 'All', TableName : ',' : KeyID, 'EventHandler', @Window : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')
    end

end event


Event PUB_RELEASE_LOCK.CLICK()

    TableName   = Get_Property(@Window : '.EDL_TABLE_NAME', 'TEXT')
    KeyID       = Get_Property(@Window : '.EDL_KEY_ID', 'TEXT')
    If (TableName NE '') AND (KeyID NE '') then
        Set_Property(@Window : '.OLE_EDT_LOCK_INFORMATION', 'OLE.CellText[1;All]', '')
        Messaging_Services('SendMessage', 'ReleaseLock', 'Request', '', 'All', TableName : ',' : KeyID, 'EventHandler', @Window : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')
    end

end event


Event PUB_SEND_MESSAGE.CLICK()

    SessionInfo = Get_Property(@Window : '.EDT_USER_SESSIONS', 'ROWDATA')
    If SessionInfo NE '' then
        Message     = Get_Property(@Window : '.EDL_MESSAGE', 'TEXT')
        If Message NE '' then
            Messaging_Services('SendMessage', 'SetPopupMessage', 'Request', '', SessionInfo<1>, Message)
        end
    end

end event


Event OLE_RPT_USER_SESSIONS.OnItemClick(Row, Button, Col, Point)

    Begin Case
        Case Button _EQC 'Right'
            ContextMenu     = 'SEND_MESSAGE' : @VM : 'Send Message' : @FM
            ContextMenu    := 'CLOSE_SESSION' : @VM : 'Close Session'
            SelPos          = Get_Property(CtrlEntId, 'OLE.SelPos')
            Convert @FM to ';' in SelPos
            Send_Message(CtrlEntId, 'OLE.ShowContextMenu', Point, ContextMenu, SelPos)

    End Case

end event


Event OLE_RPT_USER_SESSIONS.OnContextMenuClick(Item, UserData)

    Begin Case
        Case Item _EQC 'SEND_MESSAGE'
            For Each Row in UserData using ';'
                SessionID   = Get_Property(CtrlEntID, 'OLE.RowData[' : Row : ']')<1>
                Messaging_Services('SendMessage', 'SetPopupMessage', 'Request', '', SessionID, 'Testing the new messaging service.')
            Next Row

        Case Item _EQC 'CLOSE_SESSION'
            Continue    = Msg(@Window, '', 'YESNO', '', 'Session Manager' : @FM : 'Warning! This will attempt to close active OpenInsight sessions. Please confirm that this is what you want to do.')
            If Continue EQ True$ then
                
            end

    End Case

end event


Event OLE_TRE_MENU.OnSelChange(Selection)

    Begin Case
        Case Selection _EQC 'User Sessions'
            Page        = 1
            FocusCtrl   = @Window : '.PUB_REFRESH'
        Case Selection _EQC 'Lock Management'
            Page        = 2
            FocusCtrl   = @Window : '.EDL_TABLE_NAME'
        Case Selection _EQC 'Send Message'
            Page        = 3
            FocusCtrl   = ''
        Case Selection _EQC 'Close Session'
            Page        = 4
            FocusCtrl   = ''
    End Case
    Send_Event(@Window, 'PAGE', Page)
    Set_Property(FocusCtrl, 'FOCUS', True$)

end event


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

Setup_OLE_Controls:

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

    Ctrl        = @Window : '.OLE_TAB'
    Set_Property(Ctrl, 'OLE.AllowXPTheme', False$)
    Set_Property(Ctrl, 'OLE.Height', -66)
    Set_Property(Ctrl, 'OLE.CustomPaneColor', 'Horizontal(Gradient(White , White), Border(None, 3DS, 3DS, 3DS))')

    Ctrl        = @Window : '.OLE_PIC_LEFT_BORDER'
    Set_Property(Ctrl, 'OLE.Border', 'Custom Thin')
    Set_Property(Ctrl, 'OLE.BorderColors', '3DS' : @FM : '3DS' : @FM : '3DS' : @FM : '3DS')

    Ctrl        = @Window : '.OLE_TRE_MENU'
    Set_Property(Ctrl, 'OLE.Border', 'None')
    Set_Property(Ctrl, 'OLE.Background', 'None')
    Set_Property(Ctrl, 'OLE.FullRowSelect', True$)
    Set_Property(Ctrl, 'OLE.RootIndent', False$)
    Set_Property(Ctrl, 'OLE.LinesEnabled', False$)
    Set_Property(Ctrl, 'OLE.ShowFocusItem', False$)
    DefColors   = 'MidnightBlue' : @FM : 'Horizontal(Gradient(White L=90, White), Gradient(White, White L=90), Border(3DS, 3DS, 3DS, 3DS))'
    Set_Property(Ctrl, 'OLE.DefColors', DefColors)
    Set_Property(Ctrl, 'OLE.DefHeight', 32)
    Set_Property(Ctrl, 'OLE.DefAlignment', 'Center' : @FM : 'Center')
    Set_Property(Ctrl, 'OLE.DefFont', 'Segoe UI' : @SVM : 14)
    Colors      = 'MidnightBlue' : @VM : 'Horizontal(Gradient(White, White), Border(3DS, 3DS, None, 3DS))' : @FM
    Colors     := 'Blue' : @VM : 'Horizontal(Gradient(White, White L=90), Gradient(White L=90, White), Border(3DS, 3DS, 3DS, 3DS))' : @FM
    Colors     := 'Blue' : @VM : 'Horizontal(Gradient(White, White), Border(3DS, 3DS, None, 3DS))' : @FM
    Colors     := 'MidnightBlue' : @VM : 'Horizontal(Gradient(White, White), Border(3DS, 3DS, None, 3DS))' : @FM
    Set_Property(Ctrl, 'OLE.Colors', Colors)
    ItemList    = 1 : @VM : 'User Sessions' : @VM : 'User Sessions' : @FM
    ItemList   := 1 : @VM : 'Lock Management' : @VM : 'Lock Management' : @FM
    ItemList   := 1 : @VM : 'Send Message' : @VM : 'Send Message' : @FM
    ItemList   := 1 : @VM : 'Close Session' : @VM : 'Close Session'
    Set_Property(Ctrl, 'OLE.ItemList', ItemList)
    Set_Property(Ctrl, 'OLE.SelectedItems', 'User Sessions')
    Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnSelChange', 1)

    Ctrl        = @Window : '.OLE_RPT_USER_SESSIONS'
    ColumnList  = 'Station' : @VM : 'Text' : @VM : '100' : @VM : True$ : @FM
    ColumnList := 'OI UserName' : @VM : 'Text' : @VM : '100' : @VM : True$ : @FM
    ColumnList := 'SSO UserName' : @VM : 'Text' : @VM : '100' : @VM : True$ : @FM
    ColumnList := 'Process ID' : @VM : 'Number' : @VM : '100' : @VM : @VM : @VM : @VM : @VM : @VM : @VM : 'Right' : @VM : @VM : '#######' : True$
    Set_Property(Ctrl, 'OLE.ColumnList', ColumnList)
    Set_Property(Ctrl, 'OLE.ColumnFont[All]', 'Segoe UI' : @SVM : 9)
    Set_Property(Ctrl, 'OLE.ColumnHeaderFont[All]', 'Segoe UI' : @SVM : 9 : @SVM : 700)
    Set_Property(Ctrl, 'OLE.MultiSelect', 1)
    Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnItemClick', 1)
    Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnContextMenuClick', 1)

    Ctrl        = @Window : '.OLE_EDT_LOCK_INFORMATION'
    Set_Property(Ctrl, 'OLE.Dimension', 1 : @FM : 7)
    Set_Property(Ctrl, 'OLE.HeaderColumn[1]', 80 : @FM : True$ : @FM : False$ : @FM : False$)
    Set_Property(Ctrl, 'OLE.DataRow[All]', 23 : @FM : True$ : @FM : False$)
    Set_Property(Ctrl, 'OLE.HeaderRow[1]', @FM : False$)
    Set_Property(Ctrl, 'OLE.HeaderText[1;2]', '@Station')
    Set_Property(Ctrl, 'OLE.HeaderText[1;3]', '@User4')
    Set_Property(Ctrl, 'OLE.HeaderText[1;4]', '@UserName')
    Set_Property(Ctrl, 'OLE.HeaderText[1;5]', 'Process ID')
    Set_Property(Ctrl, 'OLE.HeaderText[1;6]', 'Table Name')
    Set_Property(Ctrl, 'OLE.HeaderText[1;7]', 'Key ID')
    Set_Property(Ctrl, 'OLE.HeaderText[1;8]', 'Message')
    Set_Property(Ctrl, 'OLE.DataColumn[1]', 240 : @FM : True$ : @FM : False$ : @FM : True$)
    Set_Property(Ctrl, 'OLE.HeaderFont[1;All]', 'Segoe UI' : @SVM : 9)
    Set_Property(Ctrl, 'OLE.HeaderFont[1;8]', 'Segoe UI' : @SVM : 9 : @SVM : 700)
    Set_Property(Ctrl, 'OLE.CellFont[1;All]', 'Segoe UI' : @SVM : 9)
    Set_Property(Ctrl, 'OLE.CellFont[1;7]', 'Segoe UI' : @SVM : 9 : @SVM : 700)
    Set_Property(Ctrl, 'OLE.ScrollBarsVisible', 'Never' : @FM : 'Never')
    Set_Property(Ctrl, 'ENABLED', False$)

return

