unit Knigi19;

interface

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

type
  TForm19 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button3: TButton;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    Button5: TButton;
    Button6: TButton;
    DBGrid1: TDBGrid;
    Label3: TLabel;
    Edit3: TEdit;
    RadioGroup1: TRadioGroup;
    Label1: TLabel;
    Sum_L: TLabel;
    BitBtn1: TBitBtn;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    procedure Edit3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button5MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button6MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Edit3KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form19: TForm19;

implementation

uses DobavK2, UdalK9, RedaktK7, ProsmK5, Menu1;

{$R *.dfm}

procedure TForm19.Button3Click(Sender: TObject);
begin
RedaktK7.form7.showModal;
end;

procedure TForm19.Button1Click(Sender: TObject);
begin
Close();
end;

procedure TForm19.Button5Click(Sender: TObject);
begin
ProsmK5.form5.showModal;
end;

procedure TForm19.Button6Click(Sender: TObject);
var
excel, list, data,shapka,dp: variant;
i,j,ii,jj:integer;
begin
Knigi19.form19.ADOQuery2.open;
ii:= Knigi19.form19.ADOQuery2.RecordCount;
jj:=Knigi19.form19.ADOQuery2.FieldCount;
excel:=createoleobject('excel.application');
excel.workBooks.add;
Data:=vararraycreate([1,ii,1,jj],varvariant);
Knigi19.form19.ADOQuery2.First;
for i:=1 to ii do
begin
for j:=1 to jj do
begin
data[i,j]:=Knigi19.form19.ADOQuery2.Fields[j-1].AsString;
end;
Knigi19.form19.ADOQuery2.Next;
end;
Shapka:= varArrayCreate([1,jj],varvariant);
for i:=1 to jj do
shapka[i]:= Knigi19.form19.DBGrid1.Columns[i-1].Title.caption;;
list:=excel.worksheets[1];
Dp:=list.range[list.cells[3,2],list.cells[3,jj]];
begin
list.name:='Книжный фонд';
list.rows[1].font.size:=14;
list.range['b1'].value:='Книги';
Dp.value:=shapka;
Dp:=list.range[list.cells[4,2],list.cells[3+ii,jj]];
Dp.value:=Data;
for i:=1 to jj do
if i<>2 then
list.columns.item[i].autofit;
list.columns[2].columnwidth:=16 ;
list.range[list.cells[3,2],list.cells[ii+3,jj]].borders.linestyle:=1;
excel.visible:=true;
end;
end;

procedure TForm19.FormActivate(Sender: TObject);
begin
ADOQuery2.Open;
radiogroup1.ItemIndex:=0;
end;

procedure TForm19.Edit3KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
case radiogroup1.ItemIndex of
0:  begin
  ADOQuery2.SQL.Text:='select * from inventarnaia_kniga1 where 1=1 and upper(fam_avtor) Like '+''''+AnsiUpperCase(trim(Edit3.Text))+'%''';
    ADOQuery2.Open;
    end;
1:  begin
  ADOQuery2.SQL.Text:='select * from inventarnaia_kniga1 where 1=1 and upper(nazvanie) Like '+''''+AnsiUpperCase(trim(Edit3.Text))+'%''';
    ADOQuery2.Open;
    end;
end;
end;

procedure TForm19.RadioGroup1Click(Sender: TObject);
begin
edit3.SetFocus;
end;

procedure TForm19.Button6MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Menu1.form1.StatusBar1.Panels[0].Text:='Для перевода информации из таблицы в Excel ' ;
end;

procedure TForm19.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Книжный фонд';
end;

procedure TForm19.Button4MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Добавление в книжный фонд';
end;

procedure TForm19.Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Удаление из книжного фонда';
end;

procedure TForm19.Button3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Редактирование книжного фонда';
end;

procedure TForm19.Button5MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Подробный просмотр информации о книге из книжном фонда';
end;

procedure TForm19.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Закрытие книжного фонда';
end;

procedure TForm19.BitBtn1Click(Sender: TObject);
begin
UdalK9.form9.showModal;
end;

procedure TForm19.SpeedButton2Click(Sender: TObject);
begin
Dobavk2.Form2.ShowModal;
end;

procedure TForm19.SpeedButton3Click(Sender: TObject);
begin
Form2.ADOQuery3.Close;
Form2.ADOQuery3.SQL.Text:='select sum(cena) from inventarnaia_kniga1';
Form2.ADOQuery3.Open;
Form2.ADOQuery2.Active:=true;
Sum_l.Caption:=floattostr(Form2.AdoQuery3.Fields[0].AsFloat);
end;

procedure TForm19.Edit3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
form1.StatusBar1.Panels[0].Text:='Поле для поиска книг';
end;

end.
