// K_BBS.cpp : implementation file
//

#include "stdafx.h"
#include "smsmanager.h"
#include "K_BBS.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CK_BBS dialog
#include "MainFrm.h"
#include "ProcessSocket.h"
#include "DLG_BBS_See.h"
#include "DLG_BBS_Send.h"

CK_BBS::CK_BBS(CWnd* pParent /*=NULL*/)
	: CDialog(CK_BBS::IDD, pParent)
{
	//{{AFX_DATA_INIT(CK_BBS)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bInit = false;
	m_bRefresh = false;
}


void CK_BBS::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CK_BBS)
	DDX_Control(pDX, IDC_BBS_LIST, m_wndList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CK_BBS, CDialog)
	//{{AFX_MSG_MAP(CK_BBS)
	ON_WM_SIZE()
	ON_NOTIFY(NM_DBLCLK, IDC_BBS_LIST, OnDblclkBbsList)
	ON_NOTIFY(NM_RCLICK, IDC_BBS_LIST, OnRclickBbsList)
	ON_NOTIFY(LVN_KEYDOWN, IDC_BBS_LIST, OnKeydownBbsList)
	//}}AFX_MSG_MAP
	ON_COMMAND( MENU_BBS_ADD , On_BBS_Add )
	ON_COMMAND( MENU_BBS_SEE , On_BBS_See )
	ON_COMMAND( MENU_BBS_DEL , On_BBS_Del )
	ON_COMMAND( MENU_BBS_REMSG , On_BBS_ReMsg )
	ON_COMMAND( MENU_BBS_REFRESH , On_BBS_Refresh )
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CK_BBS message handlers

BOOL CK_BBS::RefreshInfo()
{
	if ( !m_pMainFrame->GetUserPurview(PURVIEW_LIST) )
	{
		return false;
	}
	m_pMainFrame->SendFrame(SMSFUNC_AGENT_NAME,NULL,0);   //ȡ������Ϣ
	m_pMainFrame->SendFrame(SMSFUNC_YWY_NAME,NULL,0);   //ȡ������Ϣ

	return true;
}

void CK_BBS::Close()
{
	Close_BBS();
	Close_Agent();
	Close_YWY();
}

BOOL CK_BBS::ReHide()
{
	ShowWindow( SW_HIDE );
	return true;
}

BOOL CK_BBS::ReShow(BOOL bRefresh)
{
	ShowWindow( SW_SHOW );
	if ( bRefresh || !m_bRefresh )
	{
		RefreshInfo();
	}
	return true;
}

BOOL CK_BBS::ProcessSocket(Socket_Head *pHead)
{
	
	//ȡ��������Ϣ
	if (pHead->lFuncType == SMSFUNC_AGENT_NAME)
	{
		ANS_Agent_Name     * pAgent = (ANS_Agent_Name *)pHead->pFrame;
		ANS_Agent_NameData * pData = (ANS_Agent_NameData *)(pHead->pFrame+sizeof(ANS_Agent_Name));
		this->Close_Agent();
		for ( int i=0;i<pAgent->lCount;i++ )
		{
			ANS_Agent_NameData * pNewData = new ANS_Agent_NameData;
			*pNewData = *pData;
			m_Agent.AddTail(pNewData);
			pData ++;
		}
		On_BBS_Refresh();
		return true;
	}
	//ȡҵ��Ա��Ϣ
	if (pHead->lFuncType == SMSFUNC_YWY_NAME)
	{
		ANS_YWY_Name     * pYWY = (ANS_YWY_Name *)pHead->pFrame;
		ANS_YWY_NameData * pData = (ANS_YWY_NameData *)(pHead->pFrame+sizeof(ANS_YWY_Name));
		this->Close_YWY();
		for ( int i=0;i<pYWY->lCount;i++ )
		{
			ANS_YWY_NameData * pNewData = new ANS_YWY_NameData;
			*pNewData = *pData;
			m_YWY.AddTail(pNewData);
			pData ++;
		}
		return true;
	}
	//ȡ������Ϣ
	if (pHead->lFuncType == SMSFUNC_BBS_SEE)
	{
		m_bRefresh = true;  //�Ѿ�ˢ�¹�
		ANS_BBS_See     * pSee = (ANS_BBS_See *)pHead->pFrame;
		ANS_BBS_SeeData * pData = (ANS_BBS_SeeData *)(pHead->pFrame+sizeof(ANS_BBS_See));
		m_wndList.ShowWindow( SW_HIDE );
		m_wndList.DeleteAllItems(); //ɾ��ԭ�е�����
		this->Close_BBS();              //�ر�ԭ����
		TCHAR Buf[128];
		for ( int i=0;i<pSee->lCount;i++ )
		{
			ANS_BBS_SeeData * pNewData = new ANS_BBS_SeeData;
			*pNewData = *pData;
			POSITION pos = m_BBS.AddTail(pNewData);

			//m_wndList.SetHeadings(_T("���,50;״̬,60;    ������,180;   ������,120;����ʱ��,90; ����,90;     ����,180"));
			
			_stprintf(Buf , _T("%d") , pSee->lCount-i );
			long lIcon = 0;
			if ( pData->lAgentID>100 && pData->bAgentYJ )
				lIcon = 2;
			if ( pData->lAgentID>100 && !pData->bAgentYJ )
				lIcon = 1;
			m_wndList.InsertItem( i , Buf ,lIcon );
			m_wndList.SetItemData( i , (DWORD)pos );    //��Pos


			if ( pData->lSCorpID != 0 )
			{
				COleDateTime t(pData->tExpTime);
				if ( t.GetStatus()==0 )
				{
					if ( COleDateTime(pData->tExpTime) - COleDateTime(pData->tSendTime) > BBS_PROCESS_TIMEOUT )
					{
						m_wndList.SetItemText(i,1,_T("�Ѵ���(����)"));
					}
					else
					{
						m_wndList.SetItemText(i,1,_T("�Ѵ���"));
					}
				}
				else
				{
					if ( COleDateTime::GetCurrentTime() - COleDateTime(pData->tSendTime) > BBS_PROCESS_TIMEOUT )
					{
						m_wndList.SetItemText(i,1,_T("���(����)"));
					}
					else
					{
						m_wndList.SetItemText(i,1,_T("���"));
					}
				}
			}
			else
			{
				m_wndList.SetItemText(i,1,_T("--"));
			}

			if ( pData->lSCorpID == 0 )
				_stprintf(Buf, _T("����Ա->%s") , pData->szSLoginName);
			else
				if ( pData->lSCorpID == -1 )
					_stprintf(Buf, _T("����"));
				else
					_stprintf(Buf, _T("%d->%d(%s->%s)") ,pData->lSCorpID,pData->lSUserID,pData->szSCorpName,pData->szSLoginName);
			m_wndList.SetItemText(i,2,Buf);

			if ( pData->lRCorpID == 0 )
				_stprintf(Buf, _T("����Ա->%d") , pData->lRUserID);
			else
				if ( pData->lRCorpID == -1 )
					_stprintf(Buf, _T("����"));
				else
					_stprintf(Buf, _T("%d->%d") , pData->lRCorpID,pData->lRUserID);

			m_wndList.SetItemText(i,3,Buf);

			//_stprintf(Buf, _T(" %d") , pData->lRAgentID);
			CString strAgent = FindAgent(pData->lAgentID);
			CString strYWY = FindYWY(pData->lYWYID);
			_stprintf(Buf, _T("%s-%s") , strAgent,strYWY);

			m_wndList.SetItemText(i,4,Buf);


			_stprintf(Buf, _T("%04d.%02d.%02d") , pData->tSendTime.wYear,pData->tSendTime.wMonth,pData->tSendTime.wDay);
			m_wndList.SetItemText(i,5,Buf);

			m_wndList.SetItemText(i,6,pData->szType);
			m_wndList.SetItemText(i,7,pData->szBZ);

			pData ++;
		}
		m_wndList.ShowWindow( SW_SHOW );
		return true;
	}

	if (pHead->lFuncType == SMSFUNC_BBS_SEND)
	{
		if ( !m_bRefresh )  //��δˢ�£�������ʾ
			return true;

		ANS_BBS_Send * pAdd = (ANS_BBS_Send *)pHead->pFrame;
		ANS_BBS_SeeData * pData = (ANS_BBS_SeeData *)(pHead->pFrame+sizeof(ANS_BBS_Send));

		if ( pAdd->lCount == 1 )  //����1ʱ��ʾ�޸ijɹ�
		{
			long lCount = m_wndList.GetItemCount();
			//�����µ�����
			TCHAR Buf[32];
			_stprintf( Buf, _T("%d") , lCount +1 );
			m_wndList.InsertItem( 0 , Buf , pData->lStatus );


			if ( pData->lSCorpID != 0 )
			{
				COleDateTime t(pData->tExpTime);
				if ( t.GetStatus()==0 )
				{
					if ( COleDateTime(pData->tExpTime) - COleDateTime(pData->tSendTime) > BBS_PROCESS_TIMEOUT )
					{
						m_wndList.SetItemText(0,1,_T("�Ѵ���(����)"));
					}
					else
					{
						m_wndList.SetItemText(0,1,_T("�Ѵ���"));
					}
				}
				else
				{
					if ( COleDateTime::GetCurrentTime() - COleDateTime(pData->tSendTime) > BBS_PROCESS_TIMEOUT )
					{
						m_wndList.SetItemText(0,1,_T("���(����)"));
					}
					else
					{
						m_wndList.SetItemText(0,1,_T("���"));
					}
				}
			}
			else
			{
				m_wndList.SetItemText(0,1,_T("--"));
			}

			if ( pData->lSCorpID == 0 )
				_stprintf(Buf, _T("����Ա->%s") , pData->szSLoginName);
			else
				if ( pData->lSCorpID == -1 )
					_stprintf(Buf, _T("����"));
				else
					_stprintf(Buf, _T("%s->%s") , pData->szSCorpName,pData->szSLoginName);
			m_wndList.SetItemText(0,2,Buf);

			if ( pData->lRCorpID == 0 )
				_stprintf(Buf, _T("����Ա->%d") , pData->lRUserID);
			else
				if ( pData->lRCorpID == -1 )
					_stprintf(Buf, _T("����"));
				else
					_stprintf(Buf, _T("%d->%d") , pData->lRCorpID,pData->lRUserID);

			m_wndList.SetItemText(0,3,Buf);

			_stprintf(Buf, _T(" %d") , pData->lRAgentID);
			m_wndList.SetItemText(0,4,Buf);


			_stprintf(Buf, _T("%04d.%02d.%02d") , pData->tSendTime.wYear,pData->tSendTime.wMonth,pData->tSendTime.wDay);
			m_wndList.SetItemText(0,5,Buf);

			m_wndList.SetItemText(0,6,pData->szType);
			m_wndList.SetItemText(0,7,pData->szBZ);


			ANS_BBS_SeeData * pData2 = new ANS_BBS_SeeData;
			*pData2 = *pData;
			POSITION pos = m_BBS.AddTail( pData2 );
			m_wndList.SetItemData(0, (DWORD)pos );
		}
		return true;
	}
	//ɾ�����˴���
	if (pHead->lFuncType == SMSFUNC_BBS_DEL)
	{
		ANS_BBS_Del     * pDel     = (ANS_BBS_Del     *)pHead->pFrame;
		ANS_BBS_DelData * pDelData = (ANS_BBS_DelData *)(pHead->pFrame+sizeof(ANS_BBS_Del));
		POSITION pos,pos2;
		ANS_BBS_SeeData  * pSPData;
		for ( int i = pDel->lCount-1 ; i>=0 ; i-- )
		{
			if ( pDelData[i].lBBSID )  //ɾ���ɹ�
			{
				pos = (POSITION)m_wndList.GetItemData( pDelData[i].lItem );
				pos2 = pos;
				pSPData = m_BBS.GetNext( pos );
				if ( pSPData->lBBSID == pDelData[i].lBBSID )  //ID��ͬ�IJſ�ɾ��
				{
					delete pSPData;       //��ɾ������
					m_BBS.RemoveAt(pos2);   //���б���ɾ��
					m_wndList.DeleteItem(pDelData[i].lItem); //��ListCtrl��ɾ��
				}
			}
		}
		return true;
	}
	return true;
}

long CK_BBS::GetCurrentSelected()
{
	POSITION pos = m_wndList.GetFirstSelectedItemPosition();
	if ( pos )
	{
		return m_wndList.GetNextSelectedItem(pos);
	}
	return -1;
}

BOOL CK_BBS::OnInitDialog() 
{
	CDialog::OnInitDialog();

	//ȡ�ù��ò���
	//CMainFrame * pFrame = static_cast <CMainFrame *>((CMainFrame *)AfxGetMainWnd());
	this->GetParent()->GetParentFrame();
	m_pMainFrame = (CMainFrame *)this->GetParent()->GetParentFrame();
	m_pSocket    = &m_pMainFrame->m_Socket;

	//��ʼ��List
	m_Image.Create(16,16,ILC_COLOR16|ILC_MASK,5,5);
	m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_BBS) );
	m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CORP) );
	m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CORP_DISABLE) );
	m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_LOCK) );
	m_wndList.SubClassWindow2();
	m_wndList.SetHeadings(_T("���,50; ״̬,100;    ������,300;   ������,300;������-ҵ��Ա,120;����ʱ��,90; ����,90;     ����,800"));
	m_wndList.SetGridLines(true);
	m_wndList.SetImageList(&m_Image,LVSIL_SMALL);

	m_bInit = true;	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CK_BBS::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	if ( m_bInit )
	{
		m_wndList.MoveWindow( 0 , 0 , cx,cy);
	}
	
}

void CK_BBS::OnDblclkBbsList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	*pResult = 0;

	On_BBS_See();
}

void CK_BBS::OnRclickBbsList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	*pResult = 0;

	ShowRMenu();
}

void CK_BBS::OnKeydownBbsList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

void CK_BBS::SetLockItem(long lItem, BOOL bLock)
{
	if ( bLock )
		m_wndList.SetIconIndex( lItem , 3 );
	else
		m_wndList.SetIconIndex( lItem , 0 );
}

BOOL CK_BBS::isLockItem(long lItem, BOOL bShowWarning)
{
	BOOL b = (m_wndList.GetIconIndex(lItem) == 3);
	if ( b && bShowWarning )
	{
		MessageBox( _T("��¼����������ȴ����������غ��ٲ���!") , _T("������") , MB_ICONINFORMATION );
	}
	return b;
}

void CK_BBS::ShowRMenu()
{
	if (!m_pMainFrame->GetUserPurview(PURVIEW_LIST,false))  //û�в鿴Ȩ��
		return ;

	CMenu menu;
	menu.CreatePopupMenu();
	BOOL bLock = false;
	long lItem = this->GetCurrentSelected();
	if ( lItem >= 0 )
		bLock = isLockItem( lItem , false );   //ȡ���Ƿ���������
#ifndef SMSMANAGER_KF
	menu.AppendMenu(MF_STRING     , MENU_BBS_ADD, _T(" ������Ϣ ") );
#endif
	if ( lItem >=0 && !bLock)
	{
		menu.AppendMenu(MF_STRING     , MENU_BBS_SEE, _T(" �� �� ") );
#ifndef SMSMANAGER_KF
		menu.AppendMenu(MF_STRING     , MENU_BBS_DEL, _T(" ɾ �� ") );
#endif
		menu.AppendMenu(MF_STRING     , MENU_BBS_REMSG, _T(" �ظ���Ϣ ") );
	}
	else
	{
		menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED     , MENU_BBS_SEE, _T(" �� �� ") );
#ifndef SMSMANAGER_KF
		menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED     , MENU_BBS_DEL, _T(" ɾ �� ") );
#endif
		menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED     , MENU_BBS_REMSG, _T(" �ظ���Ϣ ") );
	}

	menu.AppendMenu(MF_SEPARATOR );
	menu.AppendMenu(MF_STRING     , MENU_BBS_REFRESH, _T(" ˢ �� ") );
	//��ʾ�˵�
	POINT pt ;
	::GetCursorPos( &pt );
	//this->ClientToScreen( &pt);
	menu.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RIGHTBUTTON,pt.x,pt.y, this, NULL);
	menu.DestroyMenu();
}

void CK_BBS::On_BBS_Add()
{
	if ( !m_pMainFrame->GetUserPurview(PURVIEW_LIST) )
	{
		return ;
	}

	ANS_BBS_SeeData See={0};
	See.lSCorpID = 0;  //����Ա����
	See.lSUserID = m_pMainFrame->m_lUserID;  //����ԱID
	_tcscpy(See.szSCorpName,_T("����Ա"));
	_tcscpy(See.szSLoginName , m_pMainFrame->m_Setup.szUser );

	See.lRCorpID = -1; //��ʱֻ�ܷ��������û�
	See.lRUserID = -1;
	See.lRAgentID= -1;  //���пͻ�

	DLG_BBS_Send dlg(this);
	dlg.SetParam( See );
	if ( dlg.DoModal() == IDOK )
	{
		long lSize = sizeof(REQ_BBS_Send)+sizeof(ANS_BBS_SeeData);
		BYTE * pModifyData = new BYTE[lSize];memset(pModifyData,0,lSize);
		REQ_BBS_Send * pModify = (REQ_BBS_Send *)pModifyData;   //ͷ
		ANS_BBS_SeeData * pSPData = (ANS_BBS_SeeData *)(pModifyData+sizeof(REQ_BBS_Send));
		*pSPData = dlg.GetParam();
		pModify->lItem  = 0;
		pModify->lCount = 1;
		m_pMainFrame->SendFrame( SMSFUNC_BBS_SEND , pModifyData , lSize );
	}

}
void CK_BBS::On_BBS_See()
{
	if ( !m_pMainFrame->GetUserPurview(PURVIEW_LIST) )
	{
		return ;
	}
	long lItem = GetCurrentSelected();
	if ( lItem < 0 )
		return ;
	CString strYWY = m_wndList.GetItemText(lItem,4);
	POSITION pos = (POSITION)m_wndList.GetItemData(lItem);
	POSITION pos2 = pos;
	ANS_BBS_SeeData * pData = m_BBS.GetNext( pos );
	if (pData)
	{
		DLG_BBS_See dlg(this);
		dlg.SetParam( *pData,strYWY);
		dlg.DoModal();
	}
}
void CK_BBS::On_BBS_Del()
{
	if ( !m_pMainFrame->GetUserPurview(PURVIEW_LIST) )
	{
		return ;
	}
	long lRet = MessageBox( _T("�˲�������ɾ������Ϣ���Ƿ������") , _T("����") , MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2);
	if ( lRet != IDYES )
		return;
	long lCount = m_wndList.GetSelectedCount();
	long lSize = sizeof(REQ_BBS_Del)+sizeof(ANS_BBS_DelData)*lCount;
	BYTE * pDelSend = new BYTE[lSize];memset(pDelSend,0,lSize);
	REQ_BBS_Del     * pDel = (REQ_BBS_Del *)pDelSend;   //ͷ
	ANS_BBS_DelData * pDelData = (ANS_BBS_DelData *)(pDelSend+sizeof(REQ_BBS_Del));
	pDel->lCount = lCount;
	POSITION pos = m_wndList.GetFirstSelectedItemPosition();
	ANS_BBS_SeeData * pSPData;
	POSITION pos2;
	while(pos)
	{
		pDelData->lItem   = m_wndList.GetNextSelectedItem(pos);
		pos2              = (POSITION)m_wndList.GetItemData(pDelData->lItem);
		pSPData           = m_BBS.GetNext(pos2);  //ȡ���б��е�pos
		pDelData->lBBSID  = pSPData->lBBSID;
		pDelData ++;
	}
	m_pMainFrame->SendFrame( SMSFUNC_BBS_DEL , pDelSend , lSize );
}
void CK_BBS::On_BBS_ReMsg()
{
	if ( !m_pMainFrame->GetUserPurview(PURVIEW_LIST) )
	{
		return ;
	}
	long lItem = GetCurrentSelected();
	if ( lItem < 0 )
		return ;

	POSITION pos = (POSITION)m_wndList.GetItemData(lItem);
	POSITION pos2 = pos;
	ANS_BBS_SeeData * pData = m_BBS.GetNext( pos );
	if (pData)
	{
		long lIcon=0;
		if ( pData->lAgentID>100 && pData->bAgentYJ )
			lIcon = 2;
		if ( pData->lAgentID>100 && !pData->bAgentYJ )
			lIcon = 1;

		if ( lIcon==2 )
		{
			MessageBox(_T("���Ǵ����̷����ͻ�����Ϣ�����ܻظ���") , _T("����") , MB_ICONWARNING );
			return ;
		}


		ANS_BBS_SeeData See={0};
		See.lBBSID = pData->lBBSID;
		See.lSCorpID = 0;  //����Ա����
		See.lSUserID = m_pMainFrame->m_lUserID;  //����ԱID
		_tcscpy(See.szSCorpName,_T("����Ա"));
		_tcscpy(See.szSLoginName , m_pMainFrame->m_Setup.szUser );
		See.lRCorpID = pData->lSCorpID;
		See.lRUserID = pData->lSUserID;
		DLG_BBS_Send dlg(this);
		dlg.SetParam( See , lIcon+1 );
		if ( dlg.DoModal() == IDOK )
		{
			long lSize = sizeof(REQ_BBS_Send)+sizeof(ANS_BBS_SeeData);
			BYTE * pModifyData = new BYTE[lSize];memset(pModifyData,0,lSize);
			REQ_BBS_Send * pModify = (REQ_BBS_Send *)pModifyData;   //ͷ
			ANS_BBS_SeeData * pSPData = (ANS_BBS_SeeData *)(pModifyData+sizeof(REQ_BBS_Send));
			*pSPData = dlg.GetParam();
			pModify->lItem  = lItem;
			pModify->lCount = 1;
			m_pMainFrame->SendFrame( SMSFUNC_BBS_SEND , pModifyData , lSize );
		}
	}
}
void CK_BBS::On_BBS_Refresh()
{
	REQ_BBS_See * pSee = new REQ_BBS_See;
	memset(pSee , 0 , sizeof(REQ_BBS_See));
	pSee->lType = 0;
	m_pMainFrame->SendFrame(SMSFUNC_BBS_SEE,(BYTE*)pSee,sizeof(REQ_BBS_See));
}

void CK_BBS::Close_Agent()
{
	//������������
	while (!m_Agent.IsEmpty())
	{
		ANS_Agent_NameData * pAgent = m_Agent.GetHead();
		m_Agent.RemoveHead();
		delete pAgent;
	}
}

void CK_BBS::Close_YWY()
{
	//������������
	while (!m_YWY.IsEmpty())
	{
		ANS_YWY_NameData * pYWY = m_YWY.GetHead();
		m_YWY.RemoveHead();
		delete pYWY;
	}
}

void CK_BBS::Close_BBS()
{
	//������������
	while (!m_BBS.IsEmpty())
	{
		ANS_BBS_SeeData * pData = m_BBS.GetHead();
		m_BBS.RemoveHead();
		delete pData;
	}
}

CString CK_BBS::FindAgent(long lAgentID)
{
	CString strAgent;
	ANS_Agent_NameData * pAgent;
	POSITION pos = m_Agent.GetHeadPosition();
	POSITION pos2;
	while (pos)
	{
		pos2=pos;
		pAgent = m_Agent.GetNext( pos );
		if ( pAgent->lAgentID == lAgentID )
		{
			strAgent = pAgent->szAgentName;
			break;
		}
	}

	return strAgent;
}

CString CK_BBS::FindYWY(long lYWYID)
{
	CString strYWY;
	ANS_YWY_NameData * pYWY;
	POSITION pos = m_YWY.GetHeadPosition();
	POSITION pos2;
	while (pos)
	{
		pos2=pos;
		pYWY = m_YWY.GetNext( pos );
		if ( pYWY->lYWYID == lYWYID )
		{
			strYWY = pYWY->szYWYName;
			break;
		}
	}

	return strYWY;
}