unit OptionFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, XPMenu;

type
  TOptionForm = class(TForm)
    pcOptions: TPageControl;
    tsCommon: TTabSheet;
    btnOk: TButton;
    btnCancel: TButton;
    lblCommon: TLabel;
    pnlUserInfo: TPanel;
    xpm: TXPMenu;
    cbAutoSave: TCheckBox;
    lblSaveInterval: TLabel;
    cbbSaveIntervall: TComboBox;
    lblMinutes: TLabel;
    gbOverRange: TGroupBox;
    lblTitleOverRange: TLabel;
    rbLedger: TRadioButton;
    rbDeal: TRadioButton;
    rbBoth: TRadioButton;
    procedure cbAutoSaveClick(Sender: TObject);
    procedure rbLedgerClick(Sender: TObject);
  private
    procedure SetSaveIntervalEnable(AEnable: Boolean);
    function GetOverRangeType: Integer;
    procedure SetOverRangeType(const Value: Integer);
  public
    procedure Load;
    procedure Save;

    property OverRangeType: Integer read GetOverRangeType write SetOverRangeType;
  end;

procedure ModifiedOptions;

implementation

{$R *.dfm}

uses
  Globals, ConfigDoc;

procedure ModifiedOptions;
var
  OptionFrom: TOptionForm;
begin
  OptionFrom := TOptionForm.Create(nil);
  try
    OptionFrom.Load;
    if OptionFrom.ShowModal = mrOk then
      OptionFrom.Save;
  finally
    OptionFrom.Free;
  end;
end;

{ TOptionForm }

procedure TOptionForm.Load;
begin
  with SupportManager.ConfigInfo do
  begin
    cbAutoSave.Checked := AutoSave;
    SetSaveIntervalEnable(cbAutoSave.Checked);
    cbbSaveIntervall.Text := IntToStr(AutoSaveInterval);
    Self.OverRangeType := OverRangeType;
  end;
end;

procedure TOptionForm.Save;
begin
  with SupportManager.ConfigInfo do
  begin
    AutoSave := cbAutoSave.Checked;
    AutoSaveInterval := StrToIntDef(cbbSaveIntervall.Text, 15);
    OverRangeType := Self.OverRangeType;
  end;
end;

procedure TOptionForm.cbAutoSaveClick(Sender: TObject);
begin
  SetSaveIntervalEnable(cbAutoSave.Checked);
end;

procedure TOptionForm.SetSaveIntervalEnable(AEnable: Boolean);
begin
  lblSaveInterval.Enabled := AEnable;
  cbbSaveIntervall.Enabled := AEnable;
  lblMinutes.Enabled := AEnable;
end;

function TOptionForm.GetOverRangeType: Integer;
begin
  if rbLedger.Checked then
    Result := rbLedger.Tag
  else if rbDeal.Checked then
    Result := rbDeal.Tag
  else if rbBoth.Checked then
    Result := rbBoth.Tag;
end;

procedure TOptionForm.SetOverRangeType(const Value: Integer);
begin
  rbLedger.Checked := rbLedger.Tag = Value;
  rbDeal.Checked := rbDeal.Tag = Value;
  rbBoth.Checked := rbBoth.Tag = Value;
end;

procedure TOptionForm.rbLedgerClick(Sender: TObject);
begin
  TRadioButton(Sender).Checked := True;
end;

end.
