COMPILE FUNCTION Comm_Dialog_Load_Epi_Pro(Method, Parm1, Parm2)
#pragma precomp SRP_PreCompiler

/*
	Commuter module for Dialog_Load_Epi_Pro window.
	
	03/13/2006 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg, obj_RDS2, Send_Event, RDS_React_Run, Send_Info
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, End_Dialog, Send_Message, obj_WM_IN, obj_WM_Wfrs, obj_React_Status
DECLARE FUNCTION   Get_Property, Get_Status, Dialog_Box, Popup, obj_WM_In, Send_Message, obj_NCR, obj_WM_Wfrs
DECLARE FUNCTION   SRP_Array, Database_Services, Set_Property

EQU CRLF$	TO \0D0A\

$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT RDS_EQU
$INSERT RDS_TEST_EQUATES
$INSERT EPI_SUSCEPTOR_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT EPI_PART_EQUATES
$INSERT RDS_EPILOAD
$INSERT WO_STEP_EQU
$INSERT NCR_EQU
$INSERT APPCOLORS

EQU COL$WM_CASS_IN	TO 1
EQU COL$WM_SLOT_IN	TO 2

EQU COL$POCKET		TO 1
EQU COL$USAGE		TO 2
EQU COL$ZONE		TO 3
EQU COL$IN_CASS		TO 4
EQU COL$IN_SLOT		TO 5
EQU COL$WAFER_TYPE	TO 6
EQU COL$OUT_CASS	TO 7
EQU COL$OUT_SLOT	TO 8

EQU COL$NCR_NO		TO 1
EQU COL$CASS_NO		TO 2
EQU COL$SLOT_NO		TO 3

EQU EDITABLE$			TO 4
EQU PROTECTED$			TO 8			;* Protected  - Edittable COLSTYLE constants
EQU MULTILINE_STYLE$	TO 512 			;* MultiLine Select
EQU LOCKED$				TO 8192
EQU DROPDOWN_STYLE$		TO 131072



ErrTitle = 'Error in Comm_Dialog_Load_Epi_Pro'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Close'			; GOSUB Close
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'LoadMat'			; GOSUB LoadMat
	CASE Method = 'ReturnMat'		; GOSUB ReturnMat
	CASE Method = 'ReactIR'			; GOSUB ReactIR
	CASE Method = 'ReactDR'			; GOSUB ReactDR 
	CASE Method = 'TestRun'			; GOSUB TestRun
	CASE Method = 'ConfigComp'		; GOSUB ConfigComp
	
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result



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

obj_AppWindow('Create')



* get the current style

Style = Get_Property(@WINDOW:'.WM_IN', 'STYLE')									

IF Style [1,2] _EQC "0x" THEN
  CONVERT @LOWER.CASE TO @UPPER.CASE IN STYLE
  Style = ICONV(Style [3,99], "MX")
END

Style = BitOr(Style, MULTILINE_STYLE$)
Set_Property(@WINDOW:'.WM_IN', "STYLE", Style)

ReactorStyles = Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,'')	
ReactorStyles<COL$USAGE> = BitOr(ReactorStyles<COL$USAGE>,DROPDOWN_STYLE$)
Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,ReactorStyles)
Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$USAGE,'TEST':@VM:'PROD':@VM:'DUMMY')

RDSNo		= FIELD(Parm1,@FM,1)
CurrentLoad = FIELD(Parm1,@FM,2,99)

IF RDSNo = '' THEN 
	ErrMsg('Null RDS No passed to Dialog Box...')
	End_Dialog(@WINDOW,'')
END

RDSRec = XLATE('RDS',RDSNo,'','X')

ReactorNo	= RDSRec<RDS_REACTOR$>
WONo		= RDSRec<RDS_WO$>
WOStep	 	= FIELD(RDSRec<RDS_WO_STEP_KEY$>,'*',2)

Ctrls = @WINDOW:'.RDS_NO':@RM:@WINDOW:'.WO_NO':@RM:@WINDOW:'.WO_STEP':@RM:@WINDOW:'.REACTOR_NO'
Props = 'DEFPROP':@RM: 'DEFPROP':@RM: 'DEFPROP':@RM: 'DEFPROP'
Vals  = RDSNo:@RM:WONo:@RM:WOStep:@RM:ReactorNo

Set_Property(Ctrls,Props,Vals)

LoadCnt = 0
OpenCnt = 0

RCtrl = @WINDOW:'.REACTOR_TABLE'

TestInCass = CurrentLoad<COL$IN_CASS>		;* 6/2/2009 JCH  Better test for loaded wafers added
CONVERT @VM TO '' IN TestInCass				;* 6/2/2009 JCH

IF TestInCass = '' THEN

	EpiPartNo		= XLATE('WO_LOG',WONo,WO_LOG_EPI_PART_NO$,'X')
	SubWaferSize	= XLATE('EPI_PART',EpiPartNo,EPI_PART_SUB_WAFER_SIZE$,'X')
	
	BEGIN CASE
		CASE SubWaferSize = '150 mm 6 in'
			EpiSusceptor = XLATE('EPI_SUSCEPTOR','6','','X')
			
		CASE SubWaferSize = '125 mm 5 in'
			EpiSusceptor = XLATE('EPI_SUSCEPTOR','5','','X')
			
		CASE SubWaferSize = '200 mm 8 in'
			EpiSusceptor = XLATE('EPI_SUSCEPTOR','8','','X')
		
		CASE 1
			ErrorMsg  = 'Epi Part: ':QUOTE(EpiPartNo):' has a wafer size of ':SubWaferSize:'.':CRLF$:CRLF$
			ErrorMsg := 'The EpiPRO reactors cannot process wafers of this size.'
			
			ErrMsg(ErrorMsg)
			
			End_Dialog(@WINDOW,'')
			
	END CASE

	Pockets = EpiSusceptor<EPI_SUSCEPTOR_POCKET_NO$>
	Zones	= EpiSusceptor<EPI_SUSCEPTOR_POCKET_ZONE$>
	PTypes	= EpiSusceptor<EPI_SUSCEPTOR_POCKET_TYPE$>

	FOR I = 1 TO COUNT(Pockets,@VM) + (Pockets NE '')
		Set_Property(RCtrl,'CELLPOS',Pockets<1,I>,COL$POCKET:@FM:I)		;* Loads Pocket Numbers - Default data from Susceptor Record
		Set_Property(RCtrl,'CELLPOS',PTypes<1,I>,COL$USAGE:@FM:I)		;* Test pockets
		Set_Property(RCtrl,'CELLPOS',Zones<1,I>,COL$ZONE:@FM:I)			;* Zones
		OpenCnt += 1
	NEXT I
	
END ELSE

	FOR I = 1 TO COUNT(CurrentLoad<1>,@VM) + (CurrentLoad<1> NE '')
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$POCKET,I>,COL$POCKET:@FM:I)
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$USAGE,I>,COL$USAGE:@FM:I)
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$ZONE,I>,COL$ZONE:@FM:I)
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$IN_CASS,I>,COL$IN_CASS:@FM:I)
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$IN_SLOT,I>,COL$IN_SLOT:@FM:I)
		Set_Property(RCtrl,'CELLPOS',CurrentLoad<COL$WAFER_TYPE,I>,COL$WAFER_TYPE:@FM:I)
		LoadCnt += 1
	NEXT I
END

Set_Property(@WINDOW,'@OPEN_POCKETS',OpenCnt)


IF LoadCnt = 0 AND OpenCnt = 0 THEN
	ErrMsg('LoadCnt = 0 and OpenCnt = 0, internal program error.')
	End_Dialog(@WINDOW,'')
END


BEGIN CASE
	CASE LoadCnt > 0
	
		* Loaded
		
		BriefTxt  = '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}'
		BriefTxt := '{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\b\f0\fs20 Return Material to Inbound Cassette\par'
		BriefTxt := '\b0\par'
		BriefTxt := ' 1.) Return Material to Inbound Cassette\b\par'
		BriefTxt := '\b0\par'
		BriefTxt := '}'
		
		Set_Property(@WINDOW:'.CONFIG_COMPLETE','VISIBLE',0)
		Set_Property(@WINDOW:'.TEST_RUN','VISIBLE',0)
		
		Set_Property(@WINDOW:'.LOAD_MATERIAL','VISIBLE',0)
		Set_Property(@WINDOW:'.RETURN_MATERIAL','VISIBLE',1)
		
		Set_Property(@WINDOW:'.LOAD_MATERIAL','ENABLED',0)
		Set_Property(@WINDOW:'.RETURN_MATERIAL','ENABLED',1)
		
		ReactorStyles = Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,'')
		
		ReactorStyles<COL$USAGE>		= BitAnd(ReactorStyles<COL$USAGE>,BitNot(DROPDOWN_STYLE$))
		ReactorStyles<COL$WAFER_TYPE>	= BitAnd(ReactorStyles<COL$WAFER_TYPE>,BitNot(DROPDOWN_STYLE$))
		
		
		ReactorStyles<COL$POCKET>		= BitOr(ReactorStyles<COL$POCKET>,PROTECTED$)
		ReactorStyles<COL$USAGE>		= BitOr(ReactorStyles<COL$USAGE>,PROTECTED$)
		ReactorStyles<COL$ZONE>			= BitOr(ReactorStyles<COL$ZONE>,PROTECTED$)
		ReactorStyles<COL$IN_CASS>		= BitOr(ReactorStyles<COL$IN_CASS>,PROTECTED$)
		ReactorStyles<COL$IN_SLOT>		= BitOr(ReactorStyles<COL$IN_SLOT>,PROTECTED$)
		ReactorStyles<COL$WAFER_TYPE>	= BitOr(ReactorStyles<COL$WAFER_TYPE>,PROTECTED$)
		
		Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$USAGE,'')
		Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$WAFER_TYPE,'')

		Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,ReactorStyles)
		
		
	CASE OpenCnt > 0
	
		* Ready to Load
		
		BriefTxt  = '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}'
		BriefTxt := '{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\b\f0\fs20\par'
		BriefTxt := '   Load Material into EPIPro Reactor\par'
		BriefTxt := '\b0\par'
		BriefTxt := '    1.)  Configure Pocket Utilization & Wafer Types\par'
		BriefTxt := '    2.)  Check Load Configuration Complete checkbox\par'
		BriefTxt := '    3.)  Verify Inbound Material\par'
		BriefTxt := '    4.)  Load Material into Reactor\par'
		BriefTxt := '\par'
		BriefTxt := '}'
		
		Set_Property(@WINDOW:'.CONFIG_COMPLETE','VISIBLE',1)
		Set_Property(@WINDOW:'.TEST_RUN','VISIBLE',1)
		
		Set_Property(@WINDOW:'.LOAD_MATERIAL','VISIBLE',1)
		Set_Property(@WINDOW:'.RETURN_MATERIAL','VISIBLE',0)
		
		Set_Property(@WINDOW:'.LOAD_MATERIAL','ENABLED',0)
		Set_Property(@WINDOW:'.RETURN_MATERIAL','ENABLED',0)
		
		ReactorStyles = Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,'')
			
		ReactorStyles<COL$USAGE>		= BitOr(ReactorStyles<COL$USAGE>,DROPDOWN_STYLE$)
		ReactorStyles<COL$WAFER_TYPE>	= BitOr(ReactorStyles<COL$WAFER_TYPE>,DROPDOWN_STYLE$)
		
		ReactorStyles<COL$POCKET>		= BitAnd(ReactorStyles<COL$POCKET>,BitNot(PROTECTED$))
		ReactorStyles<COL$ZONE>			= BitAnd(ReactorStyles<COL$ZONE>,BitNot(PROTECTED$))
		ReactorStyles<COL$IN_CASS>		= BitAnd(ReactorStyles<COL$IN_CASS>,BitNot(PROTECTED$))
		ReactorStyles<COL$IN_SLOT>		= BitAnd(ReactorStyles<COL$IN_SLOT>,BitNot(PROTECTED$))
		ReactorStyles<COL$WAFER_TYPE>	= BitAnd(ReactorStyles<COL$WAFER_TYPE>,BitNot(PROTECTED$))

		Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,ReactorStyles)
		
		Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$USAGE,'TEST':@VM:'PROD':@VM:'DUMMY')
		Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$WAFER_TYPE,'':@VM:'TEST')
		
		Set_Property('SYSTEM','FOCUS',@WINDOW:'.REACTOR_TABLE') 
		
	CASE 1
	
END CASE

Set_Property(@WINDOW:'.BRIEF_EDITBOX','RTFTEXT',BriefTxt)

WOStepKey = RDSRec<RDS_WO_STEP_KEY$>

WONo	= WOStepKey[1,'*']
WOStep	= WOStepKey[COL2()+1,'*']
	
GOSUB Refresh

RecordLocked = False$
InboundMat   = Get_Property(@Window:'.WM_IN', 'ARRAY')
If InboundMat NE '' then
    CassNos = InboundMat<1>
    CassNos = SRP_Array('Clean', CassNos, 'TrimAndMakeUnique', @VM)
    If CassNos NE '' then
        For each CassNo in CassNos using @VM setting vPos
            WMInKey      = WONo:'*1*':CassNo
            RecordLocked = Database_Services('IsKeyIDLocked', 'WM_IN', WMInKey)
            If RecordLocked then
                LockOwner = Xlate('WM_IN', WMInKey, 'LOCKED_BY', 'X')
                If LockOwner NE '' then
                    DisplayName = Oconv(LockOwner,'[XLATE_CONV,LSL_USERS*FIRST_LAST]')
                end else
                    DisplayName = 'an unknown user'
                end
                MsgParms    = ''
                MsgParms<1> = 'Record Locked'
                MsgParms<2> = 'The WM_IN record for this RDS is locked by ':DisplayName:'. Only one user session at a time can edit an RDS.'
                Msg(@Window, '', 'OK', '', MsgParms)
                // Disable Load button
                Set_Property(@Window:'.LOAD_MATERIAL', 'ENABLED', -1)
                Set_Property(@Window:'.TEST_RUN', 'ENABLED', -1)
            end
        Until RecordLocked EQ True$
        Next CassNo
    end
end

RETURN


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


* * * * * * *
Cancel:
* * * * * * *

RDSNo		= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
WMILocks	= Get_Property(@WINDOW,'@LOCKED_WFRS')

IF WMILocks NE '' THEN
	obj_WM_Wfrs('UnlockSet','WMI_WFRS':@RM:WMILocks)		; * Remove locks on the wafer slots
END

Set_Property(@WINDOW,'@LOCKED_WFRS','')

End_Dialog(@WINDOW,'')


IF RDSNo NE '' THEN
	Set_Property('RDS.RDS_NO','DEFPROP',RDSNo)
	Send_Event('RDS','READ')
END

RETURN




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

RCtrl	= @WINDOW:'.REACTOR_TABLE'
WMICtrl = @WINDOW:'.WM_IN'

ReactorList = Get_Property(RCtrl,'LIST')
WMInList	= Get_Property(WMICtrl,'LIST')

OpenTestCnt = 0
OpenProdCnt = 0

LineColor = ''

FOR I = 1 TO COUNT(ReactorList,@FM) + (ReactorList NE '')

	IF ReactorList<I,COL$POCKET> NE '' THEN
	

		IF ReactorList<I,COL$USAGE> = 'TEST' THEN
			Send_Message(RCtrl,'COLOR_BY_POS',0,I,YELLOW$)
			IF ReactorList<I,COL$WAFER_TYPE> = '' THEN OpenTestCnt += 1
		END
		
		IF ReactorList<I,COL$USAGE> = 'DUMMY' THEN
			Send_Message(RCtrl,'COLOR_BY_POS',0,I,WHITE$)
		END
		
		IF ReactorList<I,COL$USAGE> = 'PROD' OR ReactorList<I,COL$USAGE> = '' THEN
			Set_Property(RCtrl,'CELLPOS','',COL$USAGE:@FM:I)
			Zone = ReactorList<I,COL$ZONE> 
			IF Zone = 1 THEN LineColor = RCV_BLUE$
			IF Zone = 2 THEN LineColor = PRE_BLUE$
			IF Zone = 3 THEN LineColor = INP_BLUE$
			IF Zone = 4 THEN LineColor = POS_BLUE$
			Send_Message(RCtrl,'COLOR_BY_POS',0,I,LineColor)
		END
		
		IF (ReactorList<I,COL$USAGE> = '' OR ReactorList<I,COL$USAGE> = 'PROD') AND ReactorList<I,COL$WAFER_TYPE> = '' THEN OpenProdCnt += 1
	END	
NEXT I

Set_Property(@WINDOW:'.OPEN_PROD_POCKETS','DEFPROP',OpenProdCnt)
Set_Property(@WINDOW:'.OPEN_TEST_POCKETS','DEFPROP',OpenTestCnt)


ReadyToLoad = 0

WMICnt = COUNT(WMInList,@FM) + (WMInList NE '')

FOR I = 1 TO WMICnt
	IF WMInList<I,COL$WM_CASS_IN> NE '' THEN ReadyToLoad = 1
UNTIL ReadyToLoad

NEXT I

RDSNo = Get_Property(@Window:'.RDS_NO', 'TEXT')
BlockLoad = Xlate('RDS', RDSNo, 'BLOCK_LOAD', 'X')

If BlockLoad EQ True$ then ReadyToLoad = False$

IF ReadyToLoad THEN
	Set_Property(@WINDOW:'.LOAD_MATERIAL','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.LOAD_MATERIAL','ENABLED',0)
END

RETURN



* * * * * * *
LoadMat:
* * * * * * *

WMInLoadList	= Get_Property(@WINDOW:'.WM_IN','LIST')
ReactorList		= Get_Property(@WINDOW:'.REACTOR_TABLE','LIST')
WONo			= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
WOStep			= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
RDSNo			= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')

SelectedRows = ''
WMIWaferKeys = ''

FOR I = 1 TO COUNT(WMInLoadList,@FM) + (WMInLoadList NE '')
	IF WMInLoadList<I,COL$WM_CASS_IN> NE '' AND WMInLoadList<I,COL$WM_SLOT_IN> NE '' THEN
		WMIWaferKeys<1,-1> = WONo:'*':WOStep:'*':WMInLoadList<I,COL$WM_CASS_IN>:'*':WMInLoadList<I,COL$WM_SLOT_IN>
	END
NEXT I

OrgColor = Set_Property('DIALOG_LOAD_EPI_PRO.STATUSLINE_FIX','BACKCOLOR',YELLOW$)	;* //////// Messaging

Set_Status(0)
obj_RDS2('LoadMat',RDSNo:@RM:ReactorList:@RM:WMIWaferKeys)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

WMILocks = Get_Property(@WINDOW,'@LOCKED_WFRS')

IF WMILocks NE '' THEN
	obj_WM_Wfrs('UnlockSet','WMI_WFRS':@RM:WMILocks)		; * Remove locks on the wafer slots
END

Set_Property(@WINDOW,'@LOCKED_WFRS','')


End_Dialog(@WINDOW,'')

Set_Property('RDS.RDS_NO','DEFPROP',RDSNo)
Send_Event('RDS','READ')

RETURN

GOSUB REFRESH

RETURN


* * * * * * *
ReturnMat:
* * * * * * *

RDSNo = Get_Property(@WINDOW:'.RDS_NO','DEFPROP')

IF RDSNo = '' THEN RETURN

OrgColor = Set_Property('DIALOG_LOAD_EPI_PRO.STATUSLINE_FIX','BACKCOLOR',YELLOW$)	;* //////// Messaging

Set_Status(0)
obj_RDS2('ReturnMat',RDSNo)

Send_Info(STR(' ',60))															;** - Messaging - **
Dummy = Set_Property('DIALOG_LOAD_EPI_PRO.STATUSLINE_FIX','BACKCOLOR',OrgColor)	;** - Messaging - **

IF Get_Status(ErrCode) THEN
	ErrMsg(ErrCode)
END

GOTO Close

RETURN


* * * * * * *
ReactIR:
* * * * * * *

RowIndex = Parm1

IF RowIndex = '' THEN RETURN

CtrlID = @WINDOW:'.REACTOR_TABLE'

Dummy = Send_Message(CtrlID,'DELETE',RowIndex)

GOSUB Refresh

RETURN



* * * * * * *
ReactDR:
* * * * * * *

RowIndex = Parm1
RowData = Parm2

IF RowIndex = '' THEN RETURN

CtrlID = @WINDOW:'.REACTOR_TABLE'

Dummy = Send_Message(CtrlID, "INSERT", RowIndex, RowData)

GOSUB Refresh

RETURN


* * * * * * *
TestRun:
* * * * * * *

ReactorArray = Get_Property(@WINDOW:'.REACTOR_TABLE','ARRAY')

Usage = ReactorArray<COL$USAGE>

IF INDEX(Usage,'PROD',1) = 0 THEN
	LineCnt = COUNT(Usage,@VM) + (Usage NE '')
	FOR I = 1 To LineCnt
		IF ReactorArray<COL$POCKET,I> NE '' AND Usage<1,I> = '' THEN
			ReactorArray<COL$USAGE,I> = 'DUMMY'
		END
		Set_Property(@WINDOW:'.REACTOR_TABLE','ARRAY',ReactorArray)
	NEXT I
END

GOSUB Refresh

RETURN


* * * * * * *
ConfigComp:
* * * * * * *

GOSUB Refresh

WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
WOStep = Get_Property(@WINDOW:'.WO_STEP','DEFPROP')

CComp = Get_Property(@WINDOW:'.CONFIG_COMPLETE','CHECK')

IF CComp THEN

	* Check for more pockets configured than avaible inbound wafers  *
	
	WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
	WOStep = Get_Property(@WINDOW:'.WO_STEP','DEFPROP')

	RemainingWafers = obj_WM_In('RemainingSlots',WONo:@RM:WoStep)
	
	RWCnt = COUNT(RemainingWafers,@FM) + (RemainingWafers NE '')

	OpenProdPockets = Get_Property(@WINDOW:'.OPEN_PROD_POCKETS','DEFPROP')
	OpenTestPockets = Get_Property(@WINDOW:'.OPEN_TEST_POCKETS','DEFPROP')

	OpenPockets  = OpenProdPockets + OpenTestPockets
	
	IF OpenPockets > RWCnt THEN
		Title	 = 'EpiPRO Reactor Load Configuration'
		Message  = 'There are more slots configured for loading (':OpenPockets:') than WMI wafers remaining to load (':RWCnt:').':CRLF$:CRLF$
		Message := 'Change ':(OpenPockets - RWCnt):' additional pockets to DUMMY load to correct.'
		
		TypeOver = ''
		TypeOver<MICON$> = '*'
		
		Msg(@WINDOW,TypeOver,'OK','',Title:@FM:Message)
		
		Set_Property(@WINDOW:'.CONFIG_COMPLETE','CHECK',0)
		
		RETURN
		
	END	;* End of check for more open slots than WMI wafers remaining to be used.
	
	
	* "lock down" reactor setup fields from further changes *
	
	ReactorStyles = Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,'')
		
	ReactorStyles<COL$USAGE>		= BitAnd(ReactorStyles<COL$USAGE>,BitNot(DROPDOWN_STYLE$))
	ReactorStyles<COL$WAFER_TYPE>	= BitAnd(ReactorStyles<COL$WAFER_TYPE>,BitNot(DROPDOWN_STYLE$))
	
	ReactorStyles<COL$POCKET>		= BitOr(ReactorStyles<COL$POCKET>,PROTECTED$)
	ReactorStyles<COL$USAGE>		= BitOr(ReactorStyles<COL$USAGE>,PROTECTED$)
	ReactorStyles<COL$ZONE>			= BitOr(ReactorStyles<COL$ZONE>,PROTECTED$)
	ReactorStyles<COL$IN_CASS>		= BitOr(ReactorStyles<COL$IN_CASS>,PROTECTED$)
	ReactorStyles<COL$IN_SLOT>		= BitOr(ReactorStyles<COL$IN_SLOT>,PROTECTED$)
	ReactorStyles<COL$WAFER_TYPE>	= BitOr(ReactorStyles<COL$WAFER_TYPE>,PROTECTED$)
	
	Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$USAGE,'')
	Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$WAFER_TYPE,'')

	Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,ReactorStyles)
	
	Set_Property(@WINDOW:'.TEST_RUN','VISIBLE',0)

	* Build list of WMI wafers to load *
	
	NeededProduct = FIELD(RemainingWafers,@FM,1,OpenPockets)
	
	WMIWaferKeys = ''
	WMICnt = COUNT(NeededProduct,@FM) + (NeededProduct NE '')
	FOR I = 1 TO WMICnt
		WMIWaferKeys<1,I> = WONo:'*':WOStep:'*':NeededProduct<I,1>:'*':NeededProduct<I,2>
	NEXT I

	Set_Status(0)
	LockedWMIKeys = obj_WM_Wfrs('LockSet','WMI_WFRS':@RM:WMIWaferKeys)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END ELSE
		Set_Property(@WINDOW,'@LOCKED_WFRS',LockedWMIKeys)
	END

	FOR M = 1 TO OpenPockets
		Set_Property(@WINDOW:'.WM_IN','CELLPOS',NeededProduct<M,1>,1:@FM:M)
		Set_Property(@WINDOW:'.WM_IN','CELLPOS',NeededProduct<M,2>,2:@FM:M)
	NEXT M

	FOR M = OpenPockets + 1 TO 25
		Set_Property(@WINDOW:'.WM_IN','CELLPOS','',1:@FM:M)
		Set_Property(@WINDOW:'.WM_IN','CELLPOS','',2:@FM:M)
	NEXT M
	

END ELSE

	ReactorStyles = Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,'')
		
	ReactorStyles<COL$USAGE>		= BitOr(ReactorStyles<COL$USAGE>,DROPDOWN_STYLE$)
	ReactorStyles<COL$WAFER_TYPE>	= BitOr(ReactorStyles<COL$WAFER_TYPE>,DROPDOWN_STYLE$)
	
	ReactorStyles<COL$POCKET>		= BitAnd(ReactorStyles<COL$POCKET>,BitNot(PROTECTED$))
	ReactorStyles<COL$USAGE>		= BitAnd(ReactorStyles<COL$USAGE>,BitNot(PROTECTED$))
	ReactorStyles<COL$ZONE>			= BitAnd(ReactorStyles<COL$ZONE>,BitNot(PROTECTED$))
	ReactorStyles<COL$IN_CASS>		= BitAnd(ReactorStyles<COL$IN_CASS>,BitNot(PROTECTED$))
	ReactorStyles<COL$IN_SLOT>		= BitAnd(ReactorStyles<COL$IN_SLOT>,BitNot(PROTECTED$))
	ReactorStyles<COL$WAFER_TYPE>	= BitAnd(ReactorStyles<COL$WAFER_TYPE>,BitNot(PROTECTED$))
	
	Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$USAGE,'TEST':@VM:'PROD':@VM:'DUMMY')
	Send_Message(@WINDOW:'.REACTOR_TABLE','COLFORMAT',COL$WAFER_TYPE,'':@VM:'TEST')

	Send_Message(@WINDOW:'.REACTOR_TABLE','COLSTYLE',0,ReactorStyles)
	
	Set_Property(@WINDOW:'.TEST_RUN','VISIBLE',1)
	
	LockedWMIKeys = Get_Property(@WINDOW,'@LOCKED_WFRS')
	
	Set_Status(0)
	obj_WM_Wfrs('UnlockSet','WMI_WFRS':@RM:LockedWMIKeys)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END ELSE
		Set_Property(@WINDOW,'@LOCKED_WFRS','')
	END

	FOR M = 1 TO 25
		Set_Property(@WINDOW:'.WM_IN','CELLPOS','',1:@FM:M)
		Set_Property(@WINDOW:'.WM_IN','CELLPOS','',2:@FM:M)
	NEXT M

END

GOSUB Refresh

RecordLocked = False$
InboundMat   = Get_Property(@Window:'.WM_IN', 'ARRAY')
If InboundMat NE '' then
    CassNos = InboundMat<1>
    CassNos = SRP_Array('Clean', CassNos, 'TrimAndMakeUnique', @VM)
    If CassNos NE '' then
        For each CassNo in CassNos using @VM setting vPos
            WMInKey      = WONo:'*1*':CassNo
            RecordLocked = Database_Services('IsKeyIDLocked', 'WM_IN', WMInKey)
            If RecordLocked then
                LockOwner = Xlate('WM_IN', WMInKey, 'LOCKED_BY', 'X')
                If LockOwner NE '' then
                    DisplayName = Oconv(LockOwner,'[XLATE_CONV,LSL_USERS*FIRST_LAST]')
                end else
                    DisplayName = 'an unknown user'
                end
                MsgParms    = ''
                MsgParms<1> = 'Record Locked'
                MsgParms<2> = 'The WM_OUT record for this RDS is locked by ':DisplayName:'. Only one user session at a time can edit an RDS.'
                Msg(@Window, '', 'OK', '', MsgParms)
                // Disable Load button
                Set_Property(@Window:'.LOAD_MATERIAL', 'ENABLED', -1)
                Set_Property(@Window:'.TEST_RUN', 'ENABLED', -1)
                Set_Property(@Window:'.CONFIG_COMPLETE', 'ENABLED', -1)
            end
        Until RecordLocked EQ True$
        Next CassNo
    end
end

RETURN







