📄 calendarlog.cpp
字号:
#include "StdAfx.h"
#include "CalendarLog.h"
const LPCTSTR crlogpath=TEXT("\\AdbFlashDisk\\systemdata\\calendar.log");
CJCRLog::~CJCRLog()
{
}
CJCRLog::CJCRLog()
{
}
CString CJCRLog::GetCalendarDateStr()
{
CString strdlist=TEXT("");
CString temp=TEXT("");
CRLog lgtemp;
for (int i=0;i<crlist.GetCount();i++)
{
ZeroMemory(&lgtemp,sizeof(CRLog));
POSITION pos=crlist.FindIndex(i);
lgtemp=crlist.GetAt(pos);
temp.Format(TEXT("%s |"),lgtemp.redate);
strdlist+=temp;
}
return strdlist;
}
BOOL CJCRLog::CAFind(CRLog &fdata, int findex)
{
CRLog temp;
bool blfind=FALSE;
for(int i=crlist.GetCount()-1;i>=0;i--)
{
ZeroMemory(&temp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(i);
if (pos==NULL)
{
continue;
}
temp=crlist.GetAt(pos);
if (temp.LID==findex)
{
//已经找到
blfind=TRUE;
fdata=temp;
break;
}
}
return blfind;
}
BOOL CJCRLog::AddLog(CRLog newdata)
{
//填加到链表中
crlist.AddHead(newdata);
//保存到文件
return SaveListInFile();
}
BOOL CJCRLog::SaveListInFile()
{
CFile wfile;
if (wfile.Open(crlogpath,CFile::modeWrite|CFile::modeCreate)==0)
return FALSE;
CRLog temp;
for (int i=crlist.GetCount()-1;i>=0;i--)
{
ZeroMemory(&temp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(i);
temp=crlist.GetAt(pos);
wfile.Write(&temp,sizeof(CRLog));
}
wfile.Close();
return TRUE;
}
BOOL CJCRLog::DelLog(int ndel)
{
CRLog temp;
BOOL bldel=FALSE;
for (int i=crlist.GetCount()-1;i>=0;i--)
{
ZeroMemory(&temp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(i);
temp=crlist.GetAt(pos);
if (temp.LID==ndel)
{
//找到需要删除的
crlist.RemoveAt(pos);
bldel=TRUE;
break;
}
}
if (bldel)
{
bldel=SaveListInFile();
}
return bldel;
}
BOOL CJCRLog::CAReplace(int nrep, CRLog newdata)
{
CRLog temp;
BOOL blrep=FALSE;
for (int i=crlist.GetCount()-1;i>=0;i++)
{
ZeroMemory(&temp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(i);
temp=crlist.GetAt(pos);
if (temp.LID==nrep)
{
crlist.SetAt(pos,newdata);
blrep=TRUE;
break;
}
}
if (blrep)
{
blrep=SaveListInFile();
}
return blrep;
}
BOOL CJCRLog::InitCalendarInof()
{
CFile rfile;
if (!rfile.Open(crlogpath,CFile::modeRead))
{
return FALSE;
}
CRLog temp;
crlist.RemoveAll();
while(rfile.Read(&temp,sizeof(CRLog))>0)
{
crlist.AddHead(temp);
}
rfile.Close();
return TRUE;
}
int CJCRLog::GetFreeID()
{
int ntemp=-1;
CRLog ltemp;
BOOL blfind;
if (crlist.GetCount()==0)
{
return 1;
}
for (int i=0;i<crlist.GetCount();i++)
{
blfind=FALSE;
for(int n=0;n<crlist.GetCount();n++)
{
ZeroMemory(<emp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(n);
ltemp=crlist.GetAt(pos);
if (ltemp.LID==(i+1))
{
blfind=TRUE;
break;
}
}
if (!blfind)
{
//找到可以用的
ntemp=i+1;
break;
}
}
if (ntemp==-1)
{
ntemp=crlist.GetCount()+1;
}
return ntemp;
}
int CJCRLog::GetLogNumCount()
{
return crlist.GetCount();
}
BOOL CJCRLog::FindForIndex(CRLog &redata, int nindex)
{
CRLog temp;
bool blfind=FALSE;
ZeroMemory(&temp, sizeof(CRLog));
POSITION pos=crlist.FindIndex(nindex);
if (pos!=NULL)
{
temp=crlist.GetAt(pos);
redata=temp;
blfind=TRUE;
}
else
{
blfind=FALSE;
}
return blfind;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -