⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bchange.cpp

📁 图书管理系统,主要功能有图书的借还,增加,查询等
💻 CPP
字号:
// bchange.cpp : implementation file
//

#include "stdafx.h"
#include "图书管理系统.h"
#include "bchange.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// Cbchange dialog


Cbchange::Cbchange(CWnd* pParent /*=NULL*/)
	: CDialog(Cbchange::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cbchange)
	m_address = _T("");
	m_athor = _T("");
	m_date = _T("");
	m_have = _T("");
	m_id = _T("");
	m_name = _T("");
	m_people = _T("");
	m_booktype = _T("");
	//}}AFX_DATA_INIT
}


void Cbchange::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cbchange)
	DDX_Control(pDX, IDC_COMBO1, m_combo1);
	DDX_Text(pDX, IDC_ADDESS, m_address);
	DDX_Text(pDX, IDC_ATHOR, m_athor);
	DDX_Text(pDX, IDC_DATE, m_date);
	DDX_Text(pDX, IDC_HAVE, m_have);
	DDX_Text(pDX, IDC_ID, m_id);
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_Text(pDX, IDC_people, m_people);
	DDX_CBString(pDX, IDC_COMBO1, m_booktype);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cbchange, CDialog)
	//{{AFX_MSG_MAP(Cbchange)
	ON_BN_CLICKED(ID_ADD, OnAdd)
	ON_BN_CLICKED(ID_CHANGE, OnChange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cbchange message handlers
void Cbchange::OnAdd() 
{
	if(p!=2)
	{
		UpdateData();
		m_combo1.GetLBText(m_combo1.GetCurSel(),sql1);
		if(m_id.IsEmpty())
		{
			MessageBox("“图书编号”不能为空!");
			return;
		}
		else if(m_name.IsEmpty())
		{
			MessageBox("“图书名称”不能为空!");
			return;
		}
		else if(m_athor.IsEmpty())
		{
			MessageBox("“作者”不能为空!");
			return;
		}
		else if(m_date.IsEmpty())
		{
			MessageBox("“出版日期”不能为空!");
			return;
		}
		else if(m_address.IsEmpty())
		{
			MessageBox("“出版社”不能为空!");
			return;
		}
		else if(m_have.IsEmpty())
		{
			MessageBox("“是否借出”不能为空!");
			return;
		}
		sql.Format("select * from book order by bookid desc");
		connect();
		try
		{
			m_pRecordset->AddNew();//添加新行
			m_pRecordset->PutCollect("bookid",(_bstr_t)m_id);
			m_pRecordset->PutCollect("booktype",(_bstr_t)sql1);
			m_pRecordset->PutCollect("bookname",(_bstr_t)m_name);
			m_pRecordset->PutCollect("author",(_bstr_t)m_athor);
			m_pRecordset->PutCollect("publicdate",(_bstr_t)m_date);
			m_pRecordset->PutCollect("publisher",(_bstr_t)m_address);
			m_pRecordset->PutCollect("have",(_bstr_t)m_have);
			m_pRecordset->PutCollect("people",(_bstr_t)m_people);
			m_pRecordset->Update();
		}
		catch(...)
		{
			MessageBox("操作失败,图书编号不能重复");
			return;
		}
		MessageBox("添加成功");
		OnCancel();
		m_pRecordset->Close();
		m_pRecordset=NULL;
	}
	else
		MessageBox("操作失败,修改状态下不能添加");
}

void Cbchange::OnChange() 
{
	if(p==2)
	{
		UpdateData();
		m_combo1.GetLBText(m_combo1.GetCurSel(),sql1);
		if(m_id.IsEmpty()||sql1.IsEmpty()||m_name.IsEmpty()||m_athor.IsEmpty()||m_date.IsEmpty()||m_address.IsEmpty()||m_have.IsEmpty())	
		{
			MessageBox("图书资料不能为空");
			return;
		}
		sql.Format("select * from book where bookid='%s'",m_id);
		connect();
		if(m_pRecordset->adoEOF==0)
		{
			MessageBox("图书编号重复,请重新输入");
			m_pRecordset->Close();
			m_pRecordset=NULL;
			return;
		}
		try
		{
			sql.Format("Update book set bookid='%s',booktype='%s',bookname = '%s',author = '%s',publicdate='%s',publisher='%s', \
					have='%s',people='%s' where bookid='%s'",m_id,sql1,m_name,m_athor,m_date,m_address,m_have,m_people,mm);
			connect();
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}
		MessageBox("修改成功");
		OnCancel();
	}
	else
		MessageBox("操作失败,添加状态下不能修改");
}

BOOL Cbchange::OnInitDialog() 
{
	CDialog::OnInitDialog();
	if(p!=2)
		m_combo1.SetCurSel(0);
	if(p==2)
		read();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Cbchange::connect()
{
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset->Open(sql.AllocSysString(),
							theApp.m_pConnection.GetInterfacePtr(),	
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
}

void Cbchange::OnCancel() 
{
	CDialog::OnCancel();
}

void Cbchange::read()
{
	sql.Format("select * from book where bookid='%s'",mm);
	connect();
	if(!m_pRecordset->adoEOF)
	{
		var=m_pRecordset->GetCollect("bookid");
		if(var.vt!=VT_NULL)
			m_id=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("booktype");
		if(var.vt!=VT_NULL)
			m_booktype=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("bookname");
		if(var.vt!=VT_NULL)
			m_name=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("author");
		if(var.vt!=VT_NULL)
			m_athor=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("publicdate");
		if(var.vt!=VT_NULL)
			m_date=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("publisher");
		if(var.vt!=VT_NULL)
			m_address=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("have");
		if(var.vt!=VT_NULL)
			m_have=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("people");
		if(var.vt!=VT_NULL)
			m_people=(LPCSTR)_bstr_t(var);
		UpdateData(FALSE);
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
}

⌨️ 快捷键说明

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