SendGroupMgr.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:7k
- // SendGroupMgr.cpp : implementation file
- #include "stdafx.h"
- #include "trfAgent.h"
- #include "SendGroupMgr.h"
- #include "SndGrpRenameDlg.h"
- /////////////////////////////////////////////////////////////////////////////
- CSendGroupMgr::CSendGroupMgr(CWnd* pParent /*=NULL*/)
- : CDialog(CSendGroupMgr::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSendGroupMgr)
- //}}AFX_DATA_INIT
- }
- void CSendGroupMgr::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSendGroupMgr)
- DDX_Control(pDX, IDC_TREEUSRGRP, m_wndTreeGrpUsrs);
- DDX_Control(pDX, IDC_TREEORG, m_wndTreeOrg);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSendGroupMgr, CDialog)
- //{{AFX_MSG_MAP(CSendGroupMgr)
- ON_BN_CLICKED(IDC_BTNADDGRP, OnBtnaddgrp)
- ON_BN_CLICKED(IDC_BTNDELGRP, OnBtndelgrp)
- ON_BN_CLICKED(IDC_BTNRENAMEGRP, OnBtnrenamegrp)
- ON_BN_CLICKED(IDC_BTNRIGHT, OnBtnright)
- ON_BN_CLICKED(IDC_BTNLEFT, OnBtnleft)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREEUSRGRP, OnSelchangedTreeusrgrp)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREEORG, OnSelchangedTreeorg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- BOOL CSendGroupMgr::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- this->m_wndTreeOrg.UpdateTreeForUserDatas();
- this->m_wndTreeGrpUsrs.UpdateTreeForUserDatas();
- this->CenterWindow(NULL);
-
- return TRUE;
- }
- void CSendGroupMgr::OnBtnaddgrp()
- {
- CSndGrpRenameDlg dlg;
- if(dlg.DoModal() == IDOK)
- {
- if(!this->m_wndTreeGrpUsrs.AddGroup(dlg.m_sGroupName.GetBuffer(0)))
- {
- MSGBOX_ERROR(_LoadString(IDS_SNDGRP_ADDFAIL).GetBuffer(0));
- }
- }
- }
- void CSendGroupMgr::OnBtndelgrp()
- {
- //////////////////////////////////////////////////////////////////////////
-
- HTREEITEM hitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
- if(hitem == NULL)
- {
- MSGBOX_INFO(_LoadString(IDS_NOSELECTNODE).GetBuffer(0));
- return ;
- }
- DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hitem);
- //////////////////////////////////////////////////////////////////////////
-
- if(!this->m_wndTreeGrpUsrs.DelGroup(LOWORD(dwdata)))
- {
- MSGBOX_ERROR(_LoadString(IDS_SNDGRP_DELFAIL).GetBuffer(0));
- }
- }
- void CSendGroupMgr::OnBtnrenamegrp()
- {
- //////////////////////////////////////////////////////////////////////////
-
- HTREEITEM hitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
- if(hitem != NULL)
- {
- MSGBOX_INFO(_LoadString(IDS_NOSELECTNODE).GetBuffer(0));
- return ;
- }
-
- DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hitem);
-
- //////////////////////////////////////////////////////////////////////////
- CSndGrpRenameDlg dlg;
- if(dlg.DoModal() == IDOK)
- {
- if(!this->m_wndTreeGrpUsrs.RenameGroup(LOWORD(dwdata), dlg.m_sGroupName.GetBuffer(0)))
- {
- MSGBOX_ERROR(_LoadString(IDS_SNDGRP_RENAMEFAIL).GetBuffer(0));
- }
- else
- {
- this->m_wndTreeGrpUsrs.SetItemText(hitem, dlg.m_sGroupName.GetBuffer(0));
- }
- }
- }
- void CSendGroupMgr::OnBtnright()
- {
- HTREEITEM hdestitem = this->m_wndTreeGrpUsrs.GetSelectedItem();
- DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(hdestitem);
- if(HIWORD(dwdata) == NT_AGENT) hdestitem = this->m_wndTreeGrpUsrs.GetParentItem(hdestitem);
-
- //////////////////////////////////////////////////////////////////////////
-
- HTREEITEM hparent = this->m_wndTreeOrg.GetFirstVisibleItem();
-
- for(; hparent != NULL; )
- {
- BOOL parentchecked = this->m_wndTreeOrg.GetCheck(hparent);
-
- HTREEITEM hchild = this->m_wndTreeOrg.GetNextItem(hparent, TVGN_CHILD);
- for(; hchild != NULL; )
- {
- BOOL bselected = TRUE, bexists = FALSE;
- CString stext = this->m_wndTreeOrg.GetItemText(hchild);
- DWORD dws = this->m_wndTreeOrg.GetItemData(hchild);
- if(!parentchecked)
- {
- if(!this->m_wndTreeOrg.GetCheck(hchild)) bselected = FALSE;
- }
- //////////////////////////////////////////////////////////////////////////
-
- //determine the child whether or not exists in the parent node.
- if(bselected)
- {
- HTREEITEM hsub = this->m_wndTreeGrpUsrs.GetNextItem(hdestitem, TVGN_CHILD);
- for(; hsub != NULL; )
- {
- if(dws == this->m_wndTreeGrpUsrs.GetItemData(hsub))
- {
- bexists = TRUE;
- break;
- }
- hsub = this->m_wndTreeGrpUsrs.GetNextItem(hsub, TVGN_NEXT);
- }
- }
- //////////////////////////////////////////////////////////////////////////
-
- if(bselected && !bexists && this->m_wndTreeGrpUsrs.AddGroupUser(LOWORD(dwdata), LOWORD(dws)))
- {
- HTREEITEM hnewitem = this->m_wndTreeGrpUsrs.InsertItem(stext.GetBuffer(0), 1, 1, hdestitem);
- this->m_wndTreeGrpUsrs.SetItemData(hnewitem, dws);
- this->m_wndTreeOrg.SetCheck(hchild, TRUE);
- }
- hchild = this->m_wndTreeOrg.GetNextItem(hchild, TVGN_NEXT);
- }
- hparent = this->m_wndTreeOrg.GetNextSiblingItem(hparent);
- }
- }
- void CSendGroupMgr::OnBtnleft()
- {
- HTREEITEM hdestitem = this->m_wndTreeOrg.GetSelectedItem();
- DWORD dwdata = this->m_wndTreeOrg.GetItemData(hdestitem);
-
- if(HIWORD(dwdata) == NT_AGENT) hdestitem = this->m_wndTreeOrg.GetParentItem(hdestitem);
-
- //////////////////////////////////////////////////////////////////////////
-
- HTREEITEM hitem = NULL, hparent = this->m_wndTreeGrpUsrs.GetFirstVisibleItem();
-
- for(; hparent != NULL; )
- {
- BOOL parentchecked = this->m_wndTreeGrpUsrs.GetCheck(hparent);
-
- HTREEITEM hchild = this->m_wndTreeGrpUsrs.GetNextItem(hparent, TVGN_CHILD);
- for(; hchild != NULL; )
- {
- hitem = hchild;
- BOOL bselected = TRUE;
- CString stext = this->m_wndTreeGrpUsrs.GetItemText(hchild);
- DWORD dws = this->m_wndTreeGrpUsrs.GetItemData(hchild);
-
- hchild = this->m_wndTreeGrpUsrs.GetNextItem(hchild, TVGN_NEXT);
-
- if(!parentchecked)
- {
- if(!this->m_wndTreeGrpUsrs.GetCheck(hitem)) bselected = FALSE;
- }
- if(bselected && this->m_wndTreeGrpUsrs.DelGroupUser(LOWORD(dwdata), LOWORD(dws)))
- {
- this->m_wndTreeGrpUsrs.DeleteItem(hitem);
- }
- }
- hparent = this->m_wndTreeGrpUsrs.GetNextSiblingItem(hparent);
- }
- }
- void CSendGroupMgr::OnSelchangedTreeorg(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- BOOL benable = FALSE;
-
- if(pNMTreeView->itemNew.hItem != NULL)
- benable = TRUE;
-
- CWnd *pwnd = this->GetDlgItem(IDC_BTNRIGHT);
- pwnd->EnableWindow(benable);
-
- *pResult = 0;
- }
- void CSendGroupMgr::OnSelchangedTreeusrgrp(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- BOOL benable = FALSE;
-
- if(pNMTreeView->itemNew.hItem != NULL)
- benable = TRUE;
-
- DWORD dwdata = this->m_wndTreeGrpUsrs.GetItemData(pNMTreeView->itemNew.hItem);
- CWnd *pwnd = this->GetDlgItem(IDC_BTNRIGHT);
- pwnd->EnableWindow(benable);
-
- pwnd = this->GetDlgItem(IDC_BTNLEFT);
- pwnd->EnableWindow(benable);
-
- pwnd = this->GetDlgItem(IDC_BTNADDGRP);
- pwnd->EnableWindow(benable);
- pwnd = this->GetDlgItem(IDC_BTNDELGRP);
- pwnd->EnableWindow(benable && HIWORD(dwdata) == NT_DEPART);
- pwnd = this->GetDlgItem(IDC_BTNRENAMEGRP);
- pwnd->EnableWindow(benable && HIWORD(dwdata) == NT_DEPART);
- *pResult = 0;
- }