unit uBizInfVentasArticulo;

interface

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

const
  BIZ_InfVentasArticulo = 'Client.InfVentasArticulo';

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

  TBizInfVentasArticulo = class(TInfVentasArticuloDataTableRules, IBizInfVentasArticulo)
  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

{ TBizInfVentasArticulo }

uses
  Dialogs;

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

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

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

procedure TBizInfVentasArticulo.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 TBizInfVentasArticulo.OnBeforeSchemaCall(DataTable: TDADataTable; Request: TDARemoteRequest);
begin
  Request.ParamByName('Columns').AsString := VisibleColumns;
end;

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

initialization
  RegisterDataTableRules(BIZ_InfVentasArticulo, TBizInfVentasArticulo);

finalization

end.

