unit uBizInfMargenArticulo;

interface

uses
  Classes, DB, SysUtils, uROClasses, uDADataTable, uDAInterfaces,
  DataAbstract_Intf, uROTypes, schInfMargenArticuloClient_Intf;

const
  BIZ_InfMargenArticulo = 'Client.InfMargenArticulo';

type
  IBizInfMargenArticulo = interface(IInfMargenArticulo)
  ['{8E265668-0B6D-4475-9965-15B3EE251B24}']
    function GetVisibleColumns: String;
    procedure SetVisibleColumns(const Value: String);
    property VisibleColumns : String read GetVisibleColumns write SetVisibleColumns;
  end;

  TBizInfMargenArticulo = class(TInfMargenArticuloDataTableRules, IBizInfMargenArticulo)
  private
    FVisibleColumns : String;
    FDateParams : TDADatasetParamArray;
  protected
    function GetVisibleColumns: String;
    procedure SetVisibleColumns(const Value: String);
    procedure OnBeforeDataRequestCall(DataTable: TDADataTable; Request: TDARemoteRequest);
    procedure OnBeforeSchemaCall(DataTable: TDADataTable; Request: TDARemoteRequest);
  public
    constructor Create(aDataTable: TDADataTable); override;
    property VisibleColumns : String read GetVisibleColumns write SetVisibleColumns;
    destructor Destroy; override;
  end;


implementation

{ TBizInfMargenArticulo }

uses
  Dialogs;

constructor TBizInfMargenArticulo.Create(aDataTable: TDADataTable);
begin
  inherited;
  FDateParams := TDADatasetParamArray.Create;
  if Assigned(DataTable) then
  begin
    DataTable.OnBeforeDataRequestCall := OnBeforeDataRequestCall;
    DataTable.OnBeforeSchemaCall := OnBeforeSchemaCall;
  end;
end;

destructor TBizInfMargenArticulo.Destroy;
begin
  FreeAndNIL(FDateParams);
  inherited;
end;

function TBizInfMargenArticulo.GetVisibleColumns: String;
begin
//  if Length(FVisibleColumns) = 0 then
//     FVisibleColumns := dmInfMargenArticulo.GetNameColumns;
  Result := FVisibleColumns
end;

procedure TBizInfMargenArticulo.OnBeforeDataRequestCall(
  DataTable: TDADataTable; Request: TDARemoteRequest);
begin
  Request.ParamByName('Columns').AsString := VisibleColumns;
  FDateParams.Clear;
  NewDatasetParam(FDateParams, 'FECHAINI', DataTable.ParamByName('FECHAINI').AsDateTime);
  NewDatasetParam(FDateParams, 'FECHAFIN', DataTable.ParamByName('FECHAFIN').AsDateTime);
  Request.ParamByName('Params').AsComplexType := FDateParams;
end;

procedure TBizInfMargenArticulo.OnBeforeSchemaCall(DataTable: TDADataTable; Request: TDARemoteRequest);
begin
  Request.ParamByName('Columns').AsString := VisibleColumns;
end;

procedure TBizInfMargenArticulo.SetVisibleColumns(const Value: String);
begin
//  if Length(Value) > 0 then
    FVisibleColumns := Value
//  else
//    FVisibleColumns := dmInfMargenArticulo.GetNameColumns;
end;

initialization
  RegisterDataTableRules(BIZ_InfMargenArticulo, TBizInfMargenArticulo);

finalization

end.

