?? 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 + -