CAirportDatabase* CAirportDatabaseList::addNewDBEntry( const CString& _strDBName) 
{
	CString strName = _strDBName;
	int nPos = checkIfIncludeKeyWords(strName.GetBuffer());
	if (nPos != -1)
	{
		CString strLeft(_T(""));
		CString strRight(_T(""));
		strLeft = strName.Left(nPos);
		strRight = strName.Right(strName.GetLength() - nPos - 1);
		strName = strLeft + strRight;
	}

	for(int i=0;i<getDBCount();i++)
	{
		if(strName.CompareNoCase(getAirportDBByIndex(i)->getName())==0)
		{
			CString errormsg ;
			errormsg.Format(_T("%s has existed "),_strDBName) ;
			MessageBox(NULL,errormsg,"Warning",MB_OK) ;
			return NULL ;
		}
	}
	CString strSharePath(_T(""));
	CString strARCPath(_T(""));
	strSharePath.Format(_T("%s\\ImportDB\\%s.mdb"),PROJMANAGER->GetAppPath(),strName);
	strARCPath.Format(_T("%s\\%s"),PROJMANAGER->GetAppPath(),_T("Databases\\arc.mdb"));

	CShareTemplateDatabase* _pDB = new CShareTemplateDatabase(strARCPath,strSharePath);

	//setup database for new airport database
	CString strPartsSourceFile(_T(""));
	CString strPartsDestinationFile(_T(""));

	strPartsSourceFile.Format(_T("%s\\ArctermDB\\temp\\project.mdb"),PROJMANAGER->GetAppPath());
	if (!PathFileExists(strSharePath))
	{
		CopyFile(strPartsSourceFile,strSharePath,FALSE);

		AirportDatabaseConnection pConnectionPtr(strSharePath);
		CPartsAndShareTemplateUpdate shareTemplateDataBaseUpdater;
		if(!shareTemplateDataBaseUpdater.Update(&pConnectionPtr)) 
		{
			CString strError(_T(""));
			strError.Format(_T("Update the new Template DataBase error."));
			MessageBox(NULL,strError,"Warning",MB_OK);
			return NULL;
		}
	}
	_pDB->setName(strName);
	_pDB->SaveAirport();

	m_vAirportDB.push_back(_pDB) ;
	return _pDB ;
}
void CAirportDatabaseList::ReadAirportDBData()
{
	clear() ;
	CString SQL ;
    SQL.Format(_T("SELECT * FROM TB_PROJECT_AIRPORTDB")) ;
	CADORecordset recordset ;
	long count ;
	try
	{
		CADODatabase::ExecuteSQLStatement(SQL,count,recordset,DATABASESOURCE_TYPE_ACCESS_GLOBALDB) ;
	}
	catch (CADOException e)
	{
		e.ErrorMessage() ;
		return ;
	}
	CShareTemplateDatabase* _pDB = NULL; 
	int id = -1 ;
	CString _name ;

	CString strSharePath(_T(""));
	CString strARCPath(_T(""));
	strARCPath.Format(_T("%s\\%s"),PROJMANAGER->GetAppPath(),_T("Databases\\arc.mdb"));
	while(!recordset.IsEOF())
	{
	   recordset.GetFieldValue(_T("ID"),id) ;
	   recordset.GetFieldValue(_T("AIRPORTDB_NAME"),_name) ;
	  
	   int nPos = checkIfIncludeKeyWords(_name.GetBuffer());
	   if (nPos != -1)
	   {
		   CString strLeft(_T(""));
		   CString strRight(_T(""));
		   strLeft = _name.Left(nPos);
		   strRight = _name.Right(_name.GetLength() - nPos - 1);
		   _name = strLeft + strRight;
	   }

	   strSharePath.Format(_T("%s\\ImportDB\\%s.mdb"),PROJMANAGER->GetAppPath(),_name);
	   _pDB  = new CShareTemplateDatabase(strARCPath,strSharePath) ;
	   _pDB->setName(_name) ;
	   _pDB->SetID(id) ;
	   if (!getAirportDBByName(_name))
	   {
		    m_vAirportDB.push_back(_pDB) ;
	   }

	   if(recordset.GetFieldValue(_T("VERSION"),id))
		   _pDB->m_nVersion = id ;
	   else
		   _pDB->m_nVersion = 0 ;
	   recordset.MoveNextData() ;
	}
}
Esempio n. 3
0
// FIXME: strRemoveQuote, strLeft, strRight functions have a leak
char * strRemoveQuote(const char * str)
{
    char * tmp;
    tmp = sopstrdup(str);
    if(strlen(tmp) > 0)
    {
        //REMOVE LEADING QUOTE
        while (strcmp(strLeft(tmp,1),"\"") == 0)
        {
            tmp = strRight(tmp,strlen(tmp) - 1);
        }
    }
    if(strlen(tmp) > 0)
    {
        //REMOVE TRAILING QUOTE
        while (strcmp(strRight(tmp,1),"\"") == 0)
        {
            tmp = strLeft(tmp,strlen(tmp) - 1);
        }
    }
    return tmp;
}
Esempio n. 4
0
void FindReplace(Str& strContents, const char* pTag, const char* pValue)
{
  if (strcmp(pTag, pValue) == 0)
    return;
  for (int nPos = strContents.Find(pTag); nPos >= 0; nPos = strContents.Find(pTag))
  {
    int nRightLen = strContents.GetLength() - strlen(pTag) - nPos;
    Str strLeft(strContents.Left(nPos));
    Str strRight(strContents.Right(nRightLen));
    strLeft += pValue;
    strLeft += strRight;
    strContents = strLeft;
  }
}
CShareTemplateDatabase* CAirportDatabaseList::getAirportDBByName(const CString strName)
{
	CString strDBName = strName;
	int nPos = checkIfIncludeKeyWords(strDBName.GetBuffer());
	if (nPos != -1)
	{
		CString strLeft(_T(""));
		CString strRight(_T(""));
		strLeft = strDBName.Left(nPos);
		strRight = strDBName.Right(strDBName.GetLength() - nPos - 1);
		strDBName = strLeft + strRight;
	}

	int _iCount = m_vAirportDB.size();
	for( int i=0; i<_iCount; i++ )
	{
		if( (m_vAirportDB[i]->getName()).CompareNoCase(strDBName) == 0)
			return m_vAirportDB[i];
	}

	return NULL;
}
Esempio n. 6
0
void BuildFileName(	CUString strFormat,
					CUString strArray[NUMFILENAME_IDS],
					CUString& strName,CUString& strDir)
{

	CUString strTmp( strFormat );
	int		nPos = 0;
	int		i;

	for ( i=0; i<NUMFILENAME_IDS; i++ )
	{
		strArray[i] = FixFileNameString( strArray[i] );
	}

	// loop through all the tokens
	while ( (( nPos = strTmp.Find( _T( '%' ),nPos ) ) >=0 ) && ( nPos + 1 < strTmp.GetLength() ) )
	{
		ENUM_FILENAME_CONVERTS	convertType = FILENAME_CONVERT_NONE;
		int						nPercentID = 0;
		int						nSkipChars = 2;

		WCHAR chEval = strTmp.GetAt( nPos + 1 );

		if ( _W( 'l' ) == chEval )
		{
			convertType = FILENAME_CONVERT_LOWER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'u' ) == chEval )
		{
			convertType = FILENAME_CONVERT_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'c' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FCEW_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'f' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FC_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}

		// Get %ID number
		switch ( chEval )
		{
			case '1': nPercentID =  0; break;
			case '2': nPercentID =  1; break;
			case '3': nPercentID =  2; break;
			case '4': nPercentID =  3; break;
			case '5': nPercentID =  4; break;
			case '6': nPercentID =  5; break;
			case '7': nPercentID =  6; break;
			case '8': nPercentID =  7; break;
			case 'Y': nPercentID =  8; break;
			case 'G': nPercentID =  9; break;
			case 'A': nPercentID = 10; break;

			default:
				nPercentID = -1;
				nPos++;
			break;
		}

	
		if ( nPercentID >= 0 && nPercentID < NUMFILENAME_IDS )
		{
			CUString strLeft( strTmp.Left( nPos ) );
			CUString strMid( strArray[ nPercentID ] );
			CUString strRight( strTmp.Right( strTmp.GetLength() - nPos - nSkipChars ) );

			// do filename mangling
			strMid = FormatTrackNameString( strMid, convertType );

			strTmp = strLeft + strMid + strRight;

		}
		else
		{
			// Delete token
//			strTmp = strTmp.Left( nPos ) + strTmp.Right( strTmp.GetLength() - nPos - 1 );
		}
	}

	// Split result in a directory and file name portion
	// Search for last backslash
	nPos = strTmp.ReverseFind( _T( '\\' ) );

	if ( nPos >= 2 )
	{
		// OK, we've found the backsplash, do the split
		strDir = strTmp.Left( nPos + 1 );
		strName = strTmp.Right( strTmp.GetLength() - nPos - 1 );
	}
	else
	{
		// Only a filename, just assign the string to the filename and clear the directory
		strDir = _T( "" );
		strName = strTmp;
	}

	strDir.TrimLeft();
	strDir.TrimRight();

	// remove spaces before the directory separator and double backslashes
	INT	nIndex = 0;
	while ( nIndex < strDir.GetLength() )
	{
		if ( _T( '\\' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) || 
					 ( _T( ' ' ) == strDir[ nIndex - 1 ] ))
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}
		if ( _T( ' ' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) )
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}

		nIndex++;

	}

	strDir.TrimLeft();
	strDir.TrimRight();

	strName.TrimLeft();
	strName.TrimRight();

}