unit uViewInforme;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Forms,
  Dialogs, uViewBase, TBXDkPanels, StdCtrls, ComCtrls, TB2Dock,
  uViewAgrupaciones, uCustomView, uViewColumnas, ImgList, PngImageList,
  ActnList, uViewInformeGrid, uBizInformesBase, uViewSumarios,
  uViewInformeParametros, uViewFiltros, cxStyles, Controls;

type
  IViewInforme = interface(IViewBase)
  ['{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;

  TfrViewInforme = class(TfrViewBase, IViewInforme)
    TBXMultiDock1: TTBXMultiDock;
    pnlParametros: TTBXDockablePanel;
    TBXAlignmentPanel2: TTBXAlignmentPanel;
    TBXLink1: TTBXLink;
    TBXLink5: TTBXLink;
    TBXLink2: TTBXLink;
    pcParametros: TPageControl;
    TabSheet5: TTabSheet;
    tsColumnas: TTabSheet;
    tsAgrupacion: TTabSheet;
    TBXAlignmentPanel3: TTBXAlignmentPanel;
    bRefrescar: TButton;
    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;
    procedure actColumnasExecute(Sender: TObject);
    procedure actSumariosExecute(Sender: TObject);
    procedure actFiltrosExecute(Sender: TObject);
    procedure actAgrupacionesExecute(Sender: TObject);
  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;
  end;

implementation

{$R *.dfm}

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


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

procedure TfrViewInforme.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 TfrViewInforme.GetInforme: IBizInforme;
begin
  Result := FInforme;
end;

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

  // żEs modificable el Informe?
//  Self.Modificable := FInforme.EsModificable;
end;

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

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

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

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

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

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

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

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

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

end.
