ShowLOg.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. CRect rc;
  89. GetClientRect(rc);
  90. int wid=rc.Width ()-30;
  91. wid/=5;
  92. str.Format ("日期,%d;内容,%d", wid, wid*4);
  93. m_List1.SetHeadings(str);
  94. GetData();
  95. CenterWindow();
  96. return TRUE; // return TRUE unless you set the focus to a control
  97. // EXCEPTION: OCX Property Pages should return FALSE
  98. }
  99. void ShowLOg::GetData()
  100. {
  101. g_sendhead.bsql=0;
  102. g_sendhead.code[0]=185; // Jeff.case 185: log表;
  103. g_sendhead.tabcount=1;
  104. g_pMainWnd->ProcessChatMessageRequest2(1);
  105. if(g_bSendOK==0)return;
  106. DataToArray(&m_List1array);
  107. m_List1.DeleteAllItems2 ();
  108. int ii=0;
  109. m_List1.m_arLabels.SetSize( m_List1array.GetSize(), 1 );
  110. int count=0;
  111. for(ii=0; ii<m_List1.m_arLabels.GetSize(); ii++)
  112. {
  113. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  114. }
  115. m_List1.m_arLabels.SetSize(count, 1);
  116. ii=count;
  117. m_List1.m_LabelCount=ii;
  118. m_List1.SetItemCountEx (ii);
  119. }
  120. void ShowLOg::OnButton1()
  121. {
  122. // TODO: Add your control notification handler code here
  123. int pos=m_combo1.GetCurSel ();
  124. if(pos==-1)return;
  125. CString str;
  126. m_combo1.GetLBText(pos, str);
  127. CString sql;
  128. sql.Format("update version set [logdays]='"+str+"'");
  129. g_sendhead.bsql=1;
  130. g_pMainWnd->ProcessChatMessageRequest2(sql);
  131. if(g_bSendOK==0)return;
  132. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  133. g_cominfoarray.ElementAt(0).SetAt(112, str);
  134. }
  135. // Jeff.查询日志功能.
  136. // 1.从时间段上获取数据库里的时间范围;
  137. // 2.在1的基础上,模糊查询数据内容;
  138. // 3.是否需要做一个导出xls功能;
  139. //
  140. void ShowLOg::OnBnClickedTimefilter()
  141. {
  142. // TODO: 在此添加控件通知处理程序代码
  143. UpdateData();
  144. CString strStartTime = m_StartTime.Format("%Y-%m-%d");
  145. CString strEndTime = m_EndTime.Format("%Y-%m-%d");
  146. CString strFilter;
  147. //strFilter.Format("date >='%s' and date <='%s'",strStartTime,strEndTime);
  148. strFilter.Format("date between '%s' and '%s'",strStartTime,strEndTime);
  149. // printf("Jeff:strFilter=%s\n\n",strFilter);
  150. g_sendhead.bsql=0;
  151. g_sendhead.code[0]=185; // Jeff.case 185: log表;
  152. g_sendhead.tabcount=1;
  153. g_pMainWnd->ProcessChatMessageRequest2(strFilter);
  154. if(g_bSendOK==0) return;
  155. DataToArray(&m_List1array);
  156. SetDlgItemText(Btn_ContentFind,"查询");
  157. m_nIndex = 0;
  158. m_List1.DeleteAllItems2();
  159. int ii=0;
  160. m_List1.m_arLabels.SetSize( m_List1array.GetSize(), 1 );
  161. int count=0;
  162. for(ii=0; ii<m_List1.m_arLabels.GetSize(); ii++)
  163. {
  164. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  165. }
  166. m_List1.m_arLabels.SetSize(count, 1);
  167. ii=count;
  168. m_List1.m_LabelCount=ii;
  169. m_List1.SetItemCountEx(ii);
  170. }
  171. void ShowLOg::OnBnClickedContentfind()
  172. {
  173. UpdateData();
  174. //static int nIndex = 0;//用成员变量m_nIndex代替;
  175. CString strFind;
  176. GetDlgItemText(Edt_ContentFind,strFind);
  177. if ( strFind == "")
  178. {
  179. AfxMessageBox("请输入查找内容");
  180. return;
  181. }
  182. int nCount = m_List1.GetItemCount();
  183. BOOL bFind = FALSE;
  184. for( int i = m_nIndex; i < nCount; i++)
  185. {
  186. CString strContent = m_List1.m_arLabels.ElementAt(i).ElementAt(1);
  187. // printf("Jeff:当前项数=%d,查找:%s,内容:%s\n\n",nCount,strFind,strContent);
  188. if(strContent.Find(strFind) != -1)
  189. {
  190. int nItem = m_List1.GetTopIndex();
  191. CRect rc;
  192. m_List1.GetItemRect(nItem, rc, LVIR_BOUNDS);
  193. CSize sz(0, (i - nItem)*rc.Height());
  194. m_List1.Scroll(sz);//m_List1.SendMessage(WM_VSCROLL,SB_LINERIGHT,0);
  195. m_List1.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
  196. //m_List1.SetItemState(i,LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  197. m_List1.SetFocus();
  198. m_nIndex = i+1;
  199. bFind = TRUE;
  200. SetDlgItemText(Btn_ContentFind,"下一个");
  201. break;
  202. }
  203. }
  204. if ( bFind == FALSE )
  205. {
  206. m_nIndex = 0;
  207. SetDlgItemText(Btn_ContentFind,"查询");
  208. AfxMessageBox("未找到相关内容!");
  209. }
  210. }