#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>

#include <..\originlab\datasource.h>
/*------------------------------------------------------------------------------*
 * Modification Log:															*
 *	Sophy 3/3/2010 QA81-14057-P4 CHECK_ODBC_OPTION_WHEN_LOAD_ODQ_DIRECTLY		*
 *------------------------------------------------------------------------------*/


void impODQ(const string& fname, const TreeNode& trfiles, const TreeNode& options, Range& orng, TreeNode& trheader, const int& reimp)
{
	
	string strDSFile, strDS, strSQL, strODQfile;
	Worksheet wks = Project.ActiveLayer();
	
	LPCSTR lpcszODQfile = NULL;
	
	if(wks)
	{
		if(fname.GetLength() > 1)
		{
			string strDSFileName;
	
			bool bIsFileValid = fname.IsFile();
			if(bIsFileValid)
				lpcszODQfile = fname;
			else
				XF_THROW_EX(XF_CD_NOT_VALID_PATH, fname);
	
		}
		///Sophy 3/3/2010 QA81-14057-P4 CHECK_ODBC_OPTION_WHEN_LOAD_ODQ_DIRECTLY
	#ifndef	__SUPPORT_IMPORT_DATA_BY_ODBC_IN_QUERY_BUILDER__
		if ( !db_load_query(strDS, strSQL, lpcszODQfile, &strDSFile, &strODQfile) )
	#else
		string	strUseODBC;
		if ( !db_load_query(strDS, strSQL, lpcszODQfile, &strDSFile, &strODQfile, &strUseODBC) )		
	#endif	//__SUPPORT_IMPORT_DATA_BY_ODBC_IN_QUERY_BUILDER__
		///end CHECK_ODBC_OPTION_WHEN_LOAD_ODQ_DIRECTLY
		{
			XF_THROW_EX(XFERR_FAIL_TO_LOAD_DATABASE, fname);
		}
	
		///Sophy 3/3/2010 QA81-14057-P4 CHECK_ODBC_OPTION_WHEN_LOAD_ODQ_DIRECTLY
	#ifndef	__SUPPORT_IMPORT_DATA_BY_ODBC_IN_QUERY_BUILDER__
		if( !db_wks_set_query(wks, strDS, strSQL, strDSFile) )
	#else
		BOOL bUseODBC = strUseODBC.CompareNoCase(STR_QUERY_MODE_ODBC) == 0;
		if( !db_wks_set_query(wks, strDS, strSQL, strDSFile, false, &bUseODBC) )		
	#endif	//__SUPPORT_IMPORT_DATA_BY_ODBC_IN_QUERY_BUILDER__
		///end CHECK_ODBC_OPTION_WHEN_LOAD_ODQ_DIRECTLY
			XF_THROW(XFERR_FAIL_TO_LOAD_DATABASE_TO_WKS);
		
		db_wks_import(wks, 0, 0, true, false);
	
	}
	else
		XF_THROW(XFERR_NO_ACTIVE_WORKSHEET);
	
	
	
}

//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 impODQ_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
