📄 logindlg.cpp
字号:
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Scoremanager.h"
#include "LoginDlg.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)
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Control(pDX, IDOK, m_ok);
DDX_Control(pDX, IDC_USERNAME, m_strUserName);
DDX_Control(pDX, IDC_PASSWORD, m_strPassword);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int count=0;
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
void CLoginDlg::OnOK()
{
CString username,password;
m_strUserName.GetWindowText(username);
m_strPassword.GetWindowText(password);
if(!m_database.IsOpen())
if(m_database.Open(_T("Scoremanager")))
{
m_recordSet.m_pDatabase=&m_database;
CString strSQL;
strSQL.Format("select* from userinfo where user_name='%s' and user_password='%s' and active_status='Y'",username,password);
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
if(m_recordSet.GetRecordCount()==0)
{
if(count<3)
{
MessageBox("用户名或密码错误,请重新输入","密码错误",MB_OK|MB_ICONWARNING);
count++;
m_strPassword.SetWindowText("");
m_strPassword.SetFocus();
}
else
{
MessageBox("尝试次数太多!");
m_recordSet.Close();
m_database.Close();
CDialog::OnCancel();
}}
else
{
m_recordSet.GetFieldValue("user_level",m_userLevel);
CDialog::OnOK();
}
m_recordSet.Close();
m_database.Close();
}
else
{
MessageBox("不能打开数据库");
}
}
void CLoginDlg::OnCancel()
{
if(MessageBox("真的要退出系统吗?","退出询问",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -