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

/*
	Commuter module for REACTOR_PM (Reactor Scheduled PM) window
	
	06/5/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

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

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, NextKey, obj_Reactor_PM
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, Select_Into, MemberOf



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT REACTOR_PM_EQUATES
$INSERT POPUP_EQUATES

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


EQU COL$PM_ID		TO 1
EQU COL$DUE_DT		TO 2
EQU COL$SERV_ID		TO 3
EQU COL$SERVICE		TO 4
EQU COL$COMP_DT		TO 5



ErrTitle = 'Error in Reactor_PM'
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 = 'WRITE'			; GOSUB Write
			CASE Event = 'READ'				; GOSUB Read
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	
	CASE EntID = @WINDOW:'.LU_PM_ID' AND Event = 'CLICK'	 		; GOSUB LuPMId
	CASE EntID = @WINDOW:'.NEW_PM' AND Event = 'CLICK'	 			; GOSUB New
	CASE EntID = @WINDOW:'.VIEW_ENTRY_LOG' AND Event = 'CLICK'		; GOSUB ViewReactorLog
	CASE EntID = @WINDOW:'.VIEW_COMP_LOG' AND Event = 'CLICK'		; GOSUB ViewReactorLog
	
	CASE EntID = @WINDOW:'.PM_HISTORY'
		BEGIN CASE 
			
			CASE Event = 'DBLCLK'									; GOSUB HistoryDC
			*CASE Event = 'POSCHANGED'								; *GOSUB CleanPC
		END CASE
	
	
	
	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


* * * * * * *
Page:
* * * * * * *
/*
Page = Get_Property(@WINDOW:'.CI_TAB', 'VALUE')

Set_Property(@WINDOW,'VPOSITION', Page)
*/
RETURN


* * * * * * *
New:
* * * * * * *

PMKey = Get_Property(@WINDOW:'.PM_ID','DEFPROP')

IF PMKey = '' THEN
	NextPMKey = NextKey('REACTOR_PM')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextPMKey)
END


RETURN





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

Send_Event(@WINDOW,'PAGE',1)


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

IF Security_Check( 'Reactor PM', Write$ ) THEN
	Set_Property(@WINDOW:'.NEW_PM','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.NEW_PM','ENABLED',0)
END

ReactNo	= Get_Property(@WINDOW:'.REACTOR','DEFPROP')
ServID	= Get_Property(@WINDOW:'.REACT_SERV_ID','DEFPROP')

IF ReactNo NE '' AND ServID NE '' THEN

	ReactPMHist = obj_Reactor_PM('ReactServHist',ReactNo:@RM:ServID:@RM)	;* Open + 3 year history

	Set_Property(@WINDOW:'.PM_HISTORY','LIST',ReactPMHist)
	
END


* 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:
* * * * * * *

IF Get_Property(@WINDOW:'.ENTRY_ID','DEFPROP') = '' THEN
	Set_Property(@WINDOW:'.ENTRY_ID','DEFPROP',OCONV( @USER4, '[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
	Set_Property(@WINDOW:'.ENTRY_DATE','DEFPROP',OCONV(Date(),'D4/'))
END

GOSUB Refresh


RETURN


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

RETURN


* * * * * * *
LuPMId:
* * * * * * * 

PMKeys = Dialog_Box( 'REACTOR_PM_QUERY', @window, '' )

IF PMKeys NE '' THEN

	TypeOver = ''
	TypeOver<PDISPLAY$> = PMKeys
	TypeOver<PMODE$> = 'K'

	PMKeys = Popup(@WINDOW,TypeOver,'REACTOR_PM_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	IF PMKeys = '' THEN RETURN
	
	IF INDEX(PMKeys,@VM,1) THEN
		Send_Event(@WINDOW,'QBFINIT')
		Set_Property(@WINDOW,'QBFLIST',PMKeys)
	END ELSE	
		obj_Appwindow('LoadFormKeys',@WINDOW:@RM:PMKeys)
	END
	
	GOSUB Refresh

END
	
RETURN


* * * * * * *
ViewReactorLog:
* * * * * * *

CurrCtrl = Get_Property(@WINDOW,'FOCUS')

IF CurrCtrl = @WINDOW:'.VIEW_ENTRY_LOG' THEN
	ReactorLogNo = Get_Property(@WINDOW:'.ENTRY_RL_NO','DEFPROP')
END

IF CurrCtrl = @WINDOW:'.VIEW_COMP_LOG' THEN
	ReactorLogNo = Get_Property(@WINDOW:'.COMP_RL_NO','DEFPROP')
END


IF ReactorLogNo NE '' THEN
	
	thisFormName = 'REACTOR_LOG'
	
	thisFormWindowUp = Get_Property(thisFormName,'VISIBLE')	;* Returns 0 = hidden, 1 = visible, 2 = minimized, 3 = maximized 

	IF thisFormWindowUp = ''	THEN
		Start_Window(thisFormName,@WINDOW,ReactorLogNo:'*CENTER', '', '')	;* Put up the card window
		RETURN
	END
	
	IF thisFormWindowUp = 2		THEN Set_Property(thisFormName,'VISIBLE',9)	;* Restore the window if minimized

	IF Get_Property(thisFormName,'SAVEWARN') THEN
		Send_Event(thisFormName,'CLEAR')					;* Clear anything existing (prompts for save first)
	END

END


RETURN


* * * * * * *
HistoryDC:
* * * * * * *


CtrlEntID = @WINDOW:'.PM_HISTORY'
CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

IF CurrCol = COL$PM_ID THEN
	PMId = Get_Property(CtrlEntID,'CELLPOS',COL$PM_ID:@FM:CurrRow)

	IF PMId NE '' THEN
		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		obj_Appwindow('LoadFormKeys',@WINDOW:@RM:PMId)
	END
END	;* End of ItemNo column



RETURN
