unit srvImpresiones_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
  { TsrvImpresiones }
  TsrvImpresiones = class(TDataAbstractService, IsrvImpresiones)
    Diagrams: TDADiagrams;
    bpImpresiones: TDABusinessProcessor;
    schImpresiones: TDASchema;
    DataDictionary: TDADataDictionary;
    Bin2DataStreamer: TDABin2DataStreamer;
    procedure DataAbstractServiceBeforeAcquireConnection(aSender: TObject;
      var aConnectionName: string);
  public
    { IsrvImpresiones methods }
    function AnadirMarcaImpresion(const NombreTabla: AnsiString; const IdsTabla: AnsiString): Boolean;
    function prueba: Boolean;
  end;

implementation

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

procedure Create_srvImpresiones(out anInstance : IUnknown);
begin
  anInstance := TsrvImpresiones.Create(NIL);
end;

{ srvImpresiones }

function TsrvImpresiones.AnadirMarcaImpresion(const NombreTabla: AnsiString; const IdsTabla: AnsiString): Boolean;
var
  ASchema : TDASchema;
  AConn : IDAConnection;
  dsCommand: IDASQLCommand;
  ListaIds: TStringList;
  i: Integer;

begin
  Result := False;

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

  try
    try
      ListaIds := TStringList.Create;
      ListaIds.CommaText := IdsTabla;

      //Vamos generando todas y cada una de las marcas de impresion
      for i := 0 to ListaIds.Count - 1 do
      begin
        dsCommand := ASchema.NewCommand(AConn, 'AnadirMarcaImpresion');
        with dsCommand do
        begin
          ParamByName('TABLA').AsString := NombreTabla;
          ParamByName('IDTABLA').AsString := ListaIds.Strings[i];
        end;
        dsCommand.Execute;
        AConn.CommitTransaction;
      end;

      FreeAndNil(ListaIds);
      Result := True;
    except
      RaiseError('Error al aņadir una nueva marca de impresion ' + NombreTabla + ' en tablas');
      AConn.RollbackTransaction;
    end;
  finally
    dsCommand := NIL;
  end;
end;

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

function TsrvImpresiones.prueba: Boolean;
begin
  Result := True;
end;

initialization
  TROClassFactory.Create('srvImpresiones', Create_srvImpresiones, TsrvImpresiones_Invoker);

finalization

end.
