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

📄 registration.cpp

📁 医院管理系统在CV++条件下的完整性开发>>>
💻 CPP
字号:
// Registration.cpp: implementation of the CRegistration class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HosptialMan.h"
#include "Registration.h"
#include "PayItems.h"
#include "ADOConn.h"
#include "COMDEF.H"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRegistration::CRegistration()
{
	RegId = 0;
	PatId = 0;
	DocId = 0;
	UserName = "";
	RegDate = "";
}

CRegistration::~CRegistration()
{

}

// 属性设置
void CRegistration::SetRegId(int iRId)
{
	RegId = iRId;
}

int CRegistration::GetRegId()
{
	return RegId;
}

void CRegistration::SetPatId(int iPId)
{
	PatId = iPId;
}

int CRegistration::GetPatId()
{
	return PatId;
}

void CRegistration::SetDocId(int iDId)
{
	DocId = iDId;
}

int CRegistration::GetDocId()
{
	return DocId;
}

void CRegistration::SetUserName(CString cName)
{
	UserName = cName;
}
CString CRegistration::GetUserName()
{
	return UserName;
}

void CRegistration::SetRegDate(CString cDate)
{
	RegDate = cDate;
}

CString CRegistration::GetRegDate()
{
	return RegDate;
}

//********方法:更新、删除等*********//
void CRegistration::sql_Update(CString cRId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置UPDATE语句, 将数值转换为字符串
		CString cSql,cPId,cDId,cDate;
		_bstr_t bSql;
		cPId.Format("%d",PatId);
		cDId.Format("%d",DocId);
		// 定义时间对象,取得当前日期
		CTime t = CTime::GetCurrentTime();
		cDate.Format(_T("%04d-%02d-%02d"),t.GetYear(),t.GetMonth(),t.GetDay());
		// 更新语句
		cSql = "Update Registration Set PatId="+cPId+",DocId="+cDId+",";
		cSql += "UserName='"+UserName+"',RegDate='"+cDate+"' Where RegId="+cRId;
		bSql = (LPCTSTR)(_bstr_t)cSql;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

void CRegistration::sql_Delete(CString cRId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置Delete语句
		_bstr_t bSql;
		bSql = "Delete From Registration Where RegId="+cRId;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();

		//删除表PayItems中的对应记录
		CPayItems pay;
		pay.sql_DeleteRecords(cRId);
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

int CRegistration::GetMaxId()
{
	try
	{
		int iCnt,iMaxId = 0;
		_variant_t vCnt,vMaxId;
		// 指明数据类型为整型
		vCnt.vt = VT_I4;
		vMaxId.vt = VT_I4;
		CString cMid;
		_RecordsetPtr m_pRecordset;
		// 连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSQL;
		bSQL = "Select COUNT(*) AS cnt,MAX(RegId) AS MaxId From Registration";
		// 执行SELETE语句
		m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
		// 如果结果集为空则返回1
		vCnt = m_pRecordset->GetCollect("cnt");
		iCnt = vCnt.lVal;
		if(iCnt==0)
			iMaxId = 1;
		else
		{
			vMaxId = m_pRecordset->GetCollect("MaxId");
			iMaxId = vMaxId.lVal;
			iMaxId++;
		}
		cMid.Format("%d",iMaxId);
		// 插入新记录并返回子记录编号
		bSQL = "INSERT INTO Registration(RegId) Values("+cMid+")";
//		AfxMessageBox(bSQL);
		m_AdoConn.ExecuteSQL(bSQL);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
		return iMaxId;
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		return -1;
		AfxMessageBox(e.Description());
	}
}

⌨️ 快捷键说明

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