unit uBizDetallesAlbaranCliente;

interface

uses
  uDADataTable, schAlbaranesClienteClient_Intf, uBizDetalleColoresAlbaranCliente;

const
  BIZ_CLIENT_DETALLES_ALBARAN_CLIENTE = 'Client.DetallesAlbaran.Cliente';


type
  IBizDetallesAlbaranCliente = interface(IAlbaranesCliente_Detalles)
  ['{8EC1F1B2-C00D-4B58-9F97-C74DBADA4980}']
    function GetDetalleColores: IBizDetalleColoresAlbaranCliente;
    procedure SetDetalleColores(Value: IBizDetalleColoresAlbaranCliente);
    property DetalleColores: IBizDetalleColoresAlbaranCliente read GetDetalleColores write SetDetalleColores;
  end;

  TBizDetallesAlbaranCliente = class(TAlbaranesCliente_DetallesDataTableRules, IBizDetallesAlbaranCliente)
  protected
    FDetalleColores : IBizDetalleColoresAlbaranCliente;
    FDetalleColoresLink : TDADataSource;

    function GetDetalleColores: IBizDetalleColoresAlbaranCliente;
    procedure SetDetalleColores(Value: IBizDetalleColoresAlbaranCliente);

    procedure OnNewRecord(Sender: TDADataTable); override;
    procedure BeforeInsert(Sender: TDADataTable); override;

  public
    property DetalleColores: IBizDetalleColoresAlbaranCliente read GetDetalleColores write SetDetalleColores;

    constructor Create(aDataTable: TDADataTable); override;
    destructor Destroy; override;
  end;

implementation

uses
  Classes, DB, uDataTableUtils;

{ TBizDetallesAlbaranCliente }

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

constructor TBizDetallesAlbaranCliente.Create(aDataTable: TDADataTable);
begin
  inherited;
  FDetalleColoresLink := TDADataSource.Create(NIL);
  FDetalleColoresLink.DataTable := aDataTable;
end;

destructor TBizDetallesAlbaranCliente.Destroy;
begin
  FDetalleColores := NIL;
  FDetalleColoresLink.Free;

  inherited;
end;

function TBizDetallesAlbaranCliente.GetDetalleColores: IBizDetalleColoresAlbaranCliente;
begin
  Result := FDetalleColores;
end;

procedure TBizDetallesAlbaranCliente.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  VISIBLE := 1;
end;

procedure TBizDetallesAlbaranCliente.SetDetalleColores(Value: IBizDetalleColoresAlbaranCliente);
begin
  FDetalleColores := Value;
  EnlazarMaestroDetalle(FDetalleColoresLink, FDetalleColores);
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_DETALLES_ALBARAN_CLIENTE, TBizDetallesAlbaranCliente);

end.
