unit uViewElegirArticulosAlbaranesProveedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewArticulosPorProveedor, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxImageComboBox, cxCurrencyEdit,
  cxSpinEdit, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev,
  dxPSCompsProvider, dxPSFillPatterns, dxPSEdgePatterns, ImgList, PngImageList,
  cxGridCustomPopupMenu, cxGridPopupMenu, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk,
  uDADataTable, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, uBizContactos,
  dxPgsDlg, ActnList, TB2Item, TBX, TB2Toolbar, TBXDkPanels, TB2Dock,
  uViewFiltroBase, uDAInterfaces, uViewArticulos;

type
  IViewElegirArticulosAlbaranesProveedor = interface(IViewArticulos)
  ['{93C55517-8F37-4EDF-A1B0-95461D0AD807}']
    function GetProveedor: IBizProveedor;
    procedure SetProveedor(const Value: IBizProveedor);
    property Proveedor: IBizProveedor read GetProveedor write SetProveedor;
  end;

  TfrViewElegirArticulosAlbaranesProveedor = class(TfrViewArticulosPorProveedor, IViewElegirArticulosAlbaranesProveedor)
    cxGridLevel1: TcxGridLevel;
    procedure cxGridActiveTabChanged(Sender: TcxCustomGrid;
      ALevel: TcxGridLevel);
    procedure CustomViewDestroy(Sender: TObject);

  private
    FProveedor: IBizProveedor;
    function GetProveedor: IBizProveedor;
    procedure SetProveedor(const Value: IBizProveedor);

    //Filtros relativos a la vista
    procedure AnadirFiltroProveedor;

  public
    property Proveedor: IBizProveedor read GetProveedor write SetProveedor;
    procedure AnadirOtrosFiltros; override;

  end;

implementation
{$R *.dfm}

{ TfrViewElegirArticulosAlbaranesProveedor }

procedure TfrViewElegirArticulosAlbaranesProveedor.AnadirFiltroProveedor;
var
  FFiltro : TcxFilterCriteriaItemList;
begin
  FFiltro := AddFilterGrid(fboAnd);

  case cxGrid.ActiveLevel.Index of
    0   : if Assigned(FProveedor) then
             FFiltro.AddItem(cxGridViewID_PROVEEDOR, foEqual, FProveedor.ID, FProveedor.NOMBRE);
    1   : if Assigned(FProveedor) then
             FFiltro.AddItem(cxGridViewID_PROVEEDOR, foEqual, Null, 'ARTICULOS SIN PROVEEDOR');
  end;
end;

procedure TfrViewElegirArticulosAlbaranesProveedor.AnadirOtrosFiltros;
begin
  inherited;

  AnadirFiltroProveedor;

  //Finalmente activamos el filtro si tenemos algo
  if cxGridView.DataController.Filter.IsEmpty
  then cxGridView.DataController.Filter.Active := False
  else cxGridView.DataController.Filter.Active := True;
  cxGrid.ActiveLevel.GridView := cxGridView;
end;

procedure TfrViewElegirArticulosAlbaranesProveedor.CustomViewDestroy(
  Sender: TObject);
begin
  inherited;
  FProveedor := Nil;
end;

procedure TfrViewElegirArticulosAlbaranesProveedor.cxGridActiveTabChanged(
  Sender: TcxCustomGrid; ALevel: TcxGridLevel);
begin
  inherited;
  RefrescarFiltro;
end;

function TfrViewElegirArticulosAlbaranesProveedor.GetProveedor: IBizProveedor;
begin
  Result := FProveedor;
end;

procedure TfrViewElegirArticulosAlbaranesProveedor.SetProveedor(
  const Value: IBizProveedor);
begin
  FProveedor := Value;
  if Assigned(FProveedor) then
  begin
     cxGridLevel.Caption := FProveedor.NOMBRE;
     RefrescarFiltro;
  end;
end;

end.
