📄 lottodbmgr.cpp
字号:
// LottoDBMgr.cpp: implementation of the CLottoDBMgr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "network.h"
#include "LottoDBMgr.h"
#include "sql.h"
#include "sqlext.h"
#include "Hong_Sub.h"
#include "Mylog.h"
#include <direct.h>
#include <STDIO.H>
#define SADONIX_NO 1046
#define SQLOK( x ) ( (x) == SQL_SUCCESS_WITH_INFO || (x) == SQL_SUCCESS ) //1027 YGI
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLottoDBMgr* CLottoDBMgr::m_pClass = NULL;
CLottoDBMgr::CLottoDBMgr()
{
Clear();
m_pClass = this;
m_nLottoNumberCount = 4;//泅犁绰 匙俺狼 锅龋父栏肺 茄促.
// m_nGiveItemNumber = SADONIX_NO;//扁夯篮 荤靛 坷葱胶甫 霖促.
memset(m_anGiveItemNumber,0,sizeof(int)*5);//殿荐喊肺 瘤鞭登绰 酒捞袍 锅龋.
memset(m_anItemCount4Grade,0,sizeof(int)*5);//殿荐喊肺 瘤鞭登绰 酒捞袍 百荐.
memset(m_anWinNumberCount4Grade,0,sizeof(int)*5);//割俺狼 傈龋啊 嘎酒具 割殿牢啊..
memset(m_anWinNumbers,0,sizeof(int)*10);
m_nLottoPay = 0;
mkdir( "LotteryLog" );
}
CLottoDBMgr::~CLottoDBMgr()
{
Clear();
}
void CLottoDBMgr::Clear()
{
// memset(&m_Lotto_Info,0,sizeof(m_Lotto_Info));
m_pClass = NULL;
m_hDragonDB = NULL;
}
bool CLottoDBMgr::LoadTable(HDBC hDBC)
{
// memset(&m_Lotto_Info,0,sizeof(m_Lotto_Info));
m_hDragonDB = hDBC;
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
sprintf(szQuerry, "SELECT * FROM Lotto_Setting");
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
if (!SQLOK(retCode))
{
MyLog(0,"Lotto_Setting Table ....Loading Error!!!!");
SQLFreeStmt(hStmt, SQL_DROP);
return 0;
}
retCode = SQLFetch(hStmt);
if (!SQLOK(retCode))
{
MyLog(0,"Lotto_Setting Table ....No Data!!!!");
SQLFreeStmt(hStmt, SQL_DROP);
return 0;
}
SQLGetData(hStmt,1,SQL_C_LONG,&m_nLottoNumberCount,0,&cbValue);
SQLGetData(hStmt,2,SQL_C_LONG,&m_anGiveItemNumber[0],0,&cbValue);
SQLGetData(hStmt,3,SQL_C_LONG,&m_anGiveItemNumber[1],0,&cbValue);
SQLGetData(hStmt,4,SQL_C_LONG,&m_anGiveItemNumber[2],0,&cbValue);
SQLGetData(hStmt,5,SQL_C_LONG,&m_anGiveItemNumber[3],0,&cbValue);
SQLGetData(hStmt,6,SQL_C_LONG,&m_anGiveItemNumber[4],0,&cbValue);
SQLGetData(hStmt,7,SQL_C_LONG,&m_anItemCount4Grade[0],0,&cbValue);
SQLGetData(hStmt,8,SQL_C_LONG,&m_anItemCount4Grade[1],0,&cbValue);
SQLGetData(hStmt,9,SQL_C_LONG,&m_anItemCount4Grade[2],0,&cbValue);
SQLGetData(hStmt,10,SQL_C_LONG,&m_anItemCount4Grade[3],0,&cbValue);
SQLGetData(hStmt,11,SQL_C_LONG,&m_anItemCount4Grade[4],0,&cbValue);
SQLGetData(hStmt,12,SQL_C_LONG,&m_anWinNumberCount4Grade[0],0,&cbValue);
SQLGetData(hStmt,13,SQL_C_LONG,&m_anWinNumberCount4Grade[1],0,&cbValue);
SQLGetData(hStmt,14,SQL_C_LONG,&m_anWinNumberCount4Grade[2],0,&cbValue);
SQLGetData(hStmt,15,SQL_C_LONG,&m_anWinNumberCount4Grade[3],0,&cbValue);
SQLGetData(hStmt,16,SQL_C_LONG,&m_anWinNumberCount4Grade[4],0,&cbValue);
SQLGetData(hStmt,17,SQL_C_LONG,&m_nLottoPay,0,&cbValue);
SQLFreeStmt(hStmt, SQL_DROP);
sprintf(szQuerry, "SELECT * FROM Lotto_Event");
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
if (!SQLOK(retCode))
{
SQLFreeStmt(hStmt, SQL_DROP);
return 0;
}
retCode = SQLFetch(hStmt);
if(!SQLOK(retCode))//抛捞喉俊 郴侩捞 绝促
{
SQLFreeStmt(hStmt, SQL_DROP);
return false;
}
while (SQLOK(retCode))
{
/*
SQLGetData(hStmt, 1, SQL_C_LONG, &m_Lotto_Info.nLottoID, 0, &cbValue);//LottoID 付瘤阜 雀瞒狼 肺肚 酒捞叼啊 肺靛 等促.
SQLGetData(hStmt, 2, SQL_C_LONG, &m_Lotto_Info.StartDate.tm_year, 0, &cbValue);
SQLGetData(hStmt, 3, SQL_C_LONG, &m_Lotto_Info.StartDate.tm_mon, 0, &cbValue);
SQLGetData(hStmt, 4, SQL_C_LONG, &m_Lotto_Info.StartDate.tm_wday, 0, &cbValue);
SQLGetData(hStmt, 5, SQL_C_LONG, &m_Lotto_Info.LotteryDate.tm_year, 0, &cbValue);
SQLGetData(hStmt, 6, SQL_C_LONG, &m_Lotto_Info.LotteryDate.tm_mon, 0, &cbValue);
SQLGetData(hStmt, 7, SQL_C_LONG, &m_Lotto_Info.LotteryDate.tm_wday, 0, &cbValue);
SQLGetData(hStmt, 8, SQL_C_LONG, &m_Lotto_Info.nWinNumCount, 0, &cbValue);
*/
SQLGetData(hStmt, 9, SQL_C_LONG, &m_anWinNumbers[0], 0, &cbValue);
SQLGetData(hStmt, 10, SQL_C_LONG, &m_anWinNumbers[1], 0, &cbValue);
SQLGetData(hStmt, 11, SQL_C_LONG, &m_anWinNumbers[2], 0, &cbValue);
SQLGetData(hStmt, 12, SQL_C_LONG, &m_anWinNumbers[3], 0, &cbValue);
SQLGetData(hStmt, 13, SQL_C_LONG, &m_anWinNumbers[4], 0, &cbValue);
SQLGetData(hStmt, 14, SQL_C_LONG, &m_anWinNumbers[5], 0, &cbValue);
SQLGetData(hStmt, 15, SQL_C_LONG, &m_anWinNumbers[6], 0, &cbValue);
SQLGetData(hStmt, 16, SQL_C_LONG, &m_anWinNumbers[7], 0, &cbValue);
SQLGetData(hStmt, 17, SQL_C_LONG, &m_anWinNumbers[8], 0, &cbValue);
SQLGetData(hStmt, 18, SQL_C_LONG, &m_anWinNumbers[9], 0, &cbValue);
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
return true;
}
void CLottoDBMgr::RecvNewEvent(LOTTO_EVENT_INFO* pInfo,int cn)
{
// if(m_Lotto_Info.nLottoID >= pInfo->nLottoID)return;//捞傈 肺肚 雀瞒啊 货肺款巴焊促 农搁 酒公老档.
//Lotte_User 抛捞喉阑 彬阐洒...窍扁 傈俊. 肺弊甫 巢扁磊.
char szQuerry[512];
char szFileName[512];
RETCODE retCode;
HSTMT hStmt = NULL;
sprintf(szQuerry, "SELECT * from Lotto_Users order by User_ID");
sprintf(szFileName,"./LotteryLog/_%dUsers.txt",pInfo->nLottoID - 1);//soto-031126
FILE* fp = fopen( szFileName, "at+" );//soto-031126
if(fp != NULL)
{
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
retCode = SQLFetch(hStmt);
SDWORD cbValue;
while(SQLOK(retCode))
{
int ct = 0;
char szUserID[20] = {0,};
int nLottoID = 0;
int nLottoNumberCount = 0;
int anLottoNumbers[10] = {0,};
::SQLGetData(hStmt, ++ct, SQL_C_CHAR, szUserID, 20, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &nLottoID, 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &nLottoNumberCount, 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[0], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[1], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[2], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[3], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[4], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[5], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[6], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[7], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[8], 0, &cbValue);
::SQLGetData(hStmt, ++ct, SQL_C_LONG, &anLottoNumbers[9], 0, &cbValue);
::EatRearWhiteChar(szUserID);
fprintf(fp,"LottoID : %4d, UserID : [%s], LottoNumbers : ",nLottoID,szUserID);
for(int i = 0; i < nLottoNumberCount;++i)
{
fprintf(fp," %2d",anLottoNumbers[i]);
}
fprintf(fp,"\n");
retCode = SQLFetch(hStmt);
}
fclose(fp);
}
else
{
}
if(m_hDragonDB)
{
sprintf(szQuerry, "DELETE from Lotto_Users");
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
if(!SQLOK(retCode))
{
SQLFreeStmt(hStmt, SQL_DROP);
return;
}
SQLFreeStmt(hStmt, SQL_DROP);
}
SendNewEvent(pInfo,cn);
}
void CLottoDBMgr::SendNewEvent(LOTTO_EVENT_INFO *pInfo,int cn)
{
if(InsertToTabeInfo(pInfo))
{
t_packet p;
p.h.header.type = CMD_NEW_EVENT;
p.h.header.size = sizeof(LOTTO_EVENT_INFO);
// memcpy(&m_Lotto_Info,pInfo,sizeof(LOTTO_EVENT_INFO));
memset(m_anWinNumbers,0,sizeof(int)*10);
memcpy(&p.u.Lotto_Info,pInfo,sizeof(LOTTO_EVENT_INFO));
QueuePacket(connections,cn,&p,1);
}
}
bool CLottoDBMgr::InsertToTabeInfo(LOTTO_EVENT_INFO *pInfo)
{
if(m_hDragonDB)
{
// if(pInfo->nLottoID <= m_Lotto_Info.nLottoID)return false;
HSTMT hStmt = NULL;
RETCODE retCode;
char szQuerry[512];
sprintf(szQuerry,
"insert into Lotto_Event (Lotto_ID, StartYear, StartMonth, StartDay, LotteryYear, LotteryMonth, LotteryDay, WinNumCount, WinNumber1,WinNumber2,WinNumber3,WinNumber4,WinNumber5,WinNumber6,WinNumber7,WinNumber8,WinNumber9,WinNumber10) values ( %d , %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d )",
pInfo->nLottoID,
pInfo->StartDate.tm_year,pInfo->StartDate.tm_mon,pInfo->StartDate.tm_mday,
pInfo->LotteryDate.tm_year,pInfo->LotteryDate.tm_mon,pInfo->LotteryDate.tm_mday,
pInfo->nWinNumCount,
pInfo->anWinNumbers[0],pInfo->anWinNumbers[1],pInfo->anWinNumbers[2],pInfo->anWinNumbers[3],pInfo->anWinNumbers[4],
pInfo->anWinNumbers[5],pInfo->anWinNumbers[6],pInfo->anWinNumbers[7],pInfo->anWinNumbers[8],pInfo->anWinNumbers[9]
);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
SQLFreeStmt(hStmt, SQL_DROP);
return SQLOK(retCode);
}
return false;
}
void CLottoDBMgr::RecvCanBuyLotto(t_BUY_LOTTO *pCanBuy,int cn)
{
t_packet p;
p.h.header.type = CMD_CAN_BUY;
p.h.header.size = sizeof(t_BUY_LOTTO);
strcpy(p.u.Lotto_Buy.strCharName,pCanBuy->strCharName);
char strUserID[21] = {NULL,};
GetUserIDFromName(pCanBuy->strCharName,strUserID);
if(!strlen(strUserID))
{
return;
}
int nBuyCount = GetBuyCountByUser(strUserID, pCanBuy->nLottoID);
p.u.Lotto_Buy.nLottoID = pCanBuy->nLottoID;
if(nBuyCount == 0)//公炼扒 混荐 乐促.
{
memcpy(p.u.Lotto_Buy.anLottoNumber,pCanBuy->anLottoNumber,sizeof(int)*10);
}
else//soto-Lotto眠啊 if(nBuyCount < 5)// 吝汗 锅龋 八荤甫 秦具茄促.
{
//soto-031126 荐摹 炼例狼 巩力肺 茄惫率俊绰 10厘狼 茄拌甫 敌促.
if(LocalMgr.IsAbleNation(KOREA))
{
if(nBuyCount < 10) // BBD 040211 50厘俊辑 10厘 力茄栏肺 函版凳
{
}
else
{ //< CSD-031127
p.u.Lotto_Buy.anLottoNumber[0] = -2; // -2 汗鼻阑 腹捞 或促.
QueuePacket(connections,cn,&p,1);
return;
} //> CSD-031127
}
if(!ExistLottoNumber(pCanBuy->anLottoNumber,strUserID,pCanBuy->nLottoID))//吝汗 登瘤 臼疽促.
{
memcpy(p.u.Lotto_Buy.anLottoNumber,pCanBuy->anLottoNumber,sizeof(int)*10);
}
else//吝汗 登绰 锅龋啊 乐促.
{
p.u.Lotto_Buy.anLottoNumber[0] = -3; // -3 吝汗 登绰 锅龋.
}
}
//soto-Lotto眠啊
/*
else//混荐 乐绰 父怒 促或促.
{
p.u.Lotto_Buy.anLottoNumber[0] = -2; // -2 汗鼻阑 腹捞 或促.
}
*/
QueuePacket(connections,cn,&p,1);
}
int CLottoDBMgr::GetBuyCountByUser(char *pUserID , int nLottoID)
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
char szQuerry[512];
int nRet = 0;
sprintf(szQuerry, "SELECT * FROM Lotto_Users WHERE User_ID = '%s' and Lotto_ID = %d",pUserID,nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
retCode = SQLFetch(hStmt);
if (!SQLOK(retCode))
{
SQLFreeStmt(hStmt, SQL_DROP);
return nRet;
}
while(SQLOK(retCode))
{
nRet++;
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
return nRet;
}
return 0;
}
int CLottoDBMgr::ExistLottoNumber(int anNumber[], char *pUserID , int nLottoID)//soto-LottoADD
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
int nRet = 0;
sprintf(szQuerry, "SELECT "
"Lotto_Numbers1 Lotto_Numbers2 Lotto_Numbers3 Lotto_Numbers4 Lotto_Numbers5 "
"Lotto_Numbers6 Lotto_Numbers7 Lotto_Numbers8 Lotto_Numbers9 Lotto_Numbers10 "
"FROM Lotto_Users WHERE User_ID = '%s' and Lotto_ID = %d",
pUserID, nLottoID);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
retCode = SQLFetch(hStmt);
if (!SQLOK(retCode))
{
SQLFreeStmt(hStmt, SQL_DROP);
return nRet; //锅龋啊 绝促.持绢扼.
}
int anLottoNum[10] = {0,};
while(SQLOK(retCode))
{
int nSameNum = 0;
int nCt = 1;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);++nCt;
SQLGetData(hStmt, nCt, SQL_C_LONG, &anLottoNum[nCt-1], 0, &cbValue);
nSameNum = this->CheckTwoLottos(anNumber,anLottoNum,m_nLottoNumberCount);
if(nSameNum >= m_nLottoNumberCount)
{
SQLFreeStmt(hStmt, SQL_DROP);
return 1;//粮犁 茄促. 持瘤 付扼.
}
retCode = SQLFetch(hStmt);
}
SQLFreeStmt(hStmt, SQL_DROP);
return 0;//持阑荐 乐促.
}
return 1;//持阑荐 绝促.
}
void CLottoDBMgr::GetUserIDFromName(const char *pName, char strID[])
{
if(m_hDragonDB)
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
char szQuerry[512];
int nRet = 0;
sprintf(szQuerry, "SELECT login_id FROM Chr_Info WHERE name = '%s'",pName);
SQLAllocStmt(m_hDragonDB, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)szQuerry, SQL_NTS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -