COMPILE FUNCTION Recipe_Comm(Instruction,Parm1,Parm2)

$INSERT RECIPE_EQUATES
$INSERT RECIPE_LAYER_INFO_EQU
$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT DICT_EQUATES

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

DECLARE FUNCTION memberof, scroll_enable, utility, popup
DECLARE FUNCTION set_property, fieldcount, get_property, msg, editcell, send_event, dialog_box
DECLARE SUBROUTINE create_note, ErrMsg, Set_Property


ReturnVar = 0


BEGIN CASE
	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 Instruction = 'TabClick'				; GOSUB TabClick
	CASE 1
		ErrMsg('Unknown Instruction ':QUOTE(Instruction):' passed to Recipe_Comm')
		
END CASE

RETURN ReturnVar

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

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

Set_Property(@WINDOW,'VPOSITION',Page)


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

Void = set_property( @window:'.':FieldCToUse, 'TEXT', FieldsInControl )
Void = set_property( @window:'.':IDCToUse, 'TEXT', IDSInControl )
Void = set_property( @window, '@Fields', '' )	
Void = 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 
 
Void = set_property( @window, '@Fields', Fields )	
Void = set_property( @window, '@Values', Values )

RETURN

