// DLG_C_FaxNum_Set.cpp : implementation file
//

#include "stdafx.h"
#include "smsmanager.h"
#include "DLG_C_FaxNum_Set.h"

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

/////////////////////////////////////////////////////////////////////////////
// DLG_C_FaxNum_Set dialog
#include "C_FaxNum.h"
#include "MainFrm.h"
#include "UserDlg.h"

DLG_C_FaxNum_Set::DLG_C_FaxNum_Set(CWnd* pParent /*=NULL*/)
	: CDialog(DLG_C_FaxNum_Set::IDD, pParent)
{
	//{{AFX_DATA_INIT(DLG_C_FaxNum_Set)
	m_strAccount = _T("");
	m_strBNetAccount = _T("");
	m_strBZ = _T("");
	m_lCorp = -1;
	m_strFaxNum = _T("");
	//}}AFX_DATA_INIT

	m_pFaxNumDlg = (CC_FaxNum *)pParent;
	memset(&m_FaxNumData , 0 , sizeof(m_FaxNumData) );
}


void DLG_C_FaxNum_Set::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DLG_C_FaxNum_Set)
	DDX_Control(pDX, IDC_FAXNUM_SET_CORPID, m_E_CorpID);
	DDX_Control(pDX, IDC_FAXNUM_SET_CORP, m_L_Corp);
	DDX_Text(pDX, IDC_FAXNUM_SET_ACCOUNT, m_strAccount);
	DDX_Text(pDX, IDC_FAXNUM_SET_BNETACCOUNT, m_strBNetAccount);
	DDX_Text(pDX, IDC_FAXNUM_SET_BZ, m_strBZ);
	DDV_MaxChars(pDX, m_strBZ, 200);
	DDX_CBIndex(pDX, IDC_FAXNUM_SET_CORP, m_lCorp);
	DDX_Text(pDX, IDC_FAXNUM_SET_FAXNUM, m_strFaxNum);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DLG_C_FaxNum_Set, CDialog)
	//{{AFX_MSG_MAP(DLG_C_FaxNum_Set)
	ON_BN_CLICKED(IDC_FAXNUM_SET_LOCAL, OnFaxnumSetLocal)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLG_C_FaxNum_Set message handlers

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


	CString strTemp;
	//ҵ��Ա
	ANS_Corp_NameData * pCorp;
	m_L_Corp.AddString( _T("�޷�����ҵ") );
	m_L_Corp.SetCurSel(0);
	POSITION pos = m_pFaxNumDlg->m_Corp.GetHeadPosition();
	POSITION pos2=0;
	while (pos)
	{
		pos2=pos;
		pCorp = m_pFaxNumDlg->m_Corp.GetNext( pos );
		if ( pCorp )
		{
			strTemp.Format( _T("%d-%s"),pCorp->lCorpID , pCorp->szCorpName);
			long lItem = m_L_Corp.AddString( strTemp );
			m_L_Corp.SetItemData( lItem , (DWORD_PTR)pos2);
			if ( m_FaxNumData.lCorpID == pCorp->lCorpID )
				m_L_Corp.SetCurSel(lItem);
		}
	}

	UpdateData(true);


	m_strFaxNum = m_FaxNumData.szFaxNum;
	m_strAccount = m_FaxNumData.szUserAccount;
	m_strBNetAccount = m_FaxNumData.szBNetAccount;
	m_strBZ = m_FaxNumData.szBZ;


	UpdateData(false);

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

void DLG_C_FaxNum_Set::OnOK() 
{
	if ( !UpdateData(true ) )
		return;

	//ҵ��ԱID
	m_FaxNumData.lCorpID = 0;
	if ( m_lCorp > 0 )
	{

		POSITION pos = (POSITION)m_L_Corp.GetItemData(m_lCorp);
		ANS_Corp_NameData * pData = m_pFaxNumDlg->m_Corp.GetNext( pos );
		if (pData)
		{
			m_FaxNumData.lCorpID = pData->lCorpID;
		}
	}

	_tcscpy(m_FaxNumData.szBZ , m_strBZ);

	
	CDialog::OnOK();
}

void DLG_C_FaxNum_Set::SetParam(ANS_FaxNum_Data faxNumData)
{
	m_FaxNumData = faxNumData;
}

ANS_FaxNum_Data DLG_C_FaxNum_Set::GetFaxNumData()
{
	return m_FaxNumData;

}

void DLG_C_FaxNum_Set::OnFaxnumSetLocal() 
{
	CString strTemp;
	CString strFind;
	m_E_CorpID.GetWindowText(strFind);
	if ( strFind.GetLength()<=0 )
		return ;
	long lSel   = m_L_Corp.GetCurSel();
	long lCount = m_L_Corp.GetCount();
	for ( int i=lSel+1 ; i<lCount ; i++ )
	{
		m_L_Corp.GetLBText(i,strTemp);
		if ( strTemp.Find(strFind)>=0 )
		{
			m_L_Corp.SetCurSel(i);
			//OnSelchangeCPayCorp();
			return ;
		}
	}
	for ( i=0 ; i<lSel ; i++ )
	{
		m_L_Corp.GetLBText(i,strTemp);
		if ( strTemp.Find(strFind)>=0 )
		{
			m_L_Corp.SetCurSel(i);
			//OnSelchangeCPayCorp();
			return ;
		}
	}	
}

BOOL DLG_C_FaxNum_Set::PreTranslateMessage(MSG* pMsg) 
{
	if ( pMsg->hwnd == m_E_CorpID && pMsg->message == WM_KEYDOWN )
	{
		if ( pMsg->wParam == 13 ) //�س���
		{
			this->OnFaxnumSetLocal();
			return true;
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}