#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	type_dat,
	type_text,
	type_csv,
	type_all,
};
enum{
	overwrite_replace,
	overwrite_append,
};
enum{
	separator_tab,
	separator_comma,
	separator_space,
	separator_ct,
	separator_cs,
};
//put additional include files here
#include <GetNBox.h>
#include <oExtFile.h>
#include <okocUtils.h>

// modofication log
//--- CPY 10/19/06 NO_NEED_TO_WARN_REPLACE_ALREADY_EXISTED
//--- Cheney 2006-10-20 RESTORE_BECAUSE_IF_EDIT_PATH_NEED_WARN
//--- CPY 10/25/06 WARN_REPLACE_ALREADY_EXISTED_AND_CHECK_PATH_AND_EXT
//--- Cheney 2006-10-26 NEED_FUNCTION_TO_CHECK_FILE_NAME_VALID
//--- Cheney 2006-10-30 USE_TAGNAME_TO_REPLACE_ROW_NUM_HARD_CODE
//--- Cheney 2006-11-3 bOkEnable_AND_StrErrMessage_SHOULD_BOTH_USE_IN_NEW_DESIGN
//--- Cheney 2006-11-3 MOVE_AUTO_CHECK_SELECT_FROM_EVENT1_TO_BEFORE_EXCUTE
//--- CPY 11/3/06 EVENT1_STR_ERR_MSG_REWRITE
//--- Cheney 2006-11-3 IF_PATH_CHANGE_ALSO_NEED_UPDATE_TREE_SHOWN
//--- Cheney 2006-11-3 CHECK_IF_FILE_PATH_IS_VALID
//--- Cheney 2006-11-6 HIDE_DATA_SELECT_NODE_WHEN_NO_DATA_SELECT
//--- CPY 11/9/06 FILENAME_CHECK_WITHOUT_LOCALIZATION_PROBLEM
//--- Cheney 2006-11-10 RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
//--- Cheney 2007-2-9 SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
//--- Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL
//--- Cheney 2007-3-15 FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
//--- Jasmine 04/13/07 PRINT_XF_MSG_TO_SCRIPT_WINDOW
//--- Folger 04/16/07 REPLACE_BY_OKOC_OUT_MSG
//--- Cheney 2007-4-19 PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
//--- Sim 05-25-2007 GET_DEFAULT_FROM_ORIGIN_OPTIONS
//--- Sim 06-05-2007 WARNING_EXPORT_TO_EXISTING_FILE
//---Sim 06-18-2007 ADD_SHOW_DLG_CHECK_BOX_TO_SAVE_AS_DLG
/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
/// Iris 07/04/2007 v8.0655 CREATE_PATH_IF_SPECIFIED_PATH_IS_NOT_EXISTED
/// Iris 07/13/2007 v8.0659 SHARE_CHECK_PATH_CODES_FOR_ALL_EXPORT_XFS
/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
/// Hong 10/25/07 v8.0733 GET_COMPILE_ERROR_FOR_DUPLICATE_GLOBAL_VARIABLE
///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
/// Hong 02/22/08 v8.0810 FIX_EXPORT_FAIL_CREATE_PATH_IF_MULTI_LEVEL_NOT_EXIST
/// Sim 05-07-2009 QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
/// Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
/// Kyle 07/08/2009 QA80-13755-P1 FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
/// Kyle 07/08/2009 QA80-13755-S1 FIX_ASK_OVERWRITE_TWICE
/// Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
/// Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
/// Sim 07-09-2009 QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
/// Sim 09-28-2009 QA81-14383-P1 FIX_LOAD_THEME_FAILED_TO_UPDATE_FILE_EXTENSION
/// Sim 09-28-2009 QA81-10800-P2 FIX_ADD_DIFF_X_COL_IF_SEL_FROM_DIFF_RANGE
/// Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
/// Hong 10/16/09 QA80-13230-P5 EXPORT_ASCII_FAIL_WITH_SHEET_NAME_ALL_NUMERIC
/// Folger 10/28/09 QA81-14541 EXPORT_CSV_SHOULD_OUT_MESSAGE_ABOUT_FILE_LOCATION
/// Hong 11/19/09 QA80-14696-P2 FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
/// Hong 11/24/09 QA80-14724 EXP_CSV_NEED_SUBFIX_FOR_PHONE_AND_ZIP_CODE

#define overwrite_ask 2 ///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE

enum{
	FILE_TYPE_DAT,
	FILE_TYPE_TXT,
	FILE_TYPE_CSV,
	FILE_TYPE_ALL	
};

enum{
	SEP_TAB,
	SEP_COMMA,
	SEP_SPACE,
	SEP_COMMA_AND_TAB,
	SEP_COMMA_AND_SPACE
};

enum{
	PATH_CONSISTENT_WITH_TYPE,
	TYPE_CONSISTENT_WITH_PATH,
	TYPE_PATH_JUST_CHECK_VALUES //--- CPY 11/3/06 EVENT1_STR_ERR_MSG_REWRITE
};

//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
enum{
	ROW_LABEL_SHORTNAME,
	ROW_LABEL_LONGNAME,
	ROW_LABEL_UNITS,
	ROW_LABEL_COMMENTS
};
///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER

///Cheney 2006-10-30 USE_TAGNAME_TO_REPLACE_ROW_NUM_HARD_CODE
//#define FILE_TYPE_CHANGE 	1
//#define FILE_PATH_CHANGE 	2
#define STR_NODE_TYPE "type"
#define STR_NODE_PATH "path"
#define STR_NODE_SEP  "separator"
///end USE_TAGNAME_TO_REPLACE_ROW_NUM_HARD_CODE

#define	CHAR_SLASH					'\\'
#define	CHAR_POINT					'.'
#define STR_STAR_POINT				"*."
#define STR_LEFT_SQUARE_BRACKET		"["
#define STR_RIGHT_SQUARE_BRACKET	"]"

#define STR_ERR_FAIL_UPDATE_PATH "Failed to update path"

///Cheney 2006-11-10 RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
#define STR_ATTRIB_OLD_SEP 		"oldsep"
#define STR_ATTRIB_OLD_TYPE		"oldtype"
///end RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN

//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
#define STR_PARAMETERS			"Parameters"
///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER

#define CHECK_STRING_WRITE_TO_FILE(_strInfo, _bLabel, _strLabel, _strSep, _file) if(!_strInfo.IsEmpty())\
					{ 	_strInfo = _bLabel? _strLabel+_strSep+_strInfo : _strInfo;\
						_file.Write(&_strInfo, _strInfo.GetLength());}
						
///Cheney 2007-3-15 FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
//bool g_bCheckOverWritten = true;
/// Kyle 07/08/2009 QA80-13755-P1 FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
//static bool g_bCheckOverWritten = true; /// Hong 10/25/07 v8.0733 GET_COMPILE_ERROR_FOR_DUPLICATE_GLOBAL_VARIABLE
///End FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
///end FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE

#define STR_ASCII_FILE_GROUP "ASCII" ///---Sim 05-25-2007 GET_DEFAULT_FROM_ORIGIN_OPTIONS

#define STR_EXPORT_ASCII_FILE_GROUP "ASCIIEXP" ///---Sim 06-18-2007 ADD_SHOW_DLG_CHECK_BOX_TO_SAVE_AS_DLG
//#define STR_ONLY_FILE_NAME_ATTRIB  "OnlyFileName" ///---Jake 06/27/07 STORE_USER_FILE_NAME
///---Sim 05-25-2007 GET_DEFAULT_FROM_ORIGIN_OPTIONS
static string _get_default_path()
{
	string strPath = get_file_group_default_path(STR_ASCII_FILE_GROUP);
	if ( strPath.IsEmpty() )
		strPath = GetAppPath(FALSE);
	
	return strPath;
}
///---END GET_DEFAULT_FROM_ORIGIN_OPTIONS


///Cheney 2006-11-10 MOVE_IT_TO_SYSUTIL.C
////------ CPY 11/9/06 FILENAME_CHECK_WITHOUT_LOCALIZATION_PROBLEM
//bool is_empty_or_unassigned(LPCSTR lpcsz)
//{
	//string str = lpcsz;
	//str.TrimLeft();
	//str.TrimRight();
	//if(str.IsEmpty())
		//return true;
	//return okutil_cvt_str_to_predefined_type(str) == PDS_UNASSIGNED? true:false;
//}
////------
///end MOVE_IT_TO_SYSUTIL.C

//--- CPY 10/25/06 WARN_REPLACE_ALREADY_EXISTED_AND_CHECK_PATH_AND_EXT
static bool _get_file_ext(string& strExt, int nType)
{
	vector<string> vs = {"dat", "txt", "csv"};
	if(nType < 0 || nType >= FILE_TYPE_ALL)
		return false;
	strExt = vs[nType];
	return true;
}
static bool _check_add_file_ext(string& strFile, int nType)
{
	///---Sim 03-17-2008 FIX_CHECK_FILE_EXTENSION
	//if(nType < 0 || nType >= FILE_TYPE_ALL)
		//return false;
	//string strFilepath = strFile;
	//string strFname, strFext, strExt;
	//_get_file_ext(strExt, nType);	
	//if(!separate_file_name_ext(strFilepath, strFname, strFext) || strExt.CompareNoCase(strFext) != 0)
	//{
		//strFile = strFname + "." + strExt;
		//return true;
	//}
	//return false; // no change
	string strExt;
	if ( !_get_file_ext(strExt, nType) )
		return false;
	///---Sim 05-07-2009 QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
#ifndef CHECK_EXCEED_FILE_PATH_LENGTH_LIMITATION
	return add_file_extension(strFile, strExt);
#else
	bool bRet = add_file_extension(strFile, strExt);
	if ( bRet )
		check_trim_file_path_if_too_long(strFile);
	return bRet;
#endif
	///---END QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
	///---END FIX_CHECK_FILE_EXTENSION
}
	
//put your own support static functions here
static bool _update_type_related_nodes(TreeNode& trGetN)
{
	trGetN.separator.Show = (trGetN.type.nVal == FILE_TYPE_CSV) ? false : true;
	trGetN.separator.nVal = (trGetN.type.nVal == FILE_TYPE_CSV) ? SEP_COMMA : trGetN.separator.nVal;
	///Cheney 2006-11-10 RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
	int nOldType;
	bool bRet = trGetN.type.GetAttribute(STR_ATTRIB_OLD_TYPE, nOldType);
	if(bRet && (trGetN.type.nVal != FILE_TYPE_CSV && nOldType == FILE_TYPE_CSV) )
	{
		int nOldSep;
		if(trGetN.separator.GetAttribute(STR_ATTRIB_OLD_SEP, nOldSep))
			trGetN.separator.nVal = nOldSep;
	}
	
	if(trGetN.type.nVal != FILE_TYPE_CSV) 
		trGetN.separator.SetAttribute(STR_ATTRIB_OLD_SEP, trGetN.separator.nVal);
		
	trGetN.type.SetAttribute(STR_ATTRIB_OLD_TYPE, trGetN.type.nVal);
	///end RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
	return true;// to indicate DynaControl update needed
}

static bool _get_file_type(TreeNode& trType, int nType, string& strType)
{
	string strCombo;
	if(!trType.GetAttribute(STR_COMBO_ATTRIB, strCombo))
		return false;
	
	strType = strCombo.GetToken(nType, '|');
	
	if(nType == FILE_TYPE_TXT || nType == FILE_TYPE_ALL)
	{
		strType = strType.GetToken(1, '(');
		strType.TrimRight(')');
	}
		
	return true;
}

static bool _get_wks_name(TreeNode& trGetN, string& strWksName)
{
	Worksheet	wks;
	if(!okxf_resolve_string_get_origin_object(trGetN.iw.strVal, &wks))
		return false;
			
	strWksName = wks.GetName();
	
	return true;
}

//if user change file ext in path edit box, should check and make consistent
//e.g. if type is csv, file path should be such as "c:\\test.csv" or "c:\\test", and "c:\\test"
//must change to "c:\\test.csv"
//if user input "c:\\test.dat", should change type to dat
//if user input "c:\\test.abc", should change type to All Files
//if user change type to dat, file path should change to "c:\\test.dat"
//if user change type to All files, file path should change to "c:\\test"
static string _make_type_and_ext_consistent(TreeNode& trType, TreeNode& trPath, string& strExtFromPath, int nCtrl = PATH_CONSISTENT_WITH_TYPE)
{
	string strExtFromType;
	_get_file_ext(strExtFromType, trType.nVal);
	
	strExtFromPath = strExtFromPath.IsEmpty() ? strExtFromType : strExtFromPath;
	
	if(strExtFromPath.CompareNoCase(strExtFromType) != 0)
	{
		if(nCtrl == TYPE_CONSISTENT_WITH_PATH)
		{
			int nIndex = _find_type_index_by_ext(trType, strExtFromPath);
			trType.nVal = nIndex;
		}
		else if(nCtrl == PATH_CONSISTENT_WITH_TYPE)
		{
			strExtFromPath = strExtFromType;
		}
	}
	
	return strExtFromPath;
}

static int _find_type_index_by_ext(TreeNode& trType, string& strExt)
{
	for(int ii = FILE_TYPE_DAT; ii <= FILE_TYPE_ALL; ii++)
	{
		string strTypeTemp;
		_get_file_type(trType, ii, strTypeTemp);
		strTypeTemp.TrimLeft(STR_STAR_POINT);
		if(strTypeTemp.CompareNoCase(strExt) == 0)
			break;
	}
	
	return ii = ii >=FILE_TYPE_ALL ? FILE_TYPE_ALL : ii;
}

static bool _gui_check_update_path(TreeNode& trGetN, int nCtrl = PATH_CONSISTENT_WITH_TYPE)
{	
	TreeNode 	trType = trGetN.type;
	TreeNode 	trPath = trGetN.path;
	
	//get path, if path is empty, get current file path
	string		strPath = trPath.strVal;
	if(strPath.IsEmpty() || strPath == STR_UNASSIGNED)
		///---Sim 05-25-2007 GET_DEFAULT_FROM_ORIGIN_OPTIONS
		//strPath = GetAppPath();
		strPath = _get_default_path();
		///---END GET_DEFAULT_FROM_ORIGIN_OPTIONS
		
	/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	bool 	bIsSpecialPath = str_is_predefined_path(strPath);
	if(bIsSpecialPath)
		strPath = cvt_predefined_path_to_real_path(strPath);
	///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	
	//get ext and filname from path
	string strFile, strExtFromPath;
	separate_file_name_ext(strPath, strFile, strExtFromPath);
	string strFilename = GetFileName(strFile); //strFile have path
	
	//if fil name is empty, use actived wks'name as file name
	string strWksName;
	if(!_get_wks_name(trGetN, strWksName))
		return false;
	
	if(strFilename.IsEmpty())
	{
		strFile = GetFilePath(strFile) + strWksName;
	}
	
	//make sure path node and type node are consistent
  	string strExt = _make_type_and_ext_consistent(trType, trPath, strExtFromPath, nCtrl);
	
	//set button control
	string strType;
	_get_file_type(trType, trType.nVal, strType);
	
	string str;
	if(trType.nVal != FILE_TYPE_ALL)
		str.Format("...Save:[%s] *.%s", strType, strExt);
	else
		str.Format("...Save");
	
	trPath.SetAttribute(STR_COMBO_ATTRIB, str);	
	
	/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	/*
	///Jake 06/28/07 SUPPORT_DEFAULT_NAME
	//----Jake 06/27/07 GET_COMBO_LIST_FROM_REGISTRY verytime when file type change 	
	//char szLastXFName[MAXFULLPATH];
	//LT_get_str(LTVAR_LAST_XF, szLastXFName, MAXFULLPATH); //Jake 06/27/07 GET_THE_NAME_OF_LAST_XF_CALLED
	tree_set_browse_combo_attrib(trPath);
	//----end GET_COMBO_LIST_FROM_REGISTRY
	///end SUPPORT_DEFAULT_NAME
	*/
	///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	
	//update path in GUI
	/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	if( bIsSpecialPath )
	{
		char szFileName[100];
		lstrcat(szFileName, trPath.strVal);
		check_add_file_ext(szFileName, strExt);
		strPath = szFileName;
		strPath.TrimRight('.'); /// Iris There is a '.' at the last for FILE_TYPE_ALL, so trim it if has.
	}
	else
	///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	strPath = (trGetN.type.nVal == FILE_TYPE_ALL && strExt.IsEmpty())  //if *.*, no need to add any ext
					? strFile + strExt : strFile + "." + strExt;
	
	///---Sim 05-07-2009 QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
#ifdef CHECK_EXCEED_FILE_PATH_LENGTH_LIMITATION
	check_trim_file_path_if_too_long(strPath);
#endif
	///---END QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
	trPath.strVal = strPath;
	
	/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	tree_set_browse_combo_attrib(trPath);	
	///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	
	return true; 
}

///Cheney 2006-10-20 RESTORE_BECAUSE_IF_EDIT_PATH_NEED_WARN
//--- CPY 10/19/06 NO_NEED_TO_WARN_REPLACE_ALREADY_EXISTED
///Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
//static bool _check_path_show_warnning(string& strPath)
///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
//static bool _check_path_show_warnning(string& strPath, int nOverWriteOpn)
static bool _check_path_show_warnning(string& strPath, int nOverWriteOpn, bool& bAppend)
///---END QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
///End ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
{
	///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
	/*
	bAppend = false; ///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	///Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
	if(nOverWriteOpn == overwrite_replace)		// do nothing
		return true;
	///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	else if ( nOverWriteOpn == overwrite_append )
	{
		bAppend = true;
		return true;		
	}
	///---END QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	else if(nOverWriteOpn == overwrite_rename)
	{
		int nPos = 1;
		string strFilePath, strFileName, strFileExt;
		separate_file_name_ext(strPath, NULL, &strFileExt);
		strFileName = GetFileName(strPath, true);
		strFilePath = GetFilePath(strPath);
		while(strPath.IsFile())
		{
			strPath = strFilePath + strFileName + (string)nPos + "." + strFileExt;
			nPos++;
		}
	}
	///End ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
	while(strPath.IsFile())//check the file exist or not
	{
		string 	strErr;
		strErr.Format("%s already exists.\nDo you want to replace it?", strPath);
		if(IDNO == MessageBox(NULL, strErr, "Attention!", MB_YESNO))	
		{
			string strName = InputBox("Please enter a new name");
			if(strName.IsEmpty())
				return false;
			string strExt;
			separate_file_name_ext(strPath, NULL, strExt);
			strPath = GetFilePath(strPath) + strName + "." + strExt;
			///---Sim 05-07-2009 QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
#ifdef CHECK_EXCEED_FILE_PATH_LENGTH_LIMITATION
			check_trim_file_path_if_too_long(strPath);
#endif
			///---END QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
		}	
		else
			return true;
	}
	return true;
	*/
	
	bAppend = false;
	if ( strPath.IsFile() )
	{
		if ( overwrite_ask == nOverWriteOpn )
		{
			string strDesc;
			int nRet;
			
			do
			{
				ocu_load_msg_str(CER_REPLACE_APPEND_EXISTING_FILE, &strDesc, strPath);
				nRet = MessageBox(GetWindow(), strDesc, _L("File Exists!"), MB_YESNOCANCEL|MB_ICONQUESTION);
				if ( IDCANCEL == nRet )
				{
					string strName;
				    try
				    {
				        strName = InputBox("Please enter a new name");
				    }
				    catch(int nErr)
				    {
				        strName.Empty();
				    }
					if(strName.IsEmpty())
						return false;
					string strExt;
					separate_file_name_ext(strPath, NULL, strExt);
					//strPath = GetFilePath(strPath) + strName + "." + strExt;
					strPath = GetFilePath(strPath) + strName;
					add_file_extension(strPath, strExt);
					///---Sim 05-07-2009 QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
#ifdef CHECK_EXCEED_FILE_PATH_LENGTH_LIMITATION
					check_trim_file_path_if_too_long(strPath);
#endif
					///---END QA80-13571 FIX_CRASH_WHEN_FILE_PATH_LENGTH_IS_TOO_LONG
				}	
			}
			while ( IDCANCEL == nRet && strPath.IsFile() );

			switch ( nRet )
			{
			case IDYES:
				nOverWriteOpn = overwrite_replace;
				break;
			case IDNO:
				nOverWriteOpn = overwrite_append;
				break;
			case IDCANCEL:
				nOverWriteOpn = overwrite_replace;
				break;
			}
				
		}
		
		switch ( nOverWriteOpn )
		{
		case overwrite_replace:
			break;
		case overwrite_append:
			bAppend = true;
			break;
		default:
			return false;
		}
	}	
	
	return true;
	///---END QA80-13891 REDO_EXP_ASC_OVERWRITE
}
///end RESTORE_BECAUSE_IF_EDIT_PATH_NEED_WARN

static int _auto_check_select_range(TreeNode& trGetN, Worksheet& wks)
{
	trGetN.select.nVal = 1;
	vector<int> vr1, vc1, vr2, vc2;
	int nRanges = wks.GetSelectedRange(vr1, vc1, vr2, vc2);
	if(nRanges < 1 || (nRanges == 1 && vr1[0] == vr2[0] && vc1[0] == vc2[0])) //if only one cell select, not check
		trGetN.select.nVal = 0;
	
	return nRanges;
}

//---have loop, maybe should do in VC
static void _get_separator(string& strSep, int nType, int nSep)
{
	switch(nSep)
	{
	case SEP_TAB:
		strSep = "	";
		break;
	case SEP_COMMA:
		strSep = ",";
		break;
	case SEP_SPACE:
		strSep = " ";
		break;
	case SEP_COMMA_AND_TAB:
		strSep = ",	";
		break;
	case SEP_COMMA_AND_SPACE:
		strSep = ", ";
		break;
	default:
	}
}

//--- CPY 11/3/06 EVENT1_STR_ERR_MSG_REWRITE
// return true if OK should enable, false if should disable OK button
// lpcszNodeName = NULL if coming from global event like GETNE_ON_INIT
static bool _check_err_condition(TreeNode& trGetN, LPCSTR lpcszNodeName, string& strErrMsg)
{

	/// Iris 07/13/2007 v8.0659 SHARE_CHECK_PATH_CODES_FOR_ALL_EXPORT_XFS
	/*
	///Cheney 2006-11-3 CHECK_IF_FILE_PATH_IS_VALID
	if(lpcszNodeName != NULL)  
	{
		/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		//string strPath = GetFilePath(trGetN.path.strVal); //when init, path is empty, no need to check 
		string	strPath = GetFilePath(strAbsolutePath);
		///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		if(!strPath.IsPath())
		{
			/// Iris 07/04/2007 v8.0655 CREATE_PATH_IF_SPECIFIED_PATH_IS_NOT_EXISTED
			//strErrMsg = CER_INVALID_FILEPATH;
			//return false;
			strErrMsg = XFWARN_WILL_CREATE_NONEXISTING_PATH;
			return true;
			///end CREATE_PATH_IF_SPECIFIED_PATH_IS_NOT_EXISTED
		}
	}
	///end CHECK_IF_FILE_PATH_IS_VALID
	*/
	///end SHARE_CHECK_PATH_CODES_FOR_ALL_EXPORT_XFS
	
	if(NULL == lpcszNodeName || lstrcmpi(lpcszNodeName, STR_NODE_TYPE) == 0 || lstrcmpi(lpcszNodeName, STR_NODE_PATH) == 0)
	{
		///---Sim 09-28-2009 QA81-14383-P1 FIX_LOAD_THEME_FAILED_TO_UPDATE_FILE_EXTENSION
		//int nCtrl = TYPE_PATH_JUST_CHECK_VALUES;
		int nCtrl = PATH_CONSISTENT_WITH_TYPE;
		///---END QA81-14383-P1 FIX_LOAD_THEME_FAILED_TO_UPDATE_FILE_EXTENSION
		if(lpcszNodeName && lstrcmp(lpcszNodeName, STR_NODE_TYPE) == 0)
			nCtrl = PATH_CONSISTENT_WITH_TYPE;
		else if(lpcszNodeName && lstrcmp(lpcszNodeName, STR_NODE_PATH) == 0)
			nCtrl = TYPE_CONSISTENT_WITH_PATH;
		if(!_gui_check_update_path(trGetN, nCtrl))
		{
			strErrMsg = STR_ERR_FAIL_UPDATE_PATH;
			return false;
		}
	}
	
	/// Iris 07/13/2007 v8.0659 SHARE_CHECK_PATH_CODES_FOR_ALL_EXPORT_XFS
	bool 	bOK = true;
	check_relative_path(trGetN.path.strVal, false, &strErrMsg, &bOK);
	if( !bOK )
		return false;
	///end SHARE_CHECK_PATH_CODES_FOR_ALL_EXPORT_XFS
	
	///---Sim 06-05-2007 WARNING_EXPORT_TO_EXISTING_FILE
	/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	//if ( trGetN.path.strVal.IsFile() )
	string strAbsolutePath = cvt_predefined_path_to_real_path(trGetN.path.strVal); /// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	trGetN.overwrite.Show = false; ///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
	if(strAbsolutePath.IsFile())
	///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	{
		///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
		//strErrMsg = EXPWARN_FILE_EXIST;
		//strErrMsg += ":";
		///// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		////strErrMsg += GetFileName(trGetN.path.strVal);
		//strErrMsg += GetFileName(strAbsolutePath);
		/////end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		trGetN.overwrite.Show = true;
		///---END QA80-13891 REDO_EXP_ASC_OVERWRITE
	}
	///---END WARNING_EXPORT_TO_EXISTING_FILE
	
	return true;
}

///Cheney 2006-11-9 DIFFERENT_CASE_USE_DIFFERENT_OPTION
//r2 return -1 in GetRange means all missing, in GetSelectedRange means all column selected.
//if one subrange are whole column selected, should use GetRange(GDR_SKIP_MISSING_BLANK) get its r2 again.
//then if r2 = -1, means all missing in this subrange. should correct it
//our aim is:  
//if a wks like as :            C1   C2   C3   
//                          R1  --   --   --
//                          R2  --   --    1
//                          R3  --    7    2
//                          R4  --   --   --
//highlight Col1, then Col2, Then R2 and R3(3 subRanges)
//export result should be       C1   C2   C3
//                          R1  --   --   --
//                          R2  --   --    1
//                          R3  --    7    2
//if a wks like as :        	C1   C2     
//                      	R1  --   --  
//                      	R2  --    3  
//                      	R3  --    7  
//                      	R4  --   -- 
//highlight Col1, Then R2 and R3(2 subRanges)
//export result should be       C1   C2  
//                      	R1  --    3  
//                      	R2  --    7  
//for example1 vr1 = {0, 0, 1}, vr2 = {-1, -1, 2}, vc1 = {0, 1, 0}, vc2 = {0, 1, 2}
//should correct it to vr1 = {2, 0, 1}, vr2 = {2, 2, 2}
//for example2 vr1 = {0, 1}, vr2 = {-1, 2}, vc1 = {0, 0}, vc2 = {0, 1}
//should correct it to vr1 = {2, 1}, vr2 = {2, 2}
//return false if all subrangs is full column select and missing, otherwise return true
static bool _check_if_whole_col_or_block_missing_and_correct_range(Worksheet& wks, vector<int>& vr1, vector<int>& vr2, vector<int>& vc1, vector<int>& vc2)
{
	bool bResetRange = false;
	bool bExportData = false;
	vector<int> vResetIndex;
	
	//find select whole column or block
	for(int ii = 0; ii < vc1.GetSize(); ii++)
	{
		if(vr1[ii] != 0 || vr2[ii] != -1) //select whole column or block
		{
			bExportData = true;
			continue;
		}
		
		int r1temp, r2temp;
		bool bRet = wks.GetRange(r1temp, r2temp, vc1[ii], vc2[ii], GDR_NO_ADJUST, GDR_SKIP_MISSING_BLANK);
		vr2[ii] = r2temp;
		
		if(r2temp == -1)  //it means all missing
		{
			vResetIndex.Add(ii);
			bResetRange = true;
		}
		else
			bExportData = true;
	}
	
	//if exist vr2[ii] == -1, it means all column or block missing, should reset vr1[ii] and vr2[ii] to smallest number of r1 in all subRanges
	if(!bResetRange)
		return bExportData;
	
	//find smallest number of r1 in all subRanges
	vector<int> vr2Temp;
	vr2Temp = vr2;
	vr2Temp.Sort();
	int nSmallestr2 = 0;
	for(ii = 0; ii < vr2Temp.GetSize(); ii++)
	{
		if(vr2Temp[ii] > -1)
		{
			nSmallestr2 = vr2Temp[ii];
			break;
		}
	}
	
	//reset vr1[ii] and vr2[ii] which all missing
	for(ii = 0; ii < vResetIndex.GetSize(); ii++)
	{
		vr1[vResetIndex[ii]] = nSmallestr2;
		vr2[vResetIndex[ii]] = nSmallestr2;
	}
	
	return bExportData;
}
///end DIFFERENT_CASE_USE_DIFFERENT_OPTION

//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
static string _get_col_basicinfo(Worksheet& wks, int nCol, int nInfo)
{
	string strInfo;
	switch(nInfo)
	{
	case ROW_LABEL_SHORTNAME:
		strInfo = wks.Columns(nCol).GetName();
		break;
	case ROW_LABEL_LONGNAME:
		strInfo = wks.Columns(nCol).GetLongName();
		break;
	case ROW_LABEL_UNITS:
		strInfo = wks.Columns(nCol).GetUnits();
		break;
	case ROW_LABEL_COMMENTS:
		strInfo = wks.Columns(nCol).GetComments();
		break;
	default:
	}
	return strInfo;
}

///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
static string _get_implicit_x_basicinfo(Worksheet& wks, int nCol, int nInfo)
{
	string strInfo;
	switch(nInfo)
	{
	case ROW_LABEL_SHORTNAME:
		break;
	case ROW_LABEL_LONGNAME:
		wks.Columns(nCol).IsEvenSampling(NULL, NULL, NULL, &strInfo);
		break;
	case ROW_LABEL_UNITS:
		wks.Columns(nCol).IsEvenSampling(NULL, NULL, &strInfo, NULL);
		break;
	case ROW_LABEL_COMMENTS:
		break;
	default:
	}
	return strInfo;
}

static void _recheck_basicinfo(string& strInfo, int nType, int nInfo)
{
	if(nType == FILE_TYPE_CSV)
	{
		strInfo.TrimLeft();//trim space not needed
		if(nInfo == ROW_LABEL_COMMENTS) //only comment has multi lines
			check_to_replace_crlf_by_lf(&strInfo);
		
		check_to_add_quote_for_csv(&strInfo);
	}
	if(nInfo == ROW_LABEL_COMMENTS)
	{
		if(check_to_replace_line_feed_by_space(&strInfo) && strInfo == " ") //if separator is space, should add quotes
		{
			string strQuote('"');
			strInfo = strQuote + strInfo + strQuote;
		}
	}
	
}
///end ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL  

static string _get_wks_basicinfo(Worksheet& wks, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper, string& strSep, int nType, int nInfo, int* pAddXCol)
{	
	string strInfo;	
	int nLoop = wks.GetNumCols() - 1;
	if(nLoop < 0)
		return strInfo;
	
	bool bStrInfoEmpty = true; //if strInfo only has separator, should set it to empty and don't export it.
	//int nAddXColIndex = 0;  ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL
	int nAddXColIndex = 0; ///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	for(int ii = 0; ii <= nLoop; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		
		string strtemp = _get_col_basicinfo(wks, ii, nInfo);
		bStrInfoEmpty = !strtemp.IsEmpty()? false : bStrInfoEmpty;
		
		///Justin 2007/02/14 REPLACE_WITH_A_FUCNTION_FOR_REUSE
		//if(nType == FILE_TYPE_CSV)
		//{
			//strtemp.TrimLeft();//trim space not needed
			//if(nInfo == ROW_LABEL_COMMENTS) //only comment has multi lines
				//check_to_replace_crlf_by_lf(&strtemp);
			//
			//check_to_add_quote_for_csv(&strtemp);
		//}
		//if(nInfo == ROW_LABEL_COMMENTS)
		//{
			//if(check_to_replace_line_feed_by_space(&strtemp) && strtemp == " ") //if separator is space, should add quotes
			//{
				//string strQuote('"');
				//strtemp = strQuote + strtemp + strQuote;
			//}
		//}
		_recheck_basicinfo(strtemp, nType, nInfo);
		///end REPLACE_WITH_A_FUCNTION_FOR_REUSE
		
		//need more code to get X long name and unit
		string strAddXCol;
		///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		//if(pAddXCol != NULL && pAddXCol[ii]) //if(pAddXCol != NULL && pAddXCol[nAddXColIndex]==1) ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL
		if(pAddXCol != NULL && pAddXCol[nAddXColIndex]==1)
		///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		{
			//to justin: if long name or unit, need add it
			//may be need two string array to recode those two things
			//if(nInfo == ROW_LABEL_LONGNAME || nInfo == ROW_LABEL_UNITS)
			//strAddXCol += saXLongName[index]/saXUnit[index] + strSep;
			//bStrInfoEmpty = saXLongName[index]/saXUnit[index] is Empty? bStrInfoEmpty : false;
			//NOTES1: saXLongName and saXUnit's size not equal to vAddXIndex
			//if vAddXIndex = [1, 0 , 0, 1];
			//maybe saXLongName = [ss, yy]; is 1st and 4th column's long name
			//NOTES2: if this info empty or hidden, not export
			
			///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
			//strAddXCol = strSep;
			strAddXCol = _get_implicit_x_basicinfo(wks, ii, nInfo);
			bStrInfoEmpty = !strAddXCol.IsEmpty()? false : bStrInfoEmpty;
			_recheck_basicinfo(strAddXCol, nType, nInfo);
			
			strInfo += strAddXCol + strSep;
			//end ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
		}
		//strInfo += ii<nLoop? strAddXCol + strtemp+strSep : strAddXCol + strtemp;  
		strInfo += ii<nLoop? strtemp+strSep : strtemp;  ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
			
		//nAddXColIndex++; ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL
		nAddXColIndex++; ///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	}
	if(bStrInfoEmpty)
		strInfo.Empty();
	else
		strInfo += "\r\n";
	
	return strInfo;
}

static void _set_wks_params_name(vector<string>& vsParamName)
{
	vsParamName[0] = STR_PARAMETERS;
	int nSize = vsParamName.GetSize();
	for(int ii = 1; ii < nSize; ii++)
		vsParamName[ii] = STR_PARAMETERS + " " + ftoa(ii+1);
}

//Column1 may has 2 params, Column2 may has 4 params, Column3 may has 3 params, 
//should loop to find max size(here is 4)
static bool _count_wks_params(Worksheet& wks, int& nWksParamsSize, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper)
{
	int nLoop = wks.GetNumCols() - 1;
	vector<string> vsParamVal;
	
	for(int ii = 0; ii <= nLoop; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		
		// no paramter in this col
		if(!wks.Columns(ii).GetParameters(vsParamVal))
			continue;
		
		nWksParamsSize = nWksParamsSize < vsParamVal.GetSize()? vsParamVal.GetSize() : nWksParamsSize;
	}
	
	return true;
}

static bool _export_wks_params(file& expFile, Worksheet& wks, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper, string& strSep, int nType, bool blabel, vector<int>& vnParams, int* pAddXCol)
{
	int nLoop = wks.GetNumCols() - 1;
	if(nLoop < 0)
		return true;
	
	int nSize = 0;
	if(!_count_wks_params(wks, nSize, bSelect, vColLower, vColUpper))
		return false;

	vector<string> 	vsParameters(nSize);
	vector<int>		vsInfoEmpty(nSize);
	vsInfoEmpty = 1;  //if strInfo only has separator, should set it to empty and don't export it.
	vector<string> vsParamVal(nSize), vsParamName(nSize);
	_set_wks_params_name(vsParamName);
	
	//get info
	int nAddXColIndex = 0;
	for(int ii = 0; ii <= nLoop; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		
		int nCurrentParamSize = 0; 
		if(wks.Columns(ii).GetParameters(vsParamVal))
			nCurrentParamSize = vsParamVal.GetSize();
		
		string strAddXCol; //for support add X col
		for(int jj = 0; jj < nCurrentParamSize; jj++) //each column's parameter vector could has different length
		{
			string strtemp = vsParamVal[jj];
			//vsInfoEmpty[jj] = !strtemp.IsEmpty()? 0 : vsInfoEmpty[jj];
			vector<uint> vIndex;
			if(!strtemp.IsEmpty() && vnParams.Find(vIndex, RCLT_PARAM+jj) > 0) //if hidden, not export
				vsInfoEmpty[jj] = 0;
			
			if(nType == FILE_TYPE_CSV)
			{
				strtemp.TrimLeft();//trim space not needed
				check_to_add_quote_for_csv(&strtemp);
			}
			
			if(pAddXCol != NULL && pAddXCol[nAddXColIndex]==1)
		 		strAddXCol = strSep;
			
			vsParameters[jj] += ii<nLoop? strAddXCol + strtemp+strSep : strAddXCol + strtemp; 
		}
		
		for(int kk = jj; kk < nSize; kk++)
		{
			vsParameters[jj] += ii<nLoop? strAddXCol + strSep : strAddXCol;
		}
		
		nAddXColIndex++;
	}
	
	//write to file
	for(ii = 0; ii < nSize; ii++)
	{
		vsParameters[ii] = vsInfoEmpty[ii]==1? "" : vsParameters[ii]+"\r\n";
		CHECK_STRING_WRITE_TO_FILE(vsParameters[ii], blabel, vsParamName[ii], strSep, expFile)
	}
	
	return true;
}


static bool _export_user_params(file& expFile, Worksheet& wks, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper, string& strSep, int nType, bool blabel, vector<int>& vnUserParams, int* pAddXCol)
{
	vector<string> vsParamVal, vsParamName;
	if(!get_user_parameters(wks.Columns(0), vsParamName, vsParamVal, true))
		return false;
	
	int nSize = vsParamName.GetSize();
	if(nSize < 0)
		return false;
	if(nSize == 0)
		return true;
	
	vector<string> 	vsParameters(nSize);
	vector<int>		vsInfoEmpty(nSize);
	vsInfoEmpty = 1;  //if strInfo only has separator, should set it to empty and don't export it.
	int nLoop = wks.GetNumCols() - 1;
	if(nLoop < 0)
		return true;
	
	//to check which user parameter hidden
	vnUserParams.Sort();
		
	//get info
	int nAddXColIndex = 0;
	for(int ii = 0; ii <= nLoop; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		
		if(!get_user_parameters(wks.Columns(ii), vsParamName, vsParamVal, true))
			return false;
		
		for(int jj = 0; jj < nSize; jj++)
		{
			string strtemp = vsParamVal[jj];
			//vsInfoEmpty[jj] = !strtemp.IsEmpty()? 0 : vsInfoEmpty[jj];
			vector<uint> vIndex;
			if(!strtemp.IsEmpty() && vnUserParams.Find(vIndex, RCLT_UDL+jj) > 0) //if hidden, not export
				vsInfoEmpty[jj] = 0;
			
			if(nType == FILE_TYPE_CSV)
			{
				strtemp.TrimLeft();//trim space not needed
				check_to_add_quote_for_csv(&strtemp);
			}
			
			string strAddXCol;
			if(pAddXCol != NULL && pAddXCol[nAddXColIndex]==1)
		 		strAddXCol = strSep;
			vsParameters[jj] += ii<nLoop? strAddXCol + strtemp+strSep : strAddXCol + strtemp; 
		}
		nAddXColIndex++;
	}
	
	//write to file
	for(ii = 0; ii < nSize; ii++)
	{
		vsParameters[ii] = vsInfoEmpty[ii]==1? "" : vsParameters[ii]+"\r\n";
		CHECK_STRING_WRITE_TO_FILE(vsParameters[ii], blabel, vsParamName[ii], strSep, expFile)
	}
	
	return true;
}

///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
//static 	bool _export_sample_interv(file& expFile, Worksheet& wks, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper, string& strSep, bool bRowLabel)
static 	bool _export_sample_interv(file& expFile, Worksheet& wks, bool bSelect, vector<int>& vColLower, vector<int>& vColUpper, string& strSep, bool bRowLabel, int* pAddXCol)
///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
{
	string strSInterv;
	int nLoop = wks.GetNumCols() - 1;
	if(nLoop < 0)
		return true;
	
	bool bStrInfoEmpty = true; //if strInfo only has separator, should set it to empty and don't export it.
	int nAddXColIndex = 0; ///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	for(int ii = 0; ii <= nLoop; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		
		Column col = wks.Columns(ii);
		double dx0 = col.x0;
		double dxInc = col.xInc;
		bool bx0missing = is_missing_value(dx0);
		string strx0 = bx0missing? "" : ftoa(dx0);
		
		if(!bx0missing && is_missing_value(dxInc))
			return false;
		string strxInc = bx0missing? "" : ftoa(dxInc);
		
		bStrInfoEmpty = bx0missing? bStrInfoEmpty : false;
		
		string strtemp = bx0missing? "" : strx0 + "/" + strxInc;
		///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
		string strAddXCol; //for support add X col
		///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		//if(pAddXCol != NULL && pAddXCol[ii]==1)
		if(pAddXCol != NULL && pAddXCol[nAddXColIndex]==1)
		///---END QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	 		strAddXCol = strSep;
		strtemp = strAddXCol + strtemp;
		///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
		strSInterv += ii<nLoop? strtemp+strSep : strtemp; 
		
		nAddXColIndex++; ///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	}
	
	if(bStrInfoEmpty)
		strSInterv.Empty();
	else
		strSInterv += "\r\n";
	
	CHECK_STRING_WRITE_TO_FILE(strSInterv, bRowLabel, "Sampling Interval", strSep, expFile)
	return true;
}
///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER

///Cheney 2007-2-9 SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
//find where to add X col, if no sample interval exist, bAddXCol will be false

///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
//static bool _check_add_x_col(Worksheet& wks, bool bSelect, bool& bAddXCol, vector<int>& vAddXIndex, vector& vX0, vector& vXInc, vector<int>& vColLower, vector<int>& vColUpper)
//{
	//bAddXCol = false;
	//
	//int nLoop = wks.GetNumCols() - 1;
	//if(nLoop < 0)
		//return false;
	//
	//double dX0 = NANUM;
	//double dInc = NANUM;
	//for(int ii = 0; ii <= nLoop; ii++)
	//{
		//if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			//continue;
		//
		//Column col = wks.Columns(ii);
		//double dx0temp = col.x0;
		//double dxInctemp = col.xInc;
		//
		//if(is_missing_value(dx0temp)) //no sample interval
		//{
			//vAddXIndex.Add(0);	
			//continue;
		//}
		//
		//if(is_missing_value(dxInctemp))	//illegal sample interval
			//return false;
		//
		//if(dX0 == dx0temp && dInc && dxInctemp) //share one sample interval, no need to add
		//{
			//vAddXIndex.Add(0);
		//}
		//else
		//{
			//vAddXIndex.Add(1);
			//vX0.Add(dx0temp);
			//vXInc.Add(dxInctemp);
			//dX0 = dx0temp;
			//dInc = dxInctemp;
			//bAddXCol = true;
			////to justin: if long name or unit, need add it
			////may be need two string array to recode those two things
			////StringArray saXLongName, saXUnit;
			////saXLongName.Add(longname);
			////saXUnit.Add(unit);
			////NOTES: saXLongName and saXUnit's size not equal to vAddXIndex
			////if vAddXIndex = [1, 0 , 0, 1];
			////maybe saXLongName = [ss, yy]; is 1st and 4th column's long name
		//}
	//}
	//
	//return true;
//}

static void _check_add_x_col(Worksheet& wks, bool bSelect, bool& bAddXCol, vector<int>& vAddXIndex, vector& vX0, vector& vXInc, vector<int>& vColLower, vector<int>& vColUpper, vector<int>& vC1, vector<int>& vC2)
{
	bAddXCol = false;
	
	int nColNum = wks.GetNumCols();
	
	///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	//vAddXIndex.SetSize(nColNum);
	//vAddXIndex = 0;
	vAddXIndex.SetSize(0);
	///---END QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
	
	int nFirstAddXColInBlock = -1;
		
	double dX0, dInc;
	
	for(int ii = 0; ii < nColNum; ii++)
	{
		if(bSelect && !is_column_in_bounds(ii, vColLower, vColUpper))
			continue;
		vAddXIndex.Add(0); ///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		Column col = wks.Columns(ii);
		if(OKDATAOBJ_DESIGNATION_X == col.GetType())
		{
			nFirstAddXColInBlock = -1;
			continue;
		}
		
		if(!col.IsEvenSampling(&dX0, &dInc) || is_missing_value(dX0) )
			continue;
		
		if( nFirstAddXColInBlock > -1 && _compare_implicit_x(wks.Columns(nFirstAddXColInBlock), col) ) 
		{
			if(!bSelect || 	_check_two_cols_always_in_same_selection(nFirstAddXColInBlock, ii, vC1, vC2))   
				continue;
		}
		
		///---Sim 09-28-2009 QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		//vAddXIndex[ii] = 1;
		vAddXIndex[vAddXIndex.GetSize()-1] = 1;
		///---END QA81-10800-P1 FIX_ADD_X_COL_IF_SEL_RANGE
		vX0.Add(dX0);
		vXInc.Add(dInc);
		bAddXCol = true;
		nFirstAddXColInBlock = ii;	
	}
}
///end ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL  
///end SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
	
static void _separate_ID_for_wks_param_and_user_param(vector<int>& vnIDs, vector<int>& vnParams, vector<int>& vnUserParams)
{
	int nSize = vnIDs.GetSize();
	for(int ii = 0; ii < nSize; ii++)
	{
		//wks params
		if(vnIDs[ii] > RCLT_COMMENT && vnIDs[ii] < RCLT_SAMPLE_RATE)
			vnParams.Add(vnIDs[ii]);
		
		//user parameters
		else if(vnIDs[ii] >= RCLT_UDL)
			vnUserParams.Add(vnIDs[ii]);
	}
}
///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
static bool _compare_implicit_x(const Column& colA, const Column& colB)
{
	
	double dAx0, dBx0, dAxInc, dBxInc;
	string strALName, strBLName, strAUnits, strBUnits;
	if(!colA.IsValid() || !colB.IsValid() )
		return false;
	if(! colA.IsEvenSampling(&dAx0, &dAxInc, &strAUnits, &strALName) )
		return false;
	if(! colB.IsEvenSampling(&dBx0, &dBxInc, &strBUnits, &strBLName) )
		return false;
	
	if( (dAx0 != dBx0) || (dAxInc != dBxInc) || (strALName != strBLName)|| (strAUnits != strBUnits) )
		return false;
	
	return true;
	
}

static bool _check_two_cols_always_in_same_selection(int nColA, int nColB, vector<int>& vC1,vector<int>& vC2 )
{
	int nSelections = vC1.GetSize();
	int nAIsIn, nBIsIn;
	for(int ii = 0; ii < nSelections; ii++)
	{
		///---Sim 09-28-2009 QA81-10800-P2 FIX_ADD_DIFF_X_COL_IF_SEL_FROM_DIFF_RANGE
		//nAIsIn =  (nColA >= vC1[ii] || nColA <= vC2[ii])? 1:-1;
		//nAIsIn =  (nColA >= vC1[ii] || nColA <= vC2[ii])? 1:-1;
		nAIsIn =  (nColA >= vC1[ii] && nColA <= vC2[ii])? 1:-1;
		nBIsIn =  (nColB >= vC1[ii] && nColB <= vC2[ii])? 1:-1;
		///---END QA81-10800-P2 FIX_ADD_DIFF_X_COL_IF_SEL_FROM_DIFF_RANGE
		
		if( nAIsIn * nBIsIn == -1 )
			return false;
	}
	return true;
}
///end ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL  

/*
//---Jake 06/27/07 STORE_USER_FILE_NAME
static void _set_only_file_name_attrib(TreeNode& trPath, LPCSTR lpcszFileName)
{
	string strOnlyFileName = GetFileName(lpcszFileName);
	trPath.SetAttribute(STR_ONLY_FILE_NAME_ATTRIB,strOnlyFileName);
}
//---end STORE_USER_FILE_NAME

//----Jake 06/28/07 SET_PATH_STRING_TO_GETNTREE
static void _set_path(TreeNode& trPath)
{
	string		strPath = trPath.strVal;
	int nID = okutil_cvt_str_to_predefined_type(strPath);
	if( nID != PDS_INVALID && nID != PDS_USER)
	{
		strPath = cvt_predefined_path_to_real_path(strPath);
		string strFileName;
		trPath.GetAttribute(STR_ONLY_FILE_NAME_ATTRIB,strFileName);
		strPath = GetFilePath(strPath) + strFileName;
		trPath.strVal = strPath;
	}
	_set_only_file_name_attrib(trPath,strPath);
}
//----end SET_PATH_STRING_TO_GETNTREE
*/

void expASC(const Worksheet& iw, const int& type, const string& path, const int& overwrite, const int& select, const int& separator, const int& shortname, const int& longname, const int& units, const int& comment, const int& userparam, const int& sampinterv, const int& parameter, const int& rowlabel, const int& precision, const int& addxcol, const int& missing, const string& suffix)
{
			
	if(!iw.IsValid())
		XF_THROW(CER_NO_WORKSHEET);	
	
	if(iw.GetSystemParam(0) & WP_SHEET_HIERARCHY)
		XF_THROW(XFERR_CANNOT_EXP_REPORT_SHEET_TO_ASCII);
	//------------ CPY 10/25/06 WARN_REPLACE_ALREADY_EXISTED_AND_CHECK_PATH_AND_EXT
	// check extention
	string strFilePath = path;
	_check_add_file_ext(strFilePath, type);
	// add code to check basic path
	
	strFilePath = cvt_predefined_path_to_real_path(strFilePath);/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
	
	string strPath = GetFilePath(strFilePath);
	if(!strPath.IsPath())
	{
		/// Iris 07/04/2007 v8.0655 CREATE_PATH_IF_SPECIFIED_PATH_IS_NOT_EXISTED
		//XF_THROW(CER_INVALID_FILEPATH);
		//if( !CreateDirectory(strPath, NULL) )
		if( !CheckMakePath(strPath) ) /// Hong 02/22/08 v8.0810 FIX_EXPORT_FAIL_CREATE_PATH_IF_MULTI_LEVEL_NOT_EXIST
		{
			XF_THROW(CER_FAIL_TO_CREATE_PATH);
		}
		///end CREATE_PATH_IF_SPECIFIED_PATH_IS_NOT_EXISTED
	}
	//------------
	///Cheney 2006-10-26 NEED_FUNCTION_TO_CHECK_FILE_NAME_VALID
	//if(!strFilePath.IsFile())
		//XF_THROW(CER_INVALID_FILENAME);
	///end NEED_FUNCTION_TO_CHECK_FILE_NAME_VALID
	///Cheney 2007-3-15 FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
	//if( !_check_path_show_warnning(strFilePath) )
		//XF_THROW(CER_INVALID_FILEPATH);
	bool bAppend = false; ///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	///Kyle 07/06/2009 QA80-13755-P1 FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
	//if(g_bCheckOverWritten)
	///End FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
	{
		///Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
		//if( !_check_path_show_warnning(strFilePath) )
		///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
		//if( !_check_path_show_warnning(strFilePath, overwrite) )
		if( !_check_path_show_warnning(strFilePath, overwrite, bAppend) )
		///---END QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
		///End ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
			XF_THROW(CER_INVALID_FILEPATH);
	}
	///end FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
	//---
	
	vector<int> vColLower, vColUpper, vRowLower, vRowUpper;
	int r1, r2;
	int c1 = 0, c2 = iw.GetNumCols() - 1;
	
	vector<int> vr1, vc1, vr2, vc2;  ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL
	
	bool bExportData = true;
	if(!select)
	{
		///Cheney 2006-11-9 DIFFERENT_CASE_USE_DIFFERENT_OPTION
		iw.GetRange(r1, r2, c1, c2, GDR_NO_ADJUST, GDR_SKIP_MISSING_BLANK);
		if(r2 == -1)
			bExportData = false;
		///end DIFFERENT_CASE_USE_DIFFERENT_OPTION
		vRowLower.Add(r1);
		vRowUpper.Add(r2);
		vColLower.Add(c1);
		vColUpper.Add(c2);
	}
	else
	{
		///Cheney 2006-11-9 DIFFERENT_CASE_USE_DIFFERENT_OPTION
		iw.GetRange(r1, r2, c1, c2, GDR_NO_ADJUST, GDR_NO_ADJUST);
		///end DIFFERENT_CASE_USE_DIFFERENT_OPTION
		//vector<int> vr1, vc1, vr2, vc2;  ///Justin 2007-2-14 ADD_LONGNAME_AND_UNITS_FOR_SAMPLE_INTERVAL 
		int nRanges = iw.GetSelectedRange(vr1, vc1, vr2, vc2);
		if(nRanges < 1)
			XF_THROW(XFERR_NO_DATA_SELECT);
		
		///Cheney 2006-11-9 DIFFERENT_CASE_USE_DIFFERENT_OPTION
		//if select whole column, should check if missing, then set rupper from -1 to last non-missing
		bExportData = _check_if_whole_col_or_block_missing_and_correct_range(iw, vr1, vr2, vc1, vc2);
		///end DIFFERENT_CASE_USE_DIFFERENT_OPTION
		get_select_range_bounds(vc1, vc2, c2, vColLower, vColUpper);
		get_select_range_bounds(vr1, vr2, r2, vRowLower, vRowUpper);
	}
	
	//get show label, to support hidden label not export
	vector<int> vnIDs;
	wks_get_show_labels(iw, vnIDs);
	
	vector<int> vnParams, vnUserParams;
	_separate_ID_for_wks_param_and_user_param(vnIDs, vnParams, vnUserParams);
	
	string strSep;
	_get_separator(strSep, type, separator);
	
	file expFile;
	///---Sim 07-08-2009 QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	//if(!expFile.Open(strFilePath, file::modeCreate | file::modeWrite))
		//XF_THROW(XFERR_FAIL_OPEN_FILE);
	UINT nOpenFlags = file::modeWrite;
	if ( !strFilePath.IsFile() || !bAppend )
		nOpenFlags |= file::modeCreate;
	
	if(!expFile.Open(strFilePath, nOpenFlags))
		XF_THROW(XFERR_FAIL_OPEN_FILE);
	
	if ( bAppend )
		expFile.SeekToEnd();
	///---END QA80-13891 SUPPORT_APPEND_TO_EXISTING_FILE
	
	///Cheney 2007-2-9 SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
	///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
	//bool bAddXCol = addxcol && sampinterv;
	bool bAddXCol = addxcol;
	///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
	vector<int> vAddXIndex;
	vector vX0, vXInc;
	if(bAddXCol)
	{
		//_check_add_x_col(iw, select, bAddXCol, vAddXIndex, vX0, vXInc, vColLower, vColUpper);
		_check_add_x_col(iw, select, bAddXCol, vAddXIndex, vX0, vXInc, vColLower, vColUpper, vc1, vc2);  //justin
	}
	///end SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
	
	//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
	waitCursor wc; 
	string strInfo;
	
	//export wks info, should check if hidden, not export
	if(shortname && iw.IsHeaderShown()) 
	{
		strInfo = _get_wks_basicinfo(iw, select, vColLower, vColUpper, strSep, type, ROW_LABEL_SHORTNAME, bAddXCol? vAddXIndex : NULL);
		CHECK_STRING_WRITE_TO_FILE(strInfo, rowlabel, "Short Name", strSep, expFile)
	}
	//--- Cheney 2007-4-19 PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	//if(longname && iw.IsLabelTypeShown(true, RCLT_LONG_NAME)) 
	/// Hong 11/19/09 QA80-14696-P2 FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
	//if(longname && iw.IsLabelTypeShown(RCLT_LONG_NAME, NULL, true)) 
	if ( longname && -1 != find_in_list(RCLT_LONG_NAME, vnIDs, false) )
	/// end FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
	///end PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	{
		strInfo = _get_wks_basicinfo(iw, select, vColLower, vColUpper, strSep, type, ROW_LABEL_LONGNAME, bAddXCol? vAddXIndex : NULL);
		CHECK_STRING_WRITE_TO_FILE(strInfo, rowlabel, "Long Name", strSep, expFile)
	}
	//--- Cheney 2007-4-19 PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	//if(units && iw.IsLabelTypeShown(true, RCLT_UNIT)) 
	/// Hong 11/19/09 QA80-14696-P2 FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
	//if(units && iw.IsLabelTypeShown(RCLT_UNIT, NULL, true)) 
	if ( units && -1 != find_in_list(RCLT_UNIT, vnIDs, false) )
	/// end FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
	///end  PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	{
		strInfo = _get_wks_basicinfo(iw, select, vColLower, vColUpper, strSep, type, ROW_LABEL_UNITS, bAddXCol? vAddXIndex : NULL);
		CHECK_STRING_WRITE_TO_FILE(strInfo, rowlabel, "Units", strSep, expFile)
	}
	//--- Cheney 2007-4-19 PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	//if(comment && iw.IsLabelTypeShown(true, RCLT_COMMENT)) 
	/// Hong 11/19/09 QA80-14696-P2 FAIL_EXP_LN_IF_BOOK_IS_HIDDEN
	//if(comment && iw.IsLabelTypeShown(RCLT_COMMENT, NULL, true)) 
	if ( comment && -1 != find_in_list(RCLT_COMMENT, vnIDs, false) ) 
	/// end FAIL_EXP_LN_IF_BOOK_IS_HIDDEN 
	///end PROTOTYPE_OF_IS_LABEL_TYPE_SHOWN_CHANGED
	{
		strInfo = _get_wks_basicinfo(iw, select, vColLower, vColUpper, strSep, type, ROW_LABEL_COMMENTS, bAddXCol? vAddXIndex : NULL);
		CHECK_STRING_WRITE_TO_FILE(strInfo, rowlabel, "Comments", strSep, expFile)
	}
	if(userparam && vnUserParams.GetSize() > 0) 
	{
		_export_user_params(expFile, iw, select, vColLower, vColUpper, strSep, type, rowlabel, vnUserParams, bAddXCol? vAddXIndex : NULL);
	}
	///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
	//if(sampinterv && !bAddXCol) 
	if(sampinterv) 
	///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
	{
		vector<uint> vIndex;
		//check if hidden
		if(vnIDs.Find(vIndex, RCLT_SAMPLE_RATE) > 0) 
			///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
			//_export_sample_interv(expFile, iw, select, vColLower, vColUpper, strSep, rowlabel);
			_export_sample_interv(expFile, iw, select, vColLower, vColUpper, strSep, rowlabel, bAddXCol? vAddXIndex : NULL);
			///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
	}
	if(parameter && vnParams.GetSize() > 0) 
	{
		_export_wks_params(expFile, iw, select, vColLower, vColUpper, strSep, type, rowlabel, vnParams, bAddXCol? vAddXIndex : NULL);
	}
	///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
	
	///Cheney 2007-4-16 IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
	string strWksName = iw.GetName();
	///end IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
	
	int nErr;
	
	//export data
	if(bExportData)  // if all Ranges missing, no need to export data
	{
		///Cheney 2007-4-16 IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
		//string strWksName = iw.GetName();
		///end IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
		WorksheetPage wb;
		iw.GetParent(wb);
		string strWbName = wb.GetName();
		bool bAddQuotes = (type == FILE_TYPE_CSV) ? true : false;
		
		DWORD dwCtrl = 0;
		if(precision)
			dwCtrl |= GDAT_FULL_PRECISION;
		if(missing)
			dwCtrl |= GDAT_MISSING_AS_DASHDASH;
		/// Hong 10/16/09 QA80-13230-P5 EXPORT_ASCII_FAIL_WITH_SHEET_NAME_ALL_NUMERIC
		//nErr =
		//export_ascii_data(&expFile, strWbName, strWksName, vRowLower.GetSize(), vRowLower, vRowUpper, 
		//					vColLower.GetSize(), vColLower, vColUpper, strSep, bAddQuotes, 
		//					rowlabel, bAddXCol? vAddXIndex:NULL, bAddXCol? vX0:NULL, bAddXCol? vXInc:NULL, dwCtrl);
		string			strWksRange;
		iw.GetRangeString(strWksRange);
		/// Hong 11/24/09 QA80-14724 EXP_CSV_NEED_SUBFIX_FOR_PHONE_AND_ZIP_CODE
		//nErr =
		//export_ascii_data(&expFile, strWksRange, vRowLower.GetSize(), vRowLower, vRowUpper, 
		//					vColLower.GetSize(), vColLower, vColUpper, strSep, bAddQuotes, 
		//					rowlabel, bAddXCol? vAddXIndex:NULL, bAddXCol? vX0:NULL, bAddXCol? vXInc:NULL, dwCtrl);
		LPCSTR			lpcszSuffix = NULL;
		if ( !suffix.IsEmpty() )
			lpcszSuffix = suffix;
		nErr = export_ascii_data(&expFile, strWksRange, vRowLower.GetSize(), vRowLower, vRowUpper, 
							vColLower.GetSize(), vColLower, vColUpper, strSep, bAddQuotes, 
							rowlabel, bAddXCol? vAddXIndex:NULL, bAddXCol? vX0:NULL, bAddXCol? vXInc:NULL, dwCtrl, lpcszSuffix);
		/// end EXP_CSV_NEED_SUBFIX_FOR_PHONE_AND_ZIP_CODE
		/// end EXPORT_ASCII_FAIL_WITH_SHEET_NAME_ALL_NUMERIC
		///Cheney 2007-4-16 IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
		/////Jasmine 04/13/07 PRINT_XF_MSG_TO_SCRIPT_WINDOW
		//string strMessage;
		//strMessage.Format("Export worksheet %s to ASCII file %s", strWksName, strFilePath);
		//xf_print_msg(strMessage);
		///End PRINT_XF_MSG_TO_SCRIPT_WINDOW
		///end IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
	}
	expFile.Close();
	///Cheney 2007-4-16 IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
	string strMessage;
	///Folger 05/24/07 MODIFY_OUTPUT_INFO_MSG
	//strMessage.Format("Export worksheet %s to ASCII file %s", strWksName, strFilePath);
	///Folger 06/05/07 ADD_FAILED_MSG
	if (nErr == 0)
		///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
		if ( bAppend )
			ocu_load_msg_str(XF_EXPORT_APPEND_SUCCESS, &strMessage, strWksName, NULL, strFilePath);
		else
			ocu_load_msg_str(XF_EXPORT_SUCCESS, &strMessage, strWksName, NULL, strFilePath);
		///---END QA80-13891 REDO_EXP_ASC_OVERWRITE
	else
		ocu_load_msg_str(XF_EXPORT_FAILED, &strMessage, strWksName, NULL, strFilePath);
	///End ADD_FAILED_MSG
	///End MODIFY_OUTPUT_INFO_MSG
	
	///Jake 06/28/07 SUPPORT_DEFAULT_NAME
	//----Jake 06/27/07 GET_COMBO_LIST_FROM_REGISTRY
	//char szLastXFName[MAXFULLPATH];
	//LT_get_str(LTVAR_LAST_XF, szLastXFName, MAXFULLPATH);
	update_recent_path_list(path);//update path to registry
	//----end GET_COMBO_LIST_FROM_REGISTRY
	///end SUPPORT_DEFAULT_NAME
	
	///Folger 04/16/07 REPLACE_BY_OKOC_OUT_MSG
	//xf_print_msg(strMessage);
	okoc_out_msg(strMessage, 'I');
	///End REPLACE_BY_OKOC_OUT_MSG
	///end IF_ONLY_EXPORT_LABEL_SHOULD_ALSO_SHOW_MSG
}

//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 expASC_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return expASC_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	//--- CPY 11/3/06 EVENT1_STR_ERR_MSG_REWRITE
	/*
	if(nEventID > 0)
	{
		string strPath = GetFilePath(trGetN.path.strVal);
		bool bRet1 = strPath.IsPath();
		if(!bRet1)
			strErrMsg = CER_INVALID_FILEPATH;
		///Cheney 2006-10-26 NEED_FUNCTION_TO_CHECK_FILE_NAME_VALID
		//bool bRet2 = trGetN.path.strVal.IsFile();
		bool bRet2 = true;
		///end NEED_FUNCTION_TO_CHECK_FILE_NAME_VALID
		///Cheney 2006-11-3 bOkEnable_AND_StrErrMessage_SHOULD_BOTH_USE_IN_NEW_DESIGN
		if(!(bOKEnable = bRet1 && bRet2))
			return false;
		///end bOkEnable_AND_StrErrMessage_SHOULD_BOTT_USE_IN_NEW_DESIGN
	}
	
	//when init or change type, need update file path.
	bool bUpdatePath = (nEventID == GETNE_ON_INIT || lstrcmp(lpcszNodeName, STR_NODE_TYPE) == 0 || lstrcmp(lpcszNodeName, STR_NODE_PATH) == 0) ? true : false;
	
	if(nEventID == GETNE_ON_INIT)
		trGetN.path.strVal.Empty();
	
	int nCtrl;
	if(lstrcmp(lpcszNodeName, STR_NODE_TYPE) == 0)
		nCtrl = PATH_CONSISTENT_WITH_TYPE;
	else if(lstrcmp(lpcszNodeName, STR_NODE_PATH) == 0)
		nCtrl = TYPE_CONSISTENT_WITH_PATH;
	
	if(!_gui_check_update_path(trGetN, bUpdatePath, nCtrl))
		strErrMsg = STR_ERR_FAIL_UPDATE_PATH;
		
	_update_tree_shown(trGetN);
	
	return false;
	*/
	///Cheney 2007-3-15 FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
	//if use button, will warning if over written
	if(lstrcmpi(lpcszNodeName, STR_NODE_PATH) == 0 )
	{
		/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		/*
		///Jake 06/28/07 MOVE_CODE_TO_GLOBAL_FUN
		//----Jake 06/27/07 GET_COMBO_LIST_FROM_REGISTRY
		//
		//string		strPath = trGetN.path.strVal;
		//int nID = okutil_cvt_str_to_predefined_type(strPath);
		//if( nID != PDS_INVALID && nID != PDS_USER)
		//{
			//strPath = cvt_predefined_path_to_real_path(strPath);
			//string strFileName;
			//trGetN.path.GetAttribute(STR_ONLY_FILE_NAME_ATTRIB,strFileName);
			//strPath = GetFilePath(strPath) + strFileName;
			//trGetN.path.strVal = strPath;
		//}
		//_set_only_file_name_attrib(trGetN,strPath);
		////----end GET_COMBO_LIST_FROM_REGISTRY
		//
		TreeNode trPath = trGetN.path;
		tree_check_set_real_path(trPath);
		tree_set_only_file_name_attrib(trPath,trPath.strVal);
		/////Jake 06/28/07 MOVE_CODE_TO_GLOBAL_FUN
		*/
		///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
		///Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
		//g_bCheckOverWritten = nEventID == ONODETYPE_STR_BUTTON ? false : true;
		///Kyle 07/06/2009 QA80-13755-P1 FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
		//g_bCheckOverWritten = true;
		///End FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
		///End ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
	}
	///end FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
	//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
	if(nEventID == GETNE_ON_THEME) //if from theme, should auto check again
	{
		Worksheet	wks;
		okxf_resolve_string_get_origin_object(trGetN.iw.strVal, &wks);
		if(!wks.IsValid())
		{
			strErrMsg = CER_NO_WORKSHEET;
			bOKEnable = false;
			return false;
		}		
		_auto_check_select_range(trGetN, wks);
	}
	///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
	
	///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
	/*
	///Cheney 2007-2-9 SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
	bool bRedraw = false;
	if(lstrcmpi(lpcszNodeName, "sampinterv") == 0)
	{
		trGetN.addxcol.Show = trGetN.sampinterv.nVal;
		bRedraw = true;
	}
	///end SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
	*/
	///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
	
	bOKEnable = _check_err_condition(trGetN, nEventID==GETNE_ON_INIT || nEventID==GETNE_ON_THEME? NULL:lpcszNodeName, strErrMsg);
	///Cheney 2006-11-3 IF_PATH_CHANGE_ALSO_NEED_UPDATE_TREE_SHOWN
	//if(nEventID == GETNE_ON_INIT || lstrcmpi(lpcszNodeName, STR_NODE_TYPE) == 0)
	///Cheney 2006-11-10 RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
	if(lstrcmpi(lpcszNodeName, STR_NODE_SEP) == 0)
		trGetN.separator.SetAttribute(STR_ATTRIB_OLD_SEP, trGetN.separator.nVal);
	///end RESTORE_SEP_IF_CHANGE_TYPE_TO_CSV_THEN_BACK_AGAIN
	if(nEventID == GETNE_ON_INIT || lstrcmpi(lpcszNodeName, STR_NODE_TYPE) == 0 || lstrcmpi(lpcszNodeName, STR_NODE_PATH) == 0)
	///end IF_PATH_CHANGE_ALSO_NEED_UPDATE_TREE_SHOWN
		return _update_type_related_nodes(trGetN);
	
	///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
	//return bRedraw;// no need to redraw DynaControls
	return false;
	///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
	//--- end EVENT1_STR_ERR_MSG_REWRITE

}

int expASC_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false; 
}
//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 expASC_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	///Kyle 07/06/2009 QA80-13755 ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
	if(is_xf_startup(nGetNDialog, dwCntrl))
	{
		trGetN.path.SetAttribute(STR_DLG_OPTIONS_ATTRIB, FDLG_SUPPRESS_WARNING_SAVE_TO_EXISTING);
	}
	///End ADD_OPTION_TO_FORCE_OVERWRITE_OF_OUTPUT_WITHOUT_PROMPT
	if(nGetNDialog > -1)
	{
		//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
		//set select all
		TreeNode trShortName = trGetN.shortname;
		trShortName.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_CHECK_CONTROL); 
		///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
		Worksheet	wks;
		okxf_resolve_string_get_origin_object(trGetN.iw.strVal, &wks);
		if(!wks.IsValid())
		{
			nRet = XFEVT_ABORT;
			warning_msg_box(CER_NO_WORKSHEET, true);
			return;
		}
		if(wks.GetSystemParam(0) & WP_SHEET_HIERARCHY)
		{
			nRet = XFEVT_ABORT;
			warning_msg_box(XFERR_CANNOT_EXP_REPORT_SHEET_TO_ASCII, true);
			return;
		}
		
		///---Sim 06-18-2007 ADD_SHOW_DLG_CHECK_BOX_TO_SAVE_AS_DLG
		
		///Cheney 2006-11-3 MOVE_AUTO_CHECK_SELECT_FROM_EVENT1_TO_BEFORE_EXCUTE
		//auto check export selection if select data, if use theme, also need to auto check
		//only from script window and no theme used will not auto check.
		//also need to handle path when get path from theme except from script window and no theme
		int nRanges = 0;
		if(!(dwCntrl & LTXF_FROM_GUI_PROMPT) || (dwCntrl & LTXF_THEME_USED))
		{
			//--- Cheney 2007-1-19 SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
			//trGetN.select.nVal = 1;
			//vector<int> vr1, vc1, vr2, vc2;
			//nRanges = wks.GetSelectedRange(vr1, vc1, vr2, vc2);
			//if(nRanges < 1 || (nRanges == 1 && vr1[0] == vr2[0] && vc1[0] == vc2[0])) //if only one cell select, not check
				//trGetN.select.nVal = 0;
			nRanges = _auto_check_select_range(trGetN, wks);
			
			///---Sim 06-18-2007 NO_USED design was changed
			/*
			//trim file name from path then set it to wks name
			if((dwCntrl & LTXF_THEME_USED) && !trGetN.path.strVal.IsEmpty())
			{
				trGetN.path.strVal = GetFilePath(trGetN.path.strVal) + wks.GetName();
			}
			///end SUPPORT_EXPORT_COLUMN_INDEX_AND_USER_PARAMETER
			*/
			///---END NO_USED design was changed
		}
		///end MOVE_AUTO_CHECK_SELECT_FROM_EVENT1_TO_BEFORE_EXCUTE
		
		//if(nGetNDialog == 0)
		//{
		string strFileName = trGetN.path.strVal;
		
		if ( LTXF_FROM_GUI_MENU & dwCntrl ) // if from menu, ignore default value fname$
			strFileName = "";
		
		//if apply theme, should ask user input a file name but not pop-up a dlg
		//if(is_empty_or_unassigned(trGetN.path.strVal) || (dwCntrl & LTXF_THEME_USED))
		if( is_empty_or_unassigned(strFileName) )
		{
			/*
			TreeNode trType = trGetN.type;
			string strExt;
			_get_file_ext(strExt, trType.nVal);
			strExt = trType.nVal == FILE_TYPE_ALL ? "*.*" : STR_STAR_POINT + strExt;
			string strFileCtrl = trType.nVal == FILE_TYPE_ALL ? STR_LEFT_SQUARE_BRACKET + "All Files" + strExt + STR_RIGHT_SQUARE_BRACKET + strExt
										: STR_LEFT_SQUARE_BRACKET + strExt + STR_RIGHT_SQUARE_BRACKET + strExt;
			StringArray saFileCtrl;
			saFileCtrl.Add(strFileCtrl);
			string strWksName = wks.GetName();
			///---Sim 05-25-2007 GET_DEFAULT_FROM_ORIGIN_OPTIONS
			//string strPath = is_empty_or_unassigned(trGetN.path.strVal)? GetAppPath() : GetFilePath(trGetN.path.strVal);
			string strPath = is_empty_or_unassigned(trGetN.path.strVal)? 
						_get_default_path() : GetFilePath(trGetN.path.strVal);
			///---END GET_DEFAULT_FROM_ORIGIN_OPTIONS
			strPath = GetSaveAsBox(saFileCtrl, strPath, strWksName);
			*/
			string strWksName = wks.GetName();
			
			DWORD dwFlags = OPENBOX_FLAG_SUPPRESSPROMPT; ///---Sim 07-09-2009 QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
			int nFilesRet;
			///------ Folger 10/28/09 QA81-14541 EXPORT_CSV_SHOULD_OUT_MESSAGE_ABOUT_FILE_LOCATION
			SystemDefaultFileExtTempChange		tempChange(STR_EXPORT_ASCII_FILE_GROUP, trGetN.type.nVal + 1);
			///------ End EXPORT_CSV_SHOULD_OUT_MESSAGE_ABOUT_FILE_LOCATION
			if ( 0 != nGetNDialog )
			{
				int nShowOptionsDlg = 1;
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, _L("ASCII Data File"),
				//	0, NULL, strWksName, _L("Show Options Dialog"), &nShowOptionsDlg);
				///---Sim 07-09-2009 QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
				//nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, NULL,
					//0, NULL, strWksName, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, NULL,
					dwFlags, NULL, strWksName, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				///---END QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nRet = (nShowOptionsDlg ? XFEVT_PROCEED : XFEVT_PROCEED_NO_DLG);
			}
			else
			{
				//nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, _L("ASCII Data File"), 0, NULL, strWksName);
				///---Sim 07-09-2009 QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
				//nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, NULL, 0, NULL, strWksName); /// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nFilesRet = get_saveas_box_by_file_group(strFileName, STR_EXPORT_ASCII_FILE_GROUP, NULL, dwFlags, NULL, strWksName); /// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				///---END QA80-13891 EXPORT_FILE_SUPPRESS_FILE_EXIST_PROMPT
			}
			
			///Cheney 2006-11-24 IF_USER_CANCEL_SHOULD_ABOUT_AND_SHOW_WARN
			//if(strPath.IsEmpty())
			if ( 0 == nFilesRet )
			{
				nRet = XFEVT_ABORT;
				//no need to send a warning
				//warning_msg_box(XFERR_UI_USER_CANCEL, false);
				return;
			}
			///end IF_USER_CANCEL_SHOULD_ABOUT_AND_SHOW_WARN
			//trGetN.path.strVal = strPath;
			trGetN.path.strVal = strFileName;
			/// Iris 07/03/2007 v8.0654 USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
			//tree_set_only_file_name_attrib(trGetN.path,strFileName);//---Jake 06/27/07 STORE_USER_FILE_NAME 
			///end USAGE_OF_BROWSER_COMBO_NOT_CONSISTENT_IN_FILE_AND_PATH_CONTROL
			// reset file type
			string strFile, strExt;
			separate_file_name_ext(strFileName, strFile, strExt);
			trGetN.type.nVal = _find_type_index_by_ext(trGetN.type, strExt);
			
			///Cheney 2007-3-15 FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
			//Dialog will warning if over written
			///Kyle 07/06/2009 QA80-13755-P1 FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
			//g_bCheckOverWritten = false;
			///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
			//trGetN.overwrite.nVal = overwrite_replace; ///Kyle 07/08/2009 QA80-13755-S1 FIX_ASK_OVERWRITE_TWICE
			///---END QA80-13891 REDO_EXP_ASC_OVERWRITE
			///End FAIL_TO_HANDLE_OVERWRITE_OPTION_ON_THE_SECOND_TIME_EXPORTING
			///end FIX_BUG_OF_WARNING_TWICE_WHEN_OVER_WRITTEN_FILE
		}
		//}
		
		if(trGetN.type.nVal == FILE_TYPE_CSV) //if CSV, should not use default separator
			trGetN.separator.nVal = SEP_COMMA;
		///---END ADD_SHOW_DLG_CHECK_BOX_TO_SAVE_AS_DLG
		
		if(nGetNDialog > 0)
		{
			//---- CPY 10/25/06 better show it but disable
			//trGetN.iw.Show = 0;
			trGetN.iw.Enable = 0;
			//----
			
			///---Sim 06-18-2007 NO_USED design was changed
			/*
			///Cheney 2006-11-6 HIDE_DATA_SELECT_NODE_WHEN_NO_DATA_SELECT, because input data's interactive button disable
			if(nRanges < 1 && ( !(dwCntrl & LTXF_FROM_GUI_PROMPT) || nGetNDialog < 1)) //if input "expASC -d", should not hide it
				trGetN.select.Show = false;
			///end HIDE_DATA_SELECT_NODE_WHEN_NO_DATA_SELECT
			*/
			///---END NO_USED design was changed
			
			///---Sim 12-10-2007 CHANGE_ADD_X_COL_DESIGN_BY_MAX
			/*
			///Cheney 2007-2-9 SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
			trGetN.addxcol.Show = trGetN.sampinterv.nVal;
			///end SUPPORT_EXPORT_SAMPLE_INTERVAL_AS_X_COL
			*/
			///---END CHANGE_ADD_X_COL_DESIGN_BY_MAX
			///---Sim 07-09-2009 QA80-13891 REDO_EXP_ASC_OVERWRITE
			if ( overwrite_ask == trGetN.overwrite.nVal )
				trGetN.overwrite.nVal = overwrite_replace;
			///---END QA80-13891 REDO_EXP_ASC_OVERWRITE
		}
	}
}
//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 expASC_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
