Compile function NDW_REACTOR_SELECTION_EVENTS(CtrlEntId, Event, @PARAMS)
#pragma precomp SRP_PreCompiler
#window NDW_REACTOR_SELECTION

$Insert LOGICAL
$Insert RLIST_EQUATES

Declare subroutine End_Dialog, Set_Property, Database_Services, SRP_Show_Window, Form_Services
Declare function   Get_Property, Database_Services, Form_Services

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

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

Event WINDOW.CREATE(CreateParam)

    // Fill to and from combo boxes
    ReactorList = Database_Services('ReadDataRow', 'SYSLISTS', 'REACTOR_LIST')
    // Remove field containing list description
    ReactorList = Delete(ReactorList, 1, 0, 0)
    Set_Property(@Window, '@REACTOR_LIST', ReactorList)
    Set_Property(@Window : '.COMBO_FROM', 'LIST', ReactorList)
    Set_Property(@Window : '.COMBO_TO', 'LIST', ReactorList)
     
    GoSub Setup_OLE_Controls

    SRP_Show_Window(@Window, 'SYSTEM', 'C', 'C', 1, '', False$, False$, FormSize)
    Eventflow = 1    
    
End Event


Event PUB_CANCEL.CLICK()
    
    Result = False$
    End_Dialog(@Window, Result)
    
end event


Event PUB_OK.CLICK()
    
    Result       = ''
    ReactorBegin = ''
    ReactorEnd   = ''
    RadioVal     = Get_Property(@Window : '.RADIO_SEL', 'VALUE')
    Begin Case
        Case RadioVal EQ 'All'
            ReactorList  = Get_Property(@Window, '@REACTOR_LIST')
            NumReactors  = DCount(ReactorList, @FM)
            ReactorBegin = ReactorList<1>
            ReactorEnd   = ReactorList<NumReactors>
        Case RadioVal EQ 'Sel'
            ReactorBegin = Get_Property(@Window : '.COMBO_FROM', 'TEXT')
            ReactorEnd   = Get_Property(@Window : '.COMBO_TO', 'TEXT')
    End Case
    Result = ReactorBegin : @FM : ReactorEnd
    End_Dialog(@Window, Result)
    
end event


Event RADIO_SEL.ALL.CLICK()
    
    // -1 -> Disabled Hard
    Set_Property(@Window : '.COMBO_FROM', 'ENABLED', '-1')
    Set_Property(@Window : '.COMBO_TO', 'ENABLED', '-1')
    Eventflow = 1
    
end event


Event RADIO_SEL.SELECTION.CLICK()
    
    Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
    Set_Property(@Window : '.COMBO_FROM', 'ENABLED', True$)
    Set_Property(@Window : '.COMBO_TO', 'ENABLED', True$)
    Eventflow = 1
        
end event


Event COMBO_FROM.CHANGED(NewData)
       
    Form_Services('CloseControlMessage', CtrlEntId)
    ReactorFrom = Get_Property(CtrlEntId, 'TEXT')
    ReactorList = Get_Property(@Window, '@REACTOR_LIST')
    Locate ReactorFrom in ReactorList using @FM setting ReactorIndex then        
        ReactorTo = Get_Property(@Window : '.COMBO_TO', 'TEXT')
        If ReactorTo NE '' then
            If ReactorFrom GT ReactorTo then
                ReactorFrom = ReactorTo
                Set_Property(CtrlEntID, 'TEXT', ReactorFrom)
            end
        end   
        If (ReactorFrom NE '') and (ReactorTo NE '') then
            Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
        end else
            Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
        end
    end else
        Set_Property(CtrlEntID, 'FOCUS', True$)
        Set_Property(CtrlEntID, 'SELECTION', 1 : @FM : 999)
        Message = 'Invalid reactor entered. Please enter a valid reactor number'
        Form_Services('DisplayControlMessage', Message, 'Invalid Reactor', CtrlEntID, 'VALIDATION', 'RGB(229,20,0)')
    end
    Eventflow = 1
        
end event


Event COMBO_FROM.CHAR(VirtCode, ScanCode, CtrlKey, ShiftKey, AltKey)
    
    Form_Services('CloseControlMessage', CtrlEntId)
    ReactorFrom = Get_Property(CtrlEntId, 'TEXT')        
    ReactorTo = Get_Property(@Window : '.COMBO_TO', 'TEXT')

    If (ReactorFrom NE '') and (ReactorTo NE '') then
        Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
    end else
        Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
    end
    Eventflow = 1

end event


Event COMBO_FROM.LOSTFOCUS(Flag, FocusID)
    
    ReactorFrom = Get_Property(CtrlEntId, 'TEXT')
    ReactorList = Get_Property(@Window, '@REACTOR_LIST')
    Locate ReactorFrom in ReactorList using @FM setting ReactorIndex then        
        ReactorTo = Get_Property(@Window : '.COMBO_TO', 'TEXT')
        If ReactorTo NE '' then
            If ReactorFrom GT ReactorTo then
                ReactorFrom = ReactorTo
                Set_Property(CtrlEntID, 'TEXT', ReactorFrom)
            end
        end   
        If (ReactorFrom NE '') AND (ReactorTo NE '') then
            Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
        end else
            Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
        end
        Eventflow = 1
    end else
        Set_Property(CtrlEntID, 'FOCUS', True$)
        Set_Property(CtrlEntID, 'SELECTION', 1 : @FM : 999)
        Message = 'Invalid reactor entered. Please enter a valid reactor number'
        Form_Services('DisplayControlMessage', Message, 'Invalid Reactor', CtrlEntID, 'VALIDATION', 'RGB(229,20,0)')
        Eventflow = 0
    end
    
end event


Event COMBO_TO.CHANGED(NewData)
    
    Form_Services('CloseControlMessage', CtrlEntId)
    ReactorTo   = Get_Property(CtrlEntId, 'TEXT')
    ReactorList = Get_Property(@Window, '@REACTOR_LIST')
    Locate ReactorTo in ReactorList using @FM setting ReactorIndex then        
        ReactorFrom = Get_Property(@Window : '.COMBO_FROM', 'TEXT')
        If ReactorFrom NE '' then
            If ReactorFrom GT ReactorTo then
                ReactorFrom = ReactorTo
                Set_Property(@Window : '.COMBO_FROM', 'TEXT', ReactorFrom)
            end
        end   
        If (ReactorFrom NE '') and (ReactorTo NE '') then
            Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
        end else
            Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
        end
    end else
        Set_Property(CtrlEntID, 'FOCUS', True$)
        Set_Property(CtrlEntID, 'SELECTION', 1 : @FM : 999)
        Message = 'Invalid reactor entered. Please enter a valid reactor number'
        Form_Services('DisplayControlMessage', Message, 'Invalid Reactor', CtrlEntID, 'VALIDATION', 'RGB(229,20,0)')
    end
    Eventflow = 1
        
end event


Event COMBO_TO.CHAR(VirtCode, ScanCode, CtrlKey, ShiftKey, AltKey)
    
    Form_Services('CloseControlMessage', CtrlEntId)
    ReactorTo   = Get_Property(CtrlEntId, 'TEXT')        
    ReactorFrom = Get_Property(@Window : '.COMBO_FROM', 'TEXT')

    If (ReactorFrom NE '') and (ReactorTo NE '') then
        Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
    end else
        Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
    end
    
    Eventflow = 1
        
end event


Event COMBO_TO.LOSTFOCUS(Flag, FocusID)
    
    ReactorTo   = Get_Property(CtrlEntId, 'TEXT')
    ReactorList = Get_Property(@Window, '@REACTOR_LIST')
    Locate ReactorTo in ReactorList using @FM setting ReactorIndex then        
        ReactorFrom = Get_Property(@Window : '.COMBO_FROM', 'TEXT')
        If ReactorFrom NE '' then
            If ReactorFrom GT ReactorTo then
                ReactorFrom = ReactorTo
                Set_Property(@Window : '.COMBO_FROM', 'TEXT', ReactorFrom)
            end
        end   
        If (ReactorFrom NE '') AND (ReactorTo NE '') then
            Set_Property(@Window : '.PUB_OK', 'ENABLED', True$)
        end else
            Set_Property(@Window : '.PUB_OK', 'ENABLED', False$)
        end
        Eventflow = 1
    end else
        Set_Property(CtrlEntID, 'FOCUS', True$)
        Set_Property(CtrlEntID, 'SELECTION', 1 : @FM : 999)
        Message = 'Invalid reactor entered. Please enter a valid reactor number'
        Form_Services('DisplayControlMessage', Message, 'Invalid Reactor', CtrlEntID, 'VALIDATION', 'RGB(229,20,0)')
        Eventflow = 0
    end
    
end event


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


Setup_OLE_Controls:

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

return
