COMPILE FUNCTION Comm_Recipe(Instruction,Parm1,Parm2)


EQU CRLF$ TO CHAR(13):CHAR(10)

DECLARE FUNCTION MemberOf, Utility, Popup, Send_Message
DECLARE FUNCTION Fieldcount, Get_Property, Msg, Send_Event, Dialog_Box
DECLARE SUBROUTINE Create_Note, ErrMsg, Set_Property


$INSERT RECIPE_EQU
$INSERT RECIPE_LAYER_INFO_EQU
$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT DICT_EQUATES

EQU CR$ TO CHAR(13)

ReturnVar = 0

BEGIN CASE
	CASE Instruction = 'Create'					; GOSUB Create
	CASE Instruction = 'TabClick'				; GOSUB TabClick
	CASE Instruction = 'VScroll'				; GOSUB VScroll
	CASE Instruction = 'GET_FIELDS_VALUES'		; GOSUB GET_FIELDS_VALUES
	CASE Instruction = 'VIEW_MOD_INFO'			; GOSUB VIEW_MOD_INFO
	CASE Instruction = 'WRITE_STAMP'			; GOSUB WRITE_STAMP
	CASE Instruction = 'READ_STORE'				; GOSUB READ_STORE
	
	CASE 1
		ErrMsg('Unknown Instruction ':QUOTE(Instruction):' passed to Recipe_Comm')
		
END CASE

RETURN ReturnVar


* * * * * * *
Create:
* * * * * * *


CtrlEntID = @WINDOW:".LIMIT_INFO"

* Set the column header for column 1 to multi-line

if (MemberOf(@USER4,'EXPORT_CONTROL_ADMINS')) then
    Set_Property(@WINDOW:'.EXPORT_CONTROL','VISIBLE',1)
end else
    Set_Property(@WINDOW:'.EXPORT_CONTROL','VISIBLE',0)
end

HeaderText = Get_Property(CtrlEntID,'LABEL')

FOR N = 2 TO 35

	ColStyle = Send_Message(CtrlEntID, "COLSTYLE", N)
	ColStyle = BitOr(ColStyle,262144) 
	ColStyle = Send_Message(CtrlEntID, "COLSTYLE", N, ColStyle)

	BEGIN CASE
		CASE N = 2	; HeaderText<N> = 'Deposit':CR$:'Time':CR$:'Min'
		CASE N = 3	; HeaderText<N> = 'Deposit':CR$:'Time':CR$:'Max'
		CASE N = 4	; HeaderText<N> = 'Diluent':CR$:'Min'
		CASE N = 5	; HeaderText<N> = 'Diluent':CR$:'Max'
		CASE N = 6	; HeaderText<N> = 'Dopant':CR$:'Flow':CR$:'Min'
		CASE N = 7	; HeaderText<N> = 'Dopant':CR$:'Flow':CR$:'Max'
		CASE N = 8	; HeaderText<N> = 'HCL':CR$:'Flow':CR$:'Min'
		CASE N = 9	; HeaderText<N> = 'HCL':CR$:'Flow':CR$:'Max'
		CASE N = 10	; HeaderText<N> = 'Bake':CR$:'Time':CR$:'Min'
		CASE N = 11	; HeaderText<N> = 'Bake':CR$:'Time':CR$:'Max'
		CASE N = 12	; HeaderText<N> = 'H2':CR$:'Flow':CR$:'Min'
		CASE N = 13	; HeaderText<N> = 'H2':CR$:'Flow':CR$:'Max'
		CASE N = 14	; HeaderText<N> = 'TCS':CR$:'Flow':CR$:'Min'
		CASE N = 15	; HeaderText<N> = 'TCS':CR$:'Flow':CR$:'Max'
		CASE N = 16	; HeaderText<N> = 'DCS':CR$:'Flow':CR$:'Min'
		CASE N = 17	; HeaderText<N> = 'DCS':CR$:'Flow':CR$:'Max'
		CASE N = 18	; HeaderText<N> = 'Aux 1':CR$:'Min'
		CASE N = 19	; HeaderText<N> = 'Aux 1':CR$:'Max'
		CASE N = 20	; HeaderText<N> = 'Aux 2':CR$:'Min'
		CASE N = 21	; HeaderText<N> = 'Aux 2':CR$:'Max'
		CASE N = 22	; HeaderText<N> = 'Front':CR$:'OffSet':CR$:'Min'
		CASE N = 23	; HeaderText<N> = 'Front':CR$:'OffSet':CR$:'Max'
		CASE N = 24	; HeaderText<N> = 'Side':CR$:'OffSet':CR$:'Min'
		CASE N = 25	; HeaderText<N> = 'Side':CR$:'OffSet':CR$:'Max'
		CASE N = 26	; HeaderText<N> = 'Rear':CR$:'OffSet':CR$:'Min'
		CASE N = 27	; HeaderText<N> = 'Rear':CR$:'OffSet':CR$:'Max'
		CASE N = 28	; HeaderText<N> = 'Susc':CR$:'Etch':CR$:'Min'
		CASE N = 29	; HeaderText<N> = 'Susc':CR$:'Etch':CR$:'Max'
		CASE N = 30	; HeaderText<N> = 'Etch 1':CR$:'Min'
		CASE N = 31	; HeaderText<N> = 'Etch 1':CR$:'Max'
		CASE N = 32	; HeaderText<N> = 'Etch 2':CR$:'Min'
		CASE N = 33	; HeaderText<N> = 'Etch 2':CR$:'Max'
		CASE N = 34 ; HeaderText<N> = 'Etch 3':CR$:'Min'
		CASE N = 35 ; HeaderText<N> = 'Etch 3':CR$:'Max'
		CASE N = 36	; HeaderText<N> = 'UL Temp':CR$:'Min'
		CASE N = 37	; HeaderText<N> = 'UL Temp':CR$:'Max'
		
	END CASE
NEXT N

* Set the height of the column headers for the edittable

Set_Property(CtrlEntID,'HEADERHEIGHT',40)
Set_Property(CtrlEntID,'LABEL',HeaderText)

 


RETURN


* * * * * * *
TabClick:
* * * * * * *

IF Parm1 NE '' THEN
	Page = Parm1
END ELSE
	Page = Get_Property(@WINDOW:'.TABCONTROL','VALUE')
END

Set_Property(@WINDOW,'VPOSITION',Page)

RETURN


* * * * * * *
VScroll:
* * * * * * *

Set_Property(@WINDOW:'.TABCONTROL','VALUE', Parm1)

RETURN


* * * * * * *
WRITE_STAMP:
* * * * * * *

* GET ARRAY OF ALL UNIQUE FIELDS

OrigFields = get_property( @WINDOW, '@Fields' )
OrigValues = get_property( @WINDOW, '@Values' )
FieldCToUse = 'RMOD_FIELD'
IDCToUse    = 'RMOD_ID'

FieldsInControl = get_property( @WINDOW:'.':FieldCToUse, 'TEXT' )
IDSInControl    = get_property( @WINDOW:'.':IDCToUse, 'TEXT' )
 
gosub get_fields_values

Acnt = fieldcount( OrigFields, @fm )

FOR I = 1 TO Acnt
	FieldToCheck = OrigFields<i>
	IF Values<i> <> OrigValues<i> THEN
		LOCATE FieldToCheck IN FieldsInControl BY 'AL' USING @VM SETTING CPos THEN
			IDSInControl<1,CPos> = @USER4         	
		END ELSE
			FieldsInControl = insert( FieldsInControl, 1, CPos, 0, FieldToCheck )
			IDSInControl    = insert( IDSInControl, 1, CPos, 0, @user4 )
		END 
	END	            
NEXT I

Set_Property( @WINDOW:'.':FieldCToUse, 'TEXT', FieldsInControl )
Set_Property( @WINDOW:'.':IDCToUse, 'TEXT', IDSInControl )
Set_Property( @WINDOW, '@Fields', '' )	
Set_Property( @WINDOW, '@Values', '' )

RETURN


* * * * * * *
GET_FIELDS_VALUES:
* * * * * * *

* Called on read event of recipe

Fields = ''
Values = ''

AllControls = Utility( 'OBJECTLIST', @WINDOW, '' )
Acnt = FIELDCOUNT( AllControls, @FM )

FOR I = 1 TO Acnt
   ThisControl = AllControls<i>
   Type = get_property( ThisControl, 'TYPE' )
   Column = get_property( ThisControl, 'COLUMN' )
   
   IF Type = 'EDITTABLE' OR Type = 'EDITFIELD' OR Type = 'EDITBOX' OR Type = 'COMBOBOX' THEN
       
      CCnt = FIELDCOUNT( Column, @svm )
        FOR J = 1 TO CCnt
           ThisColumn = Column<1,1,J>
           IF ThisColumn <> '' THEN
            LOCATE ThisColumn IN Fields BY 'AL' USING @FM SETTING Fpos ELSE
               Fields = INSERT( Fields, Fpos, 0, 0, ThisColumn )
	            IF Type = 'EDITTABLE' THEN
	               Values = INSERT( Values, FPos, 0, 0, Get_Property( ThisControl, 'ARRAY' )<J> )	;* We need to pull it off the array
	            END ELSE
	               Values = INSERT( Values, FPos, 0, 0, Get_Property( ThisControl, 'TEXT' ) )		;* Use the text value
	            END
            END
         END
        NEXT J
   END
NEXT I
	
RETURN


* * * * * * *
VIEW_MOD_INFO:
* * * * * * *

FieldCToUse = 'RMOD_FIELD'
IDCToUse    = 'RMOD_ID'

PopupDisplay = ''
FieldsInControl = get_property( @WINDOW:'.':FieldCToUse, 'TEXT' )
IDSInControl    = get_property( @WINDOW:'.':IDCToUse, 'TEXT' )

Fcnt = fieldcount( FieldsInControl, @vm )

FOR I = 1 TO Fcnt
	TLabel = xlate( 'DICT.RECIPE', FieldsInControl<1,i>, DICT_DISPLAY$, 'X' )
	convert @vm to ' ' in TLabel ;* DON'T WANT MULTI LINED HEADING 
	PopupDisplay<1,-1> = TLabel:@tm:oconv( IDSInControl<1,i>, '[XLATE_CONV,LSL_USERS*FIRST_LAST]' )
NEXT I

OverRide = ''
OverRide<PDISPLAY$> = PopupDisplay
OverRide<PTITLE$> = 'Recipe Modification History View'
Void = Popup( @WINDOW, OverRide, 'RDS_MOD_HIST_VIEW' )

RETURN


* * * * * * *
READ_STORE:
* * * * * * *

* GET ARRAY OF ALL UNIQUE FIELDS
   
GOSUB GET_FIELDS_VALUES 
 
Set_Property( @WINDOW, '@Fields', Fields )	
Set_Property( @WINDOW, '@Values', Values )

RETURN

