📄 client.cpp
字号:
// Client.cpp: implementation of the CClient class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Stock.h"
#include "Client.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClient::CClient()
{
Cid = 0;
Cname = "";
Ctype = 0;
Contact = "";
Address = "";
Postcode = "";
Phone = "";
Fax = "";
Memo = "";
}
CClient::~CClient()
{
}
int CClient::GetCid()
{
return Cid;
}
void CClient::SetCid(int iCid)
{
Cid = iCid;
}
CString CClient::GetCname()
{
return Cname;
}
void CClient::SetCname(CString cCname)
{
Cname = cCname;
}
int CClient::GetCtype()
{
return Ctype;
}
void CClient::SetCtype(int iCtype)
{
Ctype = iCtype;
}
CString CClient::GetContact()
{
return Contact;
}
void CClient::SetContact(CString cContact)
{
Contact = cContact;
}
CString CClient::GetAddress()
{
return Address;
}
void CClient::SetAddress(CString cAddress)
{
Address = cAddress;
}
CString CClient::GetPostcode()
{
return Postcode;
}
void CClient::SetPostcode(CString cPostcode)
{
Postcode = cPostcode;
}
CString CClient::GetPhone()
{
return Phone;
}
void CClient::SetPhone(CString cPhone)
{
Phone = cPhone;
}
CString CClient::GetFax()
{
return Fax;
}
void CClient::SetFax(CString cFax)
{
Fax = cFax;
}
CString CClient::GetMemo()
{
return Memo;
}
void CClient::SetMemo(CString cMemo)
{
Memo = cMemo;
}
//数据库操作
int CClient::HaveName(CString cCname)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cname='" + cCname + "'";
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
//返回各列的值
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CClient::sql_insert()
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "INSERT INTO Client (Cname, Ctype, Contact, Address, Postcode, Phone, Fax, Memo) VALUES('"
+ Cname + "'," + strType + ",'" + Contact + "','" + Address + "','" + Postcode + "','"
+ Phone + "','" + Fax + "','" + Memo + "')";
//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CClient::sql_update(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置INSERT语句
CString strType;
strType.Format("%d", Ctype);
_bstr_t vSQL;
vSQL = "UPDATE Client SET Cname='" + Cname + "', Ctype=" + strType + ", Contact='"
+ Contact + "', Address='" + Address + "', Postcode='" + Postcode + "', Phone='"
+ Phone + "', Fax='" + Fax + "', Memo='" + Memo + "' WHERE Cid=" + cCid;
//执行INSERT语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
void CClient::sql_delete(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置DELETE语句
_bstr_t vSQL;
vSQL = "DELETE FROM Client WHERE Cid=" + cCid;
//执行DELETE语句
m_AdoConn.ExecuteSQL(vSQL);
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
//根据客户编号读取所有字段值
void CClient::GetData(CString cCid)
{
//连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
//设置SELECT语句
_bstr_t vSQL;
vSQL = "SELECT * FROM Client WHERE Cid=" + cCid;
//执行SELETE语句
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
//返回各列的值
if (m_pRecordset->adoEOF)
CClient();
else
{
Cid = atoi(cCid);
Cname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Cname");
Ctype = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Ctype"));
Contact = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Contact");
Address = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Address");
Postcode = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Postcode");
Phone = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Phone");
Fax = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Fax");
Memo = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Memo");
}
//断开与数据库的连接
m_AdoConn.ExitConnect();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -