COMPILE  FUNCTION GAN_STATUS(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)
#pragma precomp SRP_PreCompiler

/* 
	Commuter module for GAN_Status dialog window
	
	7/29/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, ErrMsg, obj_Appwindow, End_Dialog, Send_Message, Start_Window, Utility, Yield, WinYield
DECLARE SUBROUTINE Send_Event, Post_Event

DECLARE FUNCTION Get_Property, obj_GaN, obj_Gan_Test, Set_Property, GaN_Services, Database_Services


$INSERT APPCOLORS
$INSERT TOOL_CLASS_EQUATES
$INSERT TOOL_WFR_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT REACT_RUN_EQUATES

EQU COL$STAGE			TO 1
EQU COL$RDS_NO			TO 2
EQU COL$GAN_RUN_ID		TO 3
EQU COL$EPI_PART_NO		TO 4
EQU COL$REACT_RUN_PRI	TO 5

EQU COL$WAIT_WFR_QTY	TO 6
EQU COL$WAIT_HRS		TO 7
EQU COL$WAIT_WFR_ID		TO 8

EQU COL$TOOL_ID			TO 9
EQU COL$RUN_WFR			TO 10
EQU COL$RUN_HRS			TO 11
EQU COL$RUN_WFR_ID		TO 12

ErrTitle = 'Error in Master_Calib_List routine'
ErrorMsg = ''

Result = ''


BEGIN CASE
    CASE EntID = @WINDOW
        BEGIN CASE
            CASE Event = 'CREATE' 			; GOSUB Create
            CASE Event = 'CLOSE'			; GOSUB Close
            CASE Event = 'TIMER'			; GOSUB Refresh
                
        END CASE
    CASE EntID = @WINDOW:'.STAT_TABLE' AND Event = 'DBLCLK'		; GOSUB StatDC
        
    CASE 1
        ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
        ErrMsg(ErrorMsg)
        
END CASE

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

RETURN Result


* * * * * * *
Create:
* * * * * * *
    ScreenSize = Get_Property('SYSTEM','SIZE')
    DialogSize = Get_Property(@WINDOW,'SIZE')
    
    wScreen = ScreenSize<3>
    hScreen	= ScreenSize<4>
    
    xDialog = DialogSize<1>
    yDialog = DialogSize<2>
    wDialog = DialogSize<3>
    hDialog = DialogSize<4>
    
    
    IF hDialog >= hScreen THEN
        hDialog = hScreen - 4		;* Constant is a guess
        DialogSize<4> = hDialog		;* Limit height of dialog
    END
    
    xoffsetScreen = INT((wScreen - wDialog)/2)
    yoffsetScreen = INT((hScreen - hDialog)/2)
    
    
    DialogSize<1> = xoffsetScreen
    DialogSize<2> = yoffsetScreen
    
    Set_Property(@WINDOW,'SIZE',DialogSize)
    Set_Property(@WINDOW,'VISIBLE',1)
    Set_Property(@WINDOW,'TIMER',10000:@FM:10000)		;* 10 second refresh, 10 second offset
    
    GOSUB Refresh
    
RETURN


* * * * * * *
Close:
* * * * * * *
    
    End_Dialog(@WINDOW,'')
    
RETURN


* * * * * * *
Refresh:
* * * * * * *
    
    Set_Property(@Window, "REDRAW", False$)
    TopItem = Get_Property(@Window:'.STAT_TABLE', "TOPPOS")
    SelPos  = Get_Property(@Window:'.STAT_TABLE', "SELPOS")
    
    TableList = Database_Services('ReadDataRow', 'APP_INFO', 'GAN_WIP')
    TableList = Delete(TableList,1,0,0)
    
    Set_Property(@WINDOW:'.STAT_TABLE','LIST',TableList)
    
    tlCnt = COUNT(TableList,@FM) + (TableList NE '')
    
    FOR I = 1 TO tlCnt
        IF TableList<I,COL$STAGE> NE '' THEN	
            Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',0,I,WHITE$)
        END ELSE
            
            IF (TableList<I,COL$WAIT_WFR_ID> NE '') or (TableList<I,COL$WAIT_HRS> NE '') THEN
                
                * Waiting material
                
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_WFR_ID,I,YELLOW$)
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_HRS,I,YELLOW$)
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_WFR_QTY,I,YELLOW$)
            END
            
            IF TableList<I,COL$TOOL_ID> NE '' THEN
                
                * Material on Tool
                
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_WFR_ID,I,LS3_GREEN$)
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_HRS,I,LS3_GREEN$)
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$TOOL_ID,I,LS3_GREEN$)
                Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_WFR,I,LS3_GREEN$)
                
            END
            
            RunPri = TableList<I,COL$REACT_RUN_PRI>
            
            IF RunPri NE '' THEN
                BEGIN CASE 
                    CASE RunPri = 'P1'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$REACT_RUN_PRI,I,PR1_RED$)
                    CASE RunPri = 'P2'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$REACT_RUN_PRI,I,PR2_RED$)	
                    CASE RunPri = 'P3'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$REACT_RUN_PRI,I,PR3_RED$)	
                    CASE 1					; NULL
                END CASE
            END		
            
        END	;* End of check for Stage line
        
    NEXT I
    Set_Property(@Window:'.STAT_TABLE', "TOPPOS", TopItem)
    Set_Property(@Window:'.STAT_TABLE', "SELPOS", SelPos)
    Send_Event(@Window:'.STAT_TABLE', 'POSCHANGED', SelPos<1>, SelPos<2>)
    Set_Property(@Window, "REDRAW", True$)    
    
RETURN


* * * * * * *
StatDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.STAT_TABLE'
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    CtrlList	= Get_Property(CtrlEntID,'LIST')
    
    Begin Case
        
        Case CurrCol EQ COL$STAGE
            
            StageID = CtrlList<CurrRow,COL$STAGE>
            LocQ    = Gan_Services('GetLocQueueID', StageID)
            obj_Appwindow('ViewRelated','LOCATION':@RM:LocQ:@RM:'')
        
        Case CurrCol EQ COL$WAIT_WFR_ID
            
            WfrID = CtrlList<CurrRow,COL$WAIT_WFR_ID>
            IF INDEX(WfrID,'*',1) THEN
                CONVERT '*' TO '.' IN WfrID		
                TypeOver = ''
                TypeOver<PDISPLAY$> = 'WITH WFR_ID ':QUOTE(WfrID):' BY EVENT_DTM'		
                void = Popup(@WINDOW,TypeOver,'WO_WFR_AUDIT')	              
            END
            
        Case CurrCol EQ COL$RDS_NO
        
            RDSNo = CtrlList<CurrRow, COL$RDS_NO>
            IF RDSNo NE '' then

                PSNo     = Xlate('REACT_RUN', RDSNo, 'PS_NO', 'X')
                TechType = Xlate('PROD_SPEC', PSNo, 'TECH_TYPE', 'X')
                Begin Case
                    Case TechType EQ 'P'
                        Start_Window('DBW_GAN_RDS_PROD', '', RDSNo)
                    Case TechType EQ 'E'
                        Start_Window('REACT_RUN', '', RDSNo)
                    Case Otherwise$
                        Start_Window('REACT_RUN', '', RDSNo)
                End Case
            end
            
        Case CurrCol EQ COL$TOOL_ID
            
            ToolID = CtrlList<CurrRow,COL$TOOL_ID>        
            obj_Appwindow('ViewRelated','TOOL_WFR':@RM:ToolID:@RM:'')

    End Case

Return


