📄 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 = "男";
Marry = "";
}
CPatient::~CPatient()
{
}
// 插入新的患者信息,并返回当前的最大编号
long CPatient::sql_Insert()
{
long iMaxId = 1;
try
{
//连接数据库
_RecordsetPtr m_pRecordset;
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql;
_bstr_t bSql;
// 插入语句
cSql = "Insert Into Patient(Name,IDNum,Sex,Marry) "
" Values('"+Name+"','"+IDNum+"','"+Sex+"','"+Marry+"')";
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
bSql = "Select Max(PatId) AS MaxId From Patient";
// 执行SELETE语句
m_pRecordset = m_AdoConn.GetRecordSet(bSql);
// 如果结果集为空则记录个数为0,否则为100
if(!m_pRecordset->adoEOF)
iMaxId =atol((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 cPatId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql;
_bstr_t bSql;
// 插入语句
cSql = "Update Patient Set Name='"+Name+"',IDNum='"
+IDNum+"',Sex='"+Sex+"',Marry='"+Marry+"' Where PatId="+cPatId;
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 删除患者信息
void CPatient::sql_Delete(CString cPatId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
_bstr_t bSql;
bSql = "Delete From Patient Where PatId="+cPatId;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -