CLIENT.MOD 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. IMPLEMENTATION MODULE Client;
  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, ClientIndex, ClientData;
  7. VAR
  8. ClientWin, lastWin : Window.WinType;
  9. OnScreen : BOOLEAN;
  10. EmptyClient, BlankClient : ClientRec;
  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, myClientA : ADDRESS );
  26. VAR
  27. key : POINTER TO Globals.FileKey;
  28. myClient : POINTER TO ClientRec;
  29. BEGIN
  30. key := keyA;
  31. myClient := myClientA;
  32. Str.Copy(key^,myClient^.CNum);
  33. END MakeKey;
  34. PROCEDURE Display( aClient : ClientRec );
  35. (*
  36. This procedure displays the client 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 aClient DO
  45. Globals.WriteAt(1,15,CNum);
  46. Globals.WriteAt(2,15,LName);
  47. Globals.WriteAt(2,48,FName);
  48. Globals.WriteAt(3,15,Street);
  49. Globals.WriteAt(4,15,City);
  50. Globals.WriteAt(4,48,State);
  51. Globals.WriteAt(4,62,Zip);
  52. Globals.WriteAt(6,15,Phone);
  53. Globals.WriteAt(6,55," ");
  54. Str.FixRealToStr(Balance,2,S,ok);
  55. IF ok = FALSE THEN
  56. Globals.WriteAt(6,55,"???");
  57. ELSE
  58. Globals.WriteAt(6,55,S);
  59. END;
  60. END;
  61. END Display;
  62. PROCEDURE Clear( );
  63. (*
  64. This procedure clears the previous client information.
  65. *)
  66. BEGIN
  67. Display(BlankClient);
  68. END Clear;
  69. PROCEDURE Template( );
  70. (*
  71. This procedure un-hides the client display window and displays
  72. the field names.
  73. *)
  74. BEGIN
  75. lastWin := Window.Used();
  76. Window.Use(ClientWin);
  77. Window.PutOnTop(ClientWin);
  78. Clear();
  79. OnScreen := TRUE;
  80. END Template;
  81. PROCEDURE Input( VAR aClient : ClientRec; Clear : BOOLEAN );
  82. (*
  83. This procedure inputs the client information from the user.
  84. If Clear is TRUE, then the information is cleared before the
  85. user enters new information. If Clear is FALSE, Display() is
  86. called first to show the current information, and it is then
  87. edited.
  88. *)
  89. VAR
  90. ok,
  91. Continue : BOOLEAN;
  92. Field : CARDINAL;
  93. ch : CHAR;
  94. S : ARRAY[0..10] OF CHAR;
  95. BEGIN
  96. IF Clear THEN
  97. aClient := EmptyClient;
  98. Display(BlankClient);
  99. END;
  100. Display(aClient);
  101. Continue := TRUE;
  102. Field := 1;
  103. WITH aClient DO
  104. WHILE (Continue) DO
  105. CASE Field OF
  106. 1: Window.GotoXY(15,1); Misc.InputStr(CNum,10);
  107. | 2: Window.GotoXY(15,2); Misc.InputStr(LName,15);
  108. | 3: Window.GotoXY(48,2); Misc.InputStr(FName,10);
  109. | 4: Window.GotoXY(15,3); Misc.InputStr(Street,25);
  110. | 5: Window.GotoXY(15,4); Misc.InputStr(City,15);
  111. | 6: Window.GotoXY(48,4); Misc.InputStr(State,2);
  112. | 7: Window.GotoXY(62,4); Misc.InputStr(Zip,5);
  113. | 8: Window.GotoXY(15,6); Misc.InputStr(Phone,13);
  114. | 9: Window.GotoXY(55,6);
  115. Str.FixRealToStr(Balance,2,S,ok);
  116. Misc.InputStr(S,10);
  117. Balance := Str.StrToReal(S,ok);
  118. END;
  119. INC(Field);
  120. IF Field >= 10 THEN
  121. Window.TextColor(Globals.PromptFore);
  122. Window.TextBackground(Globals.DisplayBack);
  123. Globals.WriteAt(8,1,"Are these ok? ");
  124. Window.GotoXY(15,8);
  125. ch := IO.RdKey();
  126. Globals.WriteAt(8,1," ");
  127. IF CAP(ch) = 'Y' THEN
  128. Continue := FALSE;
  129. ELSE
  130. Field := 1;
  131. Window.TextColor(Globals.DataFore);
  132. Window.TextBackground(Globals.DataBack);
  133. END;
  134. END;
  135. END;
  136. END;
  137. END Input;
  138. PROCEDURE Search( VAR aClient : ClientRec ) : BOOLEAN ;
  139. (*
  140. This procedure asks the user for search information, and then
  141. searches for the given record. If it is found, it is copied to
  142. aClient, and TRUE is returned. If it is not found, FALSE is
  143. returned.
  144. *)
  145. VAR
  146. searchStr : Globals.FileKey;
  147. ch : CHAR;
  148. BEGIN
  149. Clear();
  150. IF aClient.CNum[0] > ' ' THEN
  151. Str.Copy(searchStr,aClient.CNum);
  152. ELSE
  153. Window.GotoXY(15,1);
  154. searchStr := "";
  155. Misc.InputStr(searchStr,10);
  156. END;
  157. IF searchStr[0] <= ' ' THEN
  158. Clear();
  159. RETURN FALSE;
  160. END;
  161. Str.Caps(searchStr);
  162. IF Btree.Find(ClientIndex,searchStr,aClient) THEN
  163. Display(aClient);
  164. ELSE
  165. IF Btree.Search(ClientIndex,searchStr,aClient) THEN
  166. Display(aClient);
  167. REPEAT
  168. GetMenu("N)ext P)revious or T)his One? ",
  169. Globals.CharSet{'N','P','T'}, ch);
  170. CASE ch OF
  171. 'N' : IF Btree.Next(ClientIndex,aClient) THEN
  172. Clear();
  173. Display(aClient);
  174. ELSE
  175. Globals.Beep();
  176. END;
  177. | 'P' : IF Btree.Prev(ClientIndex,aClient) THEN
  178. Clear();
  179. Display(aClient);
  180. ELSE
  181. Globals.Beep();
  182. END;
  183. | 'T' : ;
  184. ELSE
  185. Globals.Beep();
  186. END;
  187. UNTIL ch = 'T';
  188. ELSE
  189. Globals.WriteAt(8,1,"Failed Search!");
  190. PressAKey("Press Any Key to Continue... ");
  191. Window.TextColor(Globals.PromptFore);
  192. Window.TextBackground(Globals.DisplayBack);
  193. Globals.WriteAt(8,1," ");
  194. RETURN FALSE;
  195. END;
  196. END;
  197. PressAKey("E)dit, D)elete, or Q)uit? ");
  198. IF keyPressed = 33C THEN
  199. RETURN FALSE;
  200. ELSIF keyPressed = 'E' THEN
  201. Btree.Delete(ClientData);
  202. Input(aClient,FALSE);
  203. Btree.Add(ClientData,aClient,SIZE(aClient));
  204. RETURN TRUE;
  205. ELSIF keyPressed = 'D' THEN
  206. Btree.Delete(ClientData);
  207. RETURN FALSE;
  208. ELSE
  209. RETURN TRUE;
  210. END;
  211. END Search;
  212. PROCEDURE Close( );
  213. (*
  214. This procedure removes the client display window from the screen.
  215. *)
  216. BEGIN
  217. Window.Hide(ClientWin);
  218. Window.Use(lastWin);
  219. Window.PutOnTop(lastWin);
  220. OnScreen := FALSE;
  221. END Close;
  222. BEGIN
  223. ClientWin := Window.Open( Window.WinDef( 0, 4, 79, 14,
  224. Window.White,Window.Black,TRUE,FALSE,TRUE,TRUE,
  225. Window.SingleFrame,Window.White,Window.Black) );
  226. Window.SetFrame(ClientWin,Window.SingleFrame,Globals.DisplayBorder,
  227. Globals.DisplayBack);
  228. Window.Use(ClientWin);
  229. Window.TextColor(Globals.DisplayFore);
  230. Window.TextBackground(Globals.DisplayBack);
  231. Window.Clear();
  232. Globals.WriteAt(1,1,"Cust Number:");
  233. Globals.WriteAt(2,1,"Last Name:");
  234. Globals.WriteAt(2,40,"First:");
  235. Globals.WriteAt(3,1,"Street:");
  236. Globals.WriteAt(4,1,"City:");
  237. Globals.WriteAt(4,40,"State:");
  238. Globals.WriteAt(4,55,"Zip:");
  239. Globals.WriteAt(6,1,"Phone:");
  240. Globals.WriteAt(6,40,"Balance:");
  241. WITH BlankClient DO
  242. CNum := " ";
  243. LName := " ";
  244. FName := " ";
  245. Street := " ";
  246. City := " ";
  247. State := " ";
  248. Zip := " ";
  249. Phone := " ";
  250. Balance := 0.0;
  251. END;
  252. WITH EmptyClient DO
  253. CNum := "";
  254. LName := "";
  255. FName := "";
  256. Street := "";
  257. City := "";
  258. State := "";
  259. Zip := "";
  260. Phone := "";
  261. Balance := 0.0;
  262. END;
  263. OnScreen := FALSE;
  264. END Client.
  265.