#include "TreasureForm.h"
using namespace ObjDataEdit;
//######################################################################################################
//主要需要繼承的涵式
ReaderClass< DB_GameObjDbStruct >* TreasureForm::ObjReader( )
{
	return  GameObjDbStructEx::ObjReader_Treasure( );
}
void    TreasureForm::OnActive()
{
	static bool firstTime = true;

	if( firstTime == false )
		return;

	firstTime = false;

	BaseForm::OnActive();

}
void    TreasureForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_Treasure;
	_ObjDB.GameData.PricesType	= EM_ACPriceType_GameMoney;
	LV_TreasureList->Items->Clear();
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;
	int Count = Treasure.ItemCount;
	for( int i = 0 ; i < Count ; i++ )
	{
		System::String* StrList[] = new System::String*[6];
		StrList[0] = String::Format("{0}" , __box( Treasure.Item[i].OrgID ));
		StrList[1] = S"";
		StrList[2] = S"0%";
		StrList[3] = String::Format( "{0}" , __box( Treasure.Item[i].Count ) );
		StrList[4] = String::Format( "{0}" , __box( Treasure.Item[i].DropCount ) );
		StrList[5] = String::Format("{0}" , __box( i+1 ));
		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_TreasureList->Items->Add( NewListViewItem );
	}
	FixTreasureItemListInfo( );
}
void    TreasureForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_Treasure;
	TempObj->GameData.Cost = TempObj->GameData.Treasure.Gamble.Cost;
	TempObj->GameData.PricesType = EM_ACPriceType_GameMoney;
	TempObj->GameData.MaxHeap = 1;
	TempObj->GameData.BuyUnit = 1;
}
void    TreasureForm::OnTimeProc()
{
	static int LastEditObjectID = 0;

	int EditObjectID = DotNetStr::StringToInt( TB_ObjID->Text );
	if( EditObjectID != LastEditObjectID )
	{
		LastEditObjectID = EditObjectID;
		LB_EditObjName->Text = SearchObjName( EditObjectID );
	}
}
int     TreasureForm::ObjSize(  )
{
	GameObjDbStruct *P = NULL;
	int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) + sizeof( P->Treasure ) + 3;
	Size = Size & 0xfffffC;
	return Size;
}

void    TreasureForm::OnValueChange( )
{
	char	Buf[512];
	float TotalCost = 0;
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;
	//計算價值
	for( int i = 0 ; i < Treasure.ItemCount ; i++ )
	{
		TotalCost = SearchObjCost( Treasure.Item[i].OrgID ) * Treasure.Item[i].Count / 100000.0f * Treasure.Item[i].DropCount + TotalCost;
	}

	TempObj->GameData.Cost = int( TotalCost );

	TB_TotalCost->Text = String::Format( "{0}" , __box( int( TotalCost)  ) );

	//LB_AddPower->Text = SearchObjName( Treasure.Gamble.AddPower );
	ItemDropStruct* DropAbility = TempObj->GameData.Treasure.Gamble.DropItemAbility;
	sprintf( Buf , "%.3f%%" , float( DropAbility[0].Rate ) / 1000 );
	DropAbilityEx1->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[1].Rate ) / 1000 );
	DropAbilityEx2->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[2].Rate ) / 1000 );
	DropAbilityEx3->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[3].Rate ) / 1000 );
	DropAbilityEx4->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[4].Rate ) / 1000 );
	DropAbilityEx5->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[5].Rate ) / 1000 );
	DropAbilityEx6->Text = Buf;

	DropAbilityName1->Text = SearchObjName( DropAbility[0].OrgID );
	DropAbilityName2->Text = SearchObjName( DropAbility[1].OrgID );
	DropAbilityName3->Text = SearchObjName( DropAbility[2].OrgID );
	DropAbilityName4->Text = SearchObjName( DropAbility[3].OrgID );
	DropAbilityName5->Text = SearchObjName( DropAbility[4].OrgID );
	DropAbilityName6->Text = SearchObjName( DropAbility[5].OrgID );


}
//######################################################################################################
System::Void TreasureForm::LV_TreasureList_SelectedIndexChanged(System::Object*  sender, System::EventArgs*  e)
{
	ListView::SelectedListViewItemCollection* SelectItem = LV_TreasureList->SelectedItems;

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

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

	TB_ObjID->Text = Item->Text;
	NUD_DropRate->Value  = DotNetStr::StringToInt( Item->SubItems->Item[3]->Text );
	NUD_DropCount->Value = DotNetStr::StringToInt( Item->SubItems->Item[4]->Text );
}
System::Void TreasureForm::NewTreasureItem_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

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

	System::String* StrList[] = new System::String*[6];
	StrList[0] = TB_ObjID->Text;
//	StrList[1] = SearchObjName( DotNetStr::StringToInt( TB_ObjID->Text ) );
	StrList[1] = S"";
	StrList[2] = S"0%";
	StrList[3] = String::Format( "{0}" , __box( NUD_DropRate->Value ) );
	StrList[4] = String::Format( "{0}" , __box( NUD_DropCount->Value ) );
	StrList[5] = String::Format("{0}" , __box( LV_TreasureList->Items->Count ));
	ListViewItem*  NewListViewItem = new ListViewItem( StrList );
	LV_TreasureList->Items->Add( NewListViewItem );
	FixTreasureItemListInfo( );
	_OnValueChange = true;
}
System::Void TreasureForm::DelTreasureItem_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

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

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

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

	LV_TreasureList->Items->Remove( Item );
	FixTreasureItemListInfo( );
	_OnValueChange = true;
}
System::Void TreasureForm::DelAllTreasureItem_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

	LV_TreasureList->Items->Clear( );
	FixTreasureItemListInfo( );
	_OnValueChange = true;
}

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

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

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

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

	ListViewItem* Item = SelectItem->Item[0];
	
	Item->Text = TB_ObjID->Text;
	Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box( NUD_DropRate->Value ) );
	Item->SubItems->Item[4]->Text = String::Format( "{0}" , __box( NUD_DropCount->Value ) );
	FixTreasureItemListInfo( );
	_OnValueChange = true;
}

void	TreasureForm::FixTreasureItemListInfo( )
{
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;

	int Count = __min( LV_TreasureList->Items->Count , _MAX_TREASURE_COUNT_ );
	Treasure.ItemCount = Count;

	if( Count == 0 )
		return;

	int TotalCount = 0;
	for( int i = 1 ; i < Count ; i++ )
	{
		ListViewItem* Item = LV_TreasureList->Items->Item[i];
		
		Treasure.Item[i].OrgID = DotNetStr::StringToInt( Item->Text );
		Treasure.Item[i].DropCount = DotNetStr::StringToInt( Item->SubItems->Item[4]->Text );
		if( TotalCount <= 100000 )
		{
			Treasure.Item[i].Count = DotNetStr::StringToInt( Item->SubItems->Item[3]->Text );
		}
		else
		{
			Treasure.Item[i].Count = 0;
			Item->SubItems->Item[3]->Text = 0;
		}
		
		TotalCount += Treasure.Item[i].Count;

		if( TotalCount > 100000 )
		{
			int ExtraValue = TotalCount - 100000;
			TotalCount = 100000;
			Treasure.Item[i].Count -= ExtraValue;
			Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box(Treasure.Item[i].Count) );
		}
		float DropRate = float( Treasure.Item[i].Count) / 1000;
		Item->SubItems->Item[2]->Text = String::Format( "{0:F}%" , __box( DropRate ) );
		Item->SubItems->Item[1]->Text = SearchObjName( Treasure.Item[i].OrgID );
		Item->SubItems->Item[5]->Text = String::Format("{0}" , __box( i+1));
	}


	int ExtraValue = 100000 - TotalCount;
	ListViewItem* Item = LV_TreasureList->Items->Item[0];
	Treasure.Item[0].OrgID = DotNetStr::StringToInt( Item->Text );
	Treasure.Item[0].Count = ExtraValue;
	Treasure.Item[0].DropCount = DotNetStr::StringToInt( Item->SubItems->Item[4]->Text );
	Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box( ExtraValue ) );

	float DropRate = float( Treasure.Item[0].Count) / 1000;
	Item->SubItems->Item[2]->Text = String::Format( "{0:F}%" , __box( DropRate ) );
	Item->SubItems->Item[1]->Text = SearchObjName( Treasure.Item[0].OrgID );
}

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

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

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;
	int MaxCount = __min( LV_TreasureList->Items->Count , _MAX_TREASURE_COUNT_ );

	for( int i = 1 ; i < MaxCount ; i++ )
	{
		ListViewItem* Item = LV_TreasureList->Items->Item[i];

		Treasure.Item[i].Count = Treasure.Item[i].Count * 90 / 100;

		Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box( Treasure.Item[i].Count ) );
		Item->SubItems->Item[5]->Text = String::Format("{0}" , __box( i+1));
	}

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

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

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;
	int Count = __min( LV_TreasureList->Items->Count , _MAX_TREASURE_COUNT_ );

	for( int i = 1 ; i < Count ; i++ )
	{
		ListViewItem* Item = LV_TreasureList->Items->Item[i];

		Treasure.Item[i].Count = Treasure.Item[i].Count * 100 / 90;
		if( Treasure.Item[i].Count < 10 )
			Treasure.Item[i].Count++;

		Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box( Treasure.Item[i].Count ) );
		Item->SubItems->Item[5]->Text = String::Format("{0}" , __box( i+1));
	}

	FixTreasureItemListInfo( );
	_OnValueChange = true;
}

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

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

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

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

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

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

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		if( i == 5 )
			continue;
		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_TreasureList->SelectedIndices->Clear();
	LV_TreasureList->SelectedIndices->Add( SelectID -1 );
	_OnValueChange = true;


}
System::Void TreasureForm::Down_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CheckModifyAndCheckOut() == false )
		return;

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

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

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

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

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

	for( int i = 0 ; i < ItemDn->SubItems->Count ; i++ )
	{
		if( i == 5 )
			continue;
		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_TreasureList->SelectedIndices->Clear();
	LV_TreasureList->SelectedIndices->Add( SelectID +1 );
	_OnValueChange = true;

}

System::Void TreasureForm::SearchObj_Click(System::Object*  sender, System::EventArgs*  e)
{
	if( CB_RankBase->SelectedIndex < 0 )	
		CB_RankBase->SelectedIndex = 0;

	if( CB_RankTop->SelectedIndex < 0 )
		CB_RankTop->SelectedIndex = 0;

	String* SqlCmdStr;

	switch( TCt1_SearchObj->SelectedIndex )
	{
	case 0:		//武器
		SqlCmdStr	= String::Format( "Select GUID FROM WeaponObjectDB Where LimitLv >= {0} and LimitLv <= {1}"
							, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
							, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );

		if( CB_WeaponType->SelectedIndex > 0 )
			SqlCmdStr	= String::Format( "{0} and WeaponType = {1}" , SqlCmdStr , __box( CB_WeaponType->SelectedIndex -1  ) );

		if( CB_WeaponStandardType->SelectedIndex > 0 )
			SqlCmdStr	= String::Format( "{0} and StandardType = {1}" , SqlCmdStr , __box( CB_WeaponStandardType->SelectedIndex -1  ) );
		break;
	case 1:		//防具
		SqlCmdStr	= String::Format( "Select GUID FROM ArmorObjectDB Where LimitLv >= {0} and LimitLv <= {1}"
							, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
							, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );

		if( CB_ArmorType->SelectedIndex >0 )
			SqlCmdStr	= String::Format( "{0} and ArmorType = {1}" , SqlCmdStr , __box( CB_ArmorType->SelectedIndex -1  ) );

		if( CB_ArmorPosType->SelectedIndex >0 )
			SqlCmdStr	= String::Format( "{0} and ArmorPos = {1}" , SqlCmdStr , __box( CB_ArmorPosType->SelectedIndex -1  ) );

		if( CB_ArmorStandardType->SelectedIndex > 0 )
			SqlCmdStr	= String::Format( "{0} and StandardType = {1}" , SqlCmdStr , __box( CB_ArmorStandardType->SelectedIndex -1  ) );
		break;
	case 2:		//卡片
		SqlCmdStr	= String::Format( "Select GUID FROM CardObjectDB Where CardPriorityID >= {0} and CardPriorityID <= {1}"
			, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
			, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );
		break;

	case 3:		//符文

		SqlCmdStr	= String::Format( "Select GUID FROM RuneObjectDB Where [Level] >= {0} and [Level] <= {1}"
			, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
			, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );

		if( CB_RuneType->SelectedIndex > 0 )
			SqlCmdStr	= String::Format( "{0} and Type = {1}"
			, SqlCmdStr , __box( CB_RuneType->SelectedIndex -1 ) );
		break;
	case 4:		//道具
		SqlCmdStr	= String::Format( "Select GUID FROM ItemObjectDB Where LimitLv >= {0} and LimitLv <= {1}"
			, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
			, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );

		if( CB_WeaponType->SelectedIndex > 0 )
			SqlCmdStr	= String::Format( "{0} and ItemType = {1}" , SqlCmdStr , __box( CB_WeaponType->SelectedIndex -1  ) );

		break;
	case 5:		//附加能力
		SqlCmdStr	= String::Format( "Select GUID FROM AddPowerObjectDB Where StandardAbility_Lv >= {0} and StandardAbility_Lv <= {1}"
			, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
		break;
	case 6:		// 配方表
		{
			//		SqlCmdStr	= String::Format( "Select GUID FROM RecipeObjectDB Where StandardAbility_Lv >= {0} and StandardAbility_Lv <= {1}"
			//			, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) );
			CheckedListBox* CBox = CLB_RecipeModeFlag;

			ObjectModeStruct Mode;
			int TempMode[10];

			Mode._Mode = 0;
			Mode.Sell = 1;
			TempMode[0] = Mode._Mode;
			Mode._Mode = 0;
			Mode.Logoutdel = 1;
			TempMode[1] = Mode._Mode;
			Mode._Mode = 0;
			Mode.Expense = 1;
			TempMode[2] = Mode._Mode;
			Mode._Mode = 0;
			Mode.PickupBound = 1;
			TempMode[3] = Mode._Mode;
			Mode._Mode = 0;
			Mode.VariableRare = 1;
			TempMode[4] = Mode._Mode;

			int Flag = 0;
			for( int i = CLB_RecipeModeFlag->Items->Count - 1  ; i >= 0 ; i -- )
			{
				if( CLB_RecipeModeFlag->GetItemChecked( i ) == true )
					Flag = Flag + TempMode[ i ];
			}

			SqlCmdStr	= String::Format( "Select GUID FROM RecipeObjectDB Where RequestSkillLV >= {0} and RequestSkillLV <= {1} and  Mode&{2}={2}"
					, __box( NUD_LvBase->Value ) , __box( NUD_LVTop->Value ) , __box( Flag ) );

			SqlCmdStr	= String::Format( "{0} and Rare >= {1} and Rare <= {2} "
				, SqlCmdStr , __box( CB_RankBase->SelectedIndex ) , __box( CB_RankTop->SelectedIndex ) );

			if( CB_RecipeRequestSkill->SelectedIndex > 0 )
				SqlCmdStr	= String::Format( "{0} and RequestSkill = {1}"
					, SqlCmdStr , __box( CB_RecipeRequestSkill->SelectedIndex - 1 )  );

		}
		break;
	}

	SqlDataReader* myReader;
	sqlCommand_Base1->CommandText = SqlCmdStr ;
	myReader = sqlCommand_Base1->ExecuteReader();

	LV_SearchResult->Items->Clear();

	while( myReader->Read())
	{
		int GUID	= myReader->GetInt32( 0 );
		
		System::String* StrList[] = new System::String*[2];
		StrList[0] = String::Format("{0}" , __box( GUID ) );
		StrList[1] = SearchObjName( GUID );
		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_SearchResult->Items->Add( NewListViewItem );

	}
	myReader->Close();
}

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

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

	for( int i = 0 ; i < LV_SearchResult->Items->Count ; i++ )
	{
		ListViewItem* Item = LV_SearchResult->Items->Item[i];

		System::String* StrList[] = new System::String*[6];
		StrList[0] = Item->Text;
		StrList[1] = S"";
		StrList[2] = S"0%";
		StrList[3] = String::Format( "{0}" , __box( 1 ) );
		StrList[4] = String::Format( "{0}" , __box( 1 ) );
		StrList[5] = String::Format( "{0}" , __box( i+1 ) );
		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_TreasureList->Items->Add( NewListViewItem );
	}
	FixTreasureItemListInfo( );
	
	_OnValueChange = true;
}

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

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

	ListView::SelectedListViewItemCollection* SelectItem = LV_SearchResult->SelectedItems;
	
	for( int i = 0 ; i < SelectItem->Count ; i++ )
	{
		ListViewItem* Item = SelectItem->Item[i];

		System::String* StrList[] = new System::String*[6];
		StrList[0] = Item->Text;
		StrList[1] = S"";
		StrList[2] = S"0%";
		StrList[3] = String::Format( "{0}" , __box( 1 ) );
		StrList[4] = String::Format( "{0}" , __box( 1 ) );
		StrList[5] = String::Format( "{0}" , __box( i+1 ) );
		ListViewItem*  NewListViewItem = new ListViewItem( StrList );
		LV_TreasureList->Items->Add( NewListViewItem );
	}
	FixTreasureItemListInfo( );

	_OnValueChange = true;
}

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

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

	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
	GameTreasureStruct& Treasure = TempObj->GameData.Treasure;
	int Count = __min( LV_TreasureList->Items->Count , _MAX_TREASURE_COUNT_ );

	for( int i = 1 ; i < Count ; i++ )
	{
		ListViewItem* Item = LV_TreasureList->Items->Item[i];

		Treasure.Item[i].Count = 100000/ Count;
		Item->SubItems->Item[3]->Text = String::Format( "{0}" , __box( Treasure.Item[i].Count ) );
	}

	FixTreasureItemListInfo( );
	_OnValueChange = true;
}