COMPILE FUNCTION obj_WM_Wfrs(Method,Parms)

/*
	Methods for WMO_WFRS and WMI_WFRS tables
    
	01/15/2007 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Presence of a slot record in this file indicates that it is 'locked' by the entry logic and
    will not be available for unloading of a wafer from the reactor in to it.
    							
    
    LockSet(TableName,WMWaferKeys)			;* Creates timestamp record in table for each key passed
    UnlockSet(TableName,WMWaferKeys)		;* Deletes timestamp record from table for each key passed
   
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables
DECLARE SUBROUTINE Set_Status, Msg, obj_Tables, Send_Dyn

$INSERT WMO_WFRS_EQUATES
$INSERT WMI_WFRS_EQUATES

EQU CRLF$ TO \0D0A\

ErrTitle = 'Error in Stored Procedure "obj_WM_Wfrs"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'LockSet'				; GOSUB LockSet
	CASE Method = 'UnlockSet'			; GOSUB UnlockSet
	CASE 1
		NULL

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


* * * * * * *
LockSet:
* * * * * * *

WMTableName = Parms[1,@RM]
WMWaferKeys = Parms[COL2()+1,@RM]

IF WMTableName = '' THEN ErrorMsg = 'Null Parameter "WMTableName" passed to routine. (':Method:')'
IF WMWaferKeys = '' THEN ErrorMsg = 'Null Parameter "WMWaferKeys" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

OPEN WMTableName TO WMWfrsTable ELSE
	ErrorMsg = 'Unable to open ':QUOTE(WMTableName):' table in routine. (':Method:')'
	RETURN
END

LockedKeys = ''
FOR I = 1 TO COUNT(WMWaferKeys,@VM) + (WMWaferKeys NE '')
	WMWaferKey = WMWaferKeys<1,I>
	READ TestRec FROM WMWfrsTable,WMWaferKey THEN
		LockUser	= TestRec<WMO_WFRS_USER_NAME$>
		LockStation	= TestRec<WMO_WFRS_WORKSTATION_ID$>
		LockDTM		= OCONV(TestRec<WMO_WFRS_LOCKED_AT$>,'DT4/^HS')
		
		ErrorMsg  = 'Cassette/Wafers are currently being loaded/unloaded by: ':CRLF$
		ErrorMsg := 'User Name: ':LockUser:CRLF$
		ErrorMsg := 'Computer Station: ':LockStation:CRLF$
		ErrorMsg := 'Locked At: ':LockDTM
		
		FOR N = 1 TO COUNT(LockedKeys,@VM) + (LockedKeys NE '')
			DELETE WMWfrsTable,LockedKeys<1,N> ELSE NULL
		NEXT N
		RETURN
	END	ELSE
		* Write the timestamp record to 'lock' the slot
		CurrDTM = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTHS'),'DT')
		WMWfrRec = @USER4:@FM:@STATION:@FM:CurrDTM
		WRITE WMWfrRec ON WMWfrsTable,WMWaferKey THEN
			LockedKeys<1,-1> = WMWaferKey
		END ELSE
			ErrorMsg = 'Unable to WRITE to ':QUOTE(WMTableName):' table in routine. (':Method:')'
			FOR N = 1 TO COUNT(LockedKeys,@VM) + (LockedKeys NE '')
				DELETE WMWfrsTable,LockedKeys<1,N> ELSE NULL
			NEXT N
			RETURN
		END
	END
NEXT I

Result = LockedKeys		;* This gets put into @LOCKED_WFRS in the dialog box

RETURN



* * * * * * *
UnlockSet:
* * * * * * *
 
WMTableName = Parms[1,@RM]
WMWaferKeys = Parms[COL2()+1,@RM]

IF WMTableName = '' THEN ErrorMsg = 'Null Parameter "WMTableName" passed to routine. (':Method:')'
IF WMWaferKeys = '' THEN ErrorMsg = 'Null Parameter "WMWaferKeys" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

OPEN WMTableName TO WMWfrsTable ELSE
	ErrorMsg = 'Unable to open ':QUOTE(WMTableName):' table in routine. (':Method:')'
	RETURN
END

FOR I = 1 TO COUNT(WMWaferKeys,@VM) + (WMWaferKeys NE '')
	WMWaferKey = WMWaferKeys<1,I>
	DELETE WMWfrsTable,WMWaferKey ELSE
		ErrorMsg  = 'Unable to DELETE ':QUOTE(WMTableName):' record ':WMWaferKeys<1,I>:'.':CRLF$:CRLF$
		ErrorMsg := 'Screen print this message and give to OpenInsight System Administrator.'
	END
NEXT I

RETURN


