unit srvVentasEnProceso_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:} DataAbstract3_Intf,
  {Generated:} VARELA_Intf, uDAClasses, uDABusinessProcessor,
  uDAInterfaces, uDADataTable, uDABINAdapter, uDADataStreamer;

type
  { TsrvVentasEnProceso }
  TsrvVentasEnProceso = class(TDARemoteService, IsrvVentasEnProceso)
    DABINAdapter: TDABINAdapter;
    schVentasEnProceso: TDASchema;
  private
  protected
    function GetData(const DatasetName: String;   const Columns: String; const Params: String; const MaxRecords: Integer): Binary;
    function GetSchema(const DatasetName: String; const Columns: String): Binary;
  end;

implementation

{$R *.dfm}
uses
  {Generated:} VARELA_Invk, uDataModuleServer, uSchemaUtilsServer;

const
  CAMPOS_SUMA = '#INICIO#FINAL#IMPORTE#';

procedure Create_srvVentasEnProceso(out anInstance : IUnknown);
begin
  anInstance := TsrvVentasEnProceso.Create(NIL);
end;

{ TsrvVentasEnProceso }

function TsrvVentasEnProceso.GetData(const DatasetName: String;
  const Columns: String; const Params: String;
  const MaxRecords: Integer): Binary;
var
  ds : IDADataset;
  i : integer;
  pars: TStringList;
  parnames: array of string;
  parvalues: array of Variant;
begin
  pars := TStringList.Create;
  result := Binary.Create;
  try
    try
      pars.Text := Params;
      SetLength(parnames, pars.Count);
      SetLength(parvalues, pars.Count);
      for i := 0 to (pars.Count-1) do begin
        parnames[i] := pars.Names[i];
        parvalues[i] := pars.Values[pars.Names[i]];
      end;

      { Prepares the parameter arrays}

      with TReplicarDataSet.Create do
      begin
        SourceDataSetName := DatasetName;
        Service := Self;
        Columnas := Columns;
        ColumnasQueSuman := CAMPOS_SUMA;
        try
          ds := GetNewDataSet;
        finally
          Free;
        end;
      end;

      // Fills the parameters (if any are specified)
      if (Length(parnames) > 0) then
      begin
        for i := 0 to (Length(parnames) - 1) do
          ds.ParamByName(parnames[i]).Value := parvalues[i];
      end;

      ds.Open;
      ServiceAdapter.WriteDataset(Result, ds, [woRows], MaxRecords);
    except
      FreeAndNIl(result);
      raise;
    end;
  finally
    FreeANDNil(pars);
  end;
end;


function TsrvVentasEnProceso.GetSchema(const DatasetName,
  Columns: String): Binary;
var
  ds : IDADataset;
begin
  result := Binary.Create;
  try
    with TReplicarDataSet.Create do
    begin
      SourceDataSetName := DatasetName;
      Service := Self;
      Columnas := Columns;
      ColumnasQueSuman := CAMPOS_SUMA;
      try
        ds := GetNewDataSet;
      finally
        Free;
      end;
    end;
    
    ServiceAdapter.WriteDataset(result, ds, [woSchema]);
  except
    FreeAndNIl(result);
    raise;
  end;
end;

initialization
  TROClassFactory.Create('srvVentasEnProceso', Create_srvVentasEnProceso, TsrvVentasEnProceso_Invoker);

finalization

end.
