unit uConfiguracion;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ActnList, JvComponent,
  JvAppStorage, JvAppRegistryStorage, Contnrs, ExtCtrls, ImgList,
  PngImageList, JvExControls, JvGradientHeaderPanel, uFrameConfiguracion,
  JvComponentBase, JvPageList, JvExComCtrls, JvPageListTreeView,
  uConexionBD, uConfGeneral, uConexionOSC;

type
  TfConfiguracion = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ActionList1: TActionList;
    actAceptar: TAction;
    actCancelar: TAction;
    JvAppRegistryStorage1: TJvAppRegistryStorage;
    PngImageList1: TPngImageList;
    frConfGeneral1: TfrConfGeneral;
    PageControl1: TPageControl;
    pagGeneral: TTabSheet;
    pagBD: TTabSheet;
    frConexionBD1: TfrConexionBD;
    TabSheet1: TTabSheet;
    frConexionOSC1: TfrConexionOSC;
    procedure actAceptarExecute(Sender: TObject);
    procedure actCancelarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    FPaginaActual : IConfiguracionFrame;
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  fConfiguracion: TfConfiguracion;

implementation

uses uDataModuleServer;

{$R *.dfm}

{type
  TFrameClass = class of TFrameConfiguracion;

function CreateFrame(Parent: TWinControl; FrameClass: TFrameClass): IConfiguracionFrame;
var
  aFrame : TFrameConfiguracion;
begin
  aFrame := FrameClass.Create(NIL);
  aFrame.Name:='Frame'+IntToStr(Random(10000));
  aFrame.Parent := Parent;
  aFrame.Init;
  aFrame.Show;
  Result := aFrame;
end;}

procedure TfConfiguracion.actAceptarExecute(Sender: TObject);
begin
  if Assigned(FPaginaActual) then
    FPaginaActual.Finalize;

  dmServer.SalvarConfiguracion;
  Close;
end;

procedure TfConfiguracion.actCancelarExecute(Sender: TObject);
begin
  Close;
end;

constructor TfConfiguracion.Create(AOwner: TComponent);
begin
  inherited;
  FPaginaActual := NIL;
end;

procedure TfConfiguracion.FormShow(Sender: TObject);
begin
  PageControl1.ActivePageIndex := 0;
  //Se ha de llamar al evento ya que la asignación anterior no lo lanza
  PageControl1Change(PageControl1);
end;

procedure TfConfiguracion.PageControl1Change(Sender: TObject);
begin
  if Assigned(FPaginaActual) then
    FPaginaActual.Finalize;

  case PageControl1.ActivePageIndex of
    0   : FPaginaActual := frConfGeneral1;
    1   : FPaginaActual := frConexionBD1;
    2   : FPaginaActual := frConexionOSC1;
  end;

  if Assigned(FPaginaActual) then
    FPaginaActual.Init;

  Self.Update;
end;

end.
