ProType.cpp
资源名称:final.rar [点击查看]
上传用户:fangwenmm
上传日期:2014-06-18
资源大小:6955k
文件大小:4k
源码类别:
企业管理
开发平台:
Visual C++
- // ProType.cpp: implementation of the CProType class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Stock.h"
- #include "ProType.h"
- #include "ADOConn.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CProType::CProType()
- {
- TypeId = 0;
- TypeName = "";
- UpperId = 0;
- }
- CProType::~CProType()
- {
- }
- //读取和设置成员变量
- int CProType::GetTypeId()
- {
- return TypeId;
- }
- void CProType::SetTypeId(int iTypeId)
- {
- TypeId = iTypeId;
- }
- CString CProType::GetTypeName()
- {
- return TypeName;
- }
- void CProType::SetTypeName(CString cTypeName)
- {
- TypeName = cTypeName;
- }
- int CProType::GetUpperId()
- {
- return UpperId;
- }
- void CProType::SetUpperId(int iUpperId)
- {
- UpperId = iUpperId;
- }
- //数据库操作
- int CProType::HaveName(CString cTypeName)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置SELECT语句
- _bstr_t vSQL;
- vSQL = "SELECT * FROM ProType WHERE TypeName='" + cTypeName + "'";
- //执行SELETE语句
- _RecordsetPtr m_pRecordset;
- m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
- //返回各列的值
- if (m_pRecordset->adoEOF)
- return -1;
- else
- return 1;
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- int CProType::HaveSon(CString cTypeId)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置SELECT语句
- _bstr_t vSQL;
- vSQL = "SELECT * FROM ProType WHERE UpperId=" + cTypeId;
- //执行SELETE语句
- _RecordsetPtr m_pRecordset;
- m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
- //返回各列的值
- if (m_pRecordset->adoEOF)
- return -1;
- else
- return 1;
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CProType::sql_insert()
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置INSERT语句
- CString strId;
- strId.Format("%d", UpperId);
- _bstr_t vSQL;
- vSQL = "INSERT INTO ProType (TypeName, UpperId) VALUES('" + TypeName + "'," + strId + ")";
- //执行INSERT语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CProType::sql_update(CString cTypeId)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置UPDATE语句
- CString strId;
- strId.Format("%d", UpperId);
- _bstr_t vSQL;
- vSQL = "UPDATE ProType SET TypeName='" + TypeName + "', UpperId=" + strId
- + " WHERE TypeId=" + cTypeId;
- //执行UPDATE语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- void CProType::sql_delete(CString cTypeId)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置DELETE语句
- _bstr_t vSQL;
- vSQL = "DELETE FROM ProType WHERE TypeId=" + cTypeId;
- //执行DELETE语句
- m_AdoConn.ExecuteSQL(vSQL);
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }
- //根据客户编号读取所有字段值
- void CProType::GetData(CString cTypeId)
- {
- //连接数据库
- ADOConn m_AdoConn;
- m_AdoConn.OnInitADOConn();
- //设置SELECT语句
- _bstr_t vSQL;
- vSQL = "SELECT * FROM ProType WHERE TypeId=" + cTypeId;
- //执行SELETE语句
- _RecordsetPtr m_pRecordset;
- m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
- //返回各列的值
- if (m_pRecordset->adoEOF)
- CProType();
- else
- {
- TypeId = atoi(cTypeId);
- TypeName = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TypeName");
- UpperId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UpperId"));
- }
- //断开与数据库的连接
- m_AdoConn.ExitConnect();
- }