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

/*
	Commuter module for DIALOG_REACT_LL (Disable/Enable Load Lock side)
	
	08/21/2015 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status,obj_React_LL
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, Memberof
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_Calendar, obj_Tables


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT RTI_STYLE_EQUATES
$INSERT REACTOR_EQUATES
$INSERT REACT_LL_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_React_LL 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:'.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)

ReactNo = Parm1

CurrMode			= OCONV(XLATE('REACTOR',ReactNo,'CURR_MODE','X'),'[REACT_MODE_CONV]')
ActiveReactLLKey	= XLATE('REACTOR',ReactNo,REACTOR_ACTIVE_LL_DISABLED$,'X')

IF ActiveReactLLKey NE '' THEN
	ActiveReactRec = XLATE('REACT_LL',ActiveReactLLKey,'','X')
	ActiveLLDisabled = ActiveReactRec<REACT_LL_DISABLED$>				;* Side of Load Lock disabled (L or R)
END ELSE
	ActiveLLDisabled = ''
END


Set_Property(@WINDOW:'.REACT_NO','DEFPROP',ReactNo)
Set_Property(@WINDOW:'.ACTIVE_REACT_LL_KEY','DEFPROP',ActiveReactLLKey)
Set_Property(@WINDOW:'.CURR_MODE','DEFPROP',CurrMode)


Set_Property(@WINDOW:'.REACT_LL_HIDDEN','DEFPROP',ActiveLLDisabled)

IF ActiveLLDisabled = '' THEN
	Set_Property(@WINDOW:'.LABEL_DISABLE','TEXT','Disable:')
	Set_Property(@WINDOW:'.REACT_LL','VALUE','')					;* Clears any default button selection
END ELSE
	Set_Property(@WINDOW:'.LABEL_DISABLE','TEXT','Enable:')
	Set_Property(@WINDOW:'.REACT_LL','VALUE',ActiveLLDisabled)
	Set_Property(@WINDOW:'.REACT_LL','ENABLED',0)
END
//Added 4/19/22 per Todd H. Blocks non-maintenance from putting a LL down or up
IF Memberof(@USER4, 'MAINTENANCE') NE 1 then
    Set_Property(@WINDOW:'.REACT_LL','ENABLED',0)
    Set_Property(@WINDOW:'.SAVE_BUTTON','ENABLED',0)
end


RETURN




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


Ctrls  = @WINDOW:'.REACT_NO':@RM			; Props  = 'DEFPROP':@RM
Ctrls := @WINDOW:'.ACTIVE_REACT_LL_KEY':@RM	; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.REACT_LL':@RM			; Props := 'VALUE':@RM
Ctrls := @WINDOW:'.NOTE'					; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

ReactNo				= Vals[1,@RM]
ActiveReactLLKey	= Vals[COL2()+1,@RM]
ReactLL				= Vals[COL2()+1,@RM]
Note				= Vals[COL2()+1,@RM]

CurrUser = @USER4
CurrDTM = obj_Calendar('CurrDTM')

ActiveStartDTM = OCONV(ActiveReactLLKey[-1,'B*'],'DT4/^HS')


BEGIN CASE

	CASE ReactNo = '' 
		Error = 'Reactor No field is required.'
		
	CASE Note = ''
		Error = 'Note field is required.'
		
	CASE ActiveReactLLKey = '' AND ReactLL = '' 
		Error = 'Load Lock Side is required.'
		
	CASE 1
		Error = ''
	
END CASE


IF Error NE '' THEN
	Msg(Error)
	RETURN
END

IF ActiveReactLLKey = '' THEN

	* Create a New REACT_LL record
	
	orlParms  = ReactNo:@RM
	orlParms := CurrDTM:@RM		;* Start DTM
	orlParms := @USER4:@RM		;* Current user
	orlParms := ReactLL:@RM		;* 'L' or 'R' for LL side
	orlParms := Note			;* Note with reason for disabling the Load Lock
	
	obj_React_LL('Create',orlParms)

	End_Dialog(@WINDOW,ReactLL)
	
END ELSE
	
	* Close existing REACT_LL record
	
	orlParms  = ReactNo:@RM
	orlParms := ActiveStartDTM:@RM	;* StartDTM
	orlParms := CurrDTM:@RM			;* StopDTM
	orlParms := @USER4:@RM			;* Curr User
	orlParms := Note				;* Note with reason for clearing disabled Load Lock
	
	obj_React_LL('Close',orlParms)
	
	End_Dialog(@WINDOW,'')

END


RETURN



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


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

End_Dialog(@WINDOW,'Cancel')

RETURN



