📄 goods.cpp
字号:
// Goods.cpp: implementation of the CGoods class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PosClient.h"
#include "Goods.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGoods::CGoods()
{
gName = "";
gPrice = 0.0;
gId = "";
gType=0;
}
CGoods::~CGoods()
{
}
CString CGoods::GetGoodsName()
{
return gName;
}
void CGoods::SetGoodsName(CString gGoodsName)
{
gName = gGoodsName;
}
float CGoods::GetGoodsPrice()
{
return gPrice;
}
void CGoods::SetGoodPrice(float gGoodsPrice)
{
gPrice = gGoodsPrice;
}
int CGoods::GetGoodsType()
{
return gType;
}
void CGoods::SetGoodsType(int gGoodsType)
{
gType = gGoodsType;
}
void CGoods::SetGoodsId(CString gGoodsId)
{
gId=gGoodsId;
}
CString CGoods::GetGoodsId()
{
return gId;
}
void CGoods::SetGoodsNum(int i)
{
gNum=i;
}
int CGoods::GetGoodsNum()
{
return gNum;
}
//数据库操作
int CGoods::HaveId(CString gGoodsId)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM goods WHERE goodsID='" + gGoodsId + "'";
//执行SELECT语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CGoods::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strPrice,strType,strNum;
strPrice.Format("%f",gPrice);
strType.Format("%d", gType);
strNum.Format("%d",gNum);
_bstr_t vSQL;
vSQL = "INSERT INTO goods VALUES('" + gId + "','" + gName + "','" + strPrice + "',"
+ strType + "," + strNum + ")";
//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CGoods::sql_updatePrice(float gGoodsPrice)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString strPrice;
strPrice.Format("%f",gGoodsPrice);
_bstr_t vSQL;
vSQL = "UPDATE goods SET goodsPRICE='" + strPrice + "' WHERE gGoodsId='" + gId + "'";
//执行UPDATE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CGoods::sql_delete(CString gGoodsId)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM goods WHERE userID='" + gGoodsId + "'";
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CGoods::sql_delall()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE * FROM goods";
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
//根据员工编号读取所有字段值
void CGoods::GetData(CString gGoodsId)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM goods WHERE goodsID='" + gGoodsId + "'";
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
//返回各列的值
if (m_pRecordset->adoEOF)
CGoods();
else
{
gId = gGoodsId;
gName = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("goodsNAME");
gPrice = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("goodsPRICE"));
gType = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("goodsTYPE"));
gNum = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("goodsNUM"));
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CGoods::UpdateNum(int i,CString id)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString s;
s.Format("%d",i);
_bstr_t vSQL;
vSQL = "UPDATE goods SET goodsNUM=" + s + " WHERE goodsId='" + id + "'";
//执行UPDATE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -