unit uViewElegirArticulosPedidosProveedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewArticulos, 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, dxPgsDlg,
  ActnList, TB2Item, SpTBXItem, TB2Toolbar, SpTBXDkPanels, TB2Dock, uViewFiltroBase,
  uBizContactos, uDAInterfaces, uViewArticulosPorProveedor;

type
  IViewElegirArticulosPedidosProveedor = interface(IViewArticulos)
  ['{5292A518-0797-4FFC-AC9B-90F0113AF3AF}']
    function GetProveedor: IBizProveedor;
    procedure SetProveedor(const Value: IBizProveedor);
    property Proveedor: IBizProveedor read GetProveedor write SetProveedor;
  end;

  TfrViewElegirArticulosPedidosProveedor = class(TfrViewArticulosPorProveedor, IViewElegirArticulosPedidosProveedor)
    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

uses uViewGrid;

{$R *.dfm}

procedure TfrViewElegirArticulosPedidosProveedor.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, foNotEqual, FProveedor.ID, 'ARTICULOS DE OTROS PROVEEDORES');
  end;
end;

procedure TfrViewElegirArticulosPedidosProveedor.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 TfrViewElegirArticulosPedidosProveedor.CustomViewDestroy(Sender: TObject);
begin
  FProveedor := Nil;
  inherited;
end;

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

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

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

end.
