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;

type
  TfConfiguracion = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ActionList1: TActionList;
    actAceptar: TAction;
    actCancelar: TAction;
    JvAppRegistryStorage1: TJvAppRegistryStorage;
    PngImageList1: TPngImageList;
    JvSettingsTreeView1: TJvSettingsTreeView;
    JvPageList1: TJvPageList;
    JvStandardPage1: TJvStandardPage;
    JvStandardPage2: TJvStandardPage;
    frConfGeneral1: TfrConfGeneral;
    frConfConexionBD: TfrConexionBD;
    procedure tvArbolChange(Sender: TObject; Node: TTreeNode);
    procedure actAceptarExecute(Sender: TObject);
    procedure actCancelarExecute(Sender: TObject);
    procedure JvSettingsTreeView1Changing(Sender: TObject; Node: TTreeNode;
      var AllowChange: Boolean);
  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.tvArbolChange(Sender: TObject; Node: TTreeNode);
begin
{  if Assigned(FPaginaActual) then
    FPaginaActual.Finalize;

  case Node.Index of
    0   : FPaginaActual := CreateFrame(pnlPagina, TfrConfGeneral);
    1   : FPaginaActual := CreateFrame(pnlPagina, TfrConexionBD);
    2   : FPaginaActual := CreateFrame(pnlPagina, TfrConfFicherosEDI);
  end;
  Self.Update;
  pnlHeader.LabelCaption := Node.Text;}
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;
end;

procedure TfConfiguracion.JvSettingsTreeView1Changing(Sender: TObject;
  Node: TTreeNode; var AllowChange: Boolean);
begin
  if Assigned(FPaginaActual) then
    FPaginaActual.Finalize;

  case Node.Index of
    0   : FPaginaActual := frConfGeneral1;
    1   : FPaginaActual := frConfConexionBD;
  end;
  if Assigned(FPaginaActual) then
    FPaginaActual.Init;
  Self.Update;
end;

end.
