unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons,ExtCtrls;

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button4: TButton;
    Button5: TButton;
    BitBtn1: TBitBtn;
    Memo1: TMemo;
    Button3: TButton;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label4: TLabel;
    Label5: TLabel;
     procedure FormCreate(Sender: TObject);
     procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);



  private
    { Private decltarations }
  public
    { Public declarations }
  end;
Type
Ttovar=record
Naz:string[40];
kol:integer;
d:integer;
m:integer;
g:integer;
d1:integer;
m1:integer;
g1:integer;
stoim:integer;

end;
var
  Fz:file of Ttovar;
  Ft:TextFile;
  Sp:array[1..100] of Ttovar;
  mas:array[1..100] of string;
  nzap,k:integer;
  FileNameZ,FileNameT:string;
   Form1: TForm1;
   z:integer;

implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.Clear;
 Edit2.Clear;
 Edit3.Clear;
 Edit4.Clear;
 Edit5.Clear;
 Edit6.Clear;
 Edit7.Text:=IntToStr(5);
 Edit8.Text:=IntToStr(12);
 Edit9.Text:=IntToStr(10);
 Memo1.Clear;
 nzap:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Title:='Создать новый файл';
 if OpenDialog1.Execute then
 begin
 FileNameZ:=OpenDialog1.FileName;
 AssignFile(Fz,FileNameZ);
 Rewrite(Fz);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if OpenDialog1.Execute then
 begin
 FileNameZ:=OpenDialog1.FileName;
 AssignFile(Fz,FileNameZ);
 Reset(Fz);
end;
nzap:=0;
while not eof(fz) do begin
nzap:=nzap+1;
Read(fz,sp[nzap]);
with sp[nzap] do

Memo1.Lines.Add(IntToStr(nzap)+'  '+Naz+' '+IntToStr(kol)+' '+IntToStr(d)+'.'+IntToStr(m)+
'.'+IntToStr(g)+' '+IntToStr(stoim));
 end;
 end;
procedure TForm1.Button4Click(Sender: TObject);
var i:word;
 begin
 if SaveDialog1.Execute then
 begin
 FileNameT:=SaveDialog1.FileName;
 AssignFile(Ft,FileNameT);
 Rewrite(Ft);
 end;
 for i:=1 to nzap do
 with sp[i] do Write(Ft,i:4,'.',naz,stoim);
 CloseFile(Ft);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
nzap:=nzap+1;
with sp[nzap] do begin
Naz:=Edit1.Text;
kol:=StrToInt(Edit2.Text);
stoim:=StrToInt(Edit3.Text);
d:=StrToInt(Edit4.Text);
m:=StrToInt(Edit5.Text);
g:=StrToInt(Edit6.Text);
d1:=StrToInt(Edit7.Text);
m1:=StrToInt(Edit8.Text);
g1:=StrToInt(Edit9.Text);
Memo1.Lines.Add(IntToStr(d1)+'.'+IntToStr(m1)+
'.'+IntToStr(g1));
Memo1.Lines.Add(IntToStr(nzap)+'  '+naz+'   '+IntToStr(kol)+'   '+IntToStr(stoim)+
'   '+IntToStr(d)+'.'+IntToStr(m)+
'.'+IntToStr(g));

write(fz,sp[nzap]);
Edit1.Clear;Edit2.Clear;Edit3.Clear;Edit4.Clear;Edit5.Clear;Edit6.Clear;
end; end;


procedure TForm1.Button3Click(Sender: TObject);
var i,j:word;
st:Ttovar;
s:char;
n,nom: integer;
t,min:string;
begin
Memo1.Clear;
 with sp[nzap] do
 Memo1.Lines.Add(IntToStr(d1)+'.'+IntToStr(m1)+
'.'+IntToStr(g1));

for i:=0 to nzap do
 with sp[i] do begin
if ((stoim*kol) >1000000) and (((d1-d>=30)and (m1=m))
 or ((d1-d>0) and (m1-m=1)) or (m1-m>1))
 then begin

        inc(k);
        mas[k]:=naz;
      end;
end;
for i:=1 to k do
 begin
  min:=mas[i];
  nom:=i;
  for j:=i+1 to k do
  begin
     if mas[j]<min then
          begin
            min:=mas[j];
            nom:=j;
          end
  end;
 t:=mas[i];
 mas[i]:=min;
 mas[nom]:=t;
end;
memo1.Clear;
nom:=0;
for i:=1 to k do
  for z:=1 to nzap do
   with sp[z] do
     begin
       if Naz=mas[i] then
             Memo1.Lines.Add(IntToStr(i)+' '+naz+' '+IntToStr(kol)+' '+IntToStr(stoim)+
        '  '+IntToStr(d)+'.'+IntToStr(m)+'.'+IntToStr(g));
     end
  end;
end.

