unit uDataModuleObras;

interface

uses
  SysUtils, Classes, DB, uDADataTable, uDABINAdapter,
  uDAScriptingProvider, uDACDSDataTable, uROWinInetHttpChannel, uROTypes,
  uRORemoteService, uROClient, uROBinMessage,
  uDADesigntimeCall,
  uIDataModuleObras, uBizObras, uDataModuleBase, uDARemoteDataAdapter,
  uDADataStreamer, uDABin2DataStreamer, uDAInterfaces, uDAMemDataTable,
  uRODynamicRequest;


type
  TDataModuleObras = class(TDataModuleBase, IDataModuleObras)
    RORemoteService: TRORemoteService;
    Bin2DataStreamer: TDABin2DataStreamer;
    rda_Obras: TDARemoteDataAdapter;
    tbl_Obras: TDAMemDataTable;
    ds_Obras: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);

  protected
    procedure AsignarClaseNegocio(AAlmacen: TDADataTable); virtual;
  public
    function GetItems : IBizObra;
    function GetItem(const ID : Integer) : IBizObra;
    function NewItem : IBizObra;
  end;

implementation

{$R *.DFM}

uses
  FactuGES_Intf, uDataModuleConexion, uDataTableUtils, cxControls,
  schObrasClient_Intf;

{ TdmAlmacens }

procedure TDataModuleObras.AsignarClaseNegocio(AAlmacen: TDADataTable);
begin
  AAlmacen.BusinessRulesID := BIZ_CLIENT_OBRA;
end;

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

function TDataModuleObras.NewItem: IBizObra;
begin
  Result := GetItem(ID_NULO)
end;

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

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

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

  finally
    HideHourglassCursor;
  end;
end;

function TDataModuleObras.GetItems: IBizObra;
var
  AObra : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AObra := CloneDataTable(tbl_Obras);

    AsignarClaseNegocio(AObra);

    Result := (AObra as IBizObra);

  finally
    HideHourglassCursor;
  end;
end;


end.
