unit srvTiposIVA_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:} DataAbstractService_Impl,
  {Used RODLs:} DataAbstract4_Intf,
  {Generated:}   uDABusinessProcessor, uDABin2DataStreamer, uDADataStreamer,
  uDAScriptingProvider, uDAClasses,
  FactuGES_Intf, uDAInterfaces;

type
  { TsrvTiposIVA }
  TsrvTiposIVA = class(TDataAbstractService, IsrvTiposIVA)
    Diagrams: TDADiagrams;
    Bin2DataStreamer: TDABin2DataStreamer;
    schTiposIVA: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceCreate(Sender: TObject);
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
  public
    function DarListaTiposIVA: Binary;  
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer, uDatabaseUtils, uROClasses;

procedure Create_srvTiposIVA(out anInstance : IUnknown);
begin
  anInstance := TsrvTiposIVA.Create(NIL);
end;

{ srvTiposIVA }
procedure TsrvTiposIVA.DARemoteServiceCreate(Sender: TObject);
begin
  //SessionManager := dmServer.SessionManager;
end;

function TsrvTiposIVA.DarListaTiposIVA: Binary;
var
  ASchema : TDASchema;
  AConn : IDAConnection;
  dsData: IDADataset;
  ALista : TStringList;
begin
  Result := Binary.Create;

  ASchema := schTiposIVA;
  AConn := dmServer.ConnectionManager.NewConnection(dmServer.ConnectionManager.GetDefaultConnectionName);

  try
    dsData := ASchema.NewDataset(AConn, 'ListaTiposIVA');
  except
    RaiseError('No existe la tabla TIPOS_IVA');
  end;

  ALista := TStringList.Create;
  try
    dsData.Active := True;
    while not dsData.EOF do
    begin
      ALista.Add(Format('%s=%d', [dsData.Fields[1].AsString, dsData.Fields[0].AsInteger]));
      dsData.Next;
    end;

    ALista.SaveToStream(Result);
  finally
    FreeANDNIL(ALista);
    dsData := NIL;
    AConn := NIL;
  end;
end;

procedure TsrvTiposIVA.DataAbstractServiceBeforeAcquireConnection(
  aSender: TObject; var aConnectionName: string);
begin
  ConnectionName := dmServer.ConnectionName;
end;

initialization
  TROClassFactory.Create('srvTiposIVA', Create_srvTiposIVA, TsrvTiposIVA_Invoker);

finalization

end.
