unit uViewInformeBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Forms,
  Dialogs, uViewBase, TBXDkPanels, StdCtrls, ComCtrls, TB2Dock,
  uViewAgrupaciones, uCustomView, uViewColumnas, ImgList, PngImageList,
  ActnList, uViewInformeBaseGrid, uBizInformes, uViewSumarios, uViewGridBase,
  uViewInformeBaseParametros, uViewFiltros, cxStyles, Controls, uViewFiltroBase,
  DB, uDADataTable;

type
  IViewInformeBase = interface(IViewGridBase)
  ['{D716BE6B-1F41-4825-9385-0231D2AEF819}']
    function GetModificable: Boolean;
    procedure SetModificable(const Value: Boolean);
    property Modificable : Boolean read GetModificable write SetModificable;

    function GetInforme: IBizInforme;
    procedure SetInforme(const Value: IBizInforme);
    property Informe: IBizInforme read GetInforme write SetInforme;

    function GetOnViewChanged : TNotifyEvent;
    procedure SetOnViewChanged(const Value : TNotifyEvent);
    property OnViewChanged: TNotifyEvent read GetOnViewChanged write SetOnViewChanged;
  end;

  TfrViewInformeBase = class(TfrViewGridBase, IViewInformeBase)
    TBXMultiDock1: TTBXMultiDock;
    pnlParametros: TTBXDockablePanel;
    TBXAlignmentPanel2: TTBXAlignmentPanel;
    TBXLink1: TTBXLink;
    TBXLink5: TTBXLink;
    TBXLink2: TTBXLink;
    pcParametros: TPageControl;
    TabSheet5: TTabSheet;
    tsColumnas: TTabSheet;
    tsAgrupacion: TTabSheet;
    pnlTareas: TTBXDockablePanel;
    TBXPageScroller1: TTBXPageScroller;
    TBXAlignmentPanel1: TTBXAlignmentPanel;
    bFiltros: TTBXLink;
    bSumarios: TTBXLink;
    pcTareas: TPageControl;
    tsSumarios: TTabSheet;
    tsFiltros: TTabSheet;
    frViewColumnas1: TfrViewColumnas;
    frViewAgrupaciones1: TfrViewAgrupaciones;
    SmallImages: TPngImageList;
    LargeImages: TPngImageList;
    EditorActionList: TActionList;
    actAgrupaciones: TAction;
    actColumnas: TAction;
    actSumarios: TAction;
    actFiltros: TAction;
    frViewSumarios1: TfrViewSumarios;
    actRefrescar: TAction;
    frViewFiltros1: TfrViewFiltros;
    TBXMultiDock2: TTBXMultiDock;
    pnlIntervaloFechas: TTBXDockablePanel;
    TBXAlignmentPanel3: TTBXAlignmentPanel;
    bRefrescar: TButton;
    procedure actColumnasExecute(Sender: TObject);
    procedure actSumariosExecute(Sender: TObject);
    procedure actFiltrosExecute(Sender: TObject);
    procedure actAgrupacionesExecute(Sender: TObject);

  private
    procedure ComprobarPrivilegios;

  protected
    FInforme : IBizInforme;
    FOnViewChanged : TNotifyEvent;
    FModificable : Boolean;
    procedure ActivarTarea (const ATarea : Integer); virtual;
    function GetInforme: IBizInforme; virtual;
    procedure SetInforme(const Value: IBizInforme); virtual;
    function GetOnViewChanged : TNotifyEvent; virtual;
    procedure SetOnViewChanged(const Value : TNotifyEvent); virtual;
    function GetModificable: Boolean; virtual;
    procedure SetModificable(const Value: Boolean); virtual;

  public
    property Modificable : Boolean read GetModificable write SetModificable;
    property OnViewChanged: TNotifyEvent read GetOnViewChanged write SetOnViewChanged;
    property Informe: IBizInforme read GetInforme write SetInforme;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Refresh; override;
  end;

implementation

{$R *.dfm}

uses uDataModuleUsuarios;

const
  COLUMNAS = 1;
  AGRUPACIONES = 2;
  SUMARIOS = 3;
  FILTROS = 4;

procedure TfrViewInformeBase.actColumnasExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(COLUMNAS);
  frViewColumnas1.Refresh;
end;

procedure TfrViewInformeBase.ActivarTarea(const ATarea: Integer);
begin
  case ATarea of
    COLUMNAS    : pcParametros.ActivePage := tsColumnas;
    AGRUPACIONES  : pcParametros.ActivePage := tsAgrupacion;
    SUMARIOS    : pcTareas.ActivePage := tsSumarios;
    FILTROS     : pcTareas.ActivePage := tsFiltros;
  end;
end;

function TfrViewInformeBase.GetInforme: IBizInforme;
begin
  Result := FInforme;
end;

procedure TfrViewInformeBase.SetInforme(const Value: IBizInforme);
begin
  FInforme := Value;
  frViewColumnas1.Refresh;
  frViewAgrupaciones1.Refresh;

  ComprobarPrivilegios;
  // ¿Es modificable el InformeBase?
//  Self.Modificable := FInformeBase.EsModificable;
end;

procedure TfrViewInformeBase.actSumariosExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(SUMARIOS);
  frViewSumarios1.Refresh;
end;

procedure TfrViewInformeBase.actFiltrosExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(FILTROS);
  frViewFiltros1.Refresh;
 end;

procedure TfrViewInformeBase.actAgrupacionesExecute(Sender: TObject);
begin
  inherited;
  ActivarTarea(AGRUPACIONES);
  frViewAgrupaciones1.Refresh;
end;

function TfrViewInformeBase.GetOnViewChanged: TNotifyEvent;
begin
  Result := FOnViewChanged;
end;

procedure TfrViewInformeBase.Refresh;
var
  i: Integer;
begin
  inherited;

end;

procedure TfrViewInformeBase.SetOnViewChanged(const Value: TNotifyEvent);
begin
  FOnViewChanged := Value;
end;

procedure TfrViewInformeBase.ComprobarPrivilegios;
begin
  if not dmUsuarios.EsAdministrador then
     TBXMultiDock1.Visible := False;
end;

constructor TfrViewInformeBase.Create(AOwner: TComponent);
begin
  inherited;
  FModificable := False;
  pcParametros.ActivePage := tsColumnas;
  pcTareas.ActivePage := tsSumarios;
  FOnViewChanged := nil;
end;

destructor TfrViewInformeBase.Destroy;
begin
  ViewFiltros := Nil;
  inherited;
end;

function TfrViewInformeBase.GetModificable: Boolean;
begin
  Result := FModificable;
end;

procedure TfrViewInformeBase.SetModificable(const Value: Boolean);
begin
  FModificable := Value;

  frViewColumnas1.Modificable := FModificable;
  frViewAgrupaciones1.Modificable := FModificable;
end;

end.
