?? 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;
// 執(zhí)行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 + -