COMPILE FUNCTION Comm_Dialog_React_Event_Query(Method, Parm1, Parm2)

/*
	Commuter module for Dialog_React_Event window.
	
	01/10/2007 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, ErrMsg, RList
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Btree.Extract, Msg, Send_Info
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Send_Message, Popup, Collect.IXVals, Msg


$INSERT APPCOLORS
$INSERT MSG_EQUATES
$INSERT RLIST_EQUATES
$INSERT POPUP_EQUATES


EQU CRLF$	TO \0D0A\

EQU COL$REACT_NO		TO 1
EQU COL$REACT_TYPE		TO 2
EQU COL$RED_PRESS		TO 3
EQU COL$WAFER_SIZE		TO 4
EQU COL$TOOL_LOC		TO 5
EQU COL$ASSIGNMENT		TO 6
EQU COL$ESC_HOURS		TO 7

EQU COL$EVENT_CD	TO 1
EQU COL$EVENT_TYPE	TO 2

ErrTitle = 'Error in Comm_Dialog_Order_Find'
ErrorMsg = ''
ErrCode = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'LUReactor'		; GOSUB LUReactor
	CASE Method = 'LUEventType'		; GOSUB LUEventType
	CASE Method = 'LUDate'			; GOSUB LUDate
	CASE Method = 'StartDtGF'		; GOSUB StartDtGF
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'PerformQuery'	; GOSUB PerformQuery
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE

RETURN Result


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

obj_AppWindow('Create')

Set_Property(@WINDOW,'STATUSLINE',@WINDOW:'.STATUSLINE_FIX')

GOSUB Refresh

RETURN


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

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'		;* Multiple Select
TypeOver<PTYPE$> 	= 'E'		;* Return entire row

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

IF ReactData = '' THEN RETURN

Set_Property(@WINDOW:'.REACT_NO','LIST',ReactData)

LineCnt = COUNT(ReactData,@FM) + (ReactData NE '')
ColCnt = 7

FOR Line = 1 TO LineCnt
	FOR Column = 2 TO ColCnt
		stat = Send_Message(@WINDOW:'.REACT_NO','COLOR_BY_POS',Column,Line,GREEN$)
	NEXT Column
NEXT Line

RETURN


* * * * * * *
LUEventTYpe:
* * * * * * *

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'		;* Multiple Select
TypeOver<PTYPE$> 	= 'E'		;* Return entire row

EventTypes = Popup(@WINDOW,TypeOver,'REACT_EVENT_TYPE')

IF EventTypes = '' THEN RETURN

Set_Property(@WINDOW:'.EVENT_TYPE','LIST',EventTypes)

LineCnt = COUNT(EventTypes,@FM) + (EventTypes NE '')
ColCnt = 2

FOR Line = 1 TO LineCnt
	FOR Column = 2 TO ColCnt
		stat = Send_Message(@WINDOW:'.EVENT_TYPE','COLOR_BY_POS',Column,Line,GREEN$)
	NEXT Column
NEXT Line

RETURN




* * * * * * *
LUDate:
* * * * * * *

ReturnCtrl = Parm1[1,@RM]

IF ReturnCtrl = '' THEN ReturnCtrl = Get_Property(@WINDOW,'FOCUS')

DateSelected =  Dialog_Box('POPUP_YEAR',@WINDOW)

RetVal = OCONV(DateSelected, 'D4/')

IF RetVal NE '' THEN
	obj_Appwindow('LUValReturn',RetVal:@RM:ReturnCtrl)
END

RETURN



* * * * * * *
StartDtGF:
* * * * * * *

StartDt = Get_Property(@WINDOW:'.START_DT','DEFPROP')

IF StartDt = '' THEN
	Set_Property(@WINDOW:'.START_DT','DEFPROP',OCONV(Date(),'D4/'))
	Set_Property(@WINDOW:'.START_DT','SELECTION',1:@FM:99)
END

RETURN


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

RETURN



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

SearchString = ''


*  ReactorNo  *

ReactNos = Get_Property(@WINDOW:'.REACT_NO','ARRAY')<COL$REACT_NO>

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


*  Event Types  *

EventTypes	= Get_Property(@WINDOW:'.EVENT_TYPE','DEFPROP')<COL$EVENT_CD>


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

* Start and End Dates

StartDt = OCONV(ICONV(Get_Property(@WINDOW:'.START_DT','TEXT'),'D'),'D4')
EndDt	= OCONV(ICONV(Get_Property(@WINDOW:'.END_DT','TEXT'),'D'),'D4')

	
SelectSent  = 'SELECT REACT_EVENT '


BEGIN CASE
	CASE StartDt NE '' AND EndDt = ''
		
		SelectSent := 'WITH EVENT_DT GE ':QUOTE(StartDt)
	
	CASE StartDt = '' AND EndDt NE ''
		SelectSent := 'WITH EVENT_DT LE ':QUOTE(EndDt)

	
	CASE StartDt NE '' AND EndDt NE ''
		SelectSent := 'WITH EVENT_DT GE ':QUOTE(StartDt):' AND WITH EVENT_DT LE ':QUOTE(EndDt)
		
	CASE 1
		NULL
END CASE

IF ReactNos NE '' THEN

	SWAP @VM WITH '" "' in ReactNos
	
	SelectSent := ' AND WITH REACT_NO ':QUOTE(ReactNos)
END

IF EventTypes NE '' THEN
	SWAP @VM WITH '" "' IN EventTypes
	SelectSent := ' AND WITH EVENT_TYPE ':QUOTE(EventTypes)
END


IF ReactNos = '' THEN
	SelectSent := ' BY REACT_NO'
END

SelectSent := ' BY-DSND EVENT_DTM'

Def = ""
Def<MTEXT$> = "Selecting Reactor Events..."
Def<MTYPE$> = "U"

* display the processing message and do the processing

MsgUp = Msg(@window, Def)

RList(SelectSent,TARGET_ACTIVELIST$,'','','')

IF Get_Status(errCode) THEN
	Msg(@window, MsgUp)
	ErrMsg(errCode)
	RETURN
END ELSE
	Msg(@window, MsgUp)
END

EventKeys = ''
Done = ''

LOOP
	READNEXT EventKey ELSE Done = 1
UNTIL Done
	EventKeys := EventKey:@VM
REPEAT
EventKeys [-1,1] = ''

End_Dialog(@WINDOW,EventKeys)

RETURN




