COMPILE FUNCTION Test_Wafer(CtrlEntID,Event,Parm1, Parm2, Parm3, Parm4, Parm5)

/*
	Commuter module for Test_Wafer (Test Wafer Use) window
	
	06/28/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Forward_Event
DECLARE SUBROUTINE Send_Event, obj_TW_Use, Security_Err_Msg, Post_Event, Btree.Extract, ErrMsg, obj_WO_Mat
DECLARE SUBROUTINE Send_Message, obj_WM_IN, obj_WO_Wfr, obj_Notes

DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, MemberOf, NextKey
DECLARE FUNCTION obj_Quote, Security_Check, obj_WO_Mat, obj_WM_In, Dialog_Box, obj_WO_Wfr


$INSERT REACT_RUN_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT REACTOR_EQUATES
$INSERT NOTIFICATION_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT LSL_USERS_EQU

$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT POPUP_EQUATES
$INSERT LOGICAL

EQU CRLF$	TO \0D0A\

ErrTitle = 'Error in TEST_WAFER'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE CtrlEntID = @WINDOW AND Event = 'CREATE'			; GOSUB Create
	CASE CtrlEntID = @WINDOW AND Event = 'READ'				; GOSUB Read
	CASE CtrlEntID = @WINDOW AND Event = 'WRITE'			; GOSUB Write
	CASE CtrlEntID = @WINDOW AND Event = 'DELETE'			; GOSUB Delete
	CASE CtrlEntID = @WINDOW AND Event = 'CLEAR'			; GOSUB Refresh
	CASE CtrlEntID = @WINDOW AND Event = 'CLOSE'			; GOSUB Close
	CASE CtrlEntID = @WINDOW AND Event[1,3] = 'QBF'			; GOSUB Refresh
	
	CASE CtrlEntID = @WINDOW:'.WAFER_ID' AND Event = 'DELETEROW'	; GOSUB DeleteWaferID
	CASE CtrlEntID = @WINDOW:'.WAFER_ID' AND Event = 'INSERTROW'	; GOSUB InsertWaferID
	
	CASE CtrlEntID = @WINDOW:'.TW_QTY' AND Event = 'LOSTFOCUS'		; GOSUB TWQtyLF
	CASE CtrlEntID = @WINDOW:'.TW_CODE' AND Event = 'LOSTFOCUS'		; GOSUB Refresh
	CASE CtrlEntID = @WINDOW:'.TW_TYPE' AND Event = 'LOSTFOCUS'		; GOSUB TWTypeLF
	CASE CtrlEntID = @WINDOW:'.TW_TYPE' AND Event = 'GOTFOCUS'		; GOSUB TWTypeGF
	
	CASE CtrlEntID = @WINDOW:'.NEW_BUTTON' AND Event = 'CLICK'		; GOSUB New
	CASE CtrlEntID = @WINDOW:'.LU_TW_CODE' AND Event = 'CLICK'		; GOSUB LU_TWCode
	CASE CtrlEntID = @WINDOW:'.LU_TW_TYPE' AND Event = 'CLICK'		; GOSUB LU_TWType
	CASE CtrlEntID = @WINDOW:'.LU_TOOL' AND Event = 'CLICK'			; GOSUB LU_Tool
	CASE CtrlEntID = @WINDOW:'.LU_CUST_PART_NO' AND Event = 'CLICK'	; GOSUB LU_CustPart
	CASE CtrlEntID = @WINDOW:'.LU_WFR_ID' AND Event = 'CLICK'		; GOSUB LU_WfrID
	CASE CtrlEntID = @WINDOW:'.SIGN_BUTTON' AND Event = 'CLICK'		; GOSUB Sign
	CASE CtrlEntID = @WINDOW:'.WAFER_HELP' AND Event = 'CLICK'		; GOSUB WaferHelp
	
	CASE 1
	
		ErrorMsg = 'Unknown Instruction passed to routine':CRLF$:CtrlEntID:' - ':Event
END CASE

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

RETURN Result


* * * * * * * 
Create:
* * * * * * *

obj_Appwindow('Create',@WINDOW)


GOSUB Refresh

RETURN


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

TestRec = Get_Property(@WINDOW,'RECORD')
CONVERT @FM TO '' IN TestRec
IF TestRec = '' THEN
	Set_Property(@WINDOW,'@NEW_RECORD',1)
END

ReactNo		= Get_Property(@WINDOW:'.REACT_NO','DEFPROP')
ReactType	= XLATE('REACTOR',ReactNo,REACTOR_REACT_TYPE$,'X')

WfrIDs	= Get_Property(@WINDOW:'.WAFER_ID','DEFPROP')<1>

CONVERT @VM TO ' ' IN WfrIDs
WfrIDs = TRIM(WfrIDs)
CONVERT ' ' TO @VM in WfrIDs

WfrCnt = COUNT(WfrIDs,@VM) + (WfrIDs NE '')



Ctrls  = @WINDOW:'.WINDOW_LABEL_FIX':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.PROD_TEST_GROUP':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.LU_WFR_ID':@RM				; Props := 'ENABLED'@RM
Ctrls := @WINDOW:'.TW_QTY':@RM					; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_CODE':@RM					; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_TYPE':@RM					; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TOOL'						; Props := 'DEFPROP'



IF ReactType = 'GAN' THEN

	CurrVals = Get_Property(Ctrls,Props)
	
	CurrLabel	= CurrVals[1,@RM]
	CurrGroup	= CurrVals[COL2()+1,@RM]
	CurrEnable	= CurrVals[COL2()+1,@RM]
	CurrQty		= CurrVals[COL2()+1,@RM]
	CurrCode	= CurrVals[COL2()+1,@RM]
	CurrType	= CurrVals[COL2()+1,@RM]
	CurrTool	= CurrVals[COL2()+1,@RM]
	
	Vals  = 'GaN Char Wafer':@RM
	Vals := 'GaN Characterization Wafers':@RM
	Vals := '0':@RM
		
	IF CurrQty	= '' THEN Qty = WfrCnt		ELSE Qty = CurrQty
	IF CurrCode	= '' THEN Code = '3'		ELSE Code = CurrCode
	IF CurrType = '' THEN Type = 'PROD' 	ELSE Type = CurrType
	IF CurrTool = '' THEN Tool = 'GaN Char'	ELSE Tool = CurrTool
	
	Vals := Qty:@RM
	Vals := Code:@RM
	Vals := Type:@RM
	Vals := Tool

END ELSE

	Vals  = 'Test Wafer':@RM
	Vals := 'Product Test Wafers':@RM
	Vals := '1':@RM
	Vals := '':@RM
	Vals := '':@RM
	Vals := '':@RM
	Vals := ''


END	;* End of check for GAN reactor

Set_Property(Ctrls,Props,Vals)

GOSUB Refresh

Return


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

Forward_Event()

Post_Event(@WINDOW,'CLOSE')

Return


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

obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window

GOTO Refresh

RETURN

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

obj_Appwindow('DetailReturn')

RETURN




* * * * * * *
Delete:
* * * * * * *

DEBUG

RETURN


IF MemberOf(@USER4, 'OI_SUPERUSER') OR MemberOf( @USER4, 'SUPERVISOR' ) OR  MemberOf( @USER4, 'LEAD' ) ELSE
	MsgInfo = ''
	MsgInfo<micon$> = '!'
	MsgInfo<mtext$> = 'You must be a Supervisor OR a Lead to Remove a Test Wafer record.'
	Void = Msg( '', MsgInfo )
	RETURN
END

Ctrls  = @WINDOW:'.MET_NO':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_NO':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.WAFER_ID'		; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

MetNo		= Vals[1,@RM]
TWNo		= Vals[COL2()+1,@RM]
WaferIDs	= Vals[COL2()+1,@RM]

LOOP
UNTIL WaferIDs[-1,1] NE @VM OR WaferIDs = ''
	WaferIDs[-1,1] = ''
REPEAT

IF WaferIDs NE '' THEN

	RDSNo	= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
	MetNo	= Get_Property(@WINDOW:'.MET_NO','DEFPROP')
	TWNo 	= Get_Property(@WINDOW:'.TW_NO','DEFPROP')

	*TWUseKey = MetNo:'*':TWNo		;* Key changed to TWNo only in TEST_WAFER table
	
	* * * *   Added 3/24/2016  JCH - wafer history   * * * * 
	
	wCnt = COUNT(WaferIDs,@VM) + (WaferIDs NE '')
	
	FOR W = 1 TO wCnt
		
		
		WfrID = WaferIDs<1,W>
		CONVERT '.' TO '*' IN WfrID
		Event = 'TEST'
		
		Parms = Event:@RM:WfrID
		
		obj_WO_Wfr('RemEvent',Parms)		;* This is untested JCH 6/28/2016
		
	NEXT W
	
	* * * * *   End of update   * * * * *
	
	RRRec = XLATE('REACT_RUN',RDSNo,'','X')
	ReactType = XLATE('REACTOR',RRRec<REACT_RUN_REACTOR$>,1,'X')
	
	FirstWafer	= WaferIDs<1,1>
	WONo		= FirstWafer[1,'.']
	CassNo		= FirstWafer[COL2()+1,'.']
	
	WaferID = '' ;* Pass null to remove all references to this TW_USE record

	IF ReactType = 'EPP' THEN
		obj_WM_In('RepProdTW',WONo:@RM:CassNo:@RM:MetNo:'*':TWNo:@RM:WaferID)

	END ELSE
		obj_WO_Mat('RepProdTW',WONo:@RM:CassNo:@RM:TWNo:@RM:WaferID)
	END

END

Forward_Event()

Result = 0

Post_Event(@WINDOW,'CLOSE')

RETURN


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


CurrTWNo = Get_Property(@WINDOW:'.TW_NO','DEFPROP')

IF CurrTWNo NE '' THEN RETURN

TWNo = NextKey('TEST_WAFER')

obj_Appwindow('LUValReturn',TWNo:@RM:@WINDOW:'.TW_NO')

RETURN


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

Ctrls  = @WINDOW:'.TW_QTY':@RM				; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_CODE':@RM				; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TOOL':@RM				; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_TYPE':@RM				; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.CUST_TW_PART_NO':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.WAFER_ID':@RM			; Props := 'ARRAY':@RM
Ctrls := @WINDOW:'.SIGNATURE'				; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

TWQty			= Vals[1,@RM]
TWCode			= Vals[COL2()+1,@RM]
Tool			= Vals[COL2()+1,@RM]
TWType			= Vals[COL2()+1,@RM]
CustTWPartNo	= Vals[COL2()+1,@RM]
WaferIDs		= Vals[COL2()+1,@RM]
Signature		= Vals[COL2()+1,@RM]

LOOP
	WaferID = WaferIDs[-1,'B':@VM]
UNTIL WaferID NE '' OR WaferIDs = ''
	WaferIDs[-1,1] = ''
REPEAT

IF Signature = '' THEN

	OKToSign = 1
	TestWaferIDs = Get_Property(@WINDOW:'.WAFER_ID','DEFPROP')
	CONVERT @VM TO '' IN TestWaferIDs
	
	Ctrls  = @WINDOW:'.TOOL':@RM		; Props  = 'ENABLED':@RM
	Ctrls := @WINDOW:'.TW_TYPE':@RM		; Props := 'ENABLED':@RM
	Ctrls := @WINDOW:'.LU_TOOL':@RM		; Props := 'ENABLED':@RM
	Ctrls := @WINDOW:'.LU_TW_TYPE'		; Props := 'ENABLED'
	
	IF TWCode = 99 AND TWQty = 0 THEN	    
	    Vals = 0:@RM:0:@RM:0:@RM:0
	END ELSE
	    Vals = 1:@RM:1:@RM:1:@RM:1
	end

    Set_Property(Ctrls,Props,Vals)
	
	BEGIN CASE
		
		CASE (TWCode = '99' OR TWCode = '98') AND TWQty = 0		; NULL
		CASE (TWCode = '99' OR TWCode = '98') AND TWQty NE 0	; OKToSign = 0
		CASE TWQty = ''											; OKToSign = 0
		CASE TWCode = ''										; OKToSign = 0
		CASE TWType = ''										; OKToSign = 0
		CASE TWType = 'PROD' AND TestWaferIDs = '' 				; OKToSign = 0
			
	END CASE

	Set_Property(@WINDOW:'.SIG_GROUP','ENABLED',OKToSign)		;* Required parameters met


	TWType = Get_Property(@WINDOW:'.TW_TYPE','DEFPROP')

	IF TWType = 'CUST'  THEN
		Set_Property(@WINDOW:'.CUST_TW_GROUP','ENABLED',1)
	END ELSE
		Set_Property(@WINDOW:'.CUST_TW_GROUP','ENABLED',0)
	END

END

IF TWType = 'PROD' AND Signature = '' THEN
	Set_Property(@WINDOW:'.PROD_TEST_GROUP','ENABLED',1)
END ELSE
	IF MemberOf(@USER4, 'OI_SUPERUSER') THEN
		Set_Property(@WINDOW:'.PROD_TEST_GROUP','ENABLED',1)
	END ELSE
		Set_Property(@WINDOW:'.PROD_TEST_GROUP','ENABLED',0)
	END
	
END

* 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 Line
NEXT I

RETURN



* * * * * * *
TWQtyLF:
* * * * * * *

Ctrls  = @WINDOW:'.TW_QTY':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_CODE'				; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

TWQty 	= Vals[1,@RM]
TWType	= Vals[COL2()+1,@RM]

IF TWQty = 0 AND TWType = '' THEN 

	TypeOver = ''
	TypeOver<PDISPLAY$> = 'WITH SEQ = "99" "98" BY SEQ'
	
	TWCode = Popup(@WINDOW,TypeOver,'TW_CODES')
	
	IF TWCode = '' OR TWCode = CHAR(27) THEN RETURN
		
	Set_Property(@WINDOW:'.TW_CODE','DEFPROP',TWCode)
END

GOSUB Refresh

RETURN




* * * * * * *
TWTypeLF:
* * * * * * *

Ctrls  = @WINDOW:'.TW_QTY':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_CODE'				; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

TWQty 		= Vals[1,@RM]
TWType		= Vals[COL2()+1,@RM]

IF TWQty NE 0 AND (TWType = 99 OR TWType = 98)THEN 
	ErrMsg('TW Qty must be "0" when using TW Type "99" or "98".')
	Set_Property(@WINDOW:'TW_CODE','FOCUS',1)
END

GOSUB Refresh

RETURN


* * * * * * *
TWTypeGF:
* * * * * * *

Ctrls  = @WINDOW:'.TW_TYPE':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.WAFER_ID'			; Props := 'ARRAY'

Vals = Get_Property(Ctrls,Props)

TWType 		= Vals[1,@RM]
WaferIDs	= Vals[COL2()+1,@RM]

NoChange = 0

IF TWType = 'PROD' THEN
	CONVERT @FM:@VM TO '' IN WaferIDs
	IF WaferIDs NE '' THEN
		Msg(@WINDOW,'','TW_TYPE_CHANGE')
		NoChange = 1
	END
END

RETURN



* * * * * * *
LU_TWCode:
* * * * * * *

Result = Popup(@WINDOW,'','SHOW_TW_CODES')
		
IF Result NE '' THEN
	Parms = Result:@RM:@WINDOW:'.TW_CODE':@RM:''
	obj_Appwindow('LUValReturn',Parms )
END

GOSUB Refresh
		
RETURN


* * * * * * *
LU_TWType:
* * * * * * *

GOSUB TWTypeGF

IF NoChange = 1 THEN RETURN

Result = Popup(@WINDOW,'','TW_TYPES')
		
IF Result NE '' THEN
	Parms = Result:@RM:@WINDOW:'.TW_TYPE':@RM:''
	obj_Appwindow('LUValReturn',Parms )
END

GOSUB Refresh
		
RETURN


* * * * * * *
LU_Tool:
* * * * * * *

Result = Popup( @WINDOW, '', 'CHOOSE_TOOL' )
	
IF Result NE '' THEN
	Parms = Result:@RM:@WINDOW:'.TOOL':@RM:''
	obj_Appwindow('LUValReturn',Parms )
END

RETURN



* * * * * * *
LU_CustPart:
* * * * * * *

CustNo = Get_Property(@WINDOW:'.CUST_NO','DEFPROP')

IF CustNo NE '' THEN

	SearchString = 'CUST_NO':@VM:CustNo:@FM
	OPEN 'DICT.CUST_TW_PART' TO DictVar ELSE
		ErrMsg('Unable to open DICT.CUST_TW_PART for index lookup.')
		RETURN
	END

	Options = ''
	Flag = ''

	BTREE.EXTRACT(SearchString, 'CUST_TW_PART', DictVar, CustTWPartKeys, Options, flag)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END

	IF CustTWPartKeys = '' THEN
		ErrMsg('No TW Part Numbers on file for Customer ':QUOTE(CustNo):'.')
		RETURN
	END

	TypeOver = ''
	TypeOver<PDISPLAY$> = CustTWPartKeys
	TypeOver<PSELECT$>	= 1					;* Single select

	CustTWPartKey = Popup(@WINDOW,TypeOver,'CUST_TW_PART')
	CustTWPartNo = CustTWPartKey[-1,'B*']
	
	IF CustTWPartNo NE '' THEN
		Parms = CustTWPartNo:@RM:@WINDOW:'.CUST_TW_PART_NO':@RM:''
		obj_Appwindow('LUValReturn',Parms )
	END

END	;* End of check for null Customer number

RETURN



* * * * * * *
LU_WfrID:
* * * * * * *

Ctrls  = @WINDOW:'.MET_NO':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_NO':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.RDS_NO':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.TW_QTY':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.ZONE'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

MetNo	= Vals[1,@RM]
TWNo	= Vals[COL2()+1,@RM]
RDSNo	= Vals[COL2()+1,@RM]
TWQty	= Vals[COL2()+1,@RM]
Zone	= Vals[COL2()+1,@RM]

IF MetNo	= '' THEN RETURN
IF TWNo		= '' THEN RETURN
IF RDSNo	= '' THEN RETURN

*TWUseKey = MetNo:'*':TWNo   ;* Changed to TWNo only for TEST_WAFER table

RRRec = XLATE('REACT_RUN',RDSNo,'','X')


WONo	= RRRec<REACT_RUN_WO_NO$>
CassNo	= RRRec<REACT_RUN_CASS_NO$>
Pockets	= RRRec<REACT_RUN_POCKET$>
Zones	= RRRec<REACT_RUN_ZONE$>

PocketCnt = COUNT(Pockets,@VM) + (Pockets NE '')

ProdTestArray = ''

IF PocketCnt > 0 THEN
	* * * EpiPRO * * *
	Display = ''
	LineCnt = 0
	
	FOR I = 1 TO PocketCnt
	
		a1PktChar = RRRec<REACT_RUN_POCKET_CHAR$,I>
		a1WfrChar = RRRec<REACT_RUN_WAFER_CHAR$,I>
		a1WfrZone = RRRec<REACT_RUN_ZONE$,I>
		
		
		IF RRRec<REACT_RUN_POCKET_CHAR$,I> = 'TEST' AND RRRec<REACT_RUN_WAFER_CHAR$,I> = 'PROD' AND RRRec<REACT_RUN_ZONE$,I> = Zone THEN
			LineCnt += 1
			
			Display<1,LineCnt,1> = Pockets<1,I>
			Display<1,LineCnt,2> = RRRec<REACT_RUN_ZONE$,I>
			Display<1,LineCnt,3> = RRRec<REACT_RUN_POCKET_CHAR$,I>
			Display<1,LineCnt,4> = RRRec<REACT_RUN_WAFER_CHAR$,I>
			Display<1,LineCnt,5> = WONo:'.':RRRec<REACT_RUN_IN_CASS_NO$,I>:'.':RRRec<REACT_RUN_IN_SLOT_NO$,I>
			Display<1,LineCnt,6> = RRRec<REACT_RUN_OUT_CASS_NO$,I>:'.':RRRec<REACT_RUN_OUT_SLOT_NO$,I>
			
		END
	NEXT I
	
	IF Display = '' THEN
		ErrMsg('No Product Test Wafer configured in this zone during EpiPRO Load.')
		RETURN
	END
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = Display
	
	LOOP
		WaferIDs = Popup(@WINDOW,TypeOver,'REACT_EPI_PRO_TW_LOAD')
		WaferIDCnt = COUNT(WaferIDs,@VM) + (WaferIDs NE '')
	UNTIL WaferIDCnt = TWQty
		Response = Msg(@WINDOW,'','PROD_TEST_QTY_ERROR','',WaferIDCnt:@FM:TWQty)
		IF Response = CHAR(27) THEN RETURN
	REPEAT
	
	
	IF WaferIDCnt > 0 THEN
		ProdTestArray = ''	
		
		
		RemDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
		WfrIds = ''
		
		
		FOR N = 1 TO WaferIDCnt
		
			WaferID = WaferIDs<1,N>
			
			SrcCassNo	= Field(WaferID,'.',2)
			SlotNo		= Field(WaferID,'.',3)
			
			If SlotNo = '' Then
				Recipients		= 'DAN_CR'
				SentFrom		= @USER4
				Subject			= 'TEST_WAFER - EpiPRO':TWNo
				Message			= 'WfrID = ':QUOTE(WONo:'*':CassNo:'*':SlotNo):CRLF$:WaferIDs
				AttachWindow	= 'TEST_WAFER'
				AttachKey		= TWNo
				SendToGroup		= ''   

				Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
				obj_Notes('Create',Parms)
			END
			
			* * * *   Added 3/24/2016  JCH - wafer history   * * * * 
			
			WfrID = WONo:'*':SrcCassNo:'*':SlotNo
			
			WfrIDs<1,-1> = WfrID
			
			CurrLocs = obj_WO_Wfr('CurrLoc',WfrID:@RM:'')	;* Added 10/3/2016 JCH
					
			CurrSlotID	= CurrLocs<1,2>						;* Added 10/3/2016 JCH
			CurrTool	= CurrLocs<1,3>						;* Added 10/3/2016 JCH
			CurrInvLoc	= CurrLocs<1,4>						;* Added 10/3/2016 JCH
			
			Parms  = WONo:'*':SrcCassNo:'*':SlotNo:@RM				;* WfrID
			Parms := RemDTM:@RM										;* EventDtm
			Parms := @USER4:@RM										;* EventBy
			Parms := 'TEST':@RM										;* Event
			Parms := '':@RM											;* NewSlotID
			Parms := '':@RM											;* RunLoc
			Parms := '':@RM											;* NCRNo
			Parms := TWNo:@RM										;* TEST_WAFER No
			Parms := CurrSlotID:@RM									;* CurrSlotID
			Parms := '':@RM											;* NewToolID
			Parms := CurrTool:@RM									;* CurrToolID
			Parms := '':@RM											;* NewInvLoc
			Parms := CurrInvLoc:@RM									;* CurrInvLoc
			Parms := 'O'											;* Inbound or Outbound Wafers
			
			obj_WO_Wfr('AddEvent',Parms)
			
			* * * * *   End of Update   * * * * * *
			
			Set_Status(0)
			
			ProdTestArray<1,N> = obj_WM_IN('RemProdTW',WONo:@RM:SrcCassNo:@RM:TWNo:@RM:SlotNo)	;* Add metrology number to each selected slot
			
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
				* Back out logic here
			END
			
		NEXT N
		
		/*
		
		IF WfrIDs NE '' THEN
		
			Parms  = WfrIDs:@RM				;* WfrIDs - mv
			Parms := RemDTM:@RM				;* EventDtm
			Parms := @USER4:@RM				;* EventBy
			Parms := 'TEST':@RM				;* Event
			Parms := '':@RM					;* NewSlotIDs - mv
			Parms := '':@RM					;* RunLocs - mv
			Parms := '':@RM					;* NCRNo
			Parms := TWNo:@RM				;* TEST_WAFER No
			Parms := '':@RM					;* CurrSlotIDs - mv
			Parms := '':@RM					;* NewToolID
			Parms := '':@RM					;* CurrToolID
			Parms := '':@RM					;* NewInvLoc
			Parms := '':@RM					;* CurrInvLoc
			Parms := 'O'					;* Inbound or Outbound Wafers
		
			obj_WO_Wfr('AddEvent',Parms)
		
		END
		
		*/
	
	END
	
END ELSE
	
	WOMatRec = XLATE('WO_MAT',WONo:'*':CassNo,'','X')
	
	SlotMetNos 		= WOMatRec<WO_MAT_SLOT_MET_NO$>
	SlotNCRNos		= WOMatRec<WO_MAT_SLOT_NCR$>
	SlotWaferIDs 	= obj_WO_Mat('SlotWaferIDs',WONo:'*':CassNo)									;* Get list of available wafers in cassette
	
	WaferIDCnt = COUNT(SlotWaferIDs,@VM) + (SlotWaferIDs NE '')
	
	PopupDisplay = ''
	CurrTWUseCnt = 0
	
	FOR N = 1 TO WaferIDCnt
		PopupDisplay<1,N,1> = N
		PopupDisplay<1,N,2> = SlotWaferIDs<1,N>
		PopupDisplay<1,N,3> = SlotNCRNos<1,N>
		PopupDisplay<1,N,4> = SlotMetNos<1,N>
		IF SlotMetNos<1,N> = MetNo:'*':TWNo THEN CurrTWUseCnt += 1	;* Test Wafers already pulled from the box for this TW_USE
	NEXT N
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = PopupDisplay
	TypeOver<PFIELD$>	= 2
	
	LOOP
		WaferIDs	= Popup(@WINDOW,TypeOver,'SELECT_PROD_TEST')
		
		IF WaferIDs = '' OR WaferIDs = CHAR(27) THEN RETURN
		
		WaferIDCnt	= COUNT(WaferIDs,@VM) + (WaferIDs NE '')
		
	UNTIL WaferIDCnt + CurrTWUseCnt = TWQty
	
		Response	= Msg(@WINDOW,'','PROD_TEST_QTY_ERROR','',WaferIDCnt:@FM:TWQty)
		
		IF Response = CHAR(27) THEN RETURN
	REPEAT
	
	SlotNos = ''
	FOR N = 1 TO WaferIDCnt
		WaferID = WaferIDs<1,N>
		IF WaferID = '' THEN 
			ErrMsg('Select slots must contain a Wafer ID.')
			RETURN
		END ELSE
			SlotNos<1,-1> = Field(WaferID,'.',3)
		END
		
	NEXT N
	
	* * * *   Added 3/24/2016  JCH - wafer history   * * * * 
	
	RemDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
	
	sCnt = COUNT(SlotNos,@VM) + (SlotNos NE '')
	
	FOR S = 1 TO Scnt
	
		SlotNo = SlotNos<1,S>
		
		If SlotNo = '' Then
			Recipients		= 'DAN_CR'
			SentFrom		= @USER4
			Subject			= 'TW_USE non EpiPRO':TWNo
			Message			= 'WfrID = ':QUOTE(WONo:'*':CassNo:'*':SlotNo):CRLF$:WaferIDs
			AttachWindow	= 'TEST_WAFER'
			AttachKey		= TWNo
			SendToGroup		= ''   

			Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
			obj_Notes('Create',Parms)
		END
		
		WfrID = WONo:'*':CassNo:'*':SlotNo
		
		CurrLocs = obj_WO_Wfr('CurrLoc',WfrID:@RM:'')	;* Added 10/3/2016 JCH
					
		CurrSlotID	= CurrLocs<1,2>						;* Added 10/3/2016 JCH
		CurrTool	= CurrLocs<1,3>						;* Added 10/3/2016 JCH
		CurrInvLoc	= CurrLocs<1,4>						;* Added 10/3/2016 JCH
		
		
		
		Parms  = WfrID:@RM				;* WfrID
		Parms := RemDTM:@RM									;* EventDtm
		Parms := @USER4:@RM									;* EventBy
		Parms := 'TEST':@RM									;* Event
		Parms := '':@RM										;* NewSlotID
		Parms := '':@RM										;* RunLoc
		Parms := '':@RM										;* NCRNo
		Parms := TWNo:@RM									;* TWfrNo
		Parms := CurrSlotID:@RM								;* CurrSlotID
		Parms := '':@RM										;* NewToolID
		Parms := CurrTool:@RM								;* CurrToolID
		Parms := '':@RM										;* NewInvLoc
		Parms := CurrInvLoc:@RM								;* CurrInvLoc
		Parms := 'O'										;* Inbound or Outbound Wafers										;* CurrSlotID

		obj_WO_Wfr('AddEvent',Parms)
		
	NEXT S
	
	Set_Status(0)
	
	ProdTestArray = obj_WO_Mat('RemProdTW',WONo:@RM:CassNo:@RM:TWNo:@RM:SlotNos:@RM:'1')
		
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		* Back out logic here
	END

END	;* End of check for EpiPRO pocket load data

CurrProdTestArray = Get_Property(@WINDOW:'.WAFER_ID','ARRAY')

NewProdTestArray = ''

Position = 1
Flag  = ""
LOOP
    REMOVE CurrWfrID FROM CurrProdTestArray AT Position SETTING FLAG
WHILE Flag
	IF CurrWfrID NE '' THEN
		LOCATE CurrWfrID IN ProdTestArray BY 'AR' USING @VM  SETTING Pos ELSE
			ProdTestArray = INSERT(ProdTestArray,1,Pos,0,CurrWfrID)
		END
	END		
REPEAT

IF ProdTestArray NE '' THEN Set_Property(@WINDOW:'.WAFER_ID','ARRAY',ProdTestArray:@VM:@VM:@VM)


GOSUB Refresh

RETURN


* * * * * * *
InsertWaferID:
* * * * * * *

RowIndex = Parm1

void = Send_Message(CtrlEntID, 'DELETE', RowIndex)

ErrMsg('Use "Select Wafers" button on window to add additional wafers.')


RETURN



* * * * * * * 
DeleteWaferID:
* * * * * * *

RowIndex	= Parm1
WaferID		= Parm2

RETURN


MsgHead	= 'Replace Product Test Wafer in Cassette'
MsgText	= 'Are you sure you wish to place wafer ':WaferID:' back into the product cassette?'

OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)

IF OK THEN

	RDSNo	= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
	MetNo	= Get_Property(@WINDOW:'.MET_NO','DEFPROP')
	TWNo 	= Get_Property(@WINDOW:'.TW_NO','DEFPROP')

	*TWUseKey = MetNo:'*':TWNo
	
	RRRec = XLATE('REACT_RUN',RDSNo,'','X')
	ReactType = XLATE('REACTOR',RRRec<REACT_RUN_REACTOR$>,1,'X')
	
	WONo	= WaferID[1,'.']
	CassNo	= WaferID[COL2()+1,'.']
	
	
	* * * *   Added 3/24/2016  JCH - wafer history   * * * * 
	
	WfrID = WaferID
	CONVERT '.' TO '*' IN WfrID
	
	Parms  = WfrID:@RM
	Parms := 'TEST'
	
	obj_WO_Wfr('RemEvent',Parms)
	
	* * * * *   End of wafer history update   * * * * *
	

	IF ReactType = 'EPP' THEN
		* * * EpiPRO Box  * * *
									***********************************************************8
		obj_WM_In('RepProdTW',WONo:@RM:CassNo:@RM:MetNo:'*':TWNo:@RM:WaferID)

	END ELSE
		
		obj_WO_Mat('RepProdTW',WONo:@RM:CassNo:@RM:MetNo:'*':TWNo:@RM:WaferID)
	END

END ELSE
	Send_Message(CtrlEntID,'INSERT',RowIndex,WaferID)
END

RETURN




* * * * * * *
Sign:
* * * * * * *

Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
Valid = Valid<1>

IF Valid THEN

	CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
	
	Set_Property(@WINDOW:'.SIGNATURE','DEFPROP',@USER4)
	Set_Property(@WINDOW:'.SIG_DTM','DEFPROP',CurrDTM)
	
	/*
	* From the RDS_TEST window code - save just in case they want it back! *
	CurrDTM			= ICONV(CurrDTM,'DT')
	ReactNo			= Get_Property(@WINDOW:'.REACTOR','DEFPROP')
	OutOfProdDTM	= XLATE('REACT_STATUS',ReactNo,REACT_STATUS_OUT_OF_PROD_DTM$,'X')
	HrsSinceProd 	= OCONV((CurrDTM - OutOfProdDTM)*24,'MD2')
	
	Parms = HrsSinceProd:@RM:CtrlEntId:@RM:ColPointer+2:@FM:LinePointer		;* Hours Since Production
	obj_Appwindow('LUValReturn',Parms )
	
	EscHrs = XLATE('REACTOR',ReactNo,'ACT_ESC_HRS','X')
	IF EscHrs = '' THEN EscHrs = 0
	EscElapsedTime	= OCONV(EscHrs,'MD2')
	
	Parms = EscElapsedTime:@RM:CtrlEntId:@RM:ColPointer+3:@FM:LinePointer	;* Hours in Escalation
	obj_Appwindow('LUValReturn',Parms )
	*/
END	

GOSUB Refresh

RETURN


* * * * * * *
WaferHelp:
* * * * * * *

Msg(@WINDOW,'','TW_USE_WAFER_HELP')

RETURN

