//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FrmOptionF.h"
#include "AppGlobalF.h"
#include "FrmControllerInfoF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmOption *FrmOption;
//---------------------------------------------------------------------------
__fastcall TFrmOption::TFrmOption(TComponent* Owner)
    : TForm(Owner)
{
    FUpdate = false;
}
//---------------------------------------------------------------------------
void __fastcall TFrmOption::btnCloseClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TFrmOption::btnSetLogClick(TObject *Sender)
{
    // 로그설정
	if (MessageDlg("옵션 정보를 설정 하시겠습니까?", mtWarning, TMsgDlgButtons() << mbYes << mbNo, 0) != mrYes)
    {
		return;
	}

    bool bUpdate = false;
    if (g_LogCfg.Info   != chkInfo->Checked)
    {
        g_LogCfg.Info    = chkInfo->Checked;
        bUpdate = true;
    }
    if (g_LogCfg.Data   != chkData->Checked)
    {
        g_LogCfg.Data    = chkData->Checked;
        bUpdate = true;
    }
    if (g_LogCfg.Error  != chkError->Checked)
    {
        g_LogCfg.Error   = chkError->Checked;
        bUpdate = true;
    }
    if (g_LogCfg.Warning!= chkWarning->Checked)
    {
        g_LogCfg.Warning = chkWarning->Checked;
        bUpdate = true;
    }
    if (g_LogCfg.Debug  != chkDebug->Checked)
    {
        g_LogCfg.Debug   = chkDebug->Checked;
        bUpdate = true;
    }
    if (g_LogCfg.Detail != chkDetail->Checked)
    {
        g_LogCfg.Detail  = chkDetail->Checked;
        bUpdate = true;
    }

    APP_WriteConfigInfo("LOG", "INFO",    g_LogCfg.Info    ? "1" : "0", g_AppCfg.sConfigFile);
    APP_WriteConfigInfo("LOG", "DATA",    g_LogCfg.Data    ? "1" : "0", g_AppCfg.sConfigFile);
    APP_WriteConfigInfo("LOG", "ERROR",   g_LogCfg.Error   ? "1" : "0", g_AppCfg.sConfigFile);
    APP_WriteConfigInfo("LOG", "WARNING", g_LogCfg.Warning ? "1" : "0", g_AppCfg.sConfigFile);
    APP_WriteConfigInfo("LOG", "DEBUG",   g_LogCfg.Debug   ? "1" : "0", g_AppCfg.sConfigFile);
    APP_WriteConfigInfo("LOG", "DETAIL",  g_LogCfg.Detail  ? "1" : "0", g_AppCfg.sConfigFile);

    if (bUpdate) FUpdate = bUpdate;

	//MessageDlg("로그설정이 변경되었습니다.", mtCustom, TMsgDlgButtons() << mbOK, 0);
}
//---------------------------------------------------------------------------
void __fastcall TFrmOption::FormShow(TObject *Sender)
{
    // 서버정보 표출
    plTot->Caption = FrmControllerInfo->plTot->Caption;
    plErr->Caption = FrmControllerInfo->plErr->Caption;
    plNor->Caption = FrmControllerInfo->plNor->Caption;

    plProcessId->Caption  = g_AppCfg.sProcessId + " (" + String(g_AppCfg.nProcessPort) + ")";
    plSystemId->Caption   = g_AppCfg.sSystemId;
    //plIpAddress->Caption  = DMManager->TcpServer->LocalHostAddr();
    plCenterPort->Caption = g_AppCfg.comm.nCenterPort;
    plVmsPort->Caption    = g_AppCfg.comm.nListenPort;
    plVmsConPort->Caption = g_AppCfg.comm.nClientPort;

    // 로그설정
    chkInfo->Checked    = g_LogCfg.Info;
    chkData->Checked    = g_LogCfg.Data;
    chkError->Checked   = g_LogCfg.Error;
    chkWarning->Checked = g_LogCfg.Warning;
    chkDebug->Checked   = g_LogCfg.Debug;
    chkDetail->Checked  = g_LogCfg.Detail;
}
//---------------------------------------------------------------------------

