📄 type.cpp
字号:
// Type.cpp: implementation of the CType class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AssetsMan.h"
#include "ADOConn.h"
#include "Type.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CType::CType()
{
m_TypeId = 0;
m_TypeName = "";
}
CType::~CType()
{
}
void CType::SetTypeId(int iTypeId)
{
m_TypeId = iTypeId;
}
int CType::GetTypeId()
{
return m_TypeId;
}
void CType::SetTypeName(CString cTypeName)
{
m_TypeName = cTypeName;
}
CString CType::GetTypeName()
{
return m_TypeName;
}
// ******插入类别名称*******//
void CType::Insert()
{
try
{
//连接数据库
ADOConn adoConn;
_bstr_t bSQL;
bSQL = "Insert Into Type(TypeName) Values('"+m_TypeName+"')";
adoConn.ExecuteSQL(bSQL);
//断开与数据库的连接
adoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// ******更新类别名称*******//
void CType::Update(CString cTypeId)
{
try
{
//连接数据库
ADOConn adoConn;
_bstr_t bSQL;
bSQL = "Update Type Set TypeName='"+m_TypeName+
"' Where TypeId="+cTypeId;
adoConn.ExecuteSQL(bSQL);
//断开与数据库的连接
adoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// ******删除类别*******//
void CType::Delete(CString cTypeId)
{
try
{
//连接数据库
ADOConn adoConn;
_bstr_t bSQL;
bSQL = "Delete From Type Where TypeId="+cTypeId;
adoConn.ExecuteSQL(bSQL);
//断开与数据库的连接
adoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.Description());
}
}
// ******判断是否存在相同的类别名称*******//
int CType::HaveName(CString cTypeName)
{
int iRet = -1;
try
{
_RecordsetPtr pRecordset;
// 连接数据库
ADOConn adoConn;
_bstr_t bSQL;
bSQL = "Select * From Type Where TypeName='" + cTypeName + "'";
// 执行SELETE语句
pRecordset = adoConn.GetRecordSet(bSQL);
// 如果adoEOF属性为真,表示存在相同名称的类别信息,返回1,否则返回-1
if (pRecordset->adoEOF)
iRet = -1;
else
iRet = 1;
//断开与数据库的连接
adoConn.ExitConnect();
}
// 捕捉异常
catch(_com_error e)
{
iRet = -1;
// 显示错误信息
AfxMessageBox(e.Description());
}
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -