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

interface

uses
  uDAInterfaces, uDADataTable, uDBSelectionListUtils, schTiendaWebClient_Intf;

const
  BIZ_CLIENT_OSC_ADDRESSBOOK = 'Client.OSC.AddressBook';

type
  IBizOscAddressBook = interface(Iosc_AddressBook)
  	['{367AB44E-4E9B-4F40-B695-2ED1085C18E9}']    
    function EsNuevo : Boolean;
  end;

  TBizOscAddressBook = class(Tosc_AddressBookDataTableRules, IBizOscAddressBook, 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

{ TBizOscAddressBook }

uses
  SysUtils, uDataTableUtils, DB;

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

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

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

function TBizOscAddressBook.EsNuevo: Boolean;
begin
  Result := (address_book_id < 0);
end;

procedure TBizOscAddressBook.IniciarValoresNuevo;
begin
  entry_country_id := 195; // Spain
  entry_zone_id := 161; // Madrid
end;

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

initialization
  RegisterDataTableRules(BIZ_CLIENT_OSC_ADDRESSBOOK, TBizOscAddressBook);

finalization

end.

