当前位置:文档之家› mfc界面图书管理系统

mfc界面图书管理系统

目录1.设计目的 (1)2.问题描述 (2)3.需求分析 (2)3.1 数据需求 (2)3.2 基本功能需求 (2)3.3 非功能性需求 (3)4.概要设计 (3)5.详细设计 (5)5.4.1增加书籍 (20)5.4.2 删除书籍 (21)5.4.3 查询书籍 (21)6.调试分析 (22)7.使用说明 (23)8.设计总结 (26)9.参考文献 (27)《数据结构》课程设计图书管理1.设计目的“数据结构”是计算机科学与技术专业一门十分重要的专业技术基础课,计算机科学各领域及有关的应用软件都要使用到各种数据结构。

对于从事计算机科学及其应用的科技工作者来说,数据结构与算法是必须透彻地掌握的重要基础。

学习数据结构与算法的最终目的是解决实际的应用问题,特别是非数值计算类型的应用问题。

课程设计是加强学生实践能力的一个强有力手段。

课程设计所安排的题目,在难度和深度方面都大于平时的上机训练,要求同学在完成设计和编写中小型软件的过程中,深化对数据结构与算法课程中基本概念、理论和方法的理解;训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念;使同学的程序设计与调试水平有一个明显的提高。

课程设计要求学生在完成程序设计的同时能够撰写比较规范的设计报告。

严格实施课程设计这一环节,对于学生基本程序设计素养的培养和软件工作者工作作风的训练,将起到显著的促进作用。

2.问题描述采用Visual C++编程语言开发工具和MFC,设计并实现图书管理系统。

该系统实现了图书管理中的添加,查询,删除,全部查询,退出等功能,以及汇总图书清单,包括对书籍各项信息的汇总。

3.需求分析3.1 数据需求图书信息:书名,所属类型,作者,定价,出版日期以及ISBN。

3.2 基本功能需求1.汇总图书清单,包括对书籍各项信息的汇总;(各项信息包括书名,所属类型,作者,定价,出版日期以及ISBN。

)2.对书籍信息的增、删、查、全部查询等功能。

其中删除功能主要依靠第一无二的ISBN,查询功能可以依靠任何一种图书信息(即书名,所属类型,作者,定价,出版日期以及ISBN任意一种)。

3.3 非功能性需求用户界面需求:简洁、易用、易懂、友好的用户界面。

硬件要求:装有Visual C++6.0的计算机。

可靠性需求:保证用户在正常使用本系统时,用户的操作或误操作不会产生数据的丢失。

4.概要设计4.1 数据结构用结构struct定义图书信息,用链表实现对图书信息的存储及维护。

以文件的形式保存图书信息到硬盘。

4.2 系统包含的函数函数原型:void CAddDlg::OnButtonAdd()功能:在链表结尾添加一个结点并将链表信息存入文件“图书管理.txt”函数原型:void CChaxunDlg::OnButtonChaxun()功能: 完成查找用户信息的功能并在编辑框和用户列表中显示出来函数原型:void CDelDlg::OnButton1()功能: 删除链表和用户列表的当前结点函数原型:void CLookDlg::OnButtonDialog()功能: 在编辑框和用户列表中显示全部书籍出来4.3 函数间的关系1.进入程序调用booklist()从硬盘读取数据,并将信息放入链表中。

2.用函数CDelDlg::OnButton1()删除链表和用户列表的当前结点。

3.可用函数CAddDlg::OnButtonAdd()在链表结尾添加一个结点并在用户列表中显示haxunDlg::OnButtonChaxun()可实现按不同方式进行图书查询。

5.CLookDlg::OnButtonDialog()在编辑框和用户列表中显示全部书籍出来。

4.4 系统功能模块图图4-1 系统功能模块图5.详细设计5.1 结构体的详细定义class booklist{public:CString bookname;//书名CString congshuname;//丛书种类CString writer;//作者CString price;//价格CString dateyear;//出版年份CString datemonth;//出版月份CString ISBN;booklist *next;};5.2 系统函数详细介绍增加书籍:void CAddDlg::OnButtonAdd(){// TODO: Add your control notification handler code here UpdateData();extern booklist *head_book;if(m_bookname==""||m_congshuname==""||m_isbn==""||m_m onth==""||m_price==""||m_writer==""||m_year=="")MessageBox("请填写完整图书信息");else{booklist *p=head_book;booklist *Book=new booklist; Book->next=NULL;Book->bookname=m_bookname;Book->congshuname=m_congshuname; Book->datemonth=m_month;Book->dateyear=m_year;Book->ISBN=m_isbn;Book->price=m_price;Book->writer=m_writer;if(head_book==NULL)head_book=Book;else{if(p->ISBN>m_isbn){Book->next=head_book;head_book=Book;}else{while(p->next){if(p->next->ISBN>m_isbn){Book->next=p->next;p->next=Book;break;}p=p->next;}}if(p->next==NULL)p->next=Book;}MessageBox("添加成功");char* pszFileName = ".\\data.txt";CStdioFile myFile;CFileException fileException;CString str;if(!myFile.Open(pszFileName,CFile::modeCreate|CFile:: modeReadWrite,&fileException)){MessageBox("打开失败");TRACE("Cannotopenfile%s,error=%u\n",pszFileName,fileE xception.m_cause);}myFile.SeekToEnd();myFile.WriteString("书名,丛书名,作者,定价(元),出版年月, ISBN ");myFile.WriteString("\n");// extern booklist *head_book;for(p=head_book;p;p=p->next){str.Format("%s,%s,%s,%s,%s.%s,%s",p->bookname,p->cong shuname,p->writer,p->price,p->dateyear,p->datemonth,p->I SBN);myFile.SeekToEnd();myFile.WriteString(str);myFile.WriteString("\n");}// DestroyWindow(this);CDialog::OnCancel();}}BOOL CAddDlg::OnInitDialog(){CDialog::OnInitDialog();// TODO: Add extra initialization herem_isbn="978-7-115-";UpdateData(FALSE);return TRUE; // return TRUE unless you set the focus to //a control// EXCEPTION: OCX Property Pages should//return FALSE}void CAddDlg::OnCancel2(){// TODO: Add your control notification handler code here m_bookname=="";m_congshuname=="";m_isbn=="";m_month=="";m_price=="";m_writer=="";m_year=="";UpdateData(FALSE);}查询书籍:BOOL CChaxunDlg::OnInitDialog(){CDialog::OnInitDialog();LONG lStyle;lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE);//获//取当前窗口stylelStyle &= ~LVS_TYPEMASK; //清除显示方式位lStyle |= LVS_REPORT; //设置styleSetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle);//设置//styleDWORD dwStyle = m_list.GetExtendedStyle();dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮//(只适用与report风格的listctrl)dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report //风格的listctrl)// dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件m_list.SetExtendedStyle(dwStyle); //设置扩展风格m_list.InsertColumn( 0, "书名", LVCFMT_LEFT, 190 ); //插入列m_list.InsertColumn( 1, "丛书名", LVCFMT_LEFT, 100 );m_list.InsertColumn( 2, "作者", LVCFMT_LEFT, 120 );m_list.InsertColumn( 3, "定价", LVCFMT_LEFT, 50 );m_list.InsertColumn( 4, "出版日期", LVCFMT_LEFT, 80 );m_list.InsertColumn( 5, "ISBN", LVCFMT_LEFT, 140 );// TODO: Add extra initialization herem_bookname="不限";m_isbn="不限";m_price="不限";m_year="不限";m_month="不限";m_writer="不限";m_congshuname="不限";UpdateData(FALSE);return TRUE; // return TRUE unless you set the focus //to a control// EXCEPTION: OCX Property Pages should return FALSE }void CChaxunDlg::OnButtonChaxun(){// TODO: Add your control notification handler code here m_list.DeleteAllItems( );int i=0;//标记查找到的本数CString str;extern booklist *head_book;// m_ListBox.ResetContent();UpdateData();int nRow;for(booklist *p=head_book;p;p=p->next){if(m_bookname==""||m_bookname=="不限"||m_bookname==p->bookname)if(m_congshuname==""||m_congshuname=="不限"||m_congshuname==p->congshuname)if(m_writer==""||m_writer=="不限"||m_writer==p->writer)if(m_price==""||m_price=="不限"||m_price==p->price) if(m_isbn==""||m_isbn=="不限"||m_isbn==p->ISBN)if(m_year==""||m_year=="不限"||m_year==p->dateyear) if(m_month==""||m_month=="不限"||m_month==p->datemonth||m_month==p->datemonth.Left(2)| |(m_month==p->datemonth.Left(1)&&p->datemonth.Mid(1,1)== '(')){str.Format("%s",p->bookname);m_ListBox.AddString(str);str.Format("%s.%s",p->dateyear,p->datemonth);nRow = m_list.InsertItem(0, p->bookname);//插入行nRow = m_list.InsertItem(0, "sb");//插入行m_list.SetItemText(nRow, 1, p->congshuname);//设置数据m_list.SetItemText(nRow, 2, p->writer);//设置数据m_list.SetItemText(nRow, 3, p->price);//设置数据m_list.SetItemText(nRow, 4, str);//设置数据m_list.SetItemText(nRow, 5, p->ISBN);//设置数据i++;}}if(i==0)MessageBox("无此书");}删除书籍:void CDelDlg::OnButton1(){// TODO: Add your control notification handler code here UpdateData();int delbooknum=0;CString str;extern booklist *head_book;booklist *q,*p=head_book;//MessageBox(head_book->ISBN);while(p->ISBN==m_isbn){q=p;p=p->next;head_book=p;delbooknum++;delete q;}CString str1;if(head_book->next!=NULL){for(booklist *p=head_book;p;p=p->next){if(p->next!=NULL&&p->next->ISBN==m_isbn){str1.Format(" 书名: %s\nISBN: %s\n",p->next->bookname,p->next->ISBN);p->next=p->next->next;delbooknum++;}}}if(delbooknum==0)MessageBox("无此书","警告");else{str.Format("%s %d %s","已删除",delbooknum,"本");MessageBox(str1+str);char* pszFileName = ".\\data.txt";CStdioFile myFile;CFileException fileException;if(!myFile.Open(pszFileName,CFile::modeCreate|CFile:: modeReadWrite,&fileException)){MessageBox("打开失败");TRACE("Can not open file %s,error=%u\n",pszFileName,fileException.m_cause);}myFile.SeekToEnd();myFile.WriteString("书名,丛书名,作者,定价(元),出版年月, ISBN ");myFile.WriteString("\n");// extern booklist *head_book;for(booklist *p=head_book;p;p=p->next) {str.Format("%s,%s,%s,%s,%s.%s,%s",p->bookname,p->con gshuname,p->writer,p->price,p->dateyear,p->datemonth,p-> ISBN);myFile.SeekToEnd();myFile.WriteString(str);myFile.WriteString("\n");}CDialog::OnCancel();}}void CDelDlg::OnCancel(){// TODO: Add extra cleanup hereCDialog::OnCancel();}BOOL CDelDlg::OnInitDialog(){CDialog::OnInitDialog();// TODO: Add extra initialization herem_isbn="978-7-115-";UpdateData(FALSE);return TRUE; // return TRUE unless you set the focus toa control// EXCEPTION: OCX Property Pages should //return FALSE}查询全部书籍:BOOL CLookDlg::OnInitDialog(){CDialog::OnInitDialog();LONG lStyle;lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE); //获取当前窗口stylelStyle &= ~LVS_TYPEMASK; //清除显示方式位lStyle |= LVS_REPORT; //设置styleSetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle); //设置styleDWORD dwStyle = m_list.GetExtendedStyle();dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高//亮(只适用与report风格的listctrl)dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与//report风格的listctrl)// dwStyle |= LVS_EX_CHECKBOXES;//item前生成checkbox控件m_list.SetExtendedStyle(dwStyle); //设置扩展风格// TODO: Add extra initialization hereextern booklist *head_book;int booknum=0;extern length;CString str;m_list.InsertColumn( 0, "书名", LVCFMT_LEFT, 190 );//插入列m_list.InsertColumn( 1, "丛书名", LVCFMT_LEFT, 100 );m_list.InsertColumn( 2, "作者", LVCFMT_LEFT, 120 );m_list.InsertColumn( 3, "定价", LVCFMT_LEFT, 50 );m_list.InsertColumn( 4, "出版日期", LVCFMT_LEFT, 90 ); m_list.InsertColumn( 5, "ISBN", LVCFMT_LEFT, 180 );int nRow;for(booklist *q=head_book;q;q=q->next){str.Format("%s.%s",q->dateyear,q->datemonth);nRow = m_list.InsertItem(0, q->bookname);//插入行//nRow = m_list.InsertItem(0, "sb");//插入行m_list.SetItemText(nRow, 1, q->congshuname);//设置数据m_list.SetItemText(nRow, 2, q->writer);//设置数据m_list.SetItemText(nRow, 3, q->price);//设置数据m_list.SetItemText(nRow, 4, str);//设置数据m_list.SetItemText(nRow, 5, q->ISBN);//设置数据booknum++;}length=booknum;m_booknum=length;UpdateData(FALSE);return TRUE; // return TRUE unless you set the focus to //a control// EXCEPTION: OCX Property Pages should //return FALSE}void CLookDlg::OnButton1(){// TODO: Add your control notification handler code here CDelDlg dlg;dlg.DoModal();}5.3 系统功能模块介绍系统有四个模块其中包含了图书的增加,删除,查找(分按书名,所属类型,作者,定价,出版日期以及ISBN查找)及显示全部书籍。

相关主题