123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- // 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("未找到相关内容!");
- }
- }
|