{
===============================================================================
  Copyright (©) 2007. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 
  Versión actual: 1.0.0
  Fecha versión actual: 
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit uDataModuleBancaElectronica;

interface

uses
  SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall,

  uIDataModuleBancaElectronica, uBizBancaElectronica;

type
  TDataModuleBancaElectronica = class(TDAClientDataModule, IDataModuleBancaElectronica)
    RORemoteService: TRORemoteService;
    DABinAdapter: TDABINAdapter;
    DADesigntimeCall1: TDADesigntimeCall;
    LoginRemoteService: TRORemoteService;
    ROWinInetHTTPChannel1: TROWinInetHTTPChannel;
    ROBinMessage1: TROBinMessage;
    procedure DAClientDataModuleCreate(Sender: TObject);
  protected
    function DarNombreGenerador(DataSetName: String): String; virtual;
    function _CloneDataTable (const ADataTable : TDACDSDataTable): TDACDSDataTable; overload;
    
    // Descomentar si tiene detalles
    // function _GetDetalles: IBizDetalles;
  public
    function GetNextID(const DataSetName : String) : Integer;
    function GetItems: IBizIBizBanca;
    function GetItem(const ID : Integer) : IBizIBizBanca;
    function NewItem : IBizIBizBanca;

    // Descomentar si tiene informe
    // function GetReport(const AIBizBancaID: Integer): Binary;
    
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, uDAInterfaces,
  schBancaElectronicaClient_Intf;

{ TDataModuleBancaElectronica }


// Descomentar si tiene informe
// function TDataModuleBancaElectronica.GetReport(const AIBizBancaID: Integer): Binary;
// begin
//   Result := (RORemoteService as IsrvBancaElectronica).GenerateReport(AIBizBancaID)
// end;

procedure TDataModuleBancaElectronica.DAClientDataModuleCreate(Sender: TObject);
begin
  RORemoteService.Channel := dmConexion.Channel;
  RORemoteService.Message := dmConexion.Message;
end;

function TDataModuleBancaElectronica.DarNombreGenerador(DataSetName: String): String;
begin
  Result := '';
  if DataSetName = nme_BancaElectronica then
    Result := 'GEN_BANCA_ID'
end;

function TDataModuleBancaElectronica.GetNextID(const DataSetName: String): Integer;
var
  aGeneratorName : String;
begin
  aGeneratorName := DarNombreGenerador(DataSetName);
  Result := (RORemoteService as IsrvBancaElectronica).GetNextAutoInc(aGeneratorName)
end;

function TDataModuleBancaElectronica._CloneDataTable(const ADataTable : TDACDSDataTable): TDACDSDataTable;
begin
  Result := NIL;

  if not Assigned(ADataTable) then
    raise Exception.Create ('No se ha asignado la tabla de origen (CloneDataTable)');

  Result := TDACDSDataTable.Create(NIL);
  CloneDataTable(ADataTable, Result);
end;


// Descomentar si tiene detalles
// function TDataModuleBancaElectronica._GetDetalles: IBizIBizBancaDetalles;
// var
//   ADetalles : TDACDSDataTable;
// begin
//   ShowHourglassCursor;
//   try
//     ADetalles := _CloneDataTable(tbl_BancaElectronicaDetalles);
//     with ADetalles do
//     begin
//       BusinessRulesID := BIZ_CLIENT_IBizBancaDETALLES;
//       DetailOptions := DetailOptions -
//         [dtDisableLogOfCascadeDeletes, dtDisableLogOfCascadeUpdates];
//     end;
//     Result := (ADetalles as IBizIBizBancaDetalles);
//   finally
//     HideHourglassCursor;
//   end;
// end;


function TDataModuleBancaElectronica.GetItems: IBizIBizBanca;
var
  AIBizBanca : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AIBizBanca := _CloneDataTable(tbl_BancaElectronica);
    AIBizBanca.BusinessRulesID := BIZ_CLIENT_IBizBanca;

		// Descomentar si tiene detalles
    // with TBizIBizBanca(AIBizBanca.BusinessEventsObj) do
    //  Detalles := _GetDetalles;

    Result := (AIBizBanca as IBizIBizBanca);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleBancaElectronica.NewItem: IBizIBizBanca;
begin
  Result := GetItem(ID_NULO)
end;

function TDataModuleBancaElectronica.GetItem(const ID: Integer): IBizIBizBanca;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;
    with Result.DataTable.Where do
    begin
      if NotEmpty then
        AddOperator(opAND);
      OpenBraket;
      AddText('BANCA.' + fld_BancaElectronicaID + ' = ' + IntToStr(ID));
      CloseBraket;
    end;
  finally
    HideHourglassCursor;
  end;
end;

end.
