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

interface

uses
  uDAInterfaces, uDADataTable, uDBSelectionListUtils, schTiendaWebClient_Intf;

const
  BIZ_CLIENT_OSC_ORDERSTATUS = 'Client.OSC.OrderStatus';

type
  IBizOscOrderStatus = interface(Iosc_Orders_status_history)
  	['{D73A9573-4491-4E4E-BB2D-64197773A202}']
    function EsNuevo : Boolean;
  end;

  TBizOscOrderStatus = class(Tosc_Orders_status_historyDataTableRules, IBizOscOrderStatus, 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

{ TBizOscOrderStatus }

uses
  SysUtils, uDataTableUtils, DB;

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

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

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

function TBizOscOrderStatus.EsNuevo: Boolean;
begin
  Result := (orders_status_history_id < 0);
end;

procedure TBizOscOrderStatus.IniciarValoresNuevo;
begin
  //
end;

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

initialization
  RegisterDataTableRules(BIZ_CLIENT_OSC_ORDERSTATUS, TBizOscOrderStatus);

finalization

end.

