Storehouse.cpp
资源名称:SQLVC.rar [点击查看]
上传用户:biney012
上传日期:2022-05-09
资源大小:4592k
文件大小:3k
源码类别:
数据库系统
开发平台:
Visual C++
- // Storehouse.cpp: implementation of the CStorehouse class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Stock.h"
- #include "Storehouse.h"
- #include "ADOConn.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CStorehouse::CStorehouse()
- {
- Sid = 0;
- Sname = "";
- Memo = "";
- }
- CStorehouse::~CStorehouse()
- {
- }
- //设置和读取成员变量值
- int CStorehouse::GetSid()
- {
- return Sid;
- }
- void CStorehouse::SetSid(int iSid)
- {
- Sid = iSid;
- }
- CString CStorehouse::GetSname()
- {
- return Sname;
- }
- void CStorehouse::SetSname(CString cSname)
- {
- Sname = cSname;
- }
- CString CStorehouse::GetMemo()
- {
- return Memo;
- }
- void CStorehouse::SetMemo(CString cMemo)
- {
- Memo = cMemo;
- }
- //数据库操作
- int CStorehouse::HaveName(CString cSname)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置SELECT语句
- _bstr_t vSQL;
- vSQL = "SELECT * FROM Storehouse WHERE Sname='" + cSname + "'";
- //执行SELETE语句
- _RecordsetPtr m_pRecordset;
- m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
- //返回各列的值
- if (m_pRecordset->adoEOF)
- return -1;
- else
- return 1;
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CStorehouse::sql_insert()
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置INSERT语句
- _bstr_t vSQL;
- vSQL = "INSERT INTO Storehouse (Sname, Memo) VALUES('" + Sname + "','" + Memo + "')";
- //执行INSERT语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CStorehouse::sql_update(CString cSid)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置UPDATE语句
- _bstr_t vSQL;
- vSQL = "UPDATE Storehouse SET Sname='" + Sname + "', Memo='" + Memo
- + "' WHERE Sid=" + cSid;
- //执行UPDATE语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CStorehouse::sql_delete(CString cSid)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置DELETE语句
- _bstr_t vSQL;
- vSQL = "DELETE FROM Storehouse WHERE Sid=" + cSid;
- //执行DELETE语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- //根据客户编号读取所有字段值
- void CStorehouse::GetData(CString cSid)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置SELECT语句
- _bstr_t vSQL;
- vSQL = "SELECT * FROM Storehouse WHERE Sid=" + cSid;
- //执行SELETE语句
- _RecordsetPtr m_pRecordset;
- m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
- //返回各列的值
- if (m_pRecordset->adoEOF)
- CStorehouse();
- else
- {
- Sid = atoi(cSid);
- Sname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Sname");
- Memo = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Memo");
- }
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }