unit uDataModuleHistoricoMovimientos;

interface

uses
  SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall, uDataModuleBase,
  uIDataModuleHistoricoMovimientos, uBizHistoricoMovimientos,
  uDARemoteDataAdapter, uDADataStreamer, uDABin2DataStreamer, uDAInterfaces,
  uDAMemDataTable;

type
  TDataModuleHistoricoMovimientos = class(TDataModuleBase, IDataModuleHistoricoMovimientos)
    RORemoteService: TRORemoteService;
    Bin2DataStreamer: TDABin2DataStreamer;
    rda_Historico_Movimientos: TDARemoteDataAdapter;
    tbl_HistoricoMovimientos: TDAMemDataTable;
    ds_HistoricoMovimientos: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  protected
    procedure AsignarClaseNegocio(var AHistoricoMovimientos: TDAMemDataTable); virtual;
  public
    function GetItems : IBizHistoricoMovimientos; overload;
    function GetItems(const ID_ALMACEN : Integer) : IBizHistoricoMovimientos; overload;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, 
  schHistoricoMovimientosClient_Intf;

{ TdmArticulos }

procedure TDataModuleHistoricoMovimientos.AsignarClaseNegocio(var AHistoricoMovimientos: TDAMemDataTable);
begin
  AHistoricoMovimientos.BusinessRulesID := BIZ_CLIENT_HISTORICO_MOVIMIENTOS;
end;

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

function TDataModuleHistoricoMovimientos.GetItems(const ID_ALMACEN: Integer): IBizHistoricoMovimientos;
var
  Condicion: TDAWhereExpression;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;

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

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

  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleHistoricoMovimientos.GetItems: IBizHistoricoMovimientos;
var
  AHistoricoMovimientos : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AHistoricoMovimientos := CloneDataTable(tbl_HistoricoMovimientos);
    AsignarClaseNegocio(AHistoricoMovimientos);
    Result := (AHistoricoMovimientos as IBizHistoricoMovimientos);
  finally
    HideHourglassCursor;
  end;
end;


end.
