MFC图书管理系统_cpp文件.doc_第1页
MFC图书管理系统_cpp文件.doc_第2页
MFC图书管理系统_cpp文件.doc_第3页
MFC图书管理系统_cpp文件.doc_第4页
MFC图书管理系统_cpp文件.doc_第5页
已阅读5页,还剩75页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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, pParent), 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:DoDataExchange(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_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_BN_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(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:OnBnClickedCancel)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.MovePrev();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(FALSE);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_SEARCH)-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)-SetReadOnly(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)GetDlgItem(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)-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)-SetReadOnly(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 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_strBookIdQ.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(bookDataSet.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 CBookMDlg: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:OnBnClickedBtnLast()/ 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 your 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_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() | 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,bookDataSet.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_bEdit=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 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_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 Pages 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);pWnd4 = 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=GetDlgItem(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_PREV);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(&rect); 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);/将变化后的对话框大小设为旧大小 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.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_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 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 CBookDataSet:GetDefaultConnect()return _T(ODBC;DSN=Library);CString CBookDataSet:GetDefaultSQL()return _T(BOOK);void CBookDataSet:DoFieldExchange(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, _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() constCRecordset: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.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/ 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 CBorrowDataSet: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 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 diagnostics#ifdef _DEBUGvoid CBorrowDataSet:AssertValid() constCRecordset:AssertValid();void CBorrowDataSet:Dump(CDumpContext& dc) constCRecordset:Dump(dc);#endif /_DEBUG5 CClerkDataSet.cpp/ CClerkDataSet.h : Implementation of the CClerkDataSet class/ CClerkDataSet implementation/ code generated on 2010年5月9日, 21:56#include stdafx.h#include CClerkDataSet.hIMPLEMENT_DYNAMIC(CClerkDataSet, CRecordset)CClerkDataSet:CClerkDataSet(CDatabase* pdb): CRecordset(pdb)m_CLERK_ID = L;m_NAME = L;m_ID_CARD = L;m_PASSWORD = L;m_OFFICIER = L;m_nFields = 5;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 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 CClerkDataSet:GetDefaultConnect()return _T(ODBC;DSN=Library);/*return _T(DSN=Library;DBQ=F:x4e34x65f6x6587x4ef6Visual_2BC_2B%2Bx9879x76eex6848x4f8bx5bfcx822ax6e90x4ee3x7801(x5168x90e8)x300aVisual+C+x9879x76eex6848x4f8bx5bfcx822ax6e90x4ee3x7801(x5168x90e8)x7b2c2x90e8x5206x6e90x7801Library.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;);*/CString CClerkDataSet:GetDefaultSQL()return _T(CLERK);void CClerkDataSet:DoFieldExchange(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, _T(CLERK_ID), m_CLERK_ID);RFX_Text(pFX, _T(NAME), m_NAME);RFX_Text(pFX, _T(ID_CARD), m_ID_CARD);RFX_Text(pFX, _T(PASSWORD), m_PASSWORD);RFX_Text(pFX, _T(OFFICIER), m_OFFICIER);/ CClerkDataSet diagnostics#ifdef _DEBUGvoid CClerkDataSet:AssertValid() constCRecordset:AssertValid();void CClerkDataSet:Dump(CDumpContext& dc) constCRecordset:Dump(dc);#endif /_DEBUG5 CHistoryDataSet.cpp/ CHistoryDataSet.h : Implementation of the CHistoryDataSet class/ CHistoryDataSet implementation/ code generated on 2010年5月20日, 22:55#include stdafx.h#include CHistoryDataSet.hIMPLEMENT_DYNAMIC(CHistoryDataSet, CRecordset)CHistoryDataSet:CHistoryDataSet(CDatabase* pdb): CRecordset(pdb)m_READER_ID = L;m_BOOK_ID = L;m_BORROW_DATE;m_RETURN_DATE;m_B_CLERK_ID = L;m_R_CLERK_ID = L;m_ID = 0;m_BOOK_ID=L;m_FineAmount = 0.0;m_nFields = 9;m_nDefaultType = dynaset;/#error Security Issue: The connection string may contain a password/ The connection string below may contain plain text pas

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论