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

/*
	Commuter module for REACT_READS (Reactor Readings) window
	
	09/23/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, RList 
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note

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_EVENT_EQUATES
$INSERT POPUP_EQUATES
$INSERT RLIST_EQUATES

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


ErrTitle = 'Error in React_Reads commuter module.'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'READ'				; GOSUB Read
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	CASE EntID = @WINDOW:'.LU_REACTOR' AND Event = 'CLICK' 	; GOSUB LUReactor
	CASE EntID = @WINDOW:'.READ_DTM' AND Event = 'GOTFOCUS'	; GOSUB ReadDtmGF
	
	
		
	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:
* * * * * * *

/*
IF NOT(Security_Check('Reactor Event Log',READ$)) THEN
	Security_Err_Msg('Reactor Event Log',READ$)
	End_Window(@WINDOW)
	RETURN
END
*/

obj_Appwindow('Create',@WINDOW)

GOSUB Refresh

RETURN


* * * * * * *
Clear:
* * * * * * *


IF Get_Property(@WINDOW,'@READONLY') THEN
	obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
	Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window
END


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

* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT I
NEXT I

RETURN





* * * * * * *
Read:
* * * * * * *


GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

/*
OrderNo = Get_Property(@WINDOW:'.ORD_NO','TEXT')

Message = ''
IF RowExists('ORDER',OrderNo) THEN
	IF Get_Property(@WINDOW,'SAVEWARN') THEN
		Message = 'Order No. ':OrderNo:' has been changed.'
	END
END ELSE
	Message = 'New Order ':QUOTE(OrderNo):' entered into system.'
END

IF Message NE '' THEN
   	
	Recipients		= XLATE('NOTIFICATION','ORDER_ENTRY',NOTIFICATION_USER_ID$,'X')
	SentFrom		= @USER4
	Subject			= 'New/Update Order':OrderNo
	AttachWindow	= 'ORDER2'
	AttachKey		= OrderNo   
	SendToGroup		= ''   

	Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
	*obj_Notes('Create',Parms)																				;* Per Request from Customer Service

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
 
END
/*/

Result = 1

RETURN


* * * * * * *
Delete:
* * * * * * *

/*
IF Security_Check('Order',Delete$) THEN
	Result = 1		;* Proceed with delete
END ELSE
	Security_Err_Msg('Order',Delete$)
	Result = 0		;* Stop event chain
END
*/

RETURN

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

RETURN


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

Set_Status(0)

ReactNo = Popup(@WINDOW,'','REACTORS')

IF ReactNo = CHAR(27) OR ReactNo = '' THEN RETURN

obj_AppWindow('LUValReturn',ReactNo:@RM:@WINDOW:'.REACT_NO')

RETURN



* * * * * * *
ReadDtmGF:
* * * * * * *

ReactorNo = Get_Property(@WINDOW:'.REACT_NO','DEFPROP')

Today = Date()

SelectDt = OCONV((Today - 30),'D4/')

SelectSent = 'SELECT REACT_READS WITH REACT_NO ':ReactorNo:' AND WITH READ_DT >  ':QUOTE(SelectDt):' BY-DSND READ_DTM'

RList(SelectSent,TARGET_ACTIVELIST$, "", "", "")

ReadKeys = Popup(@WINDOW,'','REACT_READS')

IF ReadKeys = CHAR(27) OR ReadKeys = '' THEN RETURN

IF INDEX(ReadKeys,@VM,1) THEN
	Send_Event(@WINDOW,'CLEAR')
	Set_Property(@WINDOW,'QBFLIST',ReadKeys)
	GOSUB Refresh
END ELSE
	ReadDTM = OCONV(FIELD(ReadKeys,'*',2),'DT4/^HS')
	obj_AppWindow('LUValReturn',ReadDTM:@RM:@WINDOW:'.READ_DTM')
END


RETURN




