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

/*
	Commuter module for MAINT_ITEM window
	
	11/22/2013 - John C. Henry, J.C. Henry & Co., Inc. & David Klotz, IR Epi Services
*/

DECLARE SUBROUTINE Set_Property, ErrMsg, obj_Appwindow, Btree.Extract, Send_Event
DECLARE FUNCTION Get_Property, Send_Message, NextKey, Popup, obj_Calendar

$INSERT APPCOLORS
$INSERT MAINT_ITEM_EQUATES
$INSERT POPUP_EQUATES


ErrTitle = 'Error in Maint_Item'
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_PROB_CAT' AND Event = 'CLICK'	 		; GOSUB LUProbCat
	CASE EntID = @WINDOW:'.LU_REACT_SERV_ID' AND Event = 'CLICK'	; GOSUB LUReactServID
	CASE EntID = @WINDOW:'.LU_ITEM_SERIAL' AND Event = 'CLICK'	 	; GOSUB LUItemSerial
	CASE EntID = @WINDOW:'.COMP_BUTTON' AND Event = 'CLICK'	 		; GOSUB SignComp
	
	
	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)


RETURN



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

*DEBUG

RETURN



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





GOSUB Refresh

RETURN

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



RETURN


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

*Send_Event(@WINDOW,'PAGE',1)



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

Ctrls  = @WINDOW:'.ENTER_BY':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.ENTER_DTM'			; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

EnterBy		= Vals[1,@RM]
EnterDTM	= Vals[COL2()+1,@RM]

IF EnterBy	= '' THEN Vals  = 1:@RM ELSE Vals  = 0:@RM
IF EnterDTM = '' THEN Vals := 1		ELSE Vals := 0

Props = 'ENABLED':@RM:'ENABLED'

Set_Property(Ctrls,Props,Vals)

* 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


* * * * * * *
LUProbCat:
* * * * * * *

ReturnCtrl = @WINDOW:'.':Parm1

RetVal = Popup(@WINDOW,'','SHOW_REACT_PROB_CAT')
		
IF RetVal NE '' THEN
	obj_AppWindow('LUValReturn',RetVal:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
LUReactServID:
* * * * * * *

DEBUG

ReturnCtrl = @WINDOW:'.':Parm1

RetVal = Popup(@WINDOW,'','SHOW_REACT_SERVS')
   		
IF RetVal NE '' THEN
	obj_AppWindow('LUValReturn',RetVal:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
LUItemSerial:
* * * * * * *

DEBUG

RETURN

*ItemType = Get_Property(
		
IF ItemType = 'T' THEN
	RetVal = Popup(@WINDOW,'','TUBE')
END

SearchString  = 'GR_TYPE':@VM:ItemType:@FM
SearchString := 'CURR_STATUS':@VM:'N':@VM:'S':@FM 

IF ItemType = 'S' OR ItemType = 'RU' OR ItemType = 'RL' OR ItemType = 'R' THEN

	OPEN 'DICT.GRAPHITE' TO DictGraphite ELSE
		ErrMsg('Unable to open DICT.GRAPHITE')
		RETURN
	END

	SearchString  = 'GR_TYPE':@VM:ItemType:@FM
	SearchString := 'CURR_STATUS':@VM:'N':@VM:'U':@FM 
	
	GRKeys = ''
	Option = ''
	Flag = ''
	
	Btree.Extract(SearchString,'GRAPHITE',DictGraphite,GRKeys,Option,Flag)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	TypeOver = ''
	TypeOVer<PMODE$> = 'K'
	TypeOver<PDISPLAY$> = GRKEys
	RetVal = Popup(@WINDOW,TypeOver,'GRAPHITE')
	
	SerialNo = XLATE('GRAPHITE',RetVal,'SERIAL','X')
	
	RetVal = SerialNo	;* Temporary *************************************
	
END

IF RetVal NE '' THEN
	obj_AppWindow('LUValReturn',RetVal:@RM:@WINDOW:'.SERV_INFO':@RM:SelPos)
	GOSUB Refresh
END


RETURN


* * * * * * *
SignComp:
* * * * * * *
DEBUG

RETURN
