ITEMS.MOD 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. IMPLEMENTATION MODULE Items;
  2. (*
  3. Copyright (C) 1988,1989 Jensen & Partners International
  4. *)
  5. IMPORT Globals, Window, IO, Str, Misc, Btree;
  6. FROM Globals IMPORT GetMenu, ItemIndex, ItemData;
  7. VAR
  8. ItemWin, lastWin : Window.WinType;
  9. OnScreen : BOOLEAN;
  10. EmptyItem, BlankItem : ItemRec;
  11. keyPressed : CHAR;
  12. PROCEDURE PressAKey( txt : ARRAY OF CHAR);
  13. VAR
  14. ch : CHAR;
  15. BEGIN
  16. Window.TextColor(Globals.PromptFore);
  17. Window.TextBackground(Globals.DisplayBack);
  18. Globals.WriteAt(9,1,txt);
  19. Window.GotoXY(30,9);
  20. ch := IO.RdKey();
  21. Window.GotoXY(1,9);
  22. Window.ClrEol();
  23. keyPressed := CAP(ch);
  24. END PressAKey;
  25. PROCEDURE MakeKey( keyA, myItemA : ADDRESS );
  26. VAR
  27. key : POINTER TO Globals.FileKey;
  28. myItem : POINTER TO ItemRec;
  29. BEGIN
  30. key := keyA;
  31. myItem := myItemA;
  32. Str.Copy(key^,myItem^.INum);
  33. END MakeKey;
  34. PROCEDURE Display( anItem : ItemRec );
  35. (*
  36. This procedure displays the item record on the screen.
  37. *)
  38. VAR
  39. S : ARRAY[0..10] OF CHAR;
  40. ok : BOOLEAN;
  41. BEGIN
  42. Window.TextColor(Globals.DataFore);
  43. Window.TextBackground(Globals.DataBack);
  44. WITH anItem DO
  45. Globals.WriteAt(1,15,INum);
  46. Globals.WriteAt(2,15,Description);
  47. Globals.WriteAt(3,15,Mfgr);
  48. Globals.WriteAt(3,55,PartNum);
  49. Globals.WriteAt(7,15,Supplier);
  50. Window.GotoXY(15,5); IO.WrCard(QOHand,-10);
  51. Window.GotoXY(55,5); IO.WrCard(QOOrder,-10);
  52. Str.FixRealToStr(Cost,2,S,ok);
  53. Globals.WriteAt(6,15," ");
  54. IF ok = FALSE THEN
  55. Globals.WriteAt(6,15,"???");
  56. ELSE
  57. Globals.WriteAt(6,15,S);
  58. END;
  59. Str.FixRealToStr(Retail,2,S,ok);
  60. Globals.WriteAt(6,55," ");
  61. IF ok = FALSE THEN
  62. Globals.WriteAt(6,55,"???");
  63. ELSE
  64. Globals.WriteAt(6,55,S);
  65. END;
  66. END;
  67. END Display;
  68. PROCEDURE Clear( );
  69. (*
  70. This procedure clears the previous item information.
  71. *)
  72. BEGIN
  73. Display(BlankItem);
  74. END Clear;
  75. PROCEDURE Template( );
  76. (*
  77. This procedure un-hides the item display window and displays
  78. the field names.
  79. *)
  80. BEGIN
  81. lastWin := Window.Used();
  82. Window.Use(ItemWin);
  83. Window.PutOnTop(ItemWin);
  84. Clear();
  85. OnScreen := TRUE;
  86. END Template;
  87. PROCEDURE Input( VAR anItem : ItemRec; Clear : BOOLEAN );
  88. (*
  89. This procedure inputs the item information from the user.
  90. If Clear is TRUE, then the information is cleared before the
  91. user enters new information. If Clear is FALSE, Display() is
  92. called first to show the current information, and it is then
  93. edited.
  94. *)
  95. VAR
  96. ok,
  97. Continue : BOOLEAN;
  98. Field : CARDINAL;
  99. ch : CHAR;
  100. S : ARRAY[0..10] OF CHAR;
  101. BEGIN
  102. IF Clear THEN
  103. anItem := EmptyItem;
  104. Display(BlankItem);
  105. END;
  106. Display(anItem);
  107. Continue := TRUE;
  108. Field := 1;
  109. WITH anItem DO
  110. WHILE (Continue) DO
  111. CASE Field OF
  112. 1: Window.GotoXY(15,1); Misc.InputStr(INum,10);
  113. | 2: Window.GotoXY(15,2); Misc.InputStr(Description,25);
  114. | 3: Window.GotoXY(15,3); Misc.InputStr(Mfgr,20);
  115. | 4: Window.GotoXY(55,3); Misc.InputStr(PartNum,10);
  116. | 5: Window.GotoXY(15,5);
  117. Str.CardToStr(LONGCARD(QOHand),S,10,ok);
  118. Misc.InputStr(S,10);
  119. QOHand := CARDINAL(Str.StrToCard(S,10,ok));
  120. | 6: Window.GotoXY(55,5);
  121. Str.CardToStr(LONGCARD(QOOrder),S,10,ok);
  122. Misc.InputStr(S,10);
  123. QOOrder := CARDINAL(Str.StrToCard(S,10,ok));
  124. | 7: Window.GotoXY(15,6);
  125. Str.FixRealToStr(Cost,2,S,ok);
  126. Misc.InputStr(S,10);
  127. Cost := Str.StrToReal(S,ok);
  128. | 8: Window.GotoXY(55,6);
  129. Str.FixRealToStr(Retail,2,S,ok);
  130. Misc.InputStr(S,10);
  131. Retail := Str.StrToReal(S,ok);
  132. | 9: Window.GotoXY(15,7); Misc.InputStr(Supplier,10);
  133. END; (* case *)
  134. INC(Field);
  135. IF Field >= 10 THEN
  136. Window.TextColor(Globals.PromptFore);
  137. Window.TextBackground(Globals.DisplayBack);
  138. Globals.WriteAt(9,1,"Are these ok? ");
  139. Window.GotoXY(15,9);
  140. ch := IO.RdKey();
  141. Globals.WriteAt(9,1," ");
  142. IF CAP(ch) = 'Y' THEN
  143. Continue := FALSE;
  144. ELSE
  145. Field := 1;
  146. Window.TextColor(Globals.DataFore);
  147. Window.TextBackground(Globals.DataBack);
  148. END; (* if *)
  149. END; (* if *)
  150. END; (* while *)
  151. END; (* with *)
  152. END Input;
  153. PROCEDURE Search( VAR anItem : ItemRec ) : BOOLEAN ;
  154. (*
  155. The key fields from anItem are checked for data. If they
  156. are filled, that information is used to search. Otherwise,
  157. this procedure asks the user for search information, and then
  158. searches for the given record. If it is found, it is copied to
  159. anItem, and TRUE is returned. If it is not found, FALSE is
  160. returned.
  161. *)
  162. VAR
  163. searchStr : Globals.FileKey;
  164. ch : CHAR;
  165. BEGIN
  166. Clear();
  167. IF anItem.INum[0] > ' ' THEN
  168. Str.Copy(searchStr,anItem.INum);
  169. ELSE
  170. Window.GotoXY(15,1);
  171. searchStr := "";
  172. Misc.InputStr(searchStr,10);
  173. END;
  174. IF searchStr[0] <= ' ' THEN
  175. Clear();
  176. RETURN FALSE;
  177. END;
  178. Str.Caps(searchStr);
  179. (* WriteAt(sx, sy, "Searching..."); *)
  180. IF Btree.Find(ItemIndex,searchStr,anItem) THEN
  181. Display(anItem);
  182. (* WriteAt(sx, sy, " "); *)
  183. ELSE
  184. IF Btree.Search(ItemIndex,searchStr,anItem) THEN
  185. Display(anItem);
  186. REPEAT
  187. GetMenu("N)ext P)revious or T)his One? ",
  188. Globals.CharSet{'N','P','T'}, ch);
  189. CASE ch OF
  190. 'N' : IF Btree.Next(ItemIndex,anItem) THEN
  191. Clear();
  192. Display(anItem);
  193. ELSE
  194. Globals.Beep();
  195. END;
  196. | 'P' : IF Btree.Prev(ItemIndex,anItem) THEN
  197. Clear();
  198. Display(anItem);
  199. ELSE
  200. Globals.Beep();
  201. END;
  202. | 'T' : ;
  203. ELSE
  204. Globals.Beep();
  205. END;
  206. UNTIL ch = 'T';
  207. ELSE
  208. Globals.WriteAt(8,1,"Failed Search!");
  209. PressAKey("Press Any Key to Continue... ");
  210. Window.TextColor(Globals.PromptFore);
  211. Window.TextBackground(Globals.DisplayBack);
  212. Globals.WriteAt(8,1," ");
  213. RETURN FALSE;
  214. END;
  215. END;
  216. PressAKey("E)dit, D)elete, or Q)uit? ");
  217. IF keyPressed = 33C THEN
  218. RETURN FALSE;
  219. ELSIF keyPressed = 'E' THEN
  220. Btree.Delete(ItemData);
  221. Input(anItem,FALSE);
  222. Btree.Add(ItemData,anItem,SIZE(anItem));
  223. RETURN TRUE;
  224. ELSIF keyPressed = 'D' THEN
  225. Btree.Delete(ItemData);
  226. RETURN FALSE;
  227. ELSE
  228. RETURN TRUE;
  229. END;
  230. END Search;
  231. PROCEDURE Close( );
  232. (*
  233. This procedure removes the item display window from the screen.
  234. *)
  235. BEGIN
  236. Window.Hide(ItemWin);
  237. Window.Use(lastWin);
  238. Window.PutOnTop(lastWin);
  239. OnScreen := FALSE;
  240. END Close;
  241. BEGIN
  242. ItemWin := Window.Open( Window.WinDef( 0, 4, 79, 14,
  243. Window.White,Window.Black,TRUE,FALSE,TRUE,TRUE,
  244. Window.SingleFrame,Window.White,Window.Black) );
  245. Window.SetFrame(ItemWin,Window.SingleFrame,Globals.DisplayBorder,
  246. Globals.DisplayBack);
  247. Window.Use(ItemWin);
  248. Window.TextColor(Globals.DisplayFore);
  249. Window.TextBackground(Globals.DisplayBack);
  250. Window.Clear();
  251. Globals.WriteAt(1,1,"Item Number:");
  252. Globals.WriteAt(2,1,"Description:");
  253. Globals.WriteAt(3,1,"Manufacturer:");
  254. Globals.WriteAt(3,40,"Part Number:");
  255. Globals.WriteAt(5,1,"On Hand:");
  256. Globals.WriteAt(5,40,"On Order:");
  257. Globals.WriteAt(6,1,"Cost:");
  258. Globals.WriteAt(6,40,"Retail:");
  259. Globals.WriteAt(7,1,"Supplier:");
  260. WITH BlankItem DO
  261. Str.Copy(INum," ");
  262. Str.Copy(Description," ");
  263. Str.Copy(PartNum," ");
  264. Str.Copy(Mfgr," ");
  265. Str.Copy(Supplier," ");
  266. QOHand := 0;
  267. QOOrder := 0;
  268. Cost := 0.0;
  269. Retail := 0.0;
  270. END;
  271. WITH EmptyItem DO
  272. INum := "";
  273. Description := "";
  274. PartNum := "";
  275. Mfgr := "";
  276. Supplier := "";
  277. QOHand := 0;
  278. QOOrder := 0;
  279. Cost := 0.0;
  280. Retail := 0.0;
  281. END;
  282. OnScreen := FALSE;
  283. END Items.