{
===============================================================================
  Copyright (©) 2007. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 
  Versión actual: 1.0.0
  Fecha versión actual: 
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit uBizOscOrderProducts;

interface

uses
  uDAInterfaces, uDADataTable, uDBSelectionListUtils, schTiendaWebClient_Intf;

const
  BIZ_CLIENT_OSC_ORDERPRODUCTS = 'Client.OSC.OrderProducts';

type
  IBizOscOrderProducts = interface(Iosc_Orders_products)
  	['{C4800680-96AD-4890-81B0-AB182A60D195}']    
    function EsNuevo : Boolean;
  end;

  TBizOscOrderProducts = class(Tosc_Orders_ProductsDataTableRules, IBizOscOrderProducts, ISeleccionable)
  protected
  	FSeleccionableInterface : ISeleccionable;
    procedure BeforeInsert(Sender: TDADataTable); override;
    procedure OnNewRecord(Sender: TDADataTable); override;
  public
    procedure IniciarValoresNuevo;
    function EsNuevo : Boolean;
    constructor Create(aDataTable: TDADataTable); override;
    destructor Destroy; override;

    property SeleccionableInterface : ISeleccionable 
    					read FSeleccionableInterface
    					write FSeleccionableInterface 
    					implements ISeleccionable;
  end;

implementation

{ TBizOscOrderProducts }

uses
  SysUtils, uDataTableUtils, DB;

procedure TBizOscOrderProducts.BeforeInsert(Sender: TDADataTable);
var
  AMasterTable : TDADataTable;
begin
  inherited;
  AMasterTable := DataTable.GetMasterDataTable;
  if Assigned(AMasterTable) and (AMasterTable.State = dsInsert) then
    AMasterTable.Post;
end;

constructor TBizOscOrderProducts.Create(aDataTable: TDADataTable);
begin
  inherited;
	FSeleccionableInterface := TSeleccionable.Create(aDataTable);
end;

destructor TBizOscOrderProducts.Destroy;
begin
  FSeleccionableInterface := NIL;
  inherited;
end;

function TBizOscOrderProducts.EsNuevo: Boolean;
begin
  Result := (orders_products_id < 0);
end;

procedure TBizOscOrderProducts.IniciarValoresNuevo;
begin
  //
end;

procedure TBizOscOrderProducts.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  orders_products_id := GetRecNo; // -1, -2, -3...
  IniciarValoresNuevo;
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_OSC_ORDERPRODUCTS, TBizOscOrderProducts);

finalization

end.

