?? logindlg.cpp
字號(hào):
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "車友.h"
#include "LoginDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)
m_times = 2;
m_dwUser = 0;
m_pas = _T("");
//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_Control(pDX, IDC_DLOG_CUSER, m_uList);
DDX_Text(pDX, IDC_DLOG_CPASWORD, m_pas);
DDV_MaxChars(pDX, m_pas, 16);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
DWORD CLoginDlg::GetUserInfo() const
{
return m_dwUser;
}
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog();
USERINFO theUser;
char * strOper[] = { {"信息錄入員"},{"系統(tǒng)管理員"} };
UINT size = sizeof(USERINFO);
LPBYTE bt = new unsigned char[sizeof(theUser)];
CString strID;
strID.Format("User%04u",0);
int lastID;
lastID = AfxGetApp()->GetProfileInt("用戶","LastID",0);
for(int i=0;i<lastID && AfxGetApp()->GetProfileBinary("用戶",strID,&bt,&size);i++)
{
memcpy(&theUser,bt,sizeof(theUser));
CString strInfo;
strInfo.Format("%s [%s]",theUser.name,strOper[theUser.oper]);
m_uList.AddString(strInfo);
strID.Format("User%04u",i+1);
}
if(lastID > 0)
m_uList.SetCurSel(0);
delete [] bt;
return TRUE;
}
void CLoginDlg::OnOK()
{
UpdateData();
USERINFO theUser;
UINT size = sizeof(theUser);
LPBYTE bt = new unsigned char[sizeof(theUser)];
CString strID;
int id = m_uList.GetCurSel();
strID.Format("User%04u",id);
if(AfxGetApp()->GetProfileBinary("用戶",strID,&bt,&size))
{
memcpy(&theUser,bt,sizeof(theUser));
delete [] bt;
if(!m_pas.Compare(theUser.password))
{
m_dwUser = theUser.oper;
CDialog::OnOK();
return;
}
}
else
{
delete [] bt;
MessageBox("沒有該用戶的信息,請(qǐng)與系統(tǒng)管理員聯(lián)系。","讀取用戶數(shù)據(jù)錯(cuò)誤",MB_OK|MB_ICONSTOP);
return;
}
if(m_times)
{
m_times--;
MessageBox("用戶密碼不正確!請(qǐng)?jiān)俅螄L試...","登陸失敗...",MB_OK|MB_ICONSTOP);
GetDlgItem(IDC_DLOG_CPASWORD)->SetFocus();
}
else
{
MessageBox("用戶密碼不正確!\n您的登陸失敗次數(shù)已達(dá)三次,程序?qū)⑼顺觥n請(qǐng)與系統(tǒng)管理員聯(lián)系。","登陸失敗...",MB_OK|MB_ICONSTOP);
CDialog::OnCancel();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -