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

/*
	Commuter module for CALIB_LIST (Calibration List) window
	
	02/3/2010 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, Set_List_Box_Data
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, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, NextKey, MemberOf



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT CALIB_LIST_EQUATES
$INSERT POPUP_EQUATES

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

EQU COL$CAL_DT		TO 1
EQU COL$CAL_BY		TO 2
EQU COL$CAL_NOTE	TO 3


ErrTitle = 'Error in Calib_List routine'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'            ; GOSUB Write
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	CASE EntID = @WINDOW:'.NEW_ITEM' AND Event = 'CLICK'		; GOSUB NewItem
	CASE EntID = @WINDOW:'.LU_CL_NO' AND Event = 'CLICK'		; GOSUB LUCalibItem
	CASE EntID = @WINDOW:'.LU_CL_TYPE' AND Event = 'CLICK'		; GOSUB LUCalibItemType
	CASE EntID = @WINDOW:'.LU_CL_LOC' AND Event = 'CLICK'		; GOSUB LUCalibItemLoc
	CASE EntID = @WINDOW:'.CALIBRATIONS' AND Event = 'DBLCLK'	; GOSUB CalibrationsDC
	CASE EntID = @WINDOW:'.NEW_CALIBRATION' AND Event = 'CLICK'	; GOSUB NewCalibClick
	
	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:
* * * * * * *


IF MemberOf(@USER4,'CALIBRATION') ELSE
	ErrMsg('Only authorized personnel may update the Calibration List.')
	End_Window(@WINDOW)
	RETURN
END


obj_Appwindow('Create',@WINDOW)

Set_List_Box_Data( @WINDOW )

GOSUB Refresh

RETURN


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


IF Get_Property(@WINDOW,'@READONLY') THEN
	obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
	Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window
END


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



CLNo = Get_Property(@WINDOW:'.CL_NO','DEFPROP')

IF RowExists('CALIB_LIST',CLNo) 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


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

    ParentVis = Get_Property('NDW_MASTER_CALIB_LIST', 'VISIBLE')
    If ParentVis then Post_Event('NDW_MASTER_CALIB_LIST', 'OMNIEVENT')

RETURN

* * * * * * *
Delete:
* * * * * * *

/*
IF Security_Check('Order',Delete$) THEN
	Result = 1		;* Proceed with delete
END ELSE
	Security_Err_Msg('Order',Delete$)
	Result = 0		;* Stop event chain
END
*/

RETURN


* * * * * * *
NewItem:
* * * * * * *

CLNo = Get_Property(@WINDOW:'.CL_NO','DEFPROP')

IF CLNo = '' THEN
	NextCLNo = NextKey('CALIB_LIST')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextCLNo)
END


RETURN


* * * * * * *
LUCalibItem:
* * * * * * * 

CLKeys = Popup(@WINDOW,'','CALIB_LIST')

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

CONVERT @VM TO @FM IN CLKeys

IF INDEX(CLKeys,@FM,1) THEN
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',CLKeys)
	GOSUB Refresh
	Send_Event(@WINDOW,'QBFIRST')
END ELSE
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:CLKeys)
END


RETURN



* * * * * * *
LUCalibItemType:
* * * * * * *

CLItemType = Popup(@WINDOW,'','CALIB_LIST_TYPE')

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

IF CLItemType NE '' THEN
	obj_AppWindow('LUValReturn',CLItemType:@RM:@WINDOW:'.CL_TYPE') 
END

RETURN


* * * * * * *
LUCalibItemLoc:
* * * * * * *

CLItemLoc = Popup(@WINDOW,'','CALIB_LIST_LOC')

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

IF CLItemLoc NE '' THEN
	obj_AppWindow('LUValReturn',CLItemLoc:@RM:@WINDOW:'.CAL_LOC') 
END

RETURN




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


obj_Notes('Inbox',@USER4)	;* Checks for any new messages

Send_Event('MASTER_CALIB_LIST','CREATE')

RETURN



* * * * * * *
CalibrationsDC:
* * * * * * *

CtrlEntID = @WINDOW:'.CALIBRATIONS'

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

CalDt = Get_Property(CtrlEntID,'CELLPOS',COL$CAL_DT:@FM:CurrRow)

CalDt = ICONV(CalDt,'D')
CLNo = Get_Property(@WINDOW:'.CL_NO','DEFPROP')

IF CLNo NE '' AND CalDt NE '' THEN
	
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	oaParms  = 'CALIBRATION':@RM
	oaParms := CLNo:'*':CalDt:@RM
	oaParms := '':@RM						;* Default Record
	oaParms := CLNo:@RM
	oaParms := @RM
	oaParms := CtrlEntID:@RM
	oaParms := CurrPos
	
	obj_Appwindow('ViewNewDetail', oaParms)

	
END

RETURN


* * * * * * *
NewCalibClick:
* * * * * * *

CtrlEntID = @WINDOW:'.CALIBRATIONS'

CLNo = Get_Property(@WINDOW:'.CL_NO','DEFPROP')

IF CLNo NE ''  THEN
	
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	oaParms  = 'CALIBRATION':@RM
	oaParms := CLNo:@RM
	oaParms := '':@RM						;* Default Record
	oaParms := CLNo:@RM
	oaParms := @RM
	oaParms := CtrlEntID:@RM
	oaParms := 1:@FM:1
	
	obj_Appwindow('ViewNewDetail', oaParms)
	
END

RETURN






