unit DobavK2;

interface

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

type
  TForm2 = 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;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    DateTimePicker1: TDateTimePicker;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    Edit11: TEdit;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    Label13: TLabel;
    DataSource3: TDataSource;
    ADOQuery3: TADOQuery;
    DataSource4: TDataSource;
    ADOQuery4: TADOQuery;
    Label11: TLabel;
    Edit9: TEdit;


    procedure FormActivate(Sender: TObject);
    procedure Edit11KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Edit9KeyPress(Sender: TObject; var Key: Char);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(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 Edit3KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure DateTimePicker1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure sqlfilter();
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Knigi19;

{$R *.dfm}

procedure Tform2.sqlfilter();
begin
    ADOQuery2.SQL.Text:='select * from inventarnaia_kniga1 where 1=1 and upper(fam_avtor) Like '+''''+AnsiUpperCase(trim(Edit11.Text))+'%''';
    ADOQuery2.Open;
end;



procedure TForm2.Button2Click(Sender: TObject);
 begin
 ADOQuery3.Close;
ADOQuery3.SQL.Text:='select inv_nomer from inventarnaia_kniga1';
ADOQuery3.Open;
if not ADOQuery3.Locate('inv_nomer',strtofloat(edit2.Text),[loCaseInsensitive]) then
begin
ADOQuery3.Close;
if messageDLG('Вы действительно хотите добавить запись?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
with ADOQuery1 do begin
Parameters.Items[0].value:=StrToFloat(trim(label13.Caption));
Parameters.Items[1].value:=StrToFloat(trim(Edit1.Text));
Parameters.Items[2].value:=DateTimePicker1.Date;
Parameters.Items[3].value:=StrToFloat(trim(Edit2.Text));
Parameters.Items[4].Value:=trim(Edit3.Text);
Parameters.Items[5].value:=trim(Edit4.Text);
Parameters.Items[6].value:=trim(Edit5.Text);
Parameters.Items[7].value:=trim(Edit6.Text);
Parameters.Items[8].value:=StrToFloat(trim(Edit7.Text));
Parameters.Items[9].value:=StrToFloat(trim(Edit8.Text));
Parameters.Items[10].value:=0;
execSQL;
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';
Edit9.Text:='';
datetimepicker1.Date:=now();  // сегоднешняя дата
Form19.ADOQuery2.Close;
Form19.ADOQuery2.Open;
end; //of with
end else   begin
messageDLG('Номер уже существует!',mtError,[mbOK],0);
edit2.SetFocus;
end;
end;

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


procedure TForm2.DateTimePicker1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit2.SetFocus;
end;

procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
var
rez:string;
a:integer;
begin
if key=#13 then
begin
try
a:=strtoint(edit1.Text);
DateTimePicker1.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit1.Text);
edit1.Text:='';
edit1.SetFocus;
end;
end;
end;
{
procedure TForm2.Edit10KeyPress(Sender: TObject; var Key: Char);
var
a:integer;
begin
if key=#13 then
begin
try
a:=strtoint(edit10.Text);
edit1.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit10.Text);
edit10.Text:='';
edit10.SetFocus;
end;
end;

end; }

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

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

procedure TForm2.Edit6KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit7.SetFocus;
end;

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

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

procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
var
a:integer;
begin
if key=#13 then
begin
try
a:=strtoint(edit2.Text);
Edit3.SetFocus;
except
ShowMessage('Ошибка'+#13+'ввода'+edit2.Text);
edit2.Text:='';
edit2.SetFocus;
begin
ADOQuery3.Close;
ADOQuery3.SQL.Text:='select inv_nomer from inventarnaia_kniga1';
ADOQuery3.Open;
if not ADOQuery2.Locate('inv_nomer',strtofloat(edit1.Text),[loCaseInsensitive]) then
edit3.SetFocus else
begin
messageDLG('Номер уже существует!',mtError,[mbOK],0);
edit2.SetFocus;
end;
end;
end;
end;
end;

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

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

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



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

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

end.

