unit DobavCh3;

interface

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

type
  TForm3 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label14: TLabel;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    Label15: TLabel;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    ADOQuery3: TADOQuery;
    Edit10: TEdit;
    Button3: TButton;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    Button6: TButton;
    Button7: TButton;
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Edit10KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure Edit9KeyPress(Sender: TObject; var Key: Char);
    procedure Edit8KeyPress(Sender: TObject; var Key: Char);
    procedure Edit7KeyPress(Sender: TObject; var Key: Char);
    procedure Edit6KeyPress(Sender: TObject; var Key: Char);
    procedure Edit5KeyPress(Sender: TObject; var Key: Char);
    procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);
    procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit3KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure sqlfilter();
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses Spravochniki21;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
close();
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
ADOQuery2.close;
ADOQuery2.SQL.Text:='select num_chit_b from formuliar_chitatelia2';
ADOQuery2.Open;
if not ADOQuery2.Locate('num_chit_b',strtofloat(edit1.Text),[loCaseInsensitive]) then
with ADOQuery1 do begin
Parameters.Items[0].value:=StrToFloat(trim(Label15.Caption));
Parameters.Items[1].value:=StrToFloat(trim(Edit1.Text));
Parameters.Items[2].value:=trim(edit2.Text);
Parameters.Items[3].value:=trim(Edit3.Text);
Parameters.Items[4].Value:=trim(edit4.Text);
Parameters.Items[5].value:=trim(DBEdit1.Text);
Parameters.Items[6].value:=trim(DBEdit2.Text);
Parameters.Items[7].value:=trim(Edit5.Text);
Parameters.Items[8].value:=StrToFloat(trim(Edit6.Text));
Parameters.Items[9].value:=StrToFloat(trim(Edit7.Text));
Parameters.Items[10].value:=StrToFloat(trim(Edit8.Text));
Parameters.Items[11].value:=StrToFloat(trim(Edit9.Text));
Parameters.Items[12].value:=trim(DBEdit3.Text);
execSQL;

Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';
Edit9.Text:='';
Edit1.SetFocus;
//datetimepicker1.Date:=now();  // сегоднешняя дата
 //of with
end
else
begin
messageDLG('Номер уже существует!',mtError,[mbOK],0);
edit1.SetFocus;
end;

end;

procedure TForm3.Edit1KeyPress(Sender: TObject; var Key: Char);
var
b:integer;
begin
if key=#13 then
begin
try
b:=strtoint(edit1.Text);
edit2.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit1.Text);
edit1.Text:='';
edit1.SetFocus;
end;
end;
end;

procedure TForm3.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit3.SetFocus;
end;

procedure TForm3.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit4.SetFocus;
end;

procedure TForm3.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
DBEdit1.SetFocus;
end;

procedure TForm3.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
DBEdit2.SetFocus;
end;

procedure TForm3.ComboBox2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit5.SetFocus;
end;

procedure TForm3.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit6.SetFocus;
end;

procedure TForm3.Edit6KeyPress(Sender: TObject; var Key: Char);
var
b:integer;
begin
if key=#13 then
begin
try
b:=strtoint(edit6.Text);
edit7.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit6.Text);
edit6.Text:='';
edit6.SetFocus;
end;
end;
end;

procedure TForm3.Edit7KeyPress(Sender: TObject; var Key: Char);
var
b:integer;
begin
if key=#13 then
begin
try
b:=strtoint(edit7.Text);
edit8.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit7.Text);
edit7.Text:='';
edit7.SetFocus;
end;
end;
end;

procedure TForm3.Edit8KeyPress(Sender: TObject; var Key: Char);
var
b:integer;
begin
if key=#13 then
begin
try
b:=strtoint(edit8.Text);
edit9.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit8.Text);
edit8.Text:='';
edit8.SetFocus;
end;
end;
end;

procedure TForm3.Edit9KeyPress(Sender: TObject; var Key: Char);
var
b:integer;
begin
if key=#13 then
begin
try
b:=strtoint(edit9.Text);
DBEdit3.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit9.Text);
edit9.Text:='';
edit9.SetFocus;
end;
end;
end;

procedure TForm3.FormActivate(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';
Edit9.Text:='';

ADOQuery2.Close;
ADOQuery2.SQL.Text:='select max(num)+1 from formuliar_chitatelia2';
ADOQuery2.Open;
label15.Caption:=floattostr(AdoQuery2.Fields[0].AsFloat);
ADOQuery3.Active:=true;
end;

procedure TForm3.Edit10KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
sqlfilter();
end;

procedure Tform3.sqlfilter();
begin
    ADOQuery3.SQL.Text:='select * from formuliar_chitatelia2 where 1=1 and upper(familia) Like '+''''+AnsiUpperCase(trim(Edit10.Text))+'%''';
    ADOQuery3.Open;
end;

procedure TForm3.Button3Click(Sender: TObject);
begin
Spravochniki21.Form21.DBGrid1.Visible:=true;
Spravochniki21.Form21.DBGrid2.Visible:=false;
Spravochniki21.Form21.DBGrid3.Visible:=false;
Spravochniki21.Form21.ShowModal;
end;

procedure TForm3.Button7Click(Sender: TObject);
begin
Spravochniki21.Form21.DBGrid3.Visible:=true;
Spravochniki21.Form21.DBGrid2.Visible:=false;
Spravochniki21.Form21.DBGrid1.Visible:=false;
Spravochniki21.Form21.ShowModal;
end;

procedure TForm3.Button6Click(Sender: TObject);
begin
Spravochniki21.Form21.DBGrid2.Visible:=true;
Spravochniki21.Form21.DBGrid1.Visible:=false;
Spravochniki21.Form21.DBGrid3.Visible:=false;
Spravochniki21.Form21.ShowModal;
end;

end.
