* RESTORE.CMD
* M. Lynn
* Version 1.6
STORE T TO ok
STORE '80' TO myear
IF file = '1'
STORE 'PER' TO macc
ELSE
STORE 'BUS' TO macc
ENDIF

DO WHILE OK
@ 16, 3 SAY 'For what year would you like to restore the archived entries in'
@ 17, 3 SAY 'the '+maccount+' Checkbook'
@ 18, 3 SAY 'Enter 00 to abort this command ---- ' GET myear PICTURE '99'
READ
@ 16, 0 SAY '|                                                                 |'
@ 17, 0 SAY '|                                                                 |'
@ 18, 0 SAY '|                                                                 |'

	IF myear = '00'
	RELEASE ok, macc, myear, go, drive, dbf, try, del
	RETURN
	ELSE
	LOCATE FOR $(date,7,2) = myear
		IF .NOT. EOF
		@ 16, 3 SAY '*** WARNING - there are already entries in '+maccount+' for the'
		@ 17, 3 SAY 'year '+myear+' -- these new records will be added to the database'
		@ 18, 3 SAY 'and could result in duplicated entries if any are the same as'
		@ 19, 3 SAY 'the entries in the archived database.'
		@ 20, 3 SAY 'Do you wish to continue? (Y/N)'
		SET CONSOLE OFF
		WAIT TO go
		SET CONSOLE ON
		@ 16, 0 SAY '|                                                                 |'
		@ 17, 0 SAY '|                                                                 |'
		@ 18, 0 SAY '|                                                                 |'
		@ 19, 0 SAY '|                                                                 |'
		@ 20, 0 SAY '|                                                                 |'

			IF !(go) # 'Y'
			RELEASE ok, macc, myear, go, drive, dbf, try, del
			RETURN
			ENDIF
		ENDIF
	ENDIF

@ 16, 3 SAY 'Enter a single letter for the drive containing the'
@ 17, 3 SAY 'archived database: '
SET CONSOLE OFF
WAIT TO drive
SET CONSOLE ON
@ 16, 0 SAY '|                                                                 |'
@ 17, 0 SAY '|                                                                 |'

	DO CASE

	CASE !(drive) = 'A'

	CASE !(drive) = 'B'
	IF maxdrive < 2
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'C'
	IF maxdrive < 3
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'D'
	IF maxdrive < 4
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	CASE !(drive) = 'E'
	IF maxdrive < 5
	@ 16, 3 SAY 'That is an ilegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
	ENDIF

	OTHERWISE
	@ 16, 3 SAY 'That is an illegal drive'
	@ 18, 3 SAY 'Enter any character to try again'
	SET CONSOLE OFF
	WAIT
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 18, 0 SAY '|                                                                 |'
	LOOP
ENDCASE

STORE drive+':'+myear+macc TO dbf

	IF FILE (dbf)
	@ 16, 3 SAY 'File '+dbf+' located--'
	@ 17, 3 SAY 'Appending to '+maccount+'.dbf'
	ELSE
	@ 16, 3 SAY 'FILE '+dbf+' NOT FOUND'
	@ 17, 3 SAY 'Enter a Y to try again'
	SET CONSOLE OFF
	WAIT TO try
	SET CONSOLE ON
	@ 16, 0 SAY '|                                                                 |'
	@ 17, 0 SAY '|                                                                 |'

		IF !(try) = 'Y'
		LOOP
		ELSE
		RELEASE ok, macc, myear, go, drive, dbf, try, del
		RETURN
		ENDIF
	ENDIF 
@ 16, 0 SAY '|                                                                 |'

USE &maccount
APPEND FROM &dbf FOR $(date,7,2) = myear

	IF file = '1'
	@ 16, 3 SAY 're-indexing PERSONAL.DBF on the memo field'
	INDEX ON MEMO TO PERSONAL
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 're-indexing PERSONAL.DBF on the number field'
	INDEX ON NUMBER TO INDPERNO
	ELSE
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 're-indexing BUSINESS.DBF on the memo field'
	INDEX ON MEMO TO BUSINESS
	@ 16, 0 SAY '|                                                                 |'
	@ 16, 3 SAY 're-indexing the BUSINESS.DBF on the number field'
	INDEX ON NUMBER TO INDBUSNO
	ENDIF
@ 16, 0 SAY '|                                                                 |'
@ 16, 3 SAY 'Do you wish to delete the archive file '+dbf+' (Y/N)'
SET CONSOLE OFF
WAIT TO del
SET CONSOLE ON
@ 16, 0 SAY '|                                                                 |'

	IF !(del) = 'Y'
	DELETE FILE &dbf
	ENDIF

STORE F TO ok	
ENDDO # ok
RELEASE ok, macc, myear, go, drive, dbf, try, del
RETURN
el) = 'Y'
	DELETE FILE &dbf
	ENDIF

STORE F TO ok	
ENDDO # ok
RELEASE 