📄 thr_dialog3.cpp
字号:
// thr_dialog3.cpp : implementation file
//
#include "stdafx.h"
#include "医药管理系统.h"
#include "thr_dialog3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// thr_dialog dialog
thr_dialog::thr_dialog(CWnd* pParent /*=NULL*/)
: CDialog(thr_dialog::IDD, pParent)
{
//{{AFX_DATA_INIT(thr_dialog)
m_oldusername = _T("");
m_newpassword = _T("");
m_password = _T("");
//}}AFX_DATA_INIT
}
void thr_dialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(thr_dialog)
DDX_Text(pDX, IDC_EDIT1, m_oldusername);
DDX_Text(pDX, IDC_EDIT3, m_newpassword);
DDX_Text(pDX, IDC_EDIT2, m_password);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(thr_dialog, CDialog)
//{{AFX_MSG_MAP(thr_dialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// thr_dialog message handlers
void thr_dialog::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
bool modify=false;
CDatabase m_userBase;
CRecordset m_userRecordset;
int i,count1=0,count2=0,count3=0;
CString str1,str2,strSQL,a1,a2;
if(!m_userBase.IsOpen()) //连接数据库
{
m_userBase.Open("users");
m_userRecordset.m_pDatabase=&m_userBase;
}
strSQL.Format("select * from yonghuming");
m_userRecordset.Open(CRecordset::forwardOnly,strSQL);
for(i=0;i<m_userRecordset.GetRecordCount();i++)
{
m_userRecordset.GetFieldValue("username",str1);
//m_user.InsertItem(i,str);
m_userRecordset.GetFieldValue("password",str2);
//AfxMessageBox(str1);
if(thr_dialog::m_oldusername==str1)
{
if(thr_dialog::m_password==str2)
{
if(thr_dialog::m_newpassword!=str2)
{
modify=true;
a1=str1;
a2=m_newpassword;
AfxMessageBox(a1);
AfxMessageBox(a2);
// strSQL.Format("update yonghuming set password='"+thr_dialog::m_newpassword+"' where username='"+str1+"'");
// m_userRecordset.Open(CRecordset::forwardOnly,strSQL);
}
else
{
count3++;
}
}
else
{
count2++;
}
}
else
{
count1++;
m_userRecordset.MoveNext();
continue;
}
//m_user.SetItemText(i,1,str);
m_userRecordset.MoveNext();
}
if(count1==m_userRecordset.GetRecordCount())
AfxMessageBox("你输入的用户名不存在或者不能为空!!请重新输入!");
if(count2==1)
AfxMessageBox("你的用户名或密码错误!!请重新输入!");
if(count3==1)
AfxMessageBox("你输入的密码一致,请重新输入你所要修改的密码!");
if(modify==true){
/* strSQL.Format("update yonghuming set password='"+thr_dialog::m_newpassword+"' where username='"+str1+"'");
m_userRecordset.Open(CRecordset::forwardOnly,strSQL);
for(i=0;i<m_userRecordset.GetRecordCount();i++)
{
m_userRecordset.GetFieldValue("username",str1);
//m_user.InsertItem(i,str);
m_userRecordset.GetFieldValue("password",str2);
//AfxMessageBox(str1);
if(str1==thr_dialog::m_oldusername&&str2==thr_dialog::m_newpassword)
AfxMessageBox("修改成功!");
else
AfxMessageBox("修改失败!");
m_userRecordset.MoveNext();
}*/
}
m_userRecordset.Close();
m_userBase.Close();
/* if(modify==true)
{
CString strname;
try
{
strname.Format("Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=User;Initial Catalog=users");
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect=strname;
m_pConnection->Open(strConnect,"","",0);//链接数据库
_bstr_t bstrSQL = "update yonghuming set password='"+thr_dialog::m_newpassword+"' where username='"+str1+"'";
//_bstr_t bstrSQL = "delete from score where Sno=1";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
//if(m_pRecordset!=NULL)
//m_pRecordset->Close();
//m_pConnection->Close();
AfxMessageBox("操作成功");
}
catch(...)
{
AfxMessageBox("操作失败");//e.Description()
}
}*/
UpdateData(false);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -