www.pudn.com > xltsm.rar > ChkQueue.cpp


#include "StdAfx.h" 
#include "smset.h" 
#include "SendSM.h" 
 
extern char szIcpNbr[];	// 移动特服号 
extern char szCorp[];	// 智响通讯 
extern char szTel[];	// 公司电话 
extern char szWeb[];	// 公司主页 
extern char szCmccTest[];// CMCC信息 
extern char szCmdSet[];	// 当用户发送无效命令字时提示 
 
int CheckMonthTable(CMyDatabase& db) 
{ 
	CString strError; 
 
	if (MakeSureDBConnected(db, strError)){ 
		CMyDataSet ds(&db); 
		ds.Open("SELECT TOP 100 ID, MOBILE, SERVICEID, FEECODE, MESSAGE, STATUS, FEETYPE, SRCID, FEEMOBILE FROM SM_MONTH WHERE MOBILE LIKE '0%' AND STATUS BETWEEN -2 AND 0 ORDER BY STATUS DESC, INTIME ASC"); 
		if (ds.m_nSQLCode == -1){ 
			printf("\nSELECT Failed - ChkQueue!\nDBMS ERROR: %s\n", ds.GetSQLErrText()); 
			return -1; 
		} 
		for (int row = 0; row < ds.GetRowCount(); row++){ 
			long id				= ds[row][0]; 
			LPCSTR lpcszMobile	= ds[row][1]; 
			LPCSTR lpcszServiceID=ds[row][2]; 
			int nFeeCode		= ds[row][3]; 
			CString sMsg		= ds[row][4]; 
			int nStatus			= ds[row][5]; 
			int nFeeType		= ds[row][6]; 
			LPCSTR lpcszSrcID	= ds[row][7]; 
			LPCSTR lpcsFeeMobile= ds[row][8]; 
			int nMsgLevel		= 1;  // 信息级别(0=最低优先级,1=正常,2=紧急,3=十分紧急) 
			int nErrorCode		= 0;  
			BOOL bSuccess		= FALSE; 
 
			try { 
				sMsg.Replace("#ICP", szIcpNbr); 
				sMsg.Replace("#CMCCTEST", szCmccTest); 
				sMsg.Replace("#CTIVR", szCorp); 
				sMsg.Replace("#TEL", szTel); 
				sMsg.Replace("#WEB", szWeb); 
				sMsg.Replace("#CMDSET", szCmdSet); 
 
				sMsg.Replace("\x2", ""); 
				sMsg.Replace("\x3", ""); 
				sMsg.Replace("\x4", "\r"); 
				sMsg.Replace("\x5", "\n"); 
				sMsg.Replace("\x6", " "); 
 
				db.BeginTrans(); 
				if (db.ExecuteSQLFr(strError, "UPDATE SM_MONTH SET STATUS = 1 WHERE ID = %ld ", id) == -1) throw (LPCSTR)strError; 
				bSuccess = SubmitSM(lpcszMobile, lpcszServiceID, lpcszSrcID, nFeeType, nFeeCode, nMsgLevel, lpcsFeeMobile, sMsg.GetLength(), sMsg.GetBuffer(sMsg.GetLength() + 1), &nErrorCode); 
				sMsg.ReleaseBuffer(); 
				if (!bSuccess){ 
					//  发送失败 
					nStatus --; // 原来是0则变成-1,原来是-1则为-2, ... 
					if (db.ExecuteSQLFr(strError, "UPDATE SM_MONTH SET STATUS = %d, SENDTIME%d = GETDATE() WHERE ID = %ld ", nStatus, -1 * (nStatus + 1), id) == -1) throw (LPCSTR)strError; 
					printf("\n%s, %d]Failed: %s\nSMG ERROR CODE: %d", lpcszMobile, nFeeCode, sMsg, nErrorCode); 
				} else { 
					// 发送成功 
					printf("\n%s, %d]OK: %s\n", lpcszMobile, nFeeCode, sMsg); 
				} 
				db.CommitTrans(); 
			} 
			catch(LPCSTR e){ 
				db.Rollback(); 
				printf("\n%s, %d]Failed: %s\nDBMS ERROR: %s\n", lpcszMobile, nFeeCode, sMsg, e); 
				return -1; 
			} 
		} 
		return 1; 
	} 
 
	printf("\nNo Database connected\n"); 
	 
	return -1; 
}