#include "StdAfx.h" #include "MBNewGroupWnd.h" CMBNewGroupWnd::CMBNewGroupWnd(void):SHostDialog(_T("LAYOUT:DLG_NEWGROUP")) { m_bLayoutInited = FALSE; m_pServerMgr = NULL; m_pMBOrgWnd = NULL ; m_bRenameGroup = FALSE; m_strGroupID = _T(""); m_strGroupName = _T(""); } CMBNewGroupWnd::~CMBNewGroupWnd(void) { } int CMBNewGroupWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { SetMsgHandled(FALSE); return 0; } BOOL CMBNewGroupWnd::OnInitDialog(HWND hWnd, LPARAM lParam) { m_bLayoutInited = TRUE; if(m_bRenameGroup) { SWindow *pWndTitle = FindChildByName2(_T("txt_title")); if( pWndTitle ){ pWndTitle->SetWindowText(_T("¸ü¸Ä×éÃû")); } SWindow *pWndButton = FindChildByName2(_T("btn_another")); if( pWndButton ){ pWndButton->SetVisible(false,true); } SEdit *pWndCatalogName = FindChildByName2(_T("ed_groupname")); if( pWndCatalogName ) { pWndCatalogName->SetWindowText(m_strGroupName); pWndCatalogName->SetSel(0, -1); pWndCatalogName->SetFocus(); } } else { SEdit *pWndCatalogName = FindChildByName2(_T("ed_groupname")); if( pWndCatalogName ){ pWndCatalogName->SetWindowText(_T("·Ö×é")); pWndCatalogName->SetSel(0, -1); pWndCatalogName->SetFocus(); } } return 0; } // ÔÙ´´½¨Ò»¸ö void CMBNewGroupWnd::OnBtnAnther() { if( !m_pServerMgr) return; CString strGroupName; CString strNewGroupName; SWindow *pWndGroupName = FindChildByName2(_T("ed_groupname")); if( pWndGroupName ) strGroupName = pWndGroupName->GetWindowText(); if(strGroupName.IsEmpty()) return; CMBOrgView *pView = NULL; m_pServerMgr->GetOrgListMgr()->LookupView(SUBVIEW_CONTACTSTOOT, pView); if( !pView) return; POSITION pos; CMBOrgMember *pMember = NULL; BOOL bSame = TRUE; int nItem = 1; strGroupName.Trim(); strNewGroupName = strGroupName; while(bSame ) { for ( pos = pView->m_listMember.GetHeadPosition(); pos; pos ) { pMember = (CMBOrgMember *)pView->m_listMember.GetNext( pos ); //if (pMember->m_strName.CompareNoCase(strNewGroupName) == 0) if (pMember->m_strName== strNewGroupName) { bSame = FALSE; break; } } if( bSame) break; strNewGroupName.Format(_T("%s(%d)"),strGroupName,nItem); nItem++; bSame = TRUE; } //if(bSame) //{ // CString strMessage; // strMessage.Format(_T("·Ö×éÖÐÒÑÓÐͬÃû×é¡®%s¡¯"),strNewGroupName); // MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); // return; //} CString strGroupID = _T(""); CString strNotExistUser; CString strErrInfo; CString strUserList; if( !m_pServerMgr->GetOrgWebCMgr()->CreateContactGroup(strNewGroupName,strGroupID,strNotExistUser,strErrInfo,strUserList)) { CString strMessage; strMessage.Format(_T("н¨·Ö×é¡®%s¡¯Ê§°Ü"),strNewGroupName); MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); return; } pView->AddMember(AM_VIEWITEMTYPE_CUSTGROUP,strGroupID,strNewGroupName); m_pServerMgr->GetOrgListMgr()->AddMember(AM_VIEWITEMTYPE_CUSTGROUP,strGroupID,strNewGroupName); if(m_pMBOrgWnd) m_pMBOrgWnd->AddContactGroup(strGroupID, strNewGroupName); } // È·¶¨ void CMBNewGroupWnd::OnBtnDetermine() { if( !m_pServerMgr) return; CString strGroupName; CString strNewGroupName; SWindow *pWndGroupName = FindChildByName2(_T("ed_groupname")); if( pWndGroupName ) strGroupName = pWndGroupName->GetWindowText(); if(strGroupName.IsEmpty()) return; CMBOrgView *pView = NULL; m_pServerMgr->GetOrgListMgr()->LookupView(SUBVIEW_CONTACTSTOOT, pView); if( !pView) return; POSITION pos; CMBOrgMember *pMember = NULL; BOOL bSame = TRUE; int nItem = 1; strGroupName.Trim(); strNewGroupName = strGroupName; if(m_bRenameGroup) { bSame = FALSE; if(m_strGroupName == strNewGroupName) { CString strMessage; strMessage.Format(_T("·Ö×éÖÐÒÑÓÐͬÃû×é¡®%s¡¯"),strNewGroupName); MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); return; } for ( pos = pView->m_listMember.GetHeadPosition(); pos; pos ) { pMember = (CMBOrgMember *)pView->m_listMember.GetNext( pos ); if (pMember->m_strName== strNewGroupName) { bSame = TRUE; break; } } if(bSame) { CString strMessage; strMessage.Format(_T("·Ö×éÖÐÒÑÓÐͬÃû×é¡®%s¡¯"),strNewGroupName); MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); return; } CString strErrInfo; if( !m_pServerMgr->GetOrgWebCMgr()->RenameContactGroup(m_strGroupID,strNewGroupName,strErrInfo)) { CString strMessage; strMessage.Format(_T("н¨·Ö×é¡®%s¡¯Ê§°Ü"),strNewGroupName); MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); return; } pMember = NULL; pos = pView->FindMember( AM_VIEWITEMTYPE_CUSTGROUP, m_strGroupID ); if ( pos ) pMember = (CMBOrgMember *)pView->m_listMember.GetAt( pos ); if(pMember) { pMember->m_strName = strNewGroupName; } CMBOrgGroup *pGroup = NULL; m_pServerMgr->GetOrgListMgr()->LookupGroup( m_strGroupID,pGroup ); if(pGroup) { pGroup->m_strName = strNewGroupName; } } else { while(bSame ) { bSame = FALSE; for ( pos = pView->m_listMember.GetHeadPosition(); pos; pos ) { pMember = (CMBOrgMember *)pView->m_listMember.GetNext( pos ); //if (pMember->m_strName.CompareNoCase(strNewGroupName) == 0) if (pMember->m_strName== strNewGroupName) { bSame = TRUE; break; } } if( !bSame) break; strNewGroupName.Format(_T("%s(%d)"),strGroupName,nItem); nItem++; } CString strGroupID = _T(""); CString strNotExistUser; CString strErrInfo; CString strUserList; if( !m_pServerMgr->GetOrgWebCMgr()->CreateContactGroup(strNewGroupName,strGroupID,strNotExistUser,strErrInfo,strUserList)) { CString strMessage; strMessage.Format(_T("н¨·Ö×é¡®%s¡¯Ê§°Ü"),strNewGroupName); MBMessageBox(m_hWnd,strMessage,_T("Ìáʾ"),MB_OK); return; } pView->AddMember(AM_VIEWITEMTYPE_CUSTGROUP,strGroupID,strNewGroupName); m_pServerMgr->GetOrgListMgr()->AddMember(AM_VIEWITEMTYPE_CUSTGROUP,strGroupID,strNewGroupName); if(m_pMBOrgWnd) m_pMBOrgWnd->AddContactGroup(strGroupID, strNewGroupName); } SHostDialog::OnOK(); } void CMBNewGroupWnd::SetServerMgrPtr( CMBServerMgr *pMBServerMgr ) { m_pServerMgr = pMBServerMgr; } void CMBNewGroupWnd::SetOrgWndtr( CMBAMOrgWnd *pMBAMWnd ) { m_pMBOrgWnd = pMBAMWnd ; } void CMBNewGroupWnd::SetRenameGroup(CString strGroupID,CString strGroupName) { m_strGroupID = strGroupID ; m_strGroupName = strGroupName ; m_bRenameGroup = TRUE; } void CMBNewGroupWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { SetMsgHandled(FALSE); // enter¼ü if(((::GetAsyncKeyState( VK_RETURN ) & 0x8000))) { OnBtnDetermine(); } }