📄 patient.cpp
字号:
// Patient.cpp: implementation of the CPatient class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "HosptialMan.h"
#include "ADOConn.h"
#include "Patient.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPatient::CPatient()
{
Name = "";
IDNum = "";
Sex = "男";
Age = 0;
Marry = "";
}
CPatient::~CPatient()
{
}
// 属性设置
void CPatient::SetId(int iId)
{
Id = iId;
}
int CPatient::GetId()
{
return Id;
}
void CPatient::SetName(CString cName)
{
Name = cName;
}
CString CPatient::GetName()
{
return Name;
}
void CPatient::SetIDNum(CString cIDNum)
{
IDNum = cIDNum;
}
CString CPatient::GetIDNum()
{
return IDNum;
}
void CPatient::SetSex(CString cSex)
{
Sex = cSex;
}
CString CPatient::GetSex()
{
return Sex;
}
void CPatient::SetAge(int iAge)
{
Age = iAge;
}
int CPatient::GetAge()
{
return Age;
}
void CPatient::SetMarry(CString cMarry)
{
Marry = cMarry;
}
CString CPatient::GetMarry()
{
return Marry;
}
// 插入新的患者信息,并返回当前的最大编号
int CPatient::sql_Insert()
{
int iMaxId = 1;
try
{
//连接数据库
_RecordsetPtr m_pRecordset;
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql,cAge;
_bstr_t bSql;
cAge.Format("%d",Age);
// 插入语句
cSql = "Insert Into Patient(Name,IDNum,Sex,Age,Marry) Values('"+Name+"','"+IDNum+"','";
cSql += Sex+"',"+cAge+",'"+Marry+"')";
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
bSql = "Select Max(Id) AS MaxId From Patient";
// 执行SELETE语句
m_pRecordset = m_AdoConn.GetRecordSet(bSql);
// 如果结果集为空则记录个数为0,否则为100
if(!m_pRecordset->adoEOF)
iMaxId =atoi((char*)_bstr_t(m_pRecordset->GetCollect("MaxId"))); //断开与数据库的连接
m_AdoConn.ExitConnect();
return iMaxId;
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
return iMaxId;
}
// 更改患者信息
void CPatient::sql_Update(CString cId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql,cAge;
_bstr_t bSql;
cAge.Format("%d",Age);
// 插入语句
cSql = "Update Patient Set Name='"+Name+"',IDNum='"+IDNum+"',Sex='"+Sex+"',";
cSql += "Age="+cAge+",Marry='"+Marry+"' Where Id="+cId;
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 删除患者信息
void CPatient::sql_Delete(CString cId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
_bstr_t bSql;
bSql = "Delete From Patient Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -