MODULE Club; (* Copyright (C) 1988,1989 Jensen & Partners International *) IMPORT Globals, Btree, Window, Client, Items, IO, FIO, Sales; FROM Globals IMPORT ClientFile, ItemFile, ClientData, ItemData, ClientIndex, ItemIndex, oldWin, TitleWin, DisplayWin, UpdateTitle, StoreName; VAR aClient : Client.ClientRec; anItem : Items.ItemRec; ch, ch2, ch3 : CHAR; GO, Found : BOOLEAN; lines : CARDINAL; PROCEDURE OpenClientFiles(); BEGIN IF NOT FIO.Exists("CLIENT.DAT") THEN (* create a new one *) ClientFile := Btree.Open("CLIENT.DAT",2,Btree.FixSize,FALSE,FALSE,TRUE); ClientData := Btree.OpenData(ClientFile,1,SIZE(Client.ClientRec),TRUE); ClientIndex := Btree.OpenIndex(ClientFile,ClientData,2,Globals.Compare, Client.MakeKey,SIZE(Globals.FileKey), TRUE,TRUE); Btree.Close(ClientFile); END; (* if *) ClientFile := Btree.Open("CLIENT.DAT",2,Btree.FixSize,FALSE,FALSE,FALSE); ClientData := Btree.OpenData(ClientFile,1,SIZE(Client.ClientRec),FALSE); ClientIndex := Btree.OpenIndex(ClientFile,ClientData,2,Globals.Compare, Client.MakeKey,SIZE(Globals.FileKey),TRUE, FALSE); END OpenClientFiles; PROCEDURE OpenItemFiles(); BEGIN IF NOT FIO.Exists("ITEMS.DAT") THEN (* create a new one *) ItemFile := Btree.Open("ITEMS.DAT",2,Btree.FixSize,FALSE,FALSE,TRUE); ItemData := Btree.OpenData(ItemFile,1,SIZE(Items.ItemRec),TRUE); ItemIndex := Btree.OpenIndex(ItemFile,ItemData,2,Globals.Compare, Items.MakeKey,SIZE(Globals.FileKey),TRUE, TRUE); Btree.Close(ItemFile); END; (* if *) ItemFile := Btree.Open("ITEMS.DAT",2,Btree.FixSize,FALSE,FALSE,FALSE); ItemData := Btree.OpenData(ItemFile,1,SIZE(Items.ItemRec),FALSE); ItemIndex := Btree.OpenIndex(ItemFile,ItemData,2,Globals.Compare, Items.MakeKey,SIZE(Globals.FileKey),TRUE, FALSE); END OpenItemFiles; PROCEDURE Help(); CONST HelpWinDef = Window.WinDef(10,7,70,17,Window.Blue,Window.LightGray, FALSE, TRUE, TRUE, TRUE, Window.DoubleFrame, Window.Black, Window.LightGray); VAR helpWin : Window.WinType; ch : CHAR; BEGIN oldWin := Window.Used(); helpWin := Window.Open(HelpWinDef); Window.Use(helpWin); Window.Clear(); Window.SetTitle(helpWin,"Help Window", Window.CenterUpperTitle); Window.PutOnTop(helpWin); IO.WrLn(); IO.WrLn(); IO.WrStr(" This is the help window. If you would like to"); IO.WrLn(); IO.WrStr(" change the help, look in the Help() routine in"); IO.WrLn(); IO.WrStr(" the main CLUB.MOD file."); IO.WrLn(); IO.WrLn(); IO.WrLn(); IO.WrStr(" Press any key to continue... "); Window.CursorOn(); ch := IO.RdKey(); Window.CursorOff(); Window.Close(helpWin); Window.Use(oldWin); Window.PutOnTop(oldWin); END Help; BEGIN (* main program *) StoreName := "Btree Demonstration Store"; Window.PutOnTop(TitleWin); UpdateTitle(TRUE); OpenClientFiles(); OpenItemFiles(); REPEAT Globals.GetMenu("Help Clients Inventory Sales Quit >>", Globals.CharSet{'H','C','I','S','Q'}, ch ); CASE ch OF 'H' : Help(); | 'C' : Client.Template(); REPEAT Globals.GetMenu( "Add Find/edit/delete List Quit >>", Globals.CharSet{'A','F','E','D','L','Q'}, ch2); CASE ch2 OF 'A' : Client.Input(aClient,TRUE); Btree.Add(ClientData,aClient, SIZE(Client.ClientRec)); | 'F', 'E', 'D' : aClient.CNum := ""; Found := Client.Search(aClient); | 'L' : oldWin := Window.Used(); Window.Use(DisplayWin); Window.Clear(); Window.PutOnTop(DisplayWin); lines := 0; (* max 17 *) Btree.Reset(ClientData); GO := TRUE; WHILE Btree.Next(ClientIndex,aClient) AND GO DO IO.WrStrAdj(aClient.CNum,-11); IO.WrStrAdj(aClient.LName,-16); IO.WrStrAdj(aClient.FName,-11); IO.WrStrAdj(aClient.Phone,-16); IO.WrLn(); INC(lines); IF lines > 16 THEN IO.WrStr("Press to quit, any other key to continue: "); ch3 := IO.RdKey(); IF ch3 = 33C THEN GO := FALSE; END; (* if *) Window.Clear(); lines := 0; END; (* if *) END; (* while *) Globals.WriteAt(18,1,"Press a key to finish "); ch3 := IO.RdKey(); Window.Hide(DisplayWin); Window.Use(oldWin); Window.PutOnTop(oldWin); | 'Q' : Client.Close(); END; (* case *) UNTIL ch2 = 'Q'; | 'I' : Items.Template(); REPEAT Globals.GetMenu( "Add Find/edit/delete List Quit >>", Globals.CharSet{'A','F','E','D','L','Q'}, ch2); CASE ch2 OF 'A' : Items.Input(anItem,TRUE); Btree.Add(ItemData,anItem,SIZE(Items.ItemRec)); | 'F','E','D' : anItem.INum := ""; Found := Items.Search(anItem); | 'L' : oldWin := Window.Used(); Window.Use(DisplayWin); Window.Clear(); Window.PutOnTop(DisplayWin); lines := 0; (* max 17 *) Btree.Reset(ItemData); GO := TRUE; WHILE Btree.Next(ItemIndex,anItem) AND GO DO IO.WrStrAdj(anItem.INum,-11); IO.WrStrAdj(anItem.Description,-26); IO.WrStrAdj(anItem.Mfgr,-21); IO.WrStrAdj(anItem.PartNum,-11); IO.WrLn(); INC(lines); IF lines > 16 THEN IO.WrStr("Press to quit, any other key to continue: "); ch3 := IO.RdKey(); IF ch3 = 33C THEN GO := FALSE; END; (* if *) Window.Clear(); lines := 0; END; (* if *) END; (* while *) Globals.WriteAt(18,1,"Press a key to finish "); ch3 := IO.RdKey(); Window.Hide(DisplayWin); Window.Use(oldWin); Window.PutOnTop(oldWin); | 'Q' : Items.Close(); END; (* case *) UNTIL ch2 = 'Q'; | 'S' : (* run the sales floor *) Sales.Template(); REPEAT Sales.Clear(); (* clear old transaction *) Globals.GetMenu( "A)nother sale, S)how summary, or Q)uit to Menu", Globals.CharSet{'A','Q','S'},ch2); CASE ch2 OF 'A' : Sales.Work(); | 'S' : Sales.Summary(); ELSE Globals.Beep(); END; (* case *) UNTIL ch2 = 'Q'; Sales.Close(); ELSE Globals.Beep(); END; (* case *) UNTIL ch = 'Q'; Btree.Close(ClientFile); Btree.Close(ItemFile); Window.CursorOn; END Club.