// changingpswdlg.cpp: importation file //
#include "stdafx.h" #include "address.h" #include "changepswdlg.h" #include "pswdset.h"
#ifdef _debug # define new debug_new # undef this_filestatic 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_MAPEND_MESSAGE_MAP ()
/// Name: Onok // Function: Change user password
Void cchangepswdlg :: onok () {// Todo: add extra validation here updata (true); // read the password entered by the user 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);. // record and class CString strSQL; strSQL.Format ( " Select * from password where password = '% s' ", m_eldpassword); m_recordset.open (AFX_DB_USE_DEFAULT_TYPE, STRSQL); // This is one of the syntax of SQL statement,
// int temp = 0; //m_recordset.getfieldValue (temp, varch "; // If the input password is inconsistent with the database, pop up the prompt box if (m_recordset.getRecordcount () == 0) // Change special Strong //iF (M_OLDPASSWORD.Compare (VARVALUE.M_PSTRING "{MessageBox (" Original Password Error! "," Tips ", MB_OK | MB_ICONITIONS; M_OLDPASSWORD.EMPTY (); m_newpassword. Empty (); m_qurenpassword.empty (); m_ctrloldpassword.setfocus (); Updatedata (false); // Empty The content entered will be reflected in the dialog box} // If the original password is correct, the new password is different Else { IF (m_newpassword.com)! = 0) // Compares whether the two strings are the same {MessageBox ("new password error!", "prompt", MB_OK | MB_ICONITION (M_OLDPASSWORD.EMPTY (); m_newpassword.empty ( ); M_qurenpassword.empty (); Updatedata (false); // Clear the input content} else {strsql.format ("Update Password = '% s'" ", m_newpassword, m_oldpassword) M_Database.executesql (strsql); // This kind of implementation of the best and easier understanding of the SQL statement, cdialog :: onok (); MessageBox ("Congratulations, password changes! Please use the password next time:" M_NewPassword "", "Tips", MB_ok | MB_ICONIONFORMATION);}}} /// Name: OnInitDialog // Function: Change Password dialog initialization
Bool cchangepswdlg :: OnNitDialog () {cdialog :: OnItDialog (); // Todo: add extra initialization her_ctrloldpassword.setfocus (); // Note There is a trick when defining variables, // That is, you can have a control Two types of variables, because different types of variables have different member functions return true; // return true unsses you set the focus to a control // Exception: OCX Property Pages Should Return False}