unit srvRegistroCorreos_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. }
{----------------------------------------------------------------------------}

{$I RemObjects.inc}

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
  { TsrvRegistroCorreos }
  TsrvRegistroCorreos = class(TDataAbstractService, IsrvRegistroCorreos)
    Bin2DataStreamer: TDABin2DataStreamer;
    schRegistroCorreo: TDASchema;
  private
  protected
    { IsrvRegistroCorreos methods }
    function AnadirMarcaEnvio(const NombreTabla: AnsiString; const IdsTabla: TIntegerArray): Boolean;
  end;

implementation

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

procedure Create_srvRegistroCorreos(out anInstance : IUnknown);
begin
  anInstance := TsrvRegistroCorreos.Create(nil);
end;

{ srvRegistroCorreos }
function TsrvRegistroCorreos.AnadirMarcaEnvio(const NombreTabla: AnsiString; const IdsTabla: TIntegerArray): Boolean;
var
  ASchema : TDASchema;
  AConn : IDAConnection;
  dsCommand: IDASQLCommand;
  i: Integer;

begin
  Result := False;

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

      //Vamos generando todas y cada una de las marcas de impresion
      for i := 0 to IdsTabla.Count - 1 do
      begin
        dsCommand := ASchema.NewCommand(AConn, 'AnadirMarcaEnvio');
        with dsCommand do
        begin
          ParamByName('TABLA').AsString := NombreTabla;
          ParamByName('IDTABLA').AsInteger := IdsTabla.Items[i];
        end;
        dsCommand.Execute;
      end;
      AConn.CommitTransaction;
      Result := True;
    except
      RaiseError('Error al aņadir una nueva marca de envio ' + NombreTabla + ' en tablas');
      AConn.RollbackTransaction;
    end;
  finally
    dsCommand := NIL;
    ASchema := NIL;
  end;
end;

var
  fClassFactory: IROClassFactory;
initialization
  fClassFactory := TROClassFactory.Create('srvRegistroCorreos', Create_srvRegistroCorreos, TsrvRegistroCorreos_Invoker);

finalization
  UnRegisterClassFactory(fClassFactory);
  fClassFactory := nil;

end.
