unit uViewEmpleados;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewContactos, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, 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, uDAInterfaces,
  Menus, cxLookAndFeels, cxLookAndFeelPainters, dxPSPDFExportCore,
  dxPSPDFExport, cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv,
  dxPScxEditorProducers, dxPScxExtEditorProducers, dxPScxPageControlProducer,
  uCustomView, uViewBase;

type
  IViewEmpleados = interface(IViewContactos)
    ['{15826F4B-664B-4DDA-B9CD-723CE8843094}']
  end;

  TfrViewEmpleados = class(TfrViewContactos, IViewEmpleados)
    cxGridLevel1: TcxGridLevel;
    cxGridLevel2: TcxGridLevel;
    cxGridViewFECHA_BAJA: TcxGridDBColumn;
    cxStyleActivos: TcxStyle;
    cxStyleInactivos: TcxStyle;
    procedure cxGridActiveTabChanged(Sender: TcxCustomGrid; ALevel: TcxGridLevel);
    procedure cxGridViewStylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
  private
    //Filtros relativos a la vista
    procedure AnadirFiltroSituaciones;

  public
    procedure AnadirOtrosFiltros; override;
  end;

implementation
{$R *.dfm}

uses schContactosClient_Intf;

procedure TfrViewEmpleados.AnadirFiltroSituaciones;
var
  FFiltro : TcxFilterCriteriaItemList;
begin
  FFiltro := AddFilterGrid(fboAnd);

  case cxGrid.ActiveLevel.Index of
    1   : FFiltro.AddItem(cxGridViewFECHA_BAJA, foEqual, Null, 'ACTIVOS');
    2   : FFiltro.AddItem(cxGridViewFECHA_BAJA, foNotEqual, Null, 'INACTIVOS');
  end;
end;

procedure TfrViewEmpleados.AnadirOtrosFiltros;
begin
  inherited;

  AnadirFiltroSituaciones;

  //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 TfrViewEmpleados.cxGridActiveTabChanged(Sender: TcxCustomGrid;
  ALevel: TcxGridLevel);
begin
  inherited;
  RefrescarFiltro;
end;

procedure TfrViewEmpleados.cxGridViewStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  IndiceCol: Integer;
  ASituacion: String;
begin
  inherited;
  if Assigned(ARecord) then
  begin
    IndiceCol := (Sender as TcxGridDBTableView).GetColumnByFieldName(fld_EmpleadosFECHA_BAJA).Index;
    ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]);
    if Length(ASituacion) = 0 then
       AStyle.TextColor := cxStyleActivos.TextColor
    else
       AStyle.TextColor := cxStyleInactivos.TextColor;
  end;
end;

end.
