treeforhistory.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:4k
源码类别:

网格计算

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "trfAgent.h"
  3. #include "mainfrm.h"
  4. #include "TreeForHistory.h"
  5. CTreeForHistory::CTreeForHistory(){}
  6. CTreeForHistory::~CTreeForHistory(){}
  7. BEGIN_MESSAGE_MAP(CTreeForHistory, CTreeCtrl)
  8. //{{AFX_MSG_MAP(CTreeForHistory)
  9. ON_WM_CREATE()
  10. ON_WM_DESTROY()
  11. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  12. //}}AFX_MSG_MAP
  13. END_MESSAGE_MAP()
  14. int CTreeForHistory::OnCreate(LPCREATESTRUCT lpCreateStruct)
  15. {
  16. lpCreateStruct->style = TVS_HASLINES | TVS_LINESATROOT |
  17. TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_DISABLEDRAGDROP;
  18. if(-1 == CTreeCtrl::OnCreate(lpCreateStruct))
  19. {
  20. TRACE0("Failed to create the CTreeCtrl for historyn");
  21. return -1;
  22. }
  23. if(!this->m_imgTree.Create(IDB_WORKSPACE, 16, 3, RGB(255, 255, 255)))
  24. {
  25. TRACE0("Failed to create the m_imgTree for historyn");
  26. return -1;
  27. }
  28. this->SetImageList(&m_imgTree, TVSIL_NORMAL);
  29. this->MakeTree();
  30. return 0;
  31. }
  32. void CTreeForHistory::MakeTree()
  33. {
  34. //0: sended files history.
  35. //1: recved files history.
  36. const HISTREEDATA nodes[] = {
  37. {IDS_HISTREE_TODAY, 0, 1},
  38. {IDS_HISTREE_ONEDS, 1, 1},
  39. {IDS_HISTREE_TWODS, 2, 1},
  40. {IDS_HISTREE_TREDS, 3, 1},
  41. {IDS_HISTREE_FOUDS, 4, 1},
  42. {IDS_HISTREE_FIVDS, 5, 1},
  43. {IDS_HISTREE_SIXDS, 6, 1},
  44. {IDS_HISTREE_TWOWEKS, 14, 1},
  45. {IDS_HISTREE_ONEMON, 30, 1},
  46. {IDS_HISTREE_TWOMONS, 60, 1},
  47. {IDS_HISTREE_HALFYEA, 180, 1},
  48. {IDS_HISTREE_ONEYEA, 365, 1},
  49. {IDS_HISTREE_ALL, -1, 1},
  50. };
  51. //
  52. HTREEITEM hParent_r = this->InsertItem(_LoadString(IDS_RECVED_RECORD).GetBuffer(0), 3, 3);
  53. //HTREEITEM hParent_s = this->InsertItem(_LoadString(IDS_SNDED_RECORD).GetBuffer(0), 3, 3);
  54. this->SetItemData(hParent_r, 0);
  55. //this->SetItemData(hParent_s, 0);
  56. for(int i = 0; i < sizeofarray(nodes); ++i)
  57. {
  58. CString snode = _LoadString(nodes[i].nNodeTxtId);
  59. PHISTREEDATA pdata_r = new HISTREEDATA;
  60. *pdata_r = nodes[i];
  61. pdata_r->nItemType = 1;
  62. HTREEITEM hSub_r = this->InsertItem(snode, 4, 4, hParent_r);
  63. this->SetItemData(hSub_r, (DWORD)pdata_r);
  64. /*
  65. PHISTREEDATA pdata_s = new HISTREEDATA;
  66. *pdata_s = nodes[i];
  67. pdata_s->nItemType = 0;
  68. HTREEITEM hSub_s = this->InsertItem(snode, 4, 4, hParent_s);
  69. this->SetItemData(hSub_s, (DWORD)pdata_s);
  70. */
  71. }
  72. }
  73. void CTreeForHistory::ReleaseTree()
  74. {
  75. HTREEITEM hroot = this->GetRootItem();
  76. while(NULL != hroot)
  77. {
  78. PHISTREEDATA p = NULL;
  79. HTREEITEM hchild = this->GetNextItem(hroot, TVGN_CHILD);
  80. while(NULL != hchild)
  81. {
  82. p = (PHISTREEDATA)this->GetItemData(hchild);
  83. _DELETE(p);
  84. hchild = this->GetNextItem(hchild, TVGN_NEXT);
  85. }
  86. p = (PHISTREEDATA)this->GetItemData(hroot);
  87. _DELETE(p);
  88. hroot = this->GetNextItem(hroot, TVGN_NEXT);
  89. }
  90. }
  91. void CTreeForHistory::OnDestroy() 
  92. {
  93. this->ReleaseTree();
  94. CTreeCtrl::OnDestroy();
  95. }
  96. void CTreeForHistory::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  97. {
  98. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  99. *pResult = 0;
  100. PHISTREEDATA pdata = (PHISTREEDATA)this->GetItemData(pNMTreeView->itemNew.hItem);
  101. if(NULL == pdata || pNMTreeView->itemNew.hItem == pNMTreeView->itemOld.hItem) return ;
  102. CGuiRecordSet rs;
  103. char starttime[32], endtime[32], sql[MAX_SQL_SIZE];
  104. try
  105. {
  106. //////////////////////////////////////////////////////////////////////////
  107. CTime now = CTime::GetCurrentTime();
  108. _snprintf(starttime, sizeof(starttime), SYS_TIMEFORMAT,
  109.   now.GetYear(), now.GetMonth(), now.GetDay() - pdata->nLimitDays, 0, 0, 0);
  110. _snprintf(endtime, sizeof(endtime), SYS_TIMEFORMAT,
  111. now.GetYear(), now.GetMonth(), now.GetDay(), now.GetHour(), now.GetMinute(), now.GetSecond());
  112. switch(pdata->nItemType) {
  113. case 0:
  114. {
  115. _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_TRANS_TRANSHISTORY, 
  116. SQL::TRANSTYP_SNDER | SQL::TRANSTYP_SNDOK, starttime, endtime);
  117. }
  118. break;
  119. case 1:
  120. {
  121. _snprintf(sql, MAX_SQL_SIZE-1, SQL::CLIENT_TRANS_TRANSHISTORY, 
  122. SQL::TRANSTYP_RECOR | SQL::TRANSTYP_RECVOK, starttime, endtime);
  123. }
  124. break;
  125. }
  126. if(!rs.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
  127. {
  128. //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
  129. return ;
  130. }
  131. //////////////////////////////////////////////////////////////////////////
  132. CMainFrame *pmainfrm = (CMainFrame*)::AfxGetMainWnd();
  133. pmainfrm->m_pwndWorkFrame->m_pwndFileTransView->m_pwndHistoryView->AddHistoryFromRS(rs);
  134. rs.Close();
  135. }
  136. catch(...) 
  137. {
  138. }
  139. }