// ShowLOg.cpp : implementation file #include "stdafx.h" #include "ylgl.h" #include "ShowLOg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ShowLOg dialog ShowLOg::ShowLOg(CWnd* pParent /*=NULL*/) : CDialog(ShowLOg::IDD, pParent) , m_StartTime(0) , m_EndTime(0) { //{{AFX_DATA_INIT(ShowLOg) //}}AFX_DATA_INIT m_nIndex = 0; } void ShowLOg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ShowLOg) DDX_Control(pDX, IDC_COMBO1, m_combo1); DDX_Control(pDX, IDC_LIST1, m_List1); //}}AFX_DATA_MAP DDX_DateTimeCtrl(pDX, DTP_StartTime, m_StartTime); // Jeff.add DDX_DateTimeCtrl(pDX, DTP_EndTime, m_EndTime); // Jeff.add } BEGIN_MESSAGE_MAP(ShowLOg, CDialog) //{{AFX_MSG_MAP(ShowLOg) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP ON_BN_CLICKED(Btn_TimeFilter, OnBnClickedTimefilter) // Jeff.add ON_BN_CLICKED(Btn_ContentFind, OnBnClickedContentfind) // Jeff.add END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ShowLOg message handlers BOOL ShowLOg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_combo1.AddString("1个月"); m_combo1.AddString("2个月"); m_combo1.AddString("3个月"); m_combo1.AddString("6个月"); CString str = g_cominfoarray.ElementAt(0).ElementAt(112); if (str == "")str = "6个月"; m_combo1.SetCurSel(m_combo1.FindString(0, str)); #if 1 // Jeff.add m_EndTime = CTime::GetCurrentTime(); // printf("Jeff:GetYear=%d,GetMonth=%d,GetDay=%d\n\n",m_EndTime.GetYear(),m_EndTime.GetMonth(),m_EndTime.GetDay()); int nCurSel = m_combo1.GetCurSel(); // printf("Jeff:nCurSel=%d\n\n",nCurSel); switch (nCurSel) { case 0: { CTimeSpan ts(31, 0, 0, 0); m_StartTime = m_EndTime - ts; } break; case 1: { CTimeSpan ts(62, 0, 0, 0); m_StartTime = m_EndTime - ts; } break; case 2: { CTimeSpan ts(93, 0, 0, 0); m_StartTime = m_EndTime - ts; } break; case 3: { CTimeSpan ts(186, 0, 0, 0); m_StartTime = m_EndTime - ts; } break; default: break; } UpdateData(FALSE); //m_List1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP); #endif #if USE_ADO_OPT_DB m_List1.SetHeadings(_T("帐户,100;用户名,100;日期,100;类型,100;内容,100")); // m_List1.SetHeadings(_T("帐户,100;用户名,100;日期,100;类型,100;SN码,100;内容,100")); #else CRect rc; GetClientRect(rc); int wid = rc.Width() - 30; wid /= 5; CString strHead = _T(""); strHead.Format("日期,%d;内容,%d", wid, wid * 4); m_List1.SetHeadings(strHead); #endif//USE_ADO_OPT_DB GetData(); CenterWindow(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void ShowLOg::GetData() { #if USE_ADO_OPT_DB CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00"); CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59"); CString strFilter; strFilter.Format("LogDate >='%s' and LogDate <='%s'",strStartTime,strEndTime); g_sendhead.bsql = 2; //使用ADO读取 g_sendhead.code[0] = 2; // Jeff.case 185: log表; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(strFilter); if (g_bSendOK == 0) return; DataToArray(&m_List1array); m_List1.DeleteAllItems2(); m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); int ii = 0; for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(1)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(2)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(3)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(4)); // m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(5)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(6)); } m_List1.m_arLabels.SetSize(ii, 1); m_List1.m_LabelCount = ii; m_List1.SetItemCountEx(ii); #else g_sendhead.bsql = 0; g_sendhead.code[0] = 185; // Jeff.case 185: log表; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return; DataToArray(&m_List1array); m_List1.DeleteAllItems2(); int ii = 0; m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); int count = 0; for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii)); } m_List1.m_arLabels.SetSize(count, 1); ii = count; m_List1.m_LabelCount = ii; m_List1.SetItemCountEx(ii); #endif//USE_ADO_OPT_DB } void ShowLOg::OnButton1() { // TODO: Add your control notification handler code here int pos = m_combo1.GetCurSel(); if (pos == -1)return; CString str; m_combo1.GetLBText(pos, str); CString sql; sql.Format("update version set [logdays]='" + str + "'"); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; AfxMessageBox("保存成功!", MB_ICONINFORMATION); g_cominfoarray.ElementAt(0).SetAt(112, str); } // Jeff.查询日志功能. // 1.从时间段上获取数据库里的时间范围; // 2.在1的基础上,模糊查询数据内容; // 3.是否需要做一个导出xls功能; // void ShowLOg::OnBnClickedTimefilter() { // TODO: 在此添加控件通知处理程序代码 UpdateData(); #if USE_ADO_OPT_DB CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00"); CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59"); CString strFilter; strFilter.Format("LogDate >='%s' and LogDate <='%s'",strStartTime,strEndTime); g_sendhead.bsql = 2; g_sendhead.code[0] = 2; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(strFilter); if (g_bSendOK == 0) return; DataToArray(&m_List1array); SetDlgItemText(Btn_ContentFind, "查询"); m_nIndex = 0; m_List1.DeleteAllItems2(); int ii = 0; m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(1)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(2)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(3)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(4)); // m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(5)); m_List1.m_arLabels.ElementAt(ii).Add(m_List1array.ElementAt(ii).ElementAt(6)); } m_List1.m_arLabels.SetSize(ii, 1); m_List1.m_LabelCount = ii; m_List1.SetItemCountEx(ii); #else CString strStartTime = m_StartTime.Format("%Y-%m-%d 00:00:00"); CString strEndTime = m_EndTime.Format("%Y-%m-%d 23:59:59"); CString strFilter; strFilter.Format("date >='%s' and date <='%s'",strStartTime,strEndTime); g_sendhead.bsql = 0; g_sendhead.code[0] = 185; // Jeff.case 185: log表; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(strFilter); if (g_bSendOK == 0) return; DataToArray(&m_List1array); SetDlgItemText(Btn_ContentFind, "查询"); m_nIndex = 0; m_List1.DeleteAllItems2(); int ii = 0; m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1); int count = 0; for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++) { m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii)); } m_List1.m_arLabels.SetSize(count, 1); ii = count; m_List1.m_LabelCount = ii; m_List1.SetItemCountEx(ii); #endif//#ifdef USE_ADO_OPT_DB } void ShowLOg::OnBnClickedContentfind() { UpdateData(); //static int nIndex = 0;//用成员变量m_nIndex代替; CString strFind; GetDlgItemText(Edt_ContentFind, strFind); if (strFind == "") { AfxMessageBox("请输入查找内容"); return; } int nCount = m_List1.GetItemCount(); BOOL bFind = FALSE; for (int i = m_nIndex; i < nCount; i++) { #if USE_ADO_OPT_DB CString strContent = m_List1.m_arLabels.ElementAt(i).ElementAt(4); #else CString strContent = m_List1.m_arLabels.ElementAt(i).ElementAt(1); #endif//#ifdef USE_ADO_OPT_DB // printf("Jeff:当前项数=%d,查找:%s,内容:%s\n\n",nCount,strFind,strContent); if (strContent.Find(strFind) != -1) { int nItem = m_List1.GetTopIndex(); CRect rc; m_List1.GetItemRect(nItem, rc, LVIR_BOUNDS); CSize sz(0, (i - nItem)*rc.Height()); m_List1.Scroll(sz);//m_List1.SendMessage(WM_VSCROLL,SB_LINERIGHT,0); m_List1.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); //m_List1.SetItemState(i,LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); m_List1.SetFocus(); m_nIndex = i + 1; bFind = TRUE; SetDlgItemText(Btn_ContentFind, "下一个"); break; } } if (bFind == FALSE) { m_nIndex = 0; SetDlgItemText(Btn_ContentFind, "查询"); AfxMessageBox("未找到相关内容!"); } }