unit Unit14;

interface

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

type
  TForm14 = class(TForm)
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button4: TButton;
    Button3: TButton;
    Panel2: TPanel;
    Label1: TLabel;
    Label7: TLabel;
    Label3: TLabel;
    Button5: TButton;
    Button6: TButton;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    Table1: TTable;
    Table2: TTable;
    Table3: TTable;
    DataSource3: TDataSource;
    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;
    Table1id_kl: TIntegerField;
    Table1id_sp: TIntegerField;
    Table1id_zamovl: TIntegerField;
    Table1cina: TFloatField;
    DataSource4: TDataSource;
    Table4: TTable;
    Table2id: TIntegerField;
    Table2PIB_kl: TStringField;
    Table2adresa: TStringField;
    Table2telefon: TStringField;
    Table2bank_kl: TStringField;
    Table2n_rachunka: TStringField;
    Table2n_svidotstva: TStringField;
    Table2edrpou: TStringField;
    Table3id: TIntegerField;
    Table3prizvyche: TStringField;
    Table3imya: TStringField;
    Table3po_batkovi: TStringField;
    Table3data_narodsh: TDateField;
    Table3seriya_pasporta: TStringField;
    Table3nomer_pasporta: TStringField;
    Table3stat: TStringField;
    Table3index: TStringField;
    Table3adresa: TStringField;
    Table3telefon: TStringField;
    Table3ipn: TStringField;
    Table3oklad: TFloatField;
    Table3posada: TStringField;
    Table1klient: TStringField;
    Table1spivrob: TStringField;
    Table1zamovl: TStringField;
    DBLookupComboBox1: TDBLookupComboBox;
    DBLookupComboBox2: TDBLookupComboBox;
    DBLookupComboBox3: TDBLookupComboBox;
    DBEdit1: TDBEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Table1AfterPost(DataSet: TDataSet);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    procedure Aktiv (akt: boolean);
    { Public declarations }
  end;

var
  Form14: TForm14;

implementation

{$R *.dfm}

procedure TForm14.Aktiv(akt: boolean);
begin
Button1.Enabled:=akt;
Button2.Enabled:=akt;
Button3.Enabled:=akt;
Button4.Enabled:=akt;
DBGrid1.Enabled:=akt;
Button5.Enabled:=not akt;
Button6.Enabled:=not akt;
DBLookupComboBox1.Enabled:=not akt;
DBLookupComboBox2.Enabled:=not akt;
DBLookupComboBox3.Enabled:=not akt;
DBEdit1.Enabled:=not akt;
end;

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

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

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

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

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

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

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

procedure TForm14.FormActivate(Sender: TObject);
begin
Table1.Open;
Table2.Open;
Table3.Open;
Table4.Open;
Aktiv(true);
end;

procedure TForm14.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
Table2.Close;
Table3.Close;
Table4.Close;
end;

end.
