CUer类的代码如下:
// User.cpp: implementation of the CUser class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Library.h"
#include "User.h"
#include "ADOConn.h"
#include "iostream.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CUser::CUser()
{
}
CUser::~CUser()
{
}
CString CUser::GetuserName()
{
return userName;
}
void CUser::SetuserName(CString Uname)
{
userName=Uname;
}
CString CUser::Getpassword()
{
return password;
}
void CUser::Setpassword(CString Upwd)
{
password=Upwd;
}
int CUser::HaveUser(CString name,CString password)
{
ADOConn m_ADOConn;
m_ADOConn.OnInitADOConn();
CString sql;
sql.Format("SELECT*FROM [user] WHERE 用户名='%s' AND 密码='%s'", name,password);
_RecordsetPtr m_pRecordset;
m_pRecordset=m_ADOConn.GetRecordSet((_bstr_t)sql);
if(m_pRecordset->adoEOF)
return -1;
else
return 1;
m_ADOConn.ExitConnect();
}
int CUser::HaveName(CString name)
{
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString sql;
sql.Format("SELECT*FROM [user] WHERE 用户名='%s'",name);
_RecordsetPtr m_pRecordset;
m_pRecordset=m_AdoConn.GetRecordSet((_bstr_t)sql);
if(m_pRecordset->adoEOF)
return -1;
else
return 1;
m_AdoConn.ExitConnect();
}
//添加
void CUser::sql_insert()
{
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
_bstr_t vSQL;
vSQL="INSERT INTO [user] VALUES('" +userName+"','"+ password +"')";
m_AdoConn.ExecuteSQL(vSQL);
m_AdoConn.ExitConnect();
m_AdoConn.ExitConnect();
}
//删除
void CUser::sql_delete(CString username)
{
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString sql;
sql.Format("delete from [user] where 用户名='%s'",username);
m_AdoConn.ExecuteSQL((_bstr_t)sql);
m_AdoConn.ExitConnect();
}
void CUser::sql_updatepwd(CString username)
{
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
_bstr_t vSQL;
vSQL="UPDATE Czyxxb SET Pwd='"+password+"' WHERE CzyName="+" '"+username+"'";
m_AdoConn.ExecuteSQL(vSQL);
m_AdoConn.ExitConnect();
}
在添加的窗体下调用的代码如下:
void CAdd_user_dlg::Onaddok()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_name=="")
{
MessageBox("请输入用户名","图书系统");
return;
}
if(m_pwd=="")
{
MessageBox("请输入密码","图书系统");
return;
}
if(m_pwd1=="")
{
MessageBox("请确认密码","图书系统");
return;
}
if(m_pwd!=m_pwd1)
{
MessageBox("两次密码不同","图书系统");
return;
}
CUser xxb;
if(xxb.HaveName(m_name)==1)// .Havename(name)==1)
{
MessageBox("用户以存在,请重新输入","图书系统系统");
return;
}
xxb.SetuserName(m_name);// .SetUserName(m_name);
xxb.Setpassword(m_pwd);// .SetPwd(m_pwd);
xxb.sql_insert();// .sql_insert();
CDialog::OnOK();
}
希望各位大侠能帮一下忙!
小弟水平不够,还是无非看出来!