unit Unit7;

interface

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

type
  TForm7 = class(TForm)
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    Button2: TButton;
    Button4: TButton;
    Button3: TButton;
    Panel2: TPanel;
    Label2: TLabel;
    Button5: TButton;
    Button6: TButton;
    DataSource1: TDataSource;
    Table1: TTable;
    DBEdit1: 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;
    Table1obsyag: TIntegerField;
    Table1pr: TStringField;
    procedure FormActivate(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Table1AfterPost(DataSet: TDataSet);
  private
    { Private declarations }
  public
    procedure Aktiv(akt: boolean);
      { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

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

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

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

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

procedure TForm7.Button3Click(Sender: TObject);
begin
close;
end;

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

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

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

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

end.
