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;
    GroupBox1: TGroupBox;
    cbExcelWithMis: TCheckBox;
    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
  OptionForm: TOptionForm;
begin
  OptionForm := TOptionForm.Create(nil);
  try
    OptionForm.Load;
    OptionForm.ClientHeight := 338;
    OptionForm.ClientWidth := 479;
    if OptionForm.ShowModal = mrOk then
      OptionForm.Save;
  finally
    OptionForm.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;
    cbExcelWithMis.Checked := ExcelWithMis;
  end;
end;

procedure TOptionForm.Save;
begin
  with SupportManager.ConfigInfo do
  begin
    AutoSave := cbAutoSave.Checked;
    AutoSaveInterval := StrToIntDef(cbbSaveIntervall.Text, 15);
    OverRangeType := Self.OverRangeType;
    ExcelWithMis := cbExcelWithMis.Checked;
  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.
