{ RRRRRR                  ReportBuilder Class Library                  BBBBB
  RR   RR                                                              BB   BB
  RRRRRR                 Digital Metaphors Corporation                 BB BB
  RR  RR                                                               BB   BB
  RR   RR                   Copyright (c) 1996-2006                    BBBBB   }

unit Desenhar_Relatorio;

{$I ppIfDef.pas}

interface


{ By removing the 'x' which begins each of these compiler directives,
  you can enable different functionality within the end-user reporting
  solution.

  DADE    - the data tab where queries can be created by the end-user

  BDE     - BDE support for the Query Tools

  FireDAC  - FireDAC support for the Query Tools

  ADO     - ADO support for the Query Tools

  IBExpress - Interbase Express support for the Query Tools

  RAP -  the calc tab, where calculations can be coded at run-time
         (RAP is included with ReportBuilder Enterprise)

  CrossTab - adds the CrossTab component to the component palette in the
             report designer.

  CheckBox - adds a checkbox component to the component palette in the
         report designer.

  TeeChart - adds a teechart component to the report designer component
         palette. You must have TeeChart installed. More information
         is available in ..\RBuilder\TeeChart\ReadMe.doc

  UseDesignPath - determines whether the path used by the Database
         object on this form is replaced in the OnCreate event handler of
         this form with the current path.}

{$DEFINE DADE}            {remove the 'x' to enable DADE}
{x$DEFINE BDE}            {remove the 'x' to enable Borland Database Engine (BDE) }
{$DEFINE FireDAC}         {remove the 'x' to enable FireDAC }
{x$DEFINE ADO}            {remove the 'x' to enable ADO}
{x$DEFINE IBExpress}      {remove the 'x' to enable Interbase Express}
{$DEFINE CrossTab}        {remove the 'x' to enable CrossTab}
{x$DEFINE RAP}            {remove the 'x' to enable RAP}
{x$DEFINE CheckBox}       {remove the 'x' to enable CheckBox}
{x$DEFINE TeeChart}       {remove the 'x' to enable standard TeeChart}
{x$DEFINE UseDesignPath}  {remove the 'x' to use the design-time settings of Database object on this form}

uses

{$IFDEF DADE}
  daIDE, 
{$ENDIF}

{$IFDEF BDE}
  daDBBDE,
{$ENDIF}

{$IFDEF FireDAC}
  daFireDAC,
{$ENDIF}

{$IFDEF ADO}
  daADO,
{$ENDIF}

{$IFDEF IBExpress}
  daIBExpress,
{$ENDIF}

{$IFDEF CrossTab}
  ppCTDsgn,
{$ENDIF}

{$IFDEF RAP}
  raIDE,
{$ENDIF}

{$IFDEF CheckBox}
  myChkBoxDesign,
{$ENDIF}

{$IFDEF TeeChart}
  ppChrtUI,
{$ENDIF}


    daDatMan,

  Windows, system.UItypes, Classes, Controls, SysUtils, Forms, StdCtrls, ExtCtrls, Dialogs, Graphics,
  DB, ppComm, ppCache, ppClass, ppProd, ppReport, ppRptExp, ppBands,
  ppEndUsr, ppDBPipe, ppDB, ppPrnabl, ppStrtch, ppDsgnDB,
  ppRelatv, ppModule, ppViewr, ppFormWrapper, ppParameter, ppCtrls, daDataView,
  daQueryDataView, daDataModule, Grids, DBGrids, FireDAC.Stan.Intf,
  FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
  FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
  FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  FireDAC.DApt, FireDAC.VCLUI.Wait, FireDAC.Phys.ODBCBase, FireDAC.Phys.IBBase,
  FireDAC.Phys.IB, FireDAC.Comp.UI, FireDAC.Comp.DataSet, FireDAC.Phys.IBDef,
  ppDesignLayer;

type

  TfrmDesenhar_Relatorio = class(TForm)
    Shape11: TShape;
    Label6: TLabel;
    Shape12: TShape;
    Shape9: TShape;
    Label5: TLabel;
    Shape10: TShape;
    dsTable: TDataSource;
    dsField: TDataSource;
    ppDataDictionary1: TppDataDictionary;
    Shape6: TShape;
    Label7: TLabel;
    Shape5: TShape;
    Shape4: TShape;
    Label8: TLabel;
    Shape3: TShape;
    dsItem: TDataSource;
    Label1: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Shape15: TShape;
    Label2: TLabel;
    Shape16: TShape;
    dsFolder: TDataSource;
    ppReportExplorer1: TppReportExplorer;
    Shape22: TShape;
    Label10: TLabel;
    Shape23: TShape;
    Shape24: TShape;
    Shape25: TShape;
    Shape26: TShape;
    Shape7: TShape;
    Shape20: TShape;
    Shape29: TShape;
    Shape18: TShape;
    Shape17: TShape;
    Shape8: TShape;
    Shape13: TShape;
    Label3: TLabel;
    Shape14: TShape;
    Label9: TLabel;
    Shape19: TShape;
    Shape21: TShape;
    Shape27: TShape;
    Label4: TLabel;
    Shape28: TShape;
    dsJoin: TDataSource;
    dsItemUpdate: TDataSource;
    plItemUpdate: TppDBPipeline;
    plFolder: TppDBPipeline;
    plItem: TppDBPipeline;
    plTable: TppDBPipeline;
    plField: TppDBPipeline;
    plJoin: TppDBPipeline;
    euDatabase: TFDConnection;
    FDGUIxWaitCursor1: TFDGUIxWaitCursor;
    tblFolder: TFDTable;
    tblTable: TFDTable;
    tblField: TFDTable;
    tblJoin: TFDTable;
    qryItem: TFDQuery;
    qryItemUpdate: TFDQuery;
    ppReport1_bkp: TppReport;
    ppParameterList1: TppParameterList;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppDesigner1: TppDesigner;
    FDPhysIBDriverLink1: TFDPhysIBDriverLink;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    edtNomeRelatorio: TEdit;
    tblTableTABLE_NAME: TStringField;
    tblTableTABLE_ALIAS: TStringField;
    tblFieldTABLE_NAME: TStringField;
    tblFieldFIELD_NAME: TStringField;
    tblFieldFIELD_ALIAS: TStringField;
    tblFieldDATATYPE: TStringField;
    tblFieldSELECTABLE: TStringField;
    tblFieldSEARCHABLE: TStringField;
    tblFieldSORTABLE: TStringField;
    tblFieldAUTOSEARCH: TStringField;
    tblFieldMANDATORY: TStringField;
    tblJoinTABLE_NAME1: TStringField;
    tblJoinTABLE_NAME2: TStringField;
    tblJoinJOIN_TYPE: TStringField;
    tblJoinFIELD_NAMES1: TStringField;
    tblJoinOPERATORS: TStringField;
    tblJoinFIELD_NAMES2: TStringField;
    qryItemITEM_ID: TIntegerField;
    qryItemFOLDER_ID: TIntegerField;
    qryItemNAME: TStringField;
    qryItemITEM_SIZE: TIntegerField;
    qryItemITEM_TYPE: TIntegerField;
    qryItemMODIFIED: TFloatField;
    qryItemDELETED: TFloatField;
    qryItemTEMPLATE: TBlobField;
    qryItemUpdateITEM_ID: TIntegerField;
    qryItemUpdateFOLDER_ID: TIntegerField;
    qryItemUpdateNAME: TStringField;
    qryItemUpdateITEM_SIZE: TIntegerField;
    qryItemUpdateITEM_TYPE: TIntegerField;
    qryItemUpdateMODIFIED: TFloatField;
    qryItemUpdateDELETED: TFloatField;
    qryItemUpdateTEMPLATE: TBlobField;
    tblFolderFOLDER_ID: TIntegerField;
    tblFolderNAME: TStringField;
    tblFolderPARENT_ID: TIntegerField;
    ppReport1: TppReport;
    procedure FormCreate(Sender: TObject);
    procedure btnLaunchClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Imprimir_Relatorio_Template(nome_relatorio: string; Visualizar :Boolean = false; PrintDialog :Boolean = false; impressora :string = '');
    procedure Button3Click(Sender: TObject);
  private
  end;

var
  frmDesenhar_Relatorio: TfrmDesenhar_Relatorio;

implementation

{$R *.DFM}

uses
  ppTypes, CadRelatorioSistema, DataModulo, Rotinas;


procedure TfrmDesenhar_Relatorio.Imprimir_Relatorio_Template(nome_relatorio: string; Visualizar :Boolean = false; PrintDialog :Boolean = false; impressora :string = '');
begin
  ppReport1.Template.DatabaseSettings.Name  := nome_relatorio;
  ppReport1.Template.LoadFromDatabase;

  if Visualizar = False then
     ppReport1.DeviceType := dtPrinter
  else
     ppReport1.DeviceType := dtScreen;


  ppReport1.ShowPrintDialog := PrintDialog;

  ppReport1.PrinterSetup.PrinterName := impressora;

  ppreport1.print;
end;

{------------------------------------------------------------------------------}
{ TmyReportObjects.FormCreate }

procedure TfrmDesenhar_Relatorio.Button2Click(Sender: TObject);
begin
   frmCadRelatorioSistema := tfrmCadRelatorioSistema.Create(Application);
   frmCadRelatorioSistema.ShowModal;
   frmCadRelatorioSistema.Destroy;

end;

procedure TfrmDesenhar_Relatorio.Button3Click(Sender: TObject);
begin
  Imprimir_Relatorio_Template(edtNomeRelatorio.Text);
end;

procedure TfrmDesenhar_Relatorio.FormCreate(Sender: TObject);
begin
   FDPhysIBDriverLink1.VendorLib := CaminhoEXE + 'fbclient.dll';
   euDatabase.Connected := False;
   euDatabase.Params.Clear;

   euDatabase.Params.Add('DriverID=IB');
   euDatabase.Params.Add('Protocol=TCPIP');
   euDatabase.Params.Add('Database='  + dados.IB_Conexao.Path);
   euDatabase.Params.Add('Password='  + dados.IB_Conexao.Password);
   euDatabase.Params.Add('User_Name=' + dados.IB_Conexao.Username);
   euDatabase.Params.Add('Server='    + dados.IB_Conexao.Server);

   euDatabase.Connected := True;

end;

{------------------------------------------------------------------------------}
{ TmyReportObjects.btnLaunchClick }

procedure TfrmDesenhar_Relatorio.btnLaunchClick(Sender: TObject);
begin
  if not(ppReportExplorer1.Execute) then
  begin
     MessageDlg('Erro ao carregar o explorer o relatório', mtInformation, [mbOK], 0);
  end
end; {procedure, btnLaunchClick}

end.
