// GetHanBilling.cpp : ÄÜ¼Ö ÀÀ¿ë ÇÁ·Î±×·¥¿¡ ´ëÇÑ ÁøÀÔÁ¡À» Á¤ÀÇÇÕ´Ï´Ù. // #include "stdafx.h" #include #include #include #include #include #include #include #include #include using namespace std; #pragma pack(1) //##### KTE - EDIT 20041207 ##### struct HanBillingData { //DBCHAR m_EndDate[20]; //DBCHAR m_MemberID[20]; //DBCHAR m_BillNum[11]; //DBCHAR m_RylUID[11]; //DBCHAR m_GameMin[11]; //DBCHAR m_BillingType[2]; DBCHAR m_MemberID[20]; DBCHAR m_RegDate[20]; DBCHAR m_BillEndDate[20]; DBCHAR m_KeeperSeq[11]; DBCHAR m_RylUID[11]; DBCHAR m_AddedDay[11]; DBCHAR m_AddedTime[11]; DBCHAR m_AddedMonth[11]; DBCHAR m_AutoBill[2]; }; #pragma pack() template inline basic_ostream<_Elem, _Traits>& __cdecl writetime(basic_ostream<_Elem, _Traits>& _Ostr) { SYSTEMTIME systime; GetLocalTime(&systime); _Elem fill = _Ostr.fill(); _Ostr << setfill('0') << "[" << setw(4) << systime.wYear << "-" << setw(2) << systime.wMonth << "-" << setw(2) << systime.wDay << " " << setw(2) << systime.wHour << ":" << setw(2) << systime.wMinute << ":" << setw(2) << systime.wSecond << "] " << setfill(fill); return (_Ostr); } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { CLog log; CConfigurator config; OleDB hanDB; OleDB billingDB; char szQuery[OleDB::MaxQueryTextLen]; int nQueryLen = 0; if(!log.RedirectStdOut("GetHanBillingLog")) { return -1; } cout << endl << writetime << "Äõ¸®¸¦ ½ÇÇàÇÕ´Ï´Ù." << endl; TCHAR* tszConfigFileName = TEXT("BillingInfo.cfg"); if(!config.Load(tszConfigFileName)) { cout << writetime << tszConfigFileName << "DB¼³Á¤ ÆÄÀÏÀ» ÀÐÀ» ¼ö ¾ø½À´Ï´Ù." << endl; return -1; } const char* szHanServerName = config.Get("HanServerName"); const char* szHanDBName = config.Get("HanDBName"); const char* szHanUserName = config.Get("HanUserName"); const char* szHanPassword = config.Get("HanPassword"); if(!hanDB.ConnectSQLServer(szHanServerName, szHanDBName, szHanUserName, szHanPassword, OleDB::ConnType_ORACLE)) { cout << writetime << "ÇѰÔÀÓDB : Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù. : " << hanDB.GetErrorString() << " ServerName : " << szHanServerName << " DBName : " << szHanDBName << " UserName : " << szHanUserName << " Password : " << szHanPassword << endl; return -1; } const char* szBillingServerName = config.Get("BillingServerName"); const char* szBillingDBName = config.Get("BillingDBName"); const char* szBillingUserName = config.Get("BillingUserName"); const char* szBillingPassword = config.Get("BillingPassword"); if(!billingDB.ConnectSQLServer(szBillingServerName, szBillingDBName, szBillingUserName, szBillingPassword, OleDB::ConnType_MSSQL)) { cout << writetime << "ºô¸µDB : Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù. : " << billingDB.GetErrorString() << " ServerName : " << szBillingServerName << " DBName : " << szBillingDBName << " UserName : " << szBillingUserName << " Password : " << szBillingPassword << endl; return -1; } // Å×À̺í Ŭ¸®¾î if(!billingDB.ExcuteQuery("EXEC agt_PersonBilling_Delete")) { cout << writetime << "ºô¸µDB : Àӽà Å×ÀÌºí »èÁ¦¿¡ ½ÇÆÐÇß½À´Ï´Ù : " << billingDB.GetErrorString() << endl; return -1; } // µ¥ÀÌÅÍ °¡Á®¿À±â int nMinNum = 0; if(!billingDB.ExcuteQueryGetData( "SELECT intCount FROM TblImportedNum WHERE strCompType = 'H'", &nMinNum)) { cout << writetime << "ºô¸µDB : ¸¶Áö¸·À¸·Î ó¸®µÈ µ¥ÀÌÅÍ °Ç¼ö ¹øÈ£¸¦ ¾ò¾î¿Ã ¼ö ¾ø½À´Ï´Ù : " << billingDB.GetErrorString() << endl; return -1; } //##### KTE - EDIT 20041207 ##### //nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, // "SELECT TO_CHAR(ENDDATE, 'YYYY-MM-DD HH24:MI:SS '), " // "MEMBERID, " // "CAST(BILLNUM AS VARCHAR(11))," // "CAST(RYLUID AS VARCHAR(11))," // "CAST(GAMEMIN AS VARCHAR(11))," // "CAST(BILLTYPE AS VARCHAR(2)) " // " FROM RYLBILLINGT WHERE BILLNUM > ? AND HanCHK = 'N' ORDER BY BILLNUM ASC"); nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, "SELECT MEMBERID," "TO_CHAR(REGDATE, 'YYYY-MM-DD HH24:MI:SS ')," "TO_CHAR(BILLENDDATE,'YYYY-MM-DD HH24:MI:SS ')," "CAST(KEEPERSEQ AS VARCHAR(11))," "CAST(RYLUID AS VARCHAR(11))," "CAST(ADDEDDAY AS VARCHAR(11))," "CAST(ADDEDTIME AS VARCHAR(11))," "CAST(ADDEDMONTH AS VARCHAR(11))," "CAST(AUTOBILL AS VARCHAR(2)) " "FROM RYLCHECKT WHERE KEEPERSEQ > ? AND CHECKFLAG = 'N' ORDER BY KEEPERSEQ ASC"); if(nQueryLen < 0) { cout << writetime << "ÇѰÔÀÓDB : ºô¸µ µ¥ÀÌÅ͸¦ ¾ò¾î¿À´Â Äõ¸®¸¦ ¸¸µé ¼ö ¾ø½À´Ï´Ù." << endl; return -1; } OleDB::PARAM_INFO BillingInfoParam; memset(&BillingInfoParam, 0, sizeof(OleDB::PARAM_INFO)); BillingInfoParam.ColNum = 1; BillingInfoParam.ColSize[0] = sizeof(int); BillingInfoParam.ColType[0] = DBTYPE_I4; if(!hanDB.ExcuteQueryWithParams(szQuery, reinterpret_cast(&nMinNum), BillingInfoParam, OleDB::Rowset_Get)) { cout << writetime << "ÇѰÔÀÓDB : ºô¸µ Á¤º¸¸¦ ¾ò¾î¿Ã ¼ö ¾ø½À´Ï´Ù : " << hanDB.GetErrorString() << endl; return -1; } typedef std::vector BillingDataArray; BillingDataArray hanBillingArray; hanBillingArray.reserve(5000); const int MAX_DATA = 1000; HanBillingData hanBillingData[MAX_DATA]; memset(hanBillingData, 0, sizeof(HanBillingData) * MAX_DATA); int nReturnRow = 0; while(hanDB.GetData((void**)&hanBillingData, sizeof(HanBillingData), MAX_DATA, &nReturnRow)) { if(0 == nReturnRow) { break; } hanBillingArray.insert(hanBillingArray.end(), hanBillingData, hanBillingData + nReturnRow); memset(hanBillingData, 0, sizeof(HanBillingData) * MAX_DATA); } //##### KTE - EDIT 20041207 ##### // BillNum, MemberID, RylUID, BillingType, EndTime, GameMin //const char* szInsertQuery = "INSERT INTO TblPersonBilling_log " // "(intIndex, strClientID, UID, strBillingType, dateEndTime, intServiceTime, strConvertChk, dateInsertTime) " // "values (%s, '%s', %s, '%s', '%s', %s, 'N', GetDate())"; //const char* szNullEndInsertQuery = "INSERT INTO TblPersonBilling_log " // "(intIndex, strClientID, UID, strBillingType, dateEndTime, intServiceTime, strConvertChk, dateInsertTime) " // "values (%s, '%s', %s, '%s', NULL, %s, 'N', GetDate())"; // BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , BillEndDate , AutoBill ,CheckFlag,InsertTime const char* szInsertQuery = "INSERT INTO dbo.TblRYLCheckT " "(BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , BillEndDate , AutoBill,CheckFlag ,InsertTime) " "VALUES (%s, '%s' , %s , '%s' , %s , %s , %s , '%s' , '%s' , 'N' , GETDATE() )" ; const char* szNullEndInsertQuery = "INSERT INTO dbo.TblRYLCheckT " "(BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , AutoBill,CheckFlag ,InsertTime) " "VALUES (%s, '%s' , %s , '%s' , %s , %s , %s , '%s' , 'N' , GETDATE() )" ; BillingDataArray::iterator pos = hanBillingArray.begin(); BillingDataArray::iterator end = hanBillingArray.end(); for(; pos != end; ++pos) { HanBillingData& data = *pos; //if(0 == strlen(data.m_EndDate)) //{ // nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, szNullEndInsertQuery, // data.m_BillNum, data.m_MemberID, data.m_RylUID, data.m_BillingType, data.m_GameMin); //} //else //{ // nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, szInsertQuery, // data.m_BillNum, data.m_MemberID, data.m_RylUID, data.m_BillingType, // data.m_EndDate, data.m_GameMin); //} if( 0 == strlen(data.m_BillEndDate)) { nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,szNullEndInsertQuery, data.m_KeeperSeq, data.m_MemberID, data.m_RylUID, data.m_RegDate, data.m_AddedDay, data.m_AddedTime, data.m_AddedMonth, data.m_AutoBill); } else { nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,szInsertQuery, data.m_KeeperSeq, data.m_MemberID, data.m_RylUID, data.m_RegDate, data.m_AddedDay, data.m_AddedTime, data.m_AddedMonth, data.m_BillEndDate, data.m_AutoBill); } if(nQueryLen < 0) { return -1; } if(!billingDB.ExcuteQuery(szQuery)) { cout << writetime << "ºô¸µDB : ÇѰÔÀÓ¿¡¼­ °¡Á®¿Â µ¥ÀÌÅ͸¦ ±â·ÏÇÒ ¼ö ¾ø½À´Ï´Ù. : " << billingDB.GetErrorString() << " ÇöÀç BillNum : " << data.m_KeeperSeq << endl; return -1; } } int nMaxNum = 0; //##### KTE - EDIT 20041207 ##### //if(!billingDB.ExcuteQueryGetData( // "SELECT MAX(intIndex) FROM TblPersonBilling_log WHERE strConvertCHK ='N'", &nMaxNum)) if(!billingDB.ExcuteQueryGetData( "SELECT MAX(BillNum) FROM dbo.TblRYLCheckT WHERE CheckFlag = 'N'", &nMaxNum)) { cout << writetime << "ºô¸µDB : ÇѰÔÀÓ¿¡¼­ °¡Á®¿Â µ¥ÀÌÅÍ °Ç¼ö ÃÖ´ë ¹øÈ£¸¦ ¾ò¾î¿Ã ¼ö ¾ø½À´Ï´Ù : " << billingDB.GetErrorString() << endl; return -1; } if(0 < nMaxNum) { //##### KTE - EDIT 20041207 ##### //nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, // "UPDATE RYLBILLINGT SET HANCHK = 'Y' " // "WHERE BILLNUM > ? AND BILLNUM <= ? AND HANCHK = 'N'"); nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, "UPDATE RYLCHECKT SET CHECKFLAG = 'Y' " "WHERE KEEPERSEQ > ? AND KEEPERSEQ <= ? AND CHECKFLAG = 'N'"); if(nQueryLen < 0) { cout << writetime << "ÇѰÔÀÓDB : °ú±Ý ó¸® ¾÷µ¥ÀÌÆ® ½ÇÆÐ - Äõ¸® »ý¼º ½ÇÆÐ" << endl; return -1; } OleDB::PARAM_INFO BillingUpdateParam; memset(&BillingUpdateParam, 0, sizeof(OleDB::PARAM_INFO)); BillingUpdateParam.ColNum = 2; BillingUpdateParam.ColSize[0] = sizeof(int); BillingUpdateParam.ColType[0] = DBTYPE_I4; BillingUpdateParam.ColSize[1] = sizeof(int); BillingUpdateParam.ColType[1] = DBTYPE_I4; char szData[sizeof(int) * 2]; memcpy(szData, &nMinNum, sizeof(int)); memcpy(szData + sizeof(int), &nMaxNum, sizeof(int)); if(!hanDB.ExcuteQueryWithParams(szQuery, szData, BillingUpdateParam, OleDB::Rowset_Update)) { cout << writetime << "ÇѰÔÀÓDB : °ú±Ý ó¸® ¾÷µ¥ÀÌÆ® ½ÇÆÐ - Äõ¸® ½ÇÆÐ : " << hanDB.GetErrorString() << endl; return -1; } nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, "UPDATE TblImportedNum SET intCount = %d WHERE strCompType = 'H'", nMaxNum); if(nQueryLen < 0) { cout << writetime << "ºô¸µDB : °ú±Ý ó¸® ¾÷µ¥ÀÌÆ® ½ÇÆÐ - Äõ¸® »ý¼º ½ÇÆÐ " << " MinBillingNum : " << nMinNum << " MaxBillingNum : " << nMaxNum << endl; return -1; } if(!billingDB.ExcuteQuery(szQuery, OleDB::Rowset_Update)) { cout << writetime << "ºô¸µDB : °ú±Ý ó¸® ¾÷µ¥ÀÌÆ® ½ÇÆÐ - Äõ¸® ½ÇÆÐ : " << billingDB.GetErrorString() << " MinBillingNum : " << nMinNum << " MaxBillingNum : " << nMaxNum << endl; return -1; } } // µ¥ÀÌÅÍ Ã³¸® if(!billingDB.ExcuteQuery("EXEC agt_PersonBilling_CHK")) { cout << writetime << "ºô¸µDB : °¡Á®¿Â µ¥ÀÌÅ͸¦ ó¸®ÇÏ´Â µ¥ ½ÇÆÐÇß½À´Ï´Ù. : " << billingDB.GetErrorString() << " MinBillingNum : " << nMinNum << " MaxBillingNum : " << nMaxNum << endl; return -1; } cout << writetime << "Äõ¸® ½ÇÇà ¿Ï·á." << endl; return 0; }