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

📄 librarydlg.cpp

📁 图书馆借阅管理系统
💻 CPP
字号:
// LibraryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Library.h"
#include "LibraryDlg.h"

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

extern CLibraryApp theApp;       // 在此引用应用类中的theApp来获取库连接指针

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLibraryDlg dialog

CLibraryDlg::CLibraryDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLibraryDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLibraryDlg)
	m_BookID = _T("");
	m_ReaderID = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLibraryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLibraryDlg)
	DDX_Control(pDX, IDC_ReaderInfoList, m_ReaderInfoList);
	DDX_Control(pDX, IDC_ReaderStatusList, m_ReaderStatusList);
	DDX_Control(pDX, IDC_BookStatusList, m_BookStatusList);
	DDX_Text(pDX, IDC_BookID, m_BookID);
	DDX_Text(pDX, IDC_ReaderID, m_ReaderID);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLibraryDlg, CDialog)
	//{{AFX_MSG_MAP(CLibraryDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_Query, OnQuery)
	ON_BN_CLICKED(IDC_Borrow, OnBorrow)
	ON_BN_CLICKED(IDC_RefreshInfo, OnRefreshInfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLibraryDlg message handlers

BOOL CLibraryDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	InitInterface();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLibraryDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CLibraryDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CLibraryDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CLibraryDlg::OnQuery()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	m_BookStatusList.DeleteAllItems();

	if(m_BookID=="")
		return;
	
	if(CurrBook.ReadBookInfo(m_BookID))
	{
		m_BookStatusList.InsertItem(0,CurrBook.BookID);
		m_BookStatusList.SetItemText(0,1,CurrBook.BookName);
		m_BookStatusList.SetItemText(0,2,CurrBook.Author);
		m_BookStatusList.SetItemText(0,3,CurrBook.CHNum);

		int BookStatus;
		CString strBookStatus;
		BookStatus=CurrBook.IsValidBook();
		switch(BookStatus)
		{
		case 0:
			strBookStatus="图书状态:可借";
			break;
		case 1:
			strBookStatus="图书状态:已借出";
			break;
		case 2:
			strBookStatus="图书状态:已预约";
			break;
		default:
			strBookStatus="图书状态:";
		}

		((CStatic*)GetDlgItem(IDC_BookStatus))->SetWindowText(strBookStatus);
	}

}

void CLibraryDlg::OnBorrow()
{
	// TODO: Add your control notification handler code here
	if(CurrBook.IsValidBook())
	{
		::MessageBox(NULL,"图书状态不正确,不能借阅!","提醒",MB_OK);
		return;
	}
	else
	{
		if(CurrReader.BorrowBook(CurrBook))
		{
		  ::MessageBox(NULL,"操作成功!","提示",MB_OK);
		  GetBorrowInfo(CurrReader.ReaderID);
		}
		else
		  ::MessageBox(NULL,"借书操作失败!","提醒",MB_OK);
	}
}

void CLibraryDlg::OnRefreshInfo()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	m_ReaderInfoList.DeleteAllItems();

	if(m_ReaderID=="")
		return;

	if(CurrReader.ReadReaderInfo(m_ReaderID))
	{
		m_ReaderInfoList.InsertItem(0,CurrReader.ReaderID);
		m_ReaderInfoList.SetItemText(0,1,CurrReader.Name);
		m_ReaderInfoList.SetItemText(0,2,CurrReader.ClassName);
		m_ReaderInfoList.SetItemText(0,3,CurrReader.Address);
		m_ReaderInfoList.SetItemText(0,4,CurrReader.Content);

		GetBorrowInfo(CurrReader.ReaderID);
	}
}

void CLibraryDlg::InitInterface()
{
	m_BookStatusList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	m_BookStatusList.InsertColumn(0,_T("图书编号"),LVCFMT_CENTER,70);
	m_BookStatusList.InsertColumn(1,_T("图书名称"),LVCFMT_CENTER,150);
	m_BookStatusList.InsertColumn(2,_T("作者"),LVCFMT_CENTER,150);
	m_BookStatusList.InsertColumn(3,_T("中图分类号"),LVCFMT_CENTER,150);

	m_ReaderInfoList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	m_ReaderInfoList.InsertColumn(0,_T("读者姓名"),LVCFMT_CENTER,100);
	m_ReaderInfoList.InsertColumn(1,_T("借书证号"),LVCFMT_CENTER,150);
	m_ReaderInfoList.InsertColumn(2,_T("读者分类"),LVCFMT_CENTER,70);
	m_ReaderInfoList.InsertColumn(3,_T("联系方式"),LVCFMT_CENTER,150);
	m_ReaderInfoList.InsertColumn(4,_T("备注信息"),LVCFMT_CENTER,100);

	m_ReaderStatusList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	m_ReaderStatusList.InsertColumn(0,_T("图书编号"),LVCFMT_CENTER,70);
	m_ReaderStatusList.InsertColumn(1,_T("图书名称"),LVCFMT_CENTER,150);
	m_ReaderStatusList.InsertColumn(2,_T("作者"),LVCFMT_CENTER,150);
	m_ReaderStatusList.InsertColumn(3,_T("借出日期"),LVCFMT_CENTER,100);
	m_ReaderStatusList.InsertColumn(4,_T("是否已续借"),LVCFMT_CENTER,80);
}

void CLibraryDlg::GetBorrowInfo(CString strReaderID)
{
	CString SQLText;

	_RecordsetPtr pRst(__uuidof(Recordset)); 

	m_ReaderStatusList.DeleteAllItems();

	SQLText.Format("select * from V_BorrowInfo where Deleted=0 and ReaderID='%s'",strReaderID);

	try
	{
		//SQL Server数据库
		pRst=theApp.pConn->Execute(_bstr_t(SQLText),NULL,adCmdText);

		if(!pRst->BOF)
			pRst->MoveFirst();

		while(!pRst->End)
		{
			CString BookID,BookName,Author,BorrowDate,CtnFlag;
			int IsContinue;
			COleDateTime cBorrowDate;

			_variant_t vBookID		= pRst->GetCollect("BookID");
			_variant_t vBookName	= pRst->GetCollect("BookName");
			_variant_t vAuthor		= pRst->GetCollect("Author");
			_variant_t vBorrowDate	= pRst->GetCollect("BorrowDate");
			_variant_t vIsContinue	= pRst->GetCollect("IsContinue");

			BookID		=	vBookID.bstrVal;
			BookName	=	vBookName.bstrVal;
			Author		=	vAuthor.bstrVal;
			cBorrowDate =	vBorrowDate.date;
			BorrowDate	=	cBorrowDate.Format("%Y-%m-%d");
			IsContinue	=	vIsContinue.iVal;
			if(IsContinue)
				CtnFlag="是";
			else
				CtnFlag="否";

			m_ReaderStatusList.InsertItem(0,BookID);
			m_ReaderStatusList.SetItemText(0,1,BookName);
			m_ReaderStatusList.SetItemText(0,2,Author);
			m_ReaderStatusList.SetItemText(0,3,BorrowDate);
			m_ReaderStatusList.SetItemText(0,4,CtnFlag);

			pRst->MoveNext();
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	
	pRst->Close();
	pRst.Release();
}

⌨️ 快捷键说明

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