unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label16: TLabel;
    Label18: TLabel;
    Button5: TButton;
    Button6: TButton;
    GroupBox1: TGroupBox;
    Label12: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Button7: TButton;
    Button8: TButton;
    Edit2: TEdit;
    DBGrid1: TDBGrid;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    DataSource1: TDataSource;
    Query1: TQuery;
    Database1: TDatabase;
    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;
    Edit3: TEdit;
    Table1: TTable;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit10: TDBEdit;
    ComboBox2: TComboBox;
    Table1id: TIntegerField;
    Table1prizvyche: TStringField;
    Table1imya: TStringField;
    Table1po_batkovi: TStringField;
    Table1data_narodsh: TDateField;
    Table1seriya_pasporta: TStringField;
    Table1nomer_pasporta: TStringField;
    Table1stat: TStringField;
    Table1index: TStringField;
    Table1adresa: TStringField;
    Table1telefon: TStringField;
    Table1ipn: TStringField;
    Table1oklad: TFloatField;
    Table1posada: TStringField;
    Edit1: TEdit;
    Label2: TLabel;
    Label5: TLabel;
    DBEdit9: TDBEdit;
    DBEdit11: TDBEdit;
    Label8: TLabel;
    DBEdit12: TDBEdit;
    Label13: TLabel;
    Label17: TLabel;
    DBEdit13: TDBEdit;
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    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 Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ComboBox2CloseUp(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Aktiv (akt: boolean);
  end;

var
  Form2: TForm2;
implementation

{$R *.dfm}

procedure TForm2.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;
DBEdit9.Enabled:=not akt;
DBEdit10.Enabled:=not akt;
DBEdit11.Enabled:=not akt;
DBEdit12.Enabled:=not akt;
DBEdit13.Enabled:=not akt;
end;

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

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

procedure TForm2.Button1Click(Sender: TObject);
begin
Table1.Append();
Aktiv(false);
DBEdit8.Visible:=false;
ComboBox2.Visible:=true;
DBEdit1.SetFocus();
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
if Table1.IsEmpty then
exit;
Table1.Edit();
DBEdit8.Visible:=false;
ComboBox2.Visible:=true;
Aktiv(false);
DBEdit1.SetFocus();
end;

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

procedure TForm2.Button5Click(Sender: TObject);
begin
Table1.post();
Aktiv(true);
DBEdit8.Visible:=true;
ComboBox2.Visible:=false;
Button1.SetFocus();
end;

procedure TForm2.Button6Click(Sender: TObject);
begin
Table1.Cancel();
Aktiv(true);
DBEdit8.Visible:=true;
ComboBox2.Visible:=false;
DBGrid1.SetFocus();
end;

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

procedure TForm2.Button7Click(Sender: TObject);
begin
Table1.Filtered:=true;
Button7.Enabled:=false;
end;

procedure TForm2.Button8Click(Sender: TObject);
begin
Table1.Filtered:=false;
Edit1.Text:='введіть прізвище';
Button7.Enabled:=true;
end;

procedure TForm2.Edit2Change(Sender: TObject);
begin
Edit3.Text:='введіть посаду';
Table1.Locate('prizvyche',Edit2.Text,[loCaseInsensitive,loPartialKey]);
end;

procedure TForm2.Edit3Change(Sender: TObject);
begin
Edit2.Text:='введіть прізвище';
Table1.Locate('posada',Edit3.Text,[loCaseInsensitive,loPartialKey]);
end;

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

procedure TForm2.ComboBox2CloseUp(Sender: TObject);
begin
Table1stat.AsString:=ComboBox2.Text;
end;

procedure TForm2.Edit1Change(Sender: TObject);
begin
Table1.Filter:='prizvyche = '+QuotedStr(Edit1.Text);
end;

end.
