Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
void CRenamingFilesDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here

// TODO: Add your control notification handler code here
CFile cfile;
cfile.Open(_T("E:\\MyFile\\OffLineFileLog000000099.00062.txt"), CFile::modeReadWrite);
/*char pbufWrite[100];
memset(pbufWrite, 'a', sizeof(pbufWrite));
cfile.Write(pbufWrite, 100);
cfile.Flush();
cfile.SeekToBegin();*/
int iFileSize = cfile.GetLength();
char *pbufRead = new char[iFileSize+1];
cfile.Read(pbufRead, iFileSize+1);
CString cstrFileContent(pbufRead);

int iLastline = cstrFileContent.ReverseFind('\n');
int iEnd = cstrFileContent.ReverseFind('*');
int idiff = iEnd - iLastline;
CString cstUpdatedDate = cstrFileContent.Mid(iLastline,idiff);
cstUpdatedDate.Trim();
int cstrTemp1 = cstUpdatedDate.Find('+');
cstUpdatedDate.Delete(0,cstrTemp1);
CString cstr1= _T(""),cstr2= _T(""),cstr3= _T(""),cstr4= _T("");
AfxExtractSubString( cstr1,cstUpdatedDate,0,':');
AfxExtractSubString( cstr2,cstUpdatedDate,1,':');
AfxExtractSubString( cstr3,cstUpdatedDate,2,':');
AfxExtractSubString( cstr4,cstUpdatedDate,3,':');
cstr1.Remove('+');
cstr2.Remove('+');
cstr3.Remove('+');
cstr4.Remove('+');
int iDays = _ttoi(cstr1);
int iHours = _ttoi(cstr2);
int iMins = _ttoi(cstr3);
int iSecs = _ttoi(cstr4);

int iStartup = cstrFileContent.Find('*');
CString cstrStrup = cstrFileContent.Mid(0,iStartup);
int iStart = cstrStrup.Find('p');
cstrStrup.Delete(0,iStart);
cstrStrup.Remove('p');
cstrStrup.Trim();
COleDateTime dt;
dt.ParseDateTime(cstrStrup);
int iday = dt.GetDay();
int iTotalDay = iday+iDays;
int iTotalHours = dt.GetHour() + iHours;
int iTotalMins = dt.GetMinute() + iMins;

int iTotalSec = dt.GetSecond() + iSecs;
iTotalSec = 0;

CString cstrDt = _T("");
CString cstrCurrDt = _T("");
cstrDt.Format(_T("%d/%0.2d/%d %0.2d:%0.2d:%0.2d"),iTotalDay,dt.GetMonth(),dt.GetYear(),iTotalHours,iTotalMins,iTotalSec);
COleDateTime dtt;
COleDateTime dtspan;
int iHour;
int iMin ;
int iSec ;

if(dtt.ParseDateTime(cstrDt))
{
COleDateTime dtCurrent;
dtCurrent = GetDateTimeFormate();
iHour =dtCurrent.GetHour();
iMin = dtCurrent .GetMinute();
iSec = dtCurrent .GetSecond();
cstrCurrDt.Format(_T("%d/%0.2d/%d"),dtCurrent.GetDay(),dtCurrent.GetMonth(),dtCurrent.GetYear());

//dtspan = dtCurrent - dtt;
//int iTotalDays = dtspan.GetTotalDays();
}

COleDateTime dtTimeCal = dtspan;
CString cstrDtTime = dtTimeCal.Format(_T("%d/%m/%Y %H:%M:%S"));

int iHrs=iHour-iTotalHours;
int iMinutes =iMin-iTotalMins;
int iSeconds =iSec-iTotalSec ;

CString cstrTime = _T("");
cstrDt.Format(_T("%0.2d:%0.2d:%0.2d"),iHrs ,iMinutes,iSeconds);

cstrDtTime = cstrCurrDt + cstrDt;

int iPosStart = cstrFileContent.Find('\n');
CString cstrRemain = cstrFileContent.Mid(iPosStart);
CString cstrTemp = _T("");
cstrTemp = cstrFileContent;
cstrTemp.Delete(0,iPosStart);
CString cstrtime = _T("");
CString cstrNewText = _T("StartUp ")+cstrDtTime + _T(" ")+GetIncidentNumber(000035)+_T(".")+_T("0000412");
cstrNewText = cstrNewText + _T(" ")+ GetGuidCode()+_T(" ")+ GetGuidCode()+ _T(" v2 ")+ _T("45645");
int i = 0;
while(i<cstrnewtext.getlength())>
{
pbufRead[i] = cstrNewText.GetAt(i);
i++;
}
int j = 0;
while(j<cstrtemp.getlength())>
{
pbufRead[i] = cstrTemp.GetAt(j);
j++;
}
//pbufRead = cstrNewText + cstrTemp;
cfile.SeekToBegin();
cfile.Write(pbufRead,iFileSize+1);
cfile.Close();
//if(iPos != -1)
//cstrTemp = cstrFileContent.Mid(iPosStart);
//int iPosEnd = cstrTemp.Find('*');
//cstrTemp = cstrTemp.Mid(1,iPosEnd);
//pbufRead(cstrTemp);
}
Posted
Comments
OriginalGriff 5-Apr-15 10:33am    
And?
Your problem is?

A code dump does not a question make.
There is no question asked, so we have no idea what problem you are having, or what kind of help you are seeking.

Please, try to think about how you present the problem from the POV of the reader: Remember that we can't see your screen, access your HDD, or read your mind.
OriginalGriff 5-Apr-15 10:45am    
Do not repost the same thing again: it's rude, it's uneccesary, and it can duplicate work and waste our time.
I have deleted the newer spare.

Improve this one: explain what your problem is instead of just dumping your code on us and expecting us to work it out from there!
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900