LogQuery.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:7k
开发平台:

Visual C++

  1. // LogQuery.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "LogQuery.h"
  6. //owner add
  7. #include "GuiRes.h"
  8. #include "PacketMonitor.h"
  9. #include "..commonxlogfile.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. //=============================================================================================
  16. // CLogQuery property page
  17. extern CAclFile m_AclFile;
  18. IMPLEMENT_DYNCREATE(CLogQuery, CPropertyPage)
  19. CLogQuery::CLogQuery() : CPropertyPage(CLogQuery::IDD)
  20. {
  21. m_iCurrentPage = 0;
  22. m_iPageCount = 0;
  23. m_ulStartPosition = 0;
  24. m_ulRecordCount = 0;
  25. m_pLogFile = NULL;
  26. }
  27. CLogQuery::~CLogQuery()
  28. {
  29. }
  30. void CLogQuery::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CPropertyPage::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CLogQuery)
  34. DDX_Control(pDX, IDC_STOP_TIME, m_EndTime);
  35. DDX_Control(pDX, IDC_STOP_DATE, m_EndDate);
  36. DDX_Control(pDX, IDC_START_TIME, m_StartTime);
  37. DDX_Control(pDX, IDC_START_DATE, m_StartDate);
  38. DDX_Control(pDX, IDC_LIST_LOG, m_ListLog);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CLogQuery, CPropertyPage)
  42. //{{AFX_MSG_MAP(CLogQuery)
  43. ON_BN_CLICKED(IDC_LOG_QUERY_BUTTON_QUERY, OnLogQueryButtonQuery)
  44. ON_BN_CLICKED(IDC_LOG_QUERY_BUTTON_DELETE, OnLogQueryButtonDelete)
  45. ON_BN_CLICKED(IDC_LOG_QUERY_BUTTON_BACK, OnLogQueryButtonBack)
  46. ON_BN_CLICKED(IDC_LOG_QUERY_BUTTON_NEXT, OnLogQueryButtonNext)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. //=============================================================================================
  50. // CLogQuery message handlers
  51. BOOL CLogQuery::OnInitDialog() 
  52. {
  53. CPropertyPage::OnInitDialog();
  54. InitDlgResource();
  55. return TRUE;  
  56. }
  57. //---------------------------------------------------------------------------------------------
  58. //initialize dialog's resource
  59. void CLogQuery::InitDlgResource()
  60. {
  61. SetDlgItemText(IDC_LOG_QUERY_SET_LABLE ,GUI_LOG_QUERY_SET_LABLE);
  62. SetDlgItemText(IDC_LOG_QUERY_SET_START_TIME_LABLE ,GUI_LOG_QUERY_SET_START_TIME_LABLE);
  63. SetDlgItemText(IDC_LOG_QUERY_SET_END_TIME_LABLE ,GUI_LOG_QUERY_SET_END_TIME_LABLE);
  64. SetDlgItemText(IDC_LOG_QUERY_BUTTON_QUERY ,GUI_LOG_QUERY_BUTTON_QUERY);
  65. SetDlgItemText(IDC_LOG_QUERY_BUTTON_BACK ,GUI_LOG_QUERY_BUTTON_BACK);
  66. SetDlgItemText(IDC_LOG_QUERY_BUTTON_NEXT ,GUI_LOG_QUERY_BUTTON_NEXT);
  67. SetDlgItemText(IDC_LOG_QUERY_BUTTON_DELETE ,GUI_LOG_QUERY_BUTTON_DELETE);
  68. SetPageLable();
  69. CTimeSpan ts(ACL_MAX_TIME);
  70. m_StartDate.SetTime(&(CTime::GetCurrentTime() - ts));
  71. SetButton();
  72. CPacketMonitor::InitList(&m_ListLog);
  73. }
  74. void CLogQuery::OnLogQueryButtonQuery() 
  75. {
  76. LOG_FIND find;
  77. find.tStartTime = GetTime(TRUE);
  78. find.tEndTime = GetTime(FALSE);
  79. static CXLogFile m_file;
  80. m_pLogFile = (void*)&m_file;
  81. if(find.tStartTime > find.tEndTime)
  82. {
  83. AfxMessageBox(GUI_ACL_MESSAGE_START_TIME_MIN_END_TIME);
  84. return;
  85. }
  86. SetCursor(LoadCursor(NULL, IDC_WAIT));
  87. if(m_file.FindLog(&find, m_AclFile.mAclHeader.uiLogSize) != XERR_SUCCESS 
  88. || find.ulRecordCount == 0)
  89. {
  90. SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
  91. AfxMessageBox(GUI_ACL_MESSAGE_CAN_NOT_FIND_RECORD);
  92. return;
  93. }
  94. SetButton();
  95. m_ulStartPosition = find.ulStartPosition;
  96. m_ulRecordCount = find.ulRecordCount;
  97. m_ulChangeDirectionIndex = find.ulChangeDirectionIndex;
  98. m_iCurrentPage = 1;
  99. m_iPageCount = m_ulRecordCount / LOG_QUERY_PAGE_SIZE;
  100. if((m_ulRecordCount % LOG_QUERY_PAGE_SIZE) != 0)
  101. m_iPageCount ++;
  102. if(m_iPageCount > 1)
  103. SetButton(FALSE, TRUE);
  104. ShowRecordPage();
  105. SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
  106. }
  107. int CLogQuery::ShowRecordPage()
  108. {
  109. if(m_pLogFile == NULL || m_iCurrentPage <= 0 || m_iCurrentPage > m_iPageCount)
  110. return XERR_LOG_NO_CAN_SHOW_RECORD;
  111. DWORD ulShowedCount = (m_iCurrentPage - 1) * LOG_QUERY_PAGE_SIZE;
  112. DWORD ulRecordCount = (m_iCurrentPage != m_iPageCount) ? LOG_QUERY_PAGE_SIZE : 
  113.   (m_ulRecordCount - ulShowedCount);
  114. DWORD ulStartPosition = 0;
  115. if(m_ulChangeDirectionIndex > 0 && ulShowedCount >= m_ulChangeDirectionIndex)
  116. ulStartPosition = LOG_HEADER_LENTH + (ulShowedCount - m_ulChangeDirectionIndex) * SESSION_LENTH;
  117. else
  118. ulStartPosition = m_ulStartPosition + ulShowedCount * SESSION_LENTH;
  119. #if _DEBUG
  120. CString a;
  121. a.Format("ChangeDirectionIndex: %u; StartPosition: %u; m_StartPosition: %u"
  122. , m_ulChangeDirectionIndex
  123. , ulStartPosition
  124. , m_ulStartPosition
  125. );
  126. ODS(a);
  127. #endif
  128. SetPageLable(ulRecordCount);
  129. CXLogFile *m_file = (CXLogFile*)m_pLogFile;
  130. SESSION session;
  131. TRY
  132. {
  133. m_ListLog.DeleteAllItems();
  134. m_file->m_LogFile.Seek(ulStartPosition, CFile::begin);
  135. for(DWORD i = 1; i <= ulRecordCount; i++)
  136. {
  137. m_file->m_LogFile.Read(&session, SESSION_LENTH);
  138. CPacketMonitor::InsertOneList(&m_ListLog, &session, TRUE, FALSE);
  139. if(m_ulChangeDirectionIndex > 0 && (ulShowedCount + i) == m_ulChangeDirectionIndex)
  140. m_file->m_LogFile.Seek(LOG_HEADER_LENTH, CFile::begin);
  141. }
  142. }
  143. CATCH( CFileException, e )
  144. {
  145. return XERR_LOG_READ_FILE_ERROR;
  146. }
  147. END_CATCH
  148. return XERR_SUCCESS;
  149. }
  150. CTime CLogQuery::GetTime(BOOL IsStart)
  151. {
  152. CTime t(0), td1, tt1;
  153. if(IsStart)
  154. {
  155. m_StartDate.GetTime(td1);
  156. m_StartTime.GetTime(tt1);
  157. }
  158. else
  159. {
  160. m_EndDate.GetTime(td1);
  161. m_EndTime.GetTime(tt1);
  162. }
  163. CTimeSpan ts = tt1.GetHour() * 3600 + tt1.GetMinute() * 60 + tt1.GetSecond()
  164. - td1.GetHour() * 3600 - td1.GetMinute() * 60 - td1.GetSecond();
  165. t = td1 + ts;
  166. return t;
  167. }
  168. void CLogQuery::OnLogQueryButtonDelete() 
  169. {
  170. m_ListLog.DeleteAllItems();
  171. m_iPageCount = 0;
  172. m_iCurrentPage = 0;
  173. m_ulRecordCount = 0;
  174. SetPageLable();
  175. SetButton();
  176. }
  177. void CLogQuery::OnLogQueryButtonBack() 
  178. {
  179. if(!GetDlgItem(IDC_LOG_QUERY_BUTTON_BACK)->IsWindowEnabled())
  180. return;
  181. SetButton(TRUE, TRUE);
  182. m_iCurrentPage --;
  183. if(m_iCurrentPage <= 1)
  184. SetButton(FALSE, TRUE);
  185. SetCursor(LoadCursor(NULL, IDC_WAIT));
  186. ShowRecordPage();
  187. SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
  188. }
  189. void CLogQuery::OnLogQueryButtonNext() 
  190. {
  191. if(!GetDlgItem(IDC_LOG_QUERY_BUTTON_NEXT)->IsWindowEnabled())
  192. return;
  193. SetButton(TRUE, TRUE);
  194. m_iCurrentPage ++;
  195. if(m_iCurrentPage >= m_iPageCount)
  196. SetButton(TRUE, FALSE);
  197. SetCursor(LoadCursor(NULL, IDC_WAIT));
  198. ShowRecordPage();
  199. SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
  200. }
  201. void CLogQuery::SetButton(BOOL IsBack, BOOL IsNext)
  202. {
  203. GetDlgItem(IDC_LOG_QUERY_BUTTON_BACK)->EnableWindow(IsBack);
  204. GetDlgItem(IDC_LOG_QUERY_BUTTON_NEXT)->EnableWindow(IsNext);
  205. }
  206. void CLogQuery::SetPageLable(DWORD ulRecordCount)
  207. {
  208. CString tmpStr;
  209. tmpStr.Format(
  210. GUI_LOG_QUERY_RESULT_LIST_LABLE, 
  211. m_iCurrentPage,
  212. m_iPageCount, 
  213. LOG_QUERY_PAGE_SIZE,
  214. ulRecordCount,
  215. m_ulRecordCount
  216. );
  217. SetDlgItemText(IDC_LOG_QUERY_RESULT_LIST_LABLE, tmpStr);
  218. }