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

📄 product.cpp

📁 仓库管理系统
💻 CPP
字号:
// Product.cpp: implementation of the CProduct class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Stock.h"
#include "Product.h"
#include "ADOConn.h"

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

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

CProduct::CProduct()
{
	Pid = 0;
	Pname = "";
	TypeId = 0;
	Pprice = 0;
	Plow = 0;
	Phigh = 0;

}

CProduct::~CProduct()
{

}

//设置和读取成员变量
int CProduct::GetPid()
{
	return Pid;
}

void CProduct::SetPid(int iPid)
{
	Pid = iPid;
}

CString CProduct::GetPname()
{
	return Pname;
}

void CProduct::SetPname(CString cPname)
{
	Pname = cPname;
}

int CProduct::GetTypeId()
{
	return TypeId;
}

void CProduct::SetTypeId(int iTypeId)
{
	TypeId = iTypeId;
}

float CProduct::GetPprice()
{
	return Pprice;
}

void CProduct::SetPprice(float fPprice)
{
	Pprice = fPprice;
}

int CProduct::GetPlow()
{
	return Plow;
}

void CProduct::SetPlow(int iPlow)
{
	Plow = iPlow;
}

int CProduct::GetPhigh()
{
	return Phigh;
}

void CProduct::SetPhigh(int iPhigh)
{
	Phigh = iPhigh;
}


//数据库操作
int CProduct::HaveName(CString cPname)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM Product WHERE Pname='" + cPname + "'";
	//执行SELETE语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		return -1;
	else
		return 1;
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

int CProduct::HaveType(CString cTypeId)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM Product WHERE TypeId=" + cTypeId;
	//执行SELETE语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		return -1;
	else
		return 1;
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

void CProduct::sql_insert()
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置INSERT语句
	CString strTypeId;
	strTypeId.Format("%d", TypeId);
	CString strPrice;
	strPrice.Format("%f", Pprice);
	CString strPlow;
	strPlow.Format("%d", Plow);
	CString strPhigh;
	strPhigh.Format("%d", Phigh);
//	CString strValid;
//	strValid.Format("%d", Valid);
//	CString strAlarm;
//	strAlarm.Format("%d", AlarmDays);

	_bstr_t vSQL;
	vSQL = "INSERT INTO Product (Pname, TypeId,  Pprice, Plow, Phigh) VALUES('" 
		+ Pname + "'," + strTypeId + "," + strPrice + "," + strPlow + ","
		+ strPhigh + ")";

	
	//执行INSERT语句
	m_AdoConn.ExecuteSQL(vSQL);	
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}
	
void CProduct::sql_update(CString cPid)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置UPDATE语句
	CString strTypeId;
	strTypeId.Format("%d", TypeId);
	CString strPrice;
	strPrice.Format("%f", Pprice);
	CString strPlow;
	strPlow.Format("%d", Plow);
	CString strPhigh;
	strPhigh.Format("%d", Phigh);

	_bstr_t vSQL;
	vSQL = "UPDATE Product SET Pname='" + Pname + "', Pprice=" 
		+ strPrice + ", Plow=" + strPlow + ", Phigh=" + strPhigh
		+ " WHERE Pid=" + cPid;

	
	//执行UPDATE语句
	m_AdoConn.ExecuteSQL(vSQL);	
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}	

void CProduct::sql_delete(CString cPid)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置DELETE语句
	_bstr_t vSQL;
	vSQL = "DELETE FROM Product WHERE Pid=" + cPid;
	//执行DELETE语句
	m_AdoConn.ExecuteSQL(vSQL);	
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

//读取所有字段值
void CProduct::GetData(CString cPid)
{
	//连接数据库
	ADOConn m_AdoConn;
	m_AdoConn.OnInitADOConn();
	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM Product WHERE Pid=" + cPid;
	//执行SELETE语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		CProduct();
	else
	{
		Pid = atoi(cPid);
		Pname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pname");
		TypeId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TypeId"));
		Pprice = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Pprice"));
		Plow = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Plow"));
		Phigh = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phigh"));

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

⌨️ 快捷键说明

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