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

📄 libraryview.cpp

📁 实现一个图书馆管理系统
💻 CPP
字号:
// libraryView.cpp : implementation of the CLibraryView class
//

#include "stdafx.h"
#include "library.h"

#include "libraryDoc.h"
#include "libraryView.h"

#include "BookSet.h"
#include "BorrowSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLibraryView
extern CDatabase db;
extern CString CurUser;

IMPLEMENT_DYNCREATE(CLibraryView, CFormView)

BEGIN_MESSAGE_MAP(CLibraryView, CFormView)
	//{{AFX_MSG_MAP(CLibraryView)
	ON_BN_CLICKED(IDC_BUT_QUERY, OnButQuery)
	ON_BN_CLICKED(IDC_BUT_BORROWHISTORY, OnButBorrowhistory)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLibraryView construction/destruction

CLibraryView::CLibraryView()
	: CFormView(CLibraryView::IDD)
{
	//{{AFX_DATA_INIT(CLibraryView)
	m_author = _T("");
	m_bookname = _T("");
	m_bookno = _T("");
	m_publishhouse = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CLibraryView::~CLibraryView()
{
}

void CLibraryView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLibraryView)
	DDX_Control(pDX, IDC_LIST_INFO, m_info);
	DDX_Control(pDX, IDC_LIST_HISTORY, m_history);
	DDX_Text(pDX, IDC_EDIT_AUTHOR, m_author);
	DDX_Text(pDX, IDC_EDIT_BOOKNAME, m_bookname);
	DDX_Text(pDX, IDC_EDIT_BOOKNO, m_bookno);
	DDX_Text(pDX, IDC_EDIT_PUBLISHHOUSE, m_publishhouse);
	//}}AFX_DATA_MAP
}

BOOL CLibraryView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	//cs.lpszClass="nick";
	return CFormView::PreCreateWindow(cs);
}

void CLibraryView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	m_info.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
	m_info.InsertColumn(0,"书号");
	m_info.InsertColumn(1,"书名");
	m_info.InsertColumn(2,"作者");
	m_info.InsertColumn(3,"出版社");
	m_info.InsertColumn(4,"出版日期");
	m_info.InsertColumn(5,"状态");
	m_info.SetColumnWidth(0,80);
	m_info.SetColumnWidth(1,160);
	m_info.SetColumnWidth(2,80);
	m_info.SetColumnWidth(3,80);
	m_info.SetColumnWidth(4,100);
	m_info.SetColumnWidth(5,80);

	m_history.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
	m_history.InsertColumn(0,"书号");
	m_history.InsertColumn(1,"书名");
	m_history.InsertColumn(2,"借阅日期");
	m_history.InsertColumn(3,"应还日期");
	m_history.SetColumnWidth(0,80);
	m_history.SetColumnWidth(1,160);
	m_history.SetColumnWidth(2,100);
	m_history.SetColumnWidth(3,100);
}

/////////////////////////////////////////////////////////////////////////////
// CLibraryView printing

BOOL CLibraryView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CLibraryView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CLibraryView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CLibraryView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CLibraryView diagnostics

#ifdef _DEBUG
void CLibraryView::AssertValid() const
{
	CFormView::AssertValid();
}

void CLibraryView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CLibraryDoc* CLibraryView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLibraryDoc)));
	return (CLibraryDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLibraryView message handlers

void CLibraryView::OnButQuery() 
{
	// TODO: Add your control notification handler code here
	m_info.DeleteAllItems();
	UpdateData();
	if(m_bookno.IsEmpty() && m_bookname.IsEmpty() && m_author.IsEmpty() && m_publishhouse.IsEmpty())
	{
		MessageBox("查询条件不能为空!");
		return;
	}
	m_bookno.TrimRight();
	m_bookname.TrimRight();
	m_author.TrimRight();
	m_publishhouse.TrimRight();
	CBookSet *bookset=new CBookSet(&db);
	int i=0;
    
	bookset->Open();
	bookset->MoveFirst();
	bookset->m_BookNo.TrimRight();
	bookset->m_Name.TrimRight();
	bookset->m_Author.TrimRight();
	bookset->m_PublishingHouse.TrimRight();
	if(!m_bookno.IsEmpty())	
		if(m_bookno!=bookset->m_BookNo) goto nomatch;
		else
		{
		l1:	if(!m_bookname.IsEmpty())
				if(m_bookname!=bookset->m_Name)
					goto nomatch;
				else 
				{
				l2:if(!m_author.IsEmpty())
						if(m_author!=bookset->m_Author)
							goto nomatch;
						else
						{
						l3:if(!m_publishhouse.IsEmpty())
								if(m_publishhouse!=bookset->m_PublishingHouse)
									goto nomatch;
								{
									m_info.InsertItem(i,bookset->m_BookNo);
									m_info.SetItemText(i,1,bookset->m_Name);
									m_info.SetItemText(i,2,bookset->m_Author);
									m_info.SetItemText(i,3,bookset->m_PublishingHouse);
									m_info.SetItemText(i,4,bookset->m_PublishingDate);
									m_info.SetItemText(i,5,bookset->m_State);
									i++;
								}
						}
						else goto l3;
				}
				else goto l2;
		}
		else goto l1;
 
	bookset->MoveNext();
	while(!bookset->IsBOF() && !bookset->IsEOF())
	{
	bookset->m_BookNo.TrimRight();
	bookset->m_Name.TrimRight();
	bookset->m_Author.TrimRight();
	bookset->m_PublishingHouse.TrimRight();
	if(!m_bookno.IsEmpty())	
		if(m_bookno!=bookset->m_BookNo) goto nomatch;
		else
		{
		l4:	if(!m_bookname.IsEmpty())
				if(m_bookname!=bookset->m_Name)
					goto nomatch;
				else 
				{
				l5:if(!m_author.IsEmpty())
						if(m_author!=bookset->m_Author)
							goto nomatch;
						else
						{
						l6:if(!m_publishhouse.IsEmpty())
								if(m_publishhouse!=bookset->m_PublishingHouse)
									goto nomatch;
								{
									m_info.InsertItem(i,bookset->m_BookNo);
									m_info.SetItemText(i,1,bookset->m_Name);
									m_info.SetItemText(i,2,bookset->m_Author);
									m_info.SetItemText(i,3,bookset->m_PublishingHouse);
									m_info.SetItemText(i,4,bookset->m_PublishingDate);
									m_info.SetItemText(i,5,bookset->m_State);
									i++;
								}
						}
						else goto l6;
				}
				else goto l5;
		}
		else goto l4;
		bookset->MoveNext();
	}
	bookset->Close();
	return;
nomatch:
	if(i==0)
	MessageBox("很抱歉!\n没有找到符合您要求的书!");
		bookset->Close();
}

void CLibraryView::OnButBorrowhistory() 
{
	// TODO: Add your control notification handler code here
	CBorrowSet *borrow=new CBorrowSet(&db);
    m_history.DeleteAllItems();
	int i=0;
	borrow->Open();
	if(!borrow->IsBOF() && !borrow->IsEOF())
	{
		borrow->MoveFirst();
		borrow->m_UserID.TrimRight();
		if(borrow->m_UserID==CurUser && !borrow->IsBOF() && !borrow->IsEOF())
		{
			m_history.InsertItem(i,borrow->m_BookNo);
			m_history.SetItemText(i,1,borrow->m_Name);
			m_history.SetItemText(i,2,borrow->m_DateOfBorrow);
			m_history.SetItemText(i,3,borrow->m_DateOfReversion);
			i++;
		}
		borrow->MoveNext();
		while(!borrow->IsBOF() && !borrow->IsEOF())
		{
			m_history.InsertItem(i,borrow->m_BookNo);
			m_history.SetItemText(i,1,borrow->m_Name);
			m_history.SetItemText(i,2,borrow->m_DateOfBorrow);
			m_history.SetItemText(i,3,borrow->m_DateOfReversion);
			borrow->MoveNext();
			i++;
		}
		if(i==0)
			MessageBox("您当前无任何借阅纪录!");
	}
	else MessageBox("记录为空!");
	borrow->Close();
}

⌨️ 快捷键说明

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