unit uDataModuleVendedores;

interface

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

  uIDataModuleVendedores, uBizContactos, uDADesigntimeCall;

type
  TDataModuleVendedores = class(TDataModuleContactos, IDataModuleVendedores)
    tbl_Vendedores: TDACDSDataTable;
    ds_Vendedores: TDADataSource;
  public
    function GetItem(const ID : Integer) : IBizVendedor;
    function NewItem : IBizVendedor;
    function GetItems : IBizVendedor;
    function GetNextID(const DataSetName : String) : Integer; override;    
  end;


implementation

{$R *.dfm}

uses
  cxControls, schContactosClient_Intf, uDAInterfaces, uDataTableUtils;

{ TDataModuleVendedores }

function TDataModuleVendedores.GetItem(const ID: Integer): IBizVendedor;
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 TDataModuleVendedores.GetItems: IBizVendedor;
var
  AContacto : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AContacto := _CloneDataTable(tbl_Vendedores);
    AContacto.BusinessRulesID := BIZ_CLIENT_VENDEDOR;

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

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

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

  Result := inherited GetNextID(aDataSet);
end;

function TDataModuleVendedores.NewItem: IBizVendedor;
begin
  Result := GetItem(ID_NULO)
end;

end.
