unit Otchot122;

interface

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

type
  TForm22 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    DateTimePicker2: TDateTimePicker;
    Edit1: TEdit;
    Button3: TButton;
    Button4: TButton;
    Button2: TButton;
    Button5: TButton;
    procedure Button5Click(Sender: TObject);
    procedure Button4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DateTimePicker2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form22: TForm22;

implementation

uses Menu1;

{$R *.dfm}


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




procedure TForm22.Button3Click(Sender: TObject);
begin
edit1.Text:=datetostr(DateTimePicker2.datetime);
AdoQuery1.Close;

ADOQuery1.SQL.Text:='select * from vidacha_knig31 where 1=1 and upper(data_vid) Like '+''''+AnsiUpperCase(trim(Edit1.Text))+'%''';

AdoQuery1.Open;
end;

procedure TForm22.Button4Click(Sender: TObject);
var
excel, list, data,shapka,dp: variant;
i,j,ii,jj:integer;
begin
Otchot122.form22.ADOQuery1.open;
ii:= Otchot122.form22.ADOQuery1.RecordCount;
jj:=Otchot122.form22.ADOQuery1.FieldCount;
excel:=createoleobject('excel.application');;
excel.workBooks.add;
Data:=vararraycreate([1,ii,1,jj],varvariant);
Otchot122.form22.ADOQuery1.First;
for i:=1 to ii do
begin
for j:=1 to jj do
begin
data[i,j]:=Otchot122.form22.ADOQuery1.Fields[j-1].AsString;
end;
Otchot122.form22.ADOQuery1.Next;
end;
Shapka:= varArrayCreate([1,jj],varvariant);
for i:=1 to jj do
shapka[i]:= Otchot122.form22.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 TForm22.Button2Click(Sender: TObject);
begin
Otchot122.Form22.Print;
end;

procedure TForm22.FormActivate(Sender: TObject);
begin
ADOQuery1.Open;
end;

procedure TForm22.DateTimePicker2Click(Sender: TObject);
begin
edit1.Text:=datetostr(DateTimePicker2.datetime);
end;

procedure TForm22.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
edit1.Text:=datetostr(DateTimePicker2.datetime);
AdoQuery1.Close;
ADOQuery1.SQL.Text:='select * from vidacha_knig31 where 1=1 and upper(data_vid) Like '+''''+AnsiUpperCase(trim(Edit1.Text))+'%''';
AdoQuery1.Open;
end;

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

procedure TForm22.Button5Click(Sender: TObject);
begin
edit1.Text:='';
AdoQuery1.Close;
ADOQuery1.SQL.Text:='select * from vidacha_knig31 where 1=1 and upper(data_vid) Like '+''''+AnsiUpperCase(trim(Edit1.Text))+'%''';
AdoQuery1.Open;
end;

end.
