?? logindlg.cpp
字號(hào):
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Salary.h"
#include "LoginDlg.h"
#include "Crypt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr pTheConn; // Connection對(duì)象
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)
m_strDSN = _T("MISDB");
m_strUser = _T("");
m_strPasswd = _T("");
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_CBString(pDX, IDC_CMD_DSN, m_strDSN);
DDX_Text(pDX, IDC_EDT_USER, m_strUser);
DDX_Text(pDX, IDC_EDT_PASSWD, m_strPasswd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 改變"登錄人事管理系統(tǒng)"字體大小
//CFont *pFont=GetFont();
//m_font.CreatePointFont(10,NULL);
LOGFONT LogFont;
GetFont()->GetLogFont(&LogFont);
LogFont.lfHeight+=LogFont.lfHeight/2;
LogFont.lfWidth+=LogFont.lfWidth/2;
m_font.CreateFontIndirect(&LogFont);
GetDlgItem(IDC_STATIC_LOGINTEXT)->SetFont(&m_font);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLoginDlg::OnOK()
{
CString str,strPasswd;
_RecordsetPtr pRS; // Recordset對(duì)象
UpdateData();// 更新數(shù)據(jù)
// 打開(kāi)數(shù)據(jù)庫(kù)
if(pTheConn->GetState()==adStateClosed)
pTheConn->Open(m_strDSN.AllocSysString(),"","",-1);
pRS.CreateInstance(__uuidof(Recordset)); // 創(chuàng)建Recordset對(duì)象實(shí)例
strPasswd=CCrypt::Encrypt(m_strPasswd,123); // 密碼加密
// 設(shè)置過(guò)濾條件
str="ID='" + m_strUser
+ "' and PASSWD='" + strPasswd
+ "' and AUTHORITY='5'";
try
{
pRS->Filter=str.AllocSysString();
pRS->Open("PERSON",
pTheConn.GetInterfacePtr(),
adOpenStatic,adLockReadOnly,adCmdTable);
}
catch(_com_error *e)
{
CString Error = e->ErrorMessage();
AfxMessageBox(e->ErrorMessage());
}
catch(...)
{
AfxMessageBox("打開(kāi)數(shù)據(jù)集對(duì)象出錯(cuò)!");
}
int a=pRS->RecordCount;
if(pRS->RecordCount==1) // 判斷認(rèn)證是否通過(guò)
{
EndDialog(IDOK); // 關(guān)閉對(duì)話框
}
else
MessageBox("請(qǐng)確認(rèn)用戶名和密碼,注意大小寫!", "認(rèn)證失敗");
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -