unit uDataModuleHistoricoMovimientos;

interface

uses
  SysUtils, Classes, DB, uDAClientDataModule, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall,
  uIDataModuleHistoricoMovimientos, uBizHistoricoMovimientos;

type
  TDataModuleHistoricoMovimientos = class(TDAClientDataModule, IDataModuleHistoricoMovimientos)
    RORemoteService: TRORemoteService;
    DABinAdapter: TDABINAdapter;
    DADesigntimeCall1: TDADesigntimeCall;
    LoginRemoteService: TRORemoteService;
    ROWinInetHTTPChannel1: TROWinInetHTTPChannel;
    ROBinMessage1: TROBinMessage;
    tbl_Historico_Movimientos: TDACDSDataTable;
    ds_Historico_Movimientos: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);

  protected
    function _CloneDataTable (const ADataTable : TDACDSDataTable): TDACDSDataTable; overload;
    procedure AsignarClaseNegocio(var AHistoricoMovimientos: TDACDSDataTable); virtual;
  public
    function GetItems : IBizHistoricoMovimientos; overload;
    function GetItems(const ID_ALMACEN : Integer) : IBizHistoricoMovimientos; overload;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls, uDAInterfaces,
  schHistoricoMovimientosClient_Intf;

{ TdmArticulos }

procedure TDataModuleHistoricoMovimientos.AsignarClaseNegocio(var AHistoricoMovimientos: TDACDSDataTable);
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._CloneDataTable(const ADataTable : TDACDSDataTable): TDACDSDataTable;
begin
  Result := NIL;

  if not Assigned(ADataTable) then
    raise Exception.Create ('No se ha asignado la tabla de origen (CloneDataTable)');

  Result := TDACDSDataTable.Create(NIL);
  CloneDataTable(ADataTable, Result);
end;

function TDataModuleHistoricoMovimientos.GetItems(const ID_ALMACEN: Integer): IBizHistoricoMovimientos;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;
    with Result.DataTable.Where do
    begin
      if NotEmpty then
        AddOperator(opAND);

      OpenBraket;
      AddText(fld_Historico_MovimientosID_ALMACEN + ' = ' + IntToStr(ID_ALMACEN));
      CloseBraket;
    end;
  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleHistoricoMovimientos.GetItems: IBizHistoricoMovimientos;
var
  AHistoricoMovimientos : TDACDSDataTable;
begin
  ShowHourglassCursor;
  try
    AHistoricoMovimientos := _CloneDataTable(tbl_Historico_Movimientos);
    AsignarClaseNegocio(AHistoricoMovimientos);
    Result := (AHistoricoMovimientos as IBizHistoricoMovimientos);
  finally
    HideHourglassCursor;
  end;
end;


end.
