//---------------------------------------------------------------------------
#include <vcl.h>
#include <IniFiles.hpp>
#pragma hdrstop
#include "frmConfig.h"
#include "dlgFinVolSet.h"
#include "FrmTikers.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormConfig*  FormConfig;
bool          NotDeltemp          = false;
AnsiString    FinamURL;
int           FinamVolTrunc       = 0;
AnsiString    FinamDivTikers;
int           ConnectTimeout      = 30;
bool          ProxyEnable         = false;
int           ProxyPort           = 0;
AnsiString    ProxyServer;
AnsiString    ProxyUser;
AnsiString    ProxyPassword;
//---------------------------------------------------------------------------
__fastcall TFormConfig::TFormConfig(TComponent* Owner)	: TForm(Owner)
{
   CheckBox9->Checked   = NotDeltemp;
   UpDown3->Position    = ConnectTimeout;
   CheckBox2->Checked   = ProxyEnable;
   Edit3->Text          = ProxyServer;
   Edit4->Text          = ProxyPort;
   Edit5->Text          = ProxyUser;
   Edit6->Text          = ProxyPassword;

   Memo1->Text          = FinamURL;
   CheckBox2Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TFormConfig::Button1Click(TObject *Sender)
{
  TMemIniFile*     ini = new TMemIniFile( ".\\finam.ini");


	ini->WriteBool(    "main", "not_deltemp",     CheckBox9->Checked);
	ini->WriteInteger( "main", "connect_timeout", UpDown3->Position);
	ini->WriteBool(    "main", "proxy_enable",    CheckBox2->Checked);
	ini->WriteString(  "main", "proxy_server",    Edit3->Text);
	ini->WriteInteger( "main", "proxy_port",      Edit4->Text.ToInt());
	ini->WriteString(  "main", "proxy_user",      Edit5->Text);
	ini->WriteString(  "main", "proxy_password",  Edit6->Text);
	ini->WriteString(  "main", "url",             Memo1->Text);

	NotDeltemp           = CheckBox9->Checked;
	ConnectTimeout       = UpDown3->Position;
	ProxyEnable          = CheckBox2->Checked;
	ProxyServer          = Edit3->Text;
	ProxyPort            = Edit4->Text.ToInt();
	ProxyUser            = Edit5->Text;
	ProxyPassword        = Edit6->Text;

	FinamURL             = Memo1->Text;

	ini->UpdateFile();

   delete ini;
}
//---------------------------------------------------------------------------
void __fastcall TFormConfig::Button3Click(TObject *Sender)
{
  TMemIniFile*     ini = new TMemIniFile( ".\\finam.ini");


    VolSetDlg = new TVolSetDlg(NULL);
	VolSetDlg->UpDown1->Position = FinamVolTrunc;
	VolSetDlg->Edit2->Text       = FinamDivTikers;
	if( VolSetDlg->ShowModal() == mrOk )
	{
	   ini->WriteInteger( "main", "vol_trunc",  VolSetDlg->UpDown1->Position);
	   ini->WriteString(  "main", "div_tikers", VolSetDlg->Edit2->Text);

	   FinamVolTrunc  = VolSetDlg->UpDown1->Position;
	   FinamDivTikers = VolSetDlg->Edit2->Text;
	}

	ini->UpdateFile();

  delete ini;
  delete VolSetDlg;
}
//---------------------------------------------------------------------------
void __fastcall TFormConfig::Button2Click(TObject *Sender)
{
  FormTikers = new TFormTikers( NULL);

   FormTikers->ShowModal();

  delete FormTikers;
}
//---------------------------------------------------------------------------
void __fastcall TFormConfig::CheckBox2Click(TObject *Sender)
{
   Edit3->Enabled   = CheckBox2->Checked;
   Edit4->Enabled   = CheckBox2->Checked;
   Edit5->Enabled   = CheckBox2->Checked;
   Edit6->Enabled   = CheckBox2->Checked;
   Label5->Enabled  = CheckBox2->Checked;
   Label7->Enabled  = CheckBox2->Checked;
   Label8->Enabled  = CheckBox2->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TFormConfig::FormKeyPress(TObject *Sender, wchar_t &Key)
{
   if( Key == VK_ESCAPE )	Close();
}
//---------------------------------------------------------------------------

