unit UExportaciones;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, DBCtrls, JvComponentBase,
  JvDBGridExport, Vcl.DBGrids, JvExDBGrids, JvDBGrid, JvDBUltimGrid;

type
  TFExportaciones = class(TForm)
    DSExportar: TDataSource;
    QExportar: TADOQuery;
    BitBtn1: TBitBtn;
    SaveDialog1: TSaveDialog;
    CheckBox1: TCheckBox;
    DBLookupComboBox1: TDBLookupComboBox;
    TArea: TADOTable;
    BitBtn2: TBitBtn;
    DSArea: TDataSource;
    CheckBox2: TCheckBox;
    DBLookupComboBox2: TDBLookupComboBox;
    TtipoEmpleo: TADOTable;
    DSTipoEmpleo: TDataSource;
    JvDBUltimGrid1: TJvDBUltimGrid;
    Excel: TJvDBGridExcelExport;
    BitBtn3: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FExportaciones: TFExportaciones;

implementation

uses Udm;

{$R *.dfm}

procedure TFExportaciones.BitBtn1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
 //ExpGrid.SaveToXLS(SaveDialog1.FileName);

 begin
   Excel.FileName :=  SaveDialog1.FileName;
   Excel.ExportGrid;
 end
end;

procedure TFExportaciones.BitBtn2Click(Sender: TObject);
 var
  cadena : String;
begin
  cadena:= 'Select * from Exportacion ';
  if (checkbox1.Checked) or (checkbox2.Checked) then
      cadena:= cadena + ' WHERE ';
  if checkbox1.Checked then
   begin
      cadena:= cadena + ' (IdArea = ' + inttostr(DBLookupComboBox1.KeyValue)+ ')';
   end;
  //showmessage(cadena);
   if checkbox2.Checked then
   begin
      if checkbox1.Checked then
        cadena:= cadena + ' AND ';
      cadena:= cadena + ' (IdTipoEmpleo = ' + inttostr(DBLookupComboBox2.KeyValue) + ')';
   end;
  //cadena:= cadena + ' ORDER BY Nombre.' + ComboBox1.Text;
  QExportar.Active:= false;
  QExportar.SQL.Clear;
  QExportar.SQL.Add(cadena);
  QExportar.Active:= true;
end;

procedure TFExportaciones.BitBtn3Click(Sender: TObject);
begin
close;
end;

procedure TFExportaciones.FormCreate(Sender: TObject);
begin
 TArea.Active:= true;
 Ttipoempleo.Active := true;
end;

end.
