EventLog.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // EventLog.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_OCX.h"
  5. #include "EventLog.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. extern CLIENTPARAM ClientParam;
  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. time = CTime::GetCurrentTime();
  65. sFileName.Format("%s\\EventFile_%4d%02d%02d_%02d%02d%02d.txt", ClientParam.m_csLogSavePath, time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
  66. F_SaveEventFile(sFileName);
  67. F_InitList();
  68. m_bSave = TRUE;
  69. }
  70. void CEventLog::F_SaveEventFile(CString csFileName)
  71. {
  72. int i;
  73. CString sTemp;
  74. CStdioFile myFile;
  75. if(myFile.Open(csFileName, CFile::modeCreate|CFile::modeWrite) == FALSE)
  76. {
  77. MessageBox("日志文件创建失败!", "温馨提示", MB_ICONINFORMATION);
  78. return;
  79. }
  80. for(i = 0; i < iEventPos; i++)
  81. {
  82. sTemp.Format("%s %s\r\n", csEventTime[i], csEventInfo[i]);
  83. myFile.WriteString(sTemp);
  84. }
  85. myFile.Close();
  86. iEventPos = 0;
  87. }
  88. BOOL CEventLog::OnInitDialog()
  89. {
  90. CDialog::OnInitDialog();
  91. // TODO: Add extra initialization here
  92. m_bSave = FALSE;
  93. m_nTimer = 0;
  94. m_list.InsertColumn(0,"时间",LVCFMT_LEFT,120,-1);
  95. m_list.InsertColumn(1,"事件内容",LVCFMT_LEFT,600,-1);
  96. F_InitList();
  97. m_nTimer = SetTimer(EVENTLOG_TIMER, 1000, NULL);
  98. return TRUE; // return TRUE unless you set the focus to a control
  99. // EXCEPTION: OCX Property Pages should return FALSE
  100. }
  101. void CEventLog::F_InitList()
  102. {
  103. int i;
  104. m_list.DeleteAllItems();
  105. for(i = 0; i < iEventPos; i++)
  106. {
  107. m_list.InsertItem(i, csEventTime[i]);
  108. m_list.SetItemText(i, 1, csEventInfo[i]);
  109. }
  110. }
  111. void CEventLog::OnExit()
  112. {
  113. // TODO: Add your control notification handler code here
  114. if(m_nTimer)
  115. {
  116. KillTimer(EVENTLOG_TIMER);
  117. }
  118. CDialog::OnCancel();
  119. }
  120. void CEventLog::OnCancel()
  121. {
  122. // TODO: Add your control notification handler code here
  123. }
  124. void CEventLog::OnTimer(UINT nIDEvent)
  125. {
  126. // TODO: Add your message handler code here and/or call default
  127. if(nIDEvent == EVENTLOG_TIMER)
  128. {
  129. //要刷新列表,必须要对csEventTime和csEventInfo数组进行保护。
  130. //F_InitList();
  131. }
  132. CDialog::OnTimer(nIDEvent);
  133. }