unit Unit104;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frxClass, frxFIBComponents, frxDesgn, frxExportTXT, Menus,
  ImgList, frxChBox, frxDCtrl, frxDMPExport, frxCross, frxBarcode,
  frxExportXML, frxExportHTML, frxExportImage, frxExportText, frxExportCSV,
  frxExportXLS, frxExportPDF, StdCtrls, ComCtrls, frxDBSet;

type
  TfmReportes = class(TForm)
    frxPDFExport1: TfrxPDFExport;
    frxCSVExport1: TfrxCSVExport;
    frxSimpleTextExport1: TfrxSimpleTextExport;
    frxJPEGExport1: TfrxJPEGExport;
    frxHTMLExport1: TfrxHTMLExport;
    frxXMLExport1: TfrxXMLExport;
    frxReport1: TfrxReport;
    frxBarCodeObject1: TfrxBarCodeObject;
    frxCrossObject1: TfrxCrossObject;
    frxDotMatrixExport1: TfrxDotMatrixExport;
    frxDialogControls1: TfrxDialogControls;
    frxCheckBoxObject1: TfrxCheckBoxObject;
    ImageList1: TImageList;
    ListView1: TListView;
    Button1: TButton;
    Button2: TButton;
    PopupMenu1: TPopupMenu;
    ActualizarLista1: TMenuItem;
    VistaPrevia1: TMenuItem;
    frxTXTExport1: TfrxTXTExport;
    BorrarReportes1: TMenuItem;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    frxDesigner1: TfrxDesigner;
    frxFIBComponents1: TfrxFIBComponents;
    frxXLSExport1: TfrxXLSExport;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ActualizarLista1Click(Sender: TObject);
    procedure VistaPrevia1Click(Sender: TObject);
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure Button2Click(Sender: TObject);
    procedure OrdenarAlfapeticamente1Click(Sender: TObject);
    procedure BorrarReportes1Click(Sender: TObject);
  private
  REPORTE:string;

  procedure Cargar_Files();
    { Private declarations }
  public
    { Public declarations }
    WPath:String;
  end;

var
  fmReportes: TfmReportes;

implementation

uses Unit1;



{$R *.dfm}

procedure TfmReportes.Button1Click(Sender: TObject);
Begin
//frReport1.Variables['PathToDataBase'] :=
frxReport1.DesignReport;
end;

procedure TfmReportes.FormShow(Sender: TObject);
begin


Cargar_Files();
WPath := ExtractFileDir(Application.ExeName);
  Button1.Enabled := false;
  PopupMenu1.Items.Items[0].Enabled := true;
  PopupMenu1.Items.Items[1].Enabled := false;
  PopupMenu1.Items.Items[2].Enabled := false;
end;

procedure TFmReportes.Cargar_Files();
var
  APath: string;
  MySearch: TSearchRec;
begin
ListView1.Clear;
APath := ExtractFileDir(Application.ExeName) + '\Reportes';
  FindFirst(APath+'\*.fr3', faArchive	, MySearch);
  ListView1.AddItem(MySearch.Name, TStringList.Create );
  while FindNext(MySearch)=0 do
  begin
    ListView1.AddItem(MySearch.Name, TStringList.Create );
  end;
  FindClose(MySearch);
  ListView1.SortType := stText;

end;

procedure TfmReportes.ActualizarLista1Click(Sender: TObject);
begin
Cargar_Files();
end;

procedure TfmReportes.VistaPrevia1Click(Sender: TObject);
begin

frxReport1.LoadFromFile(WPath + '\Reportes\' + REPORTE);
frxReport1.ShowReport;
end;

procedure TfmReportes.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
REPORTE := ITEM.Caption;
IF  SELECTED THEN
  begin
  Button1.Enabled := true;
//  PopupMenu1.Items.Items[0].Enabled := true;
  PopupMenu1.Items.Items[1].Enabled := true;
  PopupMenu1.Items.Items[2].Enabled := true;
  frxReport1.LoadFromFile(WPath + '\Reportes\' + REPORTE);
  Memo1.Lines := frxReport1.ReportOptions.Description;
  end
  else
  begin
  Button1.Enabled := false;
// PopupMenu1.Items.Items[0].Enabled := false;
  PopupMenu1.Items.Items[1].Enabled := false;
  PopupMenu1.Items.Items[2].Enabled := false;
  end;

end;

procedure TfmReportes.Button2Click(Sender: TObject);
begin

frxReport1.Clear;
frxReport1.DesignReport;
Cargar_Files();
end;

procedure TfmReportes.OrdenarAlfapeticamente1Click(Sender: TObject);
begin
ListView1.SortType := stText;
end;

procedure TfmReportes.BorrarReportes1Click(Sender: TObject);
begin
  if MessageDlg('Esta seguro que desea eliminar el reporte seleccionado?',
    mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
  DeleteFile(WPath+'/Reportes/'+REPORTE);
  Cargar_Files();
  end;
end;

end.
