unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, StdCtrls, Mask, DBCtrls, jpeg, ExtCtrls, Grids,
  DBGrids;

type
  TForm5 = class(TForm)
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button4: TButton;
    Button3: TButton;
    Panel2: TPanel;
    Label1: TLabel;
    Button5: TButton;
    Button6: TButton;
    DataSource1: TDataSource;
    Label7: TLabel;
    Label3: TLabel;
    Table1: TTable;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Query1: TQuery;
    Query1id_sp: TIntegerField;
    Query1PIB: TStringField;
    Query1Dani_pasporta: TStringField;
    Query1Ident_kod: TStringField;
    Query1Adresa: TStringField;
    Query1Telefon: TStringField;
    Query1Data_vlasht: TDateField;
    Query1Id_vid: TIntegerField;
    Query1Posada: TStringField;
    Query1Oklad: TFloatField;
    Query1Stat: TStringField;
    Table1id: TIntegerField;
    Table1nazva: TStringField;
    Table1marka: TStringField;
    Table1od_vumiru: TStringField;
    DBEdit3: TDBEdit;
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Table1AfterPost(DataSet: TDataSet);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Aktiv(akt: boolean);
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.Aktiv(akt: boolean);
begin
DBGrid1.Enabled:=akt;
Button1.Enabled:=akt;
Button2.Enabled:=akt;
Button3.Enabled:=akt;
Button4.Enabled:=akt;
Button5.Enabled:= not akt;
Button6.Enabled:= not akt;
DBEdit1.Enabled:=not akt;
DBEdit2.Enabled:=not akt;
DBEdit3.Enabled:=not akt;
end;

procedure TForm5.FormActivate(Sender: TObject);
begin
Table1.Open;
Aktiv(true);
end;

procedure TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
end;

procedure TForm5.Table1AfterPost(DataSet: TDataSet);
begin
Table1.Close;
Table1.Open;
Table1.Last;
end;

procedure TForm5.Button1Click(Sender: TObject);
begin
Table1.Append();
Aktiv(false);
DBEdit1.SetFocus();
end;

procedure TForm5.Button2Click(Sender: TObject);
begin
if Table1.IsEmpty then
exit;
Table1.Edit();
Aktiv(false);
DBEdit1.SetFocus();
end;

procedure TForm5.Button4Click(Sender: TObject);
begin
if Application.Messagebox('Ви дійсно хочете видалити запис?','Видалення',
MB_YESNO+MB_IconQuestion)= mrYes
then Table1.Delete();
end;

procedure TForm5.Button3Click(Sender: TObject);
begin
Close;
end;

procedure TForm5.Button5Click(Sender: TObject);
begin
Table1.post();
Aktiv(true);
Button1.SetFocus();
end;

procedure TForm5.Button6Click(Sender: TObject);
begin
Table1.Cancel();
Aktiv(true);
DBGrid1.SetFocus();
end;

end.
