unit UExportaciones;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, BaseGrid, AdvGrid, DBAdvGrd,
  DBCtrls;

type
  TFExportaciones = class(TForm)
    DSExportar: TDataSource;
    QExportar: TADOQuery;
    ExpGrid: TDBAdvStringGrid;
    BitBtn1: TBitBtn;
    SaveDialog1: TSaveDialog;
    CheckBox1: TCheckBox;
    DBLookupComboBox1: TDBLookupComboBox;
    TArea: TADOTable;
    BitBtn2: TBitBtn;
    Label1: TLabel;
    ComboBox1: TComboBox;
    DSArea: TDataSource;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormCreate(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);
end;

procedure TFExportaciones.BitBtn2Click(Sender: TObject);
 var
  cadena : String;
begin
  cadena:= 'Select Personal.Nombre + '+ chr(39) + ' ' + chr(39)+ '+ Personal.Apaterno +'+ chr(39) + ' ' + chr(39)+ '+ Personal.AMaterno AS Empleado, Personal.Calle, Personal.[No], Personal.Colonia, Personal.CP, Personal.Titulo, CatPuestos.Puesto, CatProgramas.Programa, CatAreas.Area, TipoEmpleo.TipoEmpleo, ' +
  ' Personal.FechaAlta, Personal.RFC FROM (((Personal LEFT JOIN CatPuestos ON Personal.Puesto = CatPuestos.ide) LEFT JOIN CatProgramas ON Personal.Programa = CatProgramas.ide) LEFT JOIN ' +
  ' TipoEmpleo ON Personal.TipoEmpleo = TipoEmpleo.ide) LEFT JOIN CatAreas ON Personal.Area = CatAreas.ide';
  if checkbox1.Checked then
   begin
      cadena:= cadena + ' Where Personal.Area = ' + inttostr(DBLookupComboBox1.KeyValue)
   end;
  cadena:= cadena + ' ORDER BY personal.' + ComboBox1.Text;
  //showmessage(cadena);
  QExportar.Active:= false;
  QExportar.SQL.Clear;
  QExportar.SQL.Add(cadena);
  QExportar.Active:= true;
end;

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

end.
