#include "stdafx.h"
#include "Global.h"
#include "SetForm.h"
#include <Windows.h>
#include <stdio.h>
using namespace ObjDataEdit;

Void SetForm::LoadSetting(System::Object *  sender, System::EventArgs *  e)
{    
	TB_DataPath->Text = Global::GetIniString( "DataPath" );
    TB_ResourcePath->Text = Global::GetIniString( "ResourcePath" );

	int	LanguageSetting = atol( Global::GetIniString( "LanguageSetting" ) );
	if( LanguageSetting == 0 )
		LanguageSetting = -1;

	for( int i = 0 ; i < CList_Language->Items->Count ; i++ )
	{
		if( TestBit( LanguageSetting , i ) != 0 )
			CList_Language->SetItemChecked( i , true );
		else
			CList_Language->SetItemChecked( i , false );
	}
	/*
	int Flag = 0;
	for( int i = CList_Language->Items->Count -1  ; i >= 0 ; i -- )
	{
	Flag *= 2;
	if( CList_Language->GetItemChecked( i ) == true )
	Flag++;
	}

	if( Flag != 0 )
	{
	if( Str->Length  != 0 )
	Str = String::Format( "{0} and ( (OutputLanguage & %d) != 0 )" , Str , __box(Flag) );
	else
	Str = String::Format( "WHERE ( (OutputLanguage & %d) != 0 )" , __box(Flag) );

	}
	*/
}

Void SetForm::SaveSetting(System::Object *  sender, System::EventArgs *  e)
{
	if( IsChange == false )
		return;

    char    Buf[256];
    char*	Path = (char*)Global::IniRootPath.c_str(); 

    sprintf( Buf , "\"%s\"" , DotNetStr::StringToChar( TB_DataPath->Text ).c_str() );
    WritePrivateProfileString( "BOOT" , "DataPath", Buf , Path );
    sprintf( Buf , "\"%s\"" , DotNetStr::StringToChar( TB_ResourcePath->Text ).c_str() );
    WritePrivateProfileString( "BOOT" , "ResourcePath", Buf , Path );

	int LanguageSetting = 0;
	for( int i = CList_Language->Items->Count -1  ; i >= 0 ; i -- )
	{
		LanguageSetting *= 2;
		if( CList_Language->GetItemChecked( i ) == true )
			LanguageSetting++;
	}

	sprintf( Buf , "%d" , LanguageSetting );
	WritePrivateProfileString( "BOOT" , "LanguageSetting", Buf , Path );


	int Result = MessageBox::Show( "需要重新開啟程式資料才會正確" , "警告" , MessageBoxButtons::YesNo  );

	if( Result == DialogResult::Yes )
	{
		exit(1);
	}

    this->Close();
}