logindlg.cpp

来自「内容包括从VC++的基本范例到项目开发的许多典型的例子。是VC++初学者不可多得」· C++ 代码 · 共 113 行

CPP
113
字号
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ExMIS.h"
#include "LoginDlg.h"
#include "MyRecordSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog


CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
	m_strDataType = _T("");
	m_strPassword = _T("");
	m_strUsername = _T("");
	//}}AFX_DATA_INIT

	//初始权限为0
	m_nPower=0;
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_CBString(pDX, IDC_COMBO_TYPE, m_strDataType);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUsername);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers

void CLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CLoginDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CLoginDlg::OnBtnLogin() 
{

	// TODO: Add your control notification handler code here
	//检查用户名是否输入
	UpdateData(true);
	if(m_strUsername.IsEmpty()||m_strPassword.IsEmpty()||m_strDataType.IsEmpty())
	{
		AfxMessageBox("请将资料填写完整再登录!");
		return;
	}

	m_pRS.ADOOpen(m_strDataType);
	m_strSQL="SELECT password,power FROM UserTab WHERE [username]='"+m_strUsername+"' ";
	m_pRS.ADOExcute(m_strSQL);

	if(m_pRS.nFieldRows==1)
	{
		if(m_pRS.GetFieldString(0)==m_strPassword)
		{
			m_pRS.nPower=m_pRS.GetFieldNumber(1);

			CDialog::OnOK();
		}else{
			AfxMessageBox("错误的密码!");
		}
	}else{
		AfxMessageBox("错误的用户名!");
	}

}

void CLoginDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	//屏蔽此事件, 即关闭窗口的事件;
	//CDialog::OnClose();
}

void CLoginDlg::OnBtnCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?