Загрузка данных


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    RadioGroup1: TRadioGroup;
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
    Edit5: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Memo1: TMemo;
    OpenDialog1: TOpenDialog;

    procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Edit4Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);

  private
  public
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 // ComboBox1.ItemIndex := 0;
  //RadioGroup1.Caption := 'Îáðàçîâàíèå';
  if FileExists('Spets.txt') then
    ComboBox1.Items.LoadFromFile('Spets.txt');
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
  x: TextFile;
begin
  if Key = #13 then
  begin
    if Trim(ComboBox1.Text) <> '' then
      if ComboBox1.Items.IndexOf(ComboBox1.Text) = -1 then
        ComboBox1.Items.Add(ComboBox1.Text);

    ComboBox1.Text := '';
    Key := #0;
  end;
  AssignFile(x, 'Spets.txt');
  if FileExists('Spets.txt') then
    Append(x)
  else
    Rewrite(x);

  WriteLn(x,
  'ÑÏÅÖÈÀËÜÍÎÑÒÜ: ' + ComboBox1.Text);
  CloseFile(x);
  ComboBox1.Items.SaveToFile('Spets.txt');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  F: TextFile;
  Obr: string;
begin
 if RadioGroup1.ItemIndex >= 0 then
    Obr := RadioGroup1.Items[RadioGroup1.ItemIndex]
  else
    Obr := '';

  if (Trim(Edit1.Text) = '') or
    (Trim(Edit2.Text) = '') or
    (Trim(Edit3.Text) = '') or
    (Trim(Edit4.Text) = '') then
  begin
    ShowMessage('Îøèáêà! Çàïîëíèòå âñå çíà÷åíèÿ');
    Exit;
    begin
    if ComboBox1.Text <> '' then
    begin
      ComboBox1.Items.Add(ComboBox1.Text);
      ComboBox1.Items.SaveToFile('Spets.txt');
      ComboBox1.Items.LoadFromFile('Spets.txt');
      end;
    end;
  end;

  AssignFile(F, 'Sotrud.txt');

  if FileExists('Sotrud.txt') then
    Append(F)
  else
    Rewrite(F);

  WriteLn(F,
    'ÔÈÎ: ' + Edit1.Text + ' ' + Edit2.Text + ' ' + Edit3.Text +
    '; Ä.Ð.: ' + Edit4.Text +
    '; ÀÄÐÅÑ: ' + StringReplace(Memo1.Text, #13#10, ', ', [rfReplaceAll]) +
    '; ÎÁÐÀÇÎÂÀÍÈÅ: ' + Obr +
    '; ÑÏÅÖÈÀËÜÍÎÑÒÜ: ' + ComboBox1.Text
  );
  CloseFile(F);

  ShowMessage('Äàííûå ñîõðàíåíû â ôàéë Sotrud.txt');
  ComboBox1.Items.SaveToFile('Spets.txt');
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Edit5.Text := TimeToStr(Time);
end;

procedure TForm1.Edit4Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Edit4.Text := S;
end;

end.