IMPLEMENTATION MODULE Client; (* Copyright (C) 1988,1989 Jensen & Partners International *) IMPORT Globals, Window, IO, Str, Misc, Btree; FROM Globals IMPORT GetMenu, ItemIndex, ItemData, ClientIndex, ClientData; VAR ClientWin, lastWin : Window.WinType; OnScreen : BOOLEAN; EmptyClient, BlankClient : ClientRec; keyPressed : CHAR; PROCEDURE PressAKey( txt : ARRAY OF CHAR); VAR ch : CHAR; BEGIN Window.TextColor(Globals.PromptFore); Window.TextBackground(Globals.DisplayBack); Globals.WriteAt(9,1,txt); Window.GotoXY(30,9); ch := IO.RdKey(); Window.GotoXY(1,9); Window.ClrEol(); keyPressed := CAP(ch); END PressAKey; PROCEDURE MakeKey( keyA, myClientA : ADDRESS ); VAR key : POINTER TO Globals.FileKey; myClient : POINTER TO ClientRec; BEGIN key := keyA; myClient := myClientA; Str.Copy(key^,myClient^.CNum); END MakeKey; PROCEDURE Display( aClient : ClientRec ); (* This procedure displays the client record on the screen. *) VAR S : ARRAY[0..10] OF CHAR; ok : BOOLEAN; BEGIN Window.TextColor(Globals.DataFore); Window.TextBackground(Globals.DataBack); WITH aClient DO Globals.WriteAt(1,15,CNum); Globals.WriteAt(2,15,LName); Globals.WriteAt(2,48,FName); Globals.WriteAt(3,15,Street); Globals.WriteAt(4,15,City); Globals.WriteAt(4,48,State); Globals.WriteAt(4,62,Zip); Globals.WriteAt(6,15,Phone); Globals.WriteAt(6,55," "); Str.FixRealToStr(Balance,2,S,ok); IF ok = FALSE THEN Globals.WriteAt(6,55,"???"); ELSE Globals.WriteAt(6,55,S); END; END; END Display; PROCEDURE Clear( ); (* This procedure clears the previous client information. *) BEGIN Display(BlankClient); END Clear; PROCEDURE Template( ); (* This procedure un-hides the client display window and displays the field names. *) BEGIN lastWin := Window.Used(); Window.Use(ClientWin); Window.PutOnTop(ClientWin); Clear(); OnScreen := TRUE; END Template; PROCEDURE Input( VAR aClient : ClientRec; Clear : BOOLEAN ); (* This procedure inputs the client information from the user. If Clear is TRUE, then the information is cleared before the user enters new information. If Clear is FALSE, Display() is called first to show the current information, and it is then edited. *) VAR ok, Continue : BOOLEAN; Field : CARDINAL; ch : CHAR; S : ARRAY[0..10] OF CHAR; BEGIN IF Clear THEN aClient := EmptyClient; Display(BlankClient); END; Display(aClient); Continue := TRUE; Field := 1; WITH aClient DO WHILE (Continue) DO CASE Field OF 1: Window.GotoXY(15,1); Misc.InputStr(CNum,10); | 2: Window.GotoXY(15,2); Misc.InputStr(LName,15); | 3: Window.GotoXY(48,2); Misc.InputStr(FName,10); | 4: Window.GotoXY(15,3); Misc.InputStr(Street,25); | 5: Window.GotoXY(15,4); Misc.InputStr(City,15); | 6: Window.GotoXY(48,4); Misc.InputStr(State,2); | 7: Window.GotoXY(62,4); Misc.InputStr(Zip,5); | 8: Window.GotoXY(15,6); Misc.InputStr(Phone,13); | 9: Window.GotoXY(55,6); Str.FixRealToStr(Balance,2,S,ok); Misc.InputStr(S,10); Balance := Str.StrToReal(S,ok); END; INC(Field); IF Field >= 10 THEN Window.TextColor(Globals.PromptFore); Window.TextBackground(Globals.DisplayBack); Globals.WriteAt(8,1,"Are these ok? "); Window.GotoXY(15,8); ch := IO.RdKey(); Globals.WriteAt(8,1," "); IF CAP(ch) = 'Y' THEN Continue := FALSE; ELSE Field := 1; Window.TextColor(Globals.DataFore); Window.TextBackground(Globals.DataBack); END; END; END; END; END Input; PROCEDURE Search( VAR aClient : ClientRec ) : BOOLEAN ; (* This procedure asks the user for search information, and then searches for the given record. If it is found, it is copied to aClient, and TRUE is returned. If it is not found, FALSE is returned. *) VAR searchStr : Globals.FileKey; ch : CHAR; BEGIN Clear(); IF aClient.CNum[0] > ' ' THEN Str.Copy(searchStr,aClient.CNum); ELSE Window.GotoXY(15,1); searchStr := ""; Misc.InputStr(searchStr,10); END; IF searchStr[0] <= ' ' THEN Clear(); RETURN FALSE; END; Str.Caps(searchStr); IF Btree.Find(ClientIndex,searchStr,aClient) THEN Display(aClient); ELSE IF Btree.Search(ClientIndex,searchStr,aClient) THEN Display(aClient); REPEAT GetMenu("N)ext P)revious or T)his One? ", Globals.CharSet{'N','P','T'}, ch); CASE ch OF 'N' : IF Btree.Next(ClientIndex,aClient) THEN Clear(); Display(aClient); ELSE Globals.Beep(); END; | 'P' : IF Btree.Prev(ClientIndex,aClient) THEN Clear(); Display(aClient); ELSE Globals.Beep(); END; | 'T' : ; ELSE Globals.Beep(); END; UNTIL ch = 'T'; ELSE Globals.WriteAt(8,1,"Failed Search!"); PressAKey("Press Any Key to Continue... "); Window.TextColor(Globals.PromptFore); Window.TextBackground(Globals.DisplayBack); Globals.WriteAt(8,1," "); RETURN FALSE; END; END; PressAKey("E)dit, D)elete, or Q)uit? "); IF keyPressed = 33C THEN RETURN FALSE; ELSIF keyPressed = 'E' THEN Btree.Delete(ClientData); Input(aClient,FALSE); Btree.Add(ClientData,aClient,SIZE(aClient)); RETURN TRUE; ELSIF keyPressed = 'D' THEN Btree.Delete(ClientData); RETURN FALSE; ELSE RETURN TRUE; END; END Search; PROCEDURE Close( ); (* This procedure removes the client display window from the screen. *) BEGIN Window.Hide(ClientWin); Window.Use(lastWin); Window.PutOnTop(lastWin); OnScreen := FALSE; END Close; BEGIN ClientWin := Window.Open( Window.WinDef( 0, 4, 79, 14, Window.White,Window.Black,TRUE,FALSE,TRUE,TRUE, Window.SingleFrame,Window.White,Window.Black) ); Window.SetFrame(ClientWin,Window.SingleFrame,Globals.DisplayBorder, Globals.DisplayBack); Window.Use(ClientWin); Window.TextColor(Globals.DisplayFore); Window.TextBackground(Globals.DisplayBack); Window.Clear(); Globals.WriteAt(1,1,"Cust Number:"); Globals.WriteAt(2,1,"Last Name:"); Globals.WriteAt(2,40,"First:"); Globals.WriteAt(3,1,"Street:"); Globals.WriteAt(4,1,"City:"); Globals.WriteAt(4,40,"State:"); Globals.WriteAt(4,55,"Zip:"); Globals.WriteAt(6,1,"Phone:"); Globals.WriteAt(6,40,"Balance:"); WITH BlankClient DO CNum := " "; LName := " "; FName := " "; Street := " "; City := " "; State := " "; Zip := " "; Phone := " "; Balance := 0.0; END; WITH EmptyClient DO CNum := ""; LName := ""; FName := ""; Street := ""; City := ""; State := ""; Zip := ""; Phone := ""; Balance := 0.0; END; OnScreen := FALSE; END Client.