📄 basetype.cpp
字号:
// BaseType.cpp: implementation of the CBaseType class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "HosptialMan.h"
#include "BaseType.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBaseType::CBaseType()
{
Id = 0;
TypeId = 0;
TypeName = "";
}
CBaseType::~CBaseType()
{
}
//****************属性设置**************//
// 类型编号
void CBaseType::SetId(int iId)
{
Id = iId;
}
int CBaseType::GetId()
{
return Id;
}
// 所属类别分为3种:1-科室;2-药品类别;3-药品单位
void CBaseType::SetTypeId(int iTid)
{
TypeId = iTid;
}
int CBaseType::GetTypeId()
{
return TypeId;
}
// 名称
void CBaseType::SetTypeName(CString cTName)
{
TypeName = cTName;
}
CString CBaseType::GetTypeName()
{
return TypeName;
}
// 插入新的类型
void CBaseType::sql_Insert()
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置INSERT语句, 将数值转换为字符串
CString cSql,cTypeId;
_bstr_t bSql;
cTypeId.Format("%d",TypeId);
// 插入语句
cSql = "Insert Into BaseType(TypeId,TypeName) Values("+cTypeId+",'"+TypeName+"')";
bSql = (LPCTSTR)(_bstr_t)cSql;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 更改类型信息
void CBaseType::sql_Update(CString cId)
{
try
{
//连接数据库
ADOConn m_AdoConn;
//设置UPDATE语句, 将数值转换为字符串
_bstr_t bSql;
// 更新语句
bSql = "Update BaseType Set TypeName='"+TypeName+"' Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 删除类型
void CBaseType::sql_Delete(CString cId)
{
try
{
// 连接数据库
ADOConn m_AdoConn;
// 设置DELETE语句
_bstr_t bSql;
bSql = "Delete From BaseType Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// 判断在表中是否已经存在此类别的名称
BOOL CBaseType::HaveTypeName(CString cTId)
{
try
{
long lRscnt = 0;
_RecordsetPtr m_pRecordset;
// 连接数据库
ADOConn m_AdoConn;
_bstr_t bSQL;
bSQL = "Select * From BaseType Where TypeName='"+TypeName+"' And TypeId="+cTId;
// 执行SELETE语句
m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
// 如果结果集为空则记录个数为0,否则为100
if(m_pRecordset->adoEOF)
lRscnt = 0;
else
lRscnt = 100;
//断开与数据库的连接
m_AdoConn.ExitConnect();
// 如果记录个数大于0,表示存在相同名称的类别信息,返回true
if(lRscnt>0)
return true;
else
return false;
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -