IMPLEMENTATION MODULE DBFSalesrec; (* * ModBase * Release 3.0 * (c) Copyright 1986 - 1991 PMI * P.O. Box 8402 * Green Bay Wi 53308 * All Rights Reserved * by Ed Ross *) FROM ModBase3 IMPORT InitDBF,OpenDBF,CloseDBF,ReadDBRec,GetField,DBFile, DeleteRecord,DefaultFixUp,NilDBF,PosOfField; FROM DBCopier IMPORT DBPack; FROM DBIndxes IMPORT InitIndex,OpenIndex,AddToUpdateList,CloseIndex, CurrentRec,FindPositionCh,BuildIndex,GoTop,GoBottom, NextRecord,PrevRecord,CurrentKeyCh,FindPositionN, CurrentKeyN,InitCompIndex,BuildCompIndex,DBIndex; FROM StrEdit IMPORT CrunchBlanks; FROM DBStuff IMPORT MakeKey; FROM Drectory IMPORT DeleteFile; FROM StrConv IMPORT StrToReal; FROM NumTypes IMPORT Real8; FROM ScanUtils IMPORT Present,CaseSens; FROM DBFields IMPORT GetDateField,GetLogicalField,GetNumField,Replace, ReplaceD,ReplaceN; CONST Buffer = 0; Safty = TRUE; Exclusive = FALSE; AutoLock = TRUE; KeepDeleted = FALSE; VAR DBInit,IndexOpen : BOOLEAN; PROCEDURE MoveSalesrecToDBF(Rec : SalesRec ); (* This code will move the data from the record to *) (* the data base *) BEGIN WITH Rec DO Replace( SalesrecDBF, 1,ITEMNBR); (* Item number *) ReplaceN( SalesrecDBF, 2,Sold[1] ); (* number of units sold in January *) ReplaceN( SalesrecDBF, 3,Sold[2] ); (* Feb *) ReplaceN( SalesrecDBF, 4,Sold[3] ); (* Mar *) ReplaceN( SalesrecDBF, 5,Sold[4] ); (* *) ReplaceN( SalesrecDBF, 6,Sold[5] ); (* *) ReplaceN( SalesrecDBF, 7,Sold[6] ); (* *) ReplaceN( SalesrecDBF, 8,Sold[7] ); (* *) ReplaceN( SalesrecDBF, 9,Sold[8] ); (* *) ReplaceN( SalesrecDBF, 10,Sold[9] ); (* *) ReplaceN( SalesrecDBF, 11,Sold[10] ); (* *) ReplaceN( SalesrecDBF, 12,Sold[11] ); (* *) ReplaceN( SalesrecDBF, 13,Sold[12] ); (* *) END; (* end of with REC *) END MoveSalesrecToDBF; PROCEDURE MoveSalesrecFromDBF(VAR Rec : SalesRec ); (* This code will move the data from the Database to *) (* the record *) VAR B : BOOLEAN; R : Real8; BEGIN WITH Rec DO GetField( SalesrecDBF, 1,ITEMNBR); (* Item number *) GetNumField( SalesrecDBF, 2,Sold[1] ); (* number of units Sold in January *) GetNumField( SalesrecDBF, 3,Sold[2] ); (* Feb *) GetNumField( SalesrecDBF, 4,Sold[3] ); (* Mar *) GetNumField( SalesrecDBF, 5,Sold[4] ); (* *) GetNumField( SalesrecDBF, 6,Sold[5] ); (* *) GetNumField( SalesrecDBF, 7,Sold[6] ); (* *) GetNumField( SalesrecDBF, 8,Sold[7] ); (* *) GetNumField( SalesrecDBF, 9,Sold[8] ); (* *) GetNumField( SalesrecDBF, 10,Sold[9] ); (* *) GetNumField( SalesrecDBF, 11,Sold[10] ); (* *) GetNumField( SalesrecDBF, 12,Sold[11] ); (* *) GetNumField( SalesrecDBF, 13,Sold[12] ); (* *) END; (* end of with REC^ *) END MoveSalesrecFromDBF; PROCEDURE MakeItemnbrKey( DBF : DBFile; Idx : DBIndex; VAR Key : ARRAY OF CHAR); VAR B : BOOLEAN; FldNum : CARDINAL; BEGIN (* this routine doesn't alwasy work - may need to replace with getfiled*) (* FldNum := PosOfField(DBF,'Itemnbr');*) GetField(DBF,1,Key); MakeKey(Key); END MakeItemnbrKey; PROCEDURE OpenSalesrecDBF(WithIdx : BOOLEAN); VAR ER : CARDINAL; BEGIN IndexOpen := WithIdx; (* Open the DBF file *) IF NOT DBInit THEN DBInit:=TRUE; InitDBF("Salesrec.DBF", SalesrecDBF,Buffer,Safty,Exclusive, AutoLock,DefaultFixUp ); InitCompIndex( "Itemnbr.Idx",SalesRecIdx,SalesrecDBF,MakeItemnbrKey,Buffer, Safty, KeepDeleted,Exclusive); AddToUpdateList( SalesrecDBF, SalesRecIdx ); END; IF NOT OpenDBF( SalesrecDBF) THEN END; (* open all indexes and append to dbfile *) IF WithIdx THEN IF NOT OpenIndex( SalesRecIdx ) THEN ER := BuildCompIndex(SalesRecIdx,'C','Itemnbr',40); (* check key lenght *) END; ActSalesrecIdx := SalesRecIdx; (* make current index *) END; (* end with indext *) END OpenSalesrecDBF; PROCEDURE CloseSalesrecDBF (); (* close Data and index files *) BEGIN CloseDBF(SalesrecDBF); (* close dbf file *) IF IndexOpen THEN CloseIndex(SalesRecIdx ); (* close index file *) END; (* end index open*) END CloseSalesrecDBF; PROCEDURE FindSalesrecByItemnbr( Key : ARRAY OF CHAR) : BOOLEAN; VAR Found : BOOLEAN; CKey : ARRAY[0..80] OF CHAR; BEGIN ActSalesrecIdx := SalesRecIdx ; (* make this index the active idx*) FindPositionCh( SalesRecIdx, Key, Found); CurrentKeyCh(SalesRecIdx,CKey); Found := Present(Key,CKey,CaseSens); IF Found THEN ReadDBRec( SalesrecDBF, CurrentRec( SalesRecIdx)); END; RETURN Found; END FindSalesrecByItemnbr; PROCEDURE NextSalesrec () : BOOLEAN; VAR L : LONGINT; (* record number *) BEGIN IF NextRecord( ActSalesrecIdx,L) THEN ReadDBRec( SalesrecDBF,L ); RETURN TRUE; ELSE RETURN FALSE; END; END NextSalesrec; PROCEDURE PrevSalesrec () : BOOLEAN; VAR L : LONGINT; (* record number *) BEGIN IF PrevRecord( ActSalesrecIdx,L) THEN ReadDBRec( SalesrecDBF,L ); RETURN TRUE; ELSE RETURN FALSE; END; END PrevSalesrec; PROCEDURE FirstSalesrec (); VAR L : LONGINT; (* record number *) BEGIN GoTop(ActSalesrecIdx); ReadDBRec( SalesrecDBF,CurrentRec( ActSalesrecIdx)); END FirstSalesrec; PROCEDURE LastSalesrec (); VAR L : LONGINT; (* record number *) BEGIN GoBottom(ActSalesrecIdx); ReadDBRec( SalesrecDBF,CurrentRec( ActSalesrecIdx)); END LastSalesrec; PROCEDURE PackSalesrec(); VAR EM : CARDINAL; LI : LONGINT; Tmp : SalesRec; BEGIN CloseSalesrecDBF(); OpenSalesrecDBF(FALSE); (* open with no index *) DBPack(SalesrecDBF); CloseSalesrecDBF(); EM := DeleteFile('Itemnbr'); OpenSalesrecDBF(TRUE); (* open to rebuild the indexes*) CloseSalesrecDBF(); END PackSalesrec; (* initialization code *) BEGIN NilDBF(SalesrecDBF); IndexOpen := FALSE; DBInit:=FALSE; END DBFSalesrec.