{
===============================================================================
  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 uBizOscCustomers;

interface

uses
  uDAInterfaces, uDADataTable, uDBSelectionListUtils, schTiendaWebClient_Intf,
  uBizOscAddressBook;

const
  BIZ_CLIENT_OSC_CUSTOMER = 'Client.OSC.Customer';

type
  IBizOscCustomer = interface(Iosc_Customers)
  	['{DF158539-E502-4F38-B382-136A58C44EC7}']
    function EsNuevo : Boolean;

    procedure SetAddressBook(AValue : IBizOscAddressBook);
    function GetAddressBook : IBizOscAddressBook;
    property AddressBook : IBizOscAddressBook read GetAddressBook write SetAddressBook;
  end;

  TBizOscCustomer = class(Tosc_CustomersDataTableRules, IBizOscCustomer, ISeleccionable)
  protected
  	FSeleccionableInterface : ISeleccionable;
  	
     FAddressBook : IBizOscAddressBook;
     FAddressBookLink : TDADataSource;
     procedure SetAddressBook(AValue : IBizOscAddressBook);
     function GetAddressBook : IBizOscAddressBook;

    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;

    property AddressBook : IBizOscAddressBook read GetAddressBook write SetAddressBook;
  end;

implementation

{ TBizOscCustomers }

uses
  SysUtils, uDataTableUtils;

function TBizOscCustomer.GetAddressBook: IBizOscAddressBook;
begin
  Result := FAddressBook;
end;

procedure TBizOscCustomer.SetAddressBook(AValue: IBizOscAddressBook);
begin
  FAddressBook := AValue;
  EnlazarMaestroDetalle(FAddressBookLink, FAddressBook);
end;

constructor TBizOscCustomer.Create(aDataTable: TDADataTable);
begin
  inherited;
   FAddressBookLink := TDADataSource.Create(NIL);
   FAddressBookLink.DataTable := aDataTable;

	FSeleccionableInterface := TSeleccionable.Create(aDataTable);  
end;

destructor TBizOscCustomer.Destroy;
begin
   FAddressBook := NIL;
   FreeAndNIL(FAddressBookLink);

  FSeleccionableInterface := NIL;
  inherited;
end;

function TBizOscCustomer.EsNuevo: Boolean;
begin
  Result := (customers_id < 0);
end;

procedure TBizOscCustomer.IniciarValoresNuevo;
begin
  //
end;

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

initialization
  RegisterDataTableRules(BIZ_CLIENT_OSC_CUSTOMER, TBizOscCustomer);

finalization

end.

