#include "ScriptForm.h"
#include <fstream>
extern "C"{
	#include "lua/lua.h"
	#include "lua/lauxlib.h"
	#include "lua/lualib.h"
	#include "lua/llex.h"
	#include "lua/lfunc.h"
	#include "lua/ldo.h"
	#include "lua/lmem.h"
	#include "lua/lobject.h"
	#include "lua/lopcodes.h"
	#include "lua/lstring.h"
	#include "lua/lundump.h"
};

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

	//if( firstTime == false )
	//	return;

	//firstTime = false;

	BaseForm::OnActive();
}
void    ScriptForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_LuaScript;

    richTextBox2->ReadOnly = !LockOk;
    textBox1->ReadOnly = !LockOk;

    IsEditChangeText = false;
    IsEditChangeText_FuncName = false; 
}
void    ScriptForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_LuaScript;
}
void    ScriptForm::OnTimeProc()
{
	
    static int LStart = -1;
    if( richTextBox2->SelectionStart == LStart )
        return;

    LStart = richTextBox2->SelectionStart;
    int Count = LStart;
	int i = 0;

	DWORD lang = (DWORD)GetKeyboardLayout(GetCurrentThreadId());
	
	if (lang == 0x04040404) //英數輸入狀態才更新行號, 避免中文輸入狀態被干擾
	{
		for( i = 0 ; Count >= 0 && i < richTextBox2->Lines->Count ; i++ , Count--)
		{
			Count -= richTextBox2->Lines[i]->Length;
		}
	}
	
    statusBar1->Text = String::Format( "Line = {0}" , __box(i) );	
}
int     ScriptForm::ObjSize(  )
{
    int Size = sizeof( GameObjDbStruct );
    return Size;
}

//######################################################################################################
System::Void ScriptForm::richTextBox2_TextChanged(System::Object *  sender, System::EventArgs *  e)
{
    IsEditChangeText = true;
}

System::Void ScriptForm::richTextBox2_Leave(System::Object *  sender, System::EventArgs *  e)
{
    if( IsEditChangeText == true )
    {
        GetStr_TextChanged( sender , e );
        IsEditChangeText  = false;
    }
}
void	ScriptForm::OutputFileEx( int Language , char* WhereCmd )
{
	int     i;

	ReaderClass< DB_GameObjDbStruct >*      Reader = ObjReader( );
	map<string,ReadInfoStruct>*             ReadInfo ;
	map<string,ReadInfoStruct>::iterator    Iter;

	ReadInfo = Reader->ReadInfo();

	CreateDBCmdClass<DB_GameObjDbStruct> CreateCMD( Reader  , _DBName );
	sqlCommand_Base->CommandText = CreateCMD.GetSelectStr( WhereCmd ).c_str();
	SqlDataReader* myReader = sqlCommand_Base->ExecuteReader( );

	string	DataPathStr = Global::GetIniString( "DataPath" );

	DB_GameObjDbStruct  TempObjDB;
	DB_GameObjDbStruct __pin * TempObj = &TempObjDB;
	TempObj->Init( );
	//---------------------------------------------------------------------------------
	//總數
	//---------------------------------------------------------------------------------
	//for Lua grammar check
	lua_State* L_State;
	L_State = lua_open();

	while( myReader->Read( ) )
	{
		for(    Iter  = ReadInfo->begin() , i = 0 ; 
			Iter != ReadInfo->end() ; 
			Iter++ , i++ )
		{
			ReadInfoStruct *IDData = &(Iter->second);

			switch(IDData->Type)
			{
			case ENUM_Type_FloatPoint:
				{
					*((float*)(IDData->Point + int(TempObj))) = myReader->GetFloat( i );
				}
				break;

			case ENUM_Type_IntPoint:
				{
					*((int*)(IDData->Point + int(TempObj))) = myReader->GetInt32( i );
				}
				break;

			case ENUM_Type_ShortPoint:
				{
					*((short*)(IDData->Point + int(TempObj))) = myReader->GetInt16( i );
				}                
				break;
			case ENUM_Type_CharString:
			case ENUM_Type_TextData:
				{
					String* Str = myReader->GetString( i ) ;
					if( Str->Length != 0)
					{
						char utf8 __gc[] = Encoding::Default->GetBytes( Str );
						char __pin *CharStr = &utf8[0];
						strcpy( (char*)(IDData->Point + int(TempObj)) , CharStr );
					}
					else
					{
						strcpy( (char*)(IDData->Point + int(TempObj)) , "" );
					}

				}    
				break;
			case ENUM_Type_CharStringPoint:
			case ENUM_Type_TextDataPoint:
				{//不處理
					i--;
				}
				break;
			case ENUM_Type_TimeCharString:
				{
					DateTime TempDate = myReader->GetDateTime( i );
					String* Tt= String::Format( "{0}:{1}:{2}" 
						, __box( TempDate.get_Hour() )
						, __box( TempDate.get_Minute() )
						, __box( TempDate.get_Second() ) );

					Tt =  String::Format( "{0} {1} " , TempDate.ToString( "d" ) , Tt );
					char utf8 __gc[] = Encoding::Default->GetBytes( Tt );
					char __pin *Str = &utf8[0];
					strcpy( (char*)(IDData->Point + int(TempObj)) , Str );

				}
				break;
			}
		}   

//////////////////////////////////////////////////////////////////////////
		/*
//測試code 把旗直找出來換成新的號碼
		{
			char* ProcPoint = TempObj->ScriptInfo.Script;
			while( 1 )
			{
				ProcPoint = strstr( ProcPoint , "580" );
				if( ProcPoint == NULL )
					break;
				int Value = atol( ProcPoint );
				if( Value >= 580000 && Value < 581000 )
				{
					*ProcPoint = '7';
					ProcPoint+=6;
				}
				else
					ProcPoint+=3;				
			}

			//把資料存回資料庫
			char WhereCmd[512];
			sprintf( WhereCmd , "WHERE GUID=%d" , TempObj->GameData.GUID );
			sqlCommand_Base1->CommandText = CreateCMD.GetUpDateStr( TempObj , WhereCmd ).c_str();
			sqlCommand_Base1->ExecuteReader( )->Close();

		}
*/
//////////////////////////////////////////////////////////////////////////

		int Error = luaL_loadbuffer( L_State , TempObj->ScriptInfo.Script , strlen( TempObj->ScriptInfo.Script ) , "TEST" );

		if( Error )
		{
			char    luaName[32];
			sprintf( luaName , "Script GUID = %d" , TempObj->GameData.GUID);
			MessageBox::Show( lua_tostring( L_State , -1 ) , luaName );
			lua_pop( L_State , 1 );
			lua_close( L_State );
			myReader->Close( );

			MessageBox::Show( "輸出終止" , "警告" );

			return;
		}

		OnOuputObj(  (char*)DataPathStr.c_str() , TempObj );
	}

	lua_close( L_State );
	myReader->Close( );
}

void    ScriptForm::OutputFileLanguage( int LanguageID )
{
	//there are duplicated function name in scripts, cancel output file process
	if (!LuaFunctionNameDuplicationCheck())
	{
		MessageBox::Show( "LuaScript輸出已取消", "警告" );
		return;
	}
	
	OutputFileEx( LanguageID , "" );
}

//單一輸出
void   ScriptForm::OnOuputObj( char* Path , DB_GameObjDbStruct*  TempObjDB )
{
	char	Buf[1024];
    char    File[512];
    char*   FullPathFile;
	char	FullPath[512];
	
	sprintf( FullPath , "%s/%s" , Path , _OutputFileName );
	
	Com_CreatePath( FullPath );

    sprintf( File , "%s/%05d.lua" , _OutputFileName , TempObjDB->GameData.GUID % 10000 );
    if( Path[0] != 0 )
    {
//        sprintf( File , "LUAScript/%s.lua" , TempObjDB->ScriptInfo.Name );
        FullPathFile = CombineFilePath( Path , File );
    }
    
	/*
    std::fstream file;
    file.open( FullPathFile , ios::out  );
    if( file.is_open() == false )
    {
        sprintf( Buf , "%s 開檔失敗" ,  FullPathFile );
        MessageBox::Show( Buf , "警告" );
        return;
    }

	if( strlen( TempObjDB->ScriptInfo.Name ) != 0 )
	{
		char Buf[ 1024 ];
		sprintf( Buf , "function %s(%s)\n" , TempObjDB->ScriptInfo.Name , TempObjDB->ScriptInfo.Arg );
		file.write( Buf , strlen( Buf ) );
		file.write( TempObjDB->ScriptInfo.Script , strlen( TempObjDB->ScriptInfo.Script ) );
		sprintf( Buf , "\nend" );
		file.write( Buf , strlen( Buf ) );
	}
	else
	{
		file.write( TempObjDB->ScriptInfo.Script , strlen( TempObjDB->ScriptInfo.Script ) );
	}
	
    file.close();
	*/
	DWORD writeBytesOut = 0;

	HANDLE hFile = CreateFile( FullPathFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );

	if( hFile == INVALID_HANDLE_VALUE )
	{
		sprintf( Buf , "%s 開檔失敗" ,  FullPathFile );
		MessageBox::Show( Buf , "警告" );
		return;
	}


	//轉小寫
	const char* str;
	//if (strcmp(_OutputFileName, "CliLUAScript") == 0)	//client端script  執行轉小寫
	//{
	//	String* luacode = new String(TempObjDB->ScriptInfo.Script);
	//	luacode = luacode->ToLower();
	//	str = (const char*)(Marshal::StringToHGlobalAnsi(luacode)).ToPointer();
	//}
	//else
	//{
		str = TempObjDB->ScriptInfo.Script;
	//}

	if( strlen( TempObjDB->ScriptInfo.Name ) != 0 )
	{
		char Buf[ 1024 ];
		sprintf( Buf , "function %s(%s)\n" , TempObjDB->ScriptInfo.Name , TempObjDB->ScriptInfo.Arg );
		
		//file.write( Buf , strlen( Buf ) );
		//file.write( TempObjDB->ScriptInfo.Script , strlen( TempObjDB->ScriptInfo.Script ) );

		
		WriteFile( hFile, Buf,	strlen( Buf ),	&writeBytesOut, NULL );			
		WriteFile( hFile, str,	strlen( str ),	&writeBytesOut, NULL );	
		
		sprintf( Buf , "\nend" );
		WriteFile( hFile, Buf,	strlen( Buf ),	&writeBytesOut, NULL );			
	}
	else
	{
		//file.write( TempObjDB->ScriptInfo.Script , strlen( TempObjDB->ScriptInfo.Script ) );
		WriteFile( hFile, str,	strlen( str ),	&writeBytesOut, NULL );	
	}

	CloseHandle( hFile );



}

System::Void ScriptForm::textBox1_TextChanged(System::Object *  sender, System::EventArgs *  e)
{
    IsEditChangeText_FuncName = true;
    //GetStr_TextChanged( sender , e );
}

System::Void ScriptForm::textBox1_Leave(System::Object *  sender, System::EventArgs *  e)
{
    char Buf[512];
    int i;
    int Count;
    if( IsEditChangeText_FuncName != true )
        return;
    
	//可以設定為清空
	if( textBox1->Text->Length == 0 )
	{
		GetStr_TextChanged( sender , e );
		IsEditChangeText_FuncName = false;
		return;
	}

    SqlDataReader* myReader;
    //檢查函式名稱是否重復
    sprintf( Buf , "SELECT Count(GUID) FROM %s Where FuncName = '%s' " , _DBName , DotNetStr::StringToChar( textBox1->Text ).c_str() );
    sqlCommand_Base->CommandText = Buf;
    myReader = sqlCommand_Base->ExecuteReader();        

    if( myReader->Read( ) )
    {            
        Count = myReader->GetInt32(0);
    }

    myReader->Close();

    if( Count != 0 ) 
    {
        MessageBox::Show( "函式名稱重復,自動修正" , "警告" );
        for( i = 0 ; ; i++ )
        {
            sprintf( Buf , "SELECT Count(GUID) FROM %s Where FuncName = '%s%d' " , _DBName , DotNetStr::StringToChar( textBox1->Text ).c_str() , i );
            sqlCommand_Base->CommandText = Buf;
            myReader = sqlCommand_Base->ExecuteReader();        

            if( myReader->Read( ) )
            {            
                Count = myReader->GetInt32(0);
            }

            myReader->Close();
            if( Count == 0 )
            {
                textBox1->Text = String::Format( "{0}{1}", textBox1->Text , __box( i ) );
                break;
            }
        }
    }


    GetStr_TextChanged( sender , e );
    IsEditChangeText_FuncName   = false;
}

/*
void Lua_Hook(lua_State *L, lua_Debug *ar)
{
    
}
*/
void   ScriptForm::LuaParse( DB_GameObjDbStruct*  TempObjDB )
{
    lua_State* L_State;
    L_State = lua_open();
    int Error;


    Error = luaL_loadbuffer( L_State , TempObjDB->ScriptInfo.Script , strlen( TempObjDB->ScriptInfo.Script ) , "TEST" );

    if( Error )
    {
        MessageBox::Show( lua_tostring( L_State , -1 ) , "警告" );

        lua_pop( L_State , 1 );
    }
    else
        MessageBox::Show( "沒問題" , "訊息" );


    lua_close( L_State );
}

//return false if any function name duplicated
bool ScriptForm::LuaFunctionNameDuplicationCheck()
{
	
	typedef struct tagDupFuncInfo
	{
		int iGUID;
		int iLineNO;

		tagDupFuncInfo()
		{
			iGUID = 0;
			iLineNO = 0;
		}
	}DupFuncInfo;

	bool Result = true;

	map<string, vector<DupFuncInfo> >            map_FuncName_GUIDs;
	map<string, vector<DupFuncInfo> >::iterator  mIter;
	vector<DupFuncInfo>                          vector_DupInfos;

	SqlDataReader* myReader;

	char Buf[512];

	//select "FUNCNAME", "TEXT", "GUID" columns from database
	sprintf( Buf , "SELECT FUNCNAME,TEXT,GUID FROM %s" , _DBName);

	sqlCommand_Base->CommandText = Buf;
	myReader = sqlCommand_Base->ExecuteReader();

	String* strFuncName = "";
	String* strScriptText = "";

	int iGUID = 0;
	char utf8 __gc[];
	char __pin *CharStr;
	wchar_t newLine __gc [] = {'\n'};
	wchar_t nullStr __gc [] = {'\0'};
	//wchar_t separators __gc [] = {' ', '(', ')'};
	wchar_t separators __gc [] = {' '};


	DupFuncInfo dupFuncInfo;

	while( myReader->Read())
	{
		//read a single row
		strFuncName   = myReader->GetString(0)->Trim()->Trim(nullStr);
		strScriptText = myReader->GetString(1)->Trim()->Trim(nullStr);
		iGUID         = myReader->GetInt32(2);

		// if the value of "FUNCNAME" column is empty, try to analyze "TEXT" content
		if (strFuncName->Equals(""))
		{
			//the text is empty, process next row of record
			if (strScriptText->Length == 0)
				continue; //continue while loop

			//Split text content into lines by '\n'
			String* lines[] = strScriptText->Split(newLine);

			for (int lineCounter = 0; lineCounter < lines->Length; lineCounter++)
			{
				String* line = lines[lineCounter]->Trim();

				//this line doesn't contain "function" keyword, continue process next line
				if (line->ToLower()->IndexOf("function") < 0)
					continue;

				//Split a single line into tokens by ' ', '(', ')'
				String* tokens[] = line->Split(separators, StringSplitOptions::RemoveEmptyEntries);

				//function name exists only if there are two more tokens in line
				if (tokens->Length >= 2)
				{
					if (tokens[0]->ToLower()->Equals("function"))
					{
						String* functionName = "";

						int tmpIndex1 = tokens[1]->ToLower()->IndexOf("(");
						int tmpIndex2 = tokens[1]->ToLower()->IndexOf(")");

						//second token does not contains "(" and ")", the second token is function name
						if ((tmpIndex1 < 0) && (tmpIndex2 < 0))
						{
							functionName = tokens[1];
						}
						else if (tmpIndex1 >= 0)
						{
							functionName = tokens[1]->Substring(0, tmpIndex1)->Trim();
						}

						if (!String::IsNullOrEmpty(functionName))
						{
							//we find the function name
							utf8 = Encoding::Default->GetBytes( functionName );
							CharStr = &utf8[0];

							mIter = map_FuncName_GUIDs.find(CharStr);

							SecureZeroMemory(&dupFuncInfo, sizeof(dupFuncInfo));
							dupFuncInfo.iGUID   = iGUID;
							dupFuncInfo.iLineNO = lineCounter;

							if (mIter != map_FuncName_GUIDs.end())
							{
								// the function name is exists, record the GUID
								mIter->second.push_back(dupFuncInfo);
							}
							else
							{
								vector_DupInfos.clear();
								vector_DupInfos.push_back(dupFuncInfo);
								map_FuncName_GUIDs[CharStr] = vector_DupInfos;
							}
						}
					}
				}

				/*
				bool funcToken = false;
				for (int tokenCounter = 0; tokenCounter < tokens->Length; tokenCounter++)
				{
					String* token = tokens[tokenCounter];

					//check if current token is "function" keyword
					if (token->ToLower()->Equals("function"))
					{
						// this token is "function" keyword, next token which is none empty string is function name
						funcToken = true;
					}
					else
					{
						if (funcToken)
						{
							//we find the function name
							utf8 = Encoding::Default->GetBytes( token );
							CharStr = &utf8[0];

							mIter = map_FuncName_GUIDs.find(CharStr);

							SecureZeroMemory(&dupFuncInfo, sizeof(dupFuncInfo));
							dupFuncInfo.iGUID   = iGUID;
							dupFuncInfo.iLineNO = lineCounter;

							if (mIter != map_FuncName_GUIDs.end())
							{
								// the function name is exists, record the GUID
								mIter->second.push_back(dupFuncInfo);
							}
							else
							{
								vector_DupInfos.clear();
								vector_DupInfos.push_back(dupFuncInfo);
								map_FuncName_GUIDs[CharStr] = vector_DupInfos;
							}
							break;
						}
					}
				}
				*/
			}
		}
		else
		{
			utf8 = Encoding::Default->GetBytes( strFuncName );
			CharStr = &utf8[0];

			mIter = map_FuncName_GUIDs.find(CharStr);

			SecureZeroMemory(&dupFuncInfo, sizeof(dupFuncInfo));
			dupFuncInfo.iGUID  = iGUID;

			if (mIter != map_FuncName_GUIDs.end())
			{
				// the function name is exists, record the GUID
				mIter->second.push_back(dupFuncInfo);
			}
			else
			{
				vector_DupInfos.clear();
				vector_DupInfos.push_back(dupFuncInfo);
				map_FuncName_GUIDs[CharStr] = vector_DupInfos;
			}
		}
	}

	myReader->Close();

	StringBuilder* sb = new StringBuilder(2048);

	for (mIter = map_FuncName_GUIDs.begin(); mIter != map_FuncName_GUIDs.end(); mIter++)
	{
		vector_DupInfos.clear();
		vector_DupInfos = mIter->second;

		if (vector_DupInfos.size() > 1)
		{
			strFuncName = new String(mIter->first.c_str());

			sb->Append(String::Format("Function Name {0} duplicated at :", strFuncName));

			for (unsigned int i = 0 ; i < vector_DupInfos.size(); i++)
			{
				sb->Append("Script:");
				sb->Append(vector_DupInfos[i].iGUID);
				sb->Append(", Line:");
				sb->Append(vector_DupInfos[i].iLineNO);
				sb->Append("; ");
			}

			sb->Append("\n");

			Result = false;
		}
	}

	if (!Result)
	{
		sb->Append("\n");
		sb->Append("Press Ctrl+C to copy messagebox contents to clipboard");
		MessageBox::Show( sb->ToString() , "警告" );
	}

	return Result;
}


System::Void ScriptForm::Parse_Click(System::Object *  sender, System::EventArgs *  e)
{
    
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
    LuaParse( TempObj );
}


System::Void ScriptForm::button2_Click(System::Object *  sender, System::EventArgs *  e)
{
    /*
    panel3->Visible = false;
    int Value = DotNetStr::StringToInt( textBox2->Text ) - 1;

    char* Text = DotNetStr::StringToChar( richTextBox2->Text );
    int Line = 0;
    for( int i = 0 ; ; i++ )
    {
        if( Text[i] == 0 )
        {
            ::MessageBox( NULL , "行數過大" , "警告" , MB_OK );
            break;
        }
        if( Text[i] == '\n' )
        {
            Line++;
            if( Line == Value )
            {
//                richTextBox2->SelectionStart = i+1;
//                richTextBox2->SelectionLength = 10;
                break;
            }
        }

    }
    */
}

/*
void    ScriptForm::UpDateList( )
{
	char	Buf[256];
	int     i;
	int     SelectID = 0;

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

	switch( Index )
	{
	case 1://使用名稱
		sqlCommand_Base->CommandText = String::Format( "SELECT {0}.GUID, StringDB.Content, {0}.DataGroup FROM {0} , StringDB WHERE {0}.GUID = StringDB.OrgObjID AND StringDB.KeyStr LIKE 'Sys%[_]name' AND StringDB.Content LIKE '{1}' ORDER BY {0}.GUID" , (String*)_DBName , TB_WhereSQLCmd->Text );
		break;
	case 2://始用SQL
		sqlCommand_Base->CommandText = String::Format( "SELECT {0}.GUID, StringDB.Content, {0}.DataGroup FROM {0} , StringDB {1}" , (String*)_DBName , TB_WhereSQLCmd->Text );
		break;
	default://不使用
		sqlCommand_Base->CommandText = String::Format( "SELECT {0}.GUID, StringDB.Content, {0}.DataGroup FROM {0} , StringDB WHERE {0}.GUID = StringDB.OrgObjID AND StringDB.KeyStr LIKE 'Sys%[_]name' ORDER BY {0}.GUID" , (String*)_DBName  );
		break;
	}


	SqlDataReader* myReader = sqlCommand_Base->ExecuteReader();

	_ObjList->clear();
	LB_ObjList->Items->Clear();
	while( myReader->Read())
	{
		DB_GameObjDbIndexStruct Temp;
		Temp.GUID = myReader->GetInt32( 0 );

		String* Str =  myReader->GetString( 1 ) ;
		strcpy( Temp.Name , DotNetStr::StringToChar( Str ) );
		Str =  myReader->GetString( 2 ) ;
		strcpy( Temp.FuncName , DotNetStr::StringToChar( Str ) );

		_ObjList->push_back( Temp );
	}
	myReader->Close();

	LB_ObjList->BeginUpdate();
	switch( CB_ShowTitleSet->SelectedIndex )
	{
	case 1:
		{
			for ( i = 0 ; i < (int)_ObjList->size() ; i++ )
			{
				sprintf( Buf , "%03d %s", (*_ObjList)[i].GUID % 10000 , (*_ObjList)[i].FuncName );
				String* Str = Buf;

				LB_ObjList->Items->Add( Str );

				if( (*_ObjList)[i].GUID == _ObjGUID )
					SelectID = i;
			}
			break;
		}
	case 2:
		{
			for ( i = 0 ; i < (int)_ObjList->size() ; i++ )
			{				
				sprintf( Buf , "%03d %-32s %s", (*_ObjList)[i].GUID % 10000 , (*_ObjList)[i].FuncName  , (*_ObjList)[i].Name );
				String* Str = Buf;
				LB_ObjList->Items->Add( Str );

				if( (*_ObjList)[i].GUID == _ObjGUID )
					SelectID = i;
			}
			break;
		}
	default:
		{
			for ( i = 0 ; i < (int)_ObjList->size() ; i++ )
			{
				sprintf( Buf , "%03d %s", (*_ObjList)[i].GUID % 10000 , (*_ObjList)[i].Name );
				String* Str = Buf;

				LB_ObjList->Items->Add( Str );

				if( (*_ObjList)[i].GUID == _ObjGUID )
					SelectID = i;
			}
			break;
		}
	}

	if( _ObjList->size() != 0 )
		LB_ObjList->SelectedIndex  = SelectID;
	LB_ObjList->EndUpdate();

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

*/

System::Void ScriptForm::OutputOneFile_Click(System::Object*  sender, System::EventArgs*  e)
{
	char Buf[512];
	sprintf( Buf , "WHERE GUID =%d" , _ObjGUID );
	OutputFileEx( 0 , Buf );
}

