unit srvContactos_Impl;

{----------------------------------------------------------------------------}
{ This unit was automatically generated by the RemObjects SDK after reading  }
{ the RODL file associated with this project .                               }
{                                                                            }
{ This is where you are supposed to code the implementation of your objects. }
{----------------------------------------------------------------------------}

interface

uses
  {vcl:} Classes, SysUtils,
  {RemObjects:} uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions,
  {Ancestor Implementation:} DARemoteService_Impl,
  {Used RODLs:} DataAbstract_Intf,
  {Generated:} FactuGES_Intf, uDAScriptingProvider, uDABusinessProcessor,
  uDAClasses, uDADataTable, uDAInterfaces, uDAEngine, uDAIBXDriver, DB,
  IBDatabase, frxClass, frxIBXComponents, uDACDSDataTable, uDABINAdapter,
  frxDBSet, frxExportPDF;

type
  { TsrvContactos }
  TsrvContactos = class(TDARemoteService, IsrvContactos)
    DACDSDataTable1: TDACDSDataTable;
    DADataSource1: TDADataSource;
    frxDBDataset1: TfrxDBDataset;
    frxReport1: TfrxReport;
    bpCategorias: TDABusinessProcessor;
    bpContactos: TDABusinessProcessor;
    bpAsociados: TDABusinessProcessor;
    DABINAdapter: TDABINAdapter;
    schContactos: TDASchema;
    procedure DARemoteServiceActivate(const aClientID: TGUID; aSession:
            TROSession; const aMessage: IROMessage);
  protected
    function GenerateReport: Binary;
    function getCodigo(const GeneratorName: String): Integer;
  public
    destructor Destroy; override;

  end;
  
implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk,
  Dialogs, schContactosClient_Intf, fServerForm, IB,
  Variants, schContactosServer_Intf, uDataModuleServer;

procedure Create_srvContactos(out anInstance : IUnknown);
begin
  anInstance := TsrvContactos.Create(NIL);
end;

{ srvContactos }
{
******************************** TsrvContactos *********************************
}
procedure TsrvContactos.DARemoteServiceActivate(const aClientID: TGUID;
        aSession: TROSession; const aMessage: IROMessage);
begin
  ((Connection as IDAConnectionObjectAccess).ConnectionObject as
  TIBXConnection).Database.TraceFlags := [tfQPrepare, tfQExecute, tfQFetch, tfError, tfStmt, tfConnect, tfTransact, tfBlob, tfService, tfMisc];
end;

destructor TsrvContactos.Destroy;
begin

  inherited;
end;

function TsrvContactos.GenerateReport: Binary;
var
  AStream: TMemoryStream;
begin
  AStream := TMemoryStream.Create;
  Result := Binary.Create;
  try
    DACDSDataTable1.Active := True;
    frxReport1.PrepareReport;
    frxReport1.PreviewPages.SaveToStream(AStream);
    Result.LoadFromStream(AStream);
  finally
    DACDSDataTable1.Active := False;
    AStream.Free;
  end;
end;

function TsrvContactos.getCodigo(const GeneratorName: String): Integer;
var
  ds: IDADataset;
begin
  ds := Connection.NewDataset(Format('SELECT Gen_id(%s,1) FROM RDB$DataBase', [GeneratorName]));
  ds.Open;
  Result := ds.Fields[0].Value;
  ds.Close;
end;

initialization
  TROClassFactory.Create('srvContactos', Create_srvContactos, TsrvContactos_Invoker);

finalization

end.

