treeforhistory.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:4k
- #include "stdafx.h"
- #include "trfAgent.h"
- #include "mainfrm.h"
- #include "TreeForHistory.h"
- CTreeForHistory::CTreeForHistory(){}
- CTreeForHistory::~CTreeForHistory(){}
- BEGIN_MESSAGE_MAP(CTreeForHistory, CTreeCtrl)
- //{{AFX_MSG_MAP(CTreeForHistory)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- int CTreeForHistory::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- lpCreateStruct->style = TVS_HASLINES | TVS_LINESATROOT |
- TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_DISABLEDRAGDROP;
- if(-1 == CTreeCtrl::OnCreate(lpCreateStruct))
- {
- TRACE0("Failed to create the CTreeCtrl for historyn");
- return -1;
- }
- if(!this->m_imgTree.Create(IDB_WORKSPACE, 16, 3, RGB(255, 255, 255)))
- {
- TRACE0("Failed to create the m_imgTree for historyn");
- return -1;
- }
- this->SetImageList(&m_imgTree, TVSIL_NORMAL);
- this->MakeTree();
- return 0;
- }
- void CTreeForHistory::MakeTree()
- {
- //0: sended files history.
- //1: recved files history.
- const HISTREEDATA nodes[] = {
- {IDS_HISTREE_TODAY, 0, 1},
- {IDS_HISTREE_ONEDS, 1, 1},
- {IDS_HISTREE_TWODS, 2, 1},
- {IDS_HISTREE_TREDS, 3, 1},
- {IDS_HISTREE_FOUDS, 4, 1},
- {IDS_HISTREE_FIVDS, 5, 1},
- {IDS_HISTREE_SIXDS, 6, 1},
- {IDS_HISTREE_TWOWEKS, 14, 1},
- {IDS_HISTREE_ONEMON, 30, 1},
- {IDS_HISTREE_TWOMONS, 60, 1},
- {IDS_HISTREE_HALFYEA, 180, 1},
- {IDS_HISTREE_ONEYEA, 365, 1},
- {IDS_HISTREE_ALL, -1, 1},
- };
- //
- HTREEITEM hParent_r = this->InsertItem(_LoadString(IDS_RECVED_RECORD).GetBuffer(0), 3, 3);
- //HTREEITEM hParent_s = this->InsertItem(_LoadString(IDS_SNDED_RECORD).GetBuffer(0), 3, 3);
- this->SetItemData(hParent_r, 0);
- //this->SetItemData(hParent_s, 0);
- for(int i = 0; i < sizeofarray(nodes); ++i)
- {
- CString snode = _LoadString(nodes[i].nNodeTxtId);
- PHISTREEDATA pdata_r = new HISTREEDATA;
- *pdata_r = nodes[i];
- pdata_r->nItemType = 1;
- HTREEITEM hSub_r = this->InsertItem(snode, 4, 4, hParent_r);
- this->SetItemData(hSub_r, (DWORD)pdata_r);
- /*
- PHISTREEDATA pdata_s = new HISTREEDATA;
- *pdata_s = nodes[i];
- pdata_s->nItemType = 0;
- HTREEITEM hSub_s = this->InsertItem(snode, 4, 4, hParent_s);
- this->SetItemData(hSub_s, (DWORD)pdata_s);
- */
- }
- }
- void CTreeForHistory::ReleaseTree()
- {
- HTREEITEM hroot = this->GetRootItem();
- while(NULL != hroot)
- {
- PHISTREEDATA p = NULL;
- HTREEITEM hchild = this->GetNextItem(hroot, TVGN_CHILD);
- while(NULL != hchild)
- {
- p = (PHISTREEDATA)this->GetItemData(hchild);
- _DELETE(p);
- hchild = this->GetNextItem(hchild, TVGN_NEXT);
- }
- p = (PHISTREEDATA)this->GetItemData(hroot);
- _DELETE(p);
- hroot = this->GetNextItem(hroot, TVGN_NEXT);
- }
- }
- void CTreeForHistory::OnDestroy()
- {
- this->ReleaseTree();
-
- CTreeCtrl::OnDestroy();
- }
- void CTreeForHistory::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- *pResult = 0;
- PHISTREEDATA pdata = (PHISTREEDATA)this->GetItemData(pNMTreeView->itemNew.hItem);
- if(NULL == pdata || pNMTreeView->itemNew.hItem == pNMTreeView->itemOld.hItem) return ;
- CGuiRecordSet rs;
- char starttime[32], endtime[32], sql[MAX_SQL_SIZE];
- try
- {
- //////////////////////////////////////////////////////////////////////////
- CTime now = CTime::GetCurrentTime();
- _snprintf(starttime, sizeof(starttime), SYS_TIMEFORMAT,
- now.GetYear(), now.GetMonth(), now.GetDay() - pdata->nLimitDays, 0, 0, 0);
- _snprintf(endtime, sizeof(endtime), SYS_TIMEFORMAT,
- now.GetYear(), now.GetMonth(), now.GetDay(), now.GetHour(), now.GetMinute(), now.GetSecond());
-
- switch(pdata->nItemType) {
- case 0:
- {
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_TRANS_TRANSHISTORY,
- SQL::TRANSTYP_SNDER | SQL::TRANSTYP_SNDOK, starttime, endtime);
- }
- break;
- case 1:
- {
- _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_TRANS_TRANSHISTORY,
- SQL::TRANSTYP_RECOR | SQL::TRANSTYP_RECVOK, starttime, endtime);
- }
- break;
- }
-
- if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
- {
- //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
-
- CMainFrame *pmainfrm = (CMainFrame*)::AfxGetMainWnd();
- pmainfrm->m_pwndWorkFrame->m_pwndFileTransView->m_pwndHistoryView->AddHistoryFromRS(rs);
- rs.Close();
- }
- catch(...)
- {
- }
- }