📄 doctor.cpp
字号:
// Doctor.cpp: implementation of the CDoctor class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "HosptialMan.h"
#include "Doctor.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDoctor::CDoctor()
{
Name = "";
Sex = "男";
Age = 0;
DeptId = 2;
Title = "";
}
CDoctor::~CDoctor()
{
}
// 属性设置
void CDoctor::SetId(int iId)
{
Id = iId;
}
int CDoctor::GetId()
{
return Id;
}
void CDoctor::SetName(CString cName)
{
Name = cName;
}
CString CDoctor::GetName()
{
return Name;
}
void CDoctor::SetSex(CString cSex)
{
Sex = cSex;
}
CString CDoctor::GetSex()
{
return Sex;
}
void CDoctor::SetAge(int iAge)
{
Age = iAge;
}
int CDoctor::GetAge()
{
return Age;
}
void CDoctor::SetDeptId(int iDId)
{
DeptId = iDId;
}
int CDoctor::GetDeptId()
{
return DeptId;
}
void CDoctor::SetTitle(CString cTitle)
{
Title = cTitle;
}
CString CDoctor::GetTitle()
{
return Title;
}
// 插入新的医生信息
void CDoctor::sql_Insert()
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql,cAge,cDId;
_bstr_t bSql;
cAge.Format("%d",Age);
cDId.Format("%d",DeptId);
// 插入语句
cSql = "Insert Into Doctor(Name,Sex,Age,DeptId,Title) Values('"+Name+"','"+Sex+"',";
cSql += cAge+","+cDId+",'"+Title+"')";
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 更改医生信息
void CDoctor::sql_Update(CString cId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql,cAge,cDId;
_bstr_t bSql;
cAge.Format("%d",Age);
cDId.Format("%d",DeptId);
// 插入语句
cSql = "Update Doctor Set Name='"+Name+"',Sex='"+Sex+"',Age="+cAge+",";
cSql += "DeptId="+cDId+",Title='"+Title+"' Where Id="+cId;
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 删除医生信息
void CDoctor::sql_Delete(CString cId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
_bstr_t bSql;
bSql = "Delete From Doctor 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 + -