unit uViewObraReserva;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, uViewBase, uBizPedidosProveedor, cxGraphics, dxLayoutControl, cxMemo,
  cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, StdCtrls, cxControls, DB, uDADataTable,
  ActnList, uBizAlmacenes, uAlmacenesController, uPedidosProveedorController,
  Buttons, uDAInterfaces, uBizObras, uObrasController, cxButtonEdit, cxDBEdit,
  ExtCtrls, ImgList, PngImageList;

type
  IViewDireccionEntregaPedidoProv = interface(IViewBase)
  ['{7467855C-066F-4A60-B88F-2837C8050B1E}']
    function GetPedidoProveedor: IBizPedidoProveedor;
    procedure SetPedidoProveedor(const Value: IBizPedidoProveedor);
    property PedidoProveedor: IBizPedidoProveedor read GetPedidoProveedor write SetPedidoProveedor;
  end;

  TfrViewObraReserva = class(TfrViewBase, IViewDireccionEntregaPedidoProv)
    dxLayoutControl1: TdxLayoutControl;
    dxLayoutGroup1: TdxLayoutGroup;
    dsPedido: TDADataSource;
    dxLayoutControl1Item6: TdxLayoutItem;
    cbListaObrasReserva: TcxDBLookupComboBox;
    dsObras: TDADataSource;
    Label1: TLabel;
    dxLayoutControl1Item1: TdxLayoutItem;
    dxLayoutControl1Item2: TdxLayoutItem;
    Button3: TBitBtn;
    dxLayoutControl1Group1: TdxLayoutGroup;
    PngImageList: TPngImageList;
    ActionList1: TActionList;
    actVerObra: TAction;
    procedure actVerObraExecute(Sender: TObject);
    procedure actVerObraUpdate(Sender: TObject);
  protected
    FObrasController : IObrasController;
    FObras: IBizObra;
    FPedido : IBizPedidoProveedor;
    FController : IPedidosProveedorController;
    function GetPedidoProveedor: IBizPedidoProveedor;
    procedure SetPedidoProveedor(const Value: IBizPedidoProveedor);
  public
    property PedidoProveedor: IBizPedidoProveedor read GetPedidoProveedor  write SetPedidoProveedor;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation

{$R *.dfm}

uses
  uEditorRegistryUtils, uCustomView, uEditorElegirPersonaContactoPedido,
  uStringsUtils;

procedure TfrViewObraReserva.actVerObraExecute(Sender: TObject);
begin
  inherited;
  FObrasController.Ver(FObras);
end;

procedure TfrViewObraReserva.actVerObraUpdate(Sender: TObject);
begin
  inherited;
  (Sender as TAction).Enabled := Assigned(FObras) and
                  (not EsCadenaVacia(cbListaObrasReserva.Text));
end;

constructor TfrViewObraReserva.Create(AOwner: TComponent);
begin
  inherited;
  FController := TPedidosProveedorController.Create;
  FObrasController := TObrasController.Create;
  FObras := FObrasController.BuscarTodos;
  FObras.DataTable.Active := True;
  dsObras.DataTable := FObras.DataTable;
end;

destructor TfrViewObraReserva.Destroy;
begin
  FObrasController := Nil;
  FObras := Nil;

  FController := NIL;
  inherited;
end;

function TfrViewObraReserva.GetPedidoProveedor: IBizPedidoProveedor;
begin
  Result := FPedido;
end;

procedure TfrViewObraReserva.SetPedidoProveedor(
  const Value: IBizPedidoProveedor);
begin
  dsPedido.DataTable := nil;
  FPedido := Value;
  dsPedido.DataTable := FPedido.DataTable;
end;


end.
