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

网格计算

开发平台:

Visual C++

  1. // SendGroupMgr.cpp : implementation file
  2. #include "stdafx.h"
  3. #include "trfAgent.h"
  4. #include "SendGroupMgr.h"
  5. #include "SndGrpRenameDlg.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. CSendGroupMgr::CSendGroupMgr(CWnd* pParent /*=NULL*/)
  8. : CDialog(CSendGroupMgr::IDD, pParent)
  9. {
  10. //{{AFX_DATA_INIT(CSendGroupMgr)
  11. //}}AFX_DATA_INIT
  12. }
  13. void CSendGroupMgr::DoDataExchange(CDataExchange* pDX)
  14. {
  15. CDialog::DoDataExchange(pDX);
  16. //{{AFX_DATA_MAP(CSendGroupMgr)
  17. DDX_Control(pDX, IDC_TREEUSRGRP, m_wndTreeGrpUsrs);
  18. DDX_Control(pDX, IDC_TREEORG, m_wndTreeOrg);
  19. //}}AFX_DATA_MAP
  20. }
  21. BEGIN_MESSAGE_MAP(CSendGroupMgr, CDialog)
  22. //{{AFX_MSG_MAP(CSendGroupMgr)
  23. ON_BN_CLICKED(IDC_BTNADDGRP, OnBtnaddgrp)
  24. ON_BN_CLICKED(IDC_BTNDELGRP, OnBtndelgrp)
  25. ON_BN_CLICKED(IDC_BTNRENAMEGRP, OnBtnrenamegrp)
  26. ON_BN_CLICKED(IDC_BTNRIGHT, OnBtnright)
  27. ON_BN_CLICKED(IDC_BTNLEFT, OnBtnleft)
  28. ON_NOTIFY(TVN_SELCHANGED, IDC_TREEUSRGRP, OnSelchangedTreeusrgrp)
  29. ON_NOTIFY(TVN_SELCHANGED, IDC_TREEORG, OnSelchangedTreeorg)
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. BOOL CSendGroupMgr::OnInitDialog() 
  34. {
  35. CDialog::OnInitDialog();
  36. this->m_wndTreeOrg.UpdateTreeForUserDatas();
  37. this->m_wndTreeGrpUsrs.UpdateTreeForUserDatas();
  38. this->CenterWindow(NULL);
  39. return TRUE;
  40. }
  41. void CSendGroupMgr::OnBtnaddgrp() 
  42. {
  43. CSndGrpRenameDlg dlg;
  44. if(dlg.DoModal() == IDOK)
  45. {
  46. if(!this->m_wndTreeGrpUsrs.AddGroup(dlg.m_sGroupName.GetBuffer(0)))
  47. {
  48. MSGBOX_ERROR(_LoadString(IDS_SNDGRP_ADDFAIL).GetBuffer(0));
  49. }
  50. }
  51. }
  52. void CSendGroupMgr::OnBtndelgrp() 
  53. {
  54. //////////////////////////////////////////////////////////////////////////
  55. HTREEITEM hitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
  56. if(hitem == NULL)
  57. {
  58. MSGBOX_INFO(_LoadString(IDS_NOSELECTNODE).GetBuffer(0));
  59. return ;
  60. }
  61. DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hitem);
  62. //////////////////////////////////////////////////////////////////////////
  63. if(!this->m_wndTreeGrpUsrs.DelGroup(LOWORD(dwdata)))
  64. {
  65. MSGBOX_ERROR(_LoadString(IDS_SNDGRP_DELFAIL).GetBuffer(0));
  66. }
  67. }
  68. void CSendGroupMgr::OnBtnrenamegrp() 
  69. {
  70. //////////////////////////////////////////////////////////////////////////
  71. HTREEITEM hitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
  72. if(hitem != NULL)
  73. {
  74. MSGBOX_INFO(_LoadString(IDS_NOSELECTNODE).GetBuffer(0));
  75. return ;
  76. }
  77. DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hitem);
  78. //////////////////////////////////////////////////////////////////////////
  79. CSndGrpRenameDlg dlg;
  80. if(dlg.DoModal() == IDOK)
  81. {
  82. if(!this->m_wndTreeGrpUsrs.RenameGroup(LOWORD(dwdata), dlg.m_sGroupName.GetBuffer(0)))
  83. {
  84. MSGBOX_ERROR(_LoadString(IDS_SNDGRP_RENAMEFAIL).GetBuffer(0));
  85. }
  86. else
  87. {
  88. this->m_wndTreeGrpUsrs.SetItemText(hitem, dlg.m_sGroupName.GetBuffer(0));
  89. }
  90. }
  91. }
  92. void CSendGroupMgr::OnBtnright() 
  93. {
  94. HTREEITEM hdestitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
  95. DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hdestitem);
  96. if(HIWORD(dwdata) == NT_AGENT) hdestitem = this->m_wndTreeGrpUsrs.GetParentItem(hdestitem);
  97. //////////////////////////////////////////////////////////////////////////
  98. HTREEITEM hparent = this->m_wndTreeOrg.GetFirstVisibleItem();
  99. for(; hparent != NULL; )
  100. {
  101. BOOL parentchecked = this->m_wndTreeOrg.GetCheck(hparent);
  102. HTREEITEM hchild = this->m_wndTreeOrg.GetNextItem(hparent, TVGN_CHILD);
  103. for(; hchild != NULL; )
  104. {
  105. BOOL bselected = TRUE, bexists = FALSE;
  106. CString stext = this->m_wndTreeOrg.GetItemText(hchild);
  107. DWORD dws = this->m_wndTreeOrg.GetItemData(hchild);
  108. if(!parentchecked)
  109. {
  110. if(!this->m_wndTreeOrg.GetCheck(hchild)) bselected = FALSE;
  111. }
  112. //////////////////////////////////////////////////////////////////////////
  113. //determine the child whether or not exists in the parent node.
  114. if(bselected)
  115. {
  116. HTREEITEM hsub = this->m_wndTreeGrpUsrs.GetNextItem(hdestitem, TVGN_CHILD);
  117. for(; hsub != NULL; )
  118. {
  119. if(dws == this->m_wndTreeGrpUsrs.GetItemData(hsub))
  120. {
  121. bexists = TRUE;
  122. break;
  123. }
  124. hsub = this->m_wndTreeGrpUsrs.GetNextItem(hsub, TVGN_NEXT);
  125. }
  126. }
  127. //////////////////////////////////////////////////////////////////////////
  128. if(bselected && !bexists && this->m_wndTreeGrpUsrs.AddGroupUser(LOWORD(dwdata), LOWORD(dws)))
  129. {
  130. HTREEITEM hnewitem = this->m_wndTreeGrpUsrs.InsertItem(stext.GetBuffer(0), 1, 1, hdestitem);
  131. this->m_wndTreeGrpUsrs.SetItemData(hnewitem, dws);
  132. this->m_wndTreeOrg.SetCheck(hchild, TRUE);
  133. }
  134. hchild = this->m_wndTreeOrg.GetNextItem(hchild, TVGN_NEXT);
  135. }
  136. hparent = this->m_wndTreeOrg.GetNextSiblingItem(hparent);
  137. }
  138. }
  139. void CSendGroupMgr::OnBtnleft() 
  140. {
  141. HTREEITEM hdestitem = this->m_wndTreeOrg.GetSelectedItem();
  142. DWORD dwdata = this->m_wndTreeOrg.GetItemData(hdestitem);
  143. if(HIWORD(dwdata) == NT_AGENT) hdestitem = this->m_wndTreeOrg.GetParentItem(hdestitem);
  144. //////////////////////////////////////////////////////////////////////////
  145. HTREEITEM hitem = NULL, hparent = this->m_wndTreeGrpUsrs.GetFirstVisibleItem();
  146. for(; hparent != NULL; )
  147. {
  148. BOOL parentchecked = this->m_wndTreeGrpUsrs.GetCheck(hparent);
  149. HTREEITEM hchild = this->m_wndTreeGrpUsrs.GetNextItem(hparent, TVGN_CHILD);
  150. for(; hchild != NULL; )
  151. {
  152. hitem = hchild;
  153. BOOL bselected = TRUE;
  154. CString stext = this->m_wndTreeGrpUsrs.GetItemText(hchild);
  155. DWORD dws = this->m_wndTreeGrpUsrs.GetItemData(hchild);
  156. hchild = this->m_wndTreeGrpUsrs.GetNextItem(hchild, TVGN_NEXT);
  157. if(!parentchecked)
  158. {
  159. if(!this->m_wndTreeGrpUsrs.GetCheck(hitem)) bselected = FALSE;
  160. }
  161. if(bselected && this->m_wndTreeGrpUsrs.DelGroupUser(LOWORD(dwdata), LOWORD(dws)))
  162. {
  163. this->m_wndTreeGrpUsrs.DeleteItem(hitem);
  164. }
  165. }
  166. hparent = this->m_wndTreeGrpUsrs.GetNextSiblingItem(hparent);
  167. }
  168. }
  169. void CSendGroupMgr::OnSelchangedTreeorg(NMHDR* pNMHDR, LRESULT* pResult) 
  170. {
  171. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  172. BOOL benable = FALSE;
  173. if(pNMTreeView->itemNew.hItem != NULL)
  174. benable = TRUE;
  175. CWnd *pwnd = this->GetDlgItem(IDC_BTNRIGHT);
  176. pwnd->EnableWindow(benable);
  177. *pResult = 0;
  178. }
  179. void CSendGroupMgr::OnSelchangedTreeusrgrp(NMHDR* pNMHDR, LRESULT* pResult) 
  180. {
  181. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  182. BOOL benable = FALSE;
  183. if(pNMTreeView->itemNew.hItem != NULL)
  184. benable = TRUE;
  185. DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(pNMTreeView->itemNew.hItem);
  186. CWnd *pwnd = this->GetDlgItem(IDC_BTNRIGHT);
  187. pwnd->EnableWindow(benable);
  188. pwnd = this->GetDlgItem(IDC_BTNLEFT);
  189. pwnd->EnableWindow(benable);
  190. pwnd = this->GetDlgItem(IDC_BTNADDGRP);
  191. pwnd->EnableWindow(benable);
  192. pwnd = this->GetDlgItem(IDC_BTNDELGRP);
  193. pwnd->EnableWindow(benable && HIWORD(dwdata) == NT_DEPART);
  194. pwnd = this->GetDlgItem(IDC_BTNRENAMEGRP);
  195. pwnd->EnableWindow(benable && HIWORD(dwdata) == NT_DEPART);
  196. *pResult = 0;
  197. }