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

/*
	Commuter module for Reactor_PM_Query dialog window
	
	05/29/2013 - 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, Key_Sort


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

EQU COL$REACT_NO			TO 1
EQU COL$REACT_TYPE			TO 2
EQU COL$REACT_RED_PRESS		TO 3
EQU COL$REACT_WAFER_SIZE	TO 4
EQU COL$REACT_LOC_DESC		TO 5

EQU COL$SERV_ID				TO 1
EQU COL$SERV_DESC			TO 2

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



ErrTitle = 'Error in Reactor_PM_Query 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:'.LU_REACT_NO' AND Event = 'CLICK'				; GOSUB LUReactor
	CASE EntID = @WINDOW:'.PERFORM_QUERY_BUTTON' AND Event = 'CLICK'	; GOSUB PerformQuery
	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)

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

* * * * * * *
PerformQuery:
* * * * * * *


OPEN 'DICT.REACTOR_PM' TO DictVar ELSE
	ErrMsg('Unable to open "DICT.REACTOR_PM" for Query.')
	RETURN
END

Ctrls  = @WINDOW:'.LAST_DONE_FROM':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.LAST_DONE_THRU':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.DUE_FROM':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.DUE_THRU':@RM			; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.COMPLETE_FROM':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.COMPLETE_THRU':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.REACTORS':@RM			; Props := 'ARRAY':@RM
Ctrls := @WINDOW:'.REACT_SERVS':@RM			; Props := 'ARRAY':@RM
Ctrls := @WINDOW:'.NOT_COMPLETE'			; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)


LastDoneFrom  = Vals[1,@RM]
LastDoneThru  = Vals[COL2()+1,@RM]
DueFrom  = Vals[COL2()+1,@RM]
DueThru  = Vals[COL2()+1,@RM]
CompleteFrom  = Vals[COL2()+1,@RM]
CompleteThru  = Vals[COL2()+1,@RM]
Reactors      = Vals[COL2()+1,@RM]<COL$REACT_NO>
ReactServs    = Vals[COL2()+1,@RM]<COL$SERV_ID>
NotCompleted  = Vals[COL2()+1,@RM]

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

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

SearchString = ''


IF Reactors NE '' THEN
	SearchString<-1> = 'REACTOR':@VM:Reactors:@FM
END

BEGIN CASE
	CASE LastDoneFrom NE '' AND LastDoneThru = ''
		SearchString := 'LAST_DONE':@VM:'>=':LastDoneFrom:@FM
	
	CASE LastDoneFrom = '' AND LastDoneThru NE ''
		SearchString := 'LAST_DONE':@VM:'<=':LastDoneThru:@FM
	
	CASE LastDoneFrom NE '' AND LastDoneThru NE ''
		SearchString := 'LAST_DONE':@VM:LastDoneFrom:'...':LastDoneThru:@FM
		
	CASE 1
		NULL
END CASE


BEGIN CASE
	CASE DueFrom NE '' AND DueThru = ''
		SearchString := 'DUE_DT':@VM:'>=':DueFrom:@FM
	
	CASE DueFrom = '' AND DueThru NE ''
		SearchString := 'DUE_DT':@VM:'<=':DueThru:@FM
	
	CASE DueFrom NE '' AND DueThru NE ''
		SearchString := 'DUE_DT':@VM:DueFrom:'...':DueThru:@FM
		
	CASE 1
		NULL
END CASE


BEGIN CASE
	CASE CompleteFrom NE '' AND CompleteThru = ''
		SearchString := 'COMPLETE_DATE':@VM:'>=':CompleteFrom:@FM
	
	CASE CompleteFrom = '' AND CompleteThru NE ''
		SearchString := 'COMPLETE_DATE':@VM:'<=':CompleteThru:@FM
	
	CASE CompleteFrom NE '' AND CompleteThru NE ''
		SearchString := 'COMPLETE_DATE':@VM:CompleteFrom:'...':CompleteThru:@FM
		
	CASE 1
		SearchString := 'COMPLETE_DATE':@VM:'':@FM		;* Not Completed
		
	CASE 1
		NULL
		
		
END CASE


IF ReactServs <> '' THEN
    SearchString := 'REACT_SERV_ID':@VM:ReactServs:@FM
END

ReactPMKeys = ''

IF SearchString NE '' THEN
	Set_Status(0)
	Btree.Extract(SearchString,'REACTOR_PM',DictVar,ReactPMKeys,'',Flag)
	
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END


END	;* End of check for null SearchString


IF ReactPMKeys NE '' THEN
	ReactPMKeys = Key_Sort(ReactPMKeys,'REACTOR_PM','REACTOR':@FM:'SERV_DESC':@FM:'#LAST_DONE', 1 )
	End_Dialog(@WINDOW,ReactPMKeys)
END ELSE
	MsgInfo = ''
	MsgInfo<mtext$> = 'No records found meeting your criteria...' 
	MsgInfo<micon$> = '!'
	Void = msg( '', MsgInfo )
END
 
RETURN 0


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

End_Dialog(@WINDOW,'Cancel')

RETURN


* * * * * * *
LUReactor:
* * * * * * *

IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

Set_Status(0)

TypeOver = ''
TypeOver<PSELECT$> = 2	;* Multi Select

ReactNos = Popup(@WINDOW,TypeOver,'REACTORS')

IF ReactNos = '' THEN RETURN

CurrReactNos = Get_Property(@WINDOW:'.REACTORS','ARRAY')<1>

LOOP
	TestLine = CurrReactNos[-1,'B']
UNTIL TestLine NE @VM OR CurrReactNos = ''
	CurrReactNos[-1,1] = ''
REPEAT

ReactCnt = COUNT(ReactNos,@VM) + (ReactNos NE '')

FOR I = 1 TO ReactCnt
	ReactNo = ReactNos<1,I>
	LOCATE ReactNo IN CurrReactNos BY 'AR' USING @VM SETTING Pos ELSE
		CurrReactNos = INSERT(CurrReactNos,1,Pos,0,ReactNo)
	END
NEXT I


CurrCnt = COUNT(CurrReactNos,@VM) + (CurrReactNos NE '')

ReactTypes		= XLATE('REACTOR',CurrReactNos,'REACT_TYPE_DESC_OPS','X')
RedPressures	= XLATE('REACTOR',CurrReactNos,'REDUCED_PRESS','X')
WaferSizes		= XLATE('REACTOR',CurrReactNos,'WAFER_SIZE','X')
Locations		= XLATE('REACTOR',CurrReactNos,'TOOL_LOC_DESC','X')

ReactList = ''

FOR I = 1 TO CurrCnt
	ReactList<I,COL$REACT_NO> 			= ReactNos<1,I>
	ReactList<I,COL$REACT_TYPE>			= ReactTypes<1,I>
	ReactList<I,COL$REACT_RED_PRESS>	= RedPressures<1,I>
	ReactList<I,COL$REACT_WAFER_SIZE>	= WaferSizes<1,I>
	ReactList<I,COL$REACT_LOC_DESC>		= Locations<1,I>
NEXT I




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



RETURN


CtrlEntID = @WINDOW:'.REACTORS'

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












