void CVoxSQLite::GetProfile( const char* username, Profile& rProfile ) { CppSQLite3Buffer buf; buf.format( "SELECT * from Profile WHERE username = %Q;", username ); try { CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf ); int nProfileId = 0; CppSQLite3Query q = stmt.execQuery(); //Process record set. while (!q.eof()) { nProfileId = q.getIntField(0); rProfile.setFirstName ( q.getStringField(2) ); rProfile.setLastName ( q.getStringField(3) ); rProfile.setAlias ( q.getStringField(4) ); rProfile.setSmsSignature( q.getStringField(5) ); rProfile.setCompany ( q.getStringField(6) ); rProfile.setSex ( (EnumSex::Sex)q.getIntField(7) ); rProfile.setNotes ( q.getStringField(10) ); // rProfile.setBirthday( q.getStringField(8) ); // photo (filename) //TODO rProfile.setPhoto( q.getBlobField(9) ); //Address, email, phone numbers, and URLs will be in separate tables to allow for easy GetStreetAddresses( nProfileId, rProfile.getStreetAddresses() ); GetEmailAddresses ( nProfileId, rProfile.getEmailAddresses() ); GetTelephones ( nProfileId, rProfile.getTelephones() ); GetUrls ( nProfileId, rProfile.getUrls() ); q.nextRow(); } stmt.reset(); } catch (CppSQLite3Exception& e) { e.errorCode(); } }
int CFavUrlMenuDlg::GetUrls( CString strPath, CArray<ITEM, ITEM&> &arrItems ) { CStringArray arrSubDir; int curCnt = 0; if(strPath[strPath.GetLength() - 1] != _T('\\')) strPath += _T('\\'); CString strFind = strPath + "*.*"; WIN32_FIND_DATA findData; HANDLE hFile = NULL; hFile = FindFirstFile(strFind, &findData); if (hFile != INVALID_HANDLE_VALUE) { do { if ( strcmp(".", findData.cFileName )==0 || strcmp("..", findData.cFileName)==0) continue; // 略过隐藏文件和系统文件 if ( (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) continue; // 目录 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) arrSubDir.Add(findData.cFileName); // 文件 CString strFileName = findData.cFileName; strFileName.MakeLower(); if (strFileName.Right(4) == ".url") { ITEM item; item.type = ITEM_TYPE_URL; item.strPath = strPath + strFileName; strFileName = strFileName.Left(strFileName.GetLength() - 4); item.strName = strFileName; arrItems.Add(item); curCnt++; } } while (FindNextFile(hFile, &findData)); } FindClose(hFile); INT_PTR nSubDirNum = arrSubDir.GetSize(); for (INT_PTR i=0; i<nSubDirNum; i++) { CString strSubDirName = arrSubDir.GetAt(i); CArray<ITEM, ITEM&> aItems; int n = GetUrls(strPath+strSubDirName, aItems); // if (n != 0) // 不添加空文件夹 if (1) { ITEM item; item.type = ITEM_TYPE_DIRECTORY; item.strName = strSubDirName; item.strPath = strPath+strSubDirName; arrItems.Add(item); } } return curCnt; }
BOOL CFavUrlMenuDlg::OnInitDialog() { CDialog::OnInitDialog(); SetFont(&m_font); if (m_bAddFav) { ITEM item; item.type = ITEM_TYPE_BTN_ADD; item.strName = "添加到收藏夹"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_SEPARATOR; m_arrItems.Add(item); GetUrls(m_strParentPath, m_arrItems); }else { ITEM item; item.type = ITEM_TYPE_BTN_OPEN; item.strName = "打开"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_BTN_REMOE; item.strName = "删除"; item.strPath = m_strParentPath; m_arrItems.Add(item); } // 获取最长字符串所占宽度 CClientDC dc(this); int nTextWidthMax = 0; CSize size; dc.SelectObject(&m_font); for (INT_PTR i=0; i<m_arrItems.GetSize(); i++) { CString strText = m_arrItems.GetAt(i).strName; size = dc.GetTextExtent(strText); if (size.cx > nTextWidthMax) nTextWidthMax = size.cx; } nTextWidthMax = nTextWidthMax < 90 ? nTextWidthMax+100: nTextWidthMax+30; size.cx = nTextWidthMax; m_rctFirsItem = CRect(CPoint(m_nBorderWidth, m_nBorderWidth), CSize(size.cx+m_nSpacingHeigth*2, size.cy+m_nSpacingHeigth)); m_rctFirsItem.top += 6; m_rctFirsItem.bottom +=10; CRect rctWnd(0, 0, 0, 0); rctWnd.right = m_nBorderWidth*2 + m_rctFirsItem.Width(); rctWnd.bottom= m_nBorderWidth*2 + m_rctFirsItem.Height()*m_arrItems.GetSize() ; if (m_nBorderWidth % 2) { rctWnd.right += 2; rctWnd.bottom += 2; } dc.BeginPath(); dc.RoundRect(rctWnd, CPoint(m_nBorderWidth, m_nBorderWidth)); dc.EndPath(); HRGN hRgn = PathToRegion(dc.m_hDC); SetWindowRgn(hRgn, FALSE); GetRgnBox(hRgn, &rctWnd); SetWindowPos(NULL, 0, 0, rctWnd.Width(), rctWnd.Height(), SWP_NOMOVE); return TRUE; // 除非设置了控件的焦点,否则返回 TRUE }