BOOL CTxtFile::Exist(CString strPath, CString strBakDir, CString &strHistoryTmp)
{
	CString strYearMonth;
	CString strSN;
	GetSN(strSN, strPath);

	int nYear, nMonth, nDay;
	int nYearPre, nMonthPre;
	GetCrtDate(nYear, nMonth, nDay);

	const int nPreviousMonth=12;
	for (int i=0; i<=nPreviousMonth; i++)
	{
		nYearPre  = (nYear*12+nMonth-i)/12;
		nMonthPre = (nYear*12+nMonth-i)%12;

		strYearMonth.Format(_T("%d\\%d"), nYearPre, nMonthPre);

		if (FileExist(strBakDir+_T("\\")+strYearMonth+_T("\\")+strSN+_T(".tmp")) )
		{
			strHistoryTmp = strBakDir+_T("\\")+strYearMonth+_T("\\")+strSN+_T(".tmp");
			return TRUE;
		}
	}
	
	return FALSE;
}
BOOL CTxtFile::BakFile(CString strPath, CString strBakDir)
{
	int nYear, nMonth, nDay;
	GetCrtDate(nYear, nMonth, nDay);

	CString strYearMonth;
	strYearMonth.Format(_T("%d\\%d"), nYear, nMonth);

	CreateFolder(strBakDir+_T("\\")+strYearMonth);

	CString strSN;
	GetSN(strSN, strPath);

	return MoveFile(strPath, strBakDir+_T("\\")+strYearMonth+_T("\\")+strSN+_T(".tmp"));
}
Ejemplo n.º 3
0
int ReadResetReport(char* szResetReport, const int iLen)
{
    static BYTE8 szStartTimeTable[1024];

    int i = 0;
    int iResetCount = 0;
    int iStartIndex = 0;
    int iCount = 0;
    int iDestLen = 0;
    int iTempLen = 0;
    char szReportTmp[100];
    RESET_RECORD_STRUCT cRealTime;

    if ( NULL == szResetReport )
    {
        HV_Trace(5, "<ReadResetReport> szResetReport is NULL!\n");
        return -1;
    }
    // 填写记录报告头
    strcpy(szResetReport, "");
    if ( GetSN(szResetReport, iLen) < 0 )
    {
        HV_Trace(5, "<ReadResetReport> GetSN is FAILED!\n");
        return -1;
    }
    strcat(szResetReport, "\nResetRecordReport:\n");
    iDestLen = strlen(szResetReport);

    if ( GetResetCount(&iResetCount) < 0 )
    {
        HV_Trace(5, "<ReadResetReport> GetResetCount is FAILED!\n");
        return -1;
    }
    else
    {
        if ( iResetCount > 0 )
        {
            if ( iResetCount <= 64 )
            {
                iStartIndex = 0;
                iCount = iResetCount;
            }
            else
            {
                iStartIndex = iResetCount % 64;
                iCount = 64;
            }

            if ( EEPROM_Read(START_TIME_TABLE_ADDR, szStartTimeTable, iCount*sizeof(RESET_RECORD_STRUCT)) < 0 )
            {
                HV_Trace(5, "<ReadResetReport> EEPROM_Read is FAILED!\n");
                return -1;
            }

            for ( i = (iCount - 1); i >= 0; --i )
            {
                memcpy(&cRealTime,
                       szStartTimeTable + ((iStartIndex + i) % 64) * sizeof(RESET_RECORD_STRUCT),
                       sizeof(RESET_RECORD_STRUCT));

                sprintf(szReportTmp, "%08d :%04d/%02d/%02d %02d:%02d:%02d T:%02d\n",
                        (int)(iResetCount-iCount+1 + i),
                        (int)cRealTime.wYear,
                        (int)cRealTime.wMonth,
                        (int)cRealTime.wDay,
                        (int)cRealTime.wHour,
                        (int)cRealTime.wMinute,
                        (int)cRealTime.wSecond,
                        (int)(cRealTime.wResetType>>13));

                iTempLen = strlen(szReportTmp);
                if ( (iDestLen + iTempLen) < iLen )
                {
                    strcat(szResetReport, szReportTmp);
                    iDestLen += iTempLen;
                }
                else
                {
                    HV_Trace(5, "<ReadResetReport> iLen not long enough.\n");
                    break;
                }
            }
        }
        else
        {
            HV_Trace(5, "<ReadResetReport> ResetCount is Zero.\n");
        }

        return 0;
    }