unit uViewAlbaranDevCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewAlbaranCliente, cxGraphics, ActnList, DB, uDADataTable,
  dxLayoutControl, StdCtrls, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, cxTextEdit, Buttons, uCustomView, uViewBase,
  uViewDatosYSeleccionCliente, cxDBEdit, cxMemo, cxContainer, cxEdit,
  cxMaskEdit, cxCalendar, cxControls, uDAInterfaces,
  uViewDatosYSeleccionClienteAlbaran, uBizAlbaranesCliente;

type
  TfrViewAlbaranDevCliente = class(TfrViewAlbaranCliente)
    dxLayoutControl1Item17: TdxLayoutItem;
    eReferenciaAlbaranCli: TcxTextEdit;
    dxLayoutControl1Item25: TdxLayoutItem;
    Button2: TButton;
    dxLayoutControl1Group16: TdxLayoutGroup;
    actVerAlbaranCli: TAction;
    procedure actVerAlbaranCliExecute(Sender: TObject);
    procedure actVerAlbaranCliUpdate(Sender: TObject);
    procedure CustomViewCreate(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);

  protected
    FAlbaranAsociado : IBizAlbaranCliente;
    procedure SetAlbaran(const Value: IBizAlbaranCliente); override;
  end;

var
  frViewAlbaranDevCliente: TfrViewAlbaranDevCliente;

implementation

{$R *.dfm}

procedure TfrViewAlbaranDevCliente.actVerAlbaranCliExecute(Sender: TObject);
begin
  inherited;
  Controller.Ver(FAlbaranAsociado);
end;

procedure TfrViewAlbaranDevCliente.actVerAlbaranCliUpdate(Sender: TObject);
begin
  inherited;
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := Assigned(FAlbaranAsociado);
end;

procedure TfrViewAlbaranDevCliente.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FAlbaranAsociado := NIL;
end;

procedure TfrViewAlbaranDevCliente.CustomViewDestroy(Sender: TObject);
begin
  FAlbaranAsociado := NIL;
  inherited;
end;

procedure TfrViewAlbaranDevCliente.SetAlbaran(const Value: IBizAlbaranCliente);
begin
  inherited;

  if Assigned(FAlbaran) then
  begin
    FAlbaranAsociado := NIL;
    if (FAlbaran.ID_ALBARAN_DEV > 0) then
    begin
      FAlbaranAsociado := Controller.Buscar(FAlbaran.ID_ALBARAN_DEV);
      if Assigned(FAlbaranAsociado) then
      begin
        FAlbaranAsociado.DataTable.Active := True;
        eReferenciaAlbaranCli.Text := FAlbaranAsociado.REFERENCIA
      end
      else
        eReferenciaAlbaranCli.Text := '';
    end
    else
      eReferenciaAlbaranCli.Text := 'No hay pedido asociado';
  end
  else begin
    FAlbaranAsociado := NIL;
  end;
end;

end.
