?? logindlg.cpp
字號:
// 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對象
/////////////////////////////////////////////////////////////////////////////
// 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();
// 改變"登錄人事管理系統"字體大小
//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對象
UpdateData();// 更新數據
// 打開數據庫
if(pTheConn->GetState()==adStateClosed)
pTheConn->Open(m_strDSN.AllocSysString(),"","",-1);
pRS.CreateInstance(__uuidof(Recordset)); // 創建Recordset對象實例
strPasswd=CCrypt::Encrypt(m_strPasswd,123); // 密碼加密
// 設置過濾條件
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("打開數據集對象出錯!");
}
int a=pRS->RecordCount;
if(pRS->RecordCount==1) // 判斷認證是否通過
{
EndDialog(IDOK); // 關閉對話框
}
else
MessageBox("請確認用戶名和密碼,注意大小寫!", "認證失敗");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -