www.pudn.com > 200311301927570.rar > DataConvert.cpp


// DataConvert.cpp: implementation of the CDataConvert class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "DataConvert.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CDataConvert::CDataConvert() 
{ 
 
} 
 
CDataConvert::~CDataConvert() 
{ 
 
} 
 
BOOL CDataConvert::DeCharGateidToDeIntGateid(const char *chGateid, CString &strGateid) 
{ 
	__int64 nGateid = 0; 
	__int32	nTemp = 0; 
	char	chTemp[64]={0}; 
	memcpy(chTemp, chGateid, 2); 
 
	//month; 
	nTemp = atoi(chTemp); 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 63,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 62,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 61,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 60,1); 
	} 
 
	//day; 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+2, 2); 
	nTemp = atoi(chTemp); 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 59,1); 
	} 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 58,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 57,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 56,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 55,1); 
	} 
 
	//hour 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+4, 2); 
	nTemp = atoi(chTemp); 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 54,1); 
	} 
	if((nTemp & 8 )  == 8){ 
		SetBit(nGateid, 53,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 52,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 51,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 50,1); 
	} 
 
	//minute 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+6, 2); 
	nTemp = atoi(chTemp); 
	if((nTemp & 32 ) == 32){ 
		SetBit(nGateid, 49,1); 
	} 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 48,1); 
	} 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 47,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 46,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 45,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 44,1); 
	} 
 
	//second 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+8, 2); 
	nTemp = atoi(chTemp); 
	if((nTemp & 32 ) == 32){ 
		SetBit(nGateid, 43,1); 
	} 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 42,1); 
	} 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 41,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 40,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 39,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 38,1); 
	} 
 
	//gate 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+10, 7); 
	nTemp = atoi(chTemp); 
	if((nTemp & 1048576 ) == 1048576 ){ 
		SetBit(nGateid, 37,1); 
	} 
	if((nTemp & 524288 ) == 524288 ){ 
		SetBit(nGateid, 36,1); 
	} 
	if((nTemp & 262144) == 262144){ 
		SetBit(nGateid, 35,1); 
	} 
	if((nTemp & 131072 ) == 131072 ){ 
		SetBit(nGateid, 34,1); 
	} 
	if((nTemp & 65536 ) == 65536){ 
		SetBit(nGateid, 33,1); 
	} 
	if((nTemp & 32768 ) == 32768){ 
		SetBit(nGateid, 32,1); 
	} 
	if((nTemp & 16384 ) == 16384){ 
		SetBit(nGateid, 31,1); 
	} 
	if((nTemp & 8192 ) == 8192){ 
		SetBit(nGateid, 30,1); 
	} 
	if((nTemp & 4096 ) == 4096){ 
		SetBit(nGateid, 29,1); 
	} 
	if((nTemp & 2048 ) == 2048){ 
		SetBit(nGateid, 28,1); 
	} 
	if((nTemp & 1024 ) == 1024){ 
		SetBit(nGateid, 27,1); 
	} 
	if((nTemp & 512 ) == 512){ 
		SetBit(nGateid, 26,1); 
	} 
	if((nTemp & 256 ) == 256){ 
		SetBit(nGateid, 25,1); 
	} 
	if((nTemp & 128 ) == 128){ 
		SetBit(nGateid, 24,1); 
	} 
	if((nTemp & 64 ) == 64){ 
		SetBit(nGateid, 23,1); 
	} 
	if((nTemp & 32 ) == 32){ 
		SetBit(nGateid, 22,1); 
	} 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 21,1); 
	} 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 20,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 19,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 18,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 17,1); 
	} 
	 
	//msgid 
	memset(chTemp, 0, sizeof(chTemp)); 
	memcpy(chTemp, chGateid+17, 5); 
	nTemp = atoi(chTemp); 
	if((nTemp & 32768 ) == 32768){ 
		SetBit(nGateid, 15,1); 
	} 
	if((nTemp & 16384 ) == 16384){ 
		SetBit(nGateid, 14,1); 
	} 
	if((nTemp & 8192 ) == 8192){ 
		SetBit(nGateid, 13,1); 
	} 
	if((nTemp & 4096 ) == 4096){ 
		SetBit(nGateid, 12,1); 
	} 
	if((nTemp & 2048 ) == 2048){ 
		SetBit(nGateid, 11,1); 
	} 
	if((nTemp & 1024 ) == 1024){ 
		SetBit(nGateid, 10,1); 
	} 
	if((nTemp & 512 ) == 512){ 
		SetBit(nGateid, 9,1); 
	} 
	if((nTemp & 256 ) == 256){ 
		SetBit(nGateid, 8,1); 
	} 
	if((nTemp & 128 ) == 128){ 
		SetBit(nGateid, 7,1); 
	} 
	if((nTemp & 64 ) == 64){ 
		SetBit(nGateid, 6,1); 
	} 
	if((nTemp & 32 ) == 32){ 
		SetBit(nGateid, 5,1); 
	} 
	if((nTemp & 16 ) == 16){ 
		SetBit(nGateid, 4,1); 
	} 
	if((nTemp & 8 ) == 8){ 
		SetBit(nGateid, 3,1); 
	} 
	if((nTemp & 4 ) == 4){ 
		SetBit(nGateid, 2,1); 
	} 
	if((nTemp & 2 ) == 2){ 
		SetBit(nGateid, 1,1); 
	} 
	if((nTemp & 1 ) == 1){ 
		SetBit(nGateid, 0,1); 
	} 
 
	memset(chTemp, 0, sizeof(chTemp)); 
	_i64toa(nGateid, chTemp, 10); 
	strGateid = chTemp; 
	return TRUE; 
} 
 
BOOL CDataConvert::HexCharGateidToDeIntGateid(const char *chHexGateid, CString &strGateid) 
{ 
	__int64 result=0; 
	int testSuccess=0; 
	if(sscanf(chHexGateid,"%I64 ,$%d",&result,&testSuccess) ==0) 
		return FALSE; 
	if(testSuccess!=10) 
		return FALSE; 
	strGateid.Format("%I64",result); 
	return TRUE; 
} 
 
BOOL CDataConvert::SetBit(__int64 &nValue, const BYTE &byBit, BOOL bVal) 
{ 
	__int64 temp=(__int64)bVal; 
	nValue =(temp<