ShowLOg.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // ShowLOg.cpp : implementation file
  2. #include "stdafx.h"
  3. #include "ylgl.h"
  4. #include "ShowLOg.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // ShowLOg dialog
  12. ShowLOg::ShowLOg(CWnd* pParent /*=NULL*/)
  13. : CDialog(ShowLOg::IDD, pParent)
  14. , m_StartTime(0)
  15. , m_EndTime(0)
  16. {
  17. //{{AFX_DATA_INIT(ShowLOg)
  18. //}}AFX_DATA_INIT
  19. m_nIndex = 0;
  20. }
  21. void ShowLOg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(ShowLOg)
  25. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  26. DDX_Control(pDX, IDC_LIST1, m_List1);
  27. //}}AFX_DATA_MAP
  28. DDX_DateTimeCtrl(pDX, DTP_StartTime, m_StartTime); // Jeff.add
  29. DDX_DateTimeCtrl(pDX, DTP_EndTime, m_EndTime); // Jeff.add
  30. }
  31. BEGIN_MESSAGE_MAP(ShowLOg, CDialog)
  32. //{{AFX_MSG_MAP(ShowLOg)
  33. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  34. //}}AFX_MSG_MAP
  35. ON_BN_CLICKED(Btn_TimeFilter, OnBnClickedTimefilter) // Jeff.add
  36. ON_BN_CLICKED(Btn_ContentFind, OnBnClickedContentfind) // Jeff.add
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // ShowLOg message handlers
  40. BOOL ShowLOg::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. // TODO: Add extra initialization here
  44. m_combo1.AddString("1个月");
  45. m_combo1.AddString("2个月");
  46. m_combo1.AddString("3个月");
  47. m_combo1.AddString("6个月");
  48. CString str = g_cominfoarray.ElementAt(0).ElementAt(112);
  49. if (str == "")str = "6个月";
  50. m_combo1.SetCurSel(m_combo1.FindString(0, str));
  51. #if 1 // Jeff.add
  52. m_EndTime = CTime::GetCurrentTime();
  53. // printf("Jeff:GetYear=%d,GetMonth=%d,GetDay=%d\n\n",m_EndTime.GetYear(),m_EndTime.GetMonth(),m_EndTime.GetDay());
  54. int nCurSel = m_combo1.GetCurSel();
  55. // printf("Jeff:nCurSel=%d\n\n",nCurSel);
  56. switch (nCurSel)
  57. {
  58. case 0:
  59. {
  60. CTimeSpan ts(31, 0, 0, 0);
  61. m_StartTime = m_EndTime - ts;
  62. }
  63. break;
  64. case 1:
  65. {
  66. CTimeSpan ts(62, 0, 0, 0);
  67. m_StartTime = m_EndTime - ts;
  68. }
  69. break;
  70. case 2:
  71. {
  72. CTimeSpan ts(93, 0, 0, 0);
  73. m_StartTime = m_EndTime - ts;
  74. }
  75. break;
  76. case 3:
  77. {
  78. CTimeSpan ts(186, 0, 0, 0);
  79. m_StartTime = m_EndTime - ts;
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. UpdateData(FALSE);
  86. //m_List1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
  87. #endif
  88. #if USE_ADO_OPT_DB
  89. m_List1.SetHeadings(_T("帐户,100;用户名,100;日期,100;类型,100;内容,100"));
  90. // m_List1.SetHeadings(_T("帐户,100;用户名,100;日期,100;类型,100;SN码,100;内容,100"));
  91. #else
  92. CRect rc;
  93. GetClientRect(rc);
  94. int wid = rc.Width() - 30;
  95. wid /= 5;
  96. CString strHead = _T("");
  97. strHead.Format("日期,%d;内容,%d", wid, wid * 4);
  98. m_List1.SetHeadings(strHead);
  99. #endif//USE_ADO_OPT_DB
  100. GetData();
  101. CenterWindow();
  102. return TRUE; // return TRUE unless you set the focus to a control
  103. // EXCEPTION: OCX Property Pages should return FALSE
  104. }
  105. void ShowLOg::GetData()
  106. {
  107. #if USE_ADO_OPT_DB
  108. CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00");
  109. CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59");
  110. CString strFilter;
  111. strFilter.Format("LogDate >='%s' and LogDate <='%s'",strStartTime,strEndTime);
  112. g_sendhead.bsql = 2; //使用ADO读取
  113. g_sendhead.code[0] = 2; // Jeff.case 185: log表;
  114. g_sendhead.tabcount = 1;
  115. g_pMainWnd->ProcessChatMessageRequest2(strFilter);
  116. if (g_bSendOK == 0)
  117. return;
  118. DataToArray(&m_List1array);
  119. m_List1.DeleteAllItems2();
  120. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  121. int ii = 0;
  122. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  123. {
  124. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(1));
  125. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(2));
  126. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(3));
  127. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(4));
  128. // m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(5));
  129. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(6));
  130. }
  131. m_List1.m_arLabels.SetSize(ii, 1);
  132. m_List1.m_LabelCount = ii;
  133. m_List1.SetItemCountEx(ii);
  134. #else
  135. g_sendhead.bsql = 0;
  136. g_sendhead.code[0] = 185; // Jeff.case 185: log表;
  137. g_sendhead.tabcount = 1;
  138. g_pMainWnd->ProcessChatMessageRequest2(1);
  139. if (g_bSendOK == 0)return;
  140. DataToArray(&m_List1array);
  141. m_List1.DeleteAllItems2();
  142. int ii = 0;
  143. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  144. int count = 0;
  145. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  146. {
  147. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  148. }
  149. m_List1.m_arLabels.SetSize(count, 1);
  150. ii = count;
  151. m_List1.m_LabelCount = ii;
  152. m_List1.SetItemCountEx(ii);
  153. #endif//USE_ADO_OPT_DB
  154. }
  155. void ShowLOg::OnButton1()
  156. {
  157. // TODO: Add your control notification handler code here
  158. int pos = m_combo1.GetCurSel();
  159. if (pos == -1)return;
  160. CString str;
  161. m_combo1.GetLBText(pos, str);
  162. CString sql;
  163. sql.Format("update version set [logdays]='" + str + "'");
  164. g_sendhead.bsql = 1;
  165. g_pMainWnd->ProcessChatMessageRequest2(sql);
  166. if (g_bSendOK == 0)return;
  167. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  168. g_cominfoarray.ElementAt(0).SetAt(112, str);
  169. }
  170. // Jeff.查询日志功能.
  171. // 1.从时间段上获取数据库里的时间范围;
  172. // 2.在1的基础上,模糊查询数据内容;
  173. // 3.是否需要做一个导出xls功能;
  174. //
  175. void ShowLOg::OnBnClickedTimefilter()
  176. {
  177. // TODO: 在此添加控件通知处理程序代码
  178. UpdateData();
  179. #if USE_ADO_OPT_DB
  180. CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00");
  181. CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59");
  182. CString strFilter;
  183. strFilter.Format("LogDate >='%s' and LogDate <='%s'",strStartTime,strEndTime);
  184. g_sendhead.bsql = 2;
  185. g_sendhead.code[0] = 2;
  186. g_sendhead.tabcount = 1;
  187. g_pMainWnd->ProcessChatMessageRequest2(strFilter);
  188. if (g_bSendOK == 0) return;
  189. DataToArray(&m_List1array);
  190. SetDlgItemText(Btn_ContentFind, "查询");
  191. m_nIndex = 0;
  192. m_List1.DeleteAllItems2();
  193. int ii = 0;
  194. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  195. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  196. {
  197. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(1));
  198. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(2));
  199. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(3));
  200. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(4));
  201. // m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(5));
  202. m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(6));
  203. }
  204. m_List1.m_arLabels.SetSize(ii, 1);
  205. m_List1.m_LabelCount = ii;
  206. m_List1.SetItemCountEx(ii);
  207. #else
  208. CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00");
  209. CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59");
  210. CString strFilter;
  211. strFilter.Format("date >='%s' and date <='%s'",strStartTime,strEndTime);
  212. g_sendhead.bsql = 0;
  213. g_sendhead.code[0] = 185; // Jeff.case 185: log表;
  214. g_sendhead.tabcount = 1;
  215. g_pMainWnd->ProcessChatMessageRequest2(strFilter);
  216. if (g_bSendOK == 0) return;
  217. DataToArray(&m_List1array);
  218. SetDlgItemText(Btn_ContentFind, "查询");
  219. m_nIndex = 0;
  220. m_List1.DeleteAllItems2();
  221. int ii = 0;
  222. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  223. int count = 0;
  224. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  225. {
  226. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  227. }
  228. m_List1.m_arLabels.SetSize(count, 1);
  229. ii = count;
  230. m_List1.m_LabelCount = ii;
  231. m_List1.SetItemCountEx(ii);
  232. #endif//#ifdef USE_ADO_OPT_DB
  233. }
  234. void ShowLOg::OnBnClickedContentfind()
  235. {
  236. UpdateData();
  237. //static int nIndex = 0;//用成员变量m_nIndex代替;
  238. CString strFind;
  239. GetDlgItemText(Edt_ContentFind, strFind);
  240. if (strFind == "")
  241. {
  242. AfxMessageBox("请输入查找内容");
  243. return;
  244. }
  245. int nCount = m_List1.GetItemCount();
  246. BOOL bFind = FALSE;
  247. for (int i = m_nIndex; i < nCount; i++)
  248. {
  249. #if USE_ADO_OPT_DB
  250. CString strContent = m_List1.m_arLabels.ElementAt(i).ElementAt(4);
  251. #else
  252. CString strContent = m_List1.m_arLabels.ElementAt(i).ElementAt(1);
  253. #endif//#ifdef USE_ADO_OPT_DB
  254. // printf("Jeff:当前项数=%d,查找:%s,内容:%s\n\n",nCount,strFind,strContent);
  255. if (strContent.Find(strFind) != -1)
  256. {
  257. int nItem = m_List1.GetTopIndex();
  258. CRect rc;
  259. m_List1.GetItemRect(nItem, rc, LVIR_BOUNDS);
  260. CSize sz(0, (i - nItem)*rc.Height());
  261. m_List1.Scroll(sz);//m_List1.SendMessage(WM_VSCROLL,SB_LINERIGHT,0);
  262. m_List1.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
  263. //m_List1.SetItemState(i,LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  264. m_List1.SetFocus();
  265. m_nIndex = i + 1;
  266. bFind = TRUE;
  267. SetDlgItemText(Btn_ContentFind, "下一个");
  268. break;
  269. }
  270. }
  271. if (bFind == FALSE)
  272. {
  273. m_nIndex = 0;
  274. SetDlgItemText(Btn_ContentFind, "查询");
  275. AfxMessageBox("未找到相关内容!");
  276. }
  277. }