// LoginDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "VCDemo.h"
#include "LoginDlg.h"


// CLoginDlg 对话框

IMPLEMENT_DYNAMIC(CLoginDlg, CDialog)

CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{	
}

CLoginDlg::~CLoginDlg()
{
}

void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	ON_BN_CLICKED(IDC_BTN_LOGIN, &CLoginDlg::OnBnClickedBtnLogin)
	ON_BN_CLICKED(IDC_BTN_CANCEL, &CLoginDlg::OnBnClickedBtnCancel)
END_MESSAGE_MAP()


// CLoginDlg 消息处理程序

void CLoginDlg::OnBnClickedBtnLogin()
{
	// TODO: 登录
	CString strUser;
	CString strPswd;
	CString strIP;
	CString strPort;

	GetDlgItem(IDC_EDIT_USER)->GetWindowText(strUser);
	GetDlgItem(IDC_EDIT_PASSWORD)->GetWindowText(strPswd);
	GetDlgItem(IDC_EDIT_IP)->GetWindowText(strIP);
	GetDlgItem(IDC_EDIT_PORT)->GetWindowText(strPort);

	int ret = FC_ClientLogin(strUser.GetBuffer(strUser.GetLength()), strPswd.GetBuffer(strPswd.GetLength()), inet_addr(strIP), htons(atoi(strPort)), m_oUserRight);
	if(ret)
	{
		CString strText="登录失败,错误码:";				
		CString strMsg;
		switch (ret)
		{
		case AUTH_MSG_LENGTH_ERROR:
			strMsg.Format("%s=AUTH_MSG_LENGTH_ERROR", strText);
			break;
		case AUTH_MSG_CHECK_FAIL:
			strMsg.Format("%s=AUTH_MSG_CHECK_FAIL", strText);
			break;
		case AUTH_MSG_CRYPTO_LEN_ERROR:
			strMsg.Format("%s=AUTH_MSG_CRYPTO_LEN_ERROR", strText);
			break;
		case AUTH_MSG_ENCRYPT_ERROR:
			strMsg.Format("%s=AUTH_MSG_ENCRYPT_ERROR", strText);
			break;
		case AUTH_MSG_DECRYPT_ERROR:
			strMsg.Format("%s=AUTH_MSG_DECRYPT_ERROR", strText);
			break;
		case AUTH_MSG_UNKNOWN:
			strMsg.Format("%s=AUTH_MSG_UNKNOWN", strText);
			break;
		case AUTH_DB_STR_LEN_ERROR:
			strMsg.Format("%s=AUTH_DB_STR_LEN_ERROR", strText);
			break;
		case AUTH_DB_GRAMMA_ERROR:
			strMsg.Format("%s=AUTH_DB_GRAMMA_ERROR", strText);
			break;
		case AUTH_LENGTH_FLOW:
			strMsg.Format("%s=AUTH_LENGTH_FLOW", strText);
			break;
		case AUTH_CONNECT_CLOSE:
			strMsg.Format("%s=AUTH_CONNECT_CLOSE", strText);
			break;
		case AUTH_PROF_ERROR:
			strMsg.Format("%s=AUTH_PROF_ERROR",strText);
			break;
		case AUTH_IP_PORT_UNMATCH:
			strMsg.Format("%s=AUTH_IP_PORT_UNMATCH", strText);
			break;
		case AUTH_USR_NOT_FOUND:			
			strMsg.Format("%s=AUTH_USR_NOT_FOUND", strText);
			break;
		case AUTH_PASSWORD_INCORRECT:
			strMsg.Format("%s=AUTH_PASSWORD_INCORRECT", strText);
			break;
		case AUTH_USR_EXIST:
			strMsg.Format("%s=AUTH_USR_EXIST", strText);
			break;
		case AUTH_GRP_EXIST:
			strMsg.Format("%s=AUTH_GRP_EXIST", strText);
			break;
		case AUTH_NO_RESPONSE:
			strMsg.Format("%s=AUTH_NO_RESPONSE", strText);
			break;
		case AUTH_MEMORY_ERROR:
			strMsg.Format("%s=AUTH_MEMORY_ERROR", strText);
			break;
		case AUTH_OPEN_DB_FILE_ERROR:
			strMsg.Format("%s=AUTH_OPEN_DB_FILE_ERROR", strText);
			break;
		case AUTH_NO_PRIVILEGE:
			strMsg.Format("%s=AUTH_NO_PRIVILEGE", strText);
			break;
		case AUTH_ID_ERROR:
			strMsg.Format("%s=AUTH_ID_ERROR", strText);
			break;
		case AUTH_NAME_ERROR:
			strMsg.Format("%s=AUTH_NAME_ERROR", strText);
			break;
		case AUTH_LOGIN_DOMAIN_ERROR:
			strMsg.Format("%s=AUTH_LOGIN_DOMAIN_ERROR", strText);
			break;
		case AUTH_ACC_DOMAIN_ERROR:
			strMsg.Format("%s=AUTH_ACC_DOMAIN_ERROR", strText);
			break;
		case AUTH_BLG_DOMAIN_ERROR:
			strMsg.Format("%s=AUTH_BLG_DOMAIN_ERROR", strText);
			break;
		case AUTH_GRP_ERROR:
			strMsg.Format("%s=AUTH_GRP_ERROR", strText);
			break;
		case AUTH_ENABLE_ERROR:
			strMsg.Format("%s=AUTH_ENABLE_ERROR", strText);
			break;
		case AUTH_PRIORITY_ERROR:
			strMsg.Format("%s=AUTH_PRIORITY_ERROR", strText);
			break;
		case AUTH_VERSION_ERROR:
			strMsg.Format("%s=AUTH_VERSION_ERROR", strText);
			break;
		case AUTH_REC_EXIST:
			strMsg.Format("%s=AUTH_REC_EXIST", strText);
			break;
		case AUTH_NO_REFERENCED_ROW:
			strMsg.Format("%s=AUTH_NO_REFERENCED_ROW", strText);
			break;
		case AUTH_DB_ERROR:
			strMsg.Format("%s=AUTH_DB_ERROR", strText);
			break;
		case AUTH_REC_NOT_FOUND:
			strMsg.Format("%s=AUTH_REC_NOT_FOUND", strText);
			break;
		case AUTH_IS_REFERENCED_ROW:
			strMsg.Format("%s=AUTH_IS_REFERENCED_ROW", strText);
			break;
		case AUTH_EXCEED_LOGON_TIME:
			strMsg.Format("%s=AUTH_EXCEED_LOGON_TIME", strText);
			break;
		case AUTH_USER_DISABLED:
			strMsg.Format("%s=AUTH_USER_DISABLED", strText);
			break;
		case AUTH_CREATE_HBTASK_ERROR:
			strMsg.Format("%s=AUTH_CREATE_HBTASK_ERROR", strText);
			break;
		case AUTH_START_NOT_FINISH:
			strMsg.Format("%s=AUTH_START_NOT_FINISH", strText);
			break;
		case AUTH_TVWALL_DOMAIN_ERROR:
			strMsg.Format("%s=AUTH_TVWALL_DOMAIN_ERROR",strText);
			break;
		case AUTH_UNKNOWN_CLIENT_TYPE:
			strMsg.Format("%s=AUTH_UNKNOWN_CLIENT_TYPE",strText);
			break;
		case AUTH_HEARTBEAT_LOST:
			strMsg.Format("%s=AUTH_HEARTBEAT_LOST", strText);
			break;
		case AUTH_HAS_LOGIN:
			strMsg.Format("%s=AUTH_HAS_LOGIN", strText);
			break;
		case AUTH_NAME_REPEATED:
			strMsg.Format("%s=AUTH_NAME_REPEATED", strText);
			break;
		case AUTH_MOBILEPHONE_ERROR:
			strMsg.Format("%s=AUTH_MOBILEPHONE_ERROR", strText);
			break;
		case AUTH_EMAILADDR_ERROR:
			strMsg.Format("%s=AUTH_EMAILADDR_ERROR", strText);
			break;
		case AUTH_EXCEED_MAX_USER:
			strMsg.Format("%s=AUTH_EXCEED_MAX_USER", strText);
			break;
		case AUTH_SENDMSG_ERROR:
			strMsg.Format("%s=AUTH_SENDMSG_ERROR", strText);
			break;
		default:
			strMsg.Format("%s=%d", strText, ret);
			break;
		}

		AfxMessageBox(strMsg);
	}
	else
	{		
		CDialog::OnOK();
	}
}

void CLoginDlg::OnBnClickedBtnCancel()
{
	// TODO: 取消
	CDialog::OnCancel();
}

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

	GetDlgItem(IDC_EDIT_PORT)->SetWindowText("20001");

	return TRUE;  // return TRUE unless you set the focus to a control
}

BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO:
	if((pMsg->message == WM_KEYDOWN)&&(pMsg->wParam == VK_ESCAPE)||
		(pMsg->message == WM_KEYDOWN)&&(pMsg->wParam == VK_RETURN))   
	{
		return TRUE;   
	}

	return CDialog::PreTranslateMessage(pMsg);
}
