/*------------------------------------------------------------------------------*
 * File Name:				 													*
 * Creation: 																	*
 * Purpose: OriginC Source C file												*
 * Copyright (c) ABCD Corp.	2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010		*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 * Hong 12/30/06 SAVE_TIME_IN_ORGANIZER_USE_LOCAL_TIME							*
 * Hong 01/17/07 ADD_SPARKLINE_TO_IMPORT_WIZARD									*
 * Sim 03-29-2007 FIX_D&D_TO_GRAPH												*
 * AW 04/18/07 QA80-9646 v8.0604 MORE_ON_ASCII_IMPORT_MESSAGE					* 
 * Sim 05-23-2007 QA80-9427-P2 FIX_RANGE_INFO_FOR_NON_NUMERIC_DATA				*
 * Sim 05-28-2007 SCAN_FOR_NUM_COLS_ON_CHANGE_HEADER_LINES						*
 * Sim 08-06-2007 SUPPORT_SMART_SPARKLINE										*
 * EJP 2008-02-26 v8.0812 QA80-4808 STOP_IMPORT_IF_ANY_COLS_ARE_LOCKED			*
 *	Hong 08/27/08 QA80-9206 v8.0833 FIX_FAIL_GET_ACTUAL_NUM_COLIMN_AS_PARTIAL_COUNTED
 *	CPY 5/14/08 QA70-11544 IMPORTWIZ_SET_FORMAT_TO_DATE_FROM_WKSCNTRL_NOT_WORKING
 *	Hong 07/21/08 QA80-11869 FIX_FILTER_SCRIPT_FAIL_RUN_WHEN_DRAG_AND_DROP_EXCEPT_ASCII
 *	Kyle 01/04/2009 QA70-12890-P4 CENTRALIZE_CODE_TO_GET_AND_UPDATE_CUSTOM_DATE_FORMAT
 *	Hong 01/09/09 v8.0995 CORRECT_IMPASC_ERROR_RETURN_CHECKING					*
 *	Hong 09/02/09 QA80-14252 FIX_NUMBER_COLS_NOT_USED_IF_PARTIAL_IS_SET_FIRST	*
 *	Hong 10/09/09 QA80-14252-P1 FIX_ORIGIN_FREEZE_IF_NUMBER_COLS_SET_TO_ONE_WITH_PARTIAL_ENABLE
 *	Sim 02-04-2010 QA81-15063 MOVE_IMP_FILE_INFO_OUT_FROM_COL_USER_INFO_TREE	*
 *	Sim 02-05-2010 QA81-15063 ROLL_BACK_MOVE_COL_INFO_OUT_OF_USER_TREE			*
 *------------------------------------------------------------------------------*/
 
////////////////////////////////////////////////////////////////////////////////////
// Including the system header file Origin.h should be sufficient for most Origin
// applications and is recommended. Origin.h includes many of the most common system
// header files and is automatically pre-compiled when Origin runs the first time.
// Programs including Origin.h subsequently compile much more quickly as long as
// the size and number of other included header files is minimized. All NAG header
// files are now included in Origin.h and no longer need be separately included.
//
// Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h
// system header file.
#include <Origin.h>
////////////////////////////////////////////////////////////////////////////////////

#include "XFunctionEx.h" //<XFbase.h>
#include "iwbase.h"// Hong 8/21/06 CLEAN_HEADER_FILE
#include "fu_utils.h" /// Hong 8/18/06 REMOVE_TO_FU_UTILS
#include "impwiz.h"//Hong 8/07/06 MOVE_TO_IMPWIZ_H


////////////////////////////////////////////////////////////////////////////////////
// Include your own header files here.

//#define _MSG_INT(str, v) ///---Sim 08-17-2006 REMOVE_TO_FU_UTILS

////////////////////////////////////////////////////////////////////////////////////
// Start your functions here.
///---Sim 08-04-2006 COMMON_FUNC_ON_BASE_CLASS
/*
bool fuGetHdrSave(TreeNode &trFilter, int &iFirstLine, int &iNumLines)
{
	if( !trFilter.Common.HdrSaveFirstLine || !trFilter.Common.HdrSaveNumLines )
		return false;
	iFirstLine = trFilter.Common.HdrSaveFirstLine.nVal;
	iNumLines = trFilter.Common.HdrSaveNumLines.nVal;
	return true;
}
*/

///---Sim 08-17-2006 REMOVE_TO_FU_UTILS
/*
BOOL fuGetASCIMP(TreeNode& trFilter, ASCIMP& ascimp, BOOL bGetCommonNode = FALSE)
{
	_MSG_INT(fuGetASCIMP, ascimp.iDelimited)
	
	TreeNode trASCIMP = trFilter.GetNode("ASCIMP");
	if( trASCIMP )
	{
		ascimp = trASCIMP;
		if( bGetCommonNode )
		{
			ascimp.iMode = trFilter.Common.ImportMode.nVal;
			ascimp.iRenameWks = trFilter.Common.RenameWks.nVal;
			ascimp.iPartial = trFilter.Common.Partial.nVal;
			ascimp.iPartialC1 = trFilter.Common.PartialC1.nVal;
			ascimp.iPartialC2 = trFilter.Common.PartialC2.nVal;
			ascimp.iPartialR1 = trFilter.Common.PartialR1.nVal;
			ascimp.iPartialR2 = trFilter.Common.PartialR2.nVal;
			ascimp.iSkipRows = tree_node_get_int(trFilter.Common.SkipRows, 0); /// EJP 07-23-2003 v7.0631 QA70-4575 ADD_SKIPROWS_TO_BINIMP
			/// EJP 07-19-2004 v8.0911 QA70-6555 SUPPORT_WORKBOOK_IMPWIZ
			#if _OC_VER >= 0x0800
			ascimp.flags = tree_node_get_int(trFilter.Common.Flags, 0);
			#endif // _OC_VER >= 0x0800
			/// end SUPPORT_WORKBOOK_IMPWIZ
		}
		return TRUE;
	}
	return FALSE;
}
*/
///---END REMOVE_TO_FU_UTILS

/*
string fuGetDesignations(TreeNode& trFilter)
{
	string str;
	if( trFilter.Common.ColDesignations )
		str = trFilter.Common.ColDesignations.strVal;
	return str;
}
string fuGetFormats(TreeNode& trFilter)
{
	string str;
	if( trFilter.Common.ColFormats )
		str = trFilter.Common.ColFormats.strVal;
	return str;
}
BOOL fuGetRepetitive(TreeNode& trFilter)
{
	if( trFilter.Common.ColDesignationsRepetitive )
		return trFilter.Common.ColDesignationsRepetitive.nVal;
	return FALSE; // default is off
}
*/

///---Sim 08-08-2006 SPECIAL_FORMATS_IN_ASCII recover
/// AW 08/06/06 CHECK_IW_FILTER
///*
///---Sim 08-17-2006 REMOVE_TO_FU_UTILS
/*
BOOL fuGetCustomDate(TreeNode& tnFilter, string& strFormat)
{
	ASCIMP ai;
	if( fuGetASCIMP(tnFilter, ai) )
	{
		strFormat = ai.szDateFormat;
		strFormat.TrimLeft();
		strFormat.TrimRight();
		return (!strFormat.IsEmpty());
	}
	return FALSE;
}
*/
///---END REMOVE_TO_FU_UTILS
//*/
/// END CHECK_IW_FILTER
///---END SPECIAL_FORMATS_IN_ASCII

/*
// Get the worksheet columns' formats or designations setting, it actually modifies the current settings according filter setting
// This function is called when need to change part of the current settings according filter.
static int GetColumnSetting(string &strSetting, LPCSTR lpcszFilterSetting, int nTargetCol, int nNumCols, BOOL bRepetitive)
{
	if( strSetting.IsEmpty() )
		return 1; // Error

	// If the filter is NULL, just use strSetting
	if( !lpcszFilterSetting )
		return 0; // Success
	
	int nFilterLen = lstrlen(lpcszFilterSetting);
	int nSettingLen = strSetting.GetLength();
	
	if( nSettingLen - nTargetCol < nFilterLen )
		return 1;
	
	int nPos = 0;
	int nCurPosInFilterStr = 0;
	
	LPSTR lpszSetting = strSetting.GetBuffer(nSettingLen);
	LPSTR lpsz = lpszSetting + nTargetCol;
	
	while( nPos < nNumCols )
	{
		if( nCurPosInFilterStr >= nFilterLen )
			nCurPosInFilterStr = bRepetitive ? 0 : nFilterLen - 1;

		*(lpsz + nPos) = *(lpcszFilterSetting + nCurPosInFilterStr);
		
		nPos++;
		nCurPosInFilterStr++;
	}
	strSetting.ReleaseBuffer();
	
	return 0;
}
*/
///---END COMMON_FUNC_ON_BASE_CLASS


//class OC_REGISTERED IWASCII : public IWBase
class OC_REGISTERED IWASCII : public ImpWiz//Hong 8/07/06 MOVE_TO_IMPWIZ_H
{

public:
	IWASCII():ImpWiz() {m_iFilterType = FILTER_TYPE_ASCII} /// AW 08/03/06 MORE_ON_IW_IMPORT
	~IWASCII() {}
protected:
	virtual int GetColNumberFromFilter(TreeNode &trFilter) 
	{
		string str;
		int nCols;
		///---Sim 08-26-2006 GET_FILTER_BY_ID
		//ASCIMP ascimp;
		//fuGetASCIMP(trFilter, ascimp);
		//if( ascimp.iDelimited )
		if ( fuGetInt(trFilter, IDE_ASCIMP_DELIMITED, FALSE) )
		{
			// The wizard has been improved as far as scanning number of columns.
			// The user also now has the ability to set the number of columns.
			// Here we should assume the filter contains the correct number of columns.
			//nCols = ascimp.iNumColumns;
			nCols = fuGetInt(trFilter, IDE_ASCIMP_NUMCOLUMNS, 0);
		}
		else // fixed width, count tokens
		{
			// This counts the number of column widths
			// specified by the user.  This may be less than
			// the actual columns in the file since the last
			// width value is repeated until the end of line
			// is reached
			//str = ascimp.szFixedWidth;
			str = fuGetStr(trFilter, IDE_ASCIMP_COLWIDTHS, "");
			nCols = str.GetNumTokens(',');
		}
		///---END GET_FILTER_BY_ID
		return nCols;
	}

	///---Sim 08-04-2006 COMMON_FUNC_ON_BASE_CLASS
	//virtual int PrepareWksColsForImport(Layer &lyTarget, TreeNode &trFilter)
	//{
		//int nCols = 0;
		//string str;
	//
		//Worksheet wks(lyTarget);
		//if( !wks )
			//return IMPERR_PREPARE_WKS; // error, no worksheet
		//
		/////////////////////////////////////////////////////////
		//// The following (switch on filter type) will set nCols
		//// to the number of columns in the data file.
		//// This number may not always be correct, but should be
		//// sufficient for setting up the wks columns.
		////
		//// It may be easier/safer to use the ColDesignations or
		//// ColFormats setting in the filter.  I will look into
		//// this later.
		/////////////////////////////////////////////////////////
		///*
		//ASCIMP ascimp;
		//fuGetASCIMP(trFilter, ascimp);
		//if( ascimp.iDelimited )
		//{
			//// The wizard has been improved as far as scanning number of columns.
			//// The user also now has the ability to set the number of columns.
			//// Here we should assume the filter contains the correct number of columns.
			//nCols = ascimp.iNumColumns;
		//}
		//else // fixed width, count tokens
		//{
			//// This counts the number of column widths
			//// specified by the user.  This may be less than
			//// the actual columns in the file since the last
			//// width value is repeated until the end of line
			//// is reached
			//str = ascimp.szFixedWidth;
			//nCols = str.GetNumTokens(',');
		//}
		//*/
		//nCols = GetColNumberFromFilter(trFilter);
	//
		/////////////////////////////////////////////////////
		//// The following will adjust nCols based on the
		//// partial import settings.
		/////////////////////////////////////////////////////
		//int nFirstSourceCol = 0;
		//if( trFilter.Common.Partial.nVal )
		//{
			//nFirstSourceCol = trFilter.Common.PartialC1.nVal;
			//
			//if( nFirstSourceCol > trFilter.Common.PartialC2.nVal )
				//nCols -= nFirstSourceCol;
			//else
				//nCols = trFilter.Common.PartialC2.nVal - nFirstSourceCol + 1;
		//}
		//
		/////////////////////////////////////////////////////
		//// The following (switch on import mode) will
		//// adjust nCols based on the import mode.
		/////////////////////////////////////////////////////
		////int nFirstTargetCol = 0;
		//int nFirstTargetCol = 0;
		//int nNumExistingCols = wks.GetNumCols();
		//int nNewCols = 0;
		//switch( fuGetImportMode(trFilter) )
		//{
		//case ASCIMP_MODE_REPLACE_DATA:
		//case ASCIMP_MODE_APPEND_ROWS:
		//case ASCIMP_MODE_NEW_BOOKS:
		//case ASCIMP_MODE_NEW_SHEETS:
		//case ASCIMP_MODE_AUTO:
			//if( nCols > nNumExistingCols )
				//nNewCols = nCols - nNumExistingCols;
			//break;
		//case ASCIMP_MODE_APPEND_COLS:
			//nFirstTargetCol = wks_find_empty_column(wks);
			 //
			//if( nFirstTargetCol >= 0 )
			//{
				//nNewCols = nCols - (nNumExistingCols - nFirstTargetCol);
			//}
			//else // no empty columns
			//{
				//nFirstTargetCol = nNumExistingCols;
				//nNewCols = nCols;
			//}
			//break;
		//}
		//if( nNewCols > 0 )
		//{
			//Page pgTarget;
			//lyTarget.GetParent(pgTarget);
			//str.Format("work -a %d", nNewCols);
			//pgTarget.LT_execute(str);
		//}
	//
		//if( wks.IsWriteProtected(nFirstTargetCol, nFirstTargetCol + nCols) )
		//{
			//if( IDNO == MessageBox(GetWindow(),
				//_L("The data's target window has a locked column.\nDo you want to continue import?"),
				//_L("File Import"), MB_YESNO) )
			//{
				//return IMPERR_CANCEL_ON_LOCKED_COL;
			//}
		//}
		//
		//return IMPERR_NONE;
	//}
	///---END COMMON_FUNC_ON_BASE_CLASS
	
	///---Sim 08-04-2006 COMMON_FUNC_ON_BASE_CLASS
	//void SetColDesignations(Worksheet& wks, TreeNode& trFilter, int nFirstTargetCol, int nCols)
	//{
		/////////////////////////////////////////////////////////
		//// The follwoing will construct the designation and
		//// format strings.
		/////////////////////////////////////////////////////////
		//// Start with the designations and formats in the filter.
		//string strColDesig = fuGetDesignations(trFilter);
		////string strColFormat = fuGetFormats(trFilter); ///---Sim 08-04-2006 FIX_CUSTOM_DATE_FORMAT
	//
		/////---Sim 08-04-2006 NO_NEED_CUT_COL_DESIG_FORMAT_OF_FILTER
		///*
		//// If a partial import then remove the skipped columns	
		//int nFirstSourceCol = 0;
		//if( trFilter.Common.Partial.nVal )
			//nFirstSourceCol = trFilter.Common.PartialC1.nVal;
		//if( nFirstSourceCol )
		//{
			//strColDesig.Delete(0, nFirstSourceCol);
			//strColFormat.Delete(0, nFirstSourceCol);
		//}
		//*/
		/////---END NO_NEED_CUT_COL_DESIG_FORMAT_OF_FILTER
		//
		//bool bRepetitive = fuGetRepetitive(trFilter);
		//
		/////---Sim 08-03-2006 GET_CORRECT_COL_DESIG_AND_FORMAT
		///*
		//if( nFirstTargetCol ) // if not importing into the first column
		//{
			//string strExistColDesig = wks.GetColDesignations();
			//strExistColDesig.Delete(nFirstTargetCol, strExistColDesig.GetLength() - nFirstTargetCol);
			//strColDesig.Insert(0, strExistColDesig);
			//
			//string strExistColFormat = wks.GetColFormats();
			//strExistColFormat.Delete(nFirstTargetCol, strExistColFormat.GetLength() - nFirstTargetCol);
			//strColFormat.Insert(0, strExistColFormat);
		//}
		//if( strColDesig.GetLength() < wks.GetNumCols() && !bRepetitive )
		//{
			//string strTmp = wks.GetColFormats();
			//GetColumnSetting(strTmp, strColFormat, nFirstTargetCol, nCols, bRepetitive);
			//strColFormat = strTmp;
			//
			//strTmp = wks.GetColDesignations();
			//GetColumnSetting(strTmp, strColDesig, nFirstTargetCol, nCols, bRepetitive);
			//strColDesig = strTmp;
		//}
		//*/
//
		//if ( nFirstTargetCol + strColDesig.GetLength() >= wks.GetNumCols() )
		//{
			//// When the col designation have equal or more cols than the wks
			//// just add front of existing settings into current existing setting.
			//string strExistColDesig = wks.GetColDesignations();
			//strExistColDesig.Delete(nFirstTargetCol, strExistColDesig.GetLength() - nFirstTargetCol);
			//strColDesig.Insert(0, strExistColDesig);
		//}
		//else
		//{
			//// When the col designation strings have less cols than the wks
			//// we need to append the current existing settings to avoid having our
			//// last setting repeating and overwriting the existing settings.
			//string strTmp = wks.GetColDesignations();
			//GetColumnSetting(strTmp, strColDesig, nFirstTargetCol, nCols, bRepetitive);
			//strColDesig = strTmp;
		//}
		//
		/////---Sim 08-04-2006 FIX_CUSTOM_DATE_FORMAT
		///*
		//if ( nFirstTargetCol + strColFormat.GetLength() >= wks.GetNumCols() )
		//{
			//// When the col format have equal or more cols than the wks
			//// just add front of existing settings into current existing setting.
			//string strExistColFormat = wks.GetColFormats();
			//strExistColFormat.Delete(nFirstTargetCol, strExistColFormat.GetLength() - nFirstTargetCol);
			//strColFormat.Insert(0, strExistColFormat);
		//}
		//else
		//{
			//// When the col format strings have less cols than the wks
			//// we need to append the current existing settings to avoid having our
			//// last setting repeating and overwriting the existing settings.
			//string strTmp = wks.GetColFormats();
			//GetColumnSetting(strTmp, strColFormat, nFirstTargetCol, nCols, bRepetitive);
			//strColFormat = strTmp;
		//}
		//*/
		/////---END FIX_CUSTOM_DATE_FORMAT
		/////---END GET_CORRECT_COL_DESIG_AND_FORMAT
		//
		//
		//
		/////---Sim 08-04-2006 RECORD_COL_INFORMATION_THEN_BE_SET_ON_BASE_CLASS
		///*
		//if( !strColDesig.IsEmpty() )
			//wks.SetColDesignations(strColDesig, bRepetitive);
		//if( !strColFormat.IsEmpty() )
		//{
			//wks.SetColFormats(strColFormat, bRepetitive);
		//}
		//*/
		/////---END RECORD_COL_INFORMATION_THEN_BE_SET_ON_BASE_CLASS
		//
		/////---Sim 08-04-2006 FIX_CUSTOM_DATE_FORMAT
		///*
		//// add custom format to object level
		//string strCustomFormat;
		//if( fuGetCustomDate(trFilter, strCustomFormat) )
		//{
			//Column col;
			//int nIndex = strColFormat.Find('3', 0); // column formats - Date	(3)
			//while( nIndex >= 0 )
			//{
				//col = wks.Columns(nIndex);
				//if( col )
				//{
					//Tree tr;
					//if( info_get_section(col, tr, "system.display") )
					//{
						//tr.CustomFormat.strVal = strCustomFormat;
						//info_set_section(col, tr, "system.display");
					//}
					//col.SetSubFormat(LDF_OBJ_CUSTOM);
				//}
				//nIndex = strColFormat.Find('3', nIndex + 1);
			//}
			//
		//}
		//*/
		/////---END FIX_CUSTOM_DATE_FORMAT
		//
		////} ///---Sim 08-04-2006 RECORD_COL_INFORMATION_THEN_BE_SET_ON_BASE_CLASS
		//
		/////---Sim 08-04-2006 RECORD_COL_INFORMATION_THEN_BE_SET_ON_BASE_CLASS
		//m_bRepetitive = bRepetitive;
		//m_strColDesig = strColDesig;
		////m_strColFormat = strColFormat; ///---Sim 08-04-2006 FIX_CUSTOM_DATE_FORMAT
		/////---END RECORD_COL_INFORMATION_THEN_BE_SET_ON_BASE_CLASS
	//
	//}
	///---END COMMON_FUNC_ON_BASE_CLASS
	
	///---Sim 08-08-2006 SPECIAL_FORMATS_IN_ASCII recover
	/// AW 08/06/06 CHECK_IW_FILTER
	///*
	///---Sim 08-08-2006 PARTIAL_DESIGNATIOINS
	//virtual void SetColFormats(Worksheet& wks, TreeNode& trFilter, int nFirstTargetCol, int nCols)
	virtual void SetColFormats(Worksheet& wks, TreeNode& trFilter, int nFirstTargetCol, int nCols, int nFirstSourceCol) // = 0
	///---END PARTIAL_DESIGNATIOINS
	{
		///---Sim 08-08-2006 PARTIAL_DESIGNATIOINS
		//IWBase::SetColFormats(wks, trFilter, nFirstTargetCol, nCols);
		ImpWiz::SetColFormats(wks, trFilter, nFirstTargetCol, nCols, nFirstSourceCol);
		///---END PARTIAL_DESIGNATIOINS
		
		string strColFormat = wks.GetColFormats();
		
		// add custom format to object level
		string strCustomFormat;
		///---Sim 08-26-2006 GET_FILTER_BY_ID
		//if( fuGetCustomDate(trFilter, strCustomFormat) )
		if( fuGetRStr(trFilter, IDE_ASCIMP_DATEFORMAT, strCustomFormat) )
		///---END GET_FILTER_BY_ID
		{
			Column col;
			int nIndex = strColFormat.Find('3', 0); // column formats - Date	(3)
			while( nIndex >= 0 )
			{
				col = wks.Columns(nIndex);
				if( col )
				{
					//----- CPY 5/14/08 QA70-11544 IMPORTWIZ_SET_FORMAT_TO_DATE_FROM_WKSCNTRL_NOT_WORKING
					if(strCustomFormat.IsEmpty())
						col.SetSubFormat(LDF_SHORT);
					else
					{
					//----- end IMPORTWIZ_SET_FORMAT_TO_DATE_FROM_WKSCNTRL_NOT_WORKING
						Tree tr;
						if( info_get_section(col, tr, "system.display") )
						{
							tr.CustomFormat.strVal = strCustomFormat;
							info_set_section(col, tr, "system.display");
						}
						col.SetSubFormat(LDF_OBJ_CUSTOM);
					}//----- CPY 5/14/08 QA70-11544 IMPORTWIZ_SET_FORMAT_TO_DATE_FROM_WKSCNTRL_NOT_WORKING
				}
				nIndex = strColFormat.Find('3', nIndex + 1);
			}
			
		}
		
		m_strColFormat = wks.GetColFormats();
	}
	//*/
	/// END CHECK_IW_FILTER
	///---END SPECIAL_FORMATS_IN_ASCII
	
	virtual int ImportFile(Layer& lyTarget, int nFile, string& strFileName, TreeNode& trFilter, TreeNode& tnInfo, int nImportMode) 
	{
		/// Hong 07/21/08 QA80-11869 FIX_FILTER_SCRIPT_FAIL_RUN_WHEN_DRAG_AND_DROP_EXCEPT_ASCII	
		// Move from ImpWiz::Execute, code below will fail restore values if import error, it's OK right now as filter will NOT be used anymore once error occur
		///---Sim 02-03-2007 ADD_AUTO_RENAME
		// not rename in low levle, it will centralize at framework
		bool bRenameWks, bRenameWkBk, bRenameWkBkComm, bRenameColComm, bRenameWksWithVar, bRenameWkbkWithVar;
		fuDisableAllRename(trFilter, &bRenameWks, &bRenameWkBk, &bRenameWkBkComm, &bRenameColComm, &bRenameWksWithVar, &bRenameWkbkWithVar);
		/// end FIX_FILTER_SCRIPT_FAIL_RUN_WHEN_DRAG_AND_DROP_EXCEPT_ASCII
		Worksheet wks(lyTarget);
		if( !wks )
			return IMPERR_NO_TARGET_PAGE;

		ASCIMP ascimp;
		fuGetASCIMP(trFilter, ascimp);
	
		// An internal bug can appear when partial import is off and user specifies
		// a number of columns that differs from the number auto-detected.
		// A fix is to do a partial import but set the partial import settings
		// to import all the data.
		if( ascimp.iPartial == 0 )
		{
			ascimp.iPartial=1;
			ascimp.iPartialC1 = 0;
			ascimp.iPartialC2 = ascimp.iNumColumns - 1;
			ascimp.iPartialR1 = 0;
			ascimp.iPartialR2 = -1;
		}
		/// Hong 09/02/09 QA80-14252 FIX_NUMBER_COLS_NOT_USED_IF_PARTIAL_IS_SET_FIRST
		else
		{
			/// Hong 10/09/09 QA80-14252-P1 FIX_ORIGIN_FREEZE_IF_NUMBER_COLS_SET_TO_ONE_WITH_PARTIAL_ENABLE
			//ascimp.iPartialC2 = min(ascimp.iPartialC2, ascimp.iNumColumns - 1);
			ascimp.iPartialC2 = min(ascimp.iPartialC2, ascimp.iPartialC1 + ascimp.iNumColumns - 1);
			/// end FIX_ORIGIN_FREEZE_IF_NUMBER_COLS_SET_TO_ONE_WITH_PARTIAL_ENABLE
		}
		/// end FIX_NUMBER_COLS_NOT_USED_IF_PARTIAL_IS_SET_FIRST
	
		///---Sim 08-04-2006 WORKSHEET_ALREADY_PREPARE_ON_BASE_CLASE
		//PrepareWksColsForImport(lyTarget, trFilter);
		///---END WORKSHEET_ALREADY_PREPARE_ON_BASE_CLASE

		ASCIMPRESULT air;

		/// EJP 2008-02-26 v8.0812 QA80-4808 STOP_IMPORT_IF_ANY_COLS_ARE_LOCKED
		///	//if ( 0 != wks.ImportASCII(strFileName, ascimp, &air) )
		///	if ( 0 != wks.ImportASCII(strFileName, ascimp, &air, tnInfo) )/// Hong 12/30/06 SAVE_TIME_IN_ORGANIZER_USE_LOCAL_TIME	
		///		return IMPERR_IMPORT_FUNC_ERR;
		int err = wks.ImportASCII(strFileName, ascimp, &air, tnInfo);
		/// Hong 01/09/09 v8.0995 CORRECT_IMPASC_ERROR_RETURN_CHECKING
		//if( err )
		//	return err;
		if ( ERR_WKS_COL_LOCKED == err )
			return IMPERR_WKS_HAS_COL_LOCKED;
		else if ( err )
			return IMPERR_IMPORT_FUNC_ERR;
		/// end CORRECT_IMPASC_ERROR_RETURN_CHECKING
		/// end STOP_IMPORT_IF_ANY_COLS_ARE_LOCKED
		
		///---Sim 03-29-2007 FIX_D&D_TO_GRAPH
		TreeNode trDataRange = tree_get_node_by_tagname(tnInfo, "DataRange", true);
		m_orng = get_and_check_range(trDataRange);
		///---END FIX_D&D_TO_GRAPH
		
		///---Sim 05-23-2007 QA80-9427-P2 FIX_RANGE_INFO_FOR_NON_NUMERIC_DATA
		for (int nIndex = 0; nIndex < m_orng.GetNumRanges(); nIndex++ )
		{
			int nC1, nC2;
			m_orng.GetRange(wks, nC1, nC2, nIndex);
			///---Sim 02-24-2007 ADD_FILE_NAME_TO_COL_USER_INFO_TREE
			// set column user info tree
			//for (int nCol = air.nC1; nCol <= air.nC2; nCol++)
			for (int nCol = nC1; nCol <= nC2; nCol++)
			{
				Column cc(wks, nCol);
				///---Sim 02-04-2010 QA81-15063 MOVE_IMP_FILE_INFO_OUT_FROM_COL_USER_INFO_TREE
				//string strColumnInfo = "ColumnInfo";
				//Tree trColumnInfo;
				//trColumnInfo.AddTextNode(strFileName, "ImportFile");
				//trColumnInfo.Enable = ENABLE_READ_ONLY;
				//trColumnInfo.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
				//set_user_info(cc, strColumnInfo, trColumnInfo);
				fu_set_import_file_name_info(cc, strFileName, IMPORT_INFO_TO_USER_TREE);
				///---Sim 02-05-2010 QA81-15063 ROLL_BACK_MOVE_COL_INFO_OUT_OF_USER_TREE
				// roll back move column info out of user tree, as CP said
				//fu_set_import_file_name_info(cc, strFileName);
				///---END QA81-15063 ROLL_BACK_MOVE_COL_INFO_OUT_OF_USER_TREE
				///---END QA81-15063 MOVE_IMP_FILE_INFO_OUT_FROM_COL_USER_INFO_TREE
			}
			///---END ADD_FILE_NAME_TO_COL_USER_INFO_TREE
		}
		///---END QA80-9427-P2 FIX_RANGE_INFO_FOR_NON_NUMERIC_DATA
		
		///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
		/*
		/// Hong 01/17/07 ADD_SPARKLINE_TO_IMPORT_WIZARD
		bool bAddSparklines = fuGetSparkLine(trFilter);
		if( bAddSparklines )
		{
			XFBase xf("sparklines");
			if( !xf )
				return CER_FAILED_LOAD_SPK_LINE_XF;
			xf.SetArg("sel", 0);
			///---Sim 05-23-2007 QA80-9427-P2 FIX_RANGE_INFO_FOR_NON_NUMERIC_DATA
			for (int nIndex = 0; nIndex < m_orng.GetNumRanges(); nIndex++ )
			{
				int nC1, nC2;
				m_orng.GetRange(wks, nC1, nC2, nIndex);
				//xf.SetArg("c1", air.nC1+1); // XF sparklines use LT index
				//xf.SetArg("c2", air.nC2+1);
				xf.SetArg("c1", nC1+1); // XF sparklines use LT index
				xf.SetArg("c2", nC2+1);
				/// end FIX_SPARK_LINE_DISAPPEAR
				xf.SetArg("wks", wks);
				if ( !xf.Evaluate() )
					return CER_SPK_LINE_RUN_ERROR;
			}
			///---END QA80-9427-P2 FIX_RANGE_INFO_FOR_NON_NUMERIC_DATA
		}
		/// end ADD_SPARKLINE_TO_IMPORT_WIZARD
		*/
		int nSparklines = fuGetSparkLine(trFilter);
		for (nIndex = 0; nIndex < m_orng.GetNumRanges(); nIndex++ )
		{
			int nC1, nC2;
			m_orng.GetRange(wks, nC1, nC2, nIndex);
			if ( !update_sparkline(nSparklines, wks, nC1, nC2) )
				return CER_SPK_LINE_RUN_ERROR;
		}
		///---END SUPPORT_SMART_SPARKLINE
		/// AW 08/06/06 CHECK_IW_FILTER
		/*
		int nStartCol = air.nC1;
		int nNumCol = air.nC2 - air.nC1 + 1;
		SetColDesignations(wks, trFilter, nStartCol, nNumCol);
		*/
		/// END CHECK_IW_FILTER
		
		/// Hong 07/21/08 QA80-11869 FIX_FILTER_SCRIPT_FAIL_RUN_WHEN_DRAG_AND_DROP_EXCEPT_ASCII
		// Move from ImpWiz::Execute
		fuSetAllRename(trFilter, &bRenameWks, &bRenameWkBk, &bRenameWkBkComm, &bRenameColComm, &bRenameWksWithVar, &bRenameWkbkWithVar);
		/// end FIX_FILTER_SCRIPT_FAIL_RUN_WHEN_DRAG_AND_DROP_EXCEPT_ASCII
		
		///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
		
		return IMPERR_NONE; // success
	}
	
	///---Sim 01-16-2007 FIX_SET_FORMATS_AND_DESIGNATIONS_WHEN_NUMBER_COLUMNS_IS_ZERO
	virtual int Execute(Layer& lyTarget, int nIndexFile, string& strFileName, TreeNode& tnInfo, TreeNode& trFilter)
	{
		Tree trUsingFilter;
		trUsingFilter.Replace(trFilter.Clone());
		
		// check value number of column
		if ( fuGetInt(trUsingFilter, IDE_ASCIMP_DELIMITED, FALSE) 
			&& 0 == fuGetInt(trUsingFilter, IDE_ASCIMP_NUMCOLUMNS, 0) )
		{	// number of column is 0, means all columns
			// get number of column from file, and modify filter temporarily
			///---Sim 05-28-2007 SCAN_FOR_NUM_COLS_ON_CHANGE_HEADER_LINES
			ASCIMP ascimp;
			fuGetASCIMP(trUsingFilter, ascimp);
			/// AW 04/18/07 QA80-9646 v8.0604 MORE_ON_ASCII_IMPORT_MESSAGE
			//AscImpReadFileStruct(strFileName, &ascimp);
			//int nRet = AscImpReadFileStruct(strFileName, &ascimp);
			/// Hong 08/27/08 QA80-9206 v8.0833 FIX_FAIL_GET_ACTUAL_NUM_COLIMN_AS_PARTIAL_COUNTED
			ascimp.iPartial = 0;
			/// end FIX_FAIL_GET_ACTUAL_NUM_COLIMN_AS_PARTIAL_COUNTED
			int nRet = AscImpReadFileStruct(strFileName, &ascimp, AIRF_USE_ASCIMP);
			if ( nRet )
				return nRet;
			/// END MORE_ON_ASCII_IMPORT_MESSAGE
			fuSetInt(trUsingFilter, IDE_ASCIMP_NUMCOLUMNS, ascimp.iNumColumns);
			///---END SCAN_FOR_NUM_COLS_ON_CHANGE_HEADER_LINES
		}
		
		return ImpWiz::Execute(lyTarget, nIndexFile, strFileName, tnInfo, trUsingFilter);
	}
	///---END FIX_SET_FORMATS_AND_DESIGNATIONS_WHEN_NUMBER_COLUMNS_IS_ZERO
	
	/// AW 08/03/06 MORE_ON_IW_IMPORT
	/*
	virtual int GenerateImpInfo(string& strFileName, Layer& lyTarget, TreeNode& trFilter, TreeNode& trImpInfo) 
	{
		Page pgTarget;
		if (lyTarget)
			lyTarget.GetParent(pgTarget);
		
		Tree trFile;
		int iFilterType = fuGetType(trFilter);
		impinfo_GetLastFileNode(pgTarget, trFile);
		impinfo_FileInfoToFileNode(trFile, strFileName, iFilterType);
		
		TreeNode trNode = trImpInfo.FirstNode;
		while( trNode )
		{
			trFile.AddNode(trNode, true);
			trNode = trNode.NextNode;
		}

		int iFirstLine, iNumLines;
		fuGetHdrSave(trFilter, iFirstLine, iNumLines);
		if( iNumLines )
		{
			string strHdrLines;
			if( 0 == LoadTextFile(strHdrLines, strFileName, iNumLines, iFirstLine) )
			{
				/// EJP 08-13-2004 v8.0115 QA70-6472 IMPORT_INFO_STORAGE_CLEANUP
				trFile.ASCII.HeaderLines.strVal = strHdrLines;
				/// end IMPORT_INFO_STORAGE_CLEANUP

				/// EJP 2006-07-07 v8.0440 IMPROVE_HEADER_LINES_DISPLAY_IN_WKS_ORGANIZER
				trFile.ASCII.HeaderLines.ID = TRGP_MULTILINE_TEXT;
				string str;
				str.Format("%d", iNumLines);
				trFile.ASCII.HeaderLines.SetAttribute(STR_ATTRIB_MULTILINE_EDIT_DISPLAY_ROW_HEIGHT_RANGE, str);
				/// end IMPROVE_HEADER_LINES_DISPLAY_IN_WKS_ORGANIZER

				vector<byte> vb;
				if( strHdrLines.GetBytes(vb) )
					pgTarget.SetMemory("ImportHeader", vb);
			}
		}
		
		impinfo_SetLastFileNode(pgTarget, trFile);
		//trImpInfo = trFile.Clone(); // this code seem couldn't copy really. maybe memory junk come up.

		return 0; 
	}
	*/
	/// Hong 12/30/06 SAVE_TIME_IN_ORGANIZER_USE_LOCAL_TIME	
	/*
	virtual void GenerateImpInfo(string& strFileName, Page& pgTarget, TreeNode& trFilter, TreeNode& trImpInfo) 
	{
		impinfo_GetLastFileNode(pgTarget, m_trFile);	
	}
	*/
	/// end SAVE_TIME_IN_ORGANIZER_USE_LOCAL_TIME
	///---Sim 08-04-2006 FIX_CUSTOM_DATE_FORMAT
	/*
	void GetWksColInfo(Layer& lyTarget)
	{
		Worksheet wks(lyTarget);
		if ( wks )
		{
			m_strColDesig = wks.GetColDesignations();
			m_strColFormat = wks.GetColFormats();
		}
	}
	void SetWksColInfo(Page& pgTarget)
	{
		Worksheet wks(pgTarget.GetName());
		if ( wks && FILTER_TYPE_USERDEFINED != m_iFilterType)
		{
			string strColDesig = wks.GetColDesignations();  //test
			string strColFormat = wks.GetColFormats();		//test
			
			wks.SetColDesignations(m_strColDesig, m_bRepetitive);
			wks.SetColFormats(m_strColFormat, m_bRepetitive);
		}
	}
	*/
	///---END FIX_CUSTOM_DATE_FORMAT

	/// END MORE_ON_IW_IMPORT

	
};

