#include "LearnMagicForm.h"

using namespace ObjDataEdit;

//######################################################################################################
//主要需要繼承的涵式
ReaderClass< DB_GameObjDbStruct >* LearnMagicForm::ObjReader( )
{
	return GameObjDbStructEx::ObjReader_LearnMagic( );	
}
void    LearnMagicForm::OnActive()
{
    static bool FirstTime = true;

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

	BaseForm::OnActive();

	FirstTime = false;

    CB_NpcJob->Items->Clear();
    for( unsigned int i = 0 ; i < Global::JobName.size() ; i++ )
    {
        String* Str =  Global::JobName[i].c_str();
        System::Object* AddItem[] = new System::Object*[1];
        AddItem[0] = Str;
        CB_NpcJob->Items->AddRange(AddItem);
    }
	
}
void    LearnMagicForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_LearnMagic;
    if( _ObjDB.GameData.GUID - Def_ObjectClass_LearnMagic < CB_NpcJob->Items->Count )
        CB_NpcJob->SelectedIndex = _ObjDB.GameData.GUID - Def_ObjectClass_LearnMagic;
    else
        CB_NpcJob->SelectedIndex = 0;
    
    RefreshMagicName(  );    
}
//輸出時額外設定
void    LearnMagicForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_LearnMagic;
}
void    LearnMagicForm::OnTimeProc()
{
	if( ReSearchNameFlag == true )
	{
		ReSearchNameFlag = false;

		LB_MagicName->Text		= SearchObjName( DotNetStr::StringToInt(  TB_MagicID->Text ) );
		LB_KeyItemName->Text	= SearchObjName( DotNetStr::StringToInt(  TB_KeyItem->Text ) );
		LB_SPMagicName->Text	= SearchObjName( DotNetStr::StringToInt(  TB_SPMagicID->Text ) );
		LB_SPKeyItemName->Text	= SearchObjName( DotNetStr::StringToInt(  TB_SPKeyItem->Text ) );

		LB_NormalNeedMagicID1->Text	= SearchObjName( DotNetStr::StringToInt(  TB_NormalNeedMagicID1->Text ) );
		LB_NormalNeedMagicID2->Text	= SearchObjName( DotNetStr::StringToInt(  TB_NormalNeedMagicID2->Text ) );
		LB_SPNeedMagicID1->Text	= SearchObjName( DotNetStr::StringToInt(  TB_SPNeedMagicID1->Text ) );
		LB_SPNeedMagicID2->Text	= SearchObjName( DotNetStr::StringToInt(  TB_SPNeedMagicID2->Text ) );
	}
}

int     LearnMagicForm::ObjSize(  )
{
    GameObjDbStruct *P = NULL;
    int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) + sizeof( P->LearnMagic ) + 4 ;
    Size = Size & 0xfffffC;
    return Size;
}
//######################################################################################################
void LearnMagicForm::RefreshMagicName( )
{
	int i = 0;
	LV_NormalMagic->Items->Clear();
	for( i = 0 ; i < _ObjDB.GameData.LearnMagic.NormalSkillCount ; i++ )
	{
		int	Pos			= _ObjDB.GameData.LearnMagic.NormalSkill[ i ].SaveLvPos;

		int MagicID		= _ObjDB.GameData.LearnMagic.NormalSkill[ i ].MagicID;
		int	LearnLV		= _ObjDB.GameData.LearnMagic.NormalSkill[ i ].LearnLV;
		int	KeyItemID	= _ObjDB.GameData.LearnMagic.NormalSkill[ i ].KeyItemID;

		int	NeedMagicID1 = _ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicID[0];	
		int	NeedMagicLv1 = _ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicLv[0];
		int	NeedMagicID2 = _ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicID[1];
		int	NeedMagicLv2 = _ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicLv[1];

		System::String* StrList[] = new System::String*[12];

		StrList[0] = String::Format("{0}", __box( Pos ) );
		StrList[1] = String::Format("{0}", __box( MagicID ) );
		StrList[2] = SearchObjName( MagicID );
		StrList[3] = String::Format("{0}", __box( LearnLV ) );
		StrList[4] = String::Format("{0}", __box( KeyItemID ) );
		StrList[5] = SearchObjName( KeyItemID );
		StrList[6] = String::Format("{0}", __box( NeedMagicID1 ) );
		StrList[7] = SearchObjName( NeedMagicID1 );
		StrList[8] = String::Format("{0}", __box( NeedMagicLv1 ) );
		StrList[9]  = String::Format("{0}", __box( NeedMagicID2 ) );
		StrList[10]  = SearchObjName( NeedMagicID2 );
		StrList[11] = String::Format("{0}", __box( NeedMagicLv2 ) );

		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_NormalMagic->Items->Add( NewListViewItem );
	}

	LV_SPMagic->Items->Clear();
	for( i = 0 ; i < _ObjDB.GameData.LearnMagic.SPSkillCount ; i++ )
	{
		int	Pos			= _ObjDB.GameData.LearnMagic.SPSkill[ i ].SaveLvPos;		

		int MagicID		= _ObjDB.GameData.LearnMagic.SPSkill[ i ].MagicID;
		int	LearnLV		= _ObjDB.GameData.LearnMagic.SPSkill[ i ].LearnLV;
		int	KeyItemID	= _ObjDB.GameData.LearnMagic.SPSkill[ i ].KeyItemID;

		int	NeedMagicID1 = _ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicID[0];	
		int	NeedMagicLv1 = _ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicLv[0];
		int	NeedMagicID2 = _ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicID[1];
		int	NeedMagicLv2 = _ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicLv[1];

		System::String* StrList[] = new System::String*[12];

		StrList[0] = String::Format("{0}", __box( Pos ) );
		StrList[1] = String::Format("{0}", __box( MagicID ) );
		StrList[2] = SearchObjName( MagicID );
		StrList[3] = String::Format("{0}", __box( LearnLV ) );
		StrList[4] = String::Format("{0}", __box( KeyItemID ) );
		StrList[5] = SearchObjName( KeyItemID );
		StrList[6] = String::Format("{0}", __box( NeedMagicID1 ) );
		StrList[7] = SearchObjName( NeedMagicID1 );
		StrList[8] = String::Format("{0}", __box( NeedMagicLv1 ) );
		StrList[9]  = String::Format("{0}", __box( NeedMagicID2 ) );
		StrList[10]  = SearchObjName( NeedMagicID2 );
		StrList[11] = String::Format("{0}", __box( NeedMagicLv2 ) );

		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_SPMagic->Items->Add( NewListViewItem );
	}

}

Void LearnMagicForm::NewNormalMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	if( LV_NormalMagic->Items->Count >= _MAX_Edit_NormalSkill_COUNT_ )
	{
		MessageBox::Show( L"最多只可以有100筆資料" , L"錯誤" , MessageBoxButtons::OK );			
		return;
	}

	int	Pos			= DotNetStr::StringToInt(  TB_Pos->Text );

	int MagicID		= DotNetStr::StringToInt(  TB_MagicID->Text );
	int	LearnLV		= DotNetStr::StringToInt(  TB_RequestLV->Text );
	int	KeyItemID	= DotNetStr::StringToInt(  TB_KeyItem->Text );	

	int	NeedMagicID1 = DotNetStr::StringToInt(  TB_NormalNeedMagicID1->Text );	
	int	NeedMagicLv1 = DotNetStr::StringToInt(  TB_NormalNeedMagicLv1->Text );	
	int	NeedMagicID2 = DotNetStr::StringToInt(  TB_NormalNeedMagicID2->Text );	
	int	NeedMagicLv2 = DotNetStr::StringToInt(  TB_NormalNeedMagicLv2->Text );	

	System::String* StrList[] = new System::String*[12];

	StrList[0] = String::Format("{0}", __box( Pos ) );
	StrList[1] = String::Format("{0}", __box( MagicID ) );
	StrList[2] = SearchObjName( MagicID );
	StrList[3] = String::Format("{0}", __box( LearnLV ) );
	StrList[4] = String::Format("{0}", __box( KeyItemID ) );
	StrList[5] = SearchObjName( KeyItemID );
	StrList[6] = String::Format("{0}", __box( NeedMagicID1 ) );
	StrList[7] = SearchObjName( NeedMagicID1 );
	StrList[8] = String::Format("{0}", __box( NeedMagicLv1 ) );
	StrList[9]  = String::Format("{0}", __box( NeedMagicID2 ) );
	StrList[10]  = SearchObjName( NeedMagicID2 );
	StrList[11] = String::Format("{0}", __box( NeedMagicLv2 ) );

	ListViewItem*  NewListViewItem = new ListViewItem( StrList );
	LV_NormalMagic->Items->Add( NewListViewItem );

	int SelectID = _ObjDB.GameData.LearnMagic.NormalSkillCount;

	_ObjDB.GameData.LearnMagic.NormalSkillCount = LV_NormalMagic->Items->Count;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].MagicID	= MagicID;	
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].LearnLV	= LearnLV;	
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].KeyItemID	= KeyItemID;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicID[0] = NeedMagicID1;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicID[1] = NeedMagicID2;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicLv[0] = NeedMagicLv1;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicLv[1] = NeedMagicLv2;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].SaveLvPos		= Pos;

	_OnValueChange = true;
}
Void LearnMagicForm::DelNormalMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_NormalMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	int SelectID =LV_NormalMagic->SelectedIndices->Item[0];

	ListViewItem* Item = SelectItem->Item[0];

	LV_NormalMagic->Items->Remove( Item );

	_ObjDB.GameData.LearnMagic.NormalSkillCount = LV_NormalMagic->Items->Count;

	int Total = _ObjDB.GameData.LearnMagic.NormalSkillCount;


	for( int i = SelectID ; i < Total ; i++ )
	{
		//_ObjDB.GameData.LearnMagic.NormalSkill[ i ] =_ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ];
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].MagicID			= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].MagicID;
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].LearnLV			= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].LearnLV;
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].KeyItemID		= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].KeyItemID;
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicID[0]	= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].NeedMagicID[0];
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicID[1]	= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].NeedMagicID[1];
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicLv[0]	= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].NeedMagicLv[0];
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].NeedMagicLv[1]	= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].NeedMagicLv[1];
		_ObjDB.GameData.LearnMagic.NormalSkill[ i ].SaveLvPos		= _ObjDB.GameData.LearnMagic.NormalSkill[ i + 1 ].SaveLvPos;

	}

	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].MagicID			= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].LearnLV			= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].KeyItemID		= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].NeedMagicID[0]	= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].NeedMagicID[1]	= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].NeedMagicLv[0]	= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].NeedMagicLv[1]	= 0;
	_ObjDB.GameData.LearnMagic.NormalSkill[ Total ].SaveLvPos		= 0;


	_OnValueChange = true;
}
Void LearnMagicForm::ModifyNormalMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_NormalMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;
	
	int		SelectID = LV_NormalMagic->SelectedIndices->Item[0];

	ListViewItem* Item = SelectItem->Item[0];

	int	Pos			= DotNetStr::StringToInt(  TB_Pos->Text );

	int MagicID		= DotNetStr::StringToInt(  TB_MagicID->Text );
	int	LearnLV		= DotNetStr::StringToInt(  TB_RequestLV->Text );
	int	KeyItemID	= DotNetStr::StringToInt(  TB_KeyItem->Text );	

	int	NeedMagicID1 = DotNetStr::StringToInt(  TB_NormalNeedMagicID1->Text );	
	int	NeedMagicLv1 = DotNetStr::StringToInt(  TB_NormalNeedMagicLv1->Text );	
	int	NeedMagicID2 = DotNetStr::StringToInt(  TB_NormalNeedMagicID2->Text );	
	int	NeedMagicLv2 = DotNetStr::StringToInt(  TB_NormalNeedMagicLv2->Text );	

	Item->SubItems->Item[0]->Text = String::Format("{0}", __box( Pos ) );

	Item->SubItems->Item[1]->Text = String::Format("{0}", __box( MagicID ) );
	Item->SubItems->Item[2]->Text = SearchObjName( MagicID );
	Item->SubItems->Item[3]->Text = String::Format("{0}", __box( LearnLV ) );
	Item->SubItems->Item[4]->Text = String::Format("{0}", __box( KeyItemID ) );
	Item->SubItems->Item[5]->Text = SearchObjName( KeyItemID );

	Item->SubItems->Item[6]->Text= String::Format("{0}", __box( NeedMagicID1 ) );
	Item->SubItems->Item[7]->Text= SearchObjName( NeedMagicID1 );
	Item->SubItems->Item[8]->Text= String::Format("{0}", __box( NeedMagicLv1 ) );

	Item->SubItems->Item[9]->Text= String::Format("{0}", __box( NeedMagicID2 ) );
	Item->SubItems->Item[10]->Text= SearchObjName( NeedMagicID2 );
	Item->SubItems->Item[11]->Text= String::Format("{0}", __box( NeedMagicLv2 ) );

	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].MagicID	= MagicID;	
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].LearnLV	= LearnLV;	
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].KeyItemID	= KeyItemID;

	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicID[0] = NeedMagicID1;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicID[1] = NeedMagicID2;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicLv[0] = NeedMagicLv1;
	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].NeedMagicLv[1] = NeedMagicLv2;

	_ObjDB.GameData.LearnMagic.NormalSkill[SelectID].SaveLvPos	= Pos;	

	_OnValueChange = true;
}
Void LearnMagicForm::LV_NormalMagic_SelectedIndexChanged(System::Object*  sender, System::EventArgs*  e)
{
	ListView::SelectedListViewItemCollection* SelectItem = LV_NormalMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	ListViewItem* Item = SelectItem->Item[0];

	TB_Pos->Text		= Item->SubItems->Item[0]->Text;

	TB_MagicID->Text	= Item->SubItems->Item[1]->Text;
	TB_RequestLV->Text	= Item->SubItems->Item[3]->Text;
	TB_KeyItem->Text	= Item->SubItems->Item[4]->Text;

	TB_NormalNeedMagicID1->Text= Item->SubItems->Item[6]->Text;
	TB_NormalNeedMagicLv1->Text= Item->SubItems->Item[8]->Text;
	TB_NormalNeedMagicID2->Text= Item->SubItems->Item[9]->Text;
	TB_NormalNeedMagicLv2->Text= Item->SubItems->Item[11]->Text;

}

Void LearnMagicForm::NewSPMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	if( LV_SPMagic->Items->Count >= _MAX_Edit_SPSkill_COUNT_ )
	{
		MessageBox::Show( L"最多只可以有200筆資料" , L"錯誤" , MessageBoxButtons::OK );			
		return;
	}

	int	Pos			= DotNetStr::StringToInt(  TB_SPPos->Text );

	int MagicID		= DotNetStr::StringToInt(  TB_SPMagicID->Text );
	int	LearnLV		= DotNetStr::StringToInt(  TB_SPRequestLV->Text );
	int	KeyItemID	= DotNetStr::StringToInt(  TB_SPKeyItem->Text );	

	int	NeedMagicID1 = DotNetStr::StringToInt(  TB_SPNeedMagicID1->Text );	
	int	NeedMagicLv1 = DotNetStr::StringToInt(  TB_SPNeedMagicLv1->Text );	
	int	NeedMagicID2 = DotNetStr::StringToInt(  TB_SPNeedMagicID2->Text );	
	int	NeedMagicLv2 = DotNetStr::StringToInt(  TB_SPNeedMagicLv2->Text );	


	System::String* StrList[] = new System::String*[12];

	StrList[0] = String::Format("{0}", __box( Pos ) );
	StrList[1] = String::Format("{0}", __box( MagicID ) );
	StrList[2] = SearchObjName( MagicID );
	StrList[3] = String::Format("{0}", __box( LearnLV ) );
	StrList[4] = String::Format("{0}", __box( KeyItemID ) );
	StrList[5] = SearchObjName( KeyItemID );
	StrList[6] = String::Format("{0}", __box( NeedMagicID1 ) );
	StrList[7] = SearchObjName( NeedMagicID1 );
	StrList[8] = String::Format("{0}", __box( NeedMagicLv1 ) );
	StrList[9]  = String::Format("{0}", __box( NeedMagicID2 ) );
	StrList[10]  = SearchObjName( NeedMagicID2 );
	StrList[11] = String::Format("{0}", __box( NeedMagicLv2 ) );

	ListViewItem*  NewListViewItem = new ListViewItem( StrList );
	LV_SPMagic->Items->Add( NewListViewItem );

	int SelectID = _ObjDB.GameData.LearnMagic.SPSkillCount;

	_ObjDB.GameData.LearnMagic.SPSkillCount = LV_SPMagic->Items->Count;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].MagicID	= MagicID;	
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].LearnLV	= LearnLV;	
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].KeyItemID	= KeyItemID;

	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicID[0]	= NeedMagicID1;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicID[1]	= NeedMagicID2;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicLv[0]	= NeedMagicLv1;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicLv[1]	= NeedMagicLv2;

	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].SaveLvPos	= Pos;	



	_OnValueChange = true;
}
Void LearnMagicForm::DelSPMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_SPMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	int SelectID = LV_SPMagic->SelectedIndices->Item[0];;

	ListViewItem* Item = SelectItem->Item[0];

	LV_SPMagic->Items->Remove( Item );

	_ObjDB.GameData.LearnMagic.SPSkillCount = LV_SPMagic->Items->Count;

	int Total = _ObjDB.GameData.LearnMagic.SPSkillCount;

	for( int i = SelectID ; i < Total ; i++ )
	{
//		_ObjDB.GameData.LearnMagic.SPSkill[ i ] = _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ];

		_ObjDB.GameData.LearnMagic.SPSkill[ i ].MagicID			= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].MagicID;
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].LearnLV			= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].LearnLV;
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].KeyItemID		= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].KeyItemID;
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicID[0]	= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].NeedMagicID[0];
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicID[1]	= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].NeedMagicID[1];
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicLv[0]	= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].NeedMagicLv[0];
		_ObjDB.GameData.LearnMagic.SPSkill[ i ].NeedMagicLv[1]	= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].NeedMagicLv[1];

		_ObjDB.GameData.LearnMagic.SPSkill[ i ].SaveLvPos		= _ObjDB.GameData.LearnMagic.SPSkill[ i + 1 ].SaveLvPos;

	}

	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].MagicID			= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].LearnLV			= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].KeyItemID		= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].NeedMagicID[0]	= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].NeedMagicID[1]	= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].NeedMagicLv[0]	= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].NeedMagicLv[1]	= 0;
	_ObjDB.GameData.LearnMagic.SPSkill[ Total ].SaveLvPos		= 0;


	_OnValueChange = true;
}
Void LearnMagicForm::ModifySPMagic_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_SPMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	int		SelectID = LV_SPMagic->SelectedIndices->Item[0];

	ListViewItem* Item = SelectItem->Item[0];


	int	Pos			= DotNetStr::StringToInt(  TB_SPPos->Text );

	int MagicID		= DotNetStr::StringToInt(  TB_SPMagicID->Text );
	int	LearnLV		= DotNetStr::StringToInt(  TB_SPRequestLV->Text );
	int	KeyItemID	= DotNetStr::StringToInt(  TB_SPKeyItem->Text );	

	int	NeedMagicID1 = DotNetStr::StringToInt(  TB_SPNeedMagicID1->Text );	
	int	NeedMagicLv1 = DotNetStr::StringToInt(  TB_SPNeedMagicLv1->Text );	
	int	NeedMagicID2 = DotNetStr::StringToInt(  TB_SPNeedMagicID2->Text );	
	int	NeedMagicLv2 = DotNetStr::StringToInt(  TB_SPNeedMagicLv2->Text );	

	Item->SubItems->Item[0]->Text = String::Format("{0}", __box( Pos ) );

	Item->SubItems->Item[1]->Text = String::Format("{0}", __box( MagicID ) );
	Item->SubItems->Item[2]->Text = SearchObjName( MagicID );
	Item->SubItems->Item[3]->Text = String::Format("{0}", __box( LearnLV ) );
	Item->SubItems->Item[4]->Text = String::Format("{0}", __box( KeyItemID ) );
	Item->SubItems->Item[5]->Text = SearchObjName( KeyItemID );

	Item->SubItems->Item[6]->Text= String::Format("{0}", __box( NeedMagicID1 ) );
	Item->SubItems->Item[7]->Text= SearchObjName( NeedMagicID1 );
	Item->SubItems->Item[8]->Text= String::Format("{0}", __box( NeedMagicLv1 ) );

	Item->SubItems->Item[9]->Text= String::Format("{0}", __box( NeedMagicID2 ) );
	Item->SubItems->Item[10]->Text= SearchObjName( NeedMagicID2 );
	Item->SubItems->Item[11]->Text= String::Format("{0}", __box( NeedMagicLv2 ) );

/*
	System::String* StrList[] = new System::String*[12];

	StrList[0] = String::Format("{0}", __box( Pos ) );
	StrList[1] = String::Format("{0}", __box( MagicID ) );
	StrList[2] = SearchObjName( MagicID );
	StrList[3] = String::Format("{0}", __box( LearnLV ) );
	StrList[4] = String::Format("{0}", __box( KeyItemID ) );
	StrList[5] = SearchObjName( KeyItemID );
	StrList[6] = String::Format("{0}", __box( NeedMagicID1 ) );
	StrList[7] = SearchObjName( NeedMagicID1 );
	StrList[8] = String::Format("{0}", __box( NeedMagicLv1 ) );
	StrList[9]  = String::Format("{0}", __box( NeedMagicID2 ) );
	StrList[10]  = SearchObjName( NeedMagicID2 );
	StrList[11] = String::Format("{0}", __box( NeedMagicLv2 ) );
*/

	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].SaveLvPos	= Pos;	

	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].MagicID	= MagicID;	
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].LearnLV	= LearnLV;	
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].KeyItemID	= KeyItemID;

	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicID[0] = NeedMagicID1;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicID[1] = NeedMagicID2;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicLv[0] = NeedMagicLv1;
	_ObjDB.GameData.LearnMagic.SPSkill[SelectID].NeedMagicLv[1] = NeedMagicLv2;

	_OnValueChange = true;
}
Void LearnMagicForm::LV_SPMagic_SelectedIndexChanged(System::Object*  sender, System::EventArgs*  e)
{
	ListView::SelectedListViewItemCollection* SelectItem = LV_SPMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	ListViewItem* Item = SelectItem->Item[0];
	TB_SPPos->Text		= Item->SubItems->Item[0]->Text;

	TB_SPMagicID->Text	= Item->SubItems->Item[1]->Text;
	TB_SPRequestLV->Text= Item->SubItems->Item[3]->Text;
	TB_SPKeyItem->Text	= Item->SubItems->Item[4]->Text;

	TB_SPNeedMagicID1->Text= Item->SubItems->Item[6]->Text;
	TB_SPNeedMagicLv1->Text= Item->SubItems->Item[8]->Text;
	TB_SPNeedMagicID2->Text= Item->SubItems->Item[9]->Text;
	TB_SPNeedMagicLv2->Text= Item->SubItems->Item[11]->Text;

}

System::Void LearnMagicForm::OnMagicInfoChange(System::Object*  sender, System::EventArgs*  e)
{
	ReSearchNameFlag = true;
}

System::Void LearnMagicForm::NormalMagic_UpClick(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_NormalMagic->SelectedItems;

	if( SelectItem->Count <= 0 )
		return;

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	int		SelectID = LV_NormalMagic->SelectedIndices->Item[0];
	if( SelectID == 0 )
		return;

	swap( TempObj->GameData.LearnMagic.NormalSkill[SelectID] , TempObj->GameData.LearnMagic.NormalSkill[SelectID-1] );
	//////////////////////////////////////////////////////////////////////////
	ListViewItem* ItemUp = LV_NormalMagic->Items->Item[ SelectID -1 ];
	ListViewItem* ItemDn = LV_NormalMagic->Items->Item[ SelectID ];

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		String* Str;
		Str = ItemDn->SubItems->Item[i]->Text;
		ItemDn->SubItems->Item[i]->Text = ItemUp->SubItems->Item[i]->Text;
		ItemUp->SubItems->Item[i]->Text = Str;
	}
		
	//////////////////////////////////////////////////////////////////////////
	

	LV_NormalMagic->SelectedIndices->Clear();
	LV_NormalMagic->SelectedIndices->Add( SelectID -1 );
	_OnValueChange = true;
}
System::Void LearnMagicForm::NormalMagic_DownClick(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_NormalMagic->SelectedItems;

	if( SelectItem->Count == 0 )
		return;

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	int		SelectID = LV_NormalMagic->SelectedIndices->Item[0];
	if( SelectID == LV_NormalMagic->Items->Count -1  )
		return;

	swap( TempObj->GameData.LearnMagic.NormalSkill[SelectID] , TempObj->GameData.LearnMagic.NormalSkill[SelectID+1] );
	//////////////////////////////////////////////////////////////////////////
	ListViewItem* ItemUp = LV_NormalMagic->Items->Item[ SelectID ];
	ListViewItem* ItemDn = LV_NormalMagic->Items->Item[ SelectID + 1];

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		String* Str;
		Str = ItemDn->SubItems->Item[i]->Text;
		ItemDn->SubItems->Item[i]->Text = ItemUp->SubItems->Item[i]->Text;
		ItemUp->SubItems->Item[i]->Text = Str;
	}

	//////////////////////////////////////////////////////////////////////////


	LV_NormalMagic->SelectedIndices->Clear();
	LV_NormalMagic->SelectedIndices->Add( SelectID +1 );
	_OnValueChange = true;

}

System::Void LearnMagicForm::SPMagic_UpClick(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_SPMagic->SelectedItems;

	if( SelectItem->Count <= 0 )
		return;

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	int		SelectID = LV_SPMagic->SelectedIndices->Item[0];
	if( SelectID == 0 )
		return;

	swap( TempObj->GameData.LearnMagic.SPSkill[SelectID] , TempObj->GameData.LearnMagic.SPSkill[SelectID-1] );
	//////////////////////////////////////////////////////////////////////////
	ListViewItem* ItemUp = LV_SPMagic->Items->Item[ SelectID -1 ];
	ListViewItem* ItemDn = LV_SPMagic->Items->Item[ SelectID ];

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		String* Str;
		Str = ItemDn->SubItems->Item[i]->Text;
		ItemDn->SubItems->Item[i]->Text = ItemUp->SubItems->Item[i]->Text;
		ItemUp->SubItems->Item[i]->Text = Str;
	}

	//////////////////////////////////////////////////////////////////////////


	LV_SPMagic->SelectedIndices->Clear();
	LV_SPMagic->SelectedIndices->Add( SelectID -1 );
	_OnValueChange = true;

}

System::Void LearnMagicForm::SPMagic_DownClick(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_SPMagic->SelectedItems;

	if( SelectItem->Count ==0 )
		return;

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	int		SelectID = LV_SPMagic->SelectedIndices->Item[0];
	if( SelectID == LV_SPMagic->Items->Count -1  )
		return;

	swap( TempObj->GameData.LearnMagic.SPSkill[SelectID] , TempObj->GameData.LearnMagic.SPSkill[SelectID+1] );
	//////////////////////////////////////////////////////////////////////////
	ListViewItem* ItemUp = LV_SPMagic->Items->Item[ SelectID ];
	ListViewItem* ItemDn = LV_SPMagic->Items->Item[ SelectID + 1];

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		String* Str;
		Str = ItemDn->SubItems->Item[i]->Text;
		ItemDn->SubItems->Item[i]->Text = ItemUp->SubItems->Item[i]->Text;
		ItemUp->SubItems->Item[i]->Text = Str;
	}

	//////////////////////////////////////////////////////////////////////////


	LV_SPMagic->SelectedIndices->Clear();
	LV_SPMagic->SelectedIndices->Add( SelectID +1 );
	_OnValueChange = true;
}

System::Void LearnMagicForm::SetMagicLearningLvClick(System::Object*  sender, System::EventArgs*  e)
{
	
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

	for( int i = 0  ; i < TempObj->GameData.LearnMagic.NormalSkillCount ;i++)
	{
		JobSkillBaseStruct& Skill = TempObj->GameData.LearnMagic.NormalSkill[i];
		sqlCommand_Base1->CommandText = String::Format( "UPDATE MagicCollectObjectDB SET ExpTableRate = {0} WHERE GUID = {1}" , __box( Skill.LearnLV - Skill.LearnLV/3 ) , __box( Skill.MagicID ) );
		sqlCommand_Base1->ExecuteReader()->Close();  
	}

	for( int i = 0  ; i < TempObj->GameData.LearnMagic.SPSkillCount ;i++)
	{
		JobSkillBaseStruct& Skill = TempObj->GameData.LearnMagic.SPSkill[i];
		sqlCommand_Base1->CommandText = String::Format( "UPDATE MagicCollectObjectDB SET ExpTableRate = {0} WHERE GUID = {1}" , __box( Skill.LearnLV - Skill.LearnLV/3 ) , __box( Skill.MagicID ) );
		sqlCommand_Base1->ExecuteReader()->Close();  
	}
}
//更新資料之後的事件
void	LearnMagicForm::AfterUpdateObj( DB_GameObjDbStruct* TempObj )
{
	//更新法術資料
}