?? userdlg.cpp
字號:
// UserDlg.cpp : implementation file
//
#include "stdafx.h"
#include "車友.h"
#include "UserDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUserDlg dialog
#include "LoginDlg.h"
CUserDlg::CUserDlg(DWORD dwUser, CWnd* pParent /*=NULL*/)
:m_dwUser(dwUser), CDialog(CUserDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUserDlg)
m_udepwd = _T("");
m_udename = _T("");
m_udepwdr = _T("");
m_udeonp = _T("");
m_udenpr = _T("");
m_udenp = _T("");
//}}AFX_DATA_INIT
}
void CUserDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUserDlg)
DDX_Control(pDX, IDC_UD_LIST, m_udlist);
DDX_Control(pDX, IDC_UD_CPURVIEW, m_udcpv);
DDX_Text(pDX, IDC_UD_ENP, m_udepwd);
DDV_MaxChars(pDX, m_udepwd, 16);
DDX_Text(pDX, IDC_UD_ENAME, m_udename);
DDV_MaxChars(pDX, m_udename, 18);
DDX_Text(pDX, IDC_UD_ENPR, m_udepwdr);
DDV_MaxChars(pDX, m_udepwdr, 16);
DDX_Text(pDX, IDC_UD_EONP, m_udeonp);
DDV_MaxChars(pDX, m_udeonp, 16);
DDX_Text(pDX, IDC_UD_EONPR, m_udenpr);
DDV_MaxChars(pDX, m_udenpr, 16);
DDX_Text(pDX, IDC_UD_EOP, m_udenp);
DDV_MaxChars(pDX, m_udenp, 16);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUserDlg, CDialog)
//{{AFX_MSG_MAP(CUserDlg)
ON_BN_CLICKED(IDC_UD_BADD, OnUdBadd)
ON_BN_CLICKED(IDC_UD_BDEL, OnUdBdel)
ON_BN_CLICKED(IDC_UD_BHELP, OnUdBhelp)
ON_BN_CLICKED(IDC_UD_BMODIFY, OnUdBmodify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUserDlg message handlers
BOOL CUserDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_dwUser < 1)
{
GetDlgItem(IDC_UD_ENAME)->EnableWindow(FALSE);
GetDlgItem(IDC_UD_CPURVIEW)->EnableWindow(FALSE);
GetDlgItem(IDC_UD_ENP)->EnableWindow(FALSE);
GetDlgItem(IDC_UD_ENPR)->EnableWindow(FALSE);
GetDlgItem(IDC_UD_BADD)->EnableWindow(FALSE);
GetDlgItem(IDC_UD_BDEL)->EnableWindow(FALSE);
}
USERINFO theUser;
char * strOper[] = { {"信息錄入員"},{"系統管理員"} };
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_udlist.AddString(strInfo);
strID.Format("User%04u",i+1);
}
if(lastID > 0)
m_udlist.SetCurSel(0);
delete [] bt;
m_udcpv.SetCurSel(0);
return TRUE;
}
void CUserDlg::OnUdBadd()
{
UpdateData();
char * strq[] = { {"信息錄入員"},{"系統管理員"} };
int purview = m_udcpv.GetCurSel();
if(m_udename.IsEmpty())
{
MessageBox("請指定用戶名稱。","輸入錯誤",MB_OK);//|MB_ICONQUESION);
GetDlgItem(IDC_UD_ENAME)->SetFocus();
return;
}
if(purview == -1)
{
MessageBox("請指定用戶權限。","輸入錯誤",MB_OK);//|MB_ICONQUESION);
GetDlgItem(IDC_UD_CPURVIEW)->SetFocus();
return;
}
if(m_udepwd.Compare(m_udepwdr))
{
MessageBox("兩次輸入的密碼不一致,請重新輸入。","密碼驗證錯",MB_OK);//|MB_ICONQUESTION);
m_udepwd.Empty();
m_udepwdr.Empty();
UpdateData(FALSE);
GetDlgItem(IDC_UD_ENP)->SetFocus();
return;
}
int LastID = AfxGetApp()->GetProfileInt("用戶","LastID",0);
CString strID;
strID.Format("User%04u",LastID);
USERINFO user;
ZeroMemory(&user,sizeof(user));
strcpy(user.name,m_udename);
user.oper = purview;
strcpy(user.password,m_udepwd);
if(AfxGetApp()->WriteProfileBinary("用戶",strID,(LPBYTE)&user,sizeof(user)))
{
CString str = m_udename + " [" + strq[purview] + "]";
m_udlist.AddString(str);
LastID++;
AfxGetApp()->WriteProfileInt("用戶","LastID",LastID);
}
else
{
MessageBox("數據寫入出錯。","錯誤",MB_OK|MB_ICONSTOP);
return;
}
m_udcpv.SetCurSel(0);
m_udename.Empty();
m_udepwd.Empty();
m_udepwdr.Empty();
UpdateData(FALSE);
}
void CUserDlg::OnUdBdel()
{
int s;
CString strValue;
s = m_udlist.GetCurSel();
if(s<0)
{
MessageBox("請從右下角的列表中選擇一個要刪除用戶。","指定用戶錯",MB_OK|MB_ICONSTOP);
return;
}
if(s==0)
{
AfxMessageBox("為保證至少保留一個系統管理員,此用戶不允許被刪除,但您可以修改其密碼。",MB_OK|MB_ICONSTOP);
return;
}
m_udlist.GetText(s,strValue);
strValue = "確認刪除此用戶(" + strValue + ")嗎?";
if(MessageBox(strValue,"確認刪除用戶",MB_OKCANCEL|MB_ICONQUESTION) != IDOK)
return;
int nLastID = AfxGetApp()->GetProfileInt("用戶","LastID",0);
if(! nLastID)
return;
HKEY key;
if(nLastID != (s+1))
{
strValue.Format("User%04u",nLastID-1);
USERINFO user;
UINT btsize = sizeof(user);
LPBYTE bt = new unsigned char[btsize];
AfxGetApp()->GetProfileBinary("用戶",strValue,&bt,&btsize);
memcpy(&user,bt,btsize);
delete [] bt;
strValue.Format("User%04u",s);
AfxGetApp()->WriteProfileBinary("用戶",strValue,(LPBYTE)&user,btsize);
}
nLastID--;
AfxGetApp()->WriteProfileInt("用戶","LastID",nLastID);
strValue.Format("User%04u",nLastID);
::RegOpenKey(HKEY_USERS,".Default\\SoftWare\\HMN-SOFT\\車友\\用戶",&key);
::RegDeleteValue(key,strValue);
::RegCloseKey(key);
m_udlist.DeleteString(s);
}
void CUserDlg::OnUdBhelp()
{
MessageBox("在“注銷”或者“修改密碼”之前,請首先從右下角的列表框里選擇一個用戶。","幫助信息",MB_OK);
}
void CUserDlg::OnUdBmodify()
{
UpdateData(TRUE);
int s = m_udlist.GetCurSel();
if(s<0)
{
MessageBox("請從右下角的列表中選擇一個用戶。","指定用戶錯",MB_OK|MB_ICONSTOP);
return;
}
CString str;
str.Format("User%04u",s);
USERINFO user;
UINT btsize = sizeof(user);
LPBYTE bt = new unsigned char[btsize];
AfxGetApp()->GetProfileBinary("用戶",str,&bt,&btsize);
memcpy(&user,bt,btsize);
delete [] bt;
if(m_udenp.Compare(user.password))
{
AfxMessageBox("該用戶的原密碼不正確,請重新輸入。",MB_OK|MB_ICONSTOP);
SetDlgItemText(IDC_UD_EOP,"");
GetDlgItem(IDC_UD_EOP)->SetFocus();
return;
}
if(m_udeonp.Compare(m_udenpr))
{
AfxMessageBox("兩次輸入的密碼不一致,請重新輸入。",MB_OK|MB_ICONSTOP);
SetDlgItemText(IDC_UD_EONP,"");
SetDlgItemText(IDC_UD_EONPR,"");
GetDlgItem(IDC_UD_EONP)->SetFocus();
return;
}
strcpy(user.password,m_udeonp);
AfxGetApp()->WriteProfileBinary("用戶",str,(LPBYTE)&user,btsize);
AfxMessageBox("密碼修改成功!請牢記。",MB_OK);
SetDlgItemText(IDC_UD_EOP,"");
SetDlgItemText(IDC_UD_EONP,"");
SetDlgItemText(IDC_UD_EONPR,"");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -