?? clientwnd.cpp
字號:
int i;
m_playsong.SetFilePath(m_addrecord.GetSongPath(m_pSelectID[1]));
for(i = 2; i <= m_pSelectID[0]; i++)
m_playsong.SetFilePath(m_addrecord.GetSongPath(m_pSelectID[i]));
break;//已點歌單 end
case VK_F6://刪歌
gethostname(szText, sizeof(szText));
strsql.Format("select * from request where username='%s' order by playseq",
szText);
ShowSelectSong(strsql, "已點歌清單,按對應的數字鍵刪除:", false, false);
m_nMenuFlag = 4;//將m_nMenuFlag置4,執行刪歌操作
//發送消息到服務器,所選歌曲已更改
CClientSocket::SendMsg("LoadAgain", 10);
break;
case 'T'://TV和VGA
break;
}
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
//////////////////////////////////////////////////////////////////////////////////
//函數功能: 顯示菜單
//參數說明: nMenuIndex: 當前菜單索引
void CClientWnd::ShowMenu(int nMenuIndex)
{
CClientDC dc(this);
CDC mdc;
CDC mdcsgn;
mdcsgn.CreateCompatibleDC(&dc);
mdc.CreateCompatibleDC(&dc);
//加載位圖
HBITMAP hbmpsgn;
HBITMAP hbmp = LoadBitmap(m_conserver.GetAppPath() + "picture\\login.bmp", m_nScreenX, m_nScreenY);
SelectObject(mdc.m_hDC, hbmp);
int xpos = GetXPos(m_selectmenu[nMenuIndex].m_strMenuItem[0].GetBuffer(0));
int ypos = 40;
int i, j;
TextOut(&mdc.m_hDC, xpos-200, ypos+=40, m_selectmenu[nMenuIndex].m_strMenuItem[0], RGB(255,0,255));
xpos-=150;
int x = m_selectmenu[nMenuIndex].GetLftRtIndex();
int y = m_selectmenu[nMenuIndex].GetUpDwnIndex();
switch( nMenuIndex )
{
case 0://顯示主菜單
case 1://顯示語種查詢菜單
case 2://顯示歌手查詢菜單
for(i = 1; i < m_selectmenu[nMenuIndex].GetMenuItemNum(); i++)
{
TextOut(&mdc.m_hDC, xpos, ypos+i*40, m_selectmenu[nMenuIndex].m_strMenuItem[i]);
}
int nIndex;
nIndex = (x-1)*10+y;
if( nMenuIndex == 2 )//貼上各歌手的圖片
{
hbmpsgn = LoadBitmap(m_strSingerPath[nIndex-1], 120, 150);
SelectObject(mdcsgn.m_hDC, hbmpsgn);
BitBlt(mdc.m_hDC, xpos+200, ypos+40, 120, 150, mdcsgn.m_hDC, 0, 0, SRCCOPY);
}
TextOut(&mdc.m_hDC, xpos+(x-1)*40, ypos+y*40, m_selectmenu[nMenuIndex].m_strMenuItem[nIndex], RGB(255,0,255));
if( nMenuIndex == 0 )
{
int xpos = GetXPos("按返回鍵查詢已用時間和費用.");
TextOut(&mdc.m_hDC, xpos, m_nScreenY-100, "按返回鍵查詢已用時間和費用.", RGB(255,0,255));
}
break;
case 3://顯示字母查詢菜單
for(i = 0; i < m_selectmenu[nMenuIndex].GetMenuItemNum()/10 + 1; i++)
{
for( j = 1; j < 11; j++)
{
if(i*10+j < m_selectmenu[nMenuIndex].GetMenuItemNum())
TextOut(&mdc.m_hDC, xpos+(j-1)*40, ypos+(i+1)*40, m_selectmenu[nMenuIndex].m_strMenuItem[i*10+j]);
}
}
if( (y-1)*10+x > 26)//判斷移動后的位置是否大于26,是則改變X,Y坐標,
{
if( x > 6 )
{
x = 1;
m_selectmenu[nMenuIndex].SetLftRtIndex(x);
}
else if( x < 0 )
{
x = 6;
m_selectmenu[nMenuIndex].SetLftRtIndex(x);
}
m_selectmenu[nMenuIndex].SetUpDwnIndex(y);
}
TextOut(&mdc.m_hDC, xpos+(x-1)*40, ypos+y*40, m_selectmenu[nMenuIndex].m_strMenuItem[(y-1)*10+x], RGB(255,0,255));
TextOut(&mdc.m_hDC, xpos-40, ypos+200, "歌名首字母: ", RGB(255,0,255));
TextOut(&mdc.m_hDC, xpos+150, ypos+200, m_strAlphabet);
TextOut(&mdc.m_hDC, xpos-40, m_nScreenY-100, "按0選擇字母,3刪除字母,確定鍵查詢", RGB(255,0,255));
break;
case 4://顯示歌名長度菜單
for(i = 1; i < 10; i++)
{
TextOut(&mdc.m_hDC, xpos+(i-1)*40, ypos+40, m_selectmenu[nMenuIndex].m_strMenuItem[i]);
}
TextOut(&mdc.m_hDC, xpos+(x-1)*40, ypos+y*40, m_selectmenu[nMenuIndex].m_strMenuItem[(y-1)*10+x], RGB(255,0,255));
break;
}
dc.BitBlt(0, 0, m_nScreenX, m_nScreenY, &mdc, 0, 0, SRCCOPY);
}
//////////////////////////////////////////////////////////////////////////////////
//函數功能: 執行查詢操作
/*參數說明: nIndex == 0 為按確認鍵時調用
nIndex != 0 為按下的數字鍵 */
void CClientWnd::SelectSong(int nIndex)
{
int npos;
int nTotallen;//字符串總長度,得到查詢條件時用
CString strsql;//SQL語句
CString strtmp;
if( nIndex == 0 )
{
//計算當前選中的菜單在數組中的位置
int x = m_selectmenu[m_nMenuIndex].GetLftRtIndex();
int y = m_selectmenu[m_nMenuIndex].GetUpDwnIndex();
if( m_nMenuIndex < 3 )//列優先
nIndex = (x-1)*10+y;
else//行優先
nIndex = (y-1)*10+x;
if( m_strAlphabet.IsEmpty() )
m_strAlphabet = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex];
}
switch( m_nMenuIndex )
{
case 1://按語種查詢
if( nIndex > 0 && nIndex < m_selectmenu[m_nMenuIndex].GetMenuItemNum())
{
//從當前選中的菜單項中找出用于查詢的關鍵字保存在strtmp中
nTotallen = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].GetLength();
npos = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].Find("、");
strtmp = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].Right(nTotallen - npos - 3);
strsql.Format("select ID, songname, singer from songlist where speech='%s' order by songname", strtmp);
ShowSelectSong(strsql);
m_nMenuFlag = 3;//將m_nMenuFlag置3,下一步將執行選歌操作
}
break;//按語種查詢 end
case 2://按歌手查詢 begin
if( nIndex > 0 && nIndex < m_selectmenu[m_nMenuIndex].GetMenuItemNum())
{
//從當前選中的菜單項中找出用于查詢的關鍵字保存在strtmp中
nTotallen = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].GetLength();
npos = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].Find("、");
strtmp = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex].Right(nTotallen - npos - 3);
strsql.Format("select ID, songname, singer from songlist where singer='%s' order by songname", strtmp);
ShowSelectSong(strsql);
m_nMenuFlag = 3;
}
break;//按歌手查詢 end
case 3://按字母查詢
if( nIndex > 0 && nIndex < m_selectmenu[m_nMenuIndex].GetMenuItemNum())
{
strsql.Format("select ID, songname, singer, fstalphabet from songlist order by songname", m_strAlphabet);
ShowSelectSong(strsql);
m_nMenuFlag = 3;//將m_nMenuFlag置3,下一步將執行選歌
}
break;
case 4://按歌名長度查詢
if( nIndex > 0 && nIndex < m_selectmenu[m_nMenuIndex].GetMenuItemNum())
{
strtmp = m_selectmenu[m_nMenuIndex].m_strMenuItem[nIndex];
strsql.Format("select ID, songname, singer from songlist where namelen='%s' order by songname", strtmp);
ShowSelectSong(strsql);
m_nMenuFlag = 3;//將m_nMenuFlag置3,下一步將執行選歌
}
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
//函數功能: 將選定的歌顯示在屏幕上
/*參數說明: lpszsql: 將執行的SQL查詢語句
lpszTitle: 顯示的提示信息
bPageDnUp: 是否為翻頁, true為翻頁
bSonglistTable: 是否為顯示songlist表里的歌曲*/
void CClientWnd::ShowSelectSong(LPCTSTR lpszsql, LPCTSTR lpszTitle, BOOL bPageDnUp, BOOL bSonglistTable)
{
CClientDC dc(this);
DrawBGBmp();
int xpos;
int ypos = 40;
int nItemNum = 0;
m_strPreSelect = lpszsql;
try
{
_RecordsetPtr pRequestPtr;
pRequestPtr = m_addrecord.GetRecordsetPtr((_bstr_t)lpszsql);
if( !pRequestPtr->BOF )
pRequestPtr->MoveFirst();
else
{
xpos = GetXPos("沒有您要找的歌,請重新查找");
TextOut(&dc.m_hDC, xpos, ypos, "沒有您要找的歌,請重新查找", RGB(255,0,255));
return;
}
CString strFstAlphabet;
if( !bPageDnUp )//得到查詢后的總歌數
{
m_nPageNum = 0;
while( !pRequestPtr->adoEOF )
{
if( bSonglistTable && m_nMenuIndex == 3 )//當前的查詢為按字母查詢,則從所有的歌中找出歌名首字母中含有要查詢字母的歌
{
strFstAlphabet = (LPCTSTR)(_bstr_t)pRequestPtr->GetCollect("fstalphabet");
if( strFstAlphabet.Find(m_strAlphabet) != 0 )
{
pRequestPtr->MoveNext();
continue;
}
}
nItemNum++;
if( nItemNum > m_nPageNum*10 )
m_nPageNum++;
pRequestPtr->MoveNext();
}
if( nItemNum == 0 )
{
xpos = GetXPos("沒有您要找的歌,請重新查找");
TextOut(&dc.m_hDC, xpos, ypos, "沒有您要找的歌,請重新查找", RGB(255,0,255));
return;
}
if( m_pSelectID != NULL )
{
delete[] m_pSelectID;
m_pSelectID = NULL;
}
m_pSelectID = new int[nItemNum + 1];//分配一個數組,存入查詢得到的歌的ID
m_pSelectID[0] = nItemNum;//0號位置存放ID的個數
m_nPageIndex = 1;
nItemNum = 0;
pRequestPtr->MoveFirst();
}
xpos = GetXPos(lpszTitle);
TextOut(&dc.m_hDC, xpos-200, ypos+=40, lpszTitle, RGB(255,0,255));
xpos-=150;
_variant_t vtID;
_variant_t vtsongname;
_variant_t vtsinger;
CString strmsg;
int nItemIndex = 0;
while( !pRequestPtr->adoEOF )
{
nItemIndex++;
if( bPageDnUp && bSonglistTable && nItemIndex <= (m_nPageIndex-1)*10 )//控制查詢歌曲時的翻頁
{
pRequestPtr->MoveNext();
continue;
}
if( !bPageDnUp && bSonglistTable && m_nMenuIndex == 3 )//當前的查詢為按字母查詢,則從所有的歌中找出歌名首字母中含有要查詢字母的歌
{
strFstAlphabet = (LPCTSTR)(_bstr_t)pRequestPtr->GetCollect("fstalphabet");
if( strFstAlphabet.Find(m_strAlphabet) != 0 )
{
pRequestPtr->MoveNext();
continue;
}
}
int nID;
nItemNum++;
if( !bPageDnUp )//是否為翻頁, 否, 則把ID存入數組
{
vtID = pRequestPtr->GetCollect("ID");
nID = atoi((LPCTSTR)(_bstr_t)vtID);
m_pSelectID[nItemNum] = nID;
}
if( nItemNum <= 10 )//每頁顯示十首歌,當nItemNum>10時,不再顯示
{
vtsinger = pRequestPtr->GetCollect("singer");
vtsongname = pRequestPtr->GetCollect("songname");
strmsg.Format( "%-3d、 %-20s %-10s",
nItemNum,
(LPCTSTR)(_bstr_t)vtsongname,
(LPCTSTR)(_bstr_t)vtsinger );
TextOut(&dc.m_hDC, xpos, ypos+=40, strmsg);
}
pRequestPtr->MoveNext();
}
// TextOut(&dc.m_hDC,
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
return;
}
}
//////////////////////////////////////////////////////////////////////////////////
//函數功能: 將選定的歌曲加到數據庫中
/*參數說明: nIndex: 選定歌曲在數組m_pSelectID中的下標
返回值說明: 返回0: 失敗 返回1: 成功 返回2: 該歌已選過*/
BOOL CClientWnd::AddSong(int nIndex)
{
if(nIndex > m_pSelectID[0])
return 0;
char hostname[256];
gethostname(hostname, sizeof(hostname));
try
{
CString strsql;
strsql.Format("select * from songlist where ID=%d", m_pSelectID[nIndex]);
_RecordsetPtr pRequestPtr;
pRequestPtr = m_addrecord.GetRecordsetPtr(strsql);
char szID[10];
_variant_t vtsongname;
_variant_t vtsinger;
itoa(m_pSelectID[nIndex], szID, 10);
vtsongname = pRequestPtr->GetCollect("songname");
vtsinger = pRequestPtr->GetCollect("singer");
if( m_addrecord.SaveRecord(m_pSelectID[nIndex], hostname, vtsongname, vtsinger) == 2 )
return 2;
}
catch(_com_error e)
{
AfxMessageBox((CString)e.ErrorMessage() + "選歌失敗");
return 0;
}
return 1;
}
void CClientWnd::SetUsedTime(LPCTSTR lpszUsedTime)
{
m_strUsedTime = lpszUsedTime;
}
void CClientWnd::SetPayforMoney(LPCTSTR lpszPayforMoney)
{
m_strPayforMoney = lpszPayforMoney;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -