EventLog.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // EventLog.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_OCX.h"
  5. #include "EventLog.h"
  6. #include "mdlProject.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. static int iEventPos = 0;
  13. #define EVENTNUM 2000
  14. CString csEventTime[EVENTNUM];
  15. CString csEventInfo[EVENTNUM];
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CEventLog dialog
  18. void F_AddEvent(CString csEvent)
  19. {
  20. CEventLog m_eventlog;
  21. m_eventlog.AddEvent(csEvent);
  22. }
  23. CEventLog::CEventLog(CWnd* pParent /*=NULL*/)
  24. : CDialog(CEventLog::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CEventLog)
  27. //}}AFX_DATA_INIT
  28. }
  29. void CEventLog::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CEventLog)
  33. DDX_Control(pDX, IDC_LIST1, m_list);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CEventLog, CDialog)
  37. //{{AFX_MSG_MAP(CEventLog)
  38. ON_BN_CLICKED(IDC_BUTTONSAVE, OnButtonsave)
  39. ON_BN_CLICKED(IDEXIT, OnExit)
  40. ON_BN_CLICKED(ID_CANCEL, OnCancel)
  41. ON_WM_TIMER()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CEventLog message handlers
  46. void CEventLog::AddEvent(CString csEvent)
  47. {
  48. CTime time = CTime::GetCurrentTime();
  49. csEventTime[iEventPos].Format("%04d-%02d-%02d %02d:%02d:%02d", time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
  50. csEventInfo[iEventPos].Format("%s", csEvent);
  51. iEventPos++;
  52. if(iEventPos >= EVENTNUM)
  53. {
  54. iEventPos = 0;
  55. }
  56. }
  57. void CEventLog::OnButtonsave()
  58. {
  59. // TODO: Add your control notification handler code here
  60. CString sFileName;
  61. CTime time;
  62. if(iEventPos == 0)
  63. return;
  64. CNewclientDlg *pDlg = (CNewclientDlg *)this->GetParent();
  65. time = CTime::GetCurrentTime();
  66. sFileName.Format("%s\\EventFile_%4d%02d%02d_%02d%02d%02d.txt", pDlg->m_ClientParam.m_csLogSavePath, time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
  67. F_SaveEventFile(sFileName);
  68. F_InitList();
  69. m_bSave = TRUE;
  70. }
  71. void CEventLog::F_SaveEventFile(CString csFileName)
  72. {
  73. int i;
  74. CString sTemp;
  75. CStdioFile myFile;
  76. if(myFile.Open(csFileName, CFile::modeCreate|CFile::modeWrite) == FALSE)
  77. {
  78. MessageBox("日志文件创建失败!", "温馨提示", MB_ICONINFORMATION);
  79. return;
  80. }
  81. for(i = 0; i < iEventPos; i++)
  82. {
  83. sTemp.Format("%s %s\r\n", csEventTime[i], csEventInfo[i]);
  84. myFile.WriteString(sTemp);
  85. }
  86. myFile.Close();
  87. iEventPos = 0;
  88. }
  89. BOOL CEventLog::OnInitDialog()
  90. {
  91. CDialog::OnInitDialog();
  92. // TODO: Add extra initialization here
  93. m_bSave = FALSE;
  94. m_nTimer = 0;
  95. m_list.InsertColumn(0,"时间",LVCFMT_LEFT,120,-1);
  96. m_list.InsertColumn(1,"事件内容",LVCFMT_LEFT,600,-1);
  97. F_InitList();
  98. m_nTimer = SetTimer(EVENTLOG_TIMER, 1000, NULL);
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. // EXCEPTION: OCX Property Pages should return FALSE
  101. }
  102. void CEventLog::F_InitList()
  103. {
  104. int i;
  105. m_list.DeleteAllItems();
  106. for(i = 0; i < iEventPos; i++)
  107. {
  108. m_list.InsertItem(i, csEventTime[i]);
  109. m_list.SetItemText(i, 1, csEventInfo[i]);
  110. }
  111. }
  112. void CEventLog::OnExit()
  113. {
  114. // TODO: Add your control notification handler code here
  115. if(m_nTimer)
  116. {
  117. KillTimer(EVENTLOG_TIMER);
  118. }
  119. CDialog::OnCancel();
  120. }
  121. void CEventLog::OnCancel()
  122. {
  123. // TODO: Add your control notification handler code here
  124. }
  125. void CEventLog::OnTimer(UINT nIDEvent)
  126. {
  127. // TODO: Add your message handler code here and/or call default
  128. if(nIDEvent == EVENTLOG_TIMER)
  129. {
  130. //要刷新列表,必须要对csEventTime和csEventInfo数组进行保护。
  131. //F_InitList();
  132. }
  133. CDialog::OnTimer(nIDEvent);
  134. }