unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure BitBtn1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  type
  TSotr = record
    nomer: integer;
    FIO: string[40];
    chasi: integer;
    tarif: real;
    zarplata: extended;
  end;
var
  F1: file of TSotr;
  F2: TextFile;
  Sotr: array [1..200] of TSotr;
  N: integer;
  FileName1, FileName2: string;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  CloseFile(F1);
end;

procedure TForm1.Button1Click(Sender: TObject);var
  m: integer;
  Dop: real;
  BezNDS: real;

begin
 N:=N+1;
  Dop:=0;
  if (length(Edit1.Text)<1) or (length(Edit2.Text)<1) or (length(Edit3.Text)<1)
  or (length(Edit4.Text)<1) then
   begin
     Application.MessageBox ( 'Вы не ввели данные!!!' , 'Ошибка ввода!!!', mb_OK+MB_ICONERROR);
     exit;
   end;
  For m:=1 to  length(Edit2.Text) do
   begin
      if  not (Edit2.text[m] in ['0'..'9'])Then
          begin
            Application.MessageBox ( 'Правильно введите табельный номер!!!','Ошибка ввода!!!', mb_OK+MB_ICONERROR);
            Edit2.Clear;
            exit;
          end;
   end;
   For m:=1 to  length(Edit3.Text) do
    begin
      if  not (Edit3.text[m] in ['0'..'9'])Then
          begin
            Application.MessageBox ( 'Правильно введите количество часов!!!','Ошибка ввода!!!', mb_OK+MB_ICONERROR);
            Edit3.Clear;
            exit;
          end;
    end;
   For m:=1 to  length(Edit4.Text) do
    begin
      if  not (Edit4.text[m] in ['0'..'9',','])Then
          begin
            Application.MessageBox ( 'Правильно введите почасовой тариф!!!','Ошибка ввода!!!', mb_OK+MB_ICONERROR);
            Edit4.Clear;
            exit;
          end;
    end;
   For m:=1 to  length(Edit1.Text) do
    begin
      if  not (Edit1.text[m] in ['а'..'я','А'..'Я',' '])Then
          begin
            Application.MessageBox ( 'Правильно введите Ф.И.О.!!!','Ошибка ввода!!!', mb_OK+MB_ICONERROR);
            Edit1.Clear;
            exit;
          end;
    end;
  with Sotr[N] do
    begin
      nomer:=StrToInt(Edit2.Text);
      FIO:=Edit1.Text;
      chasi:=StrToInt(Edit3.Text);
      tarif:=StrToFloat(Edit4.Text);
      if chasi>144 then
        begin
          Dop:=(chasi-144)*2*tarif;
          BezNDS:=144*tarif+Dop;
        end
      else
        BezNDS:=chasi*tarif;
      zarplata:=0.88*BezNDS;
      Memo1.Lines.Add(IntToStr(nomer)+' '+FIO+' '+IntToStr(chasi)+ ' '+
      FloatToStr(tarif)+' '+FloatToStr(zarplata));
  end;
  Write(f1, Sotr[N]);
  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  Edit4.Text := '';

end;

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

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
OpenDialog1.Title := 'Открыть файл';
  if OpenDialog1.Execute then
    begin
      FileName1:=OpenDialog1.FileName;
      AssignFile(F1,FileName1);
      Reset(F1);
    end
  else
    exit;
  While not EOF(F1) do
    begin
      N:=N+1;
      Read(F1,Sotr[N]);
      with Sotr[N] do
        Memo1.Lines.Add(IntToStr(nomer)+' '+FIO+' '+IntToStr(chasi)+ ' '+
      FloatToStr(tarif)+' '+FloatToStr(zarplata));
    end;
    Button1.Show; 

end;

procedure TForm1.Button4Click(Sender: TObject); var  i : integer;
begin
 if SaveDialog1.Execute then
    begin
      FileName2:=SaveDialog1.FileName;
      AssignFile(F2,FileName2);
      Rewrite(F2); 
    end
  else
    exit;
  for i:=1 to N do
    with Sotr[i] do
      Writeln(F2, nomer,' ':2,FIO,' ':2,zarplata:8:2);
  CloseFile(F2);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    Memo1.Clear;
  Edit1.Text:='';
  Edit2.Text:='';
  Edit3.Text:='';
  Edit4.Text:='';
  Button1.Hide;
  N:=0;

end;

end.
