home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / INVTORY.ZIP / INVTORY.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1986-02-19  |  30.1 KB  |  978 lines

  1.  
  2. program Inventory;  (* INVTORY *)
  3. (*$A+,B+,C-,R-,V-*)
  4.  
  5. (****************************************************************)
  6. (*                                                              *)
  7. (*                  TURBO-access version 1.00                   *)
  8. (*                                                              *)
  9. (*                       INVENTORY PROGRAM                      *)
  10. (*                                                              *)
  11. (*                       Donald E. Palmer                       *)
  12. (*                                                              *)
  13. (*                       (V1.1 25 MAR 85)                       *)
  14. (****************************************************************)
  15. label Stop;
  16.  
  17. const
  18.  
  19. (*  data record Size definition *)
  20.   ItemRecSize  =  79;        (*  item record Size *)
  21.  
  22. (*  TURBO-access constants *)
  23.   MaxDataRecSize  =  ItemRecSize;   (*  max record Size *)
  24.   MaxKeyLen       =  30;            (*  max key Size *)
  25.   PageSize        =  16;            (*  page Size *)
  26.   Order           =  8;             (*  half page Size *)
  27.   PageStackSize   =  6;             (*  page buffer Size *)
  28.   MaxHeight       =  6;             (*  max B-tree height *)
  29.  
  30.  
  31. var
  32.   I             : Integer;
  33.   NoOfRecs      : Integer;
  34.   Quanity       : Integer;
  35.   ValPres       : Real;
  36.   ValTotal      : Real;
  37.   CostOrg       : Real;
  38.   Result        : Integer;
  39.   Title         : string[32];
  40.   StoreFil      : string[9];
  41.   FileD,FileC,
  42.     FileN       : string[9];
  43.  
  44. (*  include TURBO-access modules *)
  45.  
  46. (*$I ACCESS.BOX*)
  47. (*$I GETKEY.BOX*)
  48. (*$I ADDKEY.BOX*)
  49. (*$I DELKEY.BOX*)
  50.  
  51. type
  52.   Str2    =  string[2];
  53.   Str3    =  string[3];
  54.   Str6    =  string[6];
  55.   Str8    =  string[8];
  56.   Str9    =  string[9];
  57.   Str15   =  string[15];
  58.   Str30   =  string[30];
  59.   Str32   =  string[32];
  60.   Str80   =  string[80];
  61.   AnyStr  =  string[255];
  62.  
  63. (*  character set type *)
  64.   CharSet=  set of Char;
  65.  
  66. (*  customer record definition *)
  67.  
  68.   ItemRec = record
  69.               ItemStatus : Integer;       (*  ItemStatus *)
  70.               TypeCode   : string[2];     (*  type code *)
  71.               Name       : string[15];    (*  first name of item *)
  72.               AddName    : string[15];    (*  additional item info *)
  73.               Qty        : string[3];     (*  Quanity       *)
  74.               Location   : string[2];     (*  Item Location *)
  75.               DateObt    : string[6];     (*  Date Obtained *)
  76.               OrgCost    : string[8];     (*  Original cost *)
  77.               PresValue  : string[8];     (*  Present Value *)
  78.               TotalValue : string[9];     (*  PresValue*Qty *)
  79.             end;
  80.  
  81. var
  82.  
  83. (*  global variables *)
  84.   InvF          : DataFile;
  85.   CodeIndexFile,
  86.   NameIndexFile : IndexFile;
  87.   Ch            : Char;
  88.  
  89. (**********************************************)
  90. (*  UpcaseStr converts a string to upper case *)
  91. (*    calls: UpcaseStr   called by: UpcaseStr *)
  92. (*                           Main,KeyFromName *)
  93. (**********************************************)
  94. function UpcaseStr(S : Str80) : Str80;
  95. var
  96.   P : Integer;
  97. begin
  98.   for P := 1 to Length(S) do
  99.     S[P] := Upcase(S[P]);
  100.   UpcaseStr := S;
  101. end;
  102.  
  103. (***********************************************************)
  104. (*  ConstStr returns a string with N characters of value C *)
  105. (*    calls: Conststr    called by: InputStr, ConstStr,    *)
  106. (*                                              Main       *)
  107. (***********************************************************)
  108. function ConstStr(C : Char; N : Integer) : Str80;
  109. var
  110.   S : string[80];
  111. begin
  112.   if N < 0 then 
  113.     N := 0; 
  114.   S[0] := Chr(N); 
  115.   FillChar(S[1],N,C);
  116.   ConstStr := S;
  117. end;
  118. (***********************************************************)
  119. (*  Beep sounds the terminal bell or beeper                *)
  120. (*     calls:none      called by: Find,Select,InputStr     *)
  121. (***********************************************************)
  122. procedure Beep;
  123. begin
  124.   Write(^G);
  125. end;
  126.  
  127. (***********************************************************)
  128. (* Inputs Item from screen/keyboard                        *)
  129. (*    calls: Beep,ConstStr   called by:InputItem,Find      *)
  130. (***********************************************************)
  131. procedure InputStr(var S     : AnyStr;
  132.                        L,X,Y : Integer;
  133.                        Term  : CharSet;
  134.                    var TC    : Char    );
  135. const
  136.   UnderScore  =  '_';
  137. var
  138.   P : Integer;
  139.   Ch : Char;
  140. begin
  141.   GotoXY(X + 1,Y + 1); Write(S,ConstStr(UnderScore,L - Length(S)));
  142.   P := 0;
  143.   repeat
  144.     GotoXY(X + P + 1,Y + 1); Read(Kbd,Ch);
  145.     case Ch of
  146.       #32..#126 : if P < L then
  147.                   begin
  148.                     if Length(S) = L then
  149.                       Delete(S,L,1);
  150.                     P := P + 1;
  151.                     Insert(Ch,S,P);
  152.                     Write(Copy(S,P,L));
  153.                   end
  154.                   else Beep;
  155.       ^S        : if P > 0 then
  156.                     P := P - 1
  157.                   else Beep;
  158.       ^D        : if P < Length(S) then
  159.                     P := P + 1
  160.                   else Beep;
  161.       ^A        : P := 0;
  162.       ^F        : P := Length(S);
  163.       ^G        : if P < Length(S) then
  164.                   begin
  165.                     Delete(S,P + 1,1);
  166.                     Write(Copy(S,P + 1,L),UnderScore);
  167.                   end;
  168.       ^H,#127   : if P > 0 then
  169.                   begin
  170.                     Delete(S,P,1);
  171.                     Write(^H,Copy(S,P,L),UnderScore);
  172.                     P := P - 1;
  173.                   end
  174.                   else Beep;
  175.       ^Y        : begin
  176.                     Write(ConstStr(UnderScore,Length(S) - P));
  177.                     Delete(S,P + 1,L);
  178.                   end;
  179.     else
  180.       if not (Ch in Term) then Beep;
  181.     end;  {of case}
  182.   until Ch in Term;
  183.   P := Length(S);
  184.   GotoXY(X + P + 1,Y + 1);
  185.   Write('' :L - P);
  186.   TC := Ch;
  187. end;
  188.  
  189. (***********************************************************)
  190. (*  Select inputs selection from line 23                   *)
  191. (*     calls: Beep     called by: Main,List,CalcVal,Update *)
  192. (***********************************************************)
  193. procedure Select(    Prompt : Str80;
  194.                      Term   : CharSet;
  195.                  var TC     : Char    );
  196. var
  197.   Ch : Char;
  198. begin
  199.   GotoXY(1,23); Write(Prompt,'? ' ); ClrEol;
  200.   repeat
  201.     Read(Kbd,Ch);
  202.     TC := Upcase(Ch);
  203.     if not (TC in Term) then
  204.       Beep;
  205.   until TC in Term;
  206.   Write(Ch);
  207. end;
  208.  
  209. (************************************************************)
  210. (*  ClearFrame clears the display frame, I.E. Lines 3 to 20 *)
  211. (*    calls: none            called by: Main, List          *)
  212. (************************************************************)
  213. procedure ClearFrame;
  214. var
  215.   I : Integer;
  216. begin
  217.   for I := 3 to 20 do
  218.   begin
  219.     GotoXY(1,I + 1); ClrEol ;
  220.   end;
  221. end;
  222.  
  223. (**************************************************)
  224. (*  OutForm displays the entry form on the screen *)
  225. (*     calls: none            called by: Update   *)
  226. (**************************************************)
  227. procedure OutForm;
  228. begin
  229.   GotoXY(5,5); Write('Name :');
  230.   GotoXY(35,5); Write('Added Info :');
  231.   GotoXY(1,7); Write('Location :');
  232.   GotoXY(36,7); Write('Type Code :');
  233.   GotoXY(2,9); Write('Quanity :');
  234.   GotoXY(37,9); Write('Date Obt :');
  235.   GotoXY(1,11); Write('Org Cost :$');
  236.   GotoXY(33,11); Write('Pres Value :$');
  237.   GotoXY(33,13); Write('Total Value :$');
  238. end;
  239. (**************************************************)
  240. (*  ClearForm clears all fields in the entry form *)
  241. (*    calls: none       called by: Add, Update    *)
  242. (**************************************************)
  243. procedure ClearForm;
  244. begin
  245.   GotoXY(11,5); Write('' :15);
  246.   GotoXY(47,5); ClrEol;
  247.   GotoXY(11,7); Write('' :15);
  248.   GotoXY(47,7); ClrEol;
  249.   GotoXY(11,9); Write('' :3);
  250.   GotoXY(47,9); ClrEol;
  251.   GotoXY(12,11); Write('' :8);
  252.   GotoXY(47,11); ClrEol;
  253.   GotoXY(47,13); ClrEol;
  254. end;
  255. (**************************************************)
  256. (*  ErrMsg prints msg if Val function errs        *)
  257. (*    calls: none     called by:InputItem,CalcVal *)
  258. (**************************************************)
  259. procedure ErrMsg(var M : Integer);
  260. begin
  261.   if M = 100 then
  262.       begin
  263.         GoToXY(6,19);
  264.         Write('ERROR:  Error in Calculating SumTotal');
  265.       end
  266.     else
  267.       begin
  268.         GoToXY(6,19);
  269.         Write('ERROR:  Input Conversion Error');
  270.         M := M - 1;
  271.       end;
  272. end;
  273.  
  274. (**************************************************)
  275. (*  InputItem inputs added Item data              *)
  276. (*   calls: InputStr, ErrMsg   called by: Add     *)
  277. (**************************************************)
  278. procedure InputItem(var Item : ItemRec);
  279. const
  280.   Term : CharSet  =  [^E,^I,^M,^X,^Z];
  281. var
  282.   L : Integer;
  283.   TC : Char;
  284. begin
  285.   L := 1;
  286.   with Item do
  287.   repeat
  288.     case L of
  289.       1 : InputStr(Name,15,10,4,Term,TC);
  290.       2 : InputStr(AddName,15,46,4,Term,TC);
  291.       3 : InputStr(Location,2,10,6,Term,TC);
  292.       4 : InputStr(TypeCode,2,46,6,Term,TC);
  293.       5 : Begin
  294.             InputStr(Qty,3,10,8,Term,TC);
  295.             Val(Qty,Quanity,Result);
  296.             if Result>0 then
  297.                   ErrMsg(L);
  298.           end;
  299.       6 : InputStr(DateObt,6,46,8,Term,TC);
  300.       7 : Begin
  301.             InputStr(OrgCost,8,11,10,Term,TC);
  302.             Val(OrgCost,CostOrg,Result);
  303.             if Result>0 then ErrMsg(L);
  304.           end;
  305.       8 : Begin
  306.             InputStr(PresValue,8,46,10,Term,TC);
  307.             Val(PresValue,ValPres,Result);
  308.             if Result>0 then ErrMsg(L);
  309.           end;
  310.       9 : Begin
  311.             ValTotal := ValPres * Quanity;
  312.             Str(ValTotal:9:2,TotalValue);
  313.             GotoXY(47,13);
  314.             Write(TotalValue);ClrEol;
  315.           end;
  316.     end;
  317.     if (TC = ^I) or (TC = ^M) or (TC = ^X) then
  318.       if L = 9 then
  319.         L := 1
  320.       else L := L + 1
  321.     else
  322.       if TC = ^E then
  323.         if L = 1 then
  324.           L := 9
  325.         else L := L - 1;
  326.   until (TC = ^M) and (L = 1) or (TC = ^Z);
  327. end;
  328. (*****************************************************)
  329. (*  OutItem displays the item data contained in Item *)
  330. (*    calls: none            called by: Find         *)
  331. (*****************************************************)
  332. procedure OutItem(var Item : ItemRec);
  333. begin
  334.   with Item do
  335.   begin
  336.     GotoXY(11,5); Write(Name,'' :15 - Length(Name));
  337.     GotoXY(47,5); Write(AddName); ClrEol ;
  338.     GotoXY(11,7); Write(Location,'' :2 - Length(Location));
  339.     GotoXY(47,7); Write(TypeCode); ClrEol;
  340.     GotoXY(11,9); Write(Qty,'' :3 - Length(Qty));
  341.     GotoXY(47,9); Write(DateObt); ClrEol;
  342.     GotoXY(12,11); Write(OrgCost,'' :8 - Length(OrgCost));
  343.     GotoXY(47,11); Write(PresValue); ClrEol;
  344.     GotoXY(47,13); Write(TotalValue); ClrEol;
  345.   end;
  346. end;
  347.  
  348. (*****************************************************)
  349. (* KeyFromName creates a key from 'Name' and AddName *)
  350. (*   calls: UpcaseStr         called by: Add, Find   *)
  351. (*****************************************************)
  352. function KeyFromName(LastNm : Str15; FirstNm : Str15) : Str30;
  353. const
  354.   Blanks  =  '               ';
  355. begin
  356.   KeyFromName := UpcaseStr(LastNm) +
  357.                  Copy(Blanks,1,15 - Length(LastNm)) +
  358.                  UpcaseStr(FirstNm);
  359. end;
  360.  
  361. (*****************************************************)
  362. (*  Update is used to update the data base           *)
  363. (*     calls: Select, OutForm, ClearForm, Find, Add  *)
  364. (*     called by: Main                               *)
  365. (*****************************************************)
  366. procedure Update;
  367. var
  368.   Ch : Char;
  369.  
  370. (*****************************************************)
  371. (*  Add is used to add items                         *)
  372. (*    calls:InputItem, KeyFromName                   *)
  373. (*    calls (ACCESS): FindKey, AddRec, AddKey        *)
  374. (*    called by: Update                              *)
  375. (*****************************************************)
  376. procedure Add;
  377. var
  378.   ItemF : Integer;
  379.   Icode : string[2];
  380.   KeyN  : string[30];
  381.   Item  : ItemRec;
  382. begin
  383.   with Item do
  384.   begin
  385.     FillChar(Item,SizeOf(Item),0);
  386.     repeat
  387.       InputItem(Item);
  388.       KeyN := KeyFromName(Name,AddName);
  389.       FindKey(NameIndexFile, ItemF,KeyN);
  390.       if OK then
  391.       begin
  392.         GotoXY(6,19);
  393.         Write('ERROR : Duplicate Item');
  394.         Beep;
  395.       end;
  396.     until not OK;
  397.     AddRec(InvF,ItemF,Item);
  398.     AddKey(CodeIndexFile, ItemF,TypeCode);
  399.     AddKey(NameIndexFile, ItemF,KeyN);
  400.     GotoXY(6,19); ClrEol;
  401.   end;
  402. end;
  403.  
  404. (********************************************************)
  405. (*  Find is used to find, edit and delete items         *)
  406. (*    calls: Beep, InputStr, OutItem, KeyFromName       *)
  407. (*    calls (ACCESS): UsedRecs, FindKey, GetRec, PutRec *)
  408. (*         SearchRec, NextKey, PrevKey, DeleteKey,      *)
  409. (*         AddKey                                       *)
  410. (*    called by: Update                                 *)
  411. (********************************************************)
  412. procedure Find;
  413. var
  414.   D,L,I   : Integer;
  415.   Ch,
  416.   TC      : Char;
  417.   Icode,
  418.   PCode   : string[2];
  419.   FirstNm : string[15]; (* Name *)
  420.   KeyN,
  421.   PNm     : string[30];
  422.   LastNm  : string[15]; (* Addname *)
  423.   Item    : ItemRec;
  424. begin
  425.   if UsedRecs(InvF) > 0 then
  426.   begin
  427.     Icode := '';
  428.     repeat
  429.       InputStr(Icode,2,46,6,[^M,^Z],TC);
  430.       if Icode <> '' then
  431.       begin
  432.         FindKey(CodeIndexFile,D,Icode);
  433.         if OK then
  434.         begin
  435.           GetRec(InvF,D,Item);
  436.           OutItem(Item);
  437.         end
  438.         else
  439.         begin
  440.           GotoXY(6,19);
  441.           Write('ERROR : Type code not found'); Beep;
  442.         end;
  443.       end;
  444.     until OK or (Icode = '');
  445.     GotoXY(6,19); ClrEol;
  446.     if Icode = '' then
  447.     begin
  448.       L := 1; 
  449.       FirstNm := '';
  450.       LastNm := '';
  451.       repeat
  452.         case L of
  453.           1 : InputStr(FirstNm,15,10,4,[^I,^M,^Z],TC);
  454.           2 : InputStr(LastNm,15,46,4,[^I,^M,^Z],TC);
  455.         end;
  456.         if (TC = ^I) or (TC = ^M) then
  457.           L := 3 - L;
  458.       until (TC = ^M) and (L = 1) or (TC = ^Z);
  459.       KeyN := KeyFromName(FirstNm,LastNm);
  460.       SearchKey(NameIndexFile, D,KeyN);
  461.       if not OK then
  462.         PrevKey(NameIndexFile,D,KeyN);
  463.       repeat
  464.         GetRec(InvF,D,Item); 
  465.         OutItem(Item);
  466.         Select('Find : N)ext, P)revious, Q)uit',['N','P','Q'],Ch);
  467.         case Ch of
  468.           'N' : repeat NextKey(NameIndexFile, D,KeyN) until OK;
  469.           'P' : repeat PrevKey(NameIndexFile, D,KeyN) until OK;
  470.         end;
  471.       until Ch = 'Q';
  472.     end;
  473.     Select('Find : E)dit, D)elete, Q)uit',['E','D','Q'],Ch);
  474.     with Item do
  475.     case Ch of
  476.       'E' : begin
  477.               PCode := TypeCode;
  478.               PNm := KeyFromName(Name,AddName);
  479.               repeat
  480.                 InputItem(Item);
  481.                 if TypeCode = PCode then
  482.                   OK := false
  483.                 else
  484.                 begin
  485.                   Icode := TypeCode; 
  486.                   FindKey(CodeIndexFile, I,Icode); 
  487.                   if OK then Beep;
  488.                 end;
  489.               until not OK;
  490.               PutRec(InvF,D,Item);
  491.               if TypeCode <> PCode then
  492.               begin
  493.                 DeleteKey(CodeIndexFile, D,PCode);
  494.                 AddKey(CodeIndexFile, D,TypeCode);
  495.               end;
  496.               KeyN := KeyFromName(Name,AddName);
  497.               if KeyN <> PNm then
  498.               begin
  499.                 DeleteKey(NameIndexFile, D,PNm);
  500.                 AddKey(NameIndexFile, D,KeyN);
  501.               end;
  502.             end;
  503.       'D' : begin
  504.               DeleteKey(CodeIndexFile,D,TypeCode);
  505.               KeyN := KeyFromName(Name,AddName);
  506.               DeleteKey(NameIndexFile,D,KeyN);
  507.               DeleteRec(InvF,D);
  508.       end;
  509.     end;
  510.   end { of UsedRecs(InvF) > 0 .. }
  511.   else Beep;
  512. end;
  513.  
  514. begin(* Update*)
  515.   OutForm;
  516.   repeat
  517.     Select('Update : A)dd, F)ind, Q)uit',['A','F','Q'],Ch);
  518.     case Ch of
  519.       'A' : Add;
  520.       'F' : Find;
  521.     end;
  522.     if Ch <> 'Q' then
  523.     begin
  524.       GotoXY(60,2); Write(UsedRecs(InvF) :5);
  525.       ClearForm;
  526.     end;
  527.   until Ch = 'Q';
  528. end;
  529.  
  530. (********************************************************)
  531. (*  List is used to list items                          *)
  532. (*    calls: PrintItem, DisplayItem, Select, ClearFrame *)
  533. (*    calls (ACCESS): ClearKey, NextKey, GetRec,FileLen *)
  534. (*    called by: Main                                   *)
  535. (********************************************************)
  536. procedure List;
  537. label Escape;
  538. var
  539.   D,L,LD      : Integer;
  540.   Ch,CO,CS,CT : Char;
  541.   Icode,
  542.   LocCode,
  543.   TmpCode     : string[2];
  544.   KeyN        : string[30];
  545.   Title       : string[32];
  546.   Item        : ItemRec;
  547.  
  548. (**************************************)
  549. (*  PrintItem sends output to printer *)
  550. (*    calls: none    called by: List  *)
  551. (**************************************)
  552. procedure PrintItem(    AT  : char;
  553.                         AC  : Str2;
  554.                         itm :ItemRec;
  555.                         Ttl :Str32);
  556. begin
  557.   with itm do
  558.     begin
  559.     if AT = 'T' then
  560.         begin
  561.           if TypeCode = AC then
  562.             begin
  563.               Write(Lst,TypeCode,ConstStr(' ',2-Length(TypeCode)),' ',Title);
  564.               Write(Lst,ConstStr(' ',32-Length(Title)),' ');
  565.               Write(Lst,Location,ConstStr(' ',2-Length(Location)),' ');
  566.               Write(Lst,DateObt,ConstStr(' ',6-Length(DateObt)),' $',OrgCost);
  567.               Write(Lst,ConstStr(' ',8-Length(OrgCost)),' $',PresValue);
  568.               Write(Lst,ConstStr(' ',8-Length(PresValue)),' ',Qty);
  569.               Writeln(Lst,ConstStr(' ',3-Length(Qty)),' $',TotalValue);
  570.             end;
  571.         end
  572.       else
  573.         begin
  574.           if AT = 'L' then
  575.             begin
  576.               if Location = AC then
  577.               begin
  578.                 Write(Lst,TypeCode,ConstStr(' ',2-Length(TypeCode)),' ',Title);
  579.                 Write(Lst,ConstStr(' ',32-Length(Title)),' ');
  580.                 Write(Lst,Location,ConstStr(' ',2-Length(Location)),' ');
  581.                Write(Lst,DateObt,ConstStr(' ',6-Length(DateObt)),' $',OrgCost);
  582.                 Write(Lst,ConstStr(' ',8-Length(OrgCost)),' $',PresValue);
  583.                 Write(Lst,ConstStr(' ',8-Length(PresValue)),' ',Qty);
  584.                 Writeln(Lst,ConstStr(' ',3-Length(Qty)),' $',TotalValue);
  585.               end;
  586.             end
  587.           else
  588.             begin
  589.               Write(Lst,TypeCode,ConstStr(' ',2-Length(TypeCode)),' ',Title);
  590.               Write(Lst,ConstStr(' ',32-Length(Title)),' ');
  591.               Write(Lst,Location,ConstStr(' ',2-Length(Location)),' ');
  592.               Write(Lst,DateObt,ConstStr(' ',6-Length(DateObt)),' $',OrgCost);
  593.               Write(Lst,ConstStr(' ',8-Length(OrgCost)),' $',PresValue);
  594.               Write(Lst,ConstStr(' ',8-Length(PresValue)),' ',Qty);
  595.               Writeln(Lst,ConstStr(' ',3-Length(Qty)),' $',TotalValue);
  596.             end;
  597.         end;
  598.     end; {with}
  599. end; {PrintItem}
  600.  
  601. (****************************************)
  602. (*  DisplayItem sends output to Screen  *)
  603. (*    calls: none    called by: List    *)
  604. (****************************************)
  605. procedure DisplayItem(    AT  : char;
  606.                         AC  : Str2;
  607.                         itm :ItemRec;
  608.                         Ttl :Str32;
  609.                     var M   : integer);
  610. begin
  611.   with itm do
  612.     begin
  613.     if AT = 'T' then
  614.       begin
  615.         if TypeCode = AC then
  616.           begin
  617.             GotoXY(1,M + 1); Write(TypeCode);
  618.             GotoXY(4,M + 1); Write(Title);
  619.             GotoXY(37,M + 1); Write(Location);
  620.             GotoXY(40,M + 1); Write(DateObt);
  621.             GotoXY(47,M + 1); Write('$',OrgCost);
  622.             GotoXY(57,M + 1); Write('$',PresValue);
  623.             GotoXY(66,M + 1); Write(Qty);
  624.             GotoXY(70,M + 1); Write('$',TotalValue);
  625.             M := M + 1;
  626.           end;
  627.       end
  628.    else
  629.       begin
  630.         if Location = AC then
  631.           begin
  632.             GotoXY(1,M + 1); Write(TypeCode);
  633.             GotoXY(4,M + 1); Write(Title);
  634.             GotoXY(37,M + 1); Write(Location);
  635.             GotoXY(40,M + 1); Write(DateObt);
  636.             GotoXY(47,M + 1); Write('$',OrgCost);
  637.             GotoXY(57,M + 1); Write('$',PresValue);
  638.             GotoXY(66,M + 1); Write(Qty);
  639.             GotoXY(70,M + 1); Write('$',TotalValue);
  640.             M := M + 1;
  641.           end;
  642.       end;
  643.     end; {with itm}
  644. end; {DisplayItem}
  645.  
  646. begin(* List *)
  647.   Select('Output device : P)rinter, S)creen',['P','S'],CO);
  648.   Select('Sort by : C)ode, N)ame, U)nsorted',['C','N','U'],CS);
  649.   Select('Template Wanted?: L)ocation T)ypeCode Z)none',['L','T','Z'],CT);
  650.   if CT <> 'Z' then
  651.     begin
  652.       if CT = 'L' then
  653.           begin
  654.             GotoXY(1,23);Write('Enter Location Template:');ClrEol;
  655.             Read(trm,LocCode);
  656.           end
  657.         else
  658.           begin
  659.             GotoXY(1,23);Write('Enter TypeCode Template:');ClrEol;
  660.             Read(trm,TmpCode);
  661.           end;
  662.     end;
  663.   GotoXY(1,23); Write('Press <Esc> to abort'); ClrEol;
  664.   ClearKey(CodeIndexFile);
  665.   ClearKey(NameIndexFile);
  666.   D := 0;
  667.   LD := FileLen(InvF) - 1;
  668.   L := 4;
  669.   if CO = 'P' then
  670.        begin
  671.          Writeln(Lst);
  672.          Write(Lst,'TC Title                           Loc Date   OrgCost   ');
  673.          Writeln(Lst,'PresVal   Qty TotalVal');
  674.        end;
  675.   repeat
  676.     if KeyPressed then
  677.     begin
  678.       Read(Kbd,Ch);
  679.       if Ch = #27 then
  680.         goto Escape;
  681.     end;
  682.     case CS of
  683.       'C' : NextKey(CodeIndexFile,D,Icode);
  684.       'N' : NextKey(NameIndexFile,D,KeyN);
  685.       'U' : begin
  686.               OK := false;
  687.               while (D < LD) and not OK do
  688.               begin
  689.                 D := D + 1;
  690.                 GetRec(InvF,D,Item);
  691.                 OK := Item.ItemStatus = 0;
  692.               end;
  693.             end;
  694.     end;
  695.     if OK then
  696.       with Item do
  697.       begin
  698.         if CS <> 'U' then
  699.           GetRec(InvF,D,Item);
  700.         Title := Name;
  701.         if AddName <> '' then
  702.           Title := Name + ', ' + AddName;
  703.         if CO = 'P' then
  704.           begin
  705.             if CT = 'L' then
  706.                 PrintItem(CT,LocCode,Item,Title)
  707.               else
  708.                 if CT = 'T' then
  709.                     PrintItem(CT,TmpCode,Item,Title)
  710.                   else
  711.                     PrintItem(CT,CT,Item,Title);
  712.           end
  713.         else
  714.           begin
  715.             GotoXY(1,4);Write('TC Title');
  716.             GotoxY(36,4);Write('Loc  Date  OrgCost   PresVal  Qty   TotalVal');
  717.             if L = 21 then
  718.               begin
  719.               GotoXY(1,23);
  720.               Write('Press <RETURN> to continue');
  721.               Write(' or <Esc> to abort');
  722.               ClrEol;
  723.               repeat
  724.                 Read(Kbd,Ch)
  725.               until (Ch = ^M) or (Ch = #27);
  726.               if Ch = #27 then
  727.                 goto Escape;
  728.               GotoXY(1,23);
  729.               Write('Press <Esc> to abort'); ClrEol;
  730.               ClearFrame;
  731.               L := 4;
  732.           end;
  733.           if CT <> 'Z' then
  734.               begin
  735.                 if CT = 'L' then
  736.                     DisplayItem(CT,LocCode,Item,Title,L)
  737.                   else
  738.                     DisplayItem(CT,TmpCode,Item,Title,L);
  739.               end
  740.             else
  741.               begin
  742.                 GotoXY(1,L + 1); Write(TypeCode);
  743.                 GotoXY(4,L + 1); Write(Title);
  744.                 GotoXY(37,L + 1); Write(Location);
  745.                 GotoXY(40,L + 1); Write(DateObt);
  746.                 GotoXY(47,L + 1); Write('$',OrgCost);
  747.                 GotoXY(57,L + 1); Write('$',PresValue);
  748.                 GotoXY(66,L + 1); Write(Qty);
  749.                 GotoXY(70,L + 1); Write('$',TotalValue);
  750.                 L := L + 1;
  751.               end;
  752.       end; { of with Item do .. }
  753.     end; { of if OK .. }
  754.   until not OK;
  755.   if CO = 'S' then
  756.   begin
  757.     GotoXY(1,23); Write('Press <RETURN>'); ClrEol;
  758.     repeat
  759.       Read(Kbd,Ch)
  760.     until Ch = ^M;
  761.   end;
  762.   Escape :
  763. end;
  764.  
  765. (*************************************************************)
  766. (*  CalcValue calculates the present value of selected Items *)
  767. (*   calls:GetRec,Select,ErrMsg,CalcValue    called by: Main *)
  768. (*************************************************************)
  769. procedure CalcValue;
  770. var
  771.   ValTotal,
  772.   SumTotal  : Real;
  773.   Item      : ItemRec;
  774.   Ch,CO,LT  : Char;
  775.   LocCode,
  776.   TmpCode   : string[2];
  777.   LD,D,L,
  778.   Result    : integer;
  779.   TotalSum,
  780.   TmpVal    : string[9];
  781.  
  782.  
  783. (*************************************************************)
  784. (*  DelBlanks changes blanks in 'TotalValue' into zeros      *)
  785. (*     This is so the 'Val' function can be used             *)
  786. (*    calls: none          called by: CalcValue              *)
  787. (*************************************************************)
  788. procedure DelBlanks(TotalTmp : Str9; var ValTmp : Str9);
  789. var
  790.   I    : integer;
  791. begin
  792.   for I := 1 to 9 do
  793.     begin
  794.       if TotalTmp[I] = ' ' then
  795.           ValTmp[I] := '0'
  796.         else
  797.           ValTmp[I] := TotalTmp[I];
  798.     end;
  799. end; {DelBlanks}
  800.  
  801.  
  802. begin
  803.   SumTotal := 0;
  804.   LD := FileLen(InvF) - 1;
  805.   D := 1;
  806.   L := 100; {dummy var}
  807.   begin
  808.     Select('Output device : P)rinter, S)creen',['P','S'],CO);
  809.     Select('Template? : L)ocation, T)ypeCode, Z)none', ['L','T','Z'], Ch);
  810.     if Ch <> 'Z' then
  811.         begin
  812.           if Ch = 'L' then
  813.               begin
  814.                 GotoXY(1,23);Write('Enter Location Template:');ClrEol;
  815.                 Read(trm,LocCode);
  816.               end
  817.             else
  818.               begin
  819.                 GotoXY(1,23);Write('Enter TypeCode Template:');ClrEol;
  820.                 Read(trm,TmpCode);
  821.               end;
  822.         end;
  823.   end;
  824.   repeat
  825.       GetRec(invF,D,Item);
  826.       with Item do
  827.       begin
  828.         if Ch <> 'Z' then
  829.           begin
  830.             if Ch = 'L' then
  831.               begin
  832.                 if Location = LocCode then
  833.                   begin
  834.                     DelBlanks(Item.TotalValue,TmpVal);
  835.                     Val(TmpVal,ValTotal,Result);
  836.                     if Result <> 10 then ErrMsg(L);
  837.                     SumTotal := ValTotal + SumTotal;
  838.                   end;
  839.               end
  840.             else
  841.               begin
  842.                 if TypeCode = TmpCode then
  843.                   begin
  844.                     DelBlanks(Item.TotalValue,TmpVal);
  845.                     Val(TmpVal,ValTotal,Result);
  846.                     if Result <> 10 then ErrMsg(L);
  847.                     SumTotal := ValTotal + SumTotal;
  848.                   end;
  849.               end;
  850.           end
  851.         else
  852.           begin
  853.             DelBlanks(Item.TotalValue,TmpVal);
  854.             Val(TmpVal,ValTotal,Result);
  855.             SumTotal := ValTotal + SumTotal;
  856.           end;
  857.       end; {with Item do}
  858.     D := D + 1;
  859.   until D > LD;
  860.   Str(SumTotal:9:2,TotalSum);
  861.   if CO = 'P' then
  862.         begin
  863.           if Ch = 'Z' then
  864.               begin
  865.                 Writeln(Lst);
  866.                 Write(Lst,'Total Value for all items is: $',TotalSum);
  867.               end
  868.             else
  869.               begin
  870.                 if Ch = 'L' then
  871.                     begin
  872.                       Writeln(Lst);
  873.                       Write(Lst,'Total Value for items in Location [');
  874.                       Writeln(Lst,LocCode,'] is: $',TotalSum);
  875.                     end
  876.                   else
  877.                     begin
  878.                       Writeln(Lst);
  879.                       Write(Lst,'Total Value for items with TypeCode [');
  880.                       Writeln(Lst,TmpCode,'] is: $',TotalSum);
  881.                     end;
  882.               end;
  883.         end
  884.       else
  885.         begin
  886.           if Ch <> 'Z' then
  887.             begin
  888.                 if Ch = 'L' then
  889.                     begin
  890.                       GotoXY(1,6);
  891.                       Write('Total Value for items in Location [');
  892.                       Write(LocCode,'] is: $',TotalSum);
  893.                     end
  894.                   else
  895.                     begin
  896.                       GotoXY(1,6);
  897.                       Write('Total Value for items with TypeCode [');
  898.                       Write(TmpCode,'] is: $',TotalSum);
  899.                     end;
  900.             end
  901.           else
  902.             begin
  903.               GotoXY(1,6);
  904.               Write('Total Value for all items is: $',TotalSum);
  905.             end;
  906.         repeat
  907.           GotoXY(1,23);Write('Press <RETURN> to Continue.');ClrEol;
  908.           Read(Kbd,LT);
  909.         until LT = ^M;
  910.       end;
  911. end; {CalcValue}
  912.  
  913.  
  914. (***************************************************************)
  915. (*  Main program                                               *)
  916. (*    calls: List, Update, CalcValue, Select, ClearFrame       *)
  917. (*           ConstStr, UpcaseStr                               *)
  918. (*    calls (ACCESS): OpenFile, OpenIndex, MakeFile, MakeIndex *)
  919. (*                    CloseFile, CloseIndex                    *)
  920. (***************************************************************)
  921. (* Main program *)
  922.  
  923. begin
  924.   ClrScr ;
  925.   Writeln(ConstStr('-',79));
  926.   Writeln('TURBO-Access Inventory Database');
  927.   Writeln(ConstStr('-',79));
  928.   GotoXY(1,22); Writeln(ConstStr('-',79));
  929.   Writeln;
  930.   Write(ConstStr('-',79)); GotoXY(1,4);
  931.   InitIndex;
  932.   GotoXY(1,23);
  933.   Write('Enter Disk Drive then 3-Letter name of Data & Index file:');
  934.   Read(trm,StoreFil);
  935.   FileD := Concat(StoreFil,'.DAT');
  936.   FileC := Concat(StoreFil,'.IXC');
  937.   FileN := Concat(StoreFil,'.IXN');
  938.   OpenFile(InvF,FileD,ItemRecSize);
  939.   if OK then
  940.     OpenIndex(CodeIndexFile,FileC,2,1);
  941.   if OK then
  942.     OpenIndex(NameIndexFile,FileN,30,0);
  943.   if not OK then
  944.   begin
  945.     Select('Data files missing. Create new files (Y/N)', ['Y','N'], Ch);
  946.     if Ch = 'Y' then
  947.     begin
  948.       MakeFile(InvF,FileD,ItemRecSize);
  949.       MakeIndex(CodeIndexFile,FileC,2,1);
  950.       MakeIndex(NameIndexFile,FileN,30,0);
  951.     end
  952.    else goto Stop;
  953.   end;
  954.   GotoXY(60,2); Write(UsedRecs(InvF):5,' Records in use');
  955.   repeat
  956.     Select('Select: U)pdate, L)ist, C)alc Value, Q)uit',['U','L','C','Q'], Ch);
  957.     case Ch of
  958.       'U' : Update;
  959.       'L' : List;
  960.       'C' : CalcValue;
  961.     end;
  962.     if Ch <> 'Q' then
  963.           ClearFrame
  964.       else
  965.         begin
  966.           GotoXY(1,23);Select('Do you really want to Quit (Y/N)',['Y','N'],Ch);
  967.           if UpCase(Ch) = 'Y' then
  968.               Ch := 'Q'
  969.             else
  970.               Ch := 'X';
  971.         end;
  972.   until UpCase(Ch) = 'Q';
  973.   CloseFile(InvF);
  974.   CloseIndex(CodeIndexFile) ;
  975.   CloseIndex(NameIndexFile) ;
  976.   Stop :
  977.   ClrScr;
  978. end.