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

/* 
	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

DECLARE FUNCTION Get_Property, obj_GaN, obj_Gan_Test


$INSERT APPCOLORS
$INSERT TOOL_CLASS_EQUATES
$INSERT TOOL_WFR_EQUATES
$INSERT POPUP_EQUATES
$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_TOOL_TYPE	TO 6
EQU COL$WAIT_WFR_QTY	TO 7
EQU COL$WAIT_HRS		TO 8
EQU COL$WAIT_WFR_ID		TO 9

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

*EQU COL$WAIT_PRI		TO 10
*EQU COL$RUN_PRI			TO 15


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:
* * * * * * *

*obj_Appwindow('Create',@WINDOW)

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',60000:@FM:20000)		;* 60 second refresh, 20 second offset
Set_Property(@WINDOW,'TIMER',10000:@FM:10000)		;* 10 second refresh, 10 second offset


GOSUB Refresh

RETURN


* * * * * * *
Close:
* * * * * * *


End_Dialog(@WINDOW,'')

RETURN


* * * * * * *
Refresh:
* * * * * * *


TableList = obj_GaN('GetStatus')

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 '' 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_PRI,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_TOOL_TYPE,I,YELLOW$)
			Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_WFR_QTY,I,YELLOW$)
		END
		
		IF TableList<I,COL$RUN_WFR_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_PRI,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
		
		
		/*
		WaitPri = TableList<I,COL$WAIT_PRI>
		
		IF WaitPri NE '' THEN
			BEGIN CASE 
				CASE WaitPri = 'P1'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_PRI,I,PR1_RED$)
				CASE WaitPri = 'P2'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_PRI,I,PR2_RED$)	
				CASE WaitPri = 'P3'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$WAIT_PRI,I,PR3_RED$)	
				CASE 1					; NULL
			END CASE
		END
		
		RunPri = TableList<I,COL$RUN_PRI>
		
		IF RunPri NE '' THEN
			BEGIN CASE 
				CASE RunPri = 'P1'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_PRI,I,PR1_RED$)
				CASE RunPri = 'P2'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_PRI,I,PR2_RED$)	
				CASE RunPri = 'P3'		; Send_Message(@WINDOW:'.STAT_TABLE','COLOR_BY_POS',COL$RUN_PRI,I,PR3_RED$)	
				CASE 1					; NULL
			END CASE
		END
		*/
	
	END	;* End of check for Stage line
	
NEXT I



RETURN




* * * * * * *
StatDC:
* * * * * * *

CtrlEntID = @WINDOW:'.STAT_TABLE'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CtrlList	= Get_Property(CtrlEntID,'LIST')



IF CurrCol = COL$WAIT_WFR_ID THEN
	
	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	ELSE
		
		/*DEBUG
	
		IF WfrID = 'Multi' THEN
		
			RDSNo = CtrlList<CurrRow,COL$RDS_NO>
			
			
			RLIST('SELECT REACT_RUN WITH WO_NO = "162851" ',5,'','','')
			
			
			WfrIDs = XLATE('REACT_RUN',RDSNo,REACT_RUN_IN_WFR_ID$,'X')
			CONVERT '*' TO '.' IN WfrIDs
			SWAP @VM WITH '" "' IN WfrIDs
			
			TypeOver = ''
			TypeOver<PDISPLAY$> = 'WITH WFR_ID ':QUOTE(WfrIDS):' BY WFR_ID BY EVENT_DTM'
			
			void = Popup(@WINDOW,TypeOver,'WO_WFR_AUDIT')
		END
		*/
	END

END



IF CurrCol = COL$RDS_NO THEN

	RDSNo = CtrlList<CurrRow,COL$RDS_NO>

	IF RDSNo = '' THEN
		RETURN
	END ELSE

		obj_Appwindow('ViewRelated','REACT_RUN':@RM:RDSNo:@RM:'')

	END
END

IF CurrCol = COL$WAIT_TOOL_TYPE THEN

	CellValue = CtrlList<CurrRow,COL$WAIT_TOOL_TYPE>
	
	IF INDEX(CellValue,'*',1) THEN
		obj_Appwindow('ViewRelated','LOCATION':@RM:CellValue:@RM:'')	;* This is the key to a LOCATION record
	END ELSE
		QInLocID = XLATE('TOOL_CLASS',CellValue,'QIN_LOC_ID','X')
		
		obj_Appwindow('ViewRelated','LOCATION':@RM:QInLocID:@RM:'')
		
		*obj_Appwindow('ViewRelated','TOOL_CLASS':@RM:CellValue:@RM:'')	;* * This is the Key to a TOOL_CLASS record
	END


END


IF CurrCol = COL$TOOL_ID THEN

	ToolID = CtrlList<CurrRow,COL$TOOL_ID>
	
	obj_Appwindow('ViewRelated','TOOL_WFR':@RM:ToolID:@RM:'')

END


RETURN







