unit uViewAlbaranDevProveedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewAlbaranProveedor, cxGraphics, ActnList, DB, uDADataTable,
  dxLayoutControl, cxTextEdit, StdCtrls, cxDropDownEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, uViewDireccionEntregaAlbaranProv,
  uCustomView, uViewBase, uViewDatosYSeleccionProveedor, cxDBEdit, cxMemo,
  cxContainer, cxEdit, cxMaskEdit, cxCalendar, cxControls, uBizAlbaranesProveedor;

type
  IViewAlbaranDevProveedor = interface(IViewAlbaranProveedor)
  ['{63121947-FB27-4B10-81FA-28B1D144951B}']
  end;

  TfrViewAlbaranDevProveedor = class(TfrViewAlbaranProveedor, IViewAlbaranDevProveedor)
    dxLayoutControl1Item13: TdxLayoutItem;
    eReferenciaAlbaranProv: TcxTextEdit;
    dxLayoutControl1Item14: TdxLayoutItem;
    Button2: TButton;
    dxLayoutControl1Group9: TdxLayoutGroup;
    actVerAlbaran: TAction;
    procedure actVerAlbaranExecute(Sender: TObject);
    procedure CustomViewCreate(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);
    procedure actVerAlbaranUpdate(Sender: TObject);
    procedure frViewProveedorAlbaranactElegirContactoUpdate(Sender: TObject);
  protected
    FAlbaranAsociado : IBizAlbaranProveedor;
    procedure SetAlbaran(const Value: IBizAlbaranProveedor); override;

  end;

implementation
{$R *.dfm}

procedure TfrViewAlbaranDevProveedor.actVerAlbaranExecute(Sender: TObject);
begin
  inherited;
  Controller.Ver(FAlbaranAsociado);
end;

procedure TfrViewAlbaranDevProveedor.actVerAlbaranUpdate(Sender: TObject);
begin
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := Assigned(FAlbaranAsociado);
end;

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

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

procedure TfrViewAlbaranDevProveedor.frViewProveedorAlbaranactElegirContactoUpdate(
  Sender: TObject);
begin
  inherited;
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := not Assigned(FAlbaranAsociado);
end;

procedure TfrViewAlbaranDevProveedor.SetAlbaran(const Value: IBizAlbaranProveedor);
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;
        eReferenciaAlbaranProv.Text := FAlbaranAsociado.REFERENCIA
      end
      else
        eReferenciaAlbaranProv.Text := '';
    end
    else
      eReferenciaAlbaranProv.Text := 'No hay pedido asociado';
  end
  else begin
    FAlbaranAsociado := NIL;
  end;
end;

end.
