⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userdao.cpp

📁 RFID小区车库管理系统。实现车辆的合法性检查和计费管理。
💻 CPP
字号:
// UserDAO.cpp: implementation of the CUserDAO class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CMS.h"
#include "UserDAO.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};

CUserDAO::CUserDAO(_ConnectionPtr pConnection)
{
	m_pConnection = pConnection;
}

CUserDAO::~CUserDAO()
{

}

bool CUserDAO::SelectByCard(CString strCardID, CString& strUserID, CString& strName)
{
	_RecordsetPtr pRecordset = NULL;
	try
	{
		//创建Command对象
		_CommandPtr pCommand = NULL;
		TESTHR(pCommand.CreateInstance(__uuidof(Command)));
		pCommand->CommandText = "Select_User_By_Card";
		pCommand->CommandType = adCmdStoredProc;
		pCommand->ActiveConnection = m_pConnection;
		
		//添加多个参数
		pCommand->Parameters->Refresh();
		pCommand->Parameters->GetItem(long(1))->Value = (_bstr_t)strCardID;
		
		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		pRecordset = pCommand->Execute(&vNull ,&vNull ,adCmdStoredProc);
		if(pRecordset->adoEOF != FALSE)
		{
			return false;
		}
		else
		{
			strUserID = (char*)(_bstr_t)pRecordset->Fields->GetItem(_variant_t((long)0))->Value;
			strName = (char*)(_bstr_t)pRecordset->Fields->GetItem(_variant_t((long)1))->Value;
		}
	}
	catch(_com_error e)
	{
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());	
		MessageBox(NULL, (LPCSTR)bstrDescription,(LPCSTR)bstrSource,MB_OK);		
	}
	return true;
}

void CUserDAO::InsertUser(CString strUserID, CString strCardID, CString strName, double dSurplus)
{
	try
	{
		//创建Command对象
		_CommandPtr pCommand = NULL;
		TESTHR(pCommand.CreateInstance(__uuidof(Command)));
		pCommand->CommandText = "Insert_User";
		pCommand->CommandType = adCmdStoredProc;
		pCommand->ActiveConnection = m_pConnection;
		
		//添加多个参数
		pCommand->Parameters->Refresh();
		pCommand->Parameters->GetItem(long(1))->Value = (_bstr_t)strUserID;
		pCommand->Parameters->GetItem(long(2))->Value = (_bstr_t)strCardID;
		pCommand->Parameters->GetItem(long(3))->Value = (_bstr_t)strName;
		pCommand->Parameters->GetItem(long(4))->Value = dSurplus;
		
		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		pCommand->Execute(&vNull ,&vNull ,adCmdStoredProc);
	}
	catch(_com_error e)
	{
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());	
		MessageBox(NULL, (LPCSTR)bstrDescription,(LPCSTR)bstrSource,MB_OK);		
	}
}

void CUserDAO::DeleteUser(CString strUserID)
{
	try
	{
		//创建Command对象
		_CommandPtr pCommand = NULL;
		TESTHR(pCommand.CreateInstance(__uuidof(Command)));
		pCommand->CommandText = "Delete_User";
		pCommand->CommandType = adCmdStoredProc;
		pCommand->ActiveConnection = m_pConnection;
		
		//添加多个参数
		pCommand->Parameters->Refresh();
		pCommand->Parameters->GetItem((long)1)->Value = (_bstr_t)strUserID;
		
		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		pCommand->Execute(&vNull ,&vNull ,adCmdStoredProc);
	}
	catch(_com_error e)
	{
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());	
		MessageBox(NULL, (LPCSTR)bstrDescription,(LPCSTR)bstrSource,MB_OK);		
	}
}

void CUserDAO::UpdateUser(CString strUserID, CString strName, double dSurplus)
{
	try
	{		
		//创建Command对象
		_CommandPtr pCommand = NULL;
		TESTHR(pCommand.CreateInstance(__uuidof(Command)));
		pCommand->CommandText = "Update_User";
		pCommand->CommandType = adCmdStoredProc;
		pCommand->ActiveConnection = m_pConnection;
		
		//添加多个参数
		pCommand->Parameters->Refresh();
		pCommand->Parameters->Item[_variant_t((long)1)]->Value = (_bstr_t)strUserID;
		pCommand->Parameters->Item[_variant_t((long)2)]->Value = (_bstr_t)strName;
		pCommand->Parameters->Item[_variant_t((long)3)]->Value = dSurplus;

		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		pCommand->Execute(&vNull ,&vNull ,adCmdStoredProc);
	}
	catch(_com_error e)
	{
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());	
		MessageBox(NULL, (LPCSTR)bstrDescription,(LPCSTR)bstrSource,MB_OK);		
	}
}

bool CUserDAO::SelectUser(CString strUserID, CString& strCardID, CString& strName, double& dSurplus)
{
	_RecordsetPtr pRecordset = NULL;
	_CommandPtr pCommand = NULL;
	try
	{
		//创建Command对象
		TESTHR(pCommand.CreateInstance(__uuidof(Command)));
		pCommand->CommandText = "Select_User";
		pCommand->CommandType = adCmdStoredProc;
		pCommand->ActiveConnection = m_pConnection;
		
		//添加多个参数
		pCommand->Parameters->Refresh();
		pCommand->Parameters->Item[_variant_t((long)1)]->Value = (_bstr_t)strUserID;

		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		TESTHR(pRecordset.CreateInstance(__uuidof(Recordset)));
		pRecordset = pCommand->Execute(&vNull ,&vNull ,adCmdStoredProc);
		if(pRecordset->adoEOF == TRUE)
		{
			return false;
		}
		strCardID = (char*)(_bstr_t)pRecordset->Fields->GetItem(_variant_t((long)1))->Value;
		strName = (char*)(_bstr_t)pRecordset->Fields->GetItem(_variant_t((long)2))->Value;
		dSurplus = pRecordset->Fields->GetItem(_variant_t((long)3))->Value;
	}
	catch(_com_error e)
	{
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
		MessageBox(NULL, (LPCSTR)bstrDescription,(LPCSTR)bstrSource,MB_OK);		
	}
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -