?? 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 + -