DBFINVTR.MOD 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. IMPLEMENTATION MODULE DBFInvtry;
  2. (*
  3. * ModBase
  4. * Release 3.0
  5. * (c) Copyright 1986 - 1991 PMI
  6. * P.O. Box 8402
  7. * Green Bay Wi 53308
  8. * All Rights Reserved
  9. * by Ed Ross
  10. *)
  11. FROM ModBase3 IMPORT InitDBF,OpenDBF,CloseDBF,ReadDBRec,GetField,
  12. DBFile,DefaultFixUp,NilDBF;
  13. FROM DBCopier IMPORT DBPack;
  14. FROM DBIndxes IMPORT InitIndex,OpenIndex,AddToUpdateList,CloseIndex,
  15. CurrentRec,FindPositionCh,BuildIndex,GoTop,GoBottom,
  16. NextRecord,PrevRecord,CurrentKeyCh,FindPositionN,
  17. CurrentKeyN,InitCompIndex,BuildCompIndex,DBIndex;
  18. FROM Drectory IMPORT DeleteFile;
  19. FROM M2Strings IMPORT Assign;
  20. FROM StrEdit IMPORT CrunchBlanks,CAPstr,AssignStr;
  21. FROM DBStuff IMPORT MakeKey;
  22. FROM StrConv IMPORT StrToReal;
  23. FROM NumTypes IMPORT Real8,REALToReal8;
  24. FROM LowLevel IMPORT Fill;
  25. FROM SYSTEM IMPORT ADR;
  26. FROM ScanUtils IMPORT Present,CaseSens;
  27. FROM PosUtils IMPORT Equal;
  28. FROM DBFields IMPORT GetDateField,GetLogicalField,GetNumField,Replace,
  29. ReplaceD,ReplaceN,ReplaceL;
  30. CONST
  31. Buffer = 0;
  32. Safty = TRUE;
  33. Exclusive = FALSE;
  34. AutoLock = TRUE;
  35. VAR
  36. DBInit,IndexOpen : BOOLEAN;
  37. PROCEDURE MoveInvtryToDBF(Rec : InvtryRec );
  38. (* This code will move the data from the record to *)
  39. (* the data base *)
  40. BEGIN
  41. WITH Rec DO
  42. CAPstr(INVCODE); (* only caps for item code*)
  43. Replace( InvtryDBF, 1,INVCODE);
  44. ReplaceN( InvtryDBF, 2,REALToReal8(FLOAT(PRICETBL)));
  45. Replace( InvtryDBF, 3,GROUP);
  46. CAPstr(GROUP);
  47. CrunchBlanks(GROUP);
  48. Replace( InvtryDBF, 4,DESC);
  49. ReplaceN( InvtryDBF, 5,REALToReal8(FLOAT(REORDER)));
  50. ReplaceN( InvtryDBF, 6,ONHAND);
  51. ReplaceN( InvtryDBF, 7,REALToReal8(FLOAT(MINORDER)));
  52. ReplaceN( InvtryDBF, 8,PURPRICE);
  53. ReplaceL( InvtryDBF, 9,STOCKED);
  54. Replace( InvtryDBF, 10,UNITS);
  55. ReplaceD( InvtryDBF, 11,LASTPUR);
  56. ReplaceN( InvtryDBF, 12,LSTPUAMT);
  57. CAPstr(ORDERFRM);
  58. Replace( InvtryDBF, 13,ORDERFRM);
  59. ReplaceN( InvtryDBF, 14,UNITPRICE ); (* Unit price if not price table *)
  60. Replace(InvtryDBF,15,ONORDER); (* 'Y' - item is onorder *)
  61. ReplaceN(InvtryDBF,16,REORDAMT); (* normal reorder quant *)
  62. END; (* end of with REC *)
  63. END MoveInvtryToDBF;
  64. PROCEDURE MoveInvtryFromDBF(VAR Rec : InvtryRec );
  65. (* This code will move the data from the Database to *)
  66. (* the record *)
  67. VAR B : BOOLEAN;
  68. R : Real8;
  69. BEGIN
  70. WITH Rec DO
  71. GetField( InvtryDBF, 1,INVCODE );
  72. GetNumField( InvtryDBF, 2,R);
  73. PRICETBL:= TRUNC(R);
  74. GetField( InvtryDBF, 3,GROUP );
  75. GetField( InvtryDBF, 4,DESC );
  76. GetNumField( InvtryDBF, 5,R);
  77. REORDER:= TRUNC(R);
  78. GetNumField( InvtryDBF, 6,ONHAND);
  79. GetNumField( InvtryDBF, 7,R);
  80. MINORDER:= TRUNC(R);
  81. GetNumField( InvtryDBF, 8,PURPRICE);
  82. GetLogicalField( InvtryDBF, 9,STOCKED);
  83. GetField( InvtryDBF, 10,UNITS );
  84. GetDateField( InvtryDBF, 11,LASTPUR);
  85. GetNumField( InvtryDBF, 12,LSTPUAMT);
  86. GetField( InvtryDBF, 13,ORDERFRM );
  87. GetNumField( InvtryDBF, 14,UNITPRICE ); (* Unit price if not price table *)
  88. GetField(InvtryDBF,15,ONORDER );
  89. GetNumField(InvtryDBF,16,REORDAMT);
  90. END; (* end of with REC^ *)
  91. END MoveInvtryFromDBF;
  92. PROCEDURE FixInvRec();
  93. VAR Rec : InvtryRec;
  94. BEGIN
  95. MoveInvtryFromDBF(Rec);
  96. MoveInvtryToDBF(Rec);
  97. END FixInvRec;
  98. PROCEDURE MakeItemKey( DBF : DBFile; Idx : DBIndex;
  99. VAR Key : ARRAY OF CHAR);
  100. VAR B : BOOLEAN;
  101. BEGIN
  102. GetField( DBF, 1,Key );
  103. MakeKey(Key);
  104. END MakeItemKey;
  105. PROCEDURE OpenInvtryDBF(WithIdx : BOOLEAN);
  106. VAR
  107. ER : CARDINAL;
  108. BEGIN
  109. IndexOpen := WithIdx;
  110. (* Open the DBF file *)
  111. IF NOT DBInit THEN
  112. DBInit:=TRUE;
  113. InitDBF("Invtry.DBF", InvtryDBF,Buffer,Safty,Exclusive,AutoLock,DefaultFixUp );
  114. InitCompIndex( "Invcode.Idx",InvcodeIdx,InvtryDBF,MakeItemKey,Buffer,
  115. Safty,FALSE,Exclusive);
  116. AddToUpdateList( InvtryDBF, InvcodeIdx );
  117. END;
  118. IF NOT OpenDBF( InvtryDBF)
  119. THEN END;
  120. IF WithIdx THEN
  121. (* open all indexes and append to dbfile *)
  122. IF NOT OpenIndex( InvcodeIdx )
  123. THEN
  124. ER := BuildCompIndex(InvcodeIdx, 'C','Invcode',6);
  125. END;
  126. ActInvtryIdx := InvcodeIdx; (* make current index *)
  127. END; (* with index *)
  128. END OpenInvtryDBF;
  129. PROCEDURE CloseInvtryDBF (); (* close Data and index files *)
  130. BEGIN
  131. CloseDBF(InvtryDBF); (* close dbf file *)
  132. IF IndexOpen
  133. THEN
  134. CloseIndex(InvcodeIdx ); (* close index file *)
  135. END;
  136. END CloseInvtryDBF;
  137. PROCEDURE FindInvtryByInvcode( Key : ARRAY OF CHAR) : BOOLEAN;
  138. VAR Found : BOOLEAN;
  139. CKey : ARRAY[0..80] OF CHAR;
  140. L : LONGINT;
  141. BEGIN
  142. Fill(ADR(CKey),80,0);
  143. Assign(Key,CKey);
  144. CrunchBlanks(CKey);
  145. ActInvtryIdx := InvcodeIdx ; (* make this index the active idx*)
  146. FindPositionCh( InvcodeIdx, CKey, Found);
  147. ReadDBRec( InvtryDBF, CurrentRec( InvcodeIdx)); (* if found - then exact*)
  148. (* else the closest one*)
  149. RETURN Found;
  150. END FindInvtryByInvcode;
  151. PROCEDURE FindInvtryByOrderfrm( Key : ARRAY OF CHAR) : BOOLEAN;
  152. VAR Found : BOOLEAN;
  153. CKey : ARRAY[0..80] OF CHAR;
  154. BEGIN
  155. ActInvtryIdx := OrderfrmIdx ; (* make this index the active idx*)
  156. MakeKey(Key);
  157. FindPositionCh( OrderfrmIdx, Key, Found);
  158. CurrentKeyCh(OrderfrmIdx,CKey);
  159. Found := Equal(Key,CKey);
  160. IF Found
  161. THEN ReadDBRec( InvtryDBF, CurrentRec( OrderfrmIdx));
  162. END;
  163. RETURN Found;
  164. END FindInvtryByOrderfrm;
  165. PROCEDURE NextInvtry () : BOOLEAN;
  166. VAR
  167. L : LONGINT; (* record number *)
  168. BEGIN
  169. IF NextRecord( ActInvtryIdx,L)
  170. THEN ReadDBRec( InvtryDBF,L );
  171. RETURN TRUE;
  172. ELSE RETURN FALSE;
  173. END;
  174. END NextInvtry;
  175. PROCEDURE PrevInvtry () : BOOLEAN;
  176. VAR
  177. L : LONGINT; (* record number *)
  178. BEGIN
  179. IF PrevRecord( ActInvtryIdx,L)
  180. THEN ReadDBRec( InvtryDBF,L );
  181. RETURN TRUE;
  182. ELSE RETURN FALSE;
  183. END;
  184. END PrevInvtry;
  185. PROCEDURE FirstInvtry ();
  186. VAR
  187. L : LONGINT; (* record number *)
  188. BEGIN
  189. GoTop(ActInvtryIdx);
  190. ReadDBRec( InvtryDBF,CurrentRec( ActInvtryIdx));
  191. END FirstInvtry;
  192. PROCEDURE LastInvtry ();
  193. VAR
  194. L : LONGINT; (* record number *)
  195. BEGIN
  196. GoBottom(ActInvtryIdx);
  197. ReadDBRec( InvtryDBF,CurrentRec( ActInvtryIdx));
  198. END LastInvtry;
  199. PROCEDURE PackInvtry();
  200. VAR
  201. EM : CARDINAL;
  202. BEGIN
  203. CloseInvtryDBF();
  204. OpenInvtryDBF(FALSE);
  205. DBPack(InvtryDBF);
  206. CloseDBF(InvtryDBF);
  207. EM := DeleteFile("Invcode.Idx");
  208. EM := DeleteFile("Orderfrm.Idx");
  209. OpenInvtryDBF(TRUE); (* open & rebuild the index *)
  210. CloseInvtryDBF();
  211. END PackInvtry;
  212. BEGIN
  213. NilDBF(InvtryDBF);
  214. IndexOpen := FALSE;
  215. DBInit:=FALSE;
  216. END DBFInvtry.
  217.