program Database;

uses crt;

type
    PPolozka = ^TPolozka;
    TPolozka = record
            id : integer;
            material : string[25];
            dod : string[45];
            next : PPolozka;
          end;
    IndexPolozek = record
            id : integer;
            mat : string[40];
          end;

var
    Karta, AktualniKarta : PPolozka;
    Databaze : file of TPolozka;
    Index : array[0..100]of IndexPolozek;
    moz : char;
    i,j,posledni_cislo_databaze : integer;


procedure Zalozeni;
begin
  assign(Databaze,'Data.dta');
  rewrite(Databaze);
  close(Databaze);
  new(Karta);
  AktualniKarta := Karta;
  Karta^.id := 0;
  Karta^.material := ' ';
  Karta^.dod := ' ';
  Karta^.next := nil
end;

procedure Aktualizace;
var pom : array[1..2]of IndexPolozek;
    PomKarta2 : PPolozka;
    poc: integer;
begin
  PomKarta2 := AktualniKarta^.next;
  for i:= 0 to 100 do
  begin
    Index[i].id := -1;
    Index[i].mat := 'ώ';
  end;
  poc := 0;
  while (PomKarta2 <> nil) do
  begin
    Index[poc].mat := PomKarta2^.material;
    Index[poc].id := PomKarta2^.id;
    posledni_cislo_databaze := poc;
    poc := poc + 1;
    PomKarta2 := PomKarta2^.next;
  end;
  for i := 0 to poc do
    for j := 0 to poc-1 do
      if (Index[j].mat > Index[j+1].mat) then
      begin
        pom[1] := Index[j];
        Index[j] := Index[j+1];
        Index[j+1] := pom[1];
      end;
end;

procedure formular1;
begin
  textcolor(white);
  clrscr;
  writeln('Cislo Nazev                       Dodavatel                            ');
end;

procedure formular3;
begin
  textcolor(white);
  clrscr; gotoxy(1,8);
  writeln('                  ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
  writeln('                  Ί        Vlozte nazev materialu :          Ί');
  writeln('                  Ί                                          Ί');
  writeln('                  Ί                                          Ί');
  writeln('                  Ί           a zmacknete ENTER              Ί');
  writeln('                  Ί                                          Ί');
  writeln('                  Ί    Zobrazi se Vam cela skladova karta    Ί');
  writeln('                  Ί   a Vy se rozhodnete, zda chcete kartu   Ί');
  writeln('                  Ί             vyradit nebo ne.             Ί');
  writeln('                  ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
  textcolor(lightred);
  gotoxy(31,11); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
  gotoxy(31,13); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
end;

procedure formular4;
begin
  textcolor(white);
  clrscr; gotoxy(1,8);
  writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
  writeln('                    Ί      Vlozte nazev materialu :        Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί         a zmacknete ENTER            Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί  Zobrazi se Vam cela skladova karta  Ί');
  writeln('                    Ί  a Vy se rozhodnete, zda tato karta  Ί');
  writeln('                    Ί     je spravne vybrana nebo ne.      Ί');
  writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
  textcolor(lightred);
  gotoxy(31,11); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
  gotoxy(31,13); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
end;

procedure formular5;
begin
  textcolor(white);
  clrscr; gotoxy(1,8);
  writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
  writeln('                    Ί      Vlozte nazev materialu :        Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί         a zmacknete ENTER            Ί');
  writeln('                    Ί                                      Ί');
  writeln('                    Ί  Zobrazi se Vam cela skladova karta  Ί');
  writeln('                    Ί  a Vy se rozhodnete, zda tuto kartu  Ί');
  writeln('                    Ί     chcete modifikovat nebo ne.      Ί');
  writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
  textcolor(lightred);
  gotoxy(31,11); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
  gotoxy(31,13); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
end;


procedure ProhlizeniIndexu;
var i : integer;
begin
  clrscr; gotoxy(1,1);
  writeln('     ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΛΝΝΝΝΝΝΝΝΝΝ»');
  writeln('     Ί Material :                                Ί Pozice : Ί');
  writeln('     ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΚΝΝΝΝΝΝΝΝΝΝΌ');
  textcolor(white);
  j := 0;
  for i:=0 to 100 do
    if Index[i].id <> -1 then
    begin
      gotoxy(8,4+j); write(Index[i].mat);
      gotoxy(52,4+j); write(Index[i].id);
      j := j + 1;
    end;
  textcolor(3);
  gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
  readln;
end;

procedure Vlozeni;
var moz1: char;
    pomid: integer;
    PomKarta: PPolozka;
    Duplicita: boolean;
begin
  repeat
    formular1;
    Duplicita := false;
    gotoxy(1,4); readln(pomid);
    PomKarta := AktualniKarta;
    while (PomKarta <> nil) do
    begin
      if PomKarta^.id = pomid then
      begin
        Duplicita := true;
        textcolor(lightred);
        gotoxy(1,20);
        writeln('           ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
        writeln('           Ί Identifikacni cislo jiz existuje. Pouzijte jine. Ί');
        writeln('           ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
        gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
        readln;
        textcolor(white);
        clrscr;
      end;
      PomKarta := PomKarta^.next;
    end;
  until not(Duplicita);
  new(Karta^.next);
  Karta := Karta^.next;
  Karta^.id := pomid;
  gotoxy(7,4); readln(Karta^.material);
  gotoxy(35,4); readln(Karta^.dod);
  Karta^.next := nil;
  repeat
    textbackground(black);
    textcolor(lightred);
    gotoxy(1,20);
    writeln('           ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
    writeln('           Ί Chcete zalozit dalsi novou kartu materialu ? A/N Ί');
    writeln('           ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
    gotoxy(80,24);
    textcolor(white);
    moz1 := readkey;
    moz1 := upcase(moz1);
    if moz1 in ['A','N'] then
      case moz1 of
      'A':begin
            repeat
              formular1;
              Duplicita := false;
              gotoxy(1,4); readln(pomid);
              PomKarta := AktualniKarta;
              while (PomKarta <> nil) do
              begin
                if PomKarta^.id = pomid then
                begin
                  Duplicita := true;
                  textcolor(lightred);
                  gotoxy(1,20);
                  writeln('           ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
                  writeln('           Ί Identifikacni cislo jiz existuje. Pouzijte jine. Ί');
                  writeln('           ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
                  gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
                  readln;
                  textcolor(white);
                  clrscr;
                end;
                PomKarta := PomKarta^.next;
              end;
            until not(Duplicita);
            new(Karta^.next);
            Karta := Karta^.next;
            Karta^.id := pomid;
            gotoxy(7,4); readln(Karta^.material);
            gotoxy(35,4); readln(Karta^.dod);
            Karta^.next := nil;
          end;
      end;
  until moz1='N';
end;

procedure Prohlizeni;
var PomKarta : PPolozka;
    pomic3: string;
    pomic4: integer;

begin
  clrscr;
  formular1;
  PomKarta := AktualniKarta^.next;
  i := -1;
  while (pomKarta <> nil) do
  begin
    textcolor(3);
    gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
    textcolor(yellow);
    i := i + 1;
    gotoxy(1,i+3); write(PomKarta^.id:5);
    gotoxy(7,i+3); write(PomKarta^.material);
    gotoxy(35,i+3); write(PomKarta^.dod);
    PomKarta := PomKarta^.next;
    gotoxy(80,24);
  end;
  readln;
end;

procedure Prohlizeni_setridene;
var PomKarta : PPolozka;
    pomic3: string;
    pomic4: integer;
begin
  clrscr;
  formular1;
  for i:=0 to 100 do
  begin
    PomKarta := AktualniKarta;
    if Index[i].id <> -1 then
    begin
      pomic3 := Index[i].mat;
      pomic4 := Index[i].id;
      repeat
        PomKarta := PomKarta^.next;
      until ((pomic3 = PomKarta^.material) and (pomic4 = PomKarta^.id));
      textcolor(3);
      gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
      textcolor(yellow);
      gotoxy(1,i+3); write(PomKarta^.id:5);
      gotoxy(7,i+3); write(PomKarta^.material);
      gotoxy(35,i+3); write(PomKarta^.dod);
      gotoxy(80,24);
    end;
  end;
  readln;
end;

procedure Mazani;
var pomic3: string;
    pomic4: integer;
    nalezeno: boolean;
    moz2: char;
    PomKarta3, PK1, PK2 : PPolozka;
begin
  clrscr;
  formular3;
  textcolor(yellow);
  gotoxy(21,10); readln(pomic3);
  nalezeno := false;
  i := -1;
  PomKarta3 := AktualniKarta;
  repeat
    i := i + 1;
    if pomic3 = Index[i].mat then
    begin
      pomic4 := Index[i].id;
      repeat
        PomKarta3 := PomKarta3^.next;
      until ((pomic3 = PomKarta3^.material) and (pomic4 = PomKarta3^.id));
      clrscr;
      nalezeno := true;
      formular1;
      textcolor(yellow);
      gotoxy(1,4); write(PomKarta3^.id);
      gotoxy(7,4); write(PomKarta3^.material);
      gotoxy(35,4); write(PomKarta3^.dod);
      textcolor(lightred);
      gotoxy(1,20);
      writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
      writeln('              Ί Chcete tuto kartu materialu vyradit ?  A/N  Ί');
      writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
      moz2 := readkey;
      moz2 := upcase(moz2);
      if moz2 in ['A','N'] then
        case moz2 of
        'A':begin
              PK1 := AktualniKarta;
              while PK1 <> nil do
              begin
                if ((pomic3 = PK1^.next^.material) and
                    (pomic4 = PK1^.next^.id)) then
                begin
                  PK2 := PK1^.next;
                  PK1^.next := PK2^.next;
                  dispose(PK2);
                end;
                PK1 := PK1^.next;
              end;
              textcolor(white);
              clrscr; gotoxy(1,8);
              writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί            Material byl              Ί');
              writeln('                    Ί         z databaze vyrazen.          Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί           Stisknete ENTER            Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
              textcolor(lightred);
              gotoxy(31,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
              i := 100;
              readln;
            end;
        'N':begin
              textcolor(white);
              clrscr; gotoxy(1,8);
              writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί            Material zustal           Ί');
              writeln('                    Ί           v databazi ulozen.         Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί            Stisknete ENTER           Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    Ί                                      Ί');
              writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
              textcolor(lightred);
              gotoxy(31,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
              readln;
            end;
        end;
    end;
    if (nalezeno = false) and (i = 100) then
    begin
      textcolor(white);
      clrscr; gotoxy(1,8);
      writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
      writeln('                    Ί                                      Ί');
      writeln('                    Ί            Material neni             Ί');
      writeln('                    Ί             v databazi.              Ί');
      writeln('                    Ί                                      Ί');
      writeln('                    Ί           Stisknete ENTER            Ί');
      writeln('                    Ί                                      Ί');
      writeln('                    Ί                                      Ί');
      writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
      textcolor(lightred);
      gotoxy(32,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
      readln;
    end;
  until (i=100);
end;

procedure Hledani;
var nalezeno, potvrzeno: boolean;
    moz3: char;
    pomic3: string;
    pomic4: integer;
    PomKarta4 : PPolozka;
begin
  clrscr;
  formular4;
  textcolor(yellow);
  gotoxy(25,10); readln(pomic3);
  nalezeno := false; potvrzeno := false;
  i := -1;
  PomKarta4 := AktualniKarta;
  repeat
    i := i + 1;
    if pomic3 = Index[i].mat then
    begin
      pomic4 := Index[i].id;
      repeat
        PomKarta4 := PomKarta4^.next;
      until ((pomic3 = PomKarta4^.material) and (pomic4 = PomKarta4^.id));
      clrscr;
      nalezeno := true;
      formular1;
      textcolor(yellow);
      gotoxy(1,4); write(PomKarta4^.id);
      gotoxy(7,4); write(PomKarta4^.material);
      gotoxy(35,4); write(PomKarta4^.dod);
      textcolor(lightred);
      gotoxy(1,20);
      writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
      writeln('              Ί   Je tato karta materialu spravna ?   A/N   Ί');
      writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
      moz3 := readkey;
      moz3 := upcase(moz3);
      if moz3 in ['A','N'] then
        case moz3 of
        'A':begin
              potvrzeno := true;
              textcolor(3);
              gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
              textcolor(black);
              gotoxy(1,20);
              writeln('                                                             ');
              writeln('                                                             ');
              writeln('                                                             ');
              i := 100;
              readln;
            end;
        end;
    end;
  if (nalezeno = false) and (i=100) then
  begin
    textcolor(white);
    clrscr; gotoxy(1,8);
    writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί     Material s timto nazvem neni     Ί');
    writeln('                    Ί             v databazi.              Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί           Stisknete ENTER            Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
    textcolor(lightred);
    gotoxy(32,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
    readln;
  end;
  if (nalezeno = true) and (potvrzeno = false) and (i=100) then
  begin
    textcolor(white);
    clrscr; gotoxy(1,8);
    writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί   Jiny material s timto nazvem neni  Ί');
    writeln('                    Ί             v databazi.              Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί           Stisknete ENTER            Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
    textcolor(lightred);
    gotoxy(32,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
    readln;
  end;
  until (i=100);
end;

procedure Modifikace;
var nalezeno, potvrzeno: boolean;
    moz3, moz4: char;
    pomic3: string;
    pomic4: integer;
    PomKarta4, PK : PPolozka;
    pomid: integer;
    Duplicita: boolean;
begin
  clrscr;
  formular5;
  textcolor(yellow);
  gotoxy(25,10); readln(pomic3);
  nalezeno := false; potvrzeno := false;
  i := -1;
  PomKarta4 := AktualniKarta;
  repeat
    i := i + 1;
    if pomic3 = Index[i].mat then
    begin
      pomic4 := Index[i].id;
      repeat
        PomKarta4 := PomKarta4^.next;
      until ((pomic3 = PomKarta4^.material) and (pomic4 = PomKarta4^.id));
      clrscr;
      nalezeno := true;
      formular1;
      textcolor(yellow);
      gotoxy(1,4); write(PomKarta4^.id);
      gotoxy(7,4); write(PomKarta4^.material);
      gotoxy(35,4); write(PomKarta4^.dod);
      textcolor(lightred);
      gotoxy(1,20);
      writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
      writeln('              Ί   Je tato karta materialu spravna ?   A/N   Ί');
      writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
      moz3 := readkey;
      moz3 := upcase(moz3);
      if moz3 in ['A','N'] then
        case moz3 of
        'A':begin
              textcolor(3);
              gotoxy(1,17);
              writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
              writeln('              Ί   Vyberte, ktery udaj chcete modifikovat :  Ί');
              writeln('              Ί          Cislo materialu       -- 1         Ί');
              writeln('              Ί          Nazev materialu       -- 2         Ί');
              writeln('              Ί          Dodavatel             -- 3         Ί');
              writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
              moz4 := readkey;
              formular1;
              if moz4 in ['1','2','3'] then
              case moz4 of
                '1': begin
                       repeat
                         Duplicita := false;
                         textcolor(white);
                         gotoxy(7,4); write(PomKarta4^.material);
                         gotoxy(35,4); write(PomKarta4^.dod);
                         gotoxy(1,4); readln(pomid);
                         PK := AktualniKarta;
                         while (PK <> nil) do
                         begin
                           if PK^.id = pomid then
                           begin
                             Duplicita := true;
                             textcolor(lightred);
                             gotoxy(1,20);
                             writeln('           ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
                             writeln('           Ί Identifikacni cislo jiz existuje. Pouzijte jine. Ί');
                             writeln('           ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
                             gotoxy(20,24); write('Pokracujte stiskem klavesy ENTER.');
                             readln;
                             textcolor(white);
                             clrscr;
                             formular1;
                           end;
                           PK := PK^.next;
                         end;
                       until not(Duplicita);
                       PomKarta4^.id := pomid;
                       textbackground(black);
                       potvrzeno := true;
                       textcolor(3);
                       gotoxy(1,17);
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
                       writeln('              Ί       Modifinovana data byla ulozena.       Ί');
                       writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
                       gotoxy(22,24); write('Pokracujte stiskem klavesy ENTER.');
                       textcolor(black);
                       i := 100;
                       readln;
                     end;
                '2': begin
                       textcolor(white);
                       textbackground(green);
                       gotoxy(1,4); write(PomKarta4^.id);
                       gotoxy(35,4); write(PomKarta4^.dod);
                       gotoxy(7,4); readln(PomKarta4^.material);
                       textbackground(black);
                       potvrzeno := true;
                       textcolor(3);
                       gotoxy(1,17);
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
                       writeln('              Ί       Modifinovana data byla ulozena.       Ί');
                       writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
                       gotoxy(22,24); write('Pokracujte stiskem klavesy ENTER.');
                       textcolor(black);
                       i := 100;
                       readln;
                     end;
                '3': begin
                       textcolor(white);
                       textbackground(green);
                       gotoxy(1,4); write(PomKarta4^.id);
                       gotoxy(7,4); write(PomKarta4^.material);
                       gotoxy(35,4); readln(PomKarta4^.dod);
                       textbackground(black);
                       potvrzeno := true;
                       textcolor(3);
                       gotoxy(1,17);
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('                                                              ');
                       writeln('              ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
                       writeln('              Ί       Modifinovana data byla ulozena.       Ί');
                       writeln('              ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
                       gotoxy(22,24); write('Pokracujte stiskem klavesy ENTER.');
                       textcolor(black);
                       i := 100;
                       readln;
                     end;
                end;
            end;
        end;
    end;
  if (nalezeno = false) and (i=100) then
  begin
    textcolor(white);
    clrscr; gotoxy(1,8);
    writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί     Material s timto nazvem neni     Ί');
    writeln('                    Ί             v databazi.              Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί           Stisknete ENTER            Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
    textcolor(lightred);
    gotoxy(32,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
    readln;
  end;
  if (nalezeno = true) and (potvrzeno = false) and (i=100) then
  begin
    textcolor(white);
    clrscr; gotoxy(1,8);
    writeln('                    ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί   Jiny material s timto nazvem neni  Ί');
    writeln('                    Ί             v databazi.              Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί           Stisknete ENTER            Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    Ί                                      Ί');
    writeln('                    ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ');
    textcolor(lightred);
    gotoxy(32,12); writeln('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
    readln;
  end;
  until (i=100);
end;


procedure Inicializace_Seznamu;
var poc: integer;
begin
  assign(Databaze,'Data.dta');
  reset(Databaze);
{  seek(Databaze,0);}
  new(Karta);
  AktualniKarta := Karta;
  Karta^.id := 0;
  Karta^.material := ' ';
  Karta^.dod := ' ';
  if not(eof(Databaze)) then
  begin
    read(Databaze,Karta^);
    while not(eof(Databaze)) do begin
      new(Karta^.next);
      read(Databaze,Karta^.next^);
      Karta := Karta^.next;
    end;
  end;
  Karta^.next := nil;
  close(Databaze);
end;

procedure Ulozeni_Seznamu;
begin
  assign(Databaze,'Data.dta');
  rewrite(Databaze);
  while (AktualniKarta <> nil) do
  begin
    write(Databaze,AktualniKarta^);
    AktualniKarta := AktualniKarta^.next;
  end;
  close(Databaze);
end;



BEGIN
  Inicializace_Seznamu;
  Clrscr;
  repeat
    Aktualizace;
    textcolor(lightred);
    clrscr;
    gotoxy(32,3); write('Evidence skladu');
    gotoxy(32,4); write('***************');
    textcolor(white);
    gotoxy(33,7); write('Zakladni menu');
    gotoxy(20,10); write('Vlozeni noveho materialu        : ');
    gotoxy(20,11); write('Vyrazeni materialu              : ');
    gotoxy(20,12); write('Modifikace materialu            : ');
    gotoxy(20,13); write('Vyhledani materialu podle nazvu : ');
    gotoxy(20,14); write('Prohlizeni databaze             : ');
    gotoxy(20,15); write('Prohlizeni setridene databaze   : ');
    gotoxy(20,16); write('Prohlizeni indexoveho souboru   : ');
    gotoxy(20,17); write('Konec prace s programem         : ');
    textcolor(lightred);
    gotoxy(20,18); write('ΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ');
    textcolor(white);
    gotoxy(20,19); write('Zalozeni noveho databazoveho souboru :');
    textcolor(lightgreen);
    gotoxy(60,10); write('-- 1');
    gotoxy(60,11); write('-- 2');
    gotoxy(60,12); write('-- 3');
    gotoxy(60,13); write('-- 4');
    gotoxy(60,14); write('-- 5');
    gotoxy(60,15); write('-- 6');
    gotoxy(60,16); write('-- 7');
    gotoxy(60,17); write('-- 8');
    gotoxy(60,19); write('-- D');
    gotoxy(80,24);
  moz := readkey;
  if moz in ['1','2','3','4','5','6','7','8','D','d'] then
    case moz of
          '1': Vlozeni;
          '2': Mazani;
          '3': Modifikace;
          '4': Hledani;
          '5': Prohlizeni;
          '6': Prohlizeni_setridene;
          '7': ProhlizeniIndexu;
      'D','d': Zalozeni;
    end;
  until moz='8';
  Ulozeni_Seznamu;
END.