// ChangePswDlg.cpp : implementation file //
#include "stdafx.h" #include "Address.h" #include "ChangePswDlg.h" #include "PswdSet.h"
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
///////////////////////////////////////////////////////////////////////////// // CChangePswDlg dialog
CChangePswDlg::CChangePswDlg(CWnd* pParent /*=NULL*/) : CDialog(CChangePswDlg::IDD, pParent) { //{{AFX_DATA_INIT(CChangePswDlg) m_oldpassword = _T(""); m_newpassword = _T(""); m_qurenpassword = _T(""); //}}AFX_DATA_INIT }
void CChangePswDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CChangePswDlg) DDX_Control(pDX, IDC_EDIT1, m_ctrloldpassword); DDX_Text(pDX, IDC_EDIT1, m_oldpassword); DDX_Text(pDX, IDC_EDIT2, m_newpassword); DDX_Text(pDX, IDC_EDIT3, m_qurenpassword); //}}AFX_DATA_MAP }
BEGIN_MESSAGE_MAP(CChangePswDlg, CDialog) //{{AFX_MSG_MAP(CChangePswDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////// //名称:OnOk //功能:更改用户口令
//////////////////////////////////////////////////////////////////////// void CChangePswDlg::OnOK() { // TODO: Add extra validation here UpdateData(TRUE);//读入用户输入的密码 CDBVariant varValue;///CDBVariant??? A CDBVariant object represents a variant data type for the MFC ODBC classes. CDBVariant is similar to COleVariant; however, CDBVariant does not use OLE. CDBVariant allows you to store a value without worrying about the value’s data type CPswdSet m_recordset(&m_database);//记录及类 CString strSQL; strSQL.Format("select * from password where PASSWORD='%s'",m_oldpassword); m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL); //此处为一种执行SQL语句语法之一,
//int temp=0; //m_recordset.GetFieldValue(temp,varValue); //如果输入的密码与数据库中的不一致,则弹出提示框 if(m_recordset.GetRecordCount()==0)//改点特强 //if(m_oldpassword.Compare(varValue.m_pstring->GetBuffer(1))!=0) { MessageBox("原密码错误!","提示",MB_OK|MB_ICONINFORMATION); m_oldpassword.Empty(); m_newpassword.Empty(); m_qurenpassword.Empty(); m_ctrloldpassword.SetFocus(); UpdateData(FALSE);//清空所输入的内容将变化反映到对话框中 } //如果原密码正确,两次新密码不同 else { if(m_newpassword.Compare(m_qurenpassword)!=0)//比较两个字符串是否相同 { MessageBox("新密码错误!","提示",MB_OK|MB_ICONINFORMATION); m_oldpassword.Empty(); m_newpassword.Empty(); m_qurenpassword.Empty(); UpdateData(FALSE);//清空所输入的内容 } else { strSQL.Format("update password set PASSWORD='%s' where PASSWORD='%s'",m_newpassword,m_oldpassword); m_database.ExecuteSQL(strSQL);//该种执行SQL 语句的最佳且最 容易理解的 方法 , CDialog::OnOK(); MessageBox("恭喜,口令更改成功!下次登录请使用口令: "+m_newpassword+" ","提示",MB_OK|MB_ICONINFORMATION); } } }
///////////////////////////////////////////////////////////////////////// //名称:OnInitDialog //功能:更改口令对话框初始化
//////////////////////////////////////////////////////////////////////// BOOL CChangePswDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_ctrloldpassword.SetFocus();//注意在定义变量时 有一个技巧的, //那就是,可以一个控件有两种类型的 变量, 因为不同类型的 变量有不同的成员函数 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

|