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

/*
	Commuter module for PRS_Layer (Product Specification Layer) window
	
	06/11/2004 - John C. Henry, J.C. Henry & Co., Inc.
	10/1/2012  - Rewrite for newer call parameters
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Event, Security_Err_Msg, obj_PRS_Prop
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Start_Window, Security_Check

$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT PRS_LAYER_EQU
$INSERT PRS_LAYER_EQUATES
$INSERT SECURITY_RIGHTS_EQU

EQU CRLF$	TO \0D0A\

EQU COL$PROP_CD		TO 1
EQU COL$PROPERTY	TO 2


ErrTitle = 'Error in Comm_PRS_Layer'
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 = 'DELETE'			; GOSUB Delete
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
	
	
	CASE EntID = @WINDOW:'.LU_RECIPE' AND		Event = 'CLICK'	; GOSUB LURecipe
	CASE EntID = @WINDOW:'.LU_LAYER_TYPE' AND	Event = 'CLICK'	; GOSUB LULayerType
	
	CASE EntID = @WINDOW:'.PRS_PROP_KEY'
		BEGIN CASE
			CASE Event = 'DBLCLK'			; GOSUB PropertyDC
		
		END CASE
		
	
	CASE EntID = @WINDOW:'.NEW_PROP' AND		Event = 'CLICK'	; GOSUB NewProperty
	
	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


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

GOSUB Refresh

RETURN


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

GOTO Close

RETURN

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


GOTO Refresh

RETURN

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

obj_Appwindow('DetailReturn')

RETURN


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

Result = 0	;* Stops the DELETE event chain 

IF Security_Check('PRS_LAYER',Delete$) THEN

	PSNo		= Get_Property(@WINDOW:'.PS_NO','DEFPROP')
	LayerNo		= Get_Property(@WINDOW:'.LAYER_NO','DEFPROP')
	PropKeys	= Get_Property(@WINDOW:'.PRS_PROP_KEYS','ARRAY')
	
	LOOP
		LastChar = PropKeys[-1,1]
	UNTIL LastChar NE @VM OR PropKeys = ''
		PropKeys[-1,1] = ''
	REPEAT
	
	TestPropKeys = PropKeys
	CONVERT @VM TO '' IN TestPropKeys
	
	IF TestPropKeys  NE '' THEN
		
		MsgHead	= 'Delete Layer from System'
		MsgText	= 'Are you sure you wish to remove this layer ':PSNo:'*':LayerNo :' and all associated properties?'

		OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)

		IF OK = 1 THEN 
			Set_Status(0)
			obj_PRS_Prop('Delete',PropKeys)	;* Deletes PRS Property records
			
			IF Get_Status() THEN
				ErrMsg(errCode)		;* Check for problems deleting PRS_PROP records
				RETURN
			END ELSE
				Result = 1			;* OK to delete layer record
				
			END
		END	;* End of Yes/No message
		
	END ELSE
		IF Msg(@WINDOW,'','PRE_DELETE') THEN
			Result = 1
		END
	END ;* End of check for attached PRS_PROP records
	
END ELSE
	Security_Err_Msg('PRS_LAYER',Delete$)
END

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



RETURN

* * * * * * *
PropertyDC:
* * * * * * *

PSNo = Get_Property(@WINDOW:'.PS_NO','DEFPROP')
LayerNo	= Get_Property(@WINDOW:'.LAYER_NO','DEFPROP')

IF PSNo = '' THEN RETURN
IF LayerNo = '' THEN RETURN

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


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

	IF PropCd NE '' THEN
				
		Send_Event(@WINDOW,'WRITE')

		DetWindow	= 'PRS_PROP'
		DetKeys		= PSNo:'*':LayerNo:'*':PropCd
		DefaultRec	= ''
		RetKey		= PSNo:'*':LayerNo
		RetPage		= 1
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos

		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END

	END
END	;* End of PropCd column



RETURN



* * * * * * *
NewProperty:
* * * * * * * 

PSNo = Get_Property(@WINDOW:'.PS_NO','DEFPROP')
LayerNo	= Get_Property(@WINDOW:'.LAYER_NO','DEFPROP')

IF PSNo = '' THEN RETURN
IF LayerNo = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

DetWindow	= 'PRS_PROP'
DetKeys		= PSNo:'*':LayerNo:'*':''
DefaultRec	= ''
RetKey		= PSNo:'*':LayerNo
RetPage		= 1
RetCtrl		 = @WINDOW:'.PRS_PROP_KEY'
RetPos		= 1:@FM:1

oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

obj_AppWindow('ViewNewDetail',oAParms)
IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END


RETURN


* * * * * * *
LURecipe:
* * * * * * *

RecipeNo = Get_Property(@WINDOW:'.RECIPE','DEFPROP')

Option = Msg(@WINDOW,'','RECIPE_OPTIONS')						; * Select, Create New or Cancel


BEGIN CASE
	CASE Option = 1
		RecipeNo = Popup(@WINDOW,'','CHOOSE_RECIPE')					;* Select List
		
	CASE Option = 2
		IF RecipeNo = '' THEN
			Void = Start_Window( 'RECIPE', @WINDOW, '*Choosing', '', '' )
		END ELSE
			Void = Start_Window( 'RECIPE', @WINDOW, RecipeNo:'*CENTER', '', '' )
		END
	CASE 1
		RETURN
END CASE


IF RecipeNo NE '' THEN
	oaParms = RecipeNo:@RM:@WINDOW:'.RECIPE'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN


* * * * * * *
LULayerType:
* * * * * * *

RetVal = Popup(@WINDOW,'','LAYER_TYPE')


IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.LAYER_TYPE'
	obj_Appwindow('LUValReturn',oaParms)
END

RETURN




