📄 mainfrm.cpp
字号:
FreeTollerList();
CMDIFrameWnd::OnClose();
}
//
//edit the special user list
//
void CMainFrame::OnSpecialUser()
{
CUserListDlg dialog;
if(dialog.DoModal()==IDOK)
{
//update the user list and save it to the file "specuser.dat"
SaveSpecialUserList();
}
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
/*
1.Get the logfile from ftp server
2.Parse and Collect the toller database
*/
CMDIFrameWnd::OnTimer(nIDEvent);
//remove this line when you start the system at release version.
CTime time=CTime::GetCurrentTime();
CString strDate=time.Format(_T("%x"));
if(strDate!=sLastDate)//if date changed
{
if(time.GetHour()==nUpdateAtHour)
{
CheckIfEndOfTollerMonth();
//ftp to get log file from proxy server
if(ConnectFtpServer())
{
//CString sFileName=MakeLogFileName();
FtpGetFile(MakeLogFileName());
CloseFtpConnect();
}
//another day's toller information,we must first clear subtotal information
ClearSubTotal();
Collect();
UpdateTollerInfoDatabase();
CString sDate=time.Format("%m%d");
//generate everyday report
CString strReportFileName;
strReportFileName="c:\\toller\\report\\report"+sDate+".htm";
ReportAsHTML(strReportFileName);
strReportFileName="c:\\toller\\report\\report"+sDate+".txt";
ReportAsText(strReportFileName);
sLastDate=strDate;//let lastDate=Current Date
CWinApp* pApp=AfxGetApp();
pApp->WriteProfileString("System","LastDate",sLastDate);
}
}
}
////////////////////////////////////////////
//Toller API
////////////////////////////////////////////
void CMainFrame::LoadCERNIPPrefixList()
{
CERNIPPrefixList.RemoveAll();
CFile TheFile;
if(!TheFile.Open("c:\\toller\\cernips.dat",CFile::modeRead))
{
// TheFile.Close();
// AfxMessageBox("Unable to open SpecialUser file");
MessageBeep(0);
return;
}
//cycle read all the chars from the tab-seperate username into
//the SpecialUser List
char ch;
int nBytesRead;
CString item("");
while(TRUE)
{
nBytesRead=TheFile.Read(&ch,1);
if(nBytesRead==0)break;
if(ch!='\n')
{
if(ch=='\r')//bypass \r character
continue;
if(ch==' ')
continue;//bypass the blank space
if(ch=='\t')
continue;
item+=ch;
}
else
{
CERNIPPrefixList.AddTail(CString(item));
item="";
}
}
TheFile.Close();
}
void CMainFrame::SaveTollSetting()
{
CFile file;
if(!file.Open("c:\\toller\\tollset.dat",CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open SpecialUser file");
//file.Close();
return;
}
file.Write(&m_nTollFromDate,sizeof(int));
file.Write(&m_nCostPerKB,sizeof(int));
file.Close();
}
void CMainFrame::SaveCERNIPPrefixList()
{
CFile file;
if(!file.Open("c:\\toller\\cernips.dat",CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open SpecialUser file");
//file.Close();
return;
}
CString item,line;
POSITION pos;
pos=CERNIPPrefixList.GetHeadPosition();
if(pos==NULL)
{
file.Close();
return;
}
while(pos!=NULL)
{
item=CERNIPPrefixList.GetNext(pos);
line=item+"\r\n";
file.Write(line,line.GetLength());
line="";//clear the line buffer
}
file.Close();
}
//special list API
void CMainFrame::InitSpecialUserList()
{
SpecialUserList.RemoveAll();
}
//suffix list API
void CMainFrame::InitSuffixList()
{
SuffixList.RemoveAll();
}
void CMainFrame::LoadSpecialUserList()
{
CFile TheFile;
if(!TheFile.Open("c:\\toller\\specuser.dat",CFile::modeRead))
{
// TheFile.Close();
// AfxMessageBox("Unable to open SpecialUser file");
MessageBeep(0);
return;
}
//cycle read all the chars from the tab-seperate username into
//the SpecialUser List
SpecialUserList.RemoveAll();
char ch;
int nBytesRead;
CString item("");
while(TRUE)
{
nBytesRead=TheFile.Read(&ch,1);
if(nBytesRead==0)break;
if((ch!='\n'))//line end with \n
{
if(ch=='\r')//bypass '\r'
continue;
item+=ch;
}
else
{
SpecialUserList.AddTail(CString(item));
item="";
}
}
TheFile.Close();
}
//
//load suffix list from file
//
void CMainFrame::LoadSuffixList()
{
CFile TheFile;
if(!TheFile.Open("c:\\toller\\suffix.dat",CFile::modeRead))
{
// TheFile.Close();
// AfxMessageBox("Unable to open suffix file");
MessageBeep(0);
return;
}
//cycle read all the chars from the tab-seperate username into
//the SpecialUser List
SuffixList.RemoveAll();
char ch;
int nBytesRead;
CString item("");
while(TRUE)
{
nBytesRead=TheFile.Read(&ch,1);
if(nBytesRead==0)break;
if((ch!='\n'))//line end with \n
{
if(ch=='\r')//bypass '\r'
continue;
item+=ch;
}
else
{
SuffixList.AddTail(CString(item));
item="";
}
}
TheFile.Close();
}
//save the specialuser list to file
void CMainFrame::SaveSpecialUserList()
{
CFile file;
if(!file.Open("c:\\toller\\specuser.dat",CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open SpecialUser file");
//file.Close();
return;
}
CString item,line;
POSITION pos;
pos=SpecialUserList.GetHeadPosition();
if(pos==NULL)
{
file.Close();
return;
}
/*
item=SpecialUserList.GetAt(pos);
line=item+'\t';
file.Write(line,line.GetLength());
line="";//clear the line buffer
*/
while(pos!=NULL)
{
item=SpecialUserList.GetNext(pos);
line=item+"\r\n";
file.Write(line,line.GetLength());
line="";//clear the line buffer
}
file.Close();
}
//
//save the suffix list to file
//
void CMainFrame::SaveSuffixList()
{
CFile file;
if(!file.Open("c:\\toller\\suffix.dat",CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open Suffix file");
//file.Close();
return;
}
CString item,line;
POSITION pos;
pos=SuffixList.GetHeadPosition();
if(pos==NULL)
{
file.Close();
return;
}
/*
item=SpecialUserList.GetAt(pos);
line=item+'\t';
file.Write(line,line.GetLength());
line="";//clear the line buffer
*/
while(pos!=NULL)
{
item=SuffixList.GetNext(pos);
line=item+"\r\n";
file.Write(line,line.GetLength());
line="";//clear the line buffer
}
file.Close();
}
/////////////////////////////////////////////////////
//Toller List API
//
void CMainFrame::InitTollerList()
{
tollerList.RemoveAll();
}
//
//free the toller info list
//
void CMainFrame::FreeTollerList()
{
//free all the items in the list
POSITION pos;
CTollerInfo* pTollerInfo;
if((pos=tollerList.GetHeadPosition())==NULL)
{
//no items in the list
//free the tollerlist pointers
tollerList.RemoveAll();
return;
}
while(pos!=NULL)
{
pTollerInfo=(CTollerInfo*)tollerList.GetNext(pos);
delete pTollerInfo;
pTollerInfo=NULL;
}
//free the tollerList pointers
tollerList.RemoveAll();
}
//add a tollerInfo to the TollerList
//add a tollerInfo to the TollerList,if the username of toller
//has been in the list,just add the toller info to the info
//with the same username.
void CMainFrame::AddToTollerList(CTollerInfo& tollerInfo)
{
//traverse the toller list to find whether the szLoginName is
//in the list.
POSITION pos;
CTollerInfo* pti;
if((pos=tollerList.GetHeadPosition())==NULL)
{
//no items in the list
//we just add it into list and return
tollerList.AddTail(new CTollerInfo(tollerInfo));
return;
}
//there are some items in the list
//we first search items according to the szLoginName
pti=(CTollerInfo*)tollerList.GetAt(pos);
if(pti->GetLoginName()==tollerInfo.GetLoginName())
{
//the loginName is in the list now,we just need to modify
pti->nSubTotal+=tollerInfo.nSubTotal;
pti->nTotal +=tollerInfo.nTotal;
return;
}
while(pos!=NULL)
{
pti=(CTollerInfo*)tollerList.GetNext(pos);
if(pti->GetLoginName()==tollerInfo.GetLoginName())
{
//the loginName is in the list now,we just need to modify
pti->nSubTotal+=tollerInfo.nSubTotal;
pti->nTotal +=tollerInfo.nTotal;
return;
}
}
//not found the matched szLoginName,so we add it to the tail
tollerList.AddTail(new CTollerInfo(tollerInfo));
}
//save the tollerinfo list to the toller info database
void CMainFrame::UpdateTollerInfoDatabase()
{
StatusText("Now updating tollerinfo database");
CFile file;
CTime time=CTime::GetCurrentTime();
CString sDate=time.Format("%m%d");
//generate everyday database
sDatabaseName="c:\\toller\\database\\toller"+sDate+".dbf";
if(!file.Open(sDatabaseName,CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open SpecialUser file");
//file.Close();
return;
}
POSITION pos;
CTollerInfo* pTollerInfo;
TOLLERINFO ti;
if((pos=tollerList.GetHeadPosition())==NULL)
{
//no items in the list
return;
}
/*
pTollerInfo=(CTollerInfo*)tollerList.GetAt(pos);
pTollerInfo->GetInfoStruct(ti);
TheFile.Write(&ti,sizeof(TOLLERINFO));
*/
while(pos!=NULL)
{
pTollerInfo=(CTollerInfo*)tollerList.GetNext(pos);
pTollerInfo->GetInfoStruct(ti);
file.Write(&ti,sizeof(TOLLERINFO));
}
file.Close();
CFile CurFile;
//generate everyday database
sDatabaseName="c:\\toller\\database\\toller.dbf";
if(!CurFile.Open(sDatabaseName,CFile::modeWrite|CFile::modeCreate))
{
//AfxMessageBox("Unable to open SpecialUser file");
//file.Close();
return;
}
if((pos=tollerList.GetHeadPosition())==NULL)
{
//no items in the list
return;
}
/*
pTollerInfo=(CTollerInfo*)tollerList.GetAt(pos);
pTollerInfo->GetInfoStruct(ti);
TheFile.Write(&ti,sizeof(TOLLERINFO));
*/
while(pos!=NULL)
{
pTollerInfo=(CTollerInfo*)tollerList.GetNext(pos);
pTollerInfo->GetInfoStruct(ti);
CurFile.Write(&ti,sizeof(TOLLERINFO));
}
CurFile.Close();
StatusText("Update database OK.");
}
/*
collect the tollerinfo from logfile and save into
the toller list
*/
void CMainFrame::Collect()
{
CFile LogFile;
sLogFileName="c:\\toller\\proxylog\\access";
if(!LogFile.Open(sLogFileName,CFile::modeRead))
{
//AfxMessageBox("Cannot open the logfile");
MessageBeep(0);
return;
}
CString aline("");
char ch;
int nBytesToRead;
//first let's bypass the headline(the description of the logfile info
//structure).
while(TRUE)
{
nBytesToRead=LogFile.Read(&ch,1);
if(nBytesToRead==0)//has reached the end of the file
//so we return and exit the collect procedure
return;
if(ch=='\n')//reach the end of one line,line end
//with char combination "\r\n"
break;
}
int nLineNum=0;
CString sProgress;
while(TRUE)
{
nBytesToRead=LogFile.Read(&ch,1);
if(nBytesToRead==0)//has reached the end of the file
{ //so we return and exit the collect procedure
//and prompt user
CString sFinished;
sFinished.LoadString(IDS_COLLECT_FINISHED);
sFinished=sFinished+" "+sProgress;
StatusText(sFinished);
MessageBeep(0);
return;
}
if(ch!='\n')//reach the end of one line,line end
//with char combination "\r\n"
{
//bypass \r
if(ch=='\r')
continue;
aline+=ch;
}
else
{
sProgress.Format("Process line %d",
nLineNum);
//show the progress on the status line
StatusText(sProgress);
//maybe the first line need to be bypassed.
ParseLine(aline);
nLineNum++;
//parse the toller info from
//this line and store into the toller list
aline="";//clear the line buffer
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -