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);
}