📄 login.cpp
字号:
// LOGIN.cpp : implementation file
//
#include "stdafx.h"
#include "课程设计.h"
#include "LOGIN.h"
#include "ADOConn.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLOGIN dialog
CLOGIN::CLOGIN(CWnd* pParent /*=NULL*/)
: CDialog(CLOGIN::IDD, pParent)
{
//{{AFX_DATA_INIT(CLOGIN)
m_password = _T("");
m_user = _T("");
//}}AFX_DATA_INIT
}
void CLOGIN::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLOGIN)
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
DDX_Text(pDX, IDC_EDIT_USER, m_user);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLOGIN, CDialog)
//{{AFX_MSG_MAP(CLOGIN)
ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLOGIN message handlers
void CLOGIN::OnBtnLogin()
{
// TODO: Add your control notification handler code here
if(sql_query())
{
CMainFrame * pWnd;
pWnd = (CMainFrame *)AfxGetMainWnd();
pWnd->m_admin = 1;
DestroyWindow();
}
}
void CLOGIN::OnButton2()
{
// TODO: Add your control notification handler code here
OnOK();
}
BOOL CLOGIN::sql_query()
{
ADOConn m_adoc;
m_adoc.OnInitDBConnect();
UpdateData();
CString user;
user = "'"+m_user+"'";
_bstr_t vSQL;
vSQL = "select * from admin where username = "+user;
_RecordsetPtr m_pRecordset;
m_pRecordset = m_adoc.GetRecordSet(vSQL);
if (m_pRecordset->adoEOF < 0)
{
AfxMessageBox("用户不存在!");
m_adoc.ExitConnect();
return 0;
}
else
{
CString password; //记录密码
password = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("password");
if(m_password == password)
{
AfxMessageBox("登陆成功!");
m_adoc.ExitConnect();
return 1;
}
else
{
AfxMessageBox("密码错误!");
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -