예제 #1
0
/*=================================================================
 * Function ID :  WriteDeviceLog
 * Input       :  char* cpath, char* str
 * Output      :  void
 * Author      :  DengJun
 * Date        :  Apr   2005
 * Return	   :  void
 * Description :  
 * Notice	   :  写插入数据库时不成功的SQL语句
 *			   :  cpath-->路径 ucpID-->设备ID号 str-->日志内容
 *=================================================================*/
void CMyLog::WriteDeviceMaxMoney(char* cpath, char* ucpID,char* msg)
{
	FileBase  mfile;
	CData     m_Data;
	char	  pszFileName[128];	
	char	  lpBuffer[2048];	
	BYTE	  str[30];
	
	memset(str,		   0x00,sizeof str);		
	memset(lpBuffer,   0x00,sizeof lpBuffer);
	memset(pszFileName,0x00,sizeof pszFileName);		
	

	if( !strlen(msg) ) return ;
	m_Data.trim(cpath);
	CheckIsChangeYear(cpath);
	if( strlen(cpath) )
	{
		strcpy(pszFileName,cpath);
		strcat(pszFileName,"\\");		
	}
	strcat(pszFileName,"Sql");		
	memcpy(pszFileName+strlen(pszFileName),(char*)m_Data.GetSysTime(),8);
	strcat(pszFileName,".txt");		
	if( !m_Data.FileIsExist(pszFileName) )
	{
		CreateDirectory(cpath,NULL);
	}		
	memset(lpBuffer,0x00,sizeof lpBuffer);
	strcpy(lpBuffer,msg);
	mfile.AddLineToFile(pszFileName,lpBuffer,strlen(lpBuffer));
	return ;
}
예제 #2
0
/*=================================================================
 * Function ID :  SMT_GetLastInvoiceNo
 * Input       :  char* cpath, char* str
 * Output      :  void
 * Author      :  DengJun
 * Date        :  Apr   2005
 * Return	   :  void
 * Description :  
 * Notice	   :  
 *			   :  
 *=================================================================*/
bool CMyLog::SMT_GetLastInvoiceNo(char* sID, int *nInvoiceNo )
{
	char		sValue[20];
	char		sKeyName[20];
	int			nValue=0;
	CData		cData;
	FileBase	mfile;

	memset(sValue,0,sizeof sValue);
	memset(sKeyName,0,sizeof sKeyName);
	
	cData.BcdToAsc((byte*)sID,4,(byte*)sKeyName);
	g_CriticalSectionLock.Lock();
	if( g_WriteFileLock ) 
	{
		g_CriticalSectionLock.Unlock();
		return false;
	}
	g_WriteFileLock=true;
	GetPrivateProfileString(sKeyName, "NO", "-1",sValue,sizeof(sValue),g_sCommRec);
	if( atoi(sValue)==-1 )
	{
		memset(sValue,0,sizeof sValue);
		sprintf(sValue,"[%s]",sKeyName);
		mfile.AddLineToFile(g_sCommRec,sValue,strlen(sValue));
		memset(sValue,0,sizeof sValue);
		strcpy(sValue,"NO=1");
		mfile.AddLineToFile(g_sCommRec,sValue,strlen(sValue));
		*nInvoiceNo=0;
	}
	else
	{
		*nInvoiceNo=atol(sValue);
		if( *nInvoiceNo>=65535 ) nValue=-1;		
		else					 nValue=*nInvoiceNo;
		sprintf(sValue,"%ld",++nValue);
		WritePrivateProfileString(sKeyName, "NO",sValue,g_sCommRec);		
	}
	g_WriteFileLock=false;
	g_CriticalSectionLock.Unlock();
	return true;
}
예제 #3
0
/*=================================================================
 * Function ID :  WriteDeviceData
 * Input       :  char* cpath, char* msg
 * Output      :  void
 * Author      :  DengJun
 * Date        :  Apr   2006
 * Return	   :  void
 * Description :  
 * Notice	   :  写设备的日志
 *			   :  cpath-->路径 ucpID-->设备ID号 msg-->数据内容
 *=================================================================*/
bool CMyLog::WriteDeviceData(char* cpath, char* ucpID,char* msg)
{
	FileBase  mfile;
	CData     m_Data;
	char	  pszFileName[128];
	char	  lpBuffer[1024];
	BYTE	  str[30];
	
	memset(str,		   0x00,sizeof str);	
	memset(lpBuffer,   0x00,sizeof lpBuffer);
	memset(pszFileName,0x00,sizeof pszFileName);		
	
	m_Data.trim(cpath);
	CheckIsChangeYear(cpath);
	if( strlen(cpath) )
	{
		strcpy(pszFileName,cpath);
		strcat(pszFileName,"\\");
	}
	strcat(pszFileName,"Data");		
	memcpy(pszFileName+strlen(pszFileName),(char*)m_Data.GetSysTime(),8);
	strcat(pszFileName,"_");
	strcat(pszFileName,(char*)m_Data.BcdToAsc((BYTE*)ucpID,4,str));
	strcat(pszFileName,".txt");		
	if( !m_Data.FileIsExist(pszFileName) )
	{
		CreateDirectory(cpath,NULL);
	}	
	
	memset(lpBuffer,0x00,sizeof lpBuffer);

	strcat(lpBuffer,(char*)m_Data.GetSysTime());
	strcat(lpBuffer,",");
	strcat(lpBuffer,msg);
	if( mfile.AddLineToFile(pszFileName,lpBuffer,strlen(lpBuffer)) )
	{
		return false;
	}
	return true;
}
예제 #4
0
/*=================================================================
* Function ID :  SMT_UpBeforeFile
* Input       :  void
* Output      :  void
* Author      :  
* Date        :  2006  2
* Return	  :  void
* Description :  前置启动将当天前的文件的记录全部上传
* Notice	  : 
*=================================================================*/
bool CSmartCommunicationDlg::SMT_UpBeforeFile(XDHANDLE nHandler)
{
	int				 nTimeOut=20000;
	int				 nErrCode=0;
	char			 sErrMsg[256];	
	char			 sTempPath[256];
	char			 sBakPath[256];
	char			 sData[256],sMsg[1024];
	FILE			 *fpt=NULL;
	FileBase		 mfile;
	vector<CString>  VFileName;
	vector<CString>  VFileContent; //文件内容
	CString			 sFileContent; 
	
	memset(sMsg,     0,sizeof sMsg);
	memset(sData,    0,sizeof sData  );
	memset(sErrMsg,  0,sizeof sErrMsg);	
	memset(sTempPath,0,sizeof sTempPath);
	memset(sBakPath, 0,sizeof sBakPath);
		
	VFileName.clear();						//清除所有文件名		
	VFileContent.clear();					//保存文件内容
	SMT_GetAllFileName(VFileName);			//获取不是当天产生的文件		
	if( VFileName.empty() ) return false;
	for( int i=0; i<VFileName.size(); i++ )	//将还未上传的文件记录全部上传
	{
		memset(sTempPath,0,sizeof sTempPath);
		memset(sBakPath, 0,sizeof sBakPath);
		strcpy(sTempPath,m_DealPath);
		strcat(sTempPath,"\\");
		strcat(sTempPath,VFileName[i].GetBuffer(100));

		strcpy(sBakPath,m_DealPath);
		strcat(sBakPath,"\\Bak\\Bak_");
		strcat(sBakPath,VFileName[i].GetBuffer(100));		
		//remove(sBakPath);
		if( (fpt=mfile.OpenFile(sTempPath,"r"))==NULL)
		{
			continue;
		}
		//得到该文件的所有记录
		while( mfile.FileEOF(fpt)==0)
		{
			memset(sData,0,sizeof sData);
			if( fgets(sData,128,fpt) !=NULL )
			{
				if( !g_StartFlag )
				{
					mfile.CloseFile(fpt);
					return true;
				}
				sFileContent=sData;
				VFileContent.push_back(sFileContent);
			}
		}
		mfile.CloseFile(fpt);
		int nCount=VFileContent.size();
		bool bStatus=false;
		//上传该文件的记录
		for( int j=0; j<nCount; j++ )
		{
			bStatus=false;
			for( int k=0; i<10; k++ ) //一条记录如果上传10次还不成功,则全部重新上传
			{				
				if( !g_StartFlag ) 	
				{
					VFileContent.clear();
					return true;	//收到系统退出命令
				}
				memset(sData,0,sizeof sData);
				strcpy(sData,VFileContent[j].GetBuffer(100));
				if( !g_CInterface.SMT_UpDealRecord(nHandler,sData,nTimeOut,&nErrCode,sErrMsg) )
				{
					sprintf(sMsg,"上传文件名%s的第%ld条记录到金仕达失败(%ld,%s)",VFileName[i].GetBuffer(100),j+1,nErrCode,sErrMsg);
					if( g_IniFilePara.bWriteDebugLog ) WriteLog(sErrMsg);
					if( g_IniFilePara.bWriteDebugLog ) AddString(sMsg);
					Sleep(5000);
					continue;
				}
				bStatus=true;
				break;
			}
			if( !bStatus )
			{
				WriteLog(sErrMsg);
				VFileContent.clear();
				Sleep(1000);
				return false;	
			}
			Sleep(50);
			mfile.AddLineToFile(sBakPath,sData,strlen(sData)-1);			
		}
		SMT_DeleteFile(VFileName[i].GetBuffer(100));
		VFileContent.clear();
		if( !g_StartFlag ) 	return true;	//收到系统退出命令
	}
	if( !VFileName.empty() ) VFileName.clear();
	return true;
}