📄 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_sDSN = _T("ManageSalaryDS");
m_sUserName = _T("Admin");
m_sPassward = _T("Admin");
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_CBString(pDX, IDC_CMD_DSN, m_sDSN);
DDX_Text(pDX, IDC_EDT_USER, m_sUserName);
DDX_Text(pDX, IDC_EDT_PASSWD, m_sPassward);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
ON_EN_CHANGE(IDC_EDT_USER, OnChangeEdtUser)
//}}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 sFilter, sPassward;
_RecordsetPtr pRS; // Recordset对象
UpdateData();// 更新数据
// 打开数据库
if(pTheConn->GetState()==adStateClosed)
pTheConn->Open(m_sDSN.AllocSysString(),"","",-1);
pRS.CreateInstance(__uuidof(Recordset)); // 创建Recordset对象实例
// 设置过滤条件
sPassward="Name='" + m_sUserName
+ "' and Passward='" + m_sPassward
+ "' and authority='1'";
try
{
pRS->Filter=sPassward.AllocSysString();
pRS->Open("PersonInfo",
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("请确认用户名和密码,注意大小写!", "认证失败");
}
void CLoginDlg::OnChangeEdtUser()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -