{
===============================================================================
  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 uDataModuleFabricantes;

interface

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

  uIDataModuleFabricantes, uBizFabricantes, uDADataStreamer, uDARemoteDataAdapter,
  uDAInterfaces, uRODynamicRequest, uDABin2DataStreamer, uDAMemDataTable,
  uDataModuleBase;

type
  TDataModuleFabricantes = class(TDataModuleBase, IDataModuleFabricantes)
    RORemoteService: TRORemoteService;
    rda_Fabricantes: TDARemoteDataAdapter;
    Bin2DataStreamer: TDABin2DataStreamer;
    tbl_Fabricantes: TDAMemDataTable;
    ds_Fabricantes: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  public
    function GetItems: IBizFabricante;
    function GetItem(const ID : Integer) : IBizFabricante;
    function NewItem : IBizFabricante;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, 
  schFabricantesClient_Intf;

{ TDataModuleFabricantes }

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

function TDataModuleFabricantes.GetItems: IBizFabricante;
var
  AFabricante : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AFabricante := CloneDataTable(tbl_Fabricantes);
    AFabricante.BusinessRulesID := BIZ_CLIENT_Fabricante;

    Result := (AFabricante as IBizFabricante);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleFabricantes.NewItem: IBizFabricante;
begin
  Result := GetItem(ID_NULO)
end;

function TDataModuleFabricantes.GetItem(const ID: Integer): IBizFabricante;
var
  Condicion: TDAWhereExpression;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;

    with Result.DataTable.DynamicWhere do
    begin
      // (ID = :ID)
      Condicion := NewBinaryExpression(NewField('', fld_FabricantesID), NewConstant(ID, datInteger), dboEqual);

      if IsEmpty then
         Expression := Condicion
      else
         Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
    end;

  finally
    HideHourglassCursor;
  end;
end;

end.
