unit uDataModuleClientes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  DB, uDADataTable, uDAScriptingProvider,
  uDACDSDataTable, uDABINAdapter, uROServiceComponent, uRORemoteService,
  uROClient, uROBinMessage, uROWinInetHttpChannel,
  uBizContactos, uDataModuleContactos, uIDataModuleClientes, uDADesigntimeCall;

type
  TDataModuleClientes = class(TDataModuleContactos, IDataModuleClientes)
    tbl_Clientes: TDACDSDataTable;
    ds_Clientes: TDADataSource;
  public
    function GetItem(const ID : Integer) : IBizCliente;
    function NewItem : IBizCliente;
    function GetItems : IBizCliente;
    function GetNextID(const DataSetName : String) : Integer; override;    
  end;

implementation

{$R *.dfm}

uses
  uBizDatosBancarios, cxControls, uDAInterfaces, schContactosClient_Intf,
  uDataTableUtils, Dialogs;

{ TdmClientes }

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

function TDataModuleClientes.GetItems: IBizCliente;
var
  AContacto : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AContacto := _CloneDataTable(tbl_Clientes);
    AContacto.BusinessRulesID := BIZ_CLIENT_CLIENTE;

    with TBizCliente(AContacto.BusinessEventsObj) do
    begin
      DatosBancarios := _GetDatosBancarios;
      _Categorias := _GetCategorias;
    end;

    Result := (AContacto as IBizCliente);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleClientes.GetNextID(const DataSetName: String): Integer;
var
  aDataSet : String;
begin
  aDataSet := DataSetName;
  if aDataSet = nme_Clientes then
    aDataSet := nme_Contactos;

  Result := inherited GetNextID(aDataSet);
end;

function TDataModuleClientes.NewItem: IBizCliente;
begin
  Result := GetItem(ID_NULO)
end;

end.
