📄 customer.cpp
字号:
#include "stdafx.h"
#include "DBuser.h"
#include "Customer.h"
Customer::Customer()
{
pDB = new CDatabase();
try{
if(!pDB->OpenEx("DSN=user"))
AfxMessageBox("Error,Can't open database");
pSet = new CDBuser(pDB);
pSet->Open(CRecordset::dynaset);
}catch(CException *e){
e->ReportError();
}
}
bool Customer::Login(CString user,CString pswd) //用户登录
{
pSet->MoveFirst();
do{
if(pSet->m_ID!=user){
pSet->MoveNext();
continue;
}else if(pSet->m_PSWD==pswd)
return true;
}while(!pSet->IsEOF());
return false;
}
bool Customer::Rigister( //用户注册
CString id,
CString name,
CString sex,
CString adress,
CString email,
CString pswd)
{
int Temp;
Temp=GetMaxNum();
if(pSet->CanAppend()){
pSet->AddNew();
pSet->m_ID = id;
pSet->m_NAME = name;
pSet->m_SEX = sex;
pSet->m_ADRESS = adress;
pSet->m_EMAIL = email;
pSet->m_PSWD = pswd;
pSet->m_NO = Temp+1;
pSet->Update();
return true;
}else
return false;
}
int Customer::GetMaxNum() //获取最大用户数目
{
int i(0);
for(pSet->MoveFirst();!pSet->IsEOF();pSet->MoveNext())
i++;
return i;
}
void Customer::GetInfo() //获取当前用户信息
{
m_ID = pSet->m_ID;
m_NAME = pSet->m_NAME;
m_SEX = pSet->m_SEX;
m_ADRESS = pSet->m_ADRESS;
m_EMAIL = pSet->m_EMAIL;
m_PSWD = pSet->m_PSWD;
}
bool Customer::UpdateProfile( //更新用户信息
CString id,
CString name,
CString sex,
CString adress,
CString email,
CString pswd)
{
if(pSet->CanUpdate())
{
pSet->Edit();
pSet->m_ID = id;
pSet->m_ID = id;
pSet->m_NAME = name;
pSet->m_SEX = sex;
pSet->m_ADRESS = adress;
pSet->m_EMAIL = email;
pSet->m_PSWD = pswd;
pSet->Update();
return true;
}else
return false;
}
CString Customer::TakeExam()
{
this->GetInfo();
return this->m_ID;
}
Customer::~Customer()
{
if(pDB->IsOpen())
pDB->Close();
delete pDB;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -