{ (c) 1998 CREEQ <creeq@web.de> }
Program Verwaltungprogramm;
Uses Crt, MyUnit, Mouse;

CONST DataFileName = 'C:\TP\BIN\VERWALT.DAT';
      ExImportName = '\VERWALT.BUP';
      DummyName = 'DUMMY.DUM';

TYPE Eingaben = RECORD
                  PIN : String[20];
                  VName : String[20];
                  Name : String[20];
                  Adresse : String[30];
                  PLZ : String[20];
                  Ort : String[20];
                  Land : String[30];
                  GTag : String[20];
                  Tel : String[20];
                  Fax : String[20];
                  Mobil : String[20];
                  Email : String[40];
                  Bemerkungen : String[40];
               END;

Var DataFile : FILE of Eingaben;
    Searchdata : Eingaben;
    Status : Char;
    Position, Position2 : Byte;
    NewData : Eingaben;

Procedure BauHaupt;
Begin
  Startscreen('"Datenbank" Version 1.0b','Copyright (1998) by CREEQ');
  Window(3,3,31,13,'Hauptmen');
  textcolor(Black);
  MenuEintrag(5,5,'Neuer Eintrag');
  MenuEintrag(5,6,'Eintrag Suchen');
  MenuEintrag(5,7,'Eintrag ndern');
  MenuEintrag(5,8,'Eintrag Lschen');
  MenuEintrag(5,10,'Datenbank Importieren');
  MenuEintrag(5,11,'Datenbank Exportieren');
End;

Procedure Nothing;
begin
  mouse.off;
  window(26,9,54,15,'Nichts gefunden');
  textcolor(white);
  gotoxy(29,11); write('Keine Eintrge gefunden');
  button(35,13,45,13,'Zurck');
  mouse.on;
  repeat
    if getx = 224 then if gety = 64 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 96 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
  mouse.off;
  BauHaupt;
  Window(15,7,65,14,'Eintrag Suchen');
  Button(17,12,27,12,'Suchen');
  Button(51,12,61,12,'Anzeigen');
  textcolor(white);
  mouse.on;
end;

Procedure Beenden;
Begin
  Textcolor(Lightgray);
  Textbackground(Black);
  Clrscr;
{  Textcolor(Lightgray);
  Textbackground(Black);
  clrscr;
  schreibFarbtext(white,lightgray,'Thank You for using this program');}
  Delay(200);
  Textcolor(Lightgray);
  Textbackground(Black);
  Mouse.off;
  close(DataFile);
  Halt(0);
End;

Procedure Eintragen(Daten:Eingaben);
Begin
  Seek(DataFile,FileSize(DataFile));
  write(DataFile, Daten);
  mouse.off;
  window(28,9,52,15,'Besttigung');
  textcolor(white);
  gotoxy(31,11); write('Eintrag gespeichert');
  button(35,13,45,13,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 64 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 96 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Procedure NeuerEintrag;
Var Daten : Eingaben;
Begin
  mouse.off;
  Window(10,4,70,22,'Neuer Eintrag');
  Button(35,20,45,20,'Eintragen');
  textcolor(white);
  mouse.on;
  With Daten do
  begin
    gotoxy(12,6);  write('PIN         : '); readln(PIN);
    gotoxy(12,7);  write('Vorname     : '); readln(VName);
    gotoxy(12,8); write('Name        : '); readln(Name);
    gotoxy(12,9); write('Adresse     : '); readln(Adresse);
    gotoxy(12,10); write('PLZ         : '); readln(PLZ);
    gotoxy(12,11); write('Ort         : '); readln(Ort);
    gotoxy(12,12); write('Land        : '); readln(Land);
    gotoxy(12,13); write('Geburtstag  : '); readln(GTag);
    gotoxy(12,14); write('Telefon     : '); readln(Tel);
    gotoxy(12,15); write('Fax         : '); readln(Fax);
    gotoxy(12,16); write('Mobil       : '); readln(Mobil);
    gotoxy(12,17); write('Email       : '); readln(Email);
    gotoxy(12,18); write('Bemerkungen : '); readln(Bemerkungen);
  end;
  repeat
    if getx = 96 then if gety = 24 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then begin Eintragen(Daten); break; end;
  until FALSE;
End;

Procedure DeleteOK;
Begin
  mouse.off;
  window(28,8,52,14,'Besttigung');
  textcolor(white);
  gotoxy(32,10); write('Eintrag gelscht');
  button(35,12,45,12,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Procedure ChangeOK;
Begin
  mouse.off;
  window(28,8,52,14,'Besttigung');
  textcolor(white);
  gotoxy(32,10); write('Eintrag gendert');
  button(35,12,45,12,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Procedure DeleteChangeFail;
Begin
  mouse.off;
  window(27,8,53,14,'Fehler');
  textcolor(white);
  gotoxy(29,10); write('Keine Eintrge gefunden');
  button(35,12,45,12,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Function SucheEintrag(Begriff:String):Byte;
Var i, Treffer : Byte;
    Daten : Eingaben;
    Found : Boolean;
Begin
  Found := FALSE;
  Treffer := 0;
  i := 0;
  Seek(DataFile,i);
  while not EOF(DataFile) do
  Begin
    read(DataFile, Daten);
    with Daten do
    begin
      if Begriff = PIN then Found := TRUE;
      if Begriff = VName then Found := TRUE;
      if Begriff = Name then Found := TRUE;
      if Begriff = Adresse then Found := TRUE;
      if Begriff = PLZ then Found := TRUE;
      if Begriff = Ort then Found := TRUE;
      if Begriff = Land then Found := TRUE;
      if Begriff = GTag then Found := TRUE;
      if Begriff = Tel then Found := TRUE;
      if Begriff = Fax then Found := TRUE;
      if Begriff = Mobil then Found := TRUE;
      if Begriff = EMail then Found := TRUE;
      if Begriff = Bemerkungen then Found := TRUE;
    end;
    if Found = TRUE then
    begin
      inc(Treffer);
      Found := FALSE;
    end;
  end;
  SucheEintrag := Treffer;
End;

Procedure GiveEintrag(Begriff:String;wieviel:byte);
Var combien : Byte;
    Found : Boolean;
Begin
  combien := 0;
  Found := FALSE;
  Seek(DataFile,0);
  while not (combien = wieviel) do
  Begin
    read(DataFile, SearchData);
    with SearchData do
    begin
      if Begriff = PIN then Found := TRUE;
      if Begriff = VName then Found := TRUE;
      if Begriff = Name then Found := TRUE;
      if Begriff = Adresse then Found := TRUE;
      if Begriff = PLZ then Found := TRUE;
      if Begriff = Ort then Found := TRUE;
      if Begriff = Land then Found := TRUE;
      if Begriff = GTag then Found := TRUE;
      if Begriff = Tel then Found := TRUE;
      if Begriff = Fax then Found := TRUE;
      if Begriff = Mobil then Found := TRUE;
      if Begriff = EMail then Found := TRUE;
      if Begriff = Bemerkungen then Found := TRUE;
    end;
    if Found = TRUE then
    begin
      inc(combien);
      Found := FALSE;
    end;
  end;
End;

Procedure GiveAllEintrag(wieviel:byte);
Var combien : Byte;
Begin
  combien := 0;
  Seek(DataFile,0);
  while not (combien = wieviel) do
  Begin
    read(DataFile, SearchData);
    inc(combien);
  end;
End;

Procedure Clear;
Begin
  mouse.off;
  Window(10,4,70,22,'Eintrag Anzeigen');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'');
  textbackground(green);
  gotoxy(35,20); write('Neue Suche');
  textbackground(lightgray);
  textcolor(white);
  mouse.on;
End;

Function GetMax:Byte;
Var Max : Byte;
Begin
  Max := 0;
  seek(DataFile,0);
  while not EOF(DataFile) do
  begin
    read(DataFile,Searchdata);
    inc(Max);
  end;
  GetMax := Max;
End;

Procedure Clear2;
Begin
  mouse.off;
  Window(10,4,70,22,'Eintrag Lschen');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'Lschen');
  textcolor(white);
  mouse.on;
End;

Procedure Clear3;
Begin
  mouse.off;
  Window(10,4,70,22,'Eintrag ndern');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'ndern');
  textcolor(white);
  mouse.on;
End;

Procedure Zeigen;
Begin
  With SearchData do
  begin
    gotoxy(12,6);  write('PIN         : ',PIN);
    gotoxy(12,7);  write('Vorname     : ',VName);
    gotoxy(12,8); write('Name        : ',Name);
    gotoxy(12,9); write('Adresse     : ',Adresse);
    gotoxy(12,10); write('PLZ         : ',PLZ);
    gotoxy(12,11); write('Ort         : ',Ort);
    gotoxy(12,12); write('Land        : ',Land);
    gotoxy(12,13); write('Geburtstag  : ',GTag);
    gotoxy(12,14); write('Telefon     : ',Tel);
    gotoxy(12,15); write('Fax         : ',Fax);
    gotoxy(12,16); write('Mobil       : ',Mobil);
    gotoxy(12,17); write('Email       : ',EMail);
    gotoxy(12,18); write('Bemerkungen : ',Bemerkungen);
  end;
End;

Procedure TrefferAnzeigen(Begriff:String);
Begin
  Position := 1;
  mouse.off;
  Window(10,4,70,22,'Eintrag Anzeigen');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'');
  textbackground(green);
  gotoxy(35,20); write('Neue Suche');
  textbackground(lightgray);
  textcolor(white);
  mouse.on;
  GiveEintrag(Begriff,Position);
  Clear;
  Zeigen;
  repeat
    if getx = 96 then if gety = 24 then if MOUSE.Key = LEFTBUTTON then Begin Status := 'H'; break; end;
    if getx > 256 then if getx < 360 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then begin Status := 'S'; break; end;
    if getx > 440 then if getx < 536 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position < SucheEintrag(Begriff) then inc(Position)
      else Position := 1;
      GiveEintrag(Begriff,Position);
      Clear;
      Zeigen;
      delay(200);
    end;
    if getx > 80 then if getx < 176 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position > 1 then dec(Position)
      else Position := SucheEintrag(Begriff);
      GiveEintrag(Begriff,Position);
      Clear;
      Zeigen;
      delay(200);
    end;
  until FALSE;
End;

Function Gleich(Dummy:Eingaben):Boolean;
Var Pin2, Vname2, Name2, Adresse2, PLZ2, Ort2,
    Land2, Gtag2, Tel2, Fax2, Mobil2, Email2, Bemerkungen2 : String[40];
Begin
  Gleich := FALSE;
  with Dummy do
  begin
    PIN2 := PIN;
    VName2 := VName;
    Name2 := Name;
    Adresse2 := Adresse;
    PLZ2 := PLZ;
    Ort2 := Ort;
    Land2 := Land;
    GTag2 := GTag;
    Tel2 := Tel;
    Fax2 := Fax;
    Mobil2 := Mobil;
    Email2 := EMail;
    Bemerkungen2 := Bemerkungen;
  end;
  with Searchdata do if PIN2 = PIN then if VName2 = VName then
  if Name2 = Name then if Adresse2 = Adresse then if PLZ2 = PLZ then
  if Ort2 = Ort then if Land2 = Land then if GTag2 = GTag then
  if Tel2 = Tel then if Fax2 = Fax then if Mobil2 = Mobil then
  if Email2 = Email then if Bemerkungen2 = Bemerkungen then Gleich := TRUE;
End;

Procedure DeleteEintrag;
Var DummyFile : File of Eingaben;
    DummyData : Eingaben;
Begin
  Assign(DummyFile, DummyName);
  Rewrite(DummyFile);
  Seek(DataFile,0);
  Seek(DummyFile,0);
  while not EOF(DataFile) do
  begin
    read(DataFile, DummyData);
    if Gleich(DummyData) = FALSE then
    write(DummyFile, DummyData);
  end;
  Close(DataFile);
  rewrite(DataFile);
  seek(DummyFile,0);
  seek(DataFile,0);
  while not EOF(DummyFile) do
  begin
    read(DummyFile, DummyData);
    write(DataFile, DummyData);
  end;
  close(DummyFile);
  erase(DummyFile);
  DeleteOK;
End;

Procedure ChangeEintrag(NewData:Eingaben);
Var DummyFile : File of Eingaben;
    DummyData : Eingaben;
Begin
  Assign(DummyFile, DummyName);
  Rewrite(DummyFile);
  Seek(DataFile,0);
  Seek(DummyFile,0);
  while not EOF(DataFile) do
  begin
    read(DataFile, DummyData);
    if Gleich(DummyData) = TRUE then
    write(DummyFile, NewData)
    else write(DummyFile, DummyData);
  end;
  Close(DataFile);
  rewrite(DataFile);
  seek(DummyFile,0);
  seek(DataFile,0);
  while not EOF(DummyFile) do
  begin
    read(DummyFile, DummyData);
    write(DataFile, DummyData);
  end;
  close(DummyFile);
  erase(DummyFile);
  ChangeOK;
End;

Procedure AnderEintrag;
Var i : Byte;
Begin
  mouse.off;
  Window(10,4,72,22,'Eintrag ndern');
  Button(34,20,45,20,'ndern');
  textcolor(white);
  Zeigen;
  textcolor(yellow);
  for i := 6 to 18 do begin gotoxy(70,i);  write('ţ'); end;
  textcolor(white);
  mouse.on;
  delay(200);
  NewData := SearchData;
  repeat
    if getx = 96 then if gety = 24 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 256 then if getx < 360 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then begin ChangeEintrag(NewData);
                                                                                                  break; end;
    if getx = 552 then if gety = 40 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,6);  write('                                           ');
      gotoxy(26,6); with NewData do readln(PIN);
    end;
    if getx = 552 then if gety = 48 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,7);  write('                                           ');
      gotoxy(26,7); with NewData do readln(VName);
    end;
    if getx = 552 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,8);  write('                                           ');
      gotoxy(26,8); with NewData do readln(Name);
    end;
    if getx = 552 then if gety = 64 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,9);  write('                                           ');
      gotoxy(26,9); with NewData do readln(Adresse);
    end;
    if getx = 552 then if gety = 72 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,10);  write('                                           ');
      gotoxy(26,10); with NewData do readln(PLZ);
    end;
    if getx = 552 then if gety = 80 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,11);  write('                                           ');
      gotoxy(26,11); with NewData do readln(Ort);
    end;
    if getx = 552 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,12);  write('                                           ');
      gotoxy(26,12); with NewData do readln(Land);
    end;
    if getx = 552 then if gety = 96 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,13);  write('                                           ');
      gotoxy(26,13); with NewData do readln(GTag);
    end;
    if getx = 552 then if gety = 104 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,14);  write('                                           ');
      gotoxy(26,14); with NewData do readln(Tel);
    end;
    if getx = 552 then if gety = 112 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,15);  write('                                           ');
      gotoxy(26,15); with NewData do readln(Fax);
    end;
    if getx = 552 then if gety = 120 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,16);  write('                                           ');
      gotoxy(26,16); with NewData do readln(Mobil);
    end;
    if getx = 552 then if gety = 128 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,17);  write('                                           ');
      gotoxy(26,17); with NewData do readln(EMail);
    end;
    if getx = 552 then if gety = 136 then if MOUSE.Key = LEFTBUTTON then
    begin
      gotoxy(26,18);  write('                                           ');
      gotoxy(26,18); with NewData do readln(Bemerkungen);
    end;
  until FALSE;
End;

Procedure EintragLoschen;
Begin
  Position2 := 1;
  mouse.off;
  Window(10,4,70,22,'Eintrag Lschen');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'Lschen');
  textcolor(white);
  mouse.on;
  GiveAllEintrag(Position2);
  Clear2;
  Zeigen;
  repeat
    if getx = 96 then if gety = 24 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 256 then if getx < 360 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then begin DeleteEintrag; break; end;
    if getx > 440 then if getx < 536 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position2 < GetMax then inc(Position2)
      else Position2 := 1;
      GiveAllEintrag(Position2);
      Clear2;
      Zeigen;
      delay(200);
    end;
    if getx > 80 then if getx < 176 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position2 > 1 then dec(Position2)
      else Position2 := GetMax;
      GiveAllEintrag(Position2);
      Clear2;
      Zeigen;
      delay(200);
      delay(200)
    end;
  until FALSE;
End;

Procedure EintragAndern;
Begin
  Position2 := 1;
  mouse.off;
  Window(10,4,70,22,'Eintrag ndern');
  Button(12,20,22,20,'<- Zurck');
  Button(57,20,67,20,'Weiter ->');
  Button(34,20,45,20,'ndern');
  textcolor(white);
  mouse.on;
  GiveAllEintrag(Position2);
  Clear3;
  Zeigen;
  repeat
    if getx = 96 then if gety = 24 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 256 then if getx < 360 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then begin
                                                                                              AnderEintrag;
                                                                                              break;
                                                                                            end;
    if getx > 440 then if getx < 536 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position2 < GetMax then inc(Position2)
      else Position2 := 1;
      GiveAllEintrag(Position2);
      Clear3;
      Zeigen;
      delay(200);
    end;
    if getx > 80 then if getx < 176 then if gety = 152 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Position2 > 1 then dec(Position2)
      else Position2 := GetMax;
      GiveAllEintrag(Position2);
      Clear3;
      Zeigen;
      delay(200);
      delay(200)
    end;
  until FALSE;
End;

Procedure EintragSuchen;
Var Begriff : String;
    Treffer : Byte;
Begin
  Treffer := 0;
  mouse.off;
  Window(15,7,65,14,'Eintrag Suchen');
  Button(17,12,27,12,'Suchen');
  Button(51,12,61,12,'Anzeigen');
  textcolor(white);
  gotoxy(51,10); write('Treffer: ',Treffer);
  mouse.on;
  gotoxy(17,9); write('Suchen: '); readln(Begriff);
  repeat
    if getx = 136 then if gety = 48 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 392 then if getx < 488 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then
    begin
      if Treffer = 0 then
      begin
        Nothing;
        gotoxy(51,10); write('Treffer: ',Treffer);
        gotoxy(17,9); write('Suchen: '); readln(Begriff);
      end
      else
      begin
        TrefferAnzeigen(Begriff);
        if Status = 'S' then begin mouse.off; BauHaupt; mouse.on; EintragSuchen; end
        else break;
      end;
    end;
    if getx > 120 then if getx < 216 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then
    begin
      Treffer := SucheEintrag(Begriff);
      if Treffer = 0 then
      begin
        Nothing;
        gotoxy(51,10); write('Treffer: ',Treffer);
        gotoxy(17,9); write('Suchen: '); readln(Begriff);
      end
      else begin gotoxy(51,10); write('Treffer: ',Treffer); end;
    end;
    if Status = 'H' then begin Status := ' '; break; end;
  until FALSE;
End;

Procedure SaveOK;
Begin
  mouse.off;
  window(28,8,52,14,'Besttigung');
  textcolor(white);
  gotoxy(30,10); write('Datenbank Exportiert');
  button(35,12,45,12,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Procedure LoadOK;
Begin
  Status := 'H';
  mouse.off;
  window(28,8,52,14,'Besttigung');
  textcolor(white);
  gotoxy(30,10); write('Datenbank Importiert');
  button(35,12,45,12,'Okay');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then break;
  until FALSE;
End;

Procedure LoadFail;
Begin
  mouse.off;
  window(28,8,52,14,'Fehler');
  textcolor(white);
  gotoxy(30,10); write('Datei nicht gefunden');
  button(35,12,45,12,'Zurck');
  mouse.on;
  repeat
    if getx = 240 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then
    begin
      Status := 'H';
      break;
    end;
    if getx > 264 then if getx < 360 then if gety = 88 then if MOUSE.Key = LEFTBUTTON then
    begin
      Status := 'I';
      break;
    end;
  until FALSE;
End;

Procedure SaveEx(Verzeichnis:String);
Var ExImFile : File of Eingaben;
    Transfer : Eingaben;
Begin
  if existDirectory(Verzeichnis) = TRUE then
  begin
    assign(ExImFile, concat(Verzeichnis,ExImportName));
    rewrite(ExImFile);
    seek(DataFile,0);
    seek(ExImFile,0);
    while not EOF(DataFile) do
    begin
      read(DataFile, Transfer);
      write(ExImFile, Transfer);
    end;
    close(ExImFile);
  end
  else
  begin
    delete(Verzeichnis,length(Verzeichnis),1);
    mkdir(Verzeichnis);
    assign(ExImFile, concat(Verzeichnis,ExImportName));
    rewrite(ExImFile);
    seek(DataFile,0);
    seek(ExImFile,0);
    while not EOF(DataFile) do
    begin
      read(DataFile, Transfer);
      write(ExImFile, Transfer);
    end;
    close(ExImFile);
  end;
  SaveOK;
End;

Procedure LoadIm(Verzeichnis:String);
Var ExImFile : File of Eingaben;
    Transfer : Eingaben;
Begin
  delete(Verzeichnis,length(Verzeichnis),1);
  if ExistFile(Concat(Verzeichnis,ExImportName)) = TRUE then
  begin
    assign(ExImFile, concat(Verzeichnis,ExImportName));
    reset(ExImFile);
    close(DataFile);
    rewrite(DataFile);
    seek(DataFile,0);
    seek(ExImFile,0);
    while not EOF(ExImFile) do
    begin
      read(ExImFile, Transfer);
      write(DataFile, Transfer);
    end;
    close(ExImFile);
    LoadOK;
  end
  else LoadFail;
End;

Procedure DataExport;
Var Verzeichnis : String;
Begin
  mouse.off;
  Window(15,7,65,16,'Datenbank Exportieren');
  gotoxy(17,9); write('In welches Verzeichnis soll die Datenbank');
  gotoxy(17,10); write('exportiert werden? (z.B.: C:\BACKUP\)');
  Button(34,14,46,14,'Exportieren');
  mouse.on;
  textcolor(white);
  gotoxy(17,12); write('Verzeichnis: '); readln(Verzeichnis);
  repeat
    if getx = 136 then if gety = 48 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 256 then if getx < 368 then if gety = 104 then if MOUSE.Key = LEFTBUTTON then begin
                                                                                              SaveEx(Verzeichnis);
                                                                                              break;
                                                                                            end;
  until FALSE;
End;

Procedure DataImport;
Var Verzeichnis : String;
Begin
  mouse.off;
  Window(15,7,65,16,'Datenbank Importieren');
  gotoxy(17,9); write('Aus welchem Verzeichnis soll die Datenbank');
  gotoxy(17,10); write('importiert werden? (z.B.: C:\BACKUP\)');
  Button(34,14,46,14,'Importieren');
  mouse.on;
  textcolor(white);
  gotoxy(17,12); write('Verzeichnis: '); readln(Verzeichnis);
  repeat
    if getx = 136 then if gety = 48 then if MOUSE.Key = LEFTBUTTON then break;
    if getx > 256 then if getx < 368 then if gety = 104 then if MOUSE.Key = LEFTBUTTON then begin
                                                                                              LoadIm(Verzeichnis);
                                                                                              if Status = 'I' then DataImport;
                                                                                              break;
                                                                                            end;
  until FALSE;
End;

Procedure Hauptmenu;
Begin
  BauHaupt;
  Mouse.on;
  repeat
    if getx = 40 then if gety = 16 then if MOUSE.Key = LEFTBUTTON then Beenden;
    if getx = 32 then if gety = 32 then if MOUSE.Key = LEFTBUTTON then begin NeuerEintrag; mouse.off; Hauptmenu; end;
    if getx = 32 then if gety = 40 then if MOUSE.Key = LEFTBUTTON then begin EintragSuchen; mouse.off; Hauptmenu; end;
    if getx = 32 then if gety = 56 then if MOUSE.Key = LEFTBUTTON then
    begin
      if FileSize(DataFile) = 0 then DeleteChangeFail
      else EintragLoschen;
      mouse.off;
      Hauptmenu;
    end;
    if getx = 32 then if gety = 48 then if MOUSE.Key = LEFTBUTTON then
    begin
      if FileSize(DataFile) = 0 then DeleteChangeFail
      else EintragAndern;
      mouse.off;
      Hauptmenu;
    end;
    if getx = 32 then if gety = 72 then if MOUSE.Key = LEFTBUTTON then begin DataImport; mouse.off; Hauptmenu; end;
    if getx = 32 then if gety = 80 then if MOUSE.Key = LEFTBUTTON then begin DataExport; mouse.off; Hauptmenu; end;
  until FALSE;
End;

Begin
  Assign(DataFile, DataFileName);
  if ExistFile(DataFileName) then reset(DataFile)
  else rewrite(DataFile);
  Mouse.init;
  Hauptmenu;
End.
