*:
*: MAINWIN.DFT - dBFast Main Window Template File
*:
*:     Project: <<PROJECT_NAME>>
*:
*:     Program: <<PROG_NAME>>
*: Description: <<DESC>>
*:      Author: <<AUTHOR>>
*:    Copyright <<COPYRITE>>
*:

<<DO WHILE DLLS>>
<<DECLARE_DLL>>
<<ENDDO>>

SET PROCEDURE TO <<PROG_NAME>>
SET PROCEDURE TO <<LIBRARY>>

<<DO WHILE PROC_LIBS>>
SET PROCEDURE TO <<PROC_LIB>> && Set user procedure file
<<ENDDO>>
<<PROC_VALIDS>>


SET DELETED ON
SET CONFIRM ON

SET EVENTMSK TO 143

SET READ VIDEO TO 240

<<SCREEN_COLOR>>

<<SET_FONTS>>

IF .NOT. EMPTY("<<TITLE>>")
  SET WINDOW TITLE TO "<<TITLE>>"
ENDIF

SET CURSOR TO WAIT


PRIVATE sMenuName, sAction, lOpenDBF
STORE 0  TO nTheMenu, nTheOption, nTheKey
STORE '' TO sTheWindow, sTheButton, sMenuName, sAction
STORE .T. TO lOpenDBF
<<MEM_VARS>>

<<DECLARE_DBF_ARRAY>>

DO <<PROG_NAME>>_DBFSetup

<<DO BEFORE>>

<<DO WHILE POPUPS>>
<<CREATE POPUP>>
<<ENDDO>>

<<CREATE PULLDOWN>>

<<SET_MENU>>

<<MENU_STATES>>

DO <<PROG_NAME>>_SetUp

*: Init sAction to something so it is not empty
sAction = '?'

SET CURSOR TO ARROW

DO WHILE .NOT. EMPTY(sAction)

  DO <<PROG_NAME>>_Calcs
  
  UPDATE CONTROL ALL
  UPDATE GETS

  READ SAVE
  
  nEvent     = Event()
  nTheRow    = MROW()
  nTheCol    = MCOL()
  nTheMenu   = HMENU()
  nTheOption = VMENU()
  nTheKey    = LASTKEY()
  sTheButton = BUTTON()
  
  sAction = <<PROG_NAME>>_Translate(nEvent)
  DO <<PROG_NAME>>_Action
ENDDO

sAction = '?'

<<DO AFTER>>

<<CLOSE_MENU>> 

RETURN


*****************************
FUNCTION <<PROG_NAME>>_Translate()
*****************************
PARAMETER nTheEvent
PRIVATE sTheAction

  sTheAction = ' '
  DO CASE
	 CASE nTheEvent = eClose
		sTheAction = 'CLOSE'

<<IF KEYS>>
	 CASE nTheEvent = eKybd
		DO CASE
  <<DO WHILE KEYS>>
		  CASE ExactMatch(nTheKey, <<THE_KEY>>)
			 sTheAction = '<<THE_NAME>>'
  <<ENDDO>>
		ENDCASE
<<ENDIF>>

<<IF BUTTONS>>
	 CASE nTheEvent = eButton
		DO CASE
  <<DO WHILE BUTTONS>>
		  CASE ExactMatch(sTheButton, '<<THE_NAME>>')
			 sTheAction = '<<THE_NAME>>'
  <<ENDDO>>
		ENDCASE
<<ENDIF>>

<<IF MENUS>>
	 CASE nTheEvent = eMenu
		DO CASE
  <<DO WHILE MENUS>>
		  CASE ExactMatch(nTheMenu, <<THE_MENU>>)
			 DO CASE
	 <<DO WHILE OPTIONS>>
				CASE ExactMatch(nTheOption, <<THE_OPTION>>)
				  sTheAction = '<<THE_NAME>>'
	 <<ENDDO>>
	 			OTHERWISE
				  sTheAction = '?'
			 ENDCASE
  <<ENDDO>>
		ENDCASE
<<ENDIF>>

	 OTHERWISE
		sTheAction = '?'
  ENDCASE

RETURN(sTheAction)


*************************
PROCEDURE <<PROG_NAME>>_Action
*************************

  DO CASE
	 CASE sAction = 'CLOSE'
		sAction = ''

<<DO WHILE ACTIONS>>
	 CASE ExactMatch(sAction, '<<THE_NAME>>')
		<<DO ACTION>>
<<ENDDO>>
  ENDCASE
RETURN

*************************
PROCEDURE <<PROG_NAME>>_DBFSetup
*************************

<<DO WHILE DATAFILES>>
IF FILE("<<DATAFILE>>.DBF")
  FileOpen("<<DATAFILE>>", lOpenDBF)  
  <<IF INDEXES>>
  SET INDEX TO <<INDEXES>>
  <<ENDIF>>
  <<IF FIELDLIST>>
  SET FIELDS TO <<FIELDLIST>>
  SET FIELDS ON
  <<ENDIF>>
  <<IF FILTER>>
  SET FILTER TO <<FILTER>>
  <<ENDIF>>
ELSE
  WARNING(csNoDataFile,"<<DATAFILE>>",387)
  CLOSE WINDOW '<<PROG_NAME>>'
  RETURN
ENDIF
<<ENDDO>>

<<DO WHILE RELATIONS>>
SELECT <<REL_FROM>>
<<DO WHILE LINKS>>
  SET RELATION TO <<REL_EXP>> INTO <<REL_TO>>
<<ENDDO>>
<<ENDDO>>

STORE .F. TO lOpenDBF
RETURN


*************************
PROCEDURE <<PROG_NAME>>_SetUp
*************************

<<DO WHILE CONTROLS>>
<<CREATE CONTROL>>
<<ENDDO>>
RETURN


*************************
PROCEDURE <<PROG_NAME>>_Calcs
*************************

<<DO WHILE CALC_FIELDS>>
  <<CREATE CALC_FIELD>>
<<ENDDO>>
RETURN


*************************
FUNCTION <<PROG_NAME>>_ValidCalcs
*************************
PARAMETERS sVar1, sVar2

<<IF VALID_CALCS>>
DO CASE
<<DO WHILE VALID_CALCS>>
	CASE sVar2 = <<VALID_CAL>>
		REPLACE <<VALID_CALC>> WITH sVar2	
<<ENDDO>>
ENDCASE
<<ENDIF>>
RETURN(.T.)


*************************
FUNCTION ExactMatch()
*************************
PARAMETERS sVar1, sVar2

	lReturn = .F.
	SET EXACT ON
	lReturn = (sVar1 = sVar2)
	SET EXACT OFF
RETURN(lReturn)

