unit Unit4;

interface

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

type
  TForm4 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button4: TButton;
    Button3: TButton;
    Panel2: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Button5: TButton;
    Button6: TButton;
    GroupBox1: TGroupBox;
    Label8: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Table1: TTable;
    Label2: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: 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;
    Table1PIB_kl: TStringField;
    Table1adresa: TStringField;
    Table1telefon: TStringField;
    Table1bank_kl: TStringField;
    Table1n_rachunka: TStringField;
    Table1n_svidotstva: TStringField;
    Table1edrpou: TStringField;
    Label7: TLabel;
    Label9: TLabel;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Table1AfterPost(DataSet: TDataSet);
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Aktiv(akt: boolean);
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.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;
DBEdit4.Enabled:=not akt;
DBEdit5.Enabled:=not akt;
DBEdit6.Enabled:=not akt;
DBEdit7.Enabled:=not akt;
end;

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

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

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

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

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

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

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

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

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

procedure TForm4.Edit1Change(Sender: TObject);
begin
Table1.Locate('PIB_kl',Edit1.Text,[loCaseInsensitive,loPartialKey]);
end;

end.
