📄 logindlg.cpp
字号:
// LoginDLG.cpp : implementation file
//
#import "c:\program files\common files\system\ado\msado15.dll"\no_namespace\rename("EOF", "adoEOF")
#include "iostream.h"
#include "stdafx.h"
#include "chess.h"
#include "ChessDlg.h"
#include "LoginDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoginDLG dialog
CDatabase db;
CLoginDLG::CLoginDLG(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDLG)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CLoginDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDLG)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDLG, CDialog)
//{{AFX_MSG_MAP(CLoginDLG)
ON_BN_CLICKED(IDM_EXIT, OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDLG message handlers
void CLoginDLG::OnOK()
{
// TODO: Add extra validation here
UpdateData();
CString Username;
CString Password;
GetDlgItem(IDC_EDIT1)->GetWindowText(Username);
GetDlgItem(IDC_EDIT2)->GetWindowText(Password);
if(strlen(Username) <= 0){
MessageBox("用户名不能为空!");
return;
}
if(strlen(Password) <= 0){
MessageBox("密码不能为空!");
return;
}
CString m_strUserName,m_strPass;
CString strSql;
strSql.Format("SELECT username,password FROM user_Info WHERE username='%s'",Username);
if(!db.OpenEx("DSN=chess;UID=;PWD=")) return;
CRecordset rs(&db);
rs.Open(CRecordset::forwardOnly,strSql);
if(!rs.IsEOF())
{
rs.GetFieldValue("username",m_strUserName);
rs.GetFieldValue("password",m_strPass);
}
rs.Close();
db.Close();
if(Password==m_strPass)
EndDialog(IDOK);
else
{
MessageBox("用户名或密码错误","信息提示",MB_ICONWARNING);
rs.Close();
db.Close();
}
}
void CLoginDLG::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -