unit uDataModuleProveedores;

interface

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

  uIDataModuleProveedores, uBizContactos, uDADesigntimeCall;

type
  TDataModuleProveedores = class(TDataModuleContactos, IDataModuleProveedores)
    tbl_Proveedores: TDACDSDataTable;
    ds_Proveedores: TDADataSource;
  public
    function GetItem(const ID : Integer) : IBizProveedor;
    function NewItem : IBizProveedor;
    function GetItems : IBizProveedor;
    function GetItemsTiendaWeb : IBizProveedor;
    function GetNextID(const DataSetName : String) : Integer; override;    
  end;

implementation

{$R *.dfm}

uses
  cxControls, schContactosClient_Intf, uDAInterfaces, uDataTableUtils;

{ TDataModuleProveedores }

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

function TDataModuleProveedores.GetItems: IBizProveedor;
var
  AContacto : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AContacto := _CloneDataTable(tbl_Proveedores);
    AContacto.BusinessRulesID := BIZ_CLIENT_PROVEEDOR;

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

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

function TDataModuleProveedores.GetItemsTiendaWeb: IBizProveedor;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;
    with Result.DataTable.Where do
    begin
      if NotEmpty then
        AddOperator(opAND);
      OpenBraket;
      AddText(fld_ProveedoresTIENDA_WEB + ' = 1');
      CloseBraket;
    end;
  finally
    HideHourglassCursor;
  end;
end;

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

  Result := inherited GetNextID(aDataSet);
end;

function TDataModuleProveedores.NewItem: IBizProveedor;
begin
  Result := GetItem(ID_NULO)
end;

end.
