Uses crt,dos; Type TDate = record Year : word; Mounth : word; Day : word; end; TPilet = record PType : string[6]; PSubType : string[10]; Number : word; Price : real; Date : TDate; end; Const MenuBar : array[1..4] of string = ('MUUK','KASUM','ANDMEBAAS','VALJA'); MenuBarX : array[1..4] of byte = (5,16,29,46); SubMenu1 : array[1..3] of string = ('Laste','Opilas','Tais'); SubMenu1Y : array[1..3] of byte = (3,4,5); SubMenu2 : array[1..2] of string = ('paevapilet','kuupilet'); SubMenu2Y : array[1..2] of byte = (6,7); Var Data_Base : file of TPilet; Form : text; Pilet : TPilet; ch : char; Last_number : word; Function Get_last_number : word;forward; procedure View;forward; Procedure SubMenu2Draw;forward; function Sub_Menu2 : boolean;forward; Procedure SubMenu1Draw;forward; Procedure Sub_Menu1;forward; Procedure Profit(FromD,ToD : TDate);forward; Procedure Inquiry;forward; Procedure Print;forward; Procedure Output_file;forward; Procedure Servad;forward; Procedure MenuItemDeactivate(x,y:integer;Name:string); begin Servad; textbackground(0); gotoxy(x,y); write(Name); end; Procedure MenuItemActivate(x,y:integer;Name:string); begin Servad; textbackground(9); gotoxy(x,y); write(Name); textbackground(0); end; Procedure MenuBarDraw; var i : integer; begin Servad; textbackground(0); textcolor(7); clrscr; for i := 1 to 4 do begin gotoxy(MenuBarX[i],10); write(MenuBar[i]); end; end; Procedure Menu_Bar; var i : integer; key : char; begin i := 1; repeat MenuBarDraw; MenuItemActivate(MenuBarX[i],10,MenuBar[i]); key := readkey; case key of #75: begin MenuItemDeactivate(MenuBarX[i],10,MenuBar[i]); if i = 1 then i := 4 else i:=i-1; MenuItemActivate(MenuBarX[i],10,MenuBar[i]); end; #77: begin MenuItemDeactivate(MenuBarX[i],10,MenuBar[i]); if i = 4 then i := 1 else i:=i+1; MenuItemActivate(MenuBarX[i],10,MenuBar[i]); end; #13: begin MenuItemDeactivate(MenuBarX[i],10,MenuBar[i]); if i = 1 then Sub_Menu1; if i = 2 then Inquiry; if i = 3 then Output_file; if i = 4 then exit; end; end; until (i=4) and (key=#13) end; Procedure SubMenu1Draw; var i : integer; begin for i := 1 to 3 do begin gotoxy(2,SubMenu1Y[i]); write(SubMenu1[i]); end; end; Procedure Sub_Menu1; var i : integer; key : char; succes : boolean; begin i := 1; repeat SubMenu1Draw; MenuItemActivate(2,SubMenu1Y[i],SubMenu1[i]); key := readkey; case key of #72: begin MenuItemDeactivate(2,SubMenu1Y[i],SubMenu1[i]); if i = 1 then i := 3 else i:=i-1; MenuItemActivate(2,SubMenu1Y[i],SubMenu1[i]); end; #80: begin MenuItemDeactivate(2,SubMenu1Y[i],SubMenu1[i]); if i = 3 then i := 1 else i:=i+1; MenuItemActivate(2,SubMenu1Y[i],SubMenu1[i]); end; #13: begin Pilet.PType:=SubMenu1[i]; succes := Sub_Menu2; if succes = True then exit; end; end; until (key=#27) end; Procedure SubMenu2Draw; var i : integer; begin for i := 1 to 2 do begin gotoxy(9,SubMenu2Y[i]); write(SubMenu2[i]); end; end; function Sub_Menu2 : boolean; var i : integer; key : char; begin i := 1; repeat SubMenu2Draw; MenuItemActivate(9,SubMenu2Y[i],SubMenu2[i]); key := readkey; case key of #72: begin MenuItemDeactivate(9,SubMenu2Y[i],SubMenu2[i]); if i = 1 then i := 2 else dec(i); MenuItemActivate(9,SubMenu2Y[i],SubMenu2[i]); end; #80: begin MenuItemDeactivate(9,SubMenu2Y[i],SubMenu2[i]); if i = 2 then i := 1 else inc(i); MenuItemActivate(9,SubMenu2Y[i],SubMenu2[i]); end; #27: begin MenuItemDeactivate(9,SubMenu2Y[i],SubMenu2[i]); textcolor(0); for i:=1 to 2 do begin gotoxy(9,SubMenu2Y[i]); write(SubMenu2[i]); end; textcolor(7); Sub_Menu2 := False; exit; end; #13: begin Pilet.PSubType:=SubMenu2[i]; View; Sub_Menu2 := True; exit; end; end; until (key=#27) end; procedure View; var x,y:byte; D_of_W:word; begin Last_number := Get_last_number; Last_number:=Last_number+1; PIlet.Number:=Last_number; if (Pilet.PType = 'Laste') and (Pilet.PSubType = 'paevapilet') then Pilet.Price:=1; if (Pilet.PType = 'Laste') and (Pilet.PSubType = 'kuupilet') then Pilet.Price:=10; if (Pilet.PType = 'Opilas') and (Pilet.PSubType = 'paevapilet') then Pilet.Price:=2; if (Pilet.PType = 'Opilas') and (Pilet.PSubType = 'kuupilet') then Pilet.Price:=20; if (Pilet.PType = 'Tais') and (Pilet.PSubType = 'paevapilet') then Pilet.Price:=10; if (Pilet.PType = 'Tais') and (Pilet.PSubType = 'kuupilet') then Pilet.Price:=70; clrscr; gotoxy(10,8); write('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); for y:=9 to 14 do begin gotoxy(10,y); write('º º'); end; gotoxy(10,y+1); write('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); gotoxy(17,9); write('Tallinna loomaaed'); gotoxy(12,10); write('Pileti nr: ',Pilet.Number); gotoxy(20,11); write(Pilet.PType); gotoxy(18,12); write(Pilet.PSubType); gotoxy(12,13); write('Hind: ',Pilet.Price:5:2); with Pilet.Date do GetDate(Year,Mounth,Day,D_of_w); gotoxy(12,14); with Pilet.Date do write('Kuupaev: ',Day,'/',Mounth,'/',Year); seek(Data_Base,filesize(Data_Base)); write(Data_Base,Pilet); Print; readkey; clrscr; end; Procedure Print; begin append(Form); writeln(Form,'ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); writeln(Form,'º Tallinna loomaaed º'); writeln(Form,'º Pileti nr: ',Pilet.Number:5, ' º'); writeln(Form,'º',Pilet.PType:15,' º'); writeln(Form,'º',Pilet.PSubType:17,' º'); writeln(Form,'º Hind: ',Pilet.Price:6:2,' º'); with Pilet.Date do writeln(Form,'º Kuupaev: ',Day:2,'/',Mounth:2,'/',Year:4,' º'); writeln(Form,'ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); writeln(Form,'--------------------------------'); end; Function Get_last_number : word; var Temp : TPilet; begin reset(Data_Base); if filesize(Data_Base) = 0 then Get_last_number := 0 else begin seek(Data_Base,filesize(Data_Base)-1); read(Data_Base,Temp); Get_last_number := Temp.Number; end; end; Procedure Output_file; var key : char; flag : boolean; begin reset(Data_Base); clrscr; while Not eof(Data_Base) do begin clrscr; with Pilet do begin read(Data_Base,Pilet); writeln('ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»'); writeln('º Tallinna loomaaed º'); writeln('º Pileti nr: ',Pilet.Number:5, ' º'); writeln('º',Pilet.PType:15,' º'); writeln('º',Pilet.PSubType:17,' º'); writeln('º Hind: ',Pilet.Price:6:2,' º'); with Pilet.Date do writeln('º Kuupaev: ',Day:2,'/',Mounth:2,'/',Year:4,' º'); writeln('ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'); end; flag := true; writeln('Vajutage et lopetada labivaatus voi moni muu klahvi et jatkata'); key := readkey; if (key = #27) then exit; end; if flag = false then begin writeln('Andmebaas on tuhi'); readkey; end; end; Procedure Profit(FromD,ToD : TDate); var Sum : real; Find : boolean; begin reset(Data_Base); Sum := 0; while Not eof(Data_Base) do begin read(Data_Base,Pilet); with Pilet.Date do begin Find:= (Year >= FromD.Year) and (Year <= ToD.Year) and (Mounth >= FromD.Mounth) and (Mounth <= ToD.Mounth) and (Day >= FromD.Day) and (Day <= ToD.Day); if Find = True then Sum := Sum + Pilet.Price; end; end; gotoxy(10,13); Writeln('Kasum : ',Sum:12:2); readln; clrscr; end; Procedure Inquiry; var FromD,ToD : TDate; begin clrscr; {$I-} repeat gotoxy(10,10); clreol; write('Paevast (pp kk aaaa): '); with FromD do readln(Day,Mounth,Year); until IOResult = 0; repeat gotoxy(10,11); clreol; write('Kuni paevani (pp kk aaaa): '); with ToD do readln(Day,Mounth,Year); until IOResult = 0; {$I+} Profit(FromD,ToD); end; Procedure Servad; var i,j:integer; begin textbackground(9); for i:=1 to 80 do begin gotoxy(i,1);write(' '); gotoxy(i,24);write(' '); end; for j:=1 to 24 do begin gotoxy(1,j); write(' '); gotoxy(80,j);write(' '); end; textbackground(black); end; Begin clrscr; assign(Data_Base,'DataBase.dat'); {$I-} reset(Data_Base); if IOResult <> 0 then begin Rewrite(Data_Base); if IOResult <> 0 then writeln('Ei saa avada faili'); end; {$I+} assign(Form,'Print.txt'); {$I-} reset(Form); if IOResult <> 0 then begin Rewrite(Form); if IOResult <> 0 then writeln('Ei saa avada faili'); end; {$I+} Menu_Bar; close(Data_Base); close(Form); end.