《MFC图书管理系统_cpp文件.doc》由会员分享,可在线阅读,更多相关《MFC图书管理系统_cpp文件.doc(80页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、1 BookMDlg.cpp/ BookMDlg.cpp : implementation file#include stdafx.h#include MFC_Library_Ribbon.h#include BookMDlg.h#include afxdialogex.h#include MFC_Library_RibbonView.h/ CBookMDlg dialogIMPLEMENT_DYNAMIC(CBookMDlg, CDialogEx)CBookMDlg:CBookMDlg(CWnd* pParent /*=NULL*/): CDialogEx(CBookMDlg:IDD, pP
2、arent), m_strBookNameQ(_T(), m_strBookIdQ(_T(), m_strBookName(_T(), m_strBookId(_T(), m_strBookPress(_T(), m_strBookAuthor(_T(), m_strCanBorrow(_T(), m_bAdd(false), m_bEdit(false), m_tPressDate(0),m_pParent(pParent)CBookMDlg:CBookMDlg()void CBookMDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDat
3、aExchange(pDX);DDX_Text(pDX, IDC_BOOK_NAME_Q, m_strBookNameQ);DDX_Text(pDX, IDC_BOOK_ID_Q, m_strBookIdQ);DDX_Text(pDX, IDC_BOOK_NAME, m_strBookName);DDX_Text(pDX, IDC_BOOK_ID, m_strBookId);DDX_Text(pDX, IDC_BOOK_PRESS, m_strBookPress);DDX_Text(pDX, IDC_BOOK_AUTHOR, m_strBookAuthor);DDX_Text(pDX, IDC
4、_BOOK_CANBORROW, m_strCanBorrow);DDX_DateTimeCtrl(pDX, IDC_PRESS_DATE, m_tPressDate);DDX_Control(pDX, IDC_PRESS_DATE, PressDateCtrl);BEGIN_MESSAGE_MAP(CBookMDlg, CDialogEx)ON_BN_CLICKED(IDC_BTN_SEARCH, &CBookMDlg:OnBnClickedBtnSearch)ON_BN_CLICKED(IDC_BTN_RETURN, &CBookMDlg:OnBnClickedBtnReturn)ON_B
5、N_CLICKED(IDC_BTN_FIRST, &CBookMDlg:OnBnClickedBtnFirst)ON_BN_CLICKED(IDC_BTN_PREV, &CBookMDlg:OnBnClickedBtnPrev)ON_BN_CLICKED(IDC_BTN_LAST, &CBookMDlg:OnBnClickedBtnLast)ON_BN_CLICKED(IDC_BTN_NEXT, &CBookMDlg:OnBnClickedBtnNext)ON_BN_CLICKED(IDC_BTN_ADD, &CBookMDlg:OnBnClickedBtnAdd)ON_BN_CLICKED(
6、IDC_BTN_EDIT, &CBookMDlg:OnBnClickedBtnEdit)ON_BN_CLICKED(IDC_BTN_SAVE, &CBookMDlg:OnBnClickedBtnSave)ON_BN_CLICKED(IDC_BTN_CANCEL, &CBookMDlg:OnBnClickedBtnCancel)ON_BN_CLICKED(IDC_BTN_DELETE, &CBookMDlg:OnBnClickedBtnDelete)ON_WM_SIZE()ON_WM_DESTROY()ON_BN_CLICKED(IDCANCEL, &CBookMDlg:OnBnClickedC
7、ancel)END_MESSAGE_MAP()/ CBookMDlg message handlersvoid CBookMDlg:DisplayRecord(void)if (bookDataSet.IsBOF()&bookDataSet.IsEOF()m_strBookId=L;m_strBookName=L;m_strBookPress=L;m_strBookAuthor=L;m_strCanBorrow=L;elseif (bookDataSet.IsBOF()bookDataSet.MoveNext();elseif(bookDataSet.IsEOF()bookDataSet.Mo
8、vePrev();m_strBookName=bookDataSet.m_BOOK_NAME;m_strBookId=bookDataSet.m_BOOK_ID;m_strBookPress=bookDataSet.m_PRESS;/m_strBookDate=bookDataSet.m_PRESS_DATE.Format(%Y%m%d);m_tPressDate=bookDataSet.m_PRESS_DATE;m_strCanBorrow=bookDataSet.m_FLAG_BORROW;m_strBookAuthor=bookDataSet.m_AUTHOR;UpdateData(FA
9、LSE);void CBookMDlg:SetButtonState(void)if(m_bAdd)GetDlgItem(IDC_BTN_SAVE)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_CANCEL)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_EDIT)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_ADD)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_DELETE)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_SEARC
10、H)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_RETURN)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_FIRST)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_NEXT)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_LAST)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_PREV)-EnableWindow(FALSE);/六个编辑框的属性(CEdit*)GetDlgItem(IDC_BOOK_ID)-SetReadO
11、nly(FALSE);(CEdit*)GetDlgItem(IDC_BOOK_NAME)-SetReadOnly(FALSE);(CEdit*)GetDlgItem(IDC_BOOK_PRESS)-SetReadOnly(FALSE);(CEdit*)GetDlgItem(IDC_BOOK_AUTHOR)-SetReadOnly(FALSE);(CEdit*)GetDlgItem(IDC_BOOK_CANBORROW)-SetReadOnly(FALSE);/(CEdit*)GetDlgItem(IDC_BOOK_DATE)-SetReadOnly(FALSE);if (!m_bAdd)Get
12、DlgItem(IDC_BTN_SAVE)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_CANCEL)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_EDIT)-EnableWindow(!m_bEdit);GetDlgItem(IDC_BTN_ADD)-EnableWindow(!m_bAdd);GetDlgItem(IDC_BTN_DELETE)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_SEARCH)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_RETURN
13、)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_FIRST)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_NEXT)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_LAST)-EnableWindow(TRUE);GetDlgItem(IDC_BTN_PREV)-EnableWindow(TRUE);/六个编辑框的属性(CEdit*)GetDlgItem(IDC_BOOK_ID)-SetReadOnly(TRUE);(CEdit*)GetDlgItem(IDC_BOOK_NAME)-SetReadOn
14、ly(TRUE);(CEdit*)GetDlgItem(IDC_BOOK_PRESS)-SetReadOnly(TRUE);(CEdit*)GetDlgItem(IDC_BOOK_AUTHOR)-SetReadOnly(TRUE);(CEdit*)GetDlgItem(IDC_BOOK_CANBORROW)-SetReadOnly(TRUE);/(CEdit*)GetDlgItem(IDC_BOOK_DATE)-SetReadOnly(TRUE);void CBookMDlg:OnBnClickedBtnSearch()/ TODO: Add your control notification
15、 handler code hereUpdateData(TRUE);BOOL bAll=FALSE;if (m_strBookIdQ.IsEmpty()&m_strBookNameQ.IsEmpty()MessageBox(L请输入要查询的号码或姓名!,L提示);return;elseif (!m_strBookNameQ.IsEmpty()bookDataSet.m_strFilter=LBOOK_NAME=;bookDataSet.m_strFilter=bookDataSet.m_strFilter+m_strBookNameQ+L;bAll=TRUE;if (!m_strBookId
16、Q.IsEmpty()if(bAll)bookDataSet.m_strFilter=bookDataSet.m_strFilter+L AND BOOK_ID=+m_strBookIdQ;bookDataSet.m_strFilter=bookDataSet.m_strFilter+L;elsebookDataSet.m_strFilter=LBOOK_ID=;bookDataSet.m_strFilter=bookDataSet.m_strFilter+m_strBookIdQ+L;bookDataSet.Requery();DisplayRecord();bAll=FALSE;if(bo
17、okDataSet.IsEOF()MessageBox(L没有相关记录!,L提示);return;void CBookMDlg:OnBnClickedBtnReturn()/ TODO: Add your control notification handler code hereSetDlgItemText(IDC_BOOK_NAME_Q,L);SetDlgItemText(IDC_BOOK_ID_Q,L);UpdateData(TRUE);bookDataSet.m_strFilter=L;bookDataSet.Requery();DisplayRecord();void CBookMD
18、lg:OnBnClickedBtnFirst()/ TODO: Add your control notification handler code herebookDataSet.MoveFirst();DisplayRecord();void CBookMDlg:OnBnClickedBtnPrev()/ TODO: Add your control notification handler code hereif(!bookDataSet.IsBOF()bookDataSet.MovePrev();DisplayRecord();void CBookMDlg:OnBnClickedBtn
19、Last()/ TODO: Add your control notification handler code herebookDataSet.MoveLast();DisplayRecord();void CBookMDlg:OnBnClickedBtnNext()/ TODO: Add your control notification handler code hereif(!bookDataSet.IsEOF()bookDataSet.MoveNext();DisplayRecord();void CBookMDlg:OnBnClickedBtnAdd()/ TODO: Add yo
20、ur control notification handler code hereSetDlgItemText(IDC_BOOK_NAME,L);SetDlgItemText(IDC_BOOK_ID,L);SetDlgItemText(IDC_BOOK_PRESS,L);SetDlgItemText(IDC_BOOK_AUTHOR,L);SetDlgItemText(IDC_BOOK_CANBORROW,L);/SetDlgItemText(IDC_BOOK_DATE,L);/m_tPressDate=PressDateCtrl.;m_bAdd=TRUE;GetDlgItem(IDC_BOOK
21、_NAME)-SetFocus();SetButtonState();void CBookMDlg:OnBnClickedBtnEdit()/ TODO: Add your control notification handler code herem_bEdit=TRUE;m_bAdd=TRUE;SetButtonState();void CBookMDlg:OnBnClickedBtnSave()/ TODO: Add your control notification handler code hereUpdateData(TRUE);if (m_strBookId.IsEmpty()
22、| m_strBookName.IsEmpty() | m_strBookAuthor.IsEmpty() | m_strBookPress.IsEmpty() | m_strCanBorrow.IsEmpty()MessageBox(L请输入要添加的数据!,L提示);return;if(m_bAdd&!m_bEdit)bookDataSet.AddNew();elseif (m_bEdit)bookDataSet.Edit();GetDlgItemText(IDC_BOOK_NAME,bookDataSet.m_BOOK_NAME);GetDlgItemText(IDC_BOOK_ID,bo
23、okDataSet.m_BOOK_ID);bookDataSet.m_PRESS_DATE=m_tPressDate;GetDlgItemText(IDC_BOOK_PRESS,bookDataSet.m_PRESS);GetDlgItemText(IDC_BOOK_CANBORROW,bookDataSet.m_FLAG_BORROW);GetDlgItemText(IDC_BOOK_AUTHOR,bookDataSet.m_AUTHOR);bookDataSet.Update();bookDataSet.Requery();DisplayRecord();m_bAdd=FALSE;m_bE
24、dit=FALSE;SetButtonState();void CBookMDlg:OnBnClickedBtnCancel()/ TODO: Add your control notification handler code hereif(m_bAdd)m_bAdd=FALSE;SetButtonState();if(m_bEdit)m_bEdit=FALSE;m_bAdd=FALSE;SetButtonState();bookDataSet.Requery();DisplayRecord();void CBookMDlg:OnBnClickedBtnDelete()/ TODO: Add
25、 your control notification handler code hereif(IDYES=MessageBox(L确定要删除当前记录吗?,L提示,MB_YESNO)bookDataSet.Delete();MessageBox(L删除成功!,L成功);bookDataSet.Requery();elsereturn;DisplayRecord();BOOL CBookMDlg:OnInitDialog()CDialogEx:OnInitDialog();/ TODO: Add extra initialization hereif (!bookDataSet.Open(AFX_
26、DB_USE_DEFAULT_TYPE)MessageBox(L数据打开失败!); DisplayRecord();GetDlgItem(IDC_BTN_SAVE)-EnableWindow(FALSE);GetDlgItem(IDC_BTN_CANCEL)-EnableWindow(FALSE);GetClientRect(&m_rect);SetBackgroundColor(RGB(247,252,255);return TRUE; / return TRUE unless you set the focus to a control/ EXCEPTION: OCX Property P
27、ages should return FALSEvoid CBookMDlg:OnSize(UINT nType, int cx, int cy)CDialogEx:OnSize(nType, cx, cy);/ TODO: Add your message handler code hereCWnd *pWnd31; pWnd0 = GetDlgItem(IDC_BTN_ADD);pWnd1 = GetDlgItem(IDC_BTN_CANCEL);pWnd2 = GetDlgItem(IDC_BTN_DELETE);pWnd3 = GetDlgItem(IDC_BTN_EDIT);pWnd
28、4 = GetDlgItem(IDC_BTN_FIRST);pWnd5 = GetDlgItem(IDC_BTN_LAST);pWnd6 = GetDlgItem(IDC_BTN_NEXT);pWnd7=GetDlgItem(IDC_BTN_SAVE);pWnd8=GetDlgItem(IDC_BTN_SEARCH);pWnd9=GetDlgItem(IDC_BOOK_ID);pWnd10=GetDlgItem(IDC_BOOK_ID_Q);pWnd11=GetDlgItem(IDC_BOOK_PRESS);pWnd12=GetDlgItem(IDC_BOOK_NAME);pWnd13=Get
29、DlgItem(IDC_BOOK_NAME_Q);pWnd14=GetDlgItem(IDC_BOOK_S1);pWnd15=GetDlgItem(IDC_BOOK_S2);pWnd16=GetDlgItem(IDC_BOOK_S3);pWnd17=GetDlgItem(IDC_BOOK_S4);pWnd18=GetDlgItem(IDC_BOOK_S5);pWnd19=GetDlgItem(IDC_BOOK_S6);pWnd20=GetDlgItem(IDC_BOOK_S7);pWnd21=GetDlgItem(IDC_BOOK_S8);pWnd22=GetDlgItem(IDC_BTN_P
30、REV);pWnd23=GetDlgItem(IDC_BTN_RETURN);pWnd24=GetDlgItem(IDCANCEL);pWnd25=GetDlgItem(IDC_BOOK_S9);pWnd26=GetDlgItem(IDC_BOOK_S10);pWnd27=GetDlgItem(IDC_BOOK_AUTHOR);pWnd28=GetDlgItem(IDC_PRESS_DATE);pWnd29=GetDlgItem(IDC_BOOK_S11);pWnd30=GetDlgItem(IDC_BOOK_CANBORROW);for(int i=0;iGetWindowRect(&rec
31、t); ScreenToClient(&rect);/将控件大小转换为在对话框中的区域坐标 /cx/m_rect.Width()为对话框在横向的变化比例 rect.left=rect.left*cx/m_rect.Width();/*/调整控件大小 rect.right=rect.right*cx/m_rect.Width(); rect.top=rect.top*cy/m_rect.Height(); rect.bottom=rect.bottom*cy/m_rect.Height(); pWndi-MoveWindow(rect);/设置控件大小 GetClientRect(&m_rect
32、);/将变化后的对话框大小设为旧大小 void CBookMDlg:OnDestroy()CDialogEx:OnDestroy();/ TODO: Add your message handler code herem_pParent-PostMessage(WM_DELETE_DLG,(WPARAM)this);void CBookMDlg:OnBnClickedCancel()/ TODO: Add your control notification handler code hereCDialogEx:OnCancel();DestroyWindow();2 CBookDataSet.
33、cpp/ CBookDataSet.h : Implementation of the CBookDataSet class/ CBookDataSet implementation/ code generated on 2010年5月17日, 19:44#include stdafx.h#include CBookDataSet.hIMPLEMENT_DYNAMIC(CBookDataSet, CRecordset)CBookDataSet:CBookDataSet(CDatabase* pdb): CRecordset(pdb)m_BOOK_ID = L;m_BOOK_NAME = L;m
34、_AUTHOR = L;m_PRESS = L;/m_PRESS_DATE;m_FLAG_BORROW = L;m_nFields = 6;m_nDefaultType = dynaset;/#error Security Issue: The connection string may contain a password/ The connection string below may contain plain text passwords and/or/ other sensitive information. Please remove the #error after review
35、ing/ the connection string for any security related issues. You may want to/ store the password in some other form or use a different user authentication.CString CBookDataSet:GetDefaultConnect()return _T(ODBC;DSN=Library);CString CBookDataSet:GetDefaultSQL()return _T(BOOK);void CBookDataSet:DoFieldE
36、xchange(CFieldExchange* pFX)pFX-SetFieldType(CFieldExchange:outputColumn);/ Macros such as RFX_Text() and RFX_Int() are dependent on the/ type of the member variable, not the type of the field in the database./ ODBC will try to automatically convert the column value to the requested typeRFX_Text(pFX
37、, _T(BOOK_ID), m_BOOK_ID);RFX_Text(pFX, _T(BOOK_NAME), m_BOOK_NAME);RFX_Text(pFX, _T(AUTHOR), m_AUTHOR);RFX_Text(pFX, _T(PRESS), m_PRESS);RFX_Date(pFX, _T(PRESS_DATE), m_PRESS_DATE);RFX_Text(pFX, _T(FLAG_BORROW), m_FLAG_BORROW);/ CBookDataSet diagnostics#ifdef _DEBUGvoid CBookDataSet:AssertValid() c
38、onstCRecordset:AssertValid();void CBookDataSet:Dump(CDumpContext& dc) constCRecordset:Dump(dc);#endif /_DEBUG3 CBorrowDataSet.cpp/ CBorrowDataSet.h : Implementation of the CBorrowDataSet class/ CBorrowDataSet implementation/ code generated on 2010年5月18日, 9:15#include stdafx.h#include CBorrowDataSet.
39、hIMPLEMENT_DYNAMIC(CBorrowDataSet, CRecordset)CBorrowDataSet:CBorrowDataSet(CDatabase* pdb): CRecordset(pdb)m_READER_ID = L;m_BOOK_ID = L;m_BORROW_DATE;m_B_CLERK_ID = L;m_BOOK_NAME=L;m_ID = 0;m_nFields = 6;m_nDefaultType = dynaset;/#error Security Issue: The connection string may contain a password/
40、 The connection string below may contain plain text passwords and/or/ other sensitive information. Please remove the #error after reviewing/ the connection string for any security related issues. You may want to/ store the password in some other form or use a different user authentication.CString CB
41、orrowDataSet:GetDefaultConnect()return _T(ODBC;DSN=Library);CString CBorrowDataSet:GetDefaultSQL()return _T(BORROW);void CBorrowDataSet:DoFieldExchange(CFieldExchange* pFX)pFX-SetFieldType(CFieldExchange:outputColumn);/ Macros such as RFX_Text() and RFX_Int() are dependent on the/ type of the member
42、 variable, not the type of the field in the database./ ODBC will try to automatically convert the column value to the requested typeRFX_Text(pFX, _T(READER_ID), m_READER_ID);RFX_Text(pFX, _T(BOOK_ID), m_BOOK_ID);RFX_Date(pFX, _T(BORROW_DATE), m_BORROW_DATE);RFX_Text(pFX, _T(B_CLERK_ID), m_B_CLERK_ID);RFX_Long(pFX, _T(ID), m_ID);RFX_Text(pFX,_T(BOOK_NAME),m_BOOK_NAME);/ CBorrowDataSet diagnos