📄 lottodbmgr.cpp
字号:
if (!SQLOK(retCode))
{
SQLFreeStmt(hStmt, SQL_DROP);
return;
}
retCode = SQLFetch(hStmt);
if(SQLOK(retCode))
{
SQLGetData(hStmt, 1, SQL_C_CHAR, strID, 20, &cbValue);
::EatRearWhiteChar(strID);
}
SQLFreeStmt(hStmt, SQL_DROP);
}
}
void CLottoDBMgr::RecvLottoBuy(t_BUY_LOTTO *pBuyLotto)
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
char szQuerry[512];
int nLottoCount = 0;
int nRet = 0;
char strUserID[21] = {NULL,};
GetUserIDFromName(pBuyLotto->strCharName,strUserID);
if(!strlen(strUserID))return;
nLottoCount = m_nLottoNumberCount;
sprintf(
szQuerry,
"insert into Lotto_Users "
" values( '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
strUserID, pBuyLotto->nLottoID, nLottoCount,
pBuyLotto->anLottoNumber[0],
pBuyLotto->anLottoNumber[1],
pBuyLotto->anLottoNumber[2],
pBuyLotto->anLottoNumber[3],
pBuyLotto->anLottoNumber[4],
pBuyLotto->anLottoNumber[5],
pBuyLotto->anLottoNumber[6],
pBuyLotto->anLottoNumber[7],
pBuyLotto->anLottoNumber[8],
pBuyLotto->anLottoNumber[9]
);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode= SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
if(!SQLOK(retCode))//火涝 角菩.
{
// SQLFreeStmt(hStmt, SQL_DROP);
printf("Lotto Insert failed ID : %s , Name : %s",strUserID,pBuyLotto->strCharName);
// return;
}
// retCode = SQLExecute(hStmt) ;
SQLFreeStmt(hStmt, SQL_DROP);
return;
}
}
void CLottoDBMgr::RecvWinnerCheck(t_CHECK_WINNER *pCheckWinner, int cn)
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
int nLottoPaperCount = 0;
char strUserID[21] = {NULL,};
GetUserIDFromName(pCheckWinner->strCharName,strUserID);
if(!strlen(strUserID))return;
sprintf(szQuerry, "SELECT * FROM Lotto_Users WHERE [User_ID] = '%s' AND [Lotto_ID] = %d",strUserID,pCheckWinner->nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
retCode = SQLFetch(hStmt);
while(SQLOK(retCode))
{
nLottoPaperCount++;
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
int nItemCount = 0;
if(nLottoPaperCount)
{
sprintf(szQuerry, "SELECT * FROM Lotto_Users WHERE [User_ID] = '%s' AND [Lotto_ID] = %d",strUserID,pCheckWinner->nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
WORD ct = 4;
int anWinItemsCount[5] = {0,};
retCode = SQLFetch(hStmt);
if(SQLOK(retCode))//蜡历啊 乐促.
{
for(int i = 0;i < nLottoPaperCount;i++)
{
int anLottoNumber[10] = {0,};
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[0],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[1],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[2],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[3],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[4],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[5],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[6],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[7],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[8],0,&cbValue);ct++;
SQLGetData(hStmt,ct,SQL_C_LONG,&anLottoNumber[9],0,&cbValue);
int nSame = 0;
nSame = CheckTwoLottos(anLottoNumber,pCheckWinner->anWinNumbers,m_nLottoNumberCount);
if(nSame == m_anWinNumberCount4Grade[0])
{
nItemCount += m_anItemCount4Grade[0];
anWinItemsCount[0] += m_anItemCount4Grade[0];
}
else if(nSame == m_anWinNumberCount4Grade[1])
{
nItemCount += m_anItemCount4Grade[1];
anWinItemsCount[1] += m_anItemCount4Grade[1];
}
else if(nSame == m_anWinNumberCount4Grade[2])
{
nItemCount += m_anItemCount4Grade[2];
anWinItemsCount[2] += m_anItemCount4Grade[2];
}
else if(nSame == m_anWinNumberCount4Grade[3])
{
nItemCount += m_anItemCount4Grade[3];
anWinItemsCount[3] += m_anItemCount4Grade[3];
}
else if(nSame == m_anWinNumberCount4Grade[4])
{
nItemCount += m_anItemCount4Grade[4];
anWinItemsCount[4] += m_anItemCount4Grade[4];
}
retCode = SQLFetch(hStmt);
ct = 4;
}
}
else//弊繁 蜡历 绝促.
{
}
SQLFreeStmt(hStmt, SQL_DROP);
t_packet p;
p.h.header.type = CMD_CHECK_OK;
p.h.header.size = sizeof(t_CHECK_WINNER);
memcpy(&p.u.Check_Winner,pCheckWinner,sizeof(t_CHECK_WINNER));
p.u.Check_Winner.nWinItemCount = nItemCount;
memcpy(p.u.Check_Winner.anWinItemsCount,anWinItemsCount,sizeof(int)*5);
QueuePacket(connections,cn,&p,1);
}
//<! BBD 040127 甘辑滚俊 皋矫瘤 焊郴辑 喉废阑 钱绢林扼绊 茄促
else // 捞仇篮 茄厘档 臼巢疽促. 喉废父 钱绊 场郴磊
{
t_packet p;
p.h.header.type = CMD_DEL_LOTTO_USER_OK;
p.h.header.size = sizeof(t_DEL_LOTTO_USER_OK);
p.u.Lotto_Del_Ok.bIsDelOK = true;
QueuePacket(connections,cn,&p,1);
}
//> BBD 040127 甘辑滚俊 皋矫瘤 焊郴辑 喉废阑 钱绢林扼绊 茄促
}
}
void CLottoDBMgr::RecvDelUser(t_CHECK_WINNER *pDelUser, int cn) // BBD 040127 牢磊 眠啊
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
char szQuerry[512];
int nLottoCount = 0;
char strUserID[21] = {NULL,};
GetUserIDFromName(pDelUser->strCharName,strUserID);
if(!strlen(strUserID))return;
sprintf(szQuerry, "DELETE from Lotto_Users WHERE User_ID = '%s'",strUserID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
SQLFreeStmt(hStmt, SQL_DROP);
//<! BBD 040127 沥惑利栏肺 蜡历甫 昏力窍看澜阑 甘辑滚俊 舅赴促
// 父老 retCode啊 巩力乐促搁 绢痘霸 费归矫懦巴牢啊? 老窜 肺弊父 巢扁磊
if(retCode != SQL_SUCCESS)
{
FILE *fp;
fp = fopen( "QuerryError.txt","at+" );
if( fp )
{
fprintf( fp, szQuerry );
fclose(fp);
}
}
t_packet p;
p.h.header.type = CMD_DEL_LOTTO_USER_OK;
p.h.header.size = sizeof(t_DEL_LOTTO_USER_OK);
p.u.Lotto_Del_Ok.bIsDelOK = true;
QueuePacket(connections,cn,&p,1);
//> BBD 040127 沥惑利栏肺 蜡历甫 昏力窍看澜阑 甘辑滚俊 舅赴促
}
}
int CLottoDBMgr::CheckTwoLottos(int anTarget[], int anSource[], int count)
{
int nCount = 0;
for(int i = 0;i < count;i++)
{
for(int j = 0;j < count;j++)
{
if(anTarget[i] == anSource[j])
nCount++;
}
}
return nCount;
}
void CLottoDBMgr::RecvLottery(LOTTO_EVENT_INFO *pLottery,int cn)
{
// memcpy(&m_Lotto_Info,pLottery,sizeof(LOTTO_EVENT_INFO));
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
char szQuerry[512];
int nLottoCount = 0;
sprintf(
szQuerry,
"Update Lotto_Event set "
"LotteryYear = %d, LotteryMonth = %d, LotteryDay = %d, WinNumCount = %d, "
"WinNumber1 = %d, WinNumber2 = %d, WinNumber3 = %d, WinNumber4 = %d, WinNumber5 = %d, WinNumber6 = %d"
", WinNumber7 = %d , WinNumber8 = %d, WinNumber9 = %d, WinNumber10 = %d WHERE Lotto_ID = %d",
pLottery->LotteryDate.tm_year, pLottery->LotteryDate.tm_mon, pLottery->LotteryDate.tm_mday,
pLottery->nWinNumCount,
pLottery->anWinNumbers[0],pLottery->anWinNumbers[1],pLottery->anWinNumbers[2],pLottery->anWinNumbers[3],pLottery->anWinNumbers[4],
pLottery->anWinNumbers[5],pLottery->anWinNumbers[6],pLottery->anWinNumbers[7],pLottery->anWinNumbers[8],pLottery->anWinNumbers[9],
pLottery->nLottoID
);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
if(!SQLOK(retCode))
{
MyLog(0,"Lotto Lotto_Event Update...Fail.... Lotto Emergency!!!!!!!!!!");
}
SQLFreeStmt(hStmt, SQL_DROP);
memcpy(m_anWinNumbers,pLottery->anWinNumbers,sizeof(int)*10);
}
t_packet p;
p.h.header.type = CMD_LOTTERY_INFO;
p.h.header.size = sizeof(LOTTO_EVENT_INFO);
memcpy(&p.u.Lotto_Info,pLottery,sizeof(LOTTO_EVENT_INFO));
QueuePacket(connections,cn,&p,1);//甘 辑滚肺 焊郴 霖促.
}
void CLottoDBMgr::RecvCheckOpenWinnerMenu(t_WINNER_MENU *pWinnerMenu,int cn)
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
int nLottoPaperCount = 0;
char strUserID[21] = {NULL,};
GetUserIDFromName(pWinnerMenu->strCharName,strUserID);
if(!strlen(strUserID))return;
sprintf(szQuerry, "SELECT * FROM Lotto_Users WHERE User_ID = '%s' AND Lotto_ID = %d",strUserID,pWinnerMenu->nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
t_packet p;
p.h.header.type = CMD_CHECK_WINNER_MENU;
p.h.header.size = sizeof(t_WINNER_MENU);
memcpy(&p.u.Lotto_Winner_Menu,pWinnerMenu,sizeof(t_WINNER_MENU));
// p.u.Lotto_Winner_Menu.nPage = 1;
p.u.Lotto_Winner_Menu.nViewCount = 0;
memset(p.u.Lotto_Winner_Menu.anLottoNumber,0,sizeof(int)*10*5);
memset(p.u.Lotto_Winner_Menu.anWinNumbers,0,sizeof(int)*10);
retCode = SQLFetch(hStmt);//霉锅掳临捞 乐绰啊.
while(SQLOK(retCode))
{
if(nLottoPaperCount >= 5)break;
SQLGetData(hStmt,4,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][0],4,&cbValue);
SQLGetData(hStmt,5,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][1],4,&cbValue);
SQLGetData(hStmt,6,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][2],4,&cbValue);
SQLGetData(hStmt,7,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][3],4,&cbValue);
SQLGetData(hStmt,8,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][4],4,&cbValue);
SQLGetData(hStmt,9,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][5],4,&cbValue);
SQLGetData(hStmt,10,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][6],4,&cbValue);
SQLGetData(hStmt,11,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][7],4,&cbValue);
SQLGetData(hStmt,12,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][8],4,&cbValue);
SQLGetData(hStmt,13,SQL_C_LONG,&p.u.Lotto_Winner_Menu.anLottoNumber[nLottoPaperCount][9],4,&cbValue);
nLottoPaperCount++;
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
p.u.Lotto_Winner_Menu.nViewCount = nLottoPaperCount;
memcpy(p.u.Lotto_Winner_Menu.anWinNumbers,m_anWinNumbers,sizeof(int)*10);
p.u.Lotto_Winner_Menu.nTotalLottoCount = GetLottoCount(p.u.Lotto_Winner_Menu.strCharName,p.u.Lotto_Winner_Menu.nLottoID);
::QueuePacket(connections,cn,&p,1);
}
}
int CLottoDBMgr::GetLottoPay()
{
return m_nLottoPay;
}
void CLottoDBMgr::RecvLottoSeek(t_LOTTOPAPER_SEEK *pLotto_Seek, int cn)
{
packet p;
p.h.header.type = CMD_LOTTO_SEEK;
p.h.header.size = sizeof(t_LOTTOPAPER_SEEK);
memcpy(&p.u.Lotto_Seek,pLotto_Seek,sizeof(t_LOTTOPAPER_SEEK));
int nLottoPaperCount = 0;
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
char strUserID[21] = {NULL,};
GetUserIDFromName(pLotto_Seek->strChrName,strUserID);
if(!strlen(strUserID))return;
sprintf(szQuerry, "SELECT * FROM Lotto_Users WHERE User_ID = '%s' AND Lotto_ID = %d",strUserID,pLotto_Seek->nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
for(int i = 0;i < ((pLotto_Seek->nPage-1) * 5);++i)
{
retCode = SQLFetch(hStmt);
if(!SQLOK(retCode))break;
}
retCode = SQLFetch(hStmt);
while(SQLOK(retCode))
{
if(nLottoPaperCount >= 5)break;
SQLGetData(hStmt,4,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][0],4,&cbValue);
SQLGetData(hStmt,5,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][1],4,&cbValue);
SQLGetData(hStmt,6,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][2],4,&cbValue);
SQLGetData(hStmt,7,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][3],4,&cbValue);
SQLGetData(hStmt,8,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][4],4,&cbValue);
SQLGetData(hStmt,9,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][5],4,&cbValue);
SQLGetData(hStmt,10,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][6],4,&cbValue);
SQLGetData(hStmt,11,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][7],4,&cbValue);
SQLGetData(hStmt,12,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][8],4,&cbValue);
SQLGetData(hStmt,13,SQL_C_LONG,&p.u.Lotto_Seek.anLottoNumber[nLottoPaperCount][9],4,&cbValue);
nLottoPaperCount++;
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
}
if(nLottoPaperCount <= 0)
{
p.u.Lotto_Seek.nPage = 0;
}
p.u.Lotto_Seek.nViewCount = nLottoPaperCount;
QueuePacket(connections,cn,&p,1);
}
int CLottoDBMgr::GetLottoCount(const char *pCharName, int nLottoID)
{
int nRet = -1;
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
int nLottoPaperCount = 0;
char strUserID[21] = {NULL,};
GetUserIDFromName(pCharName,strUserID);
if(!strlen(strUserID))return nRet;
sprintf(szQuerry, "SELECT count(*) FROM Lotto_Users WHERE User_ID = '%s' AND Lotto_ID = %d",strUserID,nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
retCode = SQLFetch(hStmt);
if(SQLOK(retCode))
{
SQLGetData(hStmt,1,SQL_C_LONG,&nLottoPaperCount,0,&cbValue);
nRet = nLottoPaperCount;
}
SQLFreeStmt(hStmt, SQL_DROP);
}
return nRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -