22,210
社区成员
发帖
与我相关
我的任务
分享
void CMyDialog::OnOK() //用户登录界面,确定按钮
{
// TODO: Add extra validation here
CString Username,Password;
m_username.GetWindowText(Username);
m_password.GetWindowText(Password);
if(!m_database.IsOpen())
{
if(m_database.Open(_T("student")))
{
m_recordset.m_pDatabase=&m_database;
CString strSQL;
strSQL.Format("select * from [User] where User_name='%s' and User_password='%s'",Username,Password);
m_recordset.Open(CRecordset::forwardOnly,strSQL);
if(m_recordset.GetRecordCount()==0)
{
MessageBox("用户名或密码错误!","错误!",MB_OK|MB_ICONWARNING);
m_password.SetWindowText("");
m_password.SetFocus();
}
else
{
//m_recordset.GetFieldValue("");
CDialog::OnOK();
}
}
m_recordset.Close();
m_database.Close();
}
else
{
MessageBox("不能打开数据库!");
}
//CDialog::OnOK();
}
void CPasswordDlg::OnOK() //修改密码界面,确定按钮
{
// TODO: Add extra validation here
CString Username,Password,Newpassword,Confirmpassword;
m_username.GetWindowText(Username);
m_password.GetWindowText(Password);
m_new.GetWindowText(Newpassword);
m_confirm.GetWindowText(Confirmpassword);
CDatabase m_database;
CRecordset m_recordset;
if(Newpassword.IsEmpty()||Confirmpassword.IsEmpty())
{
MessageBox("密码不能为空!");
}
else
{
if(Newpassword!=Confirmpassword)
{
MessageBox("两次密码不一致,请重新输入密码");
m_new.SetWindowText("");
m_confirm.SetWindowText("");
m_new.SetFocus();
}
else
{
if(!m_database.IsOpen())
{
if(m_database.Open(_T("student")))
{
m_recordset.m_pDatabase=&m_database;
CString strSQL;
strSQL.Format("select * from [User] where User_name='%s' and User_password='%s'",Username,Password);
m_recordset.Open(CRecordset::forwardOnly,strSQL);
if(m_recordset.GetRecordCount()==0)
{
MessageBox("用户名或密码错误!","错误!",MB_OK|MB_ICONWARNING);
m_password.SetWindowText("");
m_new.SetWindowText("");
m_confirm.SetWindowText("");
m_password.SetFocus();
}
else
{
strSQL.Format("update [User] set User_password='%s' where User_name='%s'",Newpassword,Username);
m_database.ExecuteSQL(strSQL);
MessageBox("修改密码成功");
CDialog::OnOK();
}
m_recordset.Close();
m_database.Close();
}
else
{
MessageBox("不能打开数据库!");
}
}
}
}
}