📄 changepswdlg.cpp
字号:
// ChangepswDlg.cpp : implementation file
//
#include "stdafx.h"
#include "libmis.h"
#include "ChangepswDlg.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_strPsw1 = _T("");
m_strPsw2 = _T("");
m_strPsw3 = _T("");
m_strTitle = _T("");
//}}AFX_DATA_INIT
}
void CChangepswDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChangepswDlg)
DDX_Text(pDX, IDC_EDIT1, m_strPsw1);
DDX_Text(pDX, IDC_EDIT2, m_strPsw2);
DDX_Text(pDX, IDC_EDIT3, m_strPsw3);
DDX_Text(pDX, IDC_NAME, m_strTitle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChangepswDlg, CDialog)
//{{AFX_MSG_MAP(CChangepswDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChangepswDlg message handlers
void CChangepswDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData ();
m_strPsw1.TrimLeft ();
m_strPsw1.TrimRight ();
m_strPsw2.TrimLeft ();
m_strPsw2.TrimRight ();
m_strPsw3.TrimLeft ();
m_strPsw3.TrimRight ();
if (m_strPsw2.Compare (m_strPsw3))
{
AfxMessageBox ("新密码输入不一致!");
return;
}
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSql="SELECT * FROM admin WHERE name='"+m_strName+"' AND password='"+m_strPsw1+"'";
m_pRecordset->Open (_variant_t(strSql),m_pConnection.GetInterfacePtr (),
adOpenStatic,adLockOptimistic,adCmdText);
if (m_pRecordset->adoEOF)
{
AfxMessageBox ("用户名或密码错误!\n");
return;
}
m_pRecordset->PutCollect("name",_variant_t(m_strName));
m_pRecordset->PutCollect("password",_variant_t(m_strPsw2));
m_pRecordset->Update();
m_pRecordset->Close ();
AfxMessageBox ("更改密码成功!");
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
AfxMessageBox (errormessage);
return;
}
CDialog::OnOK();
}
BOOL CChangepswDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_strTitle.Format ("当前用户: \t%s",m_strName);
UpdateData (FALSE);
try
{
if (!m_pConnection.CreateInstance(__uuidof(Connection)))
m_pConnection->Open("Provider=Microsoft.JET.OLEDB.4.0;Data Source=lib.mdb","","",adModeUnknown);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format ("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage ());
AfxMessageBox (errormessage);
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CChangepswDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_pConnection->Close ();
return CDialog::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -