📄 logindlg.cpp
字号:
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MenuManage.h"
#include "LoginDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMenuManageApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)
m_strLoginName = _T("");
m_strLoginPwd = _T("");
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_Text(pDX, IDC_EDIT_LOGINNAME, m_strLoginName);
DDX_Text(pDX, IDC_EDIT_LOGINPWD, m_strLoginPwd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
ON_BN_CLICKED(ID_LOGIN_BTN, OnLoginBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
void CLoginDlg::OnLoginBtn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(!m_strLoginName.IsEmpty() && !m_strLoginPwd.IsEmpty())
{
try
{
CString sql;
sql = "SELECT * FROM UserInfo WHERE UserName='"+m_strLoginName+"' and UserPwd = '"+m_strLoginPwd+"'";
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//如果没有此用户和密码,再查询是否有此用户
if(m_pRecordset->adoEOF)
{
m_pRecordset->Close();
sql = "SELECT * FROM UserInfo WHERE UserName='"+m_strLoginName+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//如果没有此用户,则提示用户不存在
if(m_pRecordset->adoEOF)
{
MessageBox("此用户不存在!","登录系统");
}
//如果有,提示密码错误信息。
else
{
MessageBox("密码错误!","登录系统");
return;
}
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
else
{
theApp.m_Level = m_pRecordset->GetCollect("UserLevel").lVal;
theApp.m_name = m_strLoginName;
MessageBox("登录成功!","登录系统",MB_OKCANCEL|MB_ICONQUESTION);
CDialog::OnOK();
return;
}
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
m_pRecordset->Close();
m_pRecordset = NULL;
}
else
{
MessageBox("请输入用户名和密码","登录系统");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -