?? passworddlg.cpp
字號(hào):
// PasswordDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StudentScore.h"
#include "PasswordDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPasswordDlg dialog
CPasswordDlg::CPasswordDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPasswordDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPasswordDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPasswordDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPasswordDlg, CDialog)
//{{AFX_MSG_MAP(CPasswordDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPasswordDlg message handlers
void CPasswordDlg::OnOK()
{
//定義4個(gè)CEdit變量
CEdit* pUsername=(CEdit*) this->GetDlgItem(IDC_EDIT_USERNAME);
CEdit* pPassword=(CEdit*) this->GetDlgItem(IDC_EDIT_PASSWORD);
CEdit* pNew=(CEdit*) this->GetDlgItem(IDC_EDIT_NEW);
CEdit* pConfirm=(CEdit*) this->GetDlgItem(IDC_EDIT_CONFIRM);
//分別將文本框的值賦給4個(gè)字符串
CString username,password,newPassword,confirmPassword;
pUsername->GetWindowText(username);
pPassword->GetWindowText(password);
pNew->GetWindowText(newPassword);
pConfirm->GetWindowText(confirmPassword);
//定義數(shù)據(jù)庫(kù)對(duì)象和記錄集對(duì)象
CDatabase m_database;
CRecordset m_recordSet;
//判斷新密碼是是為空
if(newPassword.IsEmpty()||confirmPassword.IsEmpty())
{
MessageBox("密碼不為空");
}
else
{
if(newPassword!=confirmPassword)//判斷兩次輸入的新密碼是否相同
{
MessageBox("兩次輸入密碼不一致,請(qǐng)重新輸入新密碼");
pNew->SetWindowText("");//清空新密碼文本框
pConfirm->SetWindowText("");//清空確認(rèn)密碼文本框
pNew->SetFocus();//設(shè)置新密碼文本框?yàn)榻裹c(diǎn)
}
else
{
if(!m_database.IsOpen()){//如果數(shù)據(jù)沒(méi)有打開(kāi),則打開(kāi)數(shù)據(jù)庫(kù)
if(m_database.Open(_T("studentscore")))//如果正確打開(kāi)數(shù)據(jù)庫(kù)
{
m_recordSet.m_pDatabase=&m_database;//將m_database對(duì)象賦給m_pDatabase
CString strSQL;
strSQL.Format("select * from userinfo where user_name='%s' and user_password='%s' and active_status='Y'",username,password);
m_recordSet.Open(CRecordset::forwardOnly,strSQL);//打開(kāi)記錄集
if(m_recordSet.GetRecordCount()==0)//如果找不到記錄
{
MessageBox("密碼錯(cuò)誤,請(qǐng)重新輸入","密碼錯(cuò)誤",MB_OK|MB_ICONWARNING);//提示密碼錯(cuò)誤
pPassword->SetWindowText("");//清空密碼文本框
pNew->SetWindowText("");//清空新密碼文本框
pConfirm->SetWindowText("");//清空確認(rèn)密碼文本框
pPassword->SetFocus();//設(shè)置用戶名文本框?yàn)楫?dāng)前的焦點(diǎn)
}
else//如果找到記錄
{
//更新密碼的sql語(yǔ)句
strSQL.Format("update userinfo set user_password='%s' where user_name='%s'",newPassword,username);
m_database.ExecuteSQL(strSQL);//執(zhí)行sql
MessageBox("修改密碼成功!");
CDialog::OnOK();
}
m_recordSet.Close();//關(guān)閉記錄集
m_database.Close();//關(guān)閉數(shù)據(jù)庫(kù)
}
else//如果沒(méi)有正確打開(kāi)數(shù)據(jù)庫(kù)
{
MessageBox("不能打開(kāi)數(shù)據(jù)庫(kù)");
}
}
}
}
}
void CPasswordDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -