unit srvEmpresas_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, uDABINAdapter, uDAInterfaces;

type
  { TsrvEmpresas }
  TsrvEmpresas = class(TDARemoteService, IsrvEmpresas)
    BINAdapter: TDABINAdapter;
    Diagrams: TDADiagrams;
    bpEmpresas: TDABusinessProcessor;
    bpEmpresasDatosBanco: TDABusinessProcessor;
    schEmpresas: TDASchema;
    DataDictionary: TDADataDictionary;
    procedure DARemoteServiceBeforeGetDatasetData(const Dataset: IDADataset;
      const IncludeSchema: Boolean; const MaxRecords: Integer);
    procedure DARemoteServiceBeforeAcquireConnection(Sender: TDARemoteService;
      var ConnectionName: string);
    procedure DARemoteServiceCreate(Sender: TObject);
  private
  protected
    { IsrvEmpresas methods }
    function GetNextAutoInc(const GeneratorName: String): Integer;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} FactuGES_Invk, uDataModuleServer, uRORemoteDataModule,
  uDatabaseUtils, Dialogs, Variants, uROStreamSerializer, uROBinaryHelpers,
  uSesionesUtils, schEmpresasClient_Intf, uUsersManager,
  uRestriccionesUsuarioUtils;

procedure Create_srvEmpresas(out anInstance : IUnknown);
begin
  anInstance := TsrvEmpresas.Create(NIL);
end;

{ srvEmpresas }
procedure TsrvEmpresas.DARemoteServiceBeforeAcquireConnection(
  Sender: TDARemoteService; var ConnectionName: string);
begin
  ConnectionName := dmServer.ConnectionName;
end;

procedure TsrvEmpresas.DARemoteServiceBeforeGetDatasetData(
  const Dataset: IDADataset; const IncludeSchema: Boolean;
  const MaxRecords: Integer);
begin

  if (DataSet.Name <> nme_EmpresasDatosBanco) then
  begin
    { Aquí se asegura que el usuario sólo accede a las empresas a
      las que tiene permiso para acceder filtrando DataSet por ID_EMPRESA. }
    FiltrarAccesoUsuario(Session, Connection, schEmpresas, DataSet, fld_EmpresasID);
  end;
end;

procedure TsrvEmpresas.DARemoteServiceCreate(Sender: TObject);
begin
  SessionManager := dmServer.SessionManager;
end;

function TsrvEmpresas.GetNextAutoInc(const GeneratorName: String): Integer;
begin
  Result := uDatabaseUtils.GetNextAutoInc(GeneratorName)
end;

initialization
  TROClassFactory.Create('srvEmpresas', Create_srvEmpresas, TsrvEmpresas_Invoker);

finalization

end.
