COMPILE FUNCTION obj_Tool_Wfr(Method,Parms)

/*
	Methods for the TOOL_WFR (Wafer) Tables
	
	4/6/2016 JCH - Initial coding
	
	
*/

DECLARE FUNCTION Get_Status, Msg, obj_Tables, Send_Dyn, ErrMsg, obj_Tables
DECLARE SUBROUTINE ErrMsg, Set_Status, FieldStore, obj_Tables, obj_WO_Wfr

$Insert TOOL_WFR_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_Tool_Wfr"'
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 = 'SetWfrID'		; Gosub SetWfrID
	Case Method = 'ClearWfrID'		; Gosub ClearWfrID
		
	CASE 1
		NULL

END CASE

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

RETURN Result


* * * * * * *
SetWfrID:
* * * * * * *

ToolID	= Parms[1,@RM]
WfrIDs	= Parms[COL2()+1,@RM]

If ToolID = ''		THEN ErrorMsg = 'Null Parameter "ToolID" passed to routine. (':Method:')'
If WfrIDs = ''		THEN ErrorMsg = 'Null Parameter "WfrIDs" passed to routine. (':Method:')'

If ErrorMsg NE '' Then Return 

otParms = 'TOOL_WFR':@RM:ToolID
ToolWfrRec = obj_Tables('ReadRec',otParms)

WriteFlag = 0

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

FOR I = 1 TO wCnt
	WfrID = WfrIDs<1,I>
	
	Locate WfrID In ToolWfrRec<TOOL_WFR_WFR_ID$> USING @VM SETTING Pos ELSE
		ToolWfrRec = Insert(ToolWfrRec,TOOL_WFR_WFR_ID$,Pos,0, WfrID)
		WriteFlag = 1
	End

NEXT I

IF WriteFlag THEN
	otParms  = FieldStore(otParms,@RM,4,0,ToolWfrRec)
	obj_Tables('WriteRec',otParms)
END ELSE
	obj_Tables('UnlockRec',otParms)
END

Return



* * * * * * *
ClearWfrID:
* * * * * * *

ToolID	= Parms[1,@RM]
WfrIDs	= Parms[COL2()+1,@RM]

If ToolID = ''		THEN ErrorMsg = 'Null Parameter "ToolID" passed to routine. (':Method:')'
If WfrIDs = ''		THEN ErrorMsg = 'Null Parameter "WfrIDs" passed to routine. (':Method:')'

If ErrorMsg NE '' Then Return 

otParms = 'TOOL_WFR':@RM:ToolID
ToolWfrRec = obj_Tables('ReadRec',otParms)

WriteFlag = 0

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

FOR I = 1 TO wCnt
	WfrID = WfrIDs<1,I>
	
	Locate WfrID In ToolWfrRec<TOOL_WFR_WFR_ID$> USING @VM SETTING Pos Then
		ToolWfrRec = DELETE(ToolWfrRec,TOOL_WFR_WFR_ID$,Pos,0)
		WriteFlag = 1
	End
NEXT I	

IF WriteFlag THEN
	otParms  = FieldStore(otParms,@RM,4,0,ToolWfrRec)
	obj_Tables('WriteRec',otParms)
End Else 
	obj_Tables('UnlockRec',otParms)
END

Return 




