#include "PEForm.h"

using namespace ObjDataEdit;
using namespace DevExpress::XtraTreeList;
using namespace DevExpress::XtraTreeList::Nodes;

#define safe_strcopy(dest, src) {strncpy(dest, src, sizeof(dest)); dest[sizeof(dest) - 1] = 0;}

#define PE_MIN_GUID 790000
#define PE_MAX_GUID 791999
#define PH_MIN_GUID 792000
#define PH_MAX_GUID 809999
#define OB_MIN_GUID 810000
#define OB_MAX_GUID 854999
#define VAR_MIN_GUID 855000
#define VAR_MAX_GUID 899999

//**************************************************************************************
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEComponet::PEComponet(BaseForm* pPEForm, void* pRootObjDB)
{
	m_Type = EM_PE_COM_NONE;
	m_Form = pPEForm;
	m_StrList = new vector <char*>();
	m_pRootObjDB = pRootObjDB;

	m_MinGUID	= 0;
	m_MaxGUID	= 0;

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	memset(pObjDB, 0, sizeof(DB_GameObjDbStruct));

	//--------------------------------------------------------------
	//初始化SqlCommand物件指標 
	m_SQL = NULL;
	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		m_SQL = pForm->SQL;

		//--------------------------------------------------------------
		//配置字串記憶體
		std::map<std::string,ReadInfoStruct>* DataFields	= ObjReader->ReadInfo();
		std::map<std::string,ReadInfoStruct>::iterator it;

		ReadInfoStruct* pField = NULL;
		int iBaseAddr = (int)(&m_ObjDB);
		int iOffset = 0;

		for( it = DataFields->begin() ; it != DataFields->end() ; it++  )
		{		
			pField = &(it->second);
			iOffset = pField->Point;

			switch(pField->Type)
			{
			case ENUM_Type_CharStringPoint:
			case ENUM_Type_TextDataPoint:
				{
					unsigned long dwSize = 2048;

					if( pField->Size > 0 )
					{
						dwSize = pField->Size;
					}

					char* newStr = new char[dwSize];
					memset(newStr, 0, dwSize);

					*(char**)(iBaseAddr + iOffset) = newStr;

					m_StrList->push_back(newStr);
				}
				break;
			}
		}
		//--------------------------------------------------------------
	}
	//--------------------------------------------------------------
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEComponet::Release()
{
	if( m_StrList != NULL )
	{
		for( unsigned int i = 0 ; i < m_StrList->size() ; i++ )
		{
			delete (*m_StrList)[ i ];
		}
		delete m_StrList;
		m_StrList = NULL;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEComponet::ToString()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	return new String(pObjDB->GameData.Name);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::NewObjDB(int iParentGUID)
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	SqlDataReader* DBReader = NULL;
	String* strDBName = new String(DBName);

	//-------------------------------------------------------
	//get last GUID
	int	iGUID = m_MinGUID;

	m_SQL->CommandText = String::Format("SELECT GUID FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2})", strDBName, __box(m_MinGUID), __box(m_MaxGUID));
	DBReader = m_SQL->ExecuteReader();
	if(DBReader->Read())
	{
		DBReader->Close();

		m_SQL->CommandText = String::Format("SELECT GUID FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2}) AND (ParentGUID = 0) AND (Type = 0)", strDBName, __box(m_MinGUID), __box(m_MaxGUID));
		DBReader = m_SQL->ExecuteReader();

		if (DBReader->Read())
		{
			iGUID = DBReader->GetInt32(0);
			DBReader->Close();
		}
		else
		{
			DBReader->Close();

			m_SQL->CommandText = String::Format("SELECT MAX(GUID) FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2})", strDBName, __box(m_MinGUID), __box(m_MaxGUID));
			DBReader = m_SQL->ExecuteReader();

			if(DBReader->Read())
			{
				iGUID = DBReader->GetInt32(0);
				iGUID++;
			}
			DBReader->Close();

			//-------------------------------------------------------
			//Insert a new record
			m_SQL->CommandText = String::Format("INSERT INTO {0} (GUID) VALUES ({1})" , strDBName, __box(iGUID));
			DBReader = m_SQL->ExecuteReader();
			DBReader->Close();
			//-------------------------------------------------------
		}		
	}
	else
	{
		DBReader->Close();
		//-------------------------------------------------------
		//Insert a new record
		m_SQL->CommandText = String::Format("INSERT INTO {0} (GUID) VALUES ({1})" , strDBName, __box(iGUID));
		DBReader = m_SQL->ExecuteReader();
		DBReader->Close();
		//-------------------------------------------------------
	}
	//-------------------------------------------------------

	//-------------------------------------------------------
	//更新所有的字串資料
	std::map<std::string,ReadInfoStruct>* DataFields	= ObjReader->ReadInfo();
	std::map<std::string,ReadInfoStruct>::iterator it;
	ReadInfoStruct* pField = NULL;

	for(it = DataFields->begin() ; it != DataFields->end() ; it++)
	{
		String* strFieldName = new String((it->first).c_str());
		pField = &(it->second);

		switch(pField->Type)
		{
			//此型態欄位需要檢查StringDB
		case ENUM_Type_CharStringPoint:
		case ENUM_Type_TextDataPoint:
			{			
				//組合KeyStr
				String* strKey = String::Format("Sys{0}_{1}", __box(iGUID) , strFieldName);

				//----------------------------------------------------------
				//檢查系統字串是否已存在
				bool IsFindStr;
				m_SQL->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}'", strKey);
				DBReader = m_SQL->ExecuteReader();
				while( DBReader->Read( ) )
				{
					if( DBReader->GetInt32( 0 ) != 0 )
					{
						IsFindStr = true;
						break;
					}
				}
				DBReader->Close();
				//----------------------------------------------------------

				//----------------------------------------------------------
				//字串不存在, 新增系統字串
				if( IsFindStr == false )
				{
					m_SQL->CommandText = String::Format("INSERT INTO StringDB( Type , KeyStr ,OrgObjID, Content , Note ) VALUES ( 1 , '{0}' , {1}, '' , '系統物件字串' )", strKey, __box(iGUID));
					DBReader = m_SQL->ExecuteReader();
					DBReader->Close();
				}
				//----------------------------------------------------------
			}
			break;
		default:
			continue;
		}
	}

	DB_GameObjDbStruct* pRootObjDB = static_cast<DB_GameObjDbStruct*>(m_pRootObjDB);

	pObjDB->ZoneID					= pRootObjDB->ZoneID;
	pObjDB->TagID					= pRootObjDB->TagID;
	pObjDB->VersionID				= pRootObjDB->VersionID;
	pObjDB->Translate				= pRootObjDB->Translate;
	pObjDB->ProcRate				= pRootObjDB->ProcRate;
	pObjDB->GameData.LanguageSet	= pRootObjDB->GameData.LanguageSet;
	pObjDB->GameData.ImageID		= pRootObjDB->GameData.ImageID;
	safe_strcopy(pObjDB->LockAccount, pRootObjDB->LockAccount);
	safe_strcopy(pObjDB->DataGroup, pRootObjDB->DataGroup);
	pObjDB->GameData.GUID			= iGUID;
	pObjDB->GameData.PE.ParentGUID	= iParentGUID;
	pObjDB->GameData.PE.Type		= m_Type;

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::ReadObjDB(int iGUID)
{
	bool Result = false;

	char Buf[4096];

	SqlDataReader* DBReader	= NULL;

	//---------------------------------------------------------------
	//select data from database
	sprintf( Buf , "WHERE GUID = %d" , iGUID);
	CreateDBCmdClass<DB_GameObjDbStruct> CreateCMD( ObjReader, DBName);
	m_SQL->CommandText = new String(CreateCMD.GetSelectStr( Buf ).c_str());
	DBReader = m_SQL->ExecuteReader();
	//---------------------------------------------------------------

	//---------------------------------------------------------------
	//fill data into m_Data
	if( DBReader->Read( ) )
	{
		std::map<std::string,ReadInfoStruct>* DataFields	= ObjReader->ReadInfo();
		std::map<std::string,ReadInfoStruct>::iterator it;
		std::string szFieldName = "";
		int iFieldID = 0;

		ReadInfoStruct* pField = NULL;
		int iBaseAddr = (int)(&m_ObjDB);
		int iOffset = 0;
		char* pData = NULL;

		//---------------------------------------------------------------
		//fill data except system string
		for(it  = DataFields->begin(); it != DataFields->end() ; it++)
		{
			szFieldName = it->first;
			pField = &(it->second);
			iOffset = pField->Point;

			pData = (char*)(iBaseAddr + iOffset);

			switch(pField->Type)
			{
			case ENUM_Type_BinaryData:
				{
					char utf8 __gc[] = DBReader->GetSqlBinary(iFieldID++).Value;   
					char __pin* data = &utf8[0];
					memcpy( pData, data, pField->Size );
				}
				break;
			case ENUM_Type_FloatPoint:
				{
					*((float*)pData) = DBReader->GetFloat( iFieldID++ );
				}
				break;

			case ENUM_Type_IntPoint:
				{
					*((int*)pData) = DBReader->GetInt32( iFieldID++ );
				}
				break;

			case ENUM_Type_ShortPoint:
				{
					*((short*)pData) = DBReader->GetInt16( iFieldID++ );
				}                
				break;
			case ENUM_Type_BitPoint:
				{
					*((bool*)pData) = DBReader->GetBoolean( iFieldID++ );
				}
				break;
			case ENUM_Type_CharString:
			case ENUM_Type_TextData:
				{
					std::string szStr = DotNetStr::StringToChar( DBReader->GetString( iFieldID++ ) );
					strcpy( pData, szStr.c_str() );
				}    
				break;
			case ENUM_Type_CharStringPoint:
			case ENUM_Type_TextDataPoint:
				{
					//此欄位不處理
				}
				break;
			case ENUM_Type_TimeCharString:
				{
					ArrayList* args = new ArrayList();

					DateTime dtNow = DBReader->GetDateTime( iFieldID++ );

					args->Add(dtNow.ToString("d"));
					args->Add(__box(dtNow.Hour));
					args->Add(__box(dtNow.Minute));
					args->Add(__box(dtNow.Second));

					String* strNow = String::Format( "{0} {1}:{2}:{3}", args->ToArray());

					args->Clear();

					strcpy( pData , DotNetStr::StringToChar( strNow ).c_str() );
				}
				break;
			}
		}

		DBReader->Close();
		//---------------------------------------------------------------

		//---------------------------------------------------------------
		//讀取字串資料
		//更新所有的字串資料
		for( it = DataFields->begin() ; it != DataFields->end() ; it++  )
		{		
			szFieldName = it->first;
			pField = &(it->second);
			iOffset = pField->Point;

			switch(pField->Type)
			{
			case ENUM_Type_CharStringPoint:
			case ENUM_Type_TextDataPoint:	
				{
					pData = *(char**)(iBaseAddr + iOffset);
					pData[0] = 0;

					//檢查資料是否有更新
					m_SQL->CommandText = String::Format("SELECT Content FROM StringDB WHERE KeyStr = 'Sys{0}_{1}'", __box(iGUID) , new String(szFieldName.c_str()));
					DBReader  = m_SQL->ExecuteReader();
					while( DBReader->Read( ) )
					{
						String* strData = DBReader->GetString( 0 );
						strcpy( pData , DotNetStr::StringToChar( strData ).c_str() );
					}
					DBReader->Close();
				}
				break;
			default:
				continue;
			}
		}
		//---------------------------------------------------------------

		Result = true;
	}
	
	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::SaveObjDB()
{	
	SqlDataReader* DBReader = NULL;
	
	ArrayList* args = new ArrayList();

	DB_GameObjDbStruct __pin * pObjDB = &m_ObjDB;
	DB_GameObjDbStruct* pRootObjDB = static_cast<DB_GameObjDbStruct*>(m_pRootObjDB);
	int iGUID = pObjDB->GameData.GUID;

	char Buf[0x20000];
	//-----------------------------------------------------------------------------
	pObjDB->ZoneID					= pRootObjDB->ZoneID;
	pObjDB->TagID					= pRootObjDB->TagID;
	pObjDB->VersionID				= pRootObjDB->VersionID;
	pObjDB->Translate				= pRootObjDB->Translate;
	pObjDB->ProcRate				= pRootObjDB->ProcRate;
	pObjDB->GameData.LanguageSet	= pRootObjDB->GameData.LanguageSet;
	pObjDB->GameData.ImageID		= pRootObjDB->GameData.ImageID;
	safe_strcopy(pObjDB->LockAccount, pRootObjDB->LockAccount);
	safe_strcopy(pObjDB->DataGroup, pRootObjDB->DataGroup);
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//設定最後修正日期以及修改者
	DateTime dtNow = DateTime::Now;

	args->Add(dtNow.ToString("d"));
	args->Add(__box(dtNow.Hour));
	args->Add(__box(dtNow.Minute));
	args->Add(__box(dtNow.Second));

	String* strNow = String::Format( "{0} {1}:{2}:{3}", args->ToArray());

	args->Clear();

	pObjDB->IsLock   = false;
	pObjDB->IsModify = false;	
	strncpy( (char*)&pObjDB->LastModifyAccount[0] , DotNetStr::StringToChar(Account).c_str(), sizeof(pObjDB->LastModifyAccount));
	pObjDB->LastModifyAccount[sizeof(pObjDB->LastModifyAccount) - 1] = 0;
	strncpy( (char*)&pObjDB->LastModifyDate[0] , DotNetStr::StringToChar(strNow).c_str(), sizeof(pObjDB->LastModifyDate));
	pObjDB->LastModifyDate[sizeof(pObjDB->LastModifyDate) - 1] = 0;
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新主要資料
	sprintf( Buf , " Where GUID = %d" , iGUID );
	CreateDBCmdClass<DB_GameObjDbStruct> CreateCMD(ObjReader, DBName);
	std::string szUpdateStr = CreateCMD.GetUpDateStr(pObjDB , Buf );
	m_SQL->CommandText = new String(szUpdateStr.c_str());
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//解除資料鎖定
	m_SQL->CommandText = String::Format( "UpDate {0} Set IsLock = 0 Where GUID = {1}" , new String(DBName) , __box(iGUID));
	DBReader = m_SQL->ExecuteReader( );
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新所有的自動產生的系統字串資料
	std::map<std::string,ReadInfoStruct>* DataFields	= ObjReader->ReadInfo();
	std::map<std::string,ReadInfoStruct>::iterator it;
	std::string szFieldName = "";
	std::string szKeyStr = "";

	ReadInfoStruct* pField = NULL;
	int iBaseAddr = (int)(&m_ObjDB);
	int iOffset = 0;
	char* pData = NULL;

	for(it  = DataFields->begin() ; it != DataFields->end() ; it++  )
	{
		String* strFieldName = new String((it->first).c_str());
		pField = &(it->second);
		iOffset = pField->Point;

		switch(pField->Type)
		{
		case ENUM_Type_CharStringPoint:
		case ENUM_Type_TextDataPoint:
			{
				//"最後修改帳號", "鎖定帳號", "資料群組" 不處理
				if(     String::Equals( strFieldName->ToLower() , "lastmodifyaccount" ) 
					||  String::Equals( strFieldName->ToLower() , "lockaccount" )
					||  String::Equals( strFieldName->ToLower() , "datagroup" ) )
				{
					continue;
				}

				pData = *(char**)(iBaseAddr + iOffset);

				String* strSql = new String(StringToSqlStr( pData , pField->Size ).c_str());
				String* strKey = String::Format("Sys{0}_{1}", __box(iGUID), strFieldName);

				//檢查資料是否存在
				bool IsStrNotFind;
				m_SQL->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}'", strKey);
				DBReader = m_SQL->ExecuteReader();
				while( DBReader->Read( ) )			
				{
					if( DBReader->GetInt32( 0 ) == 0 )
						IsStrNotFind = true;
					else
						IsStrNotFind = false;		
				}
				DBReader->Close();


				if( IsStrNotFind == true )
				{
					args->Add(strKey);
					args->Add(strSql);
					args->Add(__box(iGUID));
					args->Add(Account);

					m_SQL->CommandText = String::Format("INSERT StringDB(KeyStr, Type, Content, OrgObjID, Content_Editor) VALUES('{0}', 1, '{1}', {2}, '{3}')", args->ToArray());
					DBReader = m_SQL->ExecuteReader();
					DBReader->Close();

					args->Clear();
				}
				else
				{
					if( strcmp( pData , "" ) == 0 || strcmp( pData, " " ) == 0 )
					{
						//清空字串資料
						m_SQL->CommandText = String::Format("UPDATE StringDB SET UpdateTime = getdate(), IsConfirmed1 = 0, IsConfirmed2 = 0, IsConfirmed3 = 0, IsConfirmed4 = 0, IsConfirmed5 = 0, IsConfirmed6 = 0, IsConfirmed7 = 0, IsConfirmed8 = 0, IsConfirmed9 = 0, IsConfirmed10 = 0, IsConfirmed11 = 0, IsConfirmed12 = 0, IsConfirmed13 = 0, IsConfirmed14 = 0, IsConfirmed15 = 0, IsUpdate = 1, IsTranslated1 = 0, IsTranslated2 = 0, IsTranslated3 = 0, IsTranslated4 = 0, IsTranslated5 = 0, IsTranslated6 = 0, IsTranslated7 = 0, IsTranslated8 = 0, IsTranslated9 = 0, IsTranslated10 = 0, IsTranslated11 = 0, IsTranslated12 = 0, IsTranslated13 = 0, IsTranslated14 = 0, IsTranslated15 = 0,  Content = '', Content_Language1 = '', Content_Language2 = '', Content_Language3 = '', Content_Language4 = '', Content_Language5 = '', Content_Language6 = '', Content_Language7 = '', Content_Language8 = '', Content_Language9 = '', Content_Language10 = '', Content_Language11 = '', Content_Language12 = '', Content_Language13 = '', Content_Language14 = '', Content_Language15 = '', Content_Editor = '{0}' WHERE KeyStr = '{1}'", Account, strKey);
						DBReader = m_SQL->ExecuteReader();
						DBReader->Close();
					}
					else
					{
						//檢查資料是否有更新
						bool IsStrChange = false;

						m_SQL->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}' and Content = '{1}'", strKey, strSql);
						DBReader  = m_SQL->ExecuteReader();   

						while( DBReader->Read( ) )
						{
							if( DBReader->GetInt32( 0 ) != 0 )
								IsStrChange = false;
							else
								IsStrChange = true;
						}
						DBReader->Close();

						if( IsStrChange  )
						{
							//更新資料
							m_SQL->CommandText = String::Format("UPDATE StringDB SET UpdateTime = getdate(), IsConfirmed1 = 0, IsConfirmed2 = 0, IsConfirmed3 = 0, IsConfirmed4 = 0, IsConfirmed5 = 0, IsConfirmed6 = 0, IsConfirmed7 = 0, IsConfirmed8 = 0, IsConfirmed9 = 0, IsConfirmed10 = 0, IsConfirmed11 = 0, IsConfirmed12 = 0, IsConfirmed13 = 0, IsConfirmed14 = 0, IsConfirmed15 = 0, IsUpdate = 1, IsTranslated1 = 0, IsTranslated2 = 0, IsTranslated3 = 0, IsTranslated4 = 0, IsTranslated5 = 0, IsTranslated6 = 0, IsTranslated7 = 0, IsTranslated8 = 0, IsTranslated9 = 0, IsTranslated10 = 0, IsTranslated11 = 0, IsTranslated12 = 0, IsTranslated13 = 0, IsTranslated14 = 0, IsTranslated15 = 0, Content = '{0}', Content_Editor = '{1}' WHERE KeyStr = '{2}'" , strSql, Account, strKey);
							DBReader = m_SQL->ExecuteReader();
							DBReader->Close();
						}
					}
				}
			}
			break;
		default:
			continue;
		}
	}
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新輸出語系
	m_SQL->CommandText = String::Format("UPDATE StringDB SET OutputLanguage = {0} WHERE OrgObjID = {1} " , __box(pObjDB->GameData.LanguageSet) , __box(iGUID));
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//修改翻譯分類	
	args->Add(__box(pObjDB->ZoneID));
	args->Add(__box(pObjDB->TagID));
	args->Add(__box(pObjDB->VersionID));
	args->Add(__box((int)(pObjDB->Translate)));
	args->Add(__box(iGUID));

	m_SQL->CommandText = String::Format("UPDATE StringDB SET DirZoneID = {0} , DirTagID = {1} , DirVersionID = {2}, Translate = {3} WHERE OrgObjID = {4}", args->ToArray());	
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();

	args->Clear();
	//-----------------------------------------------------------------------------

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::RemoveObjDB()
{
	DB_GameObjDbStruct __pin * pObjDB = &m_ObjDB;

	memset(&(pObjDB->GameData.PE), 0, sizeof(pObjDB->GameData.PE));

	SqlDataReader* DBReader = NULL;
	
	m_SQL->CommandText = String::Format("UPDATE {0} SET ParentGUID = 0, Type = 0, Flag = 0, Data = 0, LuaEvent1 = '', LuaEvent2 = '', LuaEvent3 = '', LuaEvent4 = '', LuaEvent5 = '', LuaEvent6 = '', LuaEvent7 = '', LuaEvent8 = '', LuaEvent9 = '', LuaEvent10 = '' WHERE GUID = {1}", new String(DBName), __box(pObjDB->GameData.GUID));
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::CheckModifyAndCheckOut()
{
	bool Result = false;

	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		Result = pForm->PE_CheckModifyAndCheckOut();

		DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
		DB_GameObjDbStruct* pRootObjDB = static_cast<DB_GameObjDbStruct*>(m_pRootObjDB);

		pObjDB->IsModify = pRootObjDB->IsModify;
		pObjDB->IsLock = pRootObjDB->IsLock;
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
ReaderClass< DB_GameObjDbStruct >* PEComponet::get_ObjReader()
{
	return GameObjDbStructEx::ObjReader_PE();
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
char* PEComponet::get_DBName()
{
	char* Result = NULL;

	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		Result = pForm->DBName();
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEComponet::get_Account()
{
	String* Result = "";

	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		Result = pForm->Account();
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
int PEComponet::get_GUID()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	return pObjDB->GameData.GUID;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
int PEComponet::get_ParentGUID()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	return pObjDB->GameData.PE.ParentGUID;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEComponet::set_ParentGUID(int value)
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	pObjDB->GameData.PE.ParentGUID = value;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEComponet::get_UpdateDataToDisplay()
{
	bool Result = false;

	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		Result = pForm->UpdateDataToDisplay;
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEComponet::set_UpdateDataToDisplay(bool value)
{
	if (m_Form != NULL)
	{
		PEForm* pForm = static_cast<PEForm*>(m_Form);
		pForm->UpdateDataToDisplay = value;
	}
}

//**************************************************************************************
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEPhase::PEPhase(BaseForm* pPEForm, void* pRootObjDB)
: PEComponet(pPEForm, pRootObjDB)
{
	m_Type = EM_PE_COM_PHASE;

	m_OBIndex	= new Generic::Dictionary<int, PEObjective*>();
	m_SOBs		= new Generic::List<PEObjective*>();
	m_FOBs		= new Generic::List<PEObjective*>();

	m_MinGUID = PH_MIN_GUID;
	m_MaxGUID = PH_MAX_GUID;
	m_TabPageIndex1 = 0;
	m_TabPageIndex2 = 0;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEPhase::Release()
{
	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		PEObjective* ob = m_SOBs->get_Item(i);

		if (ob)
		{
			ob->Release();
		}
	}

	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		PEObjective* ob = m_FOBs->get_Item(i);

		if (ob)
		{
			ob->Release();
		}
	}

	PEComponet::Release();
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEPhase::ToString()
{
	String* Result = "";

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (pObjDB->GameData.GUID > 0)
	{
		Result = String::Format("{0} - {1}", m_tbpMain->Text, new String(pObjDB->GameData.Name));
	}
	else
	{
		Result = S"重置";
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEPhase::NewObjDB(int iParentGUID)
{
	PEComponet::NewObjDB(iParentGUID);

	//--------------------------------------------
	//設定初始值
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	sprintf(pObjDB->GameData.Name, "%s", "Noname");
	pObjDB->GameData.PE.Flag.PH.SLogic	= false;
	pObjDB->GameData.PE.Flag.PH.FLogic	= false;
	//--------------------------------------------

	//儲存
	SaveObjDB();

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEPhase::ReadObjDB(int iGUID)
{
	PEComponet::ReadObjDB(iGUID);

	//-------------------------------------------
	//clear
	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		PEObjective* ob = m_SOBs->get_Item(i);

		if (ob)
		{
			ob->Release();
		}
	}

	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		PEObjective* ob = m_FOBs->get_Item(i);

		if (ob)
		{
			ob->Release();
		}
	}

	m_SOBs->Clear();
	m_FOBs->Clear();
	m_OBIndex->Clear();
	//-------------------------------------------

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	int iGUID = pObjDB->GameData.GUID;

	//-------------------------------------------
	//read number of Objectives from DB
	SqlDataReader* DBReader = NULL;
	String* strDBName = new String(DBName);

	int iComType = EM_PE_COM_OBJECTIVE;
	m_SQL->CommandText = String::Format("SELECT GUID FROM {0} WHERE (Type = {1}) AND (ParentGUID = {2})", strDBName, __box(iComType), __box(iGUID));
	DBReader = m_SQL->ExecuteReader();

	Generic::List<int>* lstGUIDs = new Generic::List<int>();

	while(DBReader->Read())
	{
		lstGUIDs->Add(DBReader->GetInt32(0));
	}
	DBReader->Close();
	//-------------------------------------------

	//-------------------------------------------
	//load objectives
	for (int i = 0; i < lstGUIDs->Count; ++i)
	{
		LoadOB(lstGUIDs->get_Item(i));
	}
	//-------------------------------------------

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEPhase::SaveObjDB()
{
	PEComponet::SaveObjDB();

	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		PEObjective* ob = m_SOBs->get_Item(i);

		if (ob)
		{
			ob->SaveObjDB();
		}
	}

	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		PEObjective* ob = m_FOBs->get_Item(i);

		if (ob)
		{
			ob->SaveObjDB();
		}
	}

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEPhase::RemoveObjDB()
{
	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		PEObjective* ob = m_SOBs->get_Item(i);

		if (ob)
		{
			ob->RemoveObjDB();
		}
	}

	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		PEObjective* ob = m_FOBs->get_Item(i);

		if (ob)
		{
			ob->RemoveObjDB();
		}
	}

	PEComponet::RemoveObjDB();
	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEPhase::CreateUI(System::Windows::Forms::Control* Parent, System::String* Name)
{
	m_tbpMain		= (new System::Windows::Forms::TabPage());
	m_spc1			= (new System::Windows::Forms::SplitContainer());
	m_gbxBasic		= (new System::Windows::Forms::GroupBox());
	m_spc2			= (new System::Windows::Forms::SplitContainer());
	m_gbxSOBs		= (new System::Windows::Forms::GroupBox());
	m_pnlEditSOB	= (new System::Windows::Forms::Panel());
	m_btNewSOB		= (new System::Windows::Forms::Button());
	m_btRemoveSOB	= (new System::Windows::Forms::Button());
	m_clbSLogic		= (new System::Windows::Forms::CheckedListBox());
	m_tbcSOBs		= (new System::Windows::Forms::TabControl());
	m_gbxFOBs		= (new System::Windows::Forms::GroupBox());
	m_pnlEditFOB	= (new System::Windows::Forms::Panel());
	m_btNewFOB		= (new System::Windows::Forms::Button());
	m_btRemoveFOB	= (new System::Windows::Forms::Button());
	m_clbFLogic		= (new System::Windows::Forms::CheckedListBox());
	m_tbcFOBs		= (new System::Windows::Forms::TabControl());
	m_pnlName		= (new System::Windows::Forms::Panel());
	m_lblName		= (new System::Windows::Forms::Label());
	m_tbxName		= (new System::Windows::Forms::TextBox());
	m_gbxScore		= (new System::Windows::Forms::GroupBox());
	m_lblScore		= (new System::Windows::Forms::Label());
	m_tbxScore		= (new System::Windows::Forms::TextBox());
	m_lblBonusScore1= (new System::Windows::Forms::Label());
	m_tbxBonusScore1= (new System::Windows::Forms::TextBox());
	m_lblBonusScore2= (new System::Windows::Forms::Label());
	m_tbxBonusScore2= (new System::Windows::Forms::TextBox());
	m_gbxNextPhase	= (new System::Windows::Forms::GroupBox());
	m_tbxNPTimeGap	= (new System::Windows::Forms::TextBox());
	m_lblNPTimeGap	= (new System::Windows::Forms::Label());
	m_gbxNote		= (new System::Windows::Forms::GroupBox());
	m_tbxNote		= (new System::Windows::Forms::TextBox());
	m_gbxShortNote	= (new System::Windows::Forms::GroupBox());
	m_tbxShortNote	= (new System::Windows::Forms::TextBox());

	Parent->SuspendLayout();
	m_tbpMain->SuspendLayout();
	m_spc1->Panel1->SuspendLayout();
	m_spc1->Panel2->SuspendLayout();
	m_gbxBasic->SuspendLayout();
	m_pnlName->SuspendLayout();
	m_gbxScore->SuspendLayout();
	m_gbxNextPhase->SuspendLayout();
	m_gbxNote->SuspendLayout();
	m_gbxShortNote->SuspendLayout();	
	m_spc1->SuspendLayout();
	m_spc2->Panel1->SuspendLayout();
	m_spc2->Panel2->SuspendLayout();
	m_spc2->SuspendLayout();
	m_gbxSOBs->SuspendLayout();
	m_pnlEditSOB->SuspendLayout();
	m_tbcSOBs->SuspendLayout();
	m_gbxFOBs->SuspendLayout();
	m_pnlEditFOB->SuspendLayout();	
	m_tbcFOBs->SuspendLayout();

	// 
	// Parent
	// 
	Parent->Controls->Add(m_tbpMain);
	// 
	// m_tbpMain
	// 
	m_tbpMain->Controls->Add(m_spc1);
	m_tbpMain->Location = System::Drawing::Point(4, 22);
	m_tbpMain->Padding = System::Windows::Forms::Padding(3);
	m_tbpMain->Size = System::Drawing::Size(702, 694);
	m_tbpMain->Text = Name;
	m_tbpMain->UseVisualStyleBackColor = true;
	// 
	// m_spc1
	// 
	m_spc1->Dock = System::Windows::Forms::DockStyle::Fill;
	m_spc1->FixedPanel = System::Windows::Forms::FixedPanel::Panel1;
	m_spc1->Location = System::Drawing::Point(3, 3);
	// 
	// m_spc1.Panel1
	// 
	m_spc1->Panel1->Controls->Add(m_gbxBasic);
	// 
	// m_spc1.Panel2
	// 
	m_spc1->Panel2->Controls->Add(m_spc2);
	m_spc1->Size = System::Drawing::Size(696, 688);
	m_spc1->SplitterDistance = 233;
	// 
	// m_gbxBasic
	//
	m_gbxBasic->BackColor = System::Drawing::SystemColors::Control;
	m_gbxBasic->Controls->Add(m_gbxShortNote);
	m_gbxBasic->Controls->Add(m_gbxNote);
	m_gbxBasic->Controls->Add(m_gbxNextPhase);
	m_gbxBasic->Controls->Add(m_gbxScore);
	m_gbxBasic->Controls->Add(m_pnlName);
	m_gbxBasic->Dock = System::Windows::Forms::DockStyle::Fill;
	m_gbxBasic->Location = System::Drawing::Point(0, 0);
	m_gbxBasic->Size = System::Drawing::Size(233, 688);
	m_gbxBasic->TabStop = false;
	m_gbxBasic->Text = S"基本設定";
	// 
	// m_pnlName
	// 
	m_pnlName->AutoSize = true;
	m_pnlName->Controls->Add(m_lblName);
	m_pnlName->Controls->Add(m_tbxName);
	m_pnlName->Dock = System::Windows::Forms::DockStyle::Top;
	m_pnlName->Location = System::Drawing::Point(3, 18);
	m_pnlName->Size = System::Drawing::Size(227, 30);
	// 
	// m_lblName
	// 
	m_lblName->Location = System::Drawing::Point(3, 5);
	m_lblName->Size = System::Drawing::Size(44, 22);
	m_lblName->Text = S"名稱";
	m_lblName->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxName
	// 
	m_tbxName->Location = System::Drawing::Point(53, 5);
	m_tbxName->Size = System::Drawing::Size(170, 22);
	m_tbxName->TextChanged += new System::EventHandler(this, &PEPhase::tbxName_TextChanged);
	// 
	// m_gbxScore
	// 
	m_gbxScore->Controls->Add(m_tbxBonusScore2);
	m_gbxScore->Controls->Add(m_tbxBonusScore1);
	m_gbxScore->Controls->Add(m_tbxScore);
	m_gbxScore->Controls->Add(m_lblBonusScore2);
	m_gbxScore->Controls->Add(m_lblScore);
	m_gbxScore->Controls->Add(m_lblBonusScore1);
	m_gbxScore->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxScore->Location = System::Drawing::Point(3, 48);
	m_gbxScore->Size = System::Drawing::Size(227, 100);
	m_gbxScore->TabStop = false;
	m_gbxScore->Text = S"積分";
	// 
	// m_lblScore
	// 
	m_lblScore->Location = System::Drawing::Point(3, 14);
	m_lblScore->Size = System::Drawing::Size(80, 22);
	m_lblScore->Text = S"基本積分";
	m_lblScore->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxScore
	// 
	m_tbxScore->Location = System::Drawing::Point(88, 14);
	m_tbxScore->Size = System::Drawing::Size(133, 22);
	m_tbxScore->TextChanged += new System::EventHandler(this, &PEPhase::tbxScore_TextChanged);
	// 
	// m_lblBonusScore1
	// 
	m_lblBonusScore1->Location = System::Drawing::Point(3, 42);
	m_lblBonusScore1->Size = System::Drawing::Size(80, 22);
	m_lblBonusScore1->Text = S"組隊獎勵績分";
	m_lblBonusScore1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxBonusScore1
	// 
	m_tbxBonusScore1->Location = System::Drawing::Point(88, 42);
	m_tbxBonusScore1->Size = System::Drawing::Size(133, 22);
	m_tbxBonusScore1->TextChanged += new System::EventHandler(this, &PEPhase::tbxBonusScore1_TextChanged);
	// 
	// m_lblBonusScore2
	// 
	m_lblBonusScore2->Location = System::Drawing::Point(3, 70);
	m_lblBonusScore2->Size = System::Drawing::Size(80, 22);
	m_lblBonusScore2->Text = S"Raid獎勵績分";
	m_lblBonusScore2->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxBonusScore2
	//
	m_tbxBonusScore2->Location = System::Drawing::Point(88, 70);
	m_tbxBonusScore2->Size = System::Drawing::Size(133, 22);
	m_tbxBonusScore2->TextChanged += new System::EventHandler(this, &PEPhase::tbxBonusScore2_TextChanged);
	// 
	// m_gbxNextPhase
	// 
	m_gbxNextPhase->Controls->Add(m_lblNPTimeGap);
	m_gbxNextPhase->Controls->Add(m_tbxNPTimeGap);
	m_gbxNextPhase->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxNextPhase->Location = System::Drawing::Point(3, 148);
	m_gbxNextPhase->Size = System::Drawing::Size(227, 46);
	m_gbxNextPhase->TabStop = false;
	m_gbxNextPhase->Text = S"階段結束";
	// 
	// m_lblNPTimeGap
	// 
	m_lblNPTimeGap->Location = System::Drawing::Point(92, 18);
	m_lblNPTimeGap->Size = System::Drawing::Size(120, 22);
	m_lblNPTimeGap->Text = S"秒後開始下一階段";
	m_lblNPTimeGap->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxNPTimeGap
	// 
	m_tbxNPTimeGap->Location = System::Drawing::Point(6, 18);
	m_tbxNPTimeGap->Size = System::Drawing::Size(80, 22);
	m_tbxNPTimeGap->TextChanged += new System::EventHandler(this, &PEPhase::tbxNPTimeGap_TextChanged);
	// 
	// m_gbxNote
	// 
	m_gbxNote->Controls->Add(m_tbxNote);
	m_gbxNote->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxNote->Location = System::Drawing::Point(3, 194);
	m_gbxNote->Size = System::Drawing::Size(227, 100);
	m_gbxNote->TabStop = false;
	m_gbxNote->Text = S"說明文(遊戲)";
	// 
	// m_tbxNote
	// 
	m_tbxNote->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbxNote->Location = System::Drawing::Point(3, 18);
	m_tbxNote->Multiline = true;
	m_tbxNote->Size = System::Drawing::Size(221, 79);
	m_tbxNote->TextChanged += new System::EventHandler(this, &PEPhase::tbxNote_TextChanged);
	// 
	// m_gbxShortNote
	// 
	m_gbxShortNote->Controls->Add(m_tbxShortNote);
	m_gbxShortNote->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxShortNote->Location = System::Drawing::Point(3, 294);
	m_gbxShortNote->Size = System::Drawing::Size(227, 75);
	m_gbxShortNote->TabStop = false;
	m_gbxShortNote->Text = S"註解";
	// 
	// m_tbxShortNote
	// 
	m_tbxShortNote->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbxShortNote->Location = System::Drawing::Point(3, 18);
	m_tbxShortNote->Multiline = true;
	m_tbxShortNote->Size = System::Drawing::Size(221, 54);
	m_tbxShortNote->TextChanged += new System::EventHandler(this, &PEPhase::tbxShortNote_TextChanged);
	// 
	// m_spc2
	//
	m_spc2->Dock = System::Windows::Forms::DockStyle::Fill;
	m_spc2->Location = System::Drawing::Point(0, 0);
	m_spc2->Orientation = System::Windows::Forms::Orientation::Horizontal;
	// 
	// m_spc2.Panel1
	// 
	m_spc2->Panel1->Controls->Add(m_gbxSOBs);
	// 
	// m_spc2.Panel2
	// 
	m_spc2->Panel2->Controls->Add(m_gbxFOBs);
	m_spc2->Size = System::Drawing::Size(459, 688);
	m_spc2->SplitterDistance = 337;
	m_spc2->TabIndex = 0;
	// 
	// m_gbxSOBs
	// 
	m_gbxSOBs->BackColor = System::Drawing::SystemColors::Control;
	m_gbxSOBs->Controls->Add(m_tbcSOBs);
	m_gbxSOBs->Controls->Add(m_pnlEditSOB);
	m_gbxSOBs->Dock = System::Windows::Forms::DockStyle::Fill;
	m_gbxSOBs->Location = System::Drawing::Point(0, 0);
	m_gbxSOBs->Size = System::Drawing::Size(459, 337);
	m_gbxSOBs->TabStop = false;
	m_gbxSOBs->Text = S"成功條件";
	// 
	// m_pnlEditSOB
	// 
	m_pnlEditSOB->AutoSize = true;
	m_pnlEditSOB->Controls->Add(m_clbSLogic);
	m_pnlEditSOB->Controls->Add(m_btRemoveSOB);
	m_pnlEditSOB->Controls->Add(m_btNewSOB);
	m_pnlEditSOB->Dock = System::Windows::Forms::DockStyle::Top;
	m_pnlEditSOB->Location = System::Drawing::Point(3, 18);
	m_pnlEditSOB->Size = System::Drawing::Size(453, 46);
	// 
	// m_clbPH1SLogic
	// 
	m_clbSLogic->CheckOnClick = true;
	m_clbSLogic->FormattingEnabled = true;
	System::Object* __mcTemp__4[] = new System::Object*[2];
	__mcTemp__4[0] = S"AND";
	__mcTemp__4[1] = S"OR";
	m_clbSLogic->Items->AddRange(__mcTemp__4);
	m_clbSLogic->Location = System::Drawing::Point(369, 5);
	m_clbSLogic->MultiColumn = true;
	m_clbSLogic->Size = System::Drawing::Size(80, 38);
	m_clbSLogic->SelectedValueChanged += new System::EventHandler(this, &PEPhase::clbSLogic_SelectedValueChanged);
	// 
	// m_btRemoveSOB
	// 
	m_btRemoveSOB->Location = System::Drawing::Point(84, 5);
	m_btRemoveSOB->Size = System::Drawing::Size(75, 23);
	m_btRemoveSOB->Text = S"刪除";
	m_btRemoveSOB->UseVisualStyleBackColor = true;
	m_btRemoveSOB->Click += new System::EventHandler(this, &PEPhase::btRemoveSOB_Click);
	// 
	// m_btNewSOB
	// 
	m_btNewSOB->Location = System::Drawing::Point(3, 5);
	m_btNewSOB->Size = System::Drawing::Size(75, 23);
	m_btNewSOB->Text = S"新增";
	m_btNewSOB->UseVisualStyleBackColor = true;
	m_btNewSOB->Click += new System::EventHandler(this, &PEPhase::btNewSOB_Click);
	// 
	// m_tbcSOBs
	//
	m_tbcSOBs->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbcSOBs->Location = System::Drawing::Point(3, 64);
	m_tbcSOBs->SelectedIndex = 0;
	m_tbcSOBs->Size = System::Drawing::Size(453, 270);
	// 
	// m_gbxFOBs
	// 
	m_gbxFOBs->BackColor = System::Drawing::SystemColors::Control;
	m_gbxFOBs->Controls->Add(m_tbcFOBs);
	m_gbxFOBs->Controls->Add(m_pnlEditFOB);
	m_gbxFOBs->Dock = System::Windows::Forms::DockStyle::Fill;
	m_gbxFOBs->Location = System::Drawing::Point(0, 0);
	m_gbxFOBs->Size = System::Drawing::Size(459, 347);
	m_gbxFOBs->TabStop = false;
	m_gbxFOBs->Text = S"失敗條件";
	// 
	// m_pnlEditFOB
	// 
	m_pnlEditFOB->AutoSize = true;
	m_pnlEditFOB->Controls->Add(m_clbFLogic);
	m_pnlEditFOB->Controls->Add(m_btRemoveFOB);
	m_pnlEditFOB->Controls->Add(m_btNewFOB);
	m_pnlEditFOB->Dock = System::Windows::Forms::DockStyle::Top;
	m_pnlEditFOB->Location = System::Drawing::Point(3, 18);
	m_pnlEditFOB->Size = System::Drawing::Size(453, 44);
	// 
	// m_clbFLogic
	// 
	m_clbFLogic->CheckOnClick = true;
	m_clbFLogic->FormattingEnabled = true;
	System::Object* __mcTemp__5[] = new System::Object*[2];
	__mcTemp__5[0] = S"AND";
	__mcTemp__5[1] = S"OR";
	m_clbFLogic->Items->AddRange(__mcTemp__5);
	m_clbFLogic->Location = System::Drawing::Point(369, 3);
	m_clbFLogic->Size = System::Drawing::Size(80, 38);
	m_clbFLogic->SelectedValueChanged += new System::EventHandler(this, &PEPhase::clbFLogic_SelectedValueChanged);
	// 
	// m_btRemoveFOB
	// 
	m_btRemoveFOB->Location = System::Drawing::Point(85, 3);
	m_btRemoveFOB->Size = System::Drawing::Size(75, 23);
	m_btRemoveFOB->Text = S"刪除";
	m_btRemoveFOB->UseVisualStyleBackColor = true;
	m_btRemoveFOB->Click += new System::EventHandler(this, &PEPhase::btRemoveFOB_Click);
	// 
	// m_btNewFOB
	// 
	m_btNewFOB->Location = System::Drawing::Point(4, 3);
	m_btNewFOB->Size = System::Drawing::Size(75, 23);
	m_btNewFOB->Text = S"新增";
	m_btNewFOB->UseVisualStyleBackColor = true;
	m_btNewFOB->Click += new System::EventHandler(this, &PEPhase::btNewFOB_Click);
	// 
	// m_tbcFOBs
	// 
	m_tbcFOBs->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbcFOBs->Location = System::Drawing::Point(3, 62);
	m_tbcFOBs->SelectedIndex = 0;
	m_tbcFOBs->Size = System::Drawing::Size(453, 282);

	m_tbcFOBs->ResumeLayout(false);
	m_pnlEditFOB->ResumeLayout(false);
	m_pnlEditFOB->PerformLayout();
	m_gbxFOBs->ResumeLayout(false);
	m_gbxFOBs->PerformLayout();
	m_tbcSOBs->ResumeLayout(false);
	m_pnlEditSOB->ResumeLayout(false);
	m_pnlEditSOB->PerformLayout();
	m_gbxSOBs->ResumeLayout(false);
	m_gbxSOBs->PerformLayout();
	m_spc2->Panel1->ResumeLayout(false);
	m_spc2->Panel2->ResumeLayout(false);
	m_spc2->ResumeLayout(false);
	m_gbxShortNote->ResumeLayout(false);
	m_gbxShortNote->PerformLayout();
	m_gbxNote->ResumeLayout(false);
	m_gbxNote->PerformLayout();
	m_gbxNextPhase->ResumeLayout(false);
	m_gbxNextPhase->PerformLayout();
	m_gbxScore->ResumeLayout(false);
	m_gbxScore->PerformLayout();
	m_pnlName->ResumeLayout(false);
	m_pnlName->PerformLayout();
	m_gbxBasic->ResumeLayout(false);
	m_gbxBasic->PerformLayout();	
	m_spc1->Panel1->ResumeLayout(false);
	m_spc1->Panel2->ResumeLayout(false);
	m_spc1->ResumeLayout(false);
	m_tbpMain->ResumeLayout(false);
	m_tbpMain->PerformLayout();
	Parent->ResumeLayout(false);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEPhase::UpdateUI()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	PEForm* pForm = static_cast<PEForm*>(m_Form);

	//-----------------------------------------------------------
	//基本資料
	m_tbxName->Text		 = new String(pObjDB->GameData.Name);
	m_tbxNote->Text		 = new String(pObjDB->GameData.Note);
	m_tbxShortNote->Text = new String(pObjDB->GameData.ShortNote);
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新積分
	m_tbxScore->Text		= Convert::ToString(pObjDB->GameData.PE.Data.PH.Score);
	m_tbxBonusScore1->Text	= Convert::ToString(pObjDB->GameData.PE.Data.PH.BonusScore1);
	m_tbxBonusScore2->Text	= Convert::ToString(pObjDB->GameData.PE.Data.PH.BonusScore2);
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新重置時間間隔
	m_tbxNPTimeGap->Text = Convert::ToString(__box(pObjDB->GameData.PE.Data.PH.NPHTimeGap));
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新條件邏輯
	if (pObjDB->GameData.PE.Flag.PH.SLogic == false)
	{
		m_clbSLogic->SetItemChecked(0, true);
		m_clbSLogic->SetItemChecked(1, false);
	}
	else
	{
		m_clbSLogic->SetItemChecked(0, false);
		m_clbSLogic->SetItemChecked(1, true);
	}

	if (pObjDB->GameData.PE.Flag.PH.FLogic == false)
	{
		m_clbFLogic->SetItemChecked(0, true);
		m_clbFLogic->SetItemChecked(1, false);
	}
	else
	{
		m_clbFLogic->SetItemChecked(0, false);
		m_clbFLogic->SetItemChecked(1, true);
	}
	//-----------------------------------------------------------

	PEObjective* ob = NULL;
	//-----------------------------------------------------
	//更新所有的成功條件
	m_tbcSOBs->TabPages->Clear();
	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		ob = m_SOBs->get_Item(i);

		if (ob != NULL)
		{
			System::String* strName = String::Format("條件{0}", __box(i+1));
			ob->CreateUI(m_tbcSOBs, strName);
		}
	}

	for (int i = 0; i < m_SOBs->Count; ++i)
	{
		ob = m_SOBs->get_Item(i);

		if (ob != NULL)
		{
			ob->UpdateUI();
		}
	}
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新所有的失敗條件
	m_tbcFOBs->TabPages->Clear();
	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		ob = m_FOBs->get_Item(i);

		if (ob != NULL)
		{
			System::String* strName = String::Format("條件{0}", __box(i+1));
			ob->CreateUI(m_tbcFOBs, strName);
		}
	}

	for (int i = 0; i < m_FOBs->Count; ++i)
	{
		ob = m_FOBs->get_Item(i);

		if (ob != NULL)
		{
			ob->UpdateUI();
		}
	}
	//-----------------------------------------------------	

	pObjDB->GameData.PE.Data.PH.PHIndex = m_tbpMain->TabIndex;

	m_tbcSOBs->SelectedIndex = m_TabPageIndex1;
	m_tbcFOBs->SelectedIndex = m_TabPageIndex2;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEObjective* PEPhase::NewOB(int iOBCamp)
{
	PEObjective* Result = new PEObjective(m_Form, m_pRootObjDB);
	Result->NewObjDB(GUID);
	Result->OBCamp = iOBCamp;

	switch (Result->OBCamp)
	{
	case 0:
		{
			m_SOBs->Add(Result);
		}
		break;
	case 1:
		{
			m_FOBs->Add(Result);
		}
		break;
	}

	m_OBIndex->Add(Result->GUID, Result);

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEObjective* PEPhase::LoadOB(int iGUID)
{
	PEObjective* Result = NULL;

	if (m_OBIndex->ContainsKey(iGUID))
	{
		Result = m_OBIndex->get_Item(iGUID);		
	}
	else
	{
		Result = new PEObjective(m_Form, m_pRootObjDB);
		Result->ReadObjDB(iGUID);

		switch (Result->OBCamp)
		{
		case 0:
			{
				m_SOBs->Add(Result);
			}
			break;
		case 1:
			{
				m_FOBs->Add(Result);
			}
			break;
		}

		m_OBIndex->Add(Result->GUID, Result);
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEPhase::RemoveOB(int iGUID)
{	
	if (m_OBIndex->ContainsKey(iGUID))
	{
		PEObjective* ob = m_OBIndex->get_Item(iGUID);
		switch (ob->OBCamp)
		{
		case 0:
			{
				m_SOBs->Remove(ob);
			}
			break;
		case 1:
			{
				m_FOBs->Remove(ob);
			}
			break;
		}
		ob->RemoveObjDB();
		ob->Release();
		m_OBIndex->Remove(iGUID);
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::btNewSOB_Click(System::Object* sender, System::EventArgs* e)
{
	NewOB(0);
	m_TabPageIndex1 = m_SOBs->Count - 1;

	PEForm* pForm = static_cast<PEForm*>(m_Form);
	pForm->SaveTabPageIndex();
	UpdateDataToDisplay = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::btRemoveSOB_Click(System::Object* sender, System::EventArgs* e)
{
	if( MessageBox::Show("確定要刪除此條件?", "警告", MessageBoxButtons::YesNo ) != DialogResult::Yes )
		return;

	if (m_tbcSOBs->SelectedIndex >= 0)
	{
		TabPage* tp = m_tbcSOBs->SelectedTab;

		for (int i = 0; i < m_SOBs->Count; ++i)
		{
			PEObjective* ob = m_SOBs->get_Item(i);
			if (ob != NULL)
			{
				if (ob->TabPageControl == tp)
				{
					RemoveOB(ob->GUID);
					break;
				}
			}
		}

		m_tbcSOBs->TabPages->Remove(tp);

		m_TabPageIndex1 = m_SOBs->Count - 1;

		PEForm* pForm = static_cast<PEForm*>(m_Form);
		pForm->SaveTabPageIndex();

		UpdateDataToDisplay = true;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::btNewFOB_Click(System::Object* sender, System::EventArgs* e)
{
	NewOB(1);
	m_TabPageIndex2 = m_FOBs->Count - 1;

	PEForm* pForm = static_cast<PEForm*>(m_Form);
	pForm->SaveTabPageIndex();

	UpdateDataToDisplay = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::btRemoveFOB_Click(System::Object* sender, System::EventArgs* e)
{
	if( MessageBox::Show("確定要刪除此條件?", "警告", MessageBoxButtons::YesNo ) != DialogResult::Yes )
		return;

	if (m_tbcFOBs->SelectedIndex >= 0)
	{
		TabPage* tp = m_tbcFOBs->SelectedTab;
		for (int i = 0; i < m_FOBs->Count; ++i)
		{
			PEObjective* ob = m_FOBs->get_Item(i);
			if (ob != NULL)
			{
				if (ob->TabPageControl == tp)
				{
					RemoveOB(ob->GUID);
					break;
				}
			}
		}
		m_tbcFOBs->TabPages->Remove(tp);
		m_TabPageIndex2 = m_FOBs->Count - 1;

		PEForm* pForm = static_cast<PEForm*>(m_Form);
		pForm->SaveTabPageIndex();

		UpdateDataToDisplay = true;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxName_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.Name, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxScore_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iValue = 0;

	try
	{
		iValue = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.PH.Score = iValue;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxBonusScore1_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iValue = 0;

	try
	{
		iValue = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.PH.BonusScore1 = iValue;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxBonusScore2_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iValue = 0;

	try
	{
		iValue = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.PH.BonusScore2 = iValue;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxNPTimeGap_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iValue = 0;

	try
	{
		iValue = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.PH.NPHTimeGap = iValue;
}


//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxNote_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.Note, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::tbxShortNote_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.ShortNote, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::clbSLogic_SelectedValueChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	CheckedListBox* clb = static_cast<CheckedListBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (clb->SelectedIndex >= 0)
	{
		switch (clb->SelectedIndex)
		{
		case 0:
			{
				//set as AND
				pObjDB->GameData.PE.Flag.PH.SLogic = false;

				if (clb->GetItemChecked(0))
				{
					clb->SetItemChecked(1, false);
				}
				else
				{
					clb->SetItemChecked(1, true);
				}
			}
			break;
		case 1:
			{
				//set as OR
				pObjDB->GameData.PE.Flag.PH.SLogic = true;

				if (clb->GetItemChecked(1))
				{
					clb->SetItemChecked(0, false);
				}
				else
				{
					clb->SetItemChecked(0, true);
				}
			}
			break;
		}
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEPhase::clbFLogic_SelectedValueChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	CheckedListBox* clb = static_cast<CheckedListBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (clb->SelectedIndex >= 0)
	{
		switch (clb->SelectedIndex)
		{
		case 0:
			{
				//set as AND
				pObjDB->GameData.PE.Flag.PH.FLogic = false;

				if (clb->GetItemChecked(0))
				{
					clb->SetItemChecked(1, false);
				}
				else
				{
					clb->SetItemChecked(1, true);
				}
			}
			break;
		case 1:
			{
				//set as OR
				pObjDB->GameData.PE.Flag.PH.FLogic = true;

				if (clb->GetItemChecked(1))
				{
					clb->SetItemChecked(0, false);
				}
				else
				{
					clb->SetItemChecked(0, true);
				}
			}
			break;

		}
	}
}

//**************************************************************************************
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEObjective::PEObjective(BaseForm* pPEForm, void* pRootObjDB)
: PEComponet(pPEForm, pRootObjDB)
{
	m_Type = EM_PE_COM_OBJECTIVE;
	m_MinGUID = OB_MIN_GUID;
	m_MaxGUID = OB_MAX_GUID;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEObjective::NewObjDB(int iParentGUID)
{
	PEComponet::NewObjDB(iParentGUID);	

	//--------------------------------------------
	//設定初始值
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	sprintf(pObjDB->GameData.Name, "%s", "Noname");
	pObjDB->GameData.PE.Flag.OB.Visible = true;
	pObjDB->GameData.PE.Flag.OB.Minor	= false;
	pObjDB->GameData.PE.Data.OB.OBType  = 1;
	//--------------------------------------------

	//儲存
	SaveObjDB();

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEObjective::CreateUI(System::Windows::Forms::Control* Parent, System::String* Name)
{
	m_tbpMain			= (new System::Windows::Forms::TabPage());
	m_lblName			= (new System::Windows::Forms::Label());
	m_tbxName			= (new System::Windows::Forms::TextBox());
	m_gbxObjective		= (new System::Windows::Forms::GroupBox());
	m_cbxVarName		= (new System::Windows::Forms::ComboBox());
	m_cbxType			= (new System::Windows::Forms::ComboBox());
	m_tbxThreshold		= (new System::Windows::Forms::TextBox());
	m_lblInitValue		= (new System::Windows::Forms::Label());
	m_tbxInitValue		= (new System::Windows::Forms::TextBox());
	m_clbFlag			= (new System::Windows::Forms::CheckedListBox());
	m_lblNextPhase		= (new System::Windows::Forms::Label());
	m_cbxNextPhase		= (new System::Windows::Forms::ComboBox());
	m_gbxNote			= (new System::Windows::Forms::GroupBox());
	m_tbxNote			= (new System::Windows::Forms::TextBox());
	m_gbxShortNote		= (new System::Windows::Forms::GroupBox());
	m_tbxShortNote		= (new System::Windows::Forms::TextBox());

	Parent->SuspendLayout();
	m_tbpMain->SuspendLayout();
	m_gbxObjective->SuspendLayout();
	m_gbxNote->SuspendLayout();
	m_gbxShortNote->SuspendLayout();

	// 
	// Parent
	// 
	Parent->Controls->Add(m_tbpMain);
	// 
	// m_tbpMain
	//
	m_tbpMain->BackColor = System::Drawing::SystemColors::Control;
	m_tbpMain->Controls->Add(m_gbxShortNote);
	m_tbpMain->Controls->Add(m_gbxNote);
	m_tbpMain->Controls->Add(m_gbxObjective);
	m_tbpMain->Location = System::Drawing::Point(4, 22);
	m_tbpMain->Padding = System::Windows::Forms::Padding(3);
	m_tbpMain->Size = System::Drawing::Size(445, 244);
	m_tbpMain->Text = Name;
	// 
	// m_gbxObjective
	// 
	m_gbxObjective->Controls->Add(m_clbFlag);
	m_gbxObjective->Controls->Add(m_tbxName);
	m_gbxObjective->Controls->Add(m_lblName);
	m_gbxObjective->Controls->Add(m_lblNextPhase);
	m_gbxObjective->Controls->Add(m_cbxNextPhase);
	m_gbxObjective->Controls->Add(m_tbxInitValue);
	m_gbxObjective->Controls->Add(m_lblInitValue);
	m_gbxObjective->Controls->Add(m_tbxThreshold);
	m_gbxObjective->Controls->Add(m_cbxType);
	m_gbxObjective->Controls->Add(m_cbxVarName);
	m_gbxObjective->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxObjective->Location = System::Drawing::Point(3, 3);
	m_gbxObjective->Name = S"m_gbxSOB1Setting";
	m_gbxObjective->Size = System::Drawing::Size(439, 96);
	m_gbxObjective->TabIndex = 54;
	m_gbxObjective->TabStop = false;
	m_gbxObjective->Text = S"設定";
	// 
	// m_clbFlag
	// 
	m_clbFlag->CheckOnClick = true;
	m_clbFlag->FormattingEnabled = true;
	System::Object* __mcTemp__3[] = new System::Object*[2];
	__mcTemp__3[0] = S"顯示";
	__mcTemp__3[1] = S"次要條件";
	m_clbFlag->Items->AddRange(__mcTemp__3);
	m_clbFlag->Location = System::Drawing::Point(352, 12);
	m_clbFlag->Size = System::Drawing::Size(81, 38);
	m_clbFlag->SelectedValueChanged += new System::EventHandler(this, &PEObjective::clbFlag_SelectedValueChanged);
	// 
	// m_lblName
	// 
	m_lblName->Location = System::Drawing::Point(6, 12);
	m_lblName->Size = System::Drawing::Size(70, 22);
	m_lblName->Text = S"名稱";
	m_lblName->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxName
	// 
	m_tbxName->Location = System::Drawing::Point(82, 12);
	m_tbxName->Size = System::Drawing::Size(182, 22);
	m_tbxName->TextChanged += new System::EventHandler(this, &PEObjective::tbxName_TextChanged);
	// 
	// m_lblNextPhase
	// 
	m_lblNextPhase->Location = System::Drawing::Point(6, 38);
	m_lblNextPhase->Size = System::Drawing::Size(70, 22);
	m_lblNextPhase->Text = S"達成後跳到";
	m_lblNextPhase->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_cbxNextPhase
	//
	m_cbxNextPhase->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
	m_cbxNextPhase->FormattingEnabled = true;
	m_cbxNextPhase->Location = System::Drawing::Point(82, 38);
	m_cbxNextPhase->Size = System::Drawing::Size(182, 20);
	m_cbxNextPhase->SelectedIndexChanged += new System::EventHandler(this, &PEObjective::cbxNextPhase_SelectedIndexChanged);
	// 
	// m_cbxVarName
	// 
	m_cbxVarName->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
	m_cbxVarName->FormattingEnabled = true;
	m_cbxVarName->Location = System::Drawing::Point(8, 64);
	m_cbxVarName->Size = System::Drawing::Size(135, 20);
	m_cbxVarName->SelectedIndexChanged += new System::EventHandler(this, &PEObjective::cbxVarName_SelectedIndexChanged);
	// 
	// m_cbxType
	// 
	m_cbxType->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
	m_cbxType->FormattingEnabled = true;
	System::Object* __mcTemp__2[] = new System::Object*[7];
	__mcTemp__2[0] = S">";
	__mcTemp__2[1] = S"<";
	__mcTemp__2[2] = S"=";
	__mcTemp__2[3] = S"!=";
	__mcTemp__2[4] = S">=";
	__mcTemp__2[5] = S"<=";
	__mcTemp__2[6] = S"時間限制";
	m_cbxType->Items->AddRange(__mcTemp__2);
	m_cbxType->Location = System::Drawing::Point(149, 64);
	m_cbxType->Size = System::Drawing::Size(80, 20);
	m_cbxType->SelectedIndexChanged += new System::EventHandler(this, &PEObjective::cbxType_SelectedIndexChanged);
	// 
	// m_tbxThreshold
	// 
	m_tbxThreshold->Location = System::Drawing::Point(235, 64);
	m_tbxThreshold->Size = System::Drawing::Size(60, 22);
	m_tbxThreshold->TextChanged += new System::EventHandler(this, &PEObjective::tbxThreshold_TextChanged);
	// 
	// m_lblInitValue
	// 
	m_lblInitValue->Location = System::Drawing::Point(301, 64);
	m_lblInitValue->Size = System::Drawing::Size(50, 23);
	m_lblInitValue->Text = S"初始值";
	m_lblInitValue->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
	// 
	// m_tbxInitValue
	// 
	m_tbxInitValue->Location = System::Drawing::Point(357, 64);
	m_tbxInitValue->Size = System::Drawing::Size(60, 22);
	m_cbxType->TextChanged += new System::EventHandler(this, &PEObjective::tbxInitValue_TextChanged);
	// 
	// m_gbxNote
	// 
	m_gbxNote->Controls->Add(m_tbxNote);
	m_gbxNote->Dock = System::Windows::Forms::DockStyle::Top;
	m_gbxNote->Location = System::Drawing::Point(3, 99);
	m_gbxNote->Size = System::Drawing::Size(439, 84);
	m_gbxNote->TabStop = false;
	m_gbxNote->Text = S"說明文(遊戲)";
	// 
	// m_tbxNote
	// 
	m_tbxNote->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbxNote->Location = System::Drawing::Point(3, 18);
	m_tbxNote->Multiline = true;
	m_tbxNote->Size = System::Drawing::Size(433, 63);
	m_tbxNote->TextChanged += new System::EventHandler(this, &PEObjective::tbxNote_TextChanged);
	// 
	// m_gbxShortNote
	// 
	m_gbxShortNote->Controls->Add(m_tbxShortNote);
	m_gbxShortNote->Dock = System::Windows::Forms::DockStyle::Fill;
	m_gbxShortNote->Location = System::Drawing::Point(3, 183);
	m_gbxShortNote->Size = System::Drawing::Size(439, 58);
	m_gbxShortNote->TabStop = false;
	m_gbxShortNote->Text = S"註解";
	// 
	// m_tbxShortNote
	// 
	m_tbxShortNote->Dock = System::Windows::Forms::DockStyle::Fill;
	m_tbxShortNote->Location = System::Drawing::Point(3, 18);
	m_tbxShortNote->Multiline = true;
	m_tbxShortNote->Size = System::Drawing::Size(433, 37);
	m_tbxShortNote->TextChanged += new System::EventHandler(this, &PEObjective::tbxShortNote_TextChanged);

	m_gbxShortNote->ResumeLayout(false);
	m_gbxShortNote->PerformLayout();
	m_gbxNote->ResumeLayout(false);
	m_gbxNote->PerformLayout();
	m_gbxObjective->ResumeLayout(false);
	m_gbxObjective->PerformLayout();
	m_tbpMain->ResumeLayout(false);
	m_tbpMain->PerformLayout();
	Parent->ResumeLayout(false);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEObjective::UpdateUI()
{
	PEForm* pForm = static_cast<PEForm*>(m_Form);
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	//-----------------------------------------------------------
	//基本資料
	m_tbxName->Text		 = new String(pObjDB->GameData.Name);
	m_tbxNote->Text		 = new String(pObjDB->GameData.Note);
	m_tbxShortNote->Text = new String(pObjDB->GameData.ShortNote);
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新下一階段
	m_cbxNextPhase->Items->Clear();

	PEPhase* resetPH = new PEPhase(m_Form, pObjDB);
	m_cbxNextPhase->Items->Add(resetPH);

	for (int i = 0; i < pForm->Phases->Count; ++i)
	{
		m_cbxNextPhase->Items->Add(pForm->Phases->get_Item(i));
	}

	for (int i = 0; i < m_cbxNextPhase->Items->Count; ++i)
	{
		PEPhase* ph = static_cast<PEPhase*>(m_cbxNextPhase->Items->get_Item(i));

		if (ph->GUID == pObjDB->GameData.PE.Data.OB.NPHGUID)
		{
			m_cbxNextPhase->SelectedIndex = i;
			break;
		}
	}
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新條件變數
	m_cbxVarName->Items->Clear();

	PEVar* emptyVar = new PEVar(m_Form, pObjDB);
	m_cbxVarName->Items->Add(emptyVar);

	for (int i = 0; i < pForm->Vars->Count; ++i)
	{
		m_cbxVarName->Items->Add(pForm->Vars->get_Item(i));
	}

	for (int i = 0; i < m_cbxVarName->Items->Count; ++i)
	{
		PEVar* var = static_cast<PEVar*>(m_cbxVarName->Items->get_Item(i));

		String* strData = new String(pObjDB->GameData.PE.Data.OB.VarName);

		if (String::Equals(var->VarName->ToLower(), strData->ToLower()))
		{
			m_cbxVarName->SelectedIndex = i;
			break;
		}
	}
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新條件類型
	if (pObjDB->GameData.PE.Data.OB.OBType == 0)
	{
		m_cbxType->SelectedIndex = 0;
	}
	else
	{
		m_cbxType->SelectedIndex = (pObjDB->GameData.PE.Data.OB.OBType) - 1;
	}	
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新門檻值
	m_tbxThreshold->Text = Convert::ToString(pObjDB->GameData.PE.Data.OB.Threshold);
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新初始值
	m_tbxInitValue->Text = Convert::ToString(pObjDB->GameData.PE.Data.OB.InitValue);
	//-----------------------------------------------------------

	//-----------------------------------------------------------
	//更新旗標
	m_clbFlag->SetItemChecked(0, pObjDB->GameData.PE.Flag.OB.Visible);
	m_clbFlag->SetItemChecked(1, pObjDB->GameData.PE.Flag.OB.Minor);
	//-----------------------------------------------------------

	pObjDB->GameData.PE.Data.OB.OBIndex = m_tbpMain->TabIndex;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::tbxName_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.Name, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::clbFlag_SelectedValueChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	CheckedListBox* tbx = static_cast<CheckedListBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (tbx->SelectedIndex >= 0)
	{
		switch (tbx->SelectedIndex)
		{
		case 0:
			{
				//visible flag
				pObjDB->GameData.PE.Flag.OB.Visible = tbx->GetItemChecked(0);
			}
			break;
		case 1:
			{
				//minor flag
				pObjDB->GameData.PE.Flag.OB.Minor = tbx->GetItemChecked(1);
			}
			break;

		}
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::cbxVarName_SelectedIndexChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (m_cbxVarName->SelectedIndex >= 0)
	{
		std::string szData = DotNetStr::StringToChar(m_cbxVarName->SelectedItem->ToString());
		safe_strcopy(pObjDB->GameData.PE.Data.OB.VarName, szData.c_str());
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::cbxType_SelectedIndexChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	pObjDB->GameData.PE.Data.OB.OBType = (m_cbxType->SelectedIndex) + 1;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::tbxThreshold_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iThreshold = 0;

	try
	{
		iThreshold = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.OB.Threshold = iThreshold;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::tbxInitValue_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	int iInitValue = 0;

	try
	{
		iInitValue = Convert::ToInt32(tbx->Text);
	}
	catch (...)
	{
	}

	pObjDB->GameData.PE.Data.OB.InitValue = iInitValue;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::cbxNextPhase_SelectedIndexChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	if (m_cbxNextPhase->SelectedIndex >= 0)
	{
		PEPhase* ph = static_cast<PEPhase*>(m_cbxNextPhase->SelectedItem);

		if (ph != NULL)
		{
			pObjDB->GameData.PE.Data.OB.NPHGUID = ph->GUID;
		}
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::tbxNote_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.Note, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEObjective::tbxShortNote_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	strcpy(pObjDB->GameData.ShortNote, szData.c_str());
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
int PEObjective::get_OBCamp()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	return pObjDB->GameData.PE.Data.OB.OBCamp;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEObjective::set_OBCamp(int value)
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	pObjDB->GameData.PE.Data.OB.OBCamp = value;
}

//**************************************************************************************
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEVar::PEVar(BaseForm* pPEForm, void* pRootObjDB)
: PEComponet(pPEForm, pRootObjDB)
{
	m_Type = EM_PE_COM_VAR;
	m_MinGUID = VAR_MIN_GUID;
	m_MaxGUID = VAR_MAX_GUID;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEVar::ToString()
{
	return VarName;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEVar::NewObjDB(int iParentGUID)
{
	PEComponet::NewObjDB(iParentGUID);

	//--------------------------------------------
	//設定初始值
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	sprintf(pObjDB->GameData.PE.Data.VAR.VarName, "PE_VAR_%d", pObjDB->GameData.GUID);
	//--------------------------------------------

	//儲存
	SaveObjDB();

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEVar::SaveObjDB()
{
	SqlDataReader* DBReader = NULL;

	ArrayList* args = new ArrayList();

	DB_GameObjDbStruct __pin * pObjDB = &m_ObjDB;
	DB_GameObjDbStruct* pRootObjDB = static_cast<DB_GameObjDbStruct*>(m_pRootObjDB);
	int iGUID = pObjDB->GameData.GUID;

	char Buf[0x20000];
	//-----------------------------------------------------------------------------
	pObjDB->ZoneID				= 0;
	pObjDB->TagID				= 0;
	pObjDB->VersionID			= 0;
	pObjDB->Translate			= 0;
	pObjDB->ProcRate.Rate		= 0;
	pObjDB->GameData.ImageID	= 0;
	pObjDB->GameData.Language1	= true;
	pObjDB->GameData.Language2	= true;
	pObjDB->GameData.Language3	= true;
	pObjDB->GameData.Language4	= true;
	pObjDB->GameData.Language5	= true;
	pObjDB->GameData.Language6	= true;
	pObjDB->GameData.Language7	= true;
	pObjDB->GameData.Language8	= true;
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//設定最後修正日期以及修改者
	DateTime dtNow = DateTime::Now;

	args->Add(dtNow.ToString("d"));
	args->Add(__box(dtNow.Hour));
	args->Add(__box(dtNow.Minute));
	args->Add(__box(dtNow.Second));

	String* strNow = String::Format( "{0} {1}:{2}:{3}", args->ToArray());

	args->Clear();

	pObjDB->IsLock   = false;
	pObjDB->IsModify = false;	
	strncpy( (char*)&pObjDB->LastModifyAccount[0] , DotNetStr::StringToChar(Account).c_str(), sizeof(pObjDB->LastModifyAccount));
	pObjDB->LastModifyAccount[sizeof(pObjDB->LastModifyAccount) - 1] = 0;
	strncpy( (char*)&pObjDB->LastModifyDate[0] , DotNetStr::StringToChar(strNow).c_str(), sizeof(pObjDB->LastModifyDate));
	pObjDB->LastModifyDate[sizeof(pObjDB->LastModifyDate) - 1] = 0;
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新主要資料
	sprintf( Buf , " Where GUID = %d" , iGUID );
	CreateDBCmdClass<DB_GameObjDbStruct> CreateCMD(ObjReader, DBName);
	std::string szUpdateStr = CreateCMD.GetUpDateStr(pObjDB , Buf );
	m_SQL->CommandText = new String(szUpdateStr.c_str());
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//解除資料鎖定
	m_SQL->CommandText = String::Format( "UpDate {0} Set IsLock = 0 Where GUID = {1}" , new String(DBName) , __box(iGUID));
	DBReader = m_SQL->ExecuteReader( );
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新所有的自動產生的系統字串資料
	std::map<std::string,ReadInfoStruct>* DataFields	= ObjReader->ReadInfo();
	std::map<std::string,ReadInfoStruct>::iterator it;
	std::string szFieldName = "";
	std::string szKeyStr = "";

	ReadInfoStruct* pField = NULL;
	int iBaseAddr = (int)(&m_ObjDB);
	int iOffset = 0;
	char* pData = NULL;

	for(it  = DataFields->begin() ; it != DataFields->end() ; it++  )
	{
		String* strFieldName = new String((it->first).c_str());
		pField = &(it->second);
		iOffset = pField->Point;

		switch(pField->Type)
		{
		case ENUM_Type_CharStringPoint:
		case ENUM_Type_TextDataPoint:
			{
				//"最後修改帳號", "鎖定帳號", "資料群組" 不處理
				if(     String::Equals( strFieldName->ToLower() , "lastmodifyaccount" ) 
					||  String::Equals( strFieldName->ToLower() , "lockaccount" )
					||  String::Equals( strFieldName->ToLower() , "datagroup" ) )
				{
					continue;
				}

				pData = *(char**)(iBaseAddr + iOffset);

				String* strSql = new String(StringToSqlStr( pData , pField->Size ).c_str());
				String* strKey = String::Format("Sys{0}_{1}", __box(iGUID), strFieldName);

				//檢查資料是否存在
				bool IsStrNotFind;
				m_SQL->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}'", strKey);
				DBReader = m_SQL->ExecuteReader();
				while( DBReader->Read( ) )			
				{
					if( DBReader->GetInt32( 0 ) == 0 )
						IsStrNotFind = true;
					else
						IsStrNotFind = false;		
				}
				DBReader->Close();


				if( IsStrNotFind == true )
				{
					args->Add(strKey);
					args->Add(strSql);
					args->Add(__box(iGUID));
					args->Add(Account);

					m_SQL->CommandText = String::Format("INSERT StringDB(KeyStr, Type, Content, OrgObjID, Content_Editor) VALUES('{0}', 1, '{1}', {2}, '{3}')", args->ToArray());
					DBReader = m_SQL->ExecuteReader();
					DBReader->Close();

					args->Clear();
				}
				else
				{
					if( strcmp( pData , "" ) == 0 || strcmp( pData, " " ) == 0 )
					{
						//清空字串資料
						m_SQL->CommandText = String::Format("UPDATE StringDB SET UpdateTime = getdate(), IsConfirmed1 = 0, IsConfirmed2 = 0, IsConfirmed3 = 0, IsConfirmed4 = 0, IsConfirmed5 = 0, IsConfirmed6 = 0, IsConfirmed7 = 0, IsConfirmed8 = 0, IsConfirmed9 = 0, IsConfirmed10 = 0, IsConfirmed11 = 0, IsConfirmed12 = 0, IsConfirmed13 = 0, IsConfirmed14 = 0, IsConfirmed15 = 0, IsUpdate = 1, IsTranslated1 = 0, IsTranslated2 = 0, IsTranslated3 = 0, IsTranslated4 = 0, IsTranslated5 = 0, IsTranslated6 = 0, IsTranslated7 = 0, IsTranslated8 = 0, IsTranslated9 = 0, IsTranslated10 = 0, IsTranslated11 = 0, IsTranslated12 = 0, IsTranslated13 = 0, IsTranslated14 = 0, IsTranslated15 = 0,  Content = '', Content_Language1 = '', Content_Language2 = '', Content_Language3 = '', Content_Language4 = '', Content_Language5 = '', Content_Language6 = '', Content_Language7 = '', Content_Language8 = '', Content_Language9 = '', Content_Language10 = '', Content_Language11 = '', Content_Language12 = '', Content_Language13 = '', Content_Language14 = '', Content_Language15 = '', Content_Editor = '{0}' WHERE KeyStr = '{1}'", Account, strKey);
						DBReader = m_SQL->ExecuteReader();
						DBReader->Close();
					}
					else
					{
						//檢查資料是否有更新
						bool IsStrChange = false;

						m_SQL->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}' and Content = '{1}'", strKey, strSql);
						DBReader  = m_SQL->ExecuteReader();   

						while( DBReader->Read( ) )
						{
							if( DBReader->GetInt32( 0 ) != 0 )
								IsStrChange = false;
							else
								IsStrChange = true;
						}
						DBReader->Close();

						if( IsStrChange  )
						{
							//更新資料
							m_SQL->CommandText = String::Format("UPDATE StringDB SET UpdateTime = getdate(), IsConfirmed1 = 0, IsConfirmed2 = 0, IsConfirmed3 = 0, IsConfirmed4 = 0, IsConfirmed5 = 0, IsConfirmed6 = 0, IsConfirmed7 = 0, IsConfirmed8 = 0, IsConfirmed9 = 0, IsConfirmed10 = 0, IsConfirmed11 = 0, IsConfirmed12 = 0, IsConfirmed13 = 0, IsConfirmed14 = 0, IsConfirmed15 = 0, IsUpdate = 1, IsTranslated1 = 0, IsTranslated2 = 0, IsTranslated3 = 0, IsTranslated4 = 0, IsTranslated5 = 0, IsTranslated6 = 0, IsTranslated7 = 0, IsTranslated8 = 0, IsTranslated9 = 0, IsTranslated10 = 0, IsTranslated11 = 0, IsTranslated12 = 0, IsTranslated13 = 0, IsTranslated14 = 0, IsTranslated15 = 0, Content = '{0}', Content_Editor = '{1}' WHERE KeyStr = '{2}'" , strSql, Account, strKey);
							DBReader = m_SQL->ExecuteReader();
							DBReader->Close();
						}
					}
				}
			}
			break;
		default:
			continue;
		}
	}
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//更新輸出語系
	m_SQL->CommandText = String::Format("UPDATE StringDB SET OutputLanguage = {0} WHERE OrgObjID = {1} " , __box(pObjDB->GameData.LanguageSet) , __box(iGUID));
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();
	//-----------------------------------------------------------------------------

	//-----------------------------------------------------------------------------
	//修改翻譯分類	
	args->Add(__box(pObjDB->ZoneID));
	args->Add(__box(pObjDB->TagID));
	args->Add(__box(pObjDB->VersionID));
	args->Add(__box((int)(pObjDB->Translate)));
	args->Add(__box(iGUID));

	m_SQL->CommandText = String::Format("UPDATE StringDB SET DirZoneID = {0} , DirTagID = {1} , DirVersionID = {2}, Translate = {3} WHERE OrgObjID = {4}", args->ToArray());	
	DBReader = m_SQL->ExecuteReader();
	DBReader->Close();

	args->Clear();
	//-----------------------------------------------------------------------------

	return true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEVar::get_VarName()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;

	return new String(pObjDB->GameData.PE.Data.VAR.VarName);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEVar::set_VarName(String* value)
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	std::string szData = DotNetStr::StringToChar(value);

	sprintf(pObjDB->GameData.PE.Data.VAR.VarName, "%s", szData.c_str());

	//make str end
	int iDataLen = sizeof(pObjDB->GameData.PE.Data.VAR.VarName);
	pObjDB->GameData.PE.Data.VAR.VarName[iDataLen - 1] = 0;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
String* PEVar::get_VarNote()
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	return new String(pObjDB->GameData.PE.Data.VAR.VarNote);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEVar::set_VarNote(String* value)
{
	DB_GameObjDbStruct __pin* pObjDB = &m_ObjDB;
	std::string szData = DotNetStr::StringToChar(value);

	sprintf(pObjDB->GameData.PE.Data.VAR.VarNote, "%s", szData.c_str());

	//make str end
	int iDataLen = sizeof(pObjDB->GameData.PE.Data.VAR.VarNote);
	pObjDB->GameData.PE.Data.VAR.VarNote[iDataLen - 1] = 0;
}

//**************************************************************************************
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::clbPEFlags_SelectedValueChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	CheckedListBox* tbx = static_cast<CheckedListBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	if (tbx->SelectedIndex >= 0)
	{
		switch (tbx->SelectedIndex)
		{
		case 0:
			{
				//visible flag
				pObjDB->GameData.PE.Flag.PE.UIVisible = tbx->GetItemChecked(0);
			}
			break;
		case 1:
			{
				//minor flag
				pObjDB->GameData.PE.Flag.PE.ScoreVisible = tbx->GetItemChecked(1);
			}
			break;
		}
	}

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEResetTimeGap_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	int iCoolDown = 0;

	try
	{
		iCoolDown = Convert::ToInt32(tbx->Text);
	}
	catch(...)
	{

	}

	pObjDB->GameData.PE.Data.PE.CoolDown = iCoolDown;

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::cbxPEZID_SelectedIndexChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	if (m_cbxPEZoneID->SelectedIndex >= 0)
	{
		PEZoneInfo* pInfo = static_cast<PEZoneInfo*>(m_cbxPEZoneID->SelectedItem);

		//設定ZoneID
		pObjDB->GameData.PE.Data.PE.ZoneID = pInfo->ID;

		//清除所有的子區域ID
		for (int i = 0; i < sizeof(pObjDB->GameData.PE.Data.PE.SubZoneID); ++i)
		{
			pObjDB->GameData.PE.Data.PE.SubZoneID[i] = 0;
		}

		//-----------------------------------------------------
		//更新所有的子區域列表

		LoadSubZoneInfo();

		for (int i = 0 ; i < m_cbxSZs->Count; ++i)
		{
			ComboBox* cbx = m_cbxSZs->get_Item(i);
			cbx->Items->Clear();

			cbx->Items->Add(new PESubZoneInfo(pInfo->ID, 0, ""));

			System::Collections::Generic::Dictionary<int, PESubZoneInfo*>::Enumerator enumSZInfo  = m_SubZoneInfo->GetEnumerator();
			while (enumSZInfo.MoveNext())
			{
				PESubZoneInfo* pSZInfo = enumSZInfo.Current.Value;
				cbx->Items->Add(pSZInfo);
			}

			cbx->SelectedIndex = 0;
		}
		//-----------------------------------------------------
	}

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::cbxPESZID_SelectedIndexChanged(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	System::Windows::Forms::ComboBox* cbx = static_cast<System::Windows::Forms::ComboBox*>(sender);

	if (cbx->SelectedIndex >= 0)
	{
		int iTag = Convert::ToInt32(cbx->Tag);

		PESubZoneInfo* pInfo = static_cast<PESubZoneInfo*>(cbx->SelectedItem);

		//設定ZoneID
		pObjDB->GameData.PE.Data.PE.SubZoneID[iTag] = pInfo->ID;
	}

	_OnValueChange = true;
}


//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnBegin_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnBegin, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnSucc_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnSuccess, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnFail_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnFail, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnPlayerEnter_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnPlayerEnter, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnPlayerLeave_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnPlayerLeave, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPHOnBegin_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnPHBegin, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPHOnSucc_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnPHSuccess, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPHOnFail_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnPHFail, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxOBOnArchieve_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnOBAchieve, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::tbxPEOnBalance_TextChanged(System::Object* sender, System::EventArgs* e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;

	TextBox* tbx = static_cast<TextBox*>(sender);

	DB_GameObjDbStruct __pin* pObjDB = &_ObjDB;

	std::string szData = DotNetStr::StringToChar(tbx->Text);
	safe_strcopy(pObjDB->GameData.PE.LuaEvent.PE.OnBalance, szData.c_str());

	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::btNewPEVar_Click(System::Object*  sender, System::EventArgs*  e)
{
	PEVar* var = NewVar();

	System::String* StrList[] = new System::String*[3];
	StrList[0] = Convert::ToString(__box(var->GUID));
	StrList[1] = var->VarName;
	StrList[2] = "";

	m_lvPEVar->Items->Add(new ListViewItem(StrList));

	_Update_DataToDisplay = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::btUpatePEVar_Click(System::Object* sender, System::EventArgs* e)
{
	ListViewItem* lvit = m_lvPEVar->FocusedItem;

	if (lvit != NULL)
	{
		int iGUID = Convert::ToInt32(lvit->SubItems->get_Item(0)->Text);

		if (m_VarIndex->ContainsKey(iGUID))
		{
			PEVar* var = m_VarIndex->get_Item(iGUID);

			if (var != NULL)
			{
				lvit->SubItems->get_Item(1)->Text = m_tbxPEVarName->Text;
				lvit->SubItems->get_Item(2)->Text = m_tbxPEVarNote->Text;					
				var->VarName = m_tbxPEVarName->Text;
				var->VarNote = m_tbxPEVarNote->Text;
				var->SaveObjDB();

				_Update_DataToDisplay = true;
			}
		}
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::btRemovePEVar_Click(System::Object* sender, System::EventArgs* e)
{
	ListViewItem* lvit = m_lvPEVar->FocusedItem;

	if (lvit != NULL)
	{
		if( MessageBox::Show("確定要刪除選定的PE變數?", "警告", MessageBoxButtons::YesNo ) != DialogResult::Yes)
			return;

		int iGUID = Convert::ToInt32(lvit->SubItems->get_Item(0)->Text);
		RemoveVar(iGUID);
		m_lvPEVar->Items->Remove(lvit);
		_Update_DataToDisplay = true;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::lvPEVar_SelectedIndexChanged(System::Object* sender, System::EventArgs* e)
{
	ListViewItem* lvit = m_lvPEVar->FocusedItem;

	if (lvit != NULL)
	{
		m_tbxPEVarName->Text = lvit->SubItems->get_Item(1)->Text;
		m_tbxPEVarNote->Text = lvit->SubItems->get_Item(2)->Text;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::btPENewPhase_Click(System::Object* sender, System::EventArgs* e)
{
	NewPhase();
	m_TabPageIndex = m_Phases->Count - 1;
	_Update_DataToDisplay = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::btPERemovePhase_Click(System::Object* sender, System::EventArgs* e)
{
	if( MessageBox::Show("確定要刪除此階段? 此階段所有的條件資料也將被一併刪除!!", "警告", MessageBoxButtons::YesNo ) != DialogResult::Yes )
		return;

	if (m_tbcPHs->SelectedIndex >= 0)
	{
		TabPage* tp = m_tbcPHs->SelectedTab;

		for (int i = 0; i < m_Phases->Count; ++i)
		{
			PEPhase* ph = m_Phases->get_Item(i);

			if (ph != NULL)
			{
				if (ph->TabPageControl == tp)
				{
					RemovePhase(ph->GUID);
					break;
				}
			}
		}
		
		m_tbcPHs->TabPages->Remove(tp);
		m_TabPageIndex = m_Phases->Count - 1;
		_Update_DataToDisplay = true;
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
System::Void PEForm::Treelist_AfterExpand(System::Object*  sender, DevExpress::XtraTreeList::NodeEventArgs*  e)
{
	treeList1->BeginUpdate();	
	treeList1->BeginUnboundLoad();	
	SqlDataReader* myReader;
	TreeListNode* TreeNodeMap[] = new TreeListNode* [30000];
	for( int i = 0 ; i < 30000 ; i++ )
		TreeNodeMap[i] = NULL;

	int ParentNodeID = *static_cast<__box int*>(e->Node->Tag);

	sqlCommand_Base->CommandText = String::Format( "SELECT NodeID , NodeName From ObjGroupTreeNodeDB WHERE UseDB = '{0}' AND ParentNodeID={1} ORDER BY NodeName" ,  (String*)_DBName , __box( ParentNodeID ) );
	myReader = sqlCommand_Base->ExecuteReader();
	while( myReader->Read())
	{

		int		NodeID			= myReader->GetInt32( 0 );
		String* NodeName		= myReader->GetString( 1 );
		Object* objArray __gc [] = {NodeName};


		TreeNodeMap[NodeID] =treeList1->AppendNode( objArray, e->Node->Id, 0,0,0);
		TreeNodeMap[NodeID]->set_Tag(__box(NodeID));
		TreeNodeMap[NodeID]->set_HasChildren(true);
	}
	myReader->Close();

	int Index = CB_SelectType->SelectedIndex;
	if( TB_WhereSQLCmd->Text->Length == 0 && Index != 0 )
		Index = 3;
	switch( Index )
	{
	case 0:
		{
			int LanguageSetting = Global::LanguageSetting();
			if( LanguageSetting == -1 )
			{
				sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.NodeID, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE (s.KeyStr LIKE 'Sys%[_]name') AND (n.OutputLanguage & 15 <> 0) AND (n.NodeID = {1}) AND (n.Type = 1) ORDER BY   n.GUID" , (String*)_DBName  ,static_cast<String*>(e->Node->Tag));
			}
			else
			{
				sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.NodeID, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE (s.KeyStr LIKE 'Sys%[_]name') AND (n.OutputLanguage & {1} != 0) AND (n.NodeID = {2}) AND (n.Type = 1) ORDER BY  n.GUID" , (String*)_DBName , __box( LanguageSetting ) ,static_cast<String*>(e->Node->Tag));
			}
		}
		break;
	case 1://使用名稱
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.NodeID, n.Type FROM {0} AS n INNER JOIN  StringDB AS s ON n.GUID = s.OrgObjID WHERE (RIGHT(s.KeyStr, 5) = '_name') AND (s.[Content] LIKE '%{1}%') AND (n.NodeID = {2}) AND (n.Type = 1) ORDER BY n.GUID", (String*)_DBName , TB_WhereSQLCmd->Text ,static_cast<String*>(e->Node->Tag));
		break;
	case 2://始用SQL
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.Content, n.NodeID, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID {1} AND NodeID = {2} AND (n.Type = 1)" , (String*)_DBName , TB_WhereSQLCmd->Text ,static_cast<String*>(e->Node->Tag));
		break;
	case 3://全部
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.Content, n.NodeID, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE RIGHT(keystr,5) = '_name' AND n.NodeID = {1} AND (n.Type = 1) ORDER BY n.GUID",(String*)_DBName,static_cast<String*>(e->Node->Tag));
		break;
	}		

	myReader = sqlCommand_Base->ExecuteReader();


	int		GUID;
	int		NodeID;
	String*	ObjName;
	//顯示子node 
	while( myReader->Read())
	{

		GUID	= myReader->GetInt32( 0 );
		ObjName = myReader->GetString( 1 );
		NodeID	= myReader->GetInt32( 2 );
		String*		Name = String::Format( "{0} {1}" , __box( GUID ) , ObjName );
		Object* objArray __gc [] = {Name};
		treeList1->AppendNode(objArray, e->Node);

	}
	myReader->Close();
	treeList1->EndUnboundLoad();
	treeList1->EndUpdate();
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::UpDateList()
{
	int     i;
	int     SelectID = 0;
	SqlDataReader* myReader;

	int Index = CB_SelectType->SelectedIndex;
	if( TB_WhereSQLCmd->Text->Length == 0 && Index != 0 )
		Index = 3;

	switch( Index )
	{
	case 0:
		{
			int LanguageSetting = Global::LanguageSetting();
			if( LanguageSetting == -1 )
			{
				sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.DataGroup, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE (s.KeyStr LIKE 'Sys%[_]name') AND (n.OutputLanguage & 15 <> 0) AND (n.TYPE = 1) ORDER BY   n.GUID" , (String*)_DBName  );
			}
			else
			{
				sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.DataGroup, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE (s.KeyStr LIKE 'Sys%[_]name') AND (n.OutputLanguage & {1} != 0) AND (n.TYPE = 1) ORDER BY  n.GUID" , (String*)_DBName , __box( LanguageSetting ) );
			}
		}
		break;
	case 1://使用名稱
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.[Content], n.DataGroup, n.Type FROM {0} AS n INNER JOIN  StringDB AS s ON n.GUID = s.OrgObjID WHERE (RIGHT(s.KeyStr, 5) = '_name') AND (s.[Content] LIKE '%{1}%') AND (n.TYPE = 1) ORDER BY n.GUID", (String*)_DBName , TB_WhereSQLCmd->Text);
		break;
	case 2://始用SQL
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.Content, n.DataGroup, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID {1} WHERE (n.TYPE = 1)" , (String*)_DBName , TB_WhereSQLCmd->Text );
		break;
	case 3:
	default://不使用
		sqlCommand_Base->CommandText = String::Format( "SELECT n.GUID, s.Content, n.DataGroup, n.Type FROM {0} AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE right(keystr,5) = '_name' AND (n.TYPE = 1) ORDER BY n.guid" , (String*)_DBName  );
		break;
	}
	myReader = sqlCommand_Base->ExecuteReader();

	_ObjList->clear();
	while( myReader->Read())
	{
		DB_GameObjDbIndexStruct Temp;
		Temp.GUID = myReader->GetInt32( 0 );
		String* Str =  myReader->GetString( 1 ) ;
		strcpy( Temp.Name , DotNetStr::StringToChar( Str ).c_str() );

		Str =  myReader->GetString( 2 ) ;
		strcpy( Temp.DataGroup , DotNetStr::StringToChar( Str ).c_str() );

		_ObjList->push_back( Temp );
	}
	myReader->Close();	
	//-------------------------------------------------------------------------------------
	//更新顯示資料
	//-------------------------------------------------------------------------------------
	LB_ObjList->BeginUpdate();

	while( (int)_ObjList->size() >  LB_ObjList->Items->Count )
	{
		LB_ObjList->Items->Add( S"" );
	}

	while( LB_ObjList->Items->Count > (int)_ObjList->size() )
	{
		LB_ObjList->Items->RemoveAt( _ObjList->size() );
	}


	//找到物件位置
	for ( i = 0 ; i < (int)_ObjList->size() ; i++ )
	{
		String* Str = String::Format("{0,5} {1}", __box( (*_ObjList)[i].GUID ) , (String*)( (*_ObjList)[i].Name ) );

		LB_ObjList->Items->Item[i] = Str;

		if( (*_ObjList)[i].GUID == _ObjGUID )
			SelectID = i;
	}
	if( _ObjList->size() != 0 )
	{
		LB_ObjList->SelectedIndex  = SelectID;
	}
	LB_ObjList->EndUpdate();
	//-------------------------------------------------------------------------------------
	//找 Treeview 的 Node					
	//-------------------------------------------------------------------------------------
	//找到的父Node的String以FILO方式儲存至ArrayList，使用Treelist的FindNodeByFieldValue找到Node並展開
	if (_ObjGUID != -1)
	{
		int	NodeID=_ObjGUID;
		sqlCommand_Base->CommandText = String::Format("SELECT n.GUID, s.[Content], n.NodeID, n.Type FROM {0} AS n INNER JOIN  StringDB AS s ON n.GUID = s.OrgObjID WHERE (RIGHT(s.KeyStr, 5) = '_name') AND (n.GUID = {1}) AND (n.Type = 1)",(String*)_DBName, __box(NodeID));
		myReader = sqlCommand_Base->ExecuteReader();
		if (myReader->Read())
		{
			NodeID = myReader->GetInt32( 2 );
		}		
		myReader->Close();
		//vector<Object*> NodeStack;
		ArrayList* NodeStack = new ArrayList;
		do 
		{
			sqlCommand_Base->CommandText = String::Format("SELECT ParentNodeID, NodeName, NodeID FROM ObjGroupTreeNodeDB WHERE (UseDB = '{0}') AND (NodeID = {1})",(String*)_DBName,  __box(NodeID));
			myReader = sqlCommand_Base->ExecuteReader();
			while (myReader->Read())
			{
				NodeStack->Insert(0,myReader->GetString( 1 ));
				NodeID = myReader->GetInt32( 0 );
			}			
			myReader->Close();
		}while (NodeID != -1);
		String* col = "ColName";
		System::Collections::IEnumerator* objMyEnum = NodeStack->GetEnumerator();
		while (objMyEnum->MoveNext())
		{
			TreeListNode* FindtreeNode = treeList1->FindNodeByFieldValue( col , objMyEnum->get_Current() );
			if( FindtreeNode != NULL )
			{
				FindtreeNode->set_Expanded(true);
			}
		}
		treeList1->SetFocusedNode(treeList1->FindNodeByFieldValue( col , LB_ObjList->Text ));
	}  

	LB_ObjCount->Text = String::Format( "筆數:{0}" , __box(LB_ObjList->Items->Count) );
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::UpDate_DataToDisplay()
{
	BaseForm::UpDate_DataToDisplay();

	_OnUpdate_DataToDisplay = true;

	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
	int iGUID	= pObjDB->GameData.GUID;
	int iZoneID = pObjDB->GameData.PE.Data.PE.ZoneID;

	//-----------------------------------------------------
	//從DB讀取Zone資訊
	LoadZoneInfo();
	//-----------------------------------------------------

	//-----------------------------------------------------
	//從DB讀取SubZone資訊
	LoadSubZoneInfo();
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新旗標
	m_clbPEFlags->SetItemChecked(0, pObjDB->GameData.PE.Flag.PE.UIVisible);
	m_clbPEFlags->SetItemChecked(1, pObjDB->GameData.PE.Flag.PE.ScoreVisible);
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新重置時間
	m_tbxPEResetTimeGap->Text = Convert::ToString(__box(pObjDB->GameData.PE.Data.PE.CoolDown));
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新 Zone ID 列表
	int iZIndex = -1;

	m_cbxPEZoneID->Items->Clear();
	System::Collections::Generic::Dictionary<int, PEZoneInfo*>::Enumerator enumZInfo  = m_ZoneInfo->GetEnumerator();
	while (enumZInfo.MoveNext())
	{
		PEZoneInfo* pZInfo = enumZInfo.Current.Value;

		m_cbxPEZoneID->Items->Add(pZInfo);

		if (pZInfo->ID == iZoneID)
		{
			iZIndex = m_cbxPEZoneID->Items->Count - 1;
		}
	}
	m_cbxPEZoneID->SelectedIndex = iZIndex;
	//-----------------------------------------------------
	
	//-----------------------------------------------------
	//更新所有的子區域列表
	for (int i = 0 ; i < m_cbxSZs->Count; ++i)
	{
		ComboBox* cbx = m_cbxSZs->get_Item(i);
		cbx->Items->Clear();

		cbx->Items->Add(new PESubZoneInfo(iZoneID, 0, ""));

		System::Collections::Generic::Dictionary<int, PESubZoneInfo*>::Enumerator enumSZInfo  = m_SubZoneInfo->GetEnumerator();
		while (enumSZInfo.MoveNext())
		{
			PESubZoneInfo* pSZInfo = enumSZInfo.Current.Value;
			cbx->Items->Add(enumSZInfo.Current.Value);
		}

		for (int j = 0; j < cbx->Items->Count; ++j)
		{
			PESubZoneInfo* pSZInfo = static_cast<PESubZoneInfo*>(cbx->Items->get_Item(j));
			if (pObjDB->GameData.PE.Data.PE.SubZoneID[i] == pSZInfo->ID)
			{
				cbx->SelectedIndex = j;
				break;
			}
		}		
	}
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新Lua函式
	m_tbxPEOnBegin->Text		= new String(pObjDB->GameData.PE.LuaEvent.PE.OnBegin);
	m_tbxPEOnSucc->Text			= new String(pObjDB->GameData.PE.LuaEvent.PE.OnSuccess);
	m_tbxPEOnFail->Text			= new String(pObjDB->GameData.PE.LuaEvent.PE.OnFail);
	m_tbxPEOnPlayerEnter->Text	= new String(pObjDB->GameData.PE.LuaEvent.PE.OnPlayerEnter);
	m_tbxPEOnPlayerLeave->Text	= new String(pObjDB->GameData.PE.LuaEvent.PE.OnPlayerLeave);
	m_tbxPHOnBegin->Text		= new String(pObjDB->GameData.PE.LuaEvent.PE.OnPHBegin);
	m_tbxPHOnSucc->Text			= new String(pObjDB->GameData.PE.LuaEvent.PE.OnPHSuccess);
	m_tbxPHOnFail->Text			= new String(pObjDB->GameData.PE.LuaEvent.PE.OnPHFail);
	m_tbxOBOnArchieve->Text		= new String(pObjDB->GameData.PE.LuaEvent.PE.OnOBAchieve);
	m_tbxPEOnBalance->Text		= new String(pObjDB->GameData.PE.LuaEvent.PE.OnBalance);
	//-----------------------------------------------------

	//-----------------------------------------------------
	//更新所有的階段
	m_tbcPHs->TabPages->Clear();
	for (int i = 0; i < m_Phases->Count; ++i)
	{
		PEPhase* ph = m_Phases->get_Item(i);

		if (ph != NULL)
		{
			System::String* strName = String::Format("階段{0}", __box(i+1));
			ph->CreateUI(m_tbcPHs, strName);
		}
	}

	for (int i = 0; i < m_Phases->Count; ++i)
	{
		PEPhase* ph = m_Phases->get_Item(i);

		if (ph != NULL)
		{
			ph->UpdateUI();
		}
	}
	//-----------------------------------------------------
	m_tbcPHs->SelectedIndex = m_TabPageIndex;

	_OnUpdate_DataToDisplay = false;
	_OnValueChange = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::UnLockAndSave()
{
	BaseForm::UnLockAndSave();

	//-----------------------------------------------------
	//更新所有的階段
	for (int i = 0; i < m_Phases->Count; ++i)
	{
		PEPhase* ph = m_Phases->get_Item(i);

		if (ph != NULL)
		{
			ph->SaveObjDB();
		}
	}
	//-----------------------------------------------------
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::NewObj()
{
	SqlDataReader* DBReader;

	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
	String* strDBName = new String(_DBName);

	for( int i = 0 ; i < NUD_CreateCount->Value ; i++ )
	{
		int	iGUID = PE_MIN_GUID;
		//---------------------------------------------------
		//get last GUID
		sqlCommand_Base->CommandText = String::Format("SELECT GUID FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2})", strDBName, __box(PE_MIN_GUID), __box(PE_MAX_GUID));
		DBReader = sqlCommand_Base->ExecuteReader();
		if(DBReader->Read())
		{
			DBReader->Close();

			sqlCommand_Base->CommandText = String::Format("SELECT GUID FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2}) AND (ParentGUID = 0) AND (Type = 0)", strDBName, __box(PE_MIN_GUID), __box(PE_MAX_GUID));
			DBReader = sqlCommand_Base->ExecuteReader();

			if (DBReader->Read())
			{
				iGUID = DBReader->GetInt32(0);
				DBReader->Close();
			}
			else
			{
				DBReader->Close();

				sqlCommand_Base->CommandText = String::Format("SELECT MAX(GUID) FROM {0} WHERE (GUID >= {1}) AND (GUID <= {2})", strDBName, __box(PE_MIN_GUID), __box(PE_MAX_GUID));
				DBReader = sqlCommand_Base->ExecuteReader();

				if(DBReader->Read())
				{
					iGUID = DBReader->GetInt32(0);
					iGUID++;
				}
				DBReader->Close();

				//---------------------------------------------------
				//Insert a new record
				sqlCommand_Base->CommandText = String::Format( "INSERT INTO {0} (GUID, IsLock, Type, Flag) VALUES ({1}, 0, 1, 3)" , strDBName, __box(iGUID));
				DBReader = sqlCommand_Base->ExecuteReader();
				DBReader->Close();
				//---------------------------------------------------
			}	
		}
		else
		{
			DBReader->Close();

			//---------------------------------------------------
			//Insert a new record
			sqlCommand_Base->CommandText = String::Format( "INSERT INTO {0} (GUID, IsLock, Type, Flag) VALUES ({1}, 0, 1, 3)" , strDBName, __box(iGUID));
			DBReader = sqlCommand_Base->ExecuteReader();
			DBReader->Close();
			//---------------------------------------------------
		}		
		//---------------------------------------------------

		//---------------------------------------------------
		//更新所有的字串資料
		ReaderClass< DB_GameObjDbStruct >*				Reader = ObjReader();
		std::map<std::string, ReadInfoStruct>*          ReadInfo ;
		std::map<std::string, ReadInfoStruct>::iterator Iter;

		ReadInfo = Reader->ReadInfo();

		for(Iter = ReadInfo->begin() ; Iter != ReadInfo->end() ; Iter++)
		{
			ReadInfoStruct *IDData = &(Iter->second);
			String* strFieldName = new String(Iter->first.c_str());

			switch(IDData->Type)
			{
			case ENUM_Type_CharStringPoint:
			case ENUM_Type_TextDataPoint:
				{
					//組合KeyStr
					String* strKey = String::Format("Sys{0}_{1}", __box(iGUID) , strFieldName);

					//----------------------------------------------------------
					//檢查系統字串是否已存在
					bool IsFindStr;
					sqlCommand_Base->CommandText = String::Format("SELECT COUNT(KeyStr) FROM StringDB WHERE KeyStr = '{0}'", strKey);
					DBReader = sqlCommand_Base->ExecuteReader();
					while( DBReader->Read( ) )
					{
						if( DBReader->GetInt32( 0 ) != 0 )
						{
							IsFindStr = true;
							break;
						}
					}
					DBReader->Close();
					//----------------------------------------------------------

					//----------------------------------------------------------
					//字串不存在, 新增系統字串
					if( IsFindStr == false )
					{
						if (String::Equals("name", strFieldName->ToLower()))
						{
							sqlCommand_Base->CommandText = String::Format("INSERT INTO StringDB( Type , KeyStr ,OrgObjID, Content , Note ) VALUES ( 1 , '{0}' , {1}, 'Noname' , '系統物件字串' )", strKey, __box(iGUID));

							//名稱初始值
							sprintf(pObjDB->GameData.Name, "%s", "Noname");
						}
						else
						{
							sqlCommand_Base->CommandText = String::Format("INSERT INTO StringDB( Type , KeyStr ,OrgObjID, Content , Note ) VALUES ( 1 , '{0}' , {1}, '' , '系統物件字串' )", strKey, __box(iGUID));
						}

						DBReader = sqlCommand_Base->ExecuteReader();
						DBReader->Close();
					}
					//----------------------------------------------------------
				}
				break;
			default:
				continue;
			}
		}
		//---------------------------------------------------

		//---------------------------------------------------
		//設定初始值
		pObjDB->GameData.PE.Flag.PE.UIVisible	 = true;
		pObjDB->GameData.PE.Flag.PE.ScoreVisible = true;
		//---------------------------------------------------
	}

	//資料更新
	NUD_CreateCount->Value = 1;
	LoadTreeView();
	UpDateList( );
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
ReaderClass< DB_GameObjDbStruct >* PEForm::ObjReader( )
{
	return  GameObjDbStructEx::ObjReader_PE( );
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::OnTimeProc()
{
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::OnActive()
{
	static bool FirstTime = true;

	//設定種族職業資訊
	if( FirstTime  == false )
		return;

	BaseForm::OnActive();	
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::OnSelectObj( bool LockOk )
{
	_ObjDB.GameData.Classification = EM_ObjectClass_PE;

	//----------------------------------------------
	//清除沒有被正確儲存的階段或是條件
	SqlDataReader* DBReader = NULL;
	sqlCommand_Base->CommandText = String::Format("DELETE FROM {0} WHERE ((Type = 2) OR (Type = 3)) AND (ParentGUID = 0)", new String(_DBName));
	DBReader = sqlCommand_Base->ExecuteReader();
	DBReader->Close();
	//----------------------------------------------

	LoadVars();
	LoadPhases();

	m_tbcMain->SelectedIndex = 0;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
	_ObjDB.GameData.Classification = EM_ObjectClass_PE;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
int PEForm::ObjSize(  )
{
	GameObjDbStruct *P = NULL;
	int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) +  sizeof( P->PE ) + 3;
	Size = Size & 0xfffffC;

	return Size;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::OnValueChange()
{

}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::LoadPhases()
{
	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;

	//--------------------------------------------
	//clear
	for (int i = 0; i < m_Phases->Count; ++i)
	{
		PEPhase* ph = m_Phases->get_Item(i);

		if (ph)
		{
			ph->Release();
		}
	}

	m_PhaseIndex->Clear();
	m_Phases->Clear();
	//--------------------------------------------

	//--------------------------------------------
	//read number of phases from DB
	SqlDataReader* DBReader;

	int iComType = EM_PE_COM_PHASE;
	sqlCommand_Base->CommandText = String::Format("SELECT GUID FROM {0} WHERE (Type = {1}) AND (ParentGUID = {2})", new String(_DBName), __box(iComType), __box(pObjDB->GameData.GUID));
	DBReader = sqlCommand_Base->ExecuteReader();

	Generic::List<int>* lstGUIDs = new Generic::List<int>();

	int iGUID = 0;
	while(DBReader->Read())
	{
		iGUID = DBReader->GetInt32(0);
		lstGUIDs->Add(iGUID);
	}
	DBReader->Close();
	//--------------------------------------------

	//--------------------------------------------
	//Load phases
	for (int i = 0; i < lstGUIDs->Count; ++i)
	{
		iGUID = lstGUIDs->get_Item(i);
		LoadPhase(iGUID);
	}
	//--------------------------------------------

	_Update_DataToDisplay = true;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::LoadVars()
{
	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;

	//--------------------------------------------
	//clear
	for (int i = 0; i < m_Vars->Count; ++i)
	{
		PEVar* var = m_Vars->get_Item(i);

		if (var != NULL)
		{
			var->Release();
		}
	}

	m_VarIndex->Clear();
	m_Vars->Clear();

	m_lvPEVar->Items->Clear();
	//--------------------------------------------

	//--------------------------------------------
	SqlDataReader* DBReader;

	int iComType = EM_PE_COM_VAR;
	sqlCommand_Base->CommandText = String::Format("SELECT GUID FROM {0} WHERE Type = {1}", new String(_DBName), __box(iComType));
	DBReader = sqlCommand_Base->ExecuteReader();

	Generic::List<int>* lstGUIDs = new Generic::List<int>();

	int iGUID = 0;
	while(DBReader->Read())
	{
		iGUID = DBReader->GetInt32(0);
		lstGUIDs->Add(iGUID);
	}
	DBReader->Close();
	//--------------------------------------------

	//--------------------------------------------
	for (int i = 0; i < lstGUIDs->Count; ++i)
	{
		iGUID = lstGUIDs->get_Item(i);

		PEVar* var = LoadVar(iGUID);

		System::String* StrList[] = new System::String*[3];
		StrList[0] = Convert::ToString(__box(var->GUID));
		StrList[1] = var->VarName;
		StrList[2] = var->VarNote;

		m_lvPEVar->Items->Add(new ListViewItem(StrList));
	}
	//--------------------------------------------
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::LoadZoneInfo()
{
	SqlDataReader* DBReader;

	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
	int iGUID	= pObjDB->GameData.GUID;

	sqlCommand_Base->CommandText = "SELECT n.GUID, s.Content FROM ZoneObjectDB AS n INNER JOIN StringDB AS s ON n.GUID = s.OrgObjID WHERE right(keystr,5) = '_name' ORDER BY n.GUID";
	DBReader = sqlCommand_Base->ExecuteReader();

	m_ZoneInfo->Clear();
	while( DBReader->Read() )
	{
		int iZoneGUID = DBReader->GetInt32(0);
		String* strName = DBReader->GetString(1);

		PEZoneInfo* pZInfo = new PEZoneInfo(iZoneGUID, strName);

		m_ZoneInfo->Add(iZoneGUID, pZInfo);
	}
	DBReader->Close();
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::LoadSubZoneInfo()
{
	SqlDataReader* DBReader;

	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
	int iGUID	= pObjDB->GameData.GUID;
	int iZoneID = pObjDB->GameData.PE.Data.PE.ZoneID;

	//-----------------------------------------------------
	//從DB讀取SubZone資訊
	m_SubZoneInfo->Clear();
	sqlCommand_Base->CommandText = String::Format("SELECT MapCount FROM ZoneObjectDB WHERE GUID = {0}", __box(iZoneID));
	DBReader = sqlCommand_Base->ExecuteReader();

	int iMapCount = 0;
	if (DBReader->Read())
	{
		iMapCount = DBReader->GetInt32(0);
	}
	DBReader->Close();

	if (iMapCount > 0)
	{
		m_SubZoneInfo->Clear();
		for (int i = 1; i <= iMapCount; ++i)
		{
			sqlCommand_Base->CommandText = String::Format("SELECT MapID{0}, MapName{0} FROM ZoneObjectDB WHERE GUID = {1}", __box(i), __box(iZoneID));
			DBReader = sqlCommand_Base->ExecuteReader();

			if (DBReader->Read())
			{
				int iSZID		= DBReader->GetInt32(0);
				String* strName = DBReader->GetString(1);

				PESubZoneInfo* pSZInfo = new PESubZoneInfo(iZoneID, iSZID, strName);
				m_SubZoneInfo->Add(iSZID, pSZInfo);
			}
			DBReader->Close();
		}
	}
	//-----------------------------------------------------
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEPhase* PEForm::NewPhase()
{
	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;

	PEPhase* Result = new PEPhase(this, pObjDB);
	Result->NewObjDB(pObjDB->GameData.GUID);
	m_PhaseIndex->Add(Result->GUID, Result);
	m_Phases->Add(Result);

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEPhase* PEForm::LoadPhase(int iGUID)
{
	PEPhase* Result = NULL;

	if (m_PhaseIndex->ContainsKey(iGUID))
	{
		Result = m_Phases->get_Item(iGUID);		
	}
	else
	{
		DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
		Result = new PEPhase(this, pObjDB);
		m_PhaseIndex->Add(iGUID, Result);
		m_Phases->Add(Result);
	}

	Result->ReadObjDB(iGUID);

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::RemovePhase(int iGUID)
{
	if (m_PhaseIndex->ContainsKey(iGUID))
	{
		PEPhase* ph = m_PhaseIndex->get_Item(iGUID);
		ph->RemoveObjDB();
		ph->Release();
		m_PhaseIndex->Remove(iGUID);
		m_Phases->Remove(ph);
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEVar* PEForm::NewVar()
{
	DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
	PEVar* Result = new PEVar(this, pObjDB);
	Result->NewObjDB(0);
	m_VarIndex->Add(Result->GUID, Result);
	m_Vars->Add(Result);

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
PEVar* PEForm::LoadVar(int iGUID)
{
	PEVar* Result = NULL;

	if (m_VarIndex->ContainsKey(iGUID))
	{
		Result = m_Vars->get_Item(iGUID);		
	}
	else
	{
		DB_GameObjDbStruct __pin * pObjDB = &_ObjDB;
		Result = new PEVar(this, pObjDB);
		m_VarIndex->Add(iGUID, Result);
		m_Vars->Add(Result);
	}

	Result->ReadObjDB(iGUID);

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::RemoveVar(int iGUID)
{
	if (m_VarIndex->ContainsKey(iGUID))
	{
		PEVar* var = m_VarIndex->get_Item(iGUID);
		var->RemoveObjDB();
		m_VarIndex->Remove(iGUID);
		m_Vars->Remove(var);
	}	
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
bool PEForm::PE_CheckModifyAndCheckOut()
{
	bool Result = CheckModifyAndCheckOut();

	if (Result)
	{
		if( CB_Lock->Checked == true )
			_ObjDB.IsModify = true;

		_OnValueChange = true;
	}

	return Result;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
void PEForm::SaveTabPageIndex()
{
	m_TabPageIndex = m_tbcPHs->SelectedIndex;
}