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

📄 borrowlistdlg.cpp

📁 图书馆管理系统是典型的信息管理系统(MIS),其开发主要包括后台数据库的建立和维护以及前端应用程序的开发两个方面。对于前者要求建立起数据一致性和完整性强.数据安全性好的库。而对于后者则要求应用程序功能
💻 CPP
字号:
// BorrowListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "librarym.h"
#include "BorrowListDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBorrowListDlg dialog


CBorrowListDlg::CBorrowListDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBorrowListDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBorrowListDlg)
	m_BrwBookID = _T("");
	m_BrwReaderID = _T("");
	//}}AFX_DATA_INIT
}


void CBorrowListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBorrowListDlg)
	DDX_Control(pDX, IDC_LIST_BORROW, m_BorrowList);
	DDX_Text(pDX, IDC_EDIT_BBOOKID, m_BrwBookID);
	DDX_Text(pDX, IDC_EDIT_BREADERID, m_BrwReaderID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBorrowListDlg, CDialog)
	//{{AFX_MSG_MAP(CBorrowListDlg)
	ON_BN_CLICKED(IDC_BORROWLIST_SEARCH_BTN, OnBorrowlistSearchBtn)
	ON_BN_CLICKED(IDC_BORROWLIST_CANCEL_BTN2, OnBorrowlistCancelBtn2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBorrowListDlg message handlers


BOOL CBorrowListDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	//初始化数据库连接
	HRESULT result;
	try
	{
		//实例化连接对象
		result=m_pConnection.CreateInstance(_uuidof(Connection));
		if(SUCCEEDED(result))
		{
			//设置连接属性为UDL文件
			m_pConnection->ConnectionString="File Name=LIBRARYM.udl";
			//设置等待连接打开的时间为20s
			m_pConnection->ConnectionTimeout=20;
			result=m_pConnection->Open("","","",adConnectUnspecified);

			if(FAILED(result))
			{
				AfxMessageBox("open failed");
				return TRUE;
			}
		}
		else
		{
			AfxMessageBox("createinstance of connection failed!");
			return TRUE;
		}
	}
	catch(_com_error e)
	{
		//输出异常信息
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		AfxMessageBox(bstrSource+bstrDescription);
		return TRUE;
	}

	//初始化列表
	m_BorrowList.InsertColumn(0,"BorrowNo",LVCFMT_LEFT,100);
	m_BorrowList.InsertColumn(1,"BookID",LVCFMT_CENTER,100);
	m_BorrowList.InsertColumn(2,"ReaderID",LVCFMT_CENTER,100);
	m_BorrowList.InsertColumn(3,"BorrowDate",LVCFMT_CENTER,100);
	m_BorrowList.InsertColumn(4,"ReturnDate",LVCFMT_CENTER,100);

	m_BorrowList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);


	InitListCtrl();
	return TRUE;
}

void CBorrowListDlg::InitListCtrl()
{
	HRESULT hr;
	_RecordsetPtr pBorrowList;
	hr=pBorrowList.CreateInstance(_uuidof(Recordset));
	if(FAILED(hr))
	{
		AfxMessageBox("createinstance of recordset failed!\ncan't initiate borrowlist control");
		return;
	}

	CString strSql;
	_variant_t getvar;
	CString strValue;
	int curItem=0;
	strSql="select * from BorrowRelation";

	try
	{
		hr=pBorrowList->Open(_variant_t(strSql),m_pConnection.GetInterfacePtr(),
			adOpenDynamic,adLockOptimistic,adCmdText);
		if(SUCCEEDED(hr))
		{
			while(!pBorrowList->adoEOF)
			{
				getvar=pBorrowList->GetCollect("BorrowNo");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.InsertItem(curItem,strValue);

				getvar=pBorrowList->GetCollect("BookID");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,1,strValue);

				getvar=pBorrowList->GetCollect("ReaderID");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,2,strValue);

				getvar=pBorrowList->GetCollect("BorrowDate");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,3,strValue);

				getvar=pBorrowList->GetCollect("ReturnDate");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,4,strValue);

				pBorrowList->MoveNext();
				curItem++;
			}
		}
		else
		{
			AfxMessageBox("open recordset failed!");
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;
	}
	pBorrowList->Close();
	pBorrowList=NULL;
}

void CBorrowListDlg::OnBorrowlistSearchBtn() 
{
	UpdateData(TRUE);

	CString temp;
	bool bset=false;
	CString strSql="select * from BorrowRelation where ";
	if(!m_BrwBookID.IsEmpty())
	{
		temp.Format("BookID='%s'",m_BrwBookID);
		bset=true;
	}
	if(!temp.IsEmpty())
		strSql+=temp;
	temp="";
	if(!m_BrwReaderID.IsEmpty() )
	{
		if(bset)
		{
			temp.Format("and ReaderID='%s'",m_BrwReaderID);
		}
		else
		{
			temp.Format("ReaderID='%s'",m_BrwReaderID);
			bset=true;
		}
	}
	if(!temp.IsEmpty())
		strSql+=temp;

	if(!bset)
	{
		AfxMessageBox("empty input!");
		return;
	}
	_RecordsetPtr pBorrowList;	
	pBorrowList.CreateInstance(_uuidof(Recordset));
	_variant_t getvar;
	CString strValue;
	int curItem=0;

	try
	{
		HRESULT hr;
		hr=pBorrowList->Open(_variant_t(strSql),m_pConnection.GetInterfacePtr(),
			adOpenDynamic,adLockOptimistic,adCmdText);

		if(SUCCEEDED(hr))
		{
			m_BorrowList.DeleteAllItems();

			while(!pBorrowList->adoEOF)
			{
				getvar=pBorrowList->GetCollect("BorrowNo");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.InsertItem(curItem,strValue);

				getvar=pBorrowList->GetCollect("BookID");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,1,strValue);

				getvar=pBorrowList->GetCollect("ReaderID");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,2,strValue);

				getvar=pBorrowList->GetCollect("BorrowDate");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,3,strValue);

				getvar=pBorrowList->GetCollect("ReturnDate");
				if(getvar.vt!=VT_NULL)
				{
					strValue=(LPCSTR)_bstr_t(getvar);
				}
				else
					strValue=" ";
				m_BorrowList.SetItemText(curItem,4,strValue);

				pBorrowList->MoveNext();
				curItem++;
			}
		}
		else
		{
			AfxMessageBox("open recordset failed!");
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;
	}
	pBorrowList->Close();
	pBorrowList=NULL;	

}

void CBorrowListDlg::OnBorrowlistCancelBtn2() 
{
	CDialog::OnCancel();	
}

⌨️ 快捷键说明

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