product.cpp

来自「玩具百货公司销售进货记录系统!界面比较齐全,功能完善」· C++ 代码 · 共 84 行

CPP
84
字号
// Product.cpp: implementation of the CProduct class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "heavenmis.h"
#include "Product.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CProduct::CProduct()
{
	m_curAmount=0;
	m_Name="";
	m_Descripion="";
}
CProduct::~CProduct()
{
}
long CProduct::GetKeyByName(CString name)
{
	CADORecordset* pRs=new CADORecordset(((CHeavenMISApp*)AfxGetApp())->pDB);
	CString strSQL;
	strSQL.Format("select ProductID from tbProduct where Name='%s'",name);
	pRs->Open(strSQL,CADORecordset::openQuery);
	long key;
	if(pRs->GetRecordCount()==1)
	{
		pRs->GetFieldValue("ProductID",key);
	}
	else key=-1;

	pRs->Close();
	delete pRs;
	return key;
}

long CProduct::GetAmountByName(CString name)
{
	CADORecordset* pRs=new CADORecordset(((CHeavenMISApp*)AfxGetApp())->pDB);
	CString strSQL;
	strSQL.Format("select CurAmount from tbProduct where Name='%s'",name);
	pRs->Open(strSQL,CADORecordset::openQuery);
	long amount;
	if(pRs->GetRecordCount()==1)
	{
		pRs->GetFieldValue("CurAmount",amount);
	}
	else amount=-1;
	
	pRs->Close();
	delete pRs;
	return amount;
}
void CProduct::SetAmountByName(CString name)
{
	CString strSQL;
	strSQL.Format("update tbProduct set CurAmount=%d where Name='%s'",m_curAmount,name);
	((CHeavenMISApp*)AfxGetApp())->pDB->Execute(strSQL);
}

void CProduct::AddRecord()
{
	CADORecordset* pRs=new CADORecordset(((CHeavenMISApp*)AfxGetApp())->pDB);
	CString strSQL;
	strSQL.Format("select * from tbProduct");
	pRs->Open(strSQL,CADORecordset::openQuery);
	pRs->AddNew();
	pRs->SetFieldValue("Name",m_Name);
	pRs->SetFieldValue("CurAmount",m_curAmount);
	pRs->SetFieldValue("Descripion",m_Descripion);
	pRs->Update();
	pRs->Close();
	delete pRs;
}

⌨️ 快捷键说明

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