#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here
//#include <..\originlab\Import_Utils.h>
#include <..\originlab\fu_utils.h>
#include <..\originlab\CSVFile.h>
#include <GetNBox.h>
#include <..\originlab\theme_utils.h>
/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
#define	CSV_SPEED_UP_USING_IMPORTASCII
#ifdef	CSV_SPEED_UP_USING_IMPORTASCII
	#include <..\originlab\AscImpOptions.h>
#endif	//CSV_SPEED_UP_USING_IMPORTASCII	
/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII

///////////////////////////////////////////////////////////////////////
//////// modification log
/// Hong 03/12/07 QA80-9418-S1 ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
/// Sim 03-19-2007 ADD_OPTION_TO_PARTIAL_COLUMN
/// Sim 03-20-2007 FIX_APPEND_COMMENT_WHEN_REIMPORT
/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
/// Hong 03/30/07 v8.0593 ADD_HEADER_LINE_OPTION
/// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
/// Sim 04-12-2007 IMPROVE_CSV_OPTIONS
/// Sim 04-12-2007 GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
/// Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
/// Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
/// Sim 05-18-2007 REMOVE_UID_VARIABLE
/// Sim 06-21-2007 QA80-9288-P9 DISALLOW_CHANGE_HEADER_SETTING_WHEN_REPEAT_IMPORT
/// Sim 06-25-2007 UPDATE_ORGANIZER
/// Hong 09/07/07 v8.0698b ADD_MAIN_HEADER_LINE_TO_SKIP_DATA
/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
/// Hong 07/15/08 v8.0901c FIX_1ST_IMPORT_MODE_FAIL
/// Hong 07/23/08 v8.0907 IMPROVE_IMPORT_ERROR_MSG
/// Hong 07/31/08 QA80-11920 SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR
/// CPY 11/06/08 CSV_IMPORT_FAILED_WHEN_FILE_ALREADY_OPEN_IN_EXCEL
/// Sim 11-19-2008 QA80-12604 ADD_AUTO_RESIZE_CELL_IMPORT_OPTION
/// Sim 12-31-2008 QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE
/// Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
/// Hong 06/05/09 CORRECT_MEANING_FOR_CELL_SEPARATOR
/// Hong 08/20/09 QA80-10260 FIX_FAIL_CORRECTLY_IMPORT_MULTILINES_IN_ONE_CELL_CSV_FILE_CREATED_IN_MAC
/// Hong 08/24/09 QA80-11920 IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
/// Hong 08/31/09 QA80-12899 IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE
/// Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
///////////////////////////////////////////////////////////////////////

//put your own support static functions here

#define CSV_1ST_FILE_IMPORT_MODE_LIST 	LIST_IMPORT_MODE_REPLACE_BOOK_SHEET_COLUMN ///---Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
#define CSV_IMPORT_MODE_LIST	(CSV_1ST_FILE_IMPORT_MODE_LIST & (~IW_FLAG_IMPMODE_REPLACE)) ///---Sim 05-08-2007 REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE

#define STR_NODE_NODE_DATE_FORMAT "DateFormat" ///---Sim 12-31-2008 QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE

#define STR_NODE_KEEP_DEST_COL_FMT	"KeepDestColFmt" /// Hong 08/31/09 QA80-12899 IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE

///Cheney 2007-1-17 ADD_FILTER
static bool s_bFileValid = true;
static bool s_bRangeValid = true;
#define OK_SURE(_OK_ENABLE) _OK_ENABLE = (s_bFileValid && s_bRangeValid);

static BOOL _construct_tree_setting(StringArray& vsFileNames, TreeNode& trInfo)
{
	int nCount = vsFileNames.GetSize();
	string strFileName, strTag, strInfo;
	if ( trInfo )
		trInfo.RemoveChildrenWithPrefix();
	
	GETN_USE(trInfo)
	for ( int nIndex = 0; nIndex < nCount; nIndex++ )
	{
		strFileName = vsFileNames[nIndex];
		if ( !strFileName.IsFile() )
			return false;

		strTag.Format("file%d", nIndex+1);
		strInfo.Format("File Size: %s ", GetFileSize(strFileName));
		GETN_STR(strTag, GetFileName(strFileName, false), strInfo )
		GETN_READ_ONLY
	}
	return true;
}

static bool _file_name_event(TreeNode& trGetN, string& strErrMsg)
{
	string strFileName = trGetN.fname.strVal;
	TreeNode trNode = trGetN.trfiles;
	
	trNode.RemoveChildrenWithPrefix();
	
	if (!check_imported_file_name(strFileName, strErrMsg))
		return false;
	
	StringArray vsFileNames;
	separate_multiline_files(strFileName, vsFileNames);
	if ( !_construct_tree_setting(vsFileNames, trNode) )
	{
		// clean the info on GUI
		trNode.RemoveChildrenWithPrefix();
		strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
		return false;
	}
	
	return true;
}
///end ADD_FILTER

/// Hong 03/30/07 v8.0593 ADD_HEADER_LINE_OPTION
///---Sim 04-12-2007 GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
static bool check_enable_header_setting(TreeNode& trn)
{
	if( !trn )
		return false;

	int nHeaderLines = trn.SubHeaderLines.nVal;
	if ( nHeaderLines <= 0  )
	{	// disable all header setting
		tree_set_attribute_to_all_nodes(trn, "Enable", "0");
		trn.Enable = 1;
		trn.SubHeaderLines.Enable = 1;
		trn.MainHdrLns.Enable = 1; /// Hong 09/07/07 v8.0698b ADD_MAIN_HEADER_LINE_TO_SKIP_DATA
	}
	else // nHeaderLines > 0
	{	// enable all header setting
		tree_set_attribute_to_all_nodes(trn, "Enable", "1");

		check_enable_comments_to(trn);
		check_enable_parameters_to(trn);
		check_enable_user_parameters_to(trn);
	}
	return true;
}
///---END GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
static bool check_enable_comments_to(TreeNode& trn)
{
	if( !trn )
		return false;

	int nLine = atoi(trn.CommentsFrom.strVal);
	trn.CommentsTo.Enable = (trn.CommentsFrom.Enable && nLine > 0);
	return true;
}

static bool check_enable_parameters_to(TreeNode& trn)
{
	if( !trn )
		return false;

	int nLine = atoi(trn.ParamsFrom.strVal);
	trn.ParamsTo.Enable = (trn.ParamsFrom.Enable && nLine > 0);
	return true;
}

static bool check_enable_user_parameters_to(TreeNode& trn)
{
	if( !trn )
		return false;

	int nLine = atoi(trn.UserParamsFrom.strVal);
	trn.UserParamsTo.Enable = (trn.UserParamsFrom.Enable && nLine > 0);
	return true;
}

///---Sim 04-12-2007 GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
static bool OnChangeSubheaderLines(TreeNode& tr, int nRow, int nCol, TreeNode& trNode, DWORD nEventInfo, int nCntrlType, WndContainer& getNContainer)
{
	return check_enable_header_setting(trNode.Parent());
}
///---END GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
static bool OnChangeCommentsFrom(TreeNode& tr, int nRow, int nCol, TreeNode& trNode, DWORD nEventInfo, int nCntrlType, WndContainer& getNContainer)
{
	return check_enable_comments_to(trNode.Parent());
}

static bool OnChangeParametersFrom(TreeNode& tr, int nRow, int nCol, TreeNode& trNode, DWORD nEventInfo, int nCntrlType, WndContainer& getNContainer)
{
	return check_enable_parameters_to(trNode.Parent());
}

static bool OnChangeUserParametersFrom(TreeNode& tr, int nRow, int nCol, TreeNode& trNode, DWORD nEventInfo, int nCntrlType, WndContainer& getNContainer)
{
	return check_enable_user_parameters_to(trNode.Parent());
}
/// end ADD_HEADER_LINE_OPTION

/// Hong 08/24/09 QA80-11920 IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
///------ Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
//static bool _is_comma_decimal_separator(TreeNode& trDecimal)
static bool _is_comma_decimal_separator(TreeNode& trDecimal, LPCSTR lpcszFile)
///------ End FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
{
	BOOL		bComma;
	switch ( trDecimal.nVal )
	{
	case 0:
		bComma = true;
		break;
	case 1:
		bComma = false;
		break;
	case 2:
	{
		///------ Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
		if ( is_builtin_sample_file(lpcszFile) )
		{
			bComma = true;
		}
		else
		///------ End FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
		{
			int		nNumSep = okutil_get_numeric_format();
			bComma = (NF_IS_EUROPEAN == nNumSep || NF_IS_FRENCH == nNumSep) ? false : true;
		}
	}
		break;
	default:
		bComma = true;
		break;
	}
	return bComma;
}
/// end IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT

/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
///------ Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
//static void _get_ascii_structure_from_csv_options(ASCIMP& ascImp, const TreeNode& options, int nFileIndex)
static void _get_ascii_structure_from_csv_options(ASCIMP& ascImp, const TreeNode& options, int nFileIndex, LPCSTR lpcszFile)
///------ End FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
{
	ASSERT(options);
	Tree		trAscOption;
	construct_ascii_import_options(trAscOption, false);
	tree_copy_values_by_id(options, trAscOption);
	fuSetInt(trAscOption, IDE_ASCIMP_AUTOSUBHEAD, 0);
	// XF partial options do NOT share the same DataID as ascii
	fuSetInt(trAscOption, IDE_ASCIMP_PARTIAL, fuGetPartialImport(options));
	fuSetInt(trAscOption, IDE_ASCIMP_PARTIALC1, fuGetColStartPoint(options));
	fuSetInt(trAscOption, IDE_ASCIMP_PARTIALC2, fuGetColEndPoint(options));
	fuSetInt(trAscOption, IDE_ASCIMP_PARTIALR1, fuGetStartPoint(options));
	fuSetInt(trAscOption, IDE_ASCIMP_PARTIALR2, fuGetEndPoint(options));
	fuSetInt(trAscOption, IDE_ASCIMP_READROWS, fuGetReadPoint(options));
	fuSetInt(trAscOption, IDE_ASCIMP_SKIPROWS, fuGetSkipPoint(options));		
	/// Hong 07/15/08 v8.0901c FIX_1ST_IMPORT_MODE_FAIL
	if ( 0 == nFileIndex )		
	{
		fuSetImportMode(trAscOption, fuGet1stImportMode(options));
	}
	/// end FIX_1ST_IMPORT_MODE_FAIL
	
	Tree 		trAsciiFilter;
	fuPrepareDefault(trAsciiFilter, FILTER_TYPE_ASCII);	
	OptionsToFilter(trAscOption, trAsciiFilter);
	fuDisableAllRename(trAsciiFilter);		
	fuSetAllowAllTextData(trAsciiFilter, 1);		
	/// Hong 07/15/08 v8.0901c FIX_1ST_IMPORT_MODE_FAIL
	/*
	if ( 1 == nFileIndex )		
	{
		fuSetImportMode(trAsciiFilter, fuGet1stImportMode(trAsciiFilter));
	}
	*/
	/// end FIX_1ST_IMPORT_MODE_FAIL	
	fuGetASCIMP(trAsciiFilter, ascImp);
	ascImp.iDelimited = 1;
	/// Hong 07/31/08 QA80-11920 SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR	
	//ascImp.iDelimiter = ASCIMP_DELIM_COMMA;	
	ASSERT(options.decimal);
	/// Hong 08/24/09 QA80-11920 IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
	//bool		bCommaDecimalSeparator = 0 == options.decimal.nVal ? true : false;
	///------ Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
	//bool		bCommaDecimalSeparator = _is_comma_decimal_separator(options.decimal);
	bool		bCommaDecimalSeparator = _is_comma_decimal_separator(options.decimal, lpcszFile);
	///------ End FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
	/// end IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
	ascImp.nNumSep = bCommaDecimalSeparator ? NF_IS_AMERICAN : NF_IS_EUROPEAN;
	ascImp.iDelimiter = bCommaDecimalSeparator ? ASCIMP_DELIM_COMMA : ASCIMP_DELIM_DEMICOLON; // I try with Excel, and find it use demicolon as new cell separator once comma is used as numeric separator, but we can replace it with ASCIMP_DELIM_UNKNOWN once exception appear
	/// end SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR
	ascImp.cQuote = '\"';
	ascImp.flags |= AI_FLAG_REMOVE_QUOTES;
	ascImp.iNonnumeric = 1; // NONNUMERIC_READ_AS_MISSING
	/// Hong 07/31/08 QA80-11920 SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR	
	//ascImp.nNumSep = NF_IS_AMERICAN; // need more check
	/// end SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR	
	///---Sim 12-31-2008 QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE
	TreeNode trDateFormat = options.GetNode(STR_NODE_NODE_DATE_FORMAT);
	if ( trDateFormat )
	{
		if ( strlen(trDateFormat.strVal) < MAX_SIZE_CUSTOM_FORMAT )
		{
			///Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
			//strcpy(ascImp.szDateFormat, trDateFormat.strVal);
			strncpy(ascImp.szDateFormat, NONE2EMPTY(trDateFormat.strVal), MAX_SIZE_CUSTOM_FORMAT);
			///End CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
		}
	}
	///---END QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE
	/// Hong 08/31/09 QA80-12899 IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE
	TreeNode	trKeepDestColFmt = options.GetNode(STR_NODE_KEEP_DEST_COL_FMT);
	if ( trKeepDestColFmt && 1 == trKeepDestColFmt.nVal )
	{
		// the same as ImpWiz::Execute
		ascImp.flags |= AI_FLAG_KEEP_TARGET_SHEET_COL_FORMAT;
		ascImp.iAutoColTypes = 0;
	}
	/// end IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE
}
/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII


void impCSV(const string& fname, const TreeNode& trfiles, const TreeNode& options, Range& orng, TreeNode& trheader, const int& reimp)
{
	
	//vector vImportedRangeUID; ///---Sim 02-06-2007 GET_RANGE_UID_OF_IMPORTED_FILE ///---Sim 05-18-2007 REMOVE_UID_VARIABLE remove
	
	int c1,c2; 
	Datasheet ds;
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//orng.GetRange(ds, c1, c2);
	Page pgTarget;
	if ( !GetRangeInfo(orng, ds, pgTarget, c1, c2) )
		XF_THROW(XFERR_INVALID_RANGE);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	Worksheet ws = ds;
	if ( !ws )
		XF_THROW(CER_INVALID_WKS);
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//Page pgTarget;
	//ws.GetParent(pgTarget);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	
	///---Sim 03-09-2007 TEMP_FIX_HIGHLINE_REPLACE_DATA
	if ( !reimp )
	{
		/// Hong 09/08/07 v8.0698b FIX_FAIL_DUMP_OUTPUT_RANGE_ORNG
		/*
		if ( orng )
		{
			/// Hong 09/07/07 v8.0698b FIX_OUTPUT_VARIABLE_ORNG_FAIL_DUMP
			//orng.Reset();
			//orng.Add(ws, 0);
			orng.SetRange(0, ws, 0, 0, -1, 0);
			/// end FIX_OUTPUT_VARIABLE_ORNG_FAIL_DUMP
		}
		*/
		reset_range_to_first_obj(orng, ws);
		/// end FIX_FAIL_DUMP_OUTPUT_RANGE_ORNG
	}
	///---END TEMP_FIX_HIGHLINE_REPLACE_DATA
	
	Tree trBaseInfo; 
	//if ( finfo )
		//trBaseInfo = finfo;
	TreeNode tnUsingFilter; // filter is none
	///Cheney 2007-1-17 ADD_FILTER
	//support default filter is empty
	double dDefault = 0.;
	if ( fuGetDouble(options, IDE_DISP_IMP_ORIGINVER, dDefault) )
		tnUsingFilter = options;
	///end ADD_FILTER
	
	///---Sim 01-30-2007 CONVERT_IMPORT_MODE_FROM_GUI_LIST_TO_FILTER
	//TreeNode trImportMode = tree_get_node_by_id(tnUsingFilter, IDE_IMP_IMPORTMODE, true);
	//if ( trImportMode )
	//{
		//int nImportMode = trImportMode.nVal;
		//trImportMode.nVal = getImportModeFromListIndex(nImportMode, CSV_IMPORT_MODE_LIST);
	//}
	int nFileImportMode = fuGetImportMode(tnUsingFilter);
	
	/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	#ifndef	CSV_SPEED_UP_USING_IMPORTASCII
	/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	///---Sim 03-19-2007 ADD_OPTION_TO_PARTIAL_COLUMN
	int nColFrom = 0, nColTo = -1, nRowFrom = 0, nRowTo = -1;
	bool bPartialImport = fuGetPartialImport(tnUsingFilter);
	if ( bPartialImport )
	{
		nColFrom = fuGetColStartPoint(tnUsingFilter) - 1;
		nColTo = fuGetColEndPoint(tnUsingFilter) - 1;
		nRowFrom = fuGetStartPoint(tnUsingFilter) - 1;
		nRowTo = fuGetEndPoint(tnUsingFilter) - 1;
	}
	///---END ADD_OPTION_TO_PARTIAL_COLUMN
	///---END CONVERT_IMPORT_MODE_FROM_GUI_LIST_TO_FILTER
	/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	#endif	//CSV_SPEED_UP_USING_IMPORTASCII
	/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	
	StringArray vsFileNames;
	separate_multiline_files(fname, vsFileNames);
	int nFileCount = vsFileNames.GetSize();
	if ( nFileCount <= 0 )
		XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
	
	int nC1, nC2, nR1;
	int nIndexLayer = ws.GetIndex();
	for (int nFileIndex = 0; nFileIndex < nFileCount; nFileIndex++ )
	{
		///---Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		//if ( 0 == nFileIndex && !reimp )
		//{
			//int nImportMode = get_first_file_import_mode(FILE_TYPE_CSV);
			//TreeNode trInValid;
			//
			//ws = GetTargetLayer(pgTarget, nIndexLayer, nFileIndex, trInValid, true, orng, nImportMode, nC1);
		//}
		//else
		//{
		ws = GetTargetLayer(pgTarget, nIndexLayer, nFileIndex, tnUsingFilter, true, orng, nFileImportMode, nC1);
		//}
		///---END TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		nR1 = 0;
		
		//Tree trInfo;
		//trInfo.Replace(trBaseInfo);
		string strFileTag;
		strFileTag.Format("File%d", nFileIndex + 1); // file index to be 1
		TreeNode trInfo = trBaseInfo.AddNode(strFileTag);
	/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	#ifndef	CSV_SPEED_UP_USING_IMPORTASCII
	/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
		CSVFile csvFile;
		/// Hong 03/30/07 v8.0593 ADD_HEADER_LINE_OPTION
		//int nRet = csvFile.Import(vsFileNames[nFileIndex], ws, trInfo, nC1, nR1, nColFrom, nColTo, nRowFrom, nRowTo);
		/// Hong 09/03/07 v8.0694 ALLOW_USER_SPECIFY_EXSCAPE_CHARACTER
		//int nRet = csvFile.Import(vsFileNames[nFileIndex], ws, trInfo, nC1, nR1, nColFrom, nColTo, nRowFrom, nRowTo, options.HeaderLines);
		int nRet = csvFile.Import(vsFileNames[nFileIndex], ws, trInfo, nC1, nR1, nColFrom, nColTo, nRowFrom, nRowTo, options.HeaderLines, options.escape.nVal);
		/// end ALLOW_USER_SPECIFY_EXSCAPE_CHARACTER
		/// end ADD_HEADER_LINE_OPTION
		if ( nRet )
		{
			XF_THROW_EX(nRet, vsFileNames[nFileIndex]);
		}
		
		///---Sim 03-19-2007 ADD_OPTION_TO_PARTIAL_COLUMN
		///---Sim 02-28-2007 QA80-9391 IMPORT_FILE_SKIP_DATA_POINTS
		// temporary code, later will be put into CSVFile class
		if ( bPartialImport )
		{
			csvFile.GetDataRange().GetRange(ds, nC1, nC2);
			int nSkip = 0, nRead = 1;
			nSkip = fuGetSkipPoint(tnUsingFilter);
			if ( nSkip > 0 )
				nRead = fuGetReadPoint(tnUsingFilter);
			
			//reduce_data(ws, nC1, nC2, tnUsingFilter);			
			reduce_data(ws, nC1, nC2, nSkip, 0, -1, nRead);
		}
		/////---END QA80-9391 IMPORT_FILE_SKIP_DATA_POINTS
		///---END ADD_OPTION_TO_PARTIAL_COLUMN
	/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
		DataRange	drImport;
		drImport = csvFile.GetDataRange();
		/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	/// Hong 07/10/08 QA80-11785 v8.0899 SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
	#else	//CSV_SPEED_UP_USING_IMPORTASCII				
		ASCIMP		ascImp;
		///------ Folger 10/21/09 QA81-14506 FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
		//_get_ascii_structure_from_csv_options(ascImp, options, nFileIndex);
		_get_ascii_structure_from_csv_options(ascImp, options, nFileIndex, vsFileNames[nFileIndex]);
		///------ End FAILS_TO_IMPORT_CSV_FILE_IN_SAMPLES_FOLDER_UNDER_GOS_BY_DEFAULT
		
		
		ASCIMPRESULT	ascImpResult;
		/// Hong 08/20/09 QA80-10260 FIX_FAIL_CORRECTLY_IMPORT_MULTILINES_IN_ONE_CELL_CSV_FILE_CREATED_IN_MAC
		/*
		DWORD			dwAscImpCtrl = IMPASC_NOT_SAVE_STORAGE_INFO;
		stdioFileInfo 	fInfo;
		stdioFile		stdio;
		switch ( options.escape.nVal )
		{
		case ESCAPE_CHARACTER_FMT_AUTO:	
			//---- CPY 11/06/08 CSV_IMPORT_FAILED_WHEN_FILE_ALREADY_OPEN_IN_EXCEL
			//if ( !stdio.Open(vsFileNames[nFileIndex], file::modeRead | file::typeBinary) )
			if ( !stdio.Open(vsFileNames[nFileIndex], file::modeRead | file::typeBinary | file::shareDenyNone) )
			//----
				XF_THROW_EX(IMPERR_FAILED_OPEN, vsFileNames[nFileIndex]);
			
			stdio.Scan(1000, &fInfo);
			stdio.Close();
			if ( fInfo.nLF < fInfo.nCRLF)
				dwAscImpCtrl |= IMPASC_EOL_CRLF_ONLY;			
			break;
		case ESCAPE_CHARACTER_FMT_DOS:
			dwAscImpCtrl |= IMPASC_EOL_CRLF_ONLY;
			break;
		case ESCAPE_CHARACTER_FMT_OTHERS:
		default:
			break;
		}
		int			nRet = ws.ImportASCII(vsFileNames[nFileIndex], ascImp, &ascImpResult, NULL, dwAscImpCtrl);
		*/
		DWORD			dwAscImpCtrl = IMPASC_NOT_SAVE_STORAGE_INFO | IMPASC_SKIP_QUOTED_EOL;
		int			nRet = ws.ImportASCII(vsFileNames[nFileIndex], ascImp, &ascImpResult, NULL, dwAscImpCtrl);
		/// end FIX_FAIL_CORRECTLY_IMPORT_MULTILINES_IN_ONE_CELL_CSV_FILE_CREATED_IN_MAC
		if ( nRet )
		{
			/// Hong 07/23/08 v8.0907 IMPROVE_IMPORT_ERROR_MSG
			// maybe need more precise error message
			//XF_THROW_EX(nRet, vsFileNames[nFileIndex]);
			int			nID;
			string 		str;
			switch( nRet )
			{
			case ERR_WKS_COL_LOCKED:
				nID = XFERR_WORKSHEET_HAS_COL_LOCKED;
				break;			
			default:
				nID = IMPERR_INVALID_FILE;
				str = GetFileName(vsFileNames[nFileIndex]);
				break;
			}
			XF_THROW_EX(nID, str);
			/// end IMPROVE_IMPORT_ERROR_MSG
		}
		DataRange	drImport;
		drImport = (DataRange)Project.GetObject(ascImpResult.uid);
		if ( !drImport.IsValid() )
			drImport.Add(ws, ascImpResult.nC1, "Range", ascImpResult.nC1 + ascImpResult.nC2);
	
		///Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
		update_custom_date_format_last_used(ascImp.szDateFormat);
		///End CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
	#endif	//CSV_SPEED_UP_USING_IMPORTASCII
	/// end SPEED_UP_CSV_IMPORT_USING_IMPORTASCII
		
		// rename 
		///---Sim 03-20-2007 FIX_APPEND_COMMENT_WHEN_REIMPORT
		DWORD dwCtrl = 0;
		dwCtrl |= (reimp) ? COVER_LAST_ADDED_COMMENT : 0;
		setPageAndLayerName(drImport, vsFileNames[nFileIndex], tnUsingFilter, dwCtrl);
		///---END FIX_APPEND_COMMENT_WHEN_REIMPORT
		
		// add data range info
		Tree trDataRange;
		///---Sim 05-18-2007 REMOVE_UID_VARIABLE
		//int UID = getRangeInfo(trDataRange, csvFile.GetDataRange());
		getRangeInfo(trDataRange, drImport);
		//vImportedRangeUID.Add(UID);
		///---END REMOVE_UID_VARIABLE
		
		// if current file cover existing file data, need update info of that files
		if ( !reimp )
			impinfo_UpdateExistingData(pgTarget, drImport);
		/// Hong 03/12/07 QA80-9418-S1 ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
		//impinfo_AddFile(ws, vsFileNames[nFileIndex], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange);
		impinfo_AddFile(ws, vsFileNames[nFileIndex], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange, reimp);
		/// end ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
	}
	//refresh_organizer_gui(pgTarget); ///---Sim 06-25-2007 UPDATE_ORGANIZER
	///---Sim 05-18-2007 REMOVE_UID_VARIABLE
	//if ( uid )
		//uid = vImportedRangeUID;
	///---END REMOVE_UID_VARIABLE
	if ( trheader )
		trheader.Replace(trBaseInfo.Clone(), true, true);
	
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int impCSV_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return impCSV_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	///Cheney 2007-1-17 ADD_FILTER
	OK_SURE(bOKEnable);
	
	///Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
	if(GETNE_ON_INIT == nEventID)
	{
		TreeNode trDateFormat = trGetN.options.GetNode(STR_NODE_NODE_DATE_FORMAT);
		if(trDateFormat)
		{
			update_custom_date_format_combo_attrib(trDateFormat);
			trDateFormat.strVal = EMPTY2NONE(trDateFormat.strVal);
		}
	}
	///End CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
	///support D&D show Dlg, if trFiles no child, should construct it
	if ( (GETNE_ON_INIT == nEventID && trGetN.trfiles.Children.Count() == 0) || GETNE_ON_THEME == nEventID )
	{
		s_bFileValid = _file_name_event(trGetN, strErrMsg);
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = CER_INVALID_PAGE;
		
		OK_SURE(bOKEnable);	
		return true;
	}
	//check file name if is invalid
	if ( 0 == lstrcmp(lpcszNodeName, "fname") )
	{
		s_bFileValid = _file_name_event(trGetN, strErrMsg);
		OK_SURE(bOKEnable);
		return true;
	}
	
	//check range if is invalid
	if( 0 == lstrcmp(lpcszNodeName, "orng") )
	{
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = CER_INVALID_PAGE;
		
		OK_SURE(bOKEnable);
		return true;
	}
	return false;
	///end ADD_FILTER

}

int impCSV_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	
	///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT
	if ( 0 == strcmp(lpcszVarName, "options") )
	{
		///---Sim 11-19-2008 QA80-12604 ADD_AUTO_RESIZE_CELL_IMPORT_OPTION
		//constructOptionsForXF(tr, true, true, false, false, true, true, true, true); ///---Sim 03-19-2007 ADD_OPTION_TO_PARTIAL_COLUMN
		DWORD dwCntrl =
			FILTER_OPTIONS_AUTO_RENAME
		 |	FILTER_OPTIONS_IMPORT_MODE
		 |	FILTER_OPTIONS_TEMPLATE
		 |	FILTER_OPTIONS_SKIP_POINTS
		 |	FILTER_OPTIONS_COL_PARTIAL
		 |	FILTER_OPTIONS_READ_ROW
		 |	FILTER_OPTIONS_AUTO_SIZE;
		constructOptionsForXF(tr, dwCntrl);
		///---END QA80-12604 ADD_AUTO_RESIZE_CELL_IMPORT_OPTION
		
		/// Hong 07/31/08 QA80-11920 SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR
		TreeNode	trDecimal = tr.InsertNode(tr.FirstNode, "decimal", TRGP_ENUM_LIST);
		trDecimal.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(2));
		/// Hong 06/05/09 CORRECT_MEANING_FOR_CELL_SEPARATOR
		// Hong, it's too dangrous to change tagName, so just correct the label for safe
		//trDecimal.SetAttribute(STR_LABEL_ATTRIB, _L("Decimal Separator"));
		trDecimal.SetAttribute(STR_LABEL_ATTRIB, _L("Delimiter"));
		/// end CORRECT_MEANING_FOR_CELL_SEPARATOR
		/// Hong 08/24/09 QA80-11920 IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
		//trDecimal.SetAttribute(STR_COMBO_ATTRIB, _L("Comma|Semicolon"));
		//trDecimal.nVal = 0;
		trDecimal.SetAttribute(STR_COMBO_ATTRIB, _L("Comma|Semicolon|Auto"));
		trDecimal.nVal = 2;
		/// end IMP_CSV_SUPPORT_AUTO_DETECTED_SEPARATOR_BY_DEFAULT
		/// end SUPPORT_CSV_FILE_USING_COMMA_AS_NUMERIC_SEPARATOR
		
		/// Hong 09/03/07 v8.0694 ALLOW_USER_SPECIFY_EXSCAPE_CHARACTER
		/// Hong 09/07/07 v8.0698b SUPPORT_THEME
		//TreeNode trEscape = tr.InsertNode(tr.FirstNode, "escape");
		//trEscape.ID = TRGP_ENUM_LIST;
		TreeNode trEscape = tr.InsertNode(tr.FirstNode, "escape", TRGP_ENUM_LIST);
		trEscape.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(1));
		/// end 
		trEscape.nVal = 0;
		trEscape.SetAttribute(STR_COMBO_ATTRIB, _L("Auto|CRLF (DOS/Windows)|LF (Unix, Mac)"));
		trEscape.SetAttribute(STR_LABEL_ATTRIB, _L("End of Line(EOL)"));
		/// Hong 08/20/09 QA80-10260 FIX_FAIL_CORRECTLY_IMPORT_MULTILINES_IN_ONE_CELL_CSV_FILE_CREATED_IN_MAC
		// NOT used anymore, hide it for backward-compatible
		trEscape.Show = 0;
		/// end FIX_FAIL_CORRECTLY_IMPORT_MULTILINES_IN_ONE_CELL_CSV_FILE_CREATED_IN_MAC
		/// end ALLOW_USER_SPECIFY_EXSCAPE_CHARACTER
		
		///---Sim 04-12-2007 IMPROVE_CSV_OPTIONS
		//get partial import branch node
		TreeNode trPartialImport = tree_get_node_by_id(tr, IDE_XFIMP_PARTIAL_IMPORT, true);
		trPartialImport = trPartialImport.Parent();
	
		// insert headerlines above to partial import
		TreeNode trHeaderLines = tr.InsertNode(trPartialImport, "HeaderLines");
		trHeaderLines.SetAttribute(STR_LABEL_ATTRIB, _L("Header Lines"));	/// Max 07-11-09 add label
		/// Hong 03/30/07 v8.0593 ADD_HEADER_LINE_OPTION
		//GETN_USE( tr )
		//GETN_BEGIN_BRANCH(HeaderLines, _L("Header Lines"))
		GETN_USE(trHeaderLines)
		///---END IMPROVE_CSV_OPTIONS
			/// Hong 09/07/07 v8.0698b ADD_MAIN_HEADER_LINE_TO_SKIP_DATA
			GETN_NUM(MainHdrLns, _L("Number of Main Header Lines (exclude subheader lines)"), 0)
				GETN_ID(IDE_ASCIMP_HEADLINES) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME				
			/// end ADD_MAIN_HEADER_LINE_TO_SKIP_DATA
			GETN_NUM(SubHeaderLines, _L("Number of Subheader Lines"), 0)
				GETN_ID(IDE_ASCIMP_SUBHEADLINES) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				GETN_OPTION_EVENT_EX(OnChangeSubheaderLines) ///---Sim 04-12-2007 GRAY_OUT_HEADER_SETTING_WHEN_NO_HEADER
		
			GETN_COMBO(ShortNames, _L("Short Names"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_RENAMECOLS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				
			GETN_COMBO(LongNames, _L("Long Names"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_LONGNAMES) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				
			GETN_COMBO(Units, _L("Units"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_UNITS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				
			GETN_COMBO(CommentsFrom, _L("Comments From"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_LABEL) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				GETN_OPTION_EVENT_EX(OnChangeCommentsFrom) 
				
			GETN_COMBO(CommentsTo, _L("Comments To"), 0, "|1|2|3|4|5|6|7|8|9|10")
				GETN_ID(IDE_ASCIMP_MAXLABELS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				
			GETN_COMBO(ParamsFrom, _L("System Parameters From"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_FIRSTPARAMS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				GETN_OPTION_EVENT_EX(OnChangeParametersFrom)  
				
			GETN_COMBO(ParamsTo, _L("System Parameters To"), 0, "|1|2|3|4|5|6|7|8|9|10")
				GETN_ID(IDE_ASCIMP_NUMPARAMS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
		
			GETN_COMBO(UserParamsFrom, _L("User Parameters From"), 0, _L("|<none>|1|2|3|4|5|6|7|8|9|10"))
				GETN_OPTION_SPECIALVALS("0")
				GETN_ID(IDE_ASCIMP_FIRSTUSERPARAMS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
				GETN_OPTION_EVENT_EX(OnChangeUserParametersFrom)
				
			GETN_COMBO(UserParamsTo, _L("User Parameters To"), 0, "|1|2|3|4|5|6|7|8|9|10")
				GETN_ID(IDE_ASCIMP_NUMUSERPARAMS) /// Hong 03/30/07 v8.0593 ADD_DATAID_TO_SAVE_OPTION_IN_THEME
		//GETN_END_BRANCH(HeaderLines) 		///---Sim 04-12-2007 IMPROVE_CSV_OPTIONS remove
		/// end ADD_HEADER_LINE_OPTION
		
		// custom import mode list
		///---Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode tr1stImportMode = tree_get_node_by_id(tr, IDE_DISPIMP_1STMODE, true);
		if ( tr1stImportMode )
		{
			string strCombo, strMapping;
			strCombo = getImportModeListString(strMapping, CSV_1ST_FILE_IMPORT_MODE_LIST);
			tr1stImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			tr1stImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			tr1stImportMode.nVal = ASCIMP_MODE_REPLACE_DATA;
		}
		///---END ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode trImportMode = tree_get_node_by_id(tr, IDE_IMP_IMPORTMODE, true);
		if ( trImportMode )
		{
			string strCombo, strMapping;
			strCombo = getImportModeListString(strMapping, CSV_IMPORT_MODE_LIST);
			trImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			trImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			trImportMode.nVal = ASCIMP_MODE_NEW_SHEETS;
		}
		
		// default no spark line
		//TreeNode trSparkLine = tree_get_node_by_id(tr, IDE_DISP_IMP_SPARKLINES, true);
		//trSparkLine.nVal = 0;
		//trSparkLine.Show = 0;
		
		///---Sim 12-31-2008 QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE
		TreeNode trDateFormat;
		
		TreeNode trFileNameOption = tr.GetNode(STR_FILTER_FILENAME_NODE);
		if ( trFileNameOption )
			trDateFormat = tr.InsertNode(trFileNameOption, STR_NODE_NODE_DATE_FORMAT);
		else
			trDateFormat = tr.AddNode(STR_NODE_NODE_DATE_FORMAT);
			
		trDateFormat.ID = TRGP_STR;
		trDateFormat.SetAttribute(STR_LABEL_ATTRIB, _L("Custom Date Format"));
		///Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
		//trDateFormat.SetAttribute(STR_COMBO_ATTRIB, "|");
		update_custom_date_format_combo_attrib(trDateFormat);
		///End CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
		trDateFormat.DataID = GET_FILTER_USER_DATAID(1);
		///---END QA80-12890-P1 CSV_IMPORT_KEEP_DATE_TYPE
		
		/// Hong 08/31/09 QA80-12899 IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE
		TreeNode 	trKeepDestColFmt;
		if ( trFileNameOption )
			trKeepDestColFmt = tr.InsertNode(trFileNameOption, STR_NODE_KEEP_DEST_COL_FMT);
		else
			trKeepDestColFmt = tr.AddNode(STR_NODE_KEEP_DEST_COL_FMT);
		trKeepDestColFmt.ID = TRGP_CHECK;
		trKeepDestColFmt.SetAttribute(STR_LABEL_ATTRIB, _L("Keep target column format"));
		trKeepDestColFmt.DataID = GET_FILTER_USER_DATAID(2);
		/// end IMP_WIZ_SUPPORT_KEEP_COL_FMTS_IN_TEMPLATE
		
		fuSetXFunctionName(tr, "impCSV");
	
		return 0;
	}
	///---END MORE_OPTIONS_FOR_IMPORT
	
	return -1;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void impCSV_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if ( nGetNDialog > 0 )
	{
		//trGetN.impmode.Show = 0;
		//trGetN.sparkline.Show = 0;
	//	trGetN.orng.Show = 0;
		//trGetN.uid.Show = 0; ///---Sim 05-18-2007 REMOVE_UID_VARIABLE remove
		trGetN.trheader.Show = 0;
		///Cheney 2007-1-17 ADD_FILTER
		//trGetN.trFilter.Show = 0;
		///end ADD_FILTER
		/// Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
		// disable option not allow edit when do repeat import
		if(1 == trGetN.reimp.nVal)
		{
			trGetN.fname.Enable = 2;
			trGetN.trfiles.Enable = 2;
			trGetN.orng.Enable = 2;
			///---Sim 06-21-2007 QA80-9288-P9 DISALLOW_CHANGE_HEADER_SETTING_WHEN_REPEAT_IMPORT
			//tree_set_attribute_to_all_nodes(trGetN.options.HeaderLines, STR_ENABLE_ATTRIB, "2");
			///---END QA80-9288-P9 DISALLOW_CHANGE_HEADER_SETTING_WHEN_REPEAT_IMPORT
		}
		/// end REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
	}
	///Cheney 2007-1-17 ADD_FILTER
	if(nGetNDialog >= 0)
	{
		if ( LTXF_FROM_GUI_MENU == dwCntrl )
			trGetN.fname.strVal = "";
		///---Sim 01-30-2007 CONVERT_IMPORT_MODE_FROM_FILTER_TO_GUI_LIST
		//TreeNode trImportMode = tree_get_node_by_id(trGetN.options, IDE_IMP_IMPORTMODE, true);
		//if ( trImportMode )
		//{
			//int nImportMode = trImportMode.nVal;
			//trImportMode.nVal = getListIndexFromImportMode(nImportMode, CSV_IMPORT_MODE_LIST);
		//}
		///---END CONVERT_IMPORT_MODE_FROM_FILTER_TO_GUI_LIST
	}
	///end ADD_FILTER
	if(nGetNDialog > -1)
	{
		string strFileName = trGetN.fname.strVal;
		
		/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
		if ( LTXF_FROM_GUI_MENU & dwCntrl ) // if from menu, ignore default value fname$
			strFileName = "";
		/// end IGNORE_FNAME$_WHEN_FROM_MENU
		
		if(is_empty_or_unassigned(strFileName))
		{
			/// Hong 05/31/07 v8.0630 MORE_ON_ACCESS_TO_FDLOG
			//int nFilesRet = get_open_box_by_file_group(strFileName, "CSV", "Comma Delimited File", true);
			int nFilesRet;
			if ( 0 != nGetNDialog )
			{
				int nShowOptionsDlg = 1;
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "CSV", _L("Comma Delimited File"),
				//	OPENBOX_FLAG_MULTIFILES, NULL, NULL, _L("Show Options Dialog"), &nShowOptionsDlg);
				///Sophy 10/22/2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_EXCEL_CSV_IMPORT
				/*
				nFilesRet = get_open_box_by_file_group(strFileName, "CSV", NULL,
					OPENBOX_FLAG_MULTIFILES, NULL, NULL, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				*/
				nFilesRet = get_open_box_by_file_group(strFileName, "CSV", NULL,
					OPENBOX_FLAG_MULTIFILES | OPENBOX_FLAG_FORCECHECKSTATE, NULL, NULL, 
					get_show_options_label(trGetN), &nShowOptionsDlg);
				///end SUPPORT_SAVE_SHEET_THEME_FOR_EXCEL_CSV_IMPORT
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nRet = (nShowOptionsDlg ? XFEVT_PROCEED : XFEVT_PROCEED_NO_DLG);
			}
			else
			{
				//nFilesRet = get_open_box_by_file_group(strFileName, "CSV", _L("Comma Delimited File"), true);
				nFilesRet = get_open_box_by_file_group(strFileName, "CSV", NULL, true); /// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
			}
			/// end MORE_ON_ACCESS_TO_FDLOG
			if ( 0 == nFilesRet )
			{
				nRet = XFEVT_ABORT;
				//warning_msg_box(XFERR_UI_USER_CANCEL, false);
				return;
			}
			trGetN.fname.strVal = strFileName;
			///Cheney 2007-1-17 ADD_FILTER
			string strErrMsg;
			if( !_file_name_event(trGetN, strErrMsg) )
			{
				/// Hong 03/21/07 v8.0586 FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				//nRet = XFEVT_ABORT;
				//warning_msg_box(strErrMsg, false);
				int nErrMsg = atoi(strErrMsg);
				nRet = XFEVT_ABORT;
				warning_msg_box(nErrMsg, false, 'E'); // should pass an int 	///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
				/// end FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				return;
			}
			///end ADD_FILTER
		}
	}	
}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int impCSV_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
