unit uViewPacientes;

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,
  TBX, TB2Toolbar, TBXDkPanels, TB2Dock, uViewFiltroBase, uDAInterfaces,
  Menus, uCustomView, uViewBase;

type
  IViewPacientes = interface(IViewContactos)
    ['{6321A60C-699E-451B-A28A-A7A07D0DA252}']
  end;

  TfrViewPacientes = class(TfrViewContactos, IViewPacientes)
    cxGridLevel1: TcxGridLevel;
    cxGridLevel2: TcxGridLevel;
    cxGridViewFECHA_BAJA: TcxGridDBColumn;
    cxStyleActivos: TcxStyle;
    cxStyleInactivos: TcxStyle;
    cxGridViewNUMERO_SS: TcxGridDBColumn;
    cxGridViewFECHA_NACIMIENTO: TcxGridDBColumn;
    cxGridViewPABELLON: TcxGridDBColumn;
    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 TfrViewPacientes.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 TfrViewPacientes.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 TfrViewPacientes.cxGridActiveTabChanged(Sender: TcxCustomGrid;
  ALevel: TcxGridLevel);
begin
  inherited;
  RefrescarFiltro;
end;

procedure TfrViewPacientes.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_PacientesFECHA_BAJA).Index;
    ASituacion := VarToStr(ARecord.DisplayTexts[IndiceCol]);
    if Length(ASituacion) = 0 then
       AStyle.TextColor := cxStyleActivos.TextColor
    else
       AStyle.TextColor := cxStyleInactivos.TextColor;
  end;
end;

end.
