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

📄 medicine.cpp

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

#include "stdafx.h"
#include "HosptialMan.h"
#include "ADOConn.h"
#include "Medicine.h"

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

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

CMedicine::CMedicine()
{

}

CMedicine::~CMedicine()
{

}
// 属性
void CMedicine::SetMedId(int iMId)
{
	MedId = iMId;
}
int CMedicine::GetMedId()
{
	return MedId;
}
void CMedicine::SetMedName(CString cName)
{
	MedName = cName;
}
CString CMedicine::GetMedName()
{
	return MedName;
}
void CMedicine::SetTypeId(int iTId)
{
	TypeId = iTId;
}
int CMedicine::GetTypeId()
{
	return TypeId;
}
void CMedicine::SetUnitId(int iUId)
{
	UnitId = iUId;
}
int CMedicine::GetUnitId()
{
	return UnitId;
}
void CMedicine::SetBuyPrice(float fBPrc)
{
	BuyPrice = fBPrc;
}
float CMedicine::GetBuyPrice()
{
	return BuyPrice;
}
void CMedicine::SetSalePrice(float fSPrc)
{
	SalePrice = fSPrc;
}
float CMedicine::GetSalePrice()
{
	return SalePrice;
}
void CMedicine::SetTotal(float fTotal)
{
	Total = fTotal;
}
float CMedicine::GetTotal()
{
	return Total;
}
void CMedicine::SetFlag(int iFlag)
{
	Flag = iFlag;
}
int CMedicine::GetFlag()
{
	return Flag;
}
//*******************************************************//
// 插入新的药物信息
void CMedicine::sql_Insert()
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置INSERT语句, 将数值转换为字符串
		CString cSql,cTId,cTotal,cUId,cBPrc,cSPrc,cFg;
		_bstr_t bSql;
		cTId.Format("%d",TypeId);
		cTotal.Format("%f",Total);
		cUId.Format("%d",UnitId);
		cBPrc.Format("%f",BuyPrice);
		cSPrc.Format("%f",SalePrice);
		cFg.Format("%f",Flag);
		// 插入语句
		cSql = "Insert Into Medicine(MedName,TypeId,Total,UnitId,BuyPrice,SalePrice,Flag) Values('";
		cSql += MedName+"',"+cTId+","+cTotal+","+cUId+","+cBPrc+","+cSPrc+","+cFg+")";
//		AfxMessageBox(cSql);
		bSql = (LPCTSTR)(_bstr_t)cSql;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
// 更改药物信息
void CMedicine::sql_Update(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置Update语句, 将数值转换为字符串
		CString cSql,cTId,cTotal,cUId,cBPrc,cSPrc,cFg;
		_bstr_t bSql;
		cTId.Format("%d",TypeId);
		cTotal.Format("%f",Total);
		cUId.Format("%d",UnitId);
		cBPrc.Format("%f",BuyPrice);
		cSPrc.Format("%f",SalePrice);
		cFg.Format("%d",Flag);
		// 更新语句
		cSql = "Update Medicine Set MedName='"+MedName+"',TypeId="+cTId+",Total="+cTotal+",";
		cSql += "UnitId="+cUId+",BuyPrice="+cBPrc+",SalePrice="+cSPrc+",";
		cSql += "Flag="+cFg+" Where MedId="+cId;
		bSql = (LPCTSTR)(_bstr_t)cSql;
//		AfxMessageBox(cSql);
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
// 删除药物信息
void CMedicine::sql_Delete(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置删除语句, 将数值转换为字符串
		_bstr_t bSql;
		bSql = "Delete From Medicine Where MedId="+cId;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

int CMedicine::HaveName(CString cName)
{	
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM Medicine WHERE MedName='" + cName + "'";
	
	//执行SELECT语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
	if (m_pRecordset->adoEOF)
		return -1;
	else
		return 1;

	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

⌨️ 快捷键说明

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