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

/*
	Commuter module for REACT_ITEM window
	
	01/13/2014 - John C. Henry, J.C. Henry & Co., Inc. cloned from Graphite
*/

DECLARE SUBROUTINE Set_Property, ErrMsg, obj_Appwindow, Btree.Extract, Send_Event, Post_Event, obj_React_Item, Forward_Event
DECLARE FUNCTION Get_Property, Send_Message, NextKey, Popup, obj_Calendar, Printer_Select
DECLARE FUNCTION Set_Printer, obj_Install, Start_Window, obj_React_Item_Hist, obj_React_Item, Dialog_Box


$INSERT REACT_ITEM_EQUATES
$INSERT REACT_ITEM_HIST_EQUATES
$INSERT APPCOLORS
$INSERT POPUP_EQUATES
$INSERT LOGICAL

EQU COL$REACT_NO			TO 1
EQU COL$SVC_HRS				TO 2
EQU COL$SVC_WFRS			TO 3
EQU COL$RDS_WAFER_COUNT		TO 4
EQU COL$PCRC				TO 5
EQU COL$INST_DTM			TO 6
EQU COL$INST_REACT_HRS		TO 7
EQU COL$INST_REACT_WFRS		TO 8
EQU COL$INST_RL_ID			TO 9
EQU COL$REM_DTM				TO 10
EQU COL$REM_REACT_HRS		TO 11
EQU COL$REM_REACT_WFRS		TO 12
EQU COL$REM_RL_ID			TO 13

EQU SPECIAL_BLUE$	TO 227 + (253*256) + (248*65536)
EQU CRLF$			TO \0D0A\


EQU PI$LEFT		TO	1
EQU PI$TOP		TO  2
EQU PI$RIGHT	TO	3
EQU PI$BOTTOM	TO	4
EQU PI$WIDTH	TO 	5
EQU PI$HEIGHT	TO	6
EQU PI$SIZE		TO	7


ErrTitle = 'Error in React_Item'
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:'.REACT_NO'
	
		BEGIN CASE
			CASE Event = 'DBLCLK'			; GOSUB ReactDC
			
		END CASE
		
	CASE EntID = @WINDOW:'.LU_RI_NO' AND Event = 'CLICK'	 		; GOSUB LUReactItem
	CASE EntID = @WINDOW:'.NEW' AND Event = 'CLICK'					; GOSUB New
	CASE EntID = @WINDOW:'.LU_MFR_CD' AND Event = 'CLICK'			; GOSUB LUMfrCd
	CASE EntID = @WINDOW:'.LU_RI_TYPE' AND Event = 'CLICK'			; GOSUB LURIType
	CASE EntID = @WINDOW:'.LU_PART_TYPE' AND Event = 'CLICK'		; GOSUB LUPartType
	CASE EntID = @WINDOW:'.LU_TUBE_STYLE' AND Event = 'CLICK'		; GOSUB LUTubeStyle			;* Added by dkk 12/1/14
	CASE EntID = @WINDOW:'.LU_SUSC_SIZE' AND Event = 'CLICK'		; GOSUB LUSuscSize
	CASE EntID = @WINDOW:'.LU_PKT_SIZE' AND Event = 'CLICK'			; GOSUB LUPktSize
	CASE EntID = @WINDOW:'.LU_PKT_QTY' AND Event = 'CLICK'			; GOSUB LUPktQty
	CASE EntID = @WINDOW:'.RETIRE_BUTTON' AND Event = 'CLICK'		; GOSUB RetireItem
	CASE EntID = @WINDOW:'.PRINT_LABEL' AND Event = 'CLICK'			; GOSUB PrintLabel
	CASE EntID = @WINDOW:'.RI_TYPE' AND Event = 'CHANGED'			; GOSUB RITypeChange
	CASE EntID = @WINDOW:'.PKT_SIZE' AND Event = 'CHANGED'			; GOSUB PktSizeChange
    CASE EntID = @WINDOW:'.PART_TYPE' AND Event = 'LOSTFOCUS'			; GOSUB PktSizeChange

	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)


RETURN



* * * * * * *
New:
* * * * * * *

RINo = Get_Property(@WINDOW:'.REACT_ITEM','DEFPROP')

IF RINo = '' THEN
	NextRINo = NextKey('REACT_ITEM')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextRINo)
END

EnterBy = Get_Property(@WINDOW:'.ENTER_BY','DEFPROP')

IF EnterBy = '' THEN
	Set_Property(@WINDOW:'.ENTER_BY','INVALUE',@USER4)
	Set_Property(@WINDOW:'.ENTER_DTM','DEFPROP',obj_Calendar('CurrDTM'))
END

GOSUB Refresh

RETURN


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

*DEBUG

obj_Appwindow('CardReturn',@WINDOW)

RETURN



* * * * * * *
Read:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

Parent = Get_Property(@WINDOW,'PARENT')

IF Parent = 'REACTOR_LOG' OR Parent = 'REACT_STATE' THEN
	Post_Event(@WINDOW,'CLOSE')
END

RETURN


* * * * * * *
Clear:
* * * * * * *

*Send_Event(@WINDOW,'PAGE',1)



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

Ctrls  = @WINDOW:'.ENTER_BY':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.ENTER_DTM'			; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

EnterBy		= Vals[1,@RM]
EnterDTM	= Vals[COL2()+1,@RM]

IF EnterBy	= '' THEN Vals  = 1:@RM ELSE Vals  = 0:@RM
IF EnterDTM = '' THEN Vals := 1		ELSE Vals := 0

Props = 'ENABLED':@RM:'ENABLED'

Set_Property(Ctrls,Props,Vals)

* 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

*/



ETCtrl = @WINDOW:'.REACT_NO'
ETList = Get_Property(ETCtrl,'LIST')
ListCnt = COUNT(ETList,@FM) + (ETList NE '')


FOR Line = 1 TO ListCnt
	
	IF MOD(Line,2) THEN
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REACT_NO,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$SVC_HRS,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$SVC_WFRS,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$RDS_WAFER_COUNT,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$PCRC,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_DTM,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_REACT_HRS,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_REACT_WFRS,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_RL_ID,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_DTM,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_REACT_HRS,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_REACT_WFRS,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_RL_ID,Line,RCV_BLUE$)
		
	END ELSE
		FOR N = 1 TO 11
			stat = Send_Message(ETCtrl,'COLOR_BY_POS',N,Line,WHITE$)
		NEXT N
	END
NEXT Line
RIType = Get_Property(@Window:'.RI_TYPE', 'TEXT')
If RIType EQ 'S' then
    Set_Property(@Window:'.SUSC_GROUP', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE', 'ENABLED', True$)
    Set_Property(@Window:'.LU_PKT_SIZE', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_QTY_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.LU_PKT_QTY', 'ENABLED', True$)
    Set_Property(@Window:'.PPLUS_RDS_NO_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'ENABLED', True$)
end else
    Set_Property(@Window:'.SUSC_GROUP', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE', 'TEXT', '')
    Set_Property(@Window:'.LU_PKT_SIZE', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'TEXT', '')
    Set_Property(@Window:'PKT_QTY_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_QTY', 'TEXT', '')
    Set_Property(@Window:'.LU_PKT_QTY', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'TEXT', '')
end

RETURN

* * * * * * *
RITypeChange:
* * * * * * *

RIType = Get_Property(@Window:'.RI_TYPE', 'TEXT')
If RIType EQ 'S' then
    Set_Property(@Window:'.SUSC_GROUP', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE', 'ENABLED', True$)
    Set_Property(@Window:'.LU_PKT_SIZE', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'ENABLED', True$)
    Set_Property(@Window:'.PKT_QTY_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.LU_PKT_QTY', 'ENABLED', True$)
    Set_Property(@Window:'.PPLUS_RDS_NO_LABEL', 'ENABLED', True$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'ENABLED', True$)
end else
    Set_Property(@Window:'.SUSC_GROUP', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE', 'TEXT', '')
    Set_Property(@Window:'.LU_PKT_SIZE', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_SIZE_DESC', 'TEXT', '')
    Set_Property(@Window:'PKT_QTY_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PKT_QTY', 'TEXT', '')
    Set_Property(@Window:'.LU_PKT_QTY', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO_LABEL', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'ENABLED', False$)
    Set_Property(@Window:'.PPLUS_RDS_NO', 'TEXT', '')
end
    
return


* * * * * * *
RetireItem:
* * * * * * *

Ctrls  = @WINDOW:'.RETIRE_DT':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.RETIRE_BY'			; Props := 'INVALUE'

Vals = Get_Property(Ctrls,Props)

RetDt = Vals[1,@RM]
RetBy = Vals[COL2()+1,@RM]

IF RetBy NE '' THEN RETURN		;* Nothing to do

Vals  = OCONV(Date(),'D4/'):@RM
Vals := @USER4

Set_Property(Ctrls,Props,Vals)

GraphNo = Get_Property(@WINDOW:'.GR_NO','DEFPROP')

Send_Event(@WINDOW,'WRITE')

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:GraphNo)

RETURN


* * * * * * *
ReactDC:
* * * * * * *

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

GRNo	= Get_Property(@WINDOW:'.GR_NO','DEFPROP')

IF GRNo = '' THEN RETURN

BEGIN CASE
	CASE CurrCol = COL$INST_RL_ID
		RLId = CurrRow<COL$INST_RL_ID>
		
	CASE CurrCol = COL$REM_RL_ID
		RLId = CurrRow<COL$INST_RL_ID>

END CASE

RLId = Get_Property(EntID,'CELLPOS',CurrCol:@FM:CurrRow)

IF RLId NE '' THEN
	Dummy = Start_Window( 'REACTOR_LOG', @WINDOW, RLId:'*CENTER', '', '' )
END

RETURN


* * * * * * *
LURIType:
* * * * * * *

RetVal = Popup(@WINDOW,'','REACT_ITEM_TYPE')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.RI_TYPE'
	obj_Appwindow('LUValReturn',oaParms)
END

RETURN


* * * * * * *
LUReactItem:
* * * * * * *

RetVal = Dialog_Box('DIALOG_REACT_ITEM_QUERY', @WINDOW)

Display = ''
Display<PDISPLAY$>	= RetVal
Display<PMODE$>		= 'K'

RetVal = Popup(@WINDOW,Display,'REACT_ITEM')

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

IF INDEX(RetVal,@VM,1) THEN
	Set_Property(@WINDOW,'QBFLIST',RetVal)
END ELSE
	obj_AppWindow('LoadFormKeys',@WINDOW:@RM:RetVal)
END
	
RETURN



* * * * * * *
LUPartType:
* * * * * * *


RetVal = Popup(@WINDOW,'','RI_PART_TYPE')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.PART_TYPE'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN


* * * * * * *
LUTubeStyle:							;* Added by dkk 12/1/14
* * * * * * *


RetVal = Popup(@WINDOW,'','TUBE_STYLE')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.TUBE_STYLE'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN



* * * * * * *
LUMfrCd:
* * * * * * * 

MfrCd = Popup(@WINDOW,'','REACT_VENDOR')

IF MfrCd NE '' THEN
	oaParms = MfrCd:@RM:@WINDOW:'.MFR_CD'
	obj_Appwindow('LUValReturn',oaParms)
END

RETURN


* * * * * * *
LUReactType:
* * * * * * *

RetVal = Popup(@WINDOW,'','REACTOR_TYPE')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.REACT_TYPE'
	obj_Appwindow('LUValReturn',oaParms)
END



RETURN

* * * * * * *
LUSuscSize:
* * * * * * *
RetVal = Popup(@WINDOW,'','WAFER_SIZES')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.SUSC_SIZE'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN


* * * * * * *
LUPktSize:
* * * * * * *

Retired = Get_Property(@Window: '.RETIRE_DT', 'TEXT')
RIType = Get_Property(@Window:'.RI_TYPE', 'TEXT')
If RIType EQ 'S' then
    PocketQty = ''
    Set_Property(@Window:'.PKT_QTY', 'TEXT', '')
    PartType = Get_Property(@Window: '.PART_TYPE', 'TEXT')
    If (PartType EQ 'HTR') OR (PartType EQ 'EPP') OR (PartType EQ 'ASM') then
        RetVal = Popup(@WINDOW,TypeOver,'WAFER_SIZES')
        IF RetVal NE '' THEN
            oaParms = RetVal:@RM:@WINDOW:'.PKT_SIZE'
            obj_Appwindow('LUValReturn',oaParms)
            Begin Case
               Case PartType EQ 'HTR'
                    If RetVal EQ  8 then
                        PocketQty = 3
                    end else
                        If RetVal EQ  6 then PocketQty = 5
                    end
                Case PartType EQ 'EPP'
                     If RetVal EQ  8 then
                        PocketQty = 8
                    end else
                        If RetVal EQ  6 then PocketQty = 18
                    end
                Case PartType EQ 'ASM'
                   If RetVal EQ  8 OR RetVal EQ  6  then PocketQty = 1
                   
            End Case
            Set_Property(@Window:'.PKT_QTY', 'TEXT', PocketQty)
        END
    end else
        If Retired EQ '' then ErrMsg('A valid Part Type (EPP, ASM, HTR) must be selected before selecting Pocket Size.')
    end
end

RETURN


* * * * * *
LUPktQty:
* * * * * *

ReactType = Get_Property(@WINDOW:'.REACT_TYPE','INVALUE')

IF ReactType NE '' THEN

	AllDisplayData	= XLATE('SYSREPOSPOPUPS','LSL2**SUSCEPTOR_POCKETS',PDISPLAY$,'X')
	DisplayData		= ''
	TypeOver 		= ''
	
	DispCnt = COUNT(AllDisplayData,@VM) + (AllDisplayData NE '')
	
	FOR I = 1 TO DispCnt
		DisplayLine = AllDisplayData<1,I>
		IF DisplayLine<1,1,2> = ReactType THEN
			DisplayData<1,-1> = DisplayLine
		END
	NEXT I
	
	TypeOver<PDISPLAY$> = DisplayData
	
	RetVal = Popup(@WINDOW,TypeOver,'SUSCEPTOR_POCKETS')
	
END ELSE
	RetVal = Popup(@WINDOW,'','SUSCEPTOR_POCKETS')
END


IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.PKT_QTY'
	obj_Appwindow('LUValReturn',oaParms)
END

RETURN


* * * * * * *
PrintLabel:
* * * * * * * 

Ctrls  = @WINDOW:'.RI_NO':@RM	; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW				; Props := 'ATRECORD'

Vals = Get_Property(Ctrls,Props)

RINo		= Vals[1,@RM]
CurrRec		= Vals[COL2()+1,@RM]

obj_React_Item('PrintLabel',RINo:@RM:CurrRec)

RETURN


PktSizeChange:
    
    Retired = Get_Property(@Window: '.RETIRE_DT', 'TEXT')
    RIType = Get_Property(@Window:'.RI_TYPE', 'TEXT')
    If RIType EQ 'S' then
        PocketQty = ''
        Set_Property(@Window:'.PKT_QTY', 'TEXT', '')
        PktSize = Get_Property(@Window: '.PKT_SIZE', 'TEXT')
        PartType = Get_Property(@Window: '.PART_TYPE', 'TEXT')
        If (PartType EQ 'HTR') OR (PartType EQ 'EPP') OR (PartType EQ 'ASM') then
            If PktSize EQ 6 OR PktSize EQ 8 then
                Begin Case
                    Case PartType EQ 'HTR'
                        If PktSize EQ  8 then
                            PocketQty = 3
                        end else
                            If PktSize EQ  6 then PocketQty = 5
                        end
                    Case PartType EQ 'EPP'
                         If PktSize EQ  8 then
                            PocketQty = 8
                        end else
                            If PktSize EQ  6 then PocketQty = 18
                        end
                    Case PartType EQ 'ASM'
                       If PktSize EQ  8 OR PktSize EQ  6  then PocketQty = 1
                       
                End Case
                Set_Property(@Window:'.PKT_QTY', 'TEXT', PocketQty)
            end else
                 If Retired EQ '' then ErrMsg('A valid Pocket Size (6 or 8 in.) is required.')
            end
        end else
             If Retired EQ '' then ErrMsg('A valid Part Type (EPP, ASM, HTR) must be selected before selecting Pocket Size.')
        end
    end
    
    
return

