COMPILE FUNCTION REACT_STATE(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for REACT_STATE (Reactor State) window
	
	10/8/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, ErrMsg, obj_AppWindow, Error_Services
DECLARE FUNCTION   Get_Property, Send_Message, Start_Window, Reactor_Services, Error_Services

$INSERT APPCOLORS
$INSERT LOGICAL
$INSERT REACT_STATE_EQUATES
$INSERT POPUP_EQUATES

EQU CRLF$		TO \0D0A\
EQU TAB$		TO \09\

EQU COL$RI_NO			TO 1
EQU COL$RI_TYPE			TO 2
EQU COL$RI_DESC			TO 3
EQU COL$RI_SERIAL_NO	TO 4
EQU COL$RI_INST_DTM		TO 5
EQU COL$RI_RL_NO		TO 6

Equ POPUP_WHITE$         to 15400411
Equ POPUP_GREEN$         to 16777215

ErrTitle = 'Error in REACT_STATE commuter module'
ErrorMsg = ''

Result = ''

BEGIN CASE
    CASE EntID = @WINDOW
        BEGIN CASE
            CASE Event = 'CLEAR'		; GoSub Clear
            CASE Event = 'CREATE' 		; GoSub Create
            CASE Event = 'CLOSE'		; GoSub Close
            CASE Event = 'WRITE'		; GoSub Write
            CASE Event = 'READ'			; GoSub Read
            CASE Event[1,3] = 'QBF'		; GoSub Refresh
        END CASE
        
    CASE EntID = @WINDOW:'.CURR_RI_TYPE'                    AND Event = 'DBLCLK'    ; GoSub ReactItemDC
    CASE EntId = @Window:'.PUB_INJECTOR_SETTING_HISTORY'    and Event = 'CLICK'     ; GoSub DisplayInjectorHistory
    Case EntId = @Window:'.PUB_RATIO_HISTORY'               and Event = 'CLICK'     ; GoSub DisplayRatioHistory	
        
    CASE Otherwise$
        
        ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
        ErrMsg('Application Message':@SVM:ErrorMsg)
        
END CASE

IF ErrorMsg NE '' THEN
    ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result



* * * * * * *
Create:
* * * * * * *
    
    obj_Appwindow('Create',@WINDOW)
    
RETURN


* * * * * * *
Write:
* * * * * * *
    
    
RETURN



* * * * * * *
Clear:
* * * * * * *
    
    GOTO Refresh
    
RETURN

* * * * * * *
Read:
* * * * * * *
    
    
* * * * * * *
Refresh:
* * * * * * *
    
    * QBF buttons
    
    Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
    Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'
    
    IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
        Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
    END ELSE
        Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
    END
    
    Set_Property(Ctrls,Props,Vals)
    
    * Turn edit table symbolic column backgrounds to green
    
    ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow
    
    ETCtrls	= ETSymbolics<1>
    ETCols	= ETSymbolics<2>
    
    FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
        ETCtrl	= ETCtrls<1,I>
        ETList = Get_Property(ETCtrl,'LIST')
        FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
            IF ETList<Line,1> NE '' THEN
                FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
                    stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
                NEXT N
            END
        NEXT I
    NEXT I
    
    ReactNo = Get_Property(@Window:'.REACT_NO', 'TEXT')
    If ReactNo NE '' then 
        // Populate Current Injector Settings and Current Reactor Ratios
        InjSettings = OConv(Reactor_Services('GetCurrentInjectorSettings', ReactNo), 'MD3,')
        Set_Property(@Window:'.EDT_CURR_INJ_SETTINGS', 'ARRAY', InjSettings)
        Ratios      = OConv(Reactor_Services('GetCurrentRatios', ReactNo), 'MD3,')
        Set_Property(@Window:'.EDT_CURR_RATIOS', 'ARRAY', Ratios)
        NumRatios   = Reactor_Services('GetNumRatios', ReactNo)
        If Error_Services('NoError') then
            Set_Property(@Window:'.EDT_CURR_RATIOS', 'MINROWLIMIT', NumRatios)
            Set_Property(@Window:'.EDT_CURR_RATIOS', 'MAXROWLIMIT', NumRatios)
        end
    end
    
RETURN


* * * * * * *
ReactItemDC:
* * * * * * *
    
    CurrPos = Get_Property(EntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    CurrList = Get_Property(EntID,'LIST')
    
    BEGIN CASE
        CASE CurrCol = COL$RI_NO
            RINo = CurrList<CurrRow,COL$RI_NO>
            IF RINo NE '' THEN
                obj_AppWindow('ViewRelated','REACT_ITEM':@RM:RINo)
            END
            
        CASE CurrCol = COL$RI_RL_NO
            RLNo = CurrList<CurrRow,COL$RI_RL_NO>
            IF RLNo NE '' THEN
                Dummy = Start_Window( 'REACTOR_LOG', @WINDOW, RLNo:'*CENTER', '', '' )
            END
            
    END CASE
    
RETURN


* * * * * * *
Close:
* * * * * * *
    
    
    
RETURN


* * * * * * * * * * * *
DisplayInjectorHistory:
* * * * * * * * * * * *
    
    ReactNo = Get_Property(@Window:'.REACT_NO','DEFPROP')
    If ReactNo NE '' then
        TypeOver            = ''
        TypeOver<PDISPLAY$> = 'WITH REACTOR_NO = ':ReactNo:' BY-DSND INJ_SET_DTM'
        void = Popup(@Window,TypeOver,'REACT_INJ_SETTINGS')
    end
    
return


* * * * * * * * * * * *
DisplayRatioHistory:
* * * * * * * * * * * *
    
    ReactNo = Get_Property(@Window:'.REACT_NO','DEFPROP')
    If ReactNo NE '' then
        NumRatios = Reactor_Services('GetNumRatios', ReactNo)
        If Error_Services('NoError') then 
            DisplayText               = 'WITH REACTOR_NO EQ ':ReactNo:' BY-DSND RATIO_SET_DTM':@vm:''
            PopupRec                 = ""
            PopupRec<PFILE$>         = "REACTOR_RATIOS"
            PopupRec<PDISPLAY$>      = DisplayText
            PopupRec<PFORMAT$>       = 'REACTOR_NO':@svm:'6':@svm:'C':@svm:'C':@svm:'MD0':@svm:'Reactor No'
            PopupRec<PFORMAT$, -1>   = 'RATIO_SET_DTM':@svm:'16':@svm:'C':@svm:'C':@svm:'DT/^S':@svm:'Ratio Set Dtm'
            For RatioIndex = 1 to NumRatios
                PopupRec<PFORMAT$, -1>   = 'RATIO_':RatioIndex:@svm:'7':@svm:'C':@svm:'C':@svm:'MD3,':@svm:'Ratio ':RatioIndex
            Next RatioIndex
            PopupRec<PMODE$>          = 'T'
            PopupRec<PSELECT$>        = True$
            PopupRec<PTITLE$>         = 'Reactor Ratios'
            PopupRec<PFIELD$>         = True$
            PopupRec<PTYPE$>          = "F"
            PopupRec<PCOLHDR$>        = True$
            PopupRec<PROWNUM$>        = True$
            PopupRec<PROWBTN$>        = True$
            PopupRec<PHGRID$>         = True$
            PopupRec<PVGRID$>         = True$
            PopupRec<PRESIZE$>        = True$
            PopupRec<PBORDER$>        = True$
            PopupRec<PBTNSBELOW$>     = False$
            PopupRec<PSEARCH$>        = False$
            PopupRec<PSORT$>          = False$
            PopupRec<PLOCK$>          = False$
            PopupRec<PSHOWMISSING$>   = False$
            PopupRec<PPRINTABLE$>     = True$
            PopupRec<PSHOWGAUGE$>     = False$
            PopupRec<PCAPTUREESC$>    = False$
            PopupRec<PGREENBAR$>      = True$
            PopupRec<PODDROWCOLOR$>   = POPUP_WHITE$
            PopupRec<PEVENROWCOLOR$>  = POPUP_GREEN$
            Response                  = Popup(@Window, PopupRec, '')
        end else
            Error_Services('DisplayError')
        end
    end else
        Error_Services('Add', "Reactor number is missing")
        Error_Services('DisplayError')
    end
    
return


