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

/*
	Commuter module for PM_SCHED (Preventive Maintenance Schedule) window
	
	8/24/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/


* * * * * * * *  DEAD AND NEEDS DELETED  JCH 11/30/2016  * * * * *

RETURN


DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, obj_Tables 
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 FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, obj_Popup, Popup
DECLARE FUNCTION Send_Message, Msg, NextKey



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT PM_EQUATES


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

EQU PTYPE$        TO 14		;* From POPUP_EQUATES

EQU COL$PM_KEY		TO 1
EQU COL$EARLY_DTM	TO 2
EQU COL$SCHED_DTM	TO 3
EQU COL$LATE_DTM	TO 4

ErrCode  = ''
ErrorMsg = ''
ErrTitle = 'Error in PM_SCHED routine'

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:'.PM_KEYS' AND Event = 'DBLCLK'		; GOSUB PMKeyDC
	CASE EntID = @WINDOW:'.NEW_BUTTON' AND Event = 'CLICK'		; GOSUB New
	CASE EntID = @WINDOW:'.NEW_PM' AND Event = 'CLICK'			; GOSUB NewPM
	CASE EntID = @WINDOW:'.LU_PMS_ID' AND Event = 'CLICK'		; GOSUB LUPMSId
	CASE EntID = @WINDOW:'.LU_TOOL_ID' AND Event = 'CLICK'		; GOSUB LUToolID
	CASE EntID = @WINDOW:'.LU_TIME_CD' AND Event = 'CLICK'		; GOSUB LUInterval
	
	
	
	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


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

GOTO Refresh

RETURN

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

PMSId = NextKey('PM_SCHED')

obj_Appwindow('LoadFormKey',@WINDOW:@RM:PMSId)

RETURN




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

Send_Event('MASTER_PM_LIST','GOTFOCUS')

RETURN

* * * * * * *
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,Line>,@SVM) + (ETCols<1,Line> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,Line,N>,Line,GREEN$)
			NEXT N
		END
	NEXT Line
NEXT I

RETURN





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



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

IF RowExists('PM',PMId) ELSE
	IF Get_Property(@WINDOW:'.ENTER_DTM','DEFPROP') = '' THEN
		CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTH')
		Set_Property(@WINDOW:'.ENTER_DTM','DEFPROP',CurrDTM)
	END
END

GOSUB Refresh

RETURN



* * * * * * *
LUPMSId:
* * * * * * *

PMSId = Popup(@WINDOW,'','PM_SCHED')

IF PMSId = '' THEN RETURN


IF INDEX(PMSId,@VM,1) THEN
	CONVERT @VM TO @FM IN PMSId
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',PMSId)
	Send_Event(@WINDOW,'QBFFIRST')
END ELSE
	obj_AppWindow('LoadFormKeys',@WINDOW:@RM:PMSId)
END


RETURN


* * * * * * *
LUToolID:
* * * * * * *

ToolID = Popup(@WINDOW,'','TOOLS')

IF ToolID = '' THEN RETURN

obj_Appwindow('LUValReturn',ToolID:@RM:@WINDOW:'.TOOL_ID')

RETURN




* * * * * * *
LUInterval:
* * * * * * *

Typeover = ''
Typeover<PTYPE$> = 'E'		;* Returns entire row(s)

PMInterval = Popup(@WINDOW,Typeover,'PM_INTERVAL')

IF PMInterval NE '' THEN

	TimeCode = PMInterval<1,1>
	IntDays	= PMInterval<1,3>
	
	obj_AppWindow('LUValReturn',TimeCode:@RM:@WINDOW:'.INT_TIME_CD')
	obj_AppWindow('LUValReturn',IntDays:@RM:@WINDOW:'.INTERVAL_TIME')
	
END

RETURN



* * * * * * *
NewPM:
* * * * * * *

PMSId = Get_Property(@WINDOW:'.PMS_ID','DEFPROP')

IF @USER4 = '' THEN @USER4 = 'BRYCE_BARB'

Send_Event(@WINDOW,'WRITE')								;* Write current PM_SCHED record

PMNo = NextKey('PM_SCHED')								;* Next PMKey

PMRec = ''
PMRec<PM_PMS_ID$> = PMSId								;* New PMRec


otParms = 'PM':@RM:PMNo:@RM:@RM:PMRec
obj_Tables('WriteRec',otParms)							;* Write new PM record

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

obj_Appwindow('ViewRelated','PM':@RM:PMNo:@RM:@RM)		;* View new related PM record
	
Set_Property('PM','@RETURN_KEY',PMSId)



RETURN



* * * * * * *
PMKeyDC:
* * * * * * *

CtrlEntID = @WINDOW:'.PM_KEYS'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

PMKeyList = Get_Property(CtrlEntID,'LIST')

IF PMKeyList<CurrRow,COL$PM_KEY> NE '' THEN
	PMKey = PMKeyList<CurrRow,COL$PM_KEY>
	obj_Appwindow('ViewRelated','PM':@RM:PMKey:@RM:@RM)
	
END

RETURN








