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

/*
	Commuter module for DIALOG_INJECTOR_SETTINGS (Enter Injector Settings)
	
	02/11/2014 - 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, obj_Tables

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


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT RTI_STYLE_EQUATES
$INSERT REACT_INJECTOR_EQUATES


EQU HIDDEN$		TO 32
EQU SKIPPED$	TO 4100

EQU COL$PORT1		TO 1
EQU COL$PORT2		TO 2
EQU COL$PORT3		TO 3
EQU COL$PORT4		TO 4
EQU COL$PORT5		TO 5


ErrTitle = 'Error in Dialog_Injector_Settings 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:'.SETTINGS' AND Event = 'INSERTROW'		; GOSUB InsertRow
	CASE EntID = @WINDOW:'.SETTINGS' AND Event = 'DELETEROW'		; GOSUB DeleteRow
	
	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)

RLId	= Parm1[1,@FM]
ReactNo	= Parm1[COL2()+1,@FM]
InjType	= Parm1[COL2()+1,@FM]
CurrDTM = Parm1[COL2()+1,@FM]

Ctrls  = @WINDOW:'.RL_ID':@RM			; Props  = 'DEFPROP':@RM	; Vals  = RLId:@RM
Ctrls := @WINDOW:'.REACT_NO':@RM		; Props := 'DEFPROP':@RM	; Vals := ReactNo:@RM
Ctrls := @WINDOW:'.INJ_TYPE':@RM		; Props := 'INVALUE':@RM	; Vals := InjType:@RM
Ctrls := @WINDOW:'.SET_DTM'				; Props := 'DEFPROP'		; Vals := CurrDTM

Set_Property(Ctrls,Props,Vals)


SettingStyles = Send_Message(@WINDOW:'.SETTINGS','COLSTYLE',0,'')

IF InjType = 'M' THEN
	Set_Property(@WINDOW:'.SETTINGS','ARRAY',STR(@FM,4))
	SettingStyles<COL$PORT4> = BitAnd(SettingStyles<COL$PORT4>,BitNot(HIDDEN$))
	SettingStyles<COL$PORT5> = BitAnd(SettingStyles<COL$PORT5>,BitNot(HIDDEN$))
END

IF InjType = 'B' THEN
	Set_Property(@WINDOW:'.SETTINGS','ARRAY',STR(@FM,2))
	SettingStyles<COL$PORT4> = BitOr(SettingStyles<COL$PORT4>,HIDDEN$)
	SettingStyles<COL$PORT5> = BitOr(SettingStyles<COL$PORT5>,HIDDEN$)
END

SettingStyles = Send_Message(@WINDOW:'.SETTINGS','COLSTYLE',0,'')

Set_Property(@WINDOW:'.SETTINGS','FOCUS',1)


RETURN



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

RETURN


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

CtrlEntID = @WINDOW:'.READ_TABLE'

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



RETURN



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

CtrlEntID = @WINDOW:'.READ_TABLE'

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


RETURN


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

Ctrls  = @WINDOW:'.RL_ID':@RM		; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.REACT_NO':@RM	; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.SET_DTM':@RM		; Props := 'INVALUE':@RM
Ctrls := @WINDOW:'.SETTINGS'		; Props := 'INVALUE'

Vals = Get_Property(Ctrls,Props)

RLId		= Vals[1,@RM]
ReactNo		= Vals[COL2()+1,@RM]
SetDTM		= Vals[COL2()+1,@RM]
Settings	= Vals[COL2()+1,@RM]

CONVERT @FM TO @SVM IN Settings

otParms        = 'REACT_INJECTOR':@RM:ReactNo
ReactInjectRec = obj_Tables('ReadRec',otParms)
errCode        = ''
IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	obj_Tables('UnlockRec',otParms)
	RETURN
END

LOCATE SetDTM in ReactInjectRec<REACT_INJECTOR_SET_DTM$> BY 'DR' USING @VM  SETTING Pos THEN
	NULL
END ELSE

	ReactInjectRec = INSERT(ReactInjectRec,REACT_INJECTOR_SET_DTM$,Pos,0,SetDTM)
	ReactInjectRec = INSERT(ReactInjectRec,REACT_INJECTOR_SET_RL_ID$,Pos,0,RLId)
	ReactInjectRec = INSERT(ReactInjectRec,REACT_INJECTOR_SETTING$,Pos,0,Settings)
	
	otParms = FIELDSTORE(OtParms,@RM,4,0,ReactInjectRec)
	obj_Tables('WriteRec',otParms)
	
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
END

End_Dialog(@WINDOW,'')

RETURN


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

End_Dialog(@WINDOW,'Cancel')

RETURN




