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

/*
	Commuter module for DIALOG_REACT_READS (Scan RDS numbers from original cassette RDS labels)
	
	09/10/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status,Print_React_Read_Worksheet
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, 
DECLARE SUBROUTINE End_Window,obj_React_Reads

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT REACT_READS_EQUATES
$INSERT POPUP_EQUATES

EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\

EQU COL$LOT_NO 	TO 1

EQU COL$REACTOR				TO 1
EQU COL$TYPE				TO 2
EQU COL$ASSIGN				TO 3
EQU COL$WAFER_CNT			TO 4


ErrTitle = 'Error in Dialog_WO_Rep_Scan commuter module'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
		END CASE
		
	CASE EntID = @WINDOW:'.READ_TABLE' AND Event = 'POSCHANGED'		; GOSUB ReadingPC
	CASE EntID = @WINDOW:'.READ_TABLE' AND Event = 'INSERTROW'		; GOSUB InsertRow
	CASE EntID = @WINDOW:'.READ_TABLE' AND Event = 'DELETEROW'		; GOSUB DeleteRow
	
	CASE EntID = @WINDOW:'.PRINT_BUTTON' AND Event = 'CLICK'		; GOSUB PrintForm
	CASE EntID = @WINDOW:'.SAVE_BUTTON' AND Event = 'CLICK'			; GOSUB Save
	CASE EntID = @WINDOW:'.CANCEL_BUTTON' AND Event = 'CLICK'		; GOSUB Cancel
	
		
	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)

Set_Property(@WINDOW:'.READ_BY_ID','DEFPROP',@USER4)
Set_Property(@WINDOW:'.READ_BY_NAME','DEFPROP',OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))


TimeStamp = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
Set_Property(@WINDOW:'.READ_DTM','DEFPROP',TimeStamp)



Set_Property(@WINDOW,'FOCUS',@WINDOW:'.READ_DTM')
Set_Property(@WINDOW:'.READ_DTM','SELECTION',1:@FM:65534)

ReactList = Collect.IXVals('REACTOR', 'REACT_NO')

EvenSide = ''
OddSide = ''

ReactCnt = COUNT(ReactList,@FM) + (ReactList NE '')

FOR I = 1 TO ReactCnt
	IF MOD(ReactList<I>,2) THEN
		OddSide<-1> = ReactList<I>
	END ELSE
		EvenSide<-1> = ReactList<I>
	END
NEXT I

ReactList = EvenSide:@FM:OddSide

ReactAssignDesc = OCONV(XLATE('REACTOR',ReactList,'REACT_ASSIGN_DESC','X'),'[REACT_ASSIGN_CONV]')
ReactTypeDesc = OCONV(XLATE('REACTOR',ReactList,'REACT_TYPE_DESC','X'),'[REACT_TYPE_CONV]')

ReactCnt = COUNT(ReactList,@FM) + (ReactList NE '')

FOR I = 1 TO ReactCnt
	ReactList<I,2> = ReactTypeDesc<I>
	ReactList<I,3> = ReactAssignDesc<I>
NEXT I

Set_Property(@WINDOW:'.READ_TABLE','LIST',ReactList)

GOSUB Refresh

RETURN



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

RETURN


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

CtrlName = @WINDOW:'.READ_TABLE'

ReadList = Get_Property(CtrlName,'LIST')

LineCnt = INT(COUNT(ReadList,@FM) + (ReadList NE '')/2)

FOR I = 1 TO LineCnt
	LineWfrCnts	= ReadList<I,COL$WAFER_CNT>

	IF LineWfrCnts NE '' THEN
		BadLine = 0
		
		IF LineWfrCnts AND NOT(NUM(LineWfrCnts))	THEN BadLine = 1
		
		IF BadLine THEN
			stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,RED$)
		END ELSE
			stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,GREEN$)
		END
	END ELSE
		IF MOD(I,2) THEN
			stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,RCV_BLUE$)
		END
	END
NEXT I

RETURN



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

End_Dialog(@WINDOW,'Cancel')

RETURN


* * * * * * *
ReadingPC:
* * * * * * *

CtrlEntID = @WINDOW:'.READ_TABLE'

ColCnt = COL$WAFER_CNT

PrevSelPos	= Get_Property(CtrlEntId,"PREVSELPOS")
PrevCol 	= PrevSelPos<1>
PrevRow 	= PrevSelPos<2>

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

ListData	= Get_Property(CtrlEntId,'LIST')
ArrayData	= Get_Property(CtrlEntId,'DEFPROP')


IF CurrCol < COL$WAFER_CNT THEN
	Set_Property(CtrlEntId,"SELPOS",COL$WAFER_cNT:@FM:CurrRow)
	RETURN
END

GOSUB Refresh

RETURN


* * * * * * *
InsertRow:
* * * * * * *

CtrlEntID = @WINDOW:'.READ_TABLE'

stat = Send_Message(CtrlEntID, "DELETE", Parm1)

GOSUB Refresh

RETURN



* * * * * * *
DeleteRow:
* * * * * * *

CtrlEntID = @WINDOW:'.READ_TABLE'

stat = Send_Message(CtrlEntID, "INSERT", Parm1, Parm2)

GOSUB Refresh

RETURN


* * * * * * *
Save:
* * * * * * *

ReadList	= Get_Property(@WINDOW:'.READ_TABLE','LIST')
ReadBy		= Get_Property(@WINDOW:'.READ_BY_ID','DEFPROP')
ReadDTM		= Get_Property(@WINDOW:'.READ_DTM','DEFPROP')

ReadCnt = COUNT(ReadList,@FM) + (ReadList NE '')



FOR I = 1 TO ReadCnt
	
	IF ReadList<I,COL$WAFER_CNT> NE '' THEN
	
		Parms  = ReadList<I,COL$REACTOR>:@RM
		Parms := ReadBy:@RM
		Parms := ReadDTM:@RM
		Parms := ReadList<I,COL$WAFER_CNT>
		
		Set_Status(0)
				
		obj_React_Reads('Create',Parms)
		
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
NEXT I

Result = ''

End_Dialog(@WINDOW,Result)

RETURN




* * * * * * *
PrintForm:
* * * * * * *

ReactList = Get_Property(@WINDOW:'.READ_TABLE','LIST')

Print_React_Read_Worksheet( ReactList )


RETURN












