void CStudentChooserDlg::RefreshStudentList() { vector< CString > selected; for ( int i=0; i<studentList.GetCount(); i++ ) { if ( studentList.GetSel( i ) ) { CString text; studentList.GetText( i, text ); selected.push_back( text ); } } CTable table; storage.GetStudentList( table, searchFirstName.GetString(), searchLastName.GetString(), searchSSN.GetString(), schoolYearList.GetSelectedIndex() ); int index = 0; studentList.ResetContent(); ssnLookup.clear(); while ( !table.IsAtEOF() ) { string entry; if ( (string) table["LastName"] == "" || (string) table["FirstName"] == "" ) { entry = (string) "[" + (string) table["SSN"] + "]"; } else { entry = (string) table["LastName"] + ", " + (string) table["FirstName"] + " [" + (string) table["SSN"] + "]"; } studentList.AddString( entry.c_str() ); ssnLookup[ entry.c_str() ] = table["SSN"]; table.MoveNext(); } for ( i=0; i<studentList.GetCount(); i++ ) { CString text; studentList.GetText( i, text ); for ( int j=0; j<selected.size(); j++ ) { if ( selected[j] == text ) { studentList.SetSel( i ); } } } }
void CQueryWizard::ExecuteQuery( CQueryBuilder& builder ) { //MessageBox( 0, builder.GetQuery().c_str(), "query", 0 ); CConnection conn; if ( !conn.OpenForReading() ) { MessageBox( 0, "Unable to connect to the database!", "", 0 ); return; } try { BeginWaitCursor(); CTable rs = conn.Execute( builder.GetQuery() ); char tempPath[4001]; char tempFile[4001]; ::GetTempPath( 4000, tempPath ); int fileNum = 0; FILE* f = NULL; while ( !f ) { sprintf( tempFile, "%s\\studentinfo%d.xls", tempPath, fileNum++ ); f = fopen( tempFile, "w" ); if ( !f && fileNum == 0 ) { MessageBox( 0, "Unable to create file to store query!", "StudentInfo QueryWizard", 0 ); return; } } vector<string> header = builder.GetSelect(); for ( int j=0; j<header.size(); j++ ) { if ( j ) { fprintf( f, "\t%s", header[j].c_str() ); } else { fprintf( f, "%s", header[j].c_str() ); } } fprintf( f, "\n" ); while ( !rs.IsAtEOF() ) { for ( int i=0; i<rs.GetColumnCount(); i++ ) { if ( i ) { fprintf( f, "\t%s", ((string)rs[i]).c_str() ); } else { fprintf( f, "%s", ((string)rs[i]).c_str() ); } } fprintf( f, "\n" ); rs.MoveNext(); } fclose(f); ShellExecute( NULL, "open", tempFile, NULL, NULL, SW_SHOWNORMAL ); EndWaitCursor(); } catch ( ... ) { //char temp[10000]; //if ( e.GetErrorMessage( temp, 10000 ) ) { MessageBox( 0, "Unable to execute the query!", "", 0 ); //} else { // MessageBox( 0, ( (string)"Unable to execute the query: " + (string)temp ).c_str(), "", 0 ); //} } }