419 lines
10 KiB
C++
419 lines
10 KiB
C++
// DLG_UserSelect.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "corpsms.h"
|
|
#include "DLG_UserSelect.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// DLG_UserSelect dialog
|
|
|
|
#include "MainFrm.h"
|
|
|
|
DLG_UserSelect::DLG_UserSelect(CWnd* pParent /*=NULL*/)
|
|
: CDialog(DLG_UserSelect::IDD, pParent)
|
|
, m_strName(_T(""))
|
|
{
|
|
//{{AFX_DATA_INIT(DLG_UserSelect)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_lUserID = -1;
|
|
m_strRoot = _T("ËùÓÐÈËÔ±");
|
|
m_bGroup = false;
|
|
|
|
m_strDB = _T("Users");
|
|
m_bShowUser = true;
|
|
|
|
m_lShowType = 0;
|
|
m_bFirstFind = true;
|
|
m_hSearched = NULL;
|
|
}
|
|
|
|
|
|
void DLG_UserSelect::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(DLG_UserSelect)
|
|
DDX_Control(pDX, IDC_USERSELECT_TREE, m_wndTree);
|
|
//}}AFX_DATA_MAP
|
|
DDX_Control(pDX, IDC_USERSELECT_NAME, m_wndName);
|
|
DDX_Text(pDX, IDC_USERSELECT_NAME, m_strName);
|
|
DDV_MaxChars(pDX, m_strName, 32);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(DLG_UserSelect, CDialog)
|
|
//{{AFX_MSG_MAP(DLG_UserSelect)
|
|
ON_NOTIFY(NM_DBLCLK, IDC_USERSELECT_TREE, OnDblclkUserselectTree)
|
|
//}}AFX_MSG_MAP
|
|
ON_BN_CLICKED(IDC_USERSELECT_NAME_S, &DLG_UserSelect::OnBnClickedUserselectNameS)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// DLG_UserSelect message handlers
|
|
|
|
void DLG_UserSelect::SetParam(CMainFrame *pFrame,CString strDB , CString strRoot,BOOL bShowUser)
|
|
{
|
|
m_pMainFrame = pFrame;
|
|
m_AdoRS.SetAdoConnection( &pFrame->m_adoConnection );
|
|
m_strDB = strDB;
|
|
m_bShowUser = bShowUser;
|
|
m_strRoot = strRoot;
|
|
}
|
|
|
|
long DLG_UserSelect::GetParam(CString & strUser)
|
|
{
|
|
strUser = m_strUser;
|
|
return m_lUserID;
|
|
}
|
|
|
|
BOOL DLG_UserSelect::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
//´´½¨Í¼ÏñÁбí
|
|
m_Image.Create( 20 , 20 , ILC_COLOR32|ILC_MASK , 5 , 1);
|
|
CBitmap bmp;
|
|
bmp.LoadBitmap( IDB_F_FOLDER );
|
|
m_Image.Add( &bmp , RGB(255,255,255) ); //Îļþ¼Ð
|
|
bmp.DeleteObject(); bmp.LoadBitmap( IDB_F_FOLDER_O );
|
|
m_Image.Add( &bmp , RGB(255,255,255) ); //Îļþ¼Ð-´ò¿ª
|
|
bmp.DeleteObject(); bmp.LoadBitmap( IDB_F_GADDRESS );
|
|
m_Image.Add( &bmp , RGB(255,255,255) ); //¹«ÓõØÖ·±¾
|
|
bmp.DeleteObject(); bmp.LoadBitmap( IDB_L_USER_NOR );
|
|
m_Image.Add( &bmp , RGB(193,193,193) ); //Óû§
|
|
|
|
m_strUser = m_strRoot;
|
|
|
|
m_wndTree.SetBkColor( RGB(180,213,170) );
|
|
m_wndTree.SetImageList(&m_Image, TVSIL_NORMAL );
|
|
m_MainItem = m_wndTree.InsertItem( m_strRoot , 2 , 2 );
|
|
m_wndTree.SetItemData( m_MainItem , -1 );
|
|
ShowGGroup( m_MainItem , _T("") );
|
|
m_wndTree.Expand(m_MainItem,TVE_EXPAND);
|
|
m_wndTree.SelectItem( m_MainItem );
|
|
|
|
|
|
if ( m_lShowType==1 )
|
|
{
|
|
this->SetWindowText(_T("ÇëÑ¡ÔñÐèÒª²éѯµÄÓû§"));
|
|
}
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
BOOL DLG_UserSelect::ShowGGroup(HTREEITEM hMainItem, TCHAR *pGroupID)
|
|
{
|
|
CAdoRecordSet AdoRS;
|
|
CAdoRecordSet AdoRS2;
|
|
AdoRS.SetAdoConnection( &m_pMainFrame->m_adoConnection );
|
|
AdoRS2.SetAdoConnection(&m_pMainFrame->m_adoConnection);
|
|
TCHAR szSelect[128]={0};
|
|
_stprintf( szSelect , _T("select * from %s where GroupID like '%s_' AND UserType='0' order by CreateTime") , m_strDB , pGroupID );
|
|
BOOL b = AdoRS.Open( szSelect );
|
|
long lCount = AdoRS.GetRecordCount();
|
|
if ( b && lCount )
|
|
{
|
|
AdoRS.MoveFirst();
|
|
while( !AdoRS.IsEOF() )
|
|
{
|
|
TCHAR szGroupID[16]={0};
|
|
TCHAR szName[16]={0};
|
|
long lUserID=0;
|
|
AdoRS.GetCollect( _T("GroupID") , szGroupID );
|
|
AdoRS.GetCollect( _T("Name") , szName );
|
|
AdoRS.GetCollect( _T("UserID") , lUserID );
|
|
HTREEITEM hItem = m_wndTree.InsertItem( szName , 0,1 , hMainItem );
|
|
m_wndTree.SetItemData( hItem , lUserID );
|
|
|
|
/*
|
|
if (m_bShowUser)
|
|
{
|
|
//ÏÔʾÍê×éÖ®ºó£¬ÏÔʾÓû§
|
|
if (_tcslen(szGroupID) <= 0)
|
|
{
|
|
_stprintf(szSelect, _T("select * from %s where GroupID = '' OR GroupID is NULL AND UserType='1' order by CreateTime "), m_strDB);
|
|
}
|
|
else
|
|
{
|
|
_stprintf(szSelect, _T("select * from %s where GroupID = '%s' AND UserType='1' order by CreateTime"), m_strDB, szGroupID);
|
|
}
|
|
b = AdoRS2.Open(szSelect);
|
|
lCount = AdoRS2.GetRecordCount();
|
|
if (b && lCount)
|
|
{
|
|
AdoRS2.MoveFirst();
|
|
while (!AdoRS2.IsEOF())
|
|
{
|
|
CString strShow;
|
|
CString strName;
|
|
CString strLoginName;
|
|
long lUserID = 0;
|
|
AdoRS2.GetCollect(_T("Name"), strName);
|
|
AdoRS2.GetCollect(_T("LoginName"), strLoginName);
|
|
AdoRS2.GetCollect(_T("UserID"), lUserID);
|
|
|
|
strShow.Format(_T("%s [%s]"), strName, strLoginName);
|
|
|
|
//if ( m_lShowType==1 ) //ÏÔʾÐÕÃû+ÊÖ»úºÅ
|
|
//{
|
|
// CString strMobile;
|
|
// AdoRS.GetCollect( _T("Mobile") , strMobile );
|
|
//
|
|
// CString strTemp;
|
|
// strTemp.Format( _T("%s[%s]") , szName , strMobile );
|
|
// _tcscpy(szName , strTemp);
|
|
//}
|
|
|
|
HTREEITEM hItem2 = m_wndTree.InsertItem(strShow, 3, 3, hItem);
|
|
m_wndTree.SetItemData(hItem2, lUserID);
|
|
AdoRS2.MoveNext();
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
ShowGGroup( hItem , szGroupID );
|
|
AdoRS.MoveNext();
|
|
}
|
|
}
|
|
|
|
if ( m_bShowUser )
|
|
{
|
|
//ÏÔʾÍê×éÖ®ºó£¬ÏÔʾÓû§
|
|
if ( _tcslen(pGroupID)<=0 )
|
|
{
|
|
_stprintf( szSelect , _T("select * from %s where GroupID = '' OR GroupID is NULL AND UserType='1' order by CreateTime "),m_strDB );
|
|
}
|
|
else
|
|
{
|
|
_stprintf( szSelect , _T("select * from %s where GroupID = '%s' AND UserType='1' order by CreateTime") ,m_strDB, pGroupID );
|
|
}
|
|
b = AdoRS.Open( szSelect );
|
|
lCount = AdoRS.GetRecordCount();
|
|
if ( b && lCount )
|
|
{
|
|
AdoRS.MoveFirst();
|
|
while( !AdoRS.IsEOF() )
|
|
{
|
|
CString strShow;
|
|
CString strName;
|
|
CString strLoginName;
|
|
long lUserID=0;
|
|
AdoRS.GetCollect( _T("Name") , strName);
|
|
AdoRS.GetCollect(_T("LoginName"), strLoginName);
|
|
AdoRS.GetCollect( _T("UserID") , lUserID );
|
|
|
|
strShow.Format(_T("%s [%s]"), strName, strLoginName);
|
|
|
|
//if ( m_lShowType==1 ) //ÏÔʾÐÕÃû+ÊÖ»úºÅ
|
|
//{
|
|
// CString strMobile;
|
|
// AdoRS.GetCollect( _T("Mobile") , strMobile );
|
|
//
|
|
// CString strTemp;
|
|
// strTemp.Format( _T("%s[%s]") , szName , strMobile );
|
|
// _tcscpy(szName , strTemp);
|
|
//}
|
|
|
|
HTREEITEM hItem = m_wndTree.InsertItem(strShow, 3,3 , hMainItem );
|
|
m_wndTree.SetItemData( hItem , lUserID );
|
|
AdoRS.MoveNext();
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void DLG_UserSelect::OnOK()
|
|
{
|
|
HTREEITEM hItem = m_wndTree.GetSelectedItem();
|
|
if ( !hItem )
|
|
{
|
|
MessageBox( _T("Äã±ØÐë´Ó×ó±ßµÄÊ÷×´ÁбíÖÐÑ¡ÔñÒ»¸ö²éѯ¶ÔÏó!"),_T("´íÎó"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
m_strUser = m_wndTree.GetItemText(hItem);
|
|
m_lUserID = m_wndTree.GetItemData(hItem);
|
|
int iImage=0;
|
|
int iSImage=0;
|
|
m_wndTree.GetItemImage(hItem,iImage,iSImage);
|
|
if ( iImage==0 || iImage== 2 )
|
|
m_bGroup = true;
|
|
else
|
|
m_bGroup = false;
|
|
|
|
//Éú³ÉÊ÷×´²éѯÓû§Ãû
|
|
CString strTemp;
|
|
HTREEITEM hParItem = m_wndTree.GetParentItem(hItem);
|
|
while (hParItem != NULL && hParItem != m_MainItem)
|
|
{
|
|
strTemp = m_wndTree.GetItemText(hParItem);
|
|
m_strUser = strTemp+"\\"+m_strUser;
|
|
hParItem = m_wndTree.GetParentItem(hParItem);
|
|
}
|
|
|
|
|
|
if ( m_lShowType==1 ) //ÏÔʾÐÕÃû+ÊÖ»úºÅ
|
|
{
|
|
if ( m_bGroup && m_lUserID!=-1 ) //Ö»ÄÜÑ¡ÔñÓû§£¬²»ÄÜÑ¡ÔñÓû§×é
|
|
{
|
|
MessageBox( _T("Äã±ØÐë´Ó×ó±ßµÄÊ÷×´ÁбíÖÐÑ¡ÔñÒ»¸öÓû§!"),_T("´íÎó"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
/*
|
|
//·Ö½âÐÕÃûÓëºÅÂë
|
|
CString strTemp= m_wndTree.GetItemText(hItem);;
|
|
long lBegin=0;
|
|
long lEnd=0;
|
|
lBegin=strTemp.Find(_T("["));
|
|
lEnd=strTemp.Find(_T("]"));
|
|
|
|
if ( lBegin>=0 )
|
|
m_strUser = strTemp.Left(lBegin);
|
|
|
|
if ( lEnd>lBegin )
|
|
{
|
|
m_strMobile =strTemp.Mid(lBegin+1,lEnd-lBegin-1);
|
|
}
|
|
|
|
if ( !::isMobileNum(m_strMobile , m_strMobile.GetLength()) )
|
|
{
|
|
MessageBox( _T("ËùÑ¡ÔñÒµÎñÔ±µÄÊÖ»úºÅÂë²»ÕýÈ·£¬ÇëÐÞÕý»òÖØÑ¡!"),_T("´íÎó"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
*/
|
|
}
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void DLG_UserSelect::OnDblclkUserselectTree(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
|
|
*pResult = 0;
|
|
|
|
OnOK();
|
|
}
|
|
|
|
void DLG_UserSelect::SetShowType(long lShowType)
|
|
{
|
|
m_lShowType =lShowType; //0-Ö»ÏÔʾÐÕÃû£¬1-ÏÔʾÐÕÃû+ÊÖ»úºÅÂë
|
|
|
|
}
|
|
|
|
|
|
BOOL DLG_UserSelect::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
//´Ë¾ÙÊÇΪÁËÓû§ÔÚÊäÈëºÅÂëʱ°´Á˻سµÈ»ºóתµ½ÊäÈëÄÚÈÝ
|
|
//¶¨Î»¿Í»§
|
|
if (pMsg->message == WM_KEYDOWN)
|
|
{
|
|
if (pMsg->wParam == VK_RETURN && pMsg->hwnd == m_wndName)
|
|
{
|
|
SearchItem();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
m_bFirstFind = true; //Ö»ÒªÊäÈëÁ˷ǻسµ£¬¶¼Êǵ±ÖØÐÂËÑË÷
|
|
}
|
|
}
|
|
|
|
return CDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
BOOL DLG_UserSelect::SearchItem(void)
|
|
{
|
|
CString strName;
|
|
m_wndName.GetWindowText(strName);
|
|
if (strName.GetLength() <= 0)
|
|
{
|
|
MessageBox(_T("ÇëÊäÈëÐèÒª²éѯµÄ¹Ø¼ü×Ö£¡"),_T("´íÎó"), MB_ICONWARNING);
|
|
m_wndName.SetFocus();
|
|
return false;
|
|
}
|
|
HTREEITEM hItem = m_wndTree.GetSelectedItem();
|
|
if (hItem == NULL) //Èç¹ûµ±Ç°Ñ¡ÔñΪ¿Õ£¬Ï൱ÓÚÖØÐ¿ªÊ¼ËÑË÷
|
|
{
|
|
m_bFirstFind = true;
|
|
m_hSearched = NULL;
|
|
}
|
|
|
|
HTREEITEM hItem2;
|
|
if (m_bFirstFind) //ÖØÐÂËÑË÷
|
|
{
|
|
m_ASearch.RemoveAll();
|
|
hItem2 = FindItemName(m_MainItem, strName,NULL);
|
|
m_bFirstFind = false; //²»ÊÇÖØÐÂËÑË÷ÁË¡£
|
|
}
|
|
else
|
|
{
|
|
hItem2 = FindItemName(m_MainItem, strName, m_hSearched);
|
|
}
|
|
if (hItem2)
|
|
{
|
|
m_hSearched = hItem2;
|
|
m_wndTree.SelectItem(hItem2);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
CString str;
|
|
str.Format(_T("ËÑË÷¹Ø¼ü×Ö:%s£¬Òѵ½Ä©Î²¡£"), strName);
|
|
MessageBox(str,_T("ÐÅÏ¢") , MB_ICONINFORMATION);
|
|
m_bFirstFind = true; //ÖØÐ¿ªÊ¼ËÑË÷
|
|
m_ASearch.RemoveAll();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
HTREEITEM DLG_UserSelect::FindItemName(HTREEITEM hNodeItem, CString strName, HTREEITEM hSearched)
|
|
{
|
|
CString strItemName = m_wndTree.GetItemText(hNodeItem);
|
|
if (strItemName.MakeUpper().Find(strName.MakeUpper()) >= 0)
|
|
{
|
|
long lUserID = m_wndTree.GetItemData(hNodeItem);
|
|
long lLength = m_ASearch.GetCount();
|
|
for (int i = 0; i < lLength; i++)
|
|
{
|
|
if (lUserID == m_ASearch.GetAt(i))
|
|
break;
|
|
}
|
|
if (i >= lLength) //ûÓÐÕÒ¹ýµÄ£¬·µ»Ø
|
|
{
|
|
m_ASearch.Add(lUserID);
|
|
return hNodeItem;
|
|
}
|
|
}
|
|
|
|
//ÏÈËÑ×Ó½Úµã
|
|
HTREEITEM hCurItem = m_wndTree.GetChildItem(hNodeItem);//µÃµ½µ±Ç°½ÚµãµÄµÚÒ»¸ö×Ó½ÚµãµÄ¾ä±ú
|
|
|
|
HTREEITEM hNextItem=NULL;
|
|
|
|
while (hCurItem != NULL)
|
|
{
|
|
hNextItem = hCurItem;
|
|
HTREEITEM hItem2 = FindItemName(hNextItem, strName, hSearched);
|
|
if (hItem2 != NULL)
|
|
{
|
|
return hItem2;
|
|
}
|
|
hCurItem = m_wndTree.GetNextSiblingItem(hCurItem);//µÃµ½µ±Ç°½ÚµãµÄÐֵܽڵãµÄ¾ä±ú
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void DLG_UserSelect::OnBnClickedUserselectNameS()
|
|
{
|
|
SearchItem();
|
|
}
|