数据库课程设计图书馆管理系统.doc

上传人:laozhun 文档编号:2395596 上传时间:2023-02-17 格式:DOC 页数:30 大小:669.50KB
返回 下载 相关 举报
数据库课程设计图书馆管理系统.doc_第1页
第1页 / 共30页
数据库课程设计图书馆管理系统.doc_第2页
第2页 / 共30页
数据库课程设计图书馆管理系统.doc_第3页
第3页 / 共30页
数据库课程设计图书馆管理系统.doc_第4页
第4页 / 共30页
数据库课程设计图书馆管理系统.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《数据库课程设计图书馆管理系统.doc》由会员分享,可在线阅读,更多相关《数据库课程设计图书馆管理系统.doc(30页珍藏版)》请在三一办公上搜索。

1、数 据 库 课 程 设 计 题 目: 图书馆管理系统 目录摘要4第一章 绪论5第二章 需求分析62.1 需求概述62.2 用例图6第三章 系统流程图7第四章 数据库建立84.1 数据字典84.2逻辑设计104.3物理设计134.4 关系图144.5存储过程的创建144.6触发器的创建154.7 规则的建立16第五章 数据库应用开发175.1 主窗体设计175.2 读者功能模块175.3 管理员功能模块225.4 系统管理员模块23第六章 数据录入与上机测试26第七章 结论29参考文献30 摘要本文是应用vb、sqlserver2000开发一个小型的图书馆管理系统,主要包括前台(vb实现)与后台

2、(sqlserver2000实现)的设计。包括了数据库与vb的一些基本功能的运用,熟悉开发软件应用程序的基本流程。一个图书馆管理系统有利于书籍的分类与管理,以及读者的管理。这个图书管理系统实现了读者的一些基本的运用功能,包括查询图书、借阅图书、归还图书、续借图书等,以及管理员管理图书(包括添加与注销图书)的功能,和系统管理员对管理员与读者的管理功能。系统运行结果说明本系统能够实现基本的图书馆功能。关键词:Sqlserver2000,vb,图书管理系统,设计 Abstract This paper is using vb, sqlserver2000 develop a small librar

3、y management system, mainly including the receptionist (vb realize) and backend (sqlserver2000 realize) design. Includes database and some basic functions of vb application development software applications, familiar with the basic process. A library management system will help books of classificati

4、on and management, and readers management. This books management system management system realizes the readers some of the basic use function, including inquires the books, borrowing books, return books, renew the book and so on, as well as administrator management books (including adding and cancel

5、lation books) function, and administrators to administrator with the reader management functions. System operation results this system can realize the basic function of the library. Keywords: Sqlserver2000, vb, books management system management system, design 第一章 绪论该图书馆管理系统实现了基本的图书、读者管理的功能。用sqlserv

6、er2000做后台,实现表的建立,有读者表(reader)、图书表(book)、借阅表(borrow)、管理员表(admin)。管理员的功能仅限于对图书,而系统管理员可以对管理员与读者进行操作。管理员的功能有:个人信息查询、密码修改、图书添加、图书修改、读者信息查询等。读者的功能有:个人信息查询、密码修改、借阅信息查询、借阅图书、图书查询等,借阅信息查询中包括有续借、归还。对后台表的操作包括数据的添加管理,关系图的建立,存储过程的建立以及存储器的建立,从而来实现对表中数据的操作。前台窗体的建立包括标签、文本框、按钮、表格等。前台与数据库的连接用到ADO。 第二章 需求分析2.1 需求概述图书馆

7、管理系统实现图书的管理及读者借书功能。随着科学技术的不断提高图书管理系统的功能也越来越齐全。通过图书馆管理系统实现读者的借书、还书等功能,及图书的数目分类管理等功能。读者登录之后可以进行个人信息查询及修改,图书查询、借阅、续借、归还等功能。管理员登陆之后可以对读者信息进行查询,和个人信息的查询和修改,以及图书的添加和注销的功能。而对于系统管理员是系统中默认的可以对管理员及读者进行管理。2.2 用例图 根据上面的需求概述,得出程序的主要用例图,如图1所示。 查询读者 管理员登录图书查询续借归还图书借阅图书添加图书注销系统管理员 图1 第三章 系统流程图 该图书馆管理系统的系统流程图如下图2所示开

8、始读者登录系统管理员登录管理员登录个人信息查询图书信息查询图书续借归还图书借阅个人信息查询添加注销读者添加注销管理员个人信息查询添加注销图书密码修改读者还书确认结束 图1.2系统流程图 第四章 数据库建立数据库的建立包括概念设计,逻辑设计,物理设计等多个方面。具体包括由E-R图到表的建立,关系图等的建立。由于系统的需求建立四张表的信息如下:读者信息表(reader):包括读者证号、密码、姓名、性别、住址、联系电话、借书数目。反映了读者的一些基本的信息。图书信息表(book):包括图书编号、图书名称、作者、出版社、出版日期、总量、库存量。反映了图书的一些基本信息。借阅表(borrow):包括读者

9、证号、图书编号、读者姓名、图书名称、借阅时间、归还时间。反映了某读者的借阅信息。管理员表(admin):包括工作号、密码、姓名、住址、联系电话。概括了管理员的基本信息。4.1 数据字典一、数据项reader数据项名涵义说明数据类型长度与其他数据项之间的逻辑关系读者证号读者相关信息Char20决定了要借的图书密码读者相关信息Char20决定了要借的图书姓名读者相关信息Char40决定了要借的图书性别读者相关信息Char3决定了要借的图书住址读者相关信息Char40决定了要借的图书联系电话读者相关信息Char13决定了要借的图书借书数目读者相关信息Int4决定了要借的图书book数据项名涵义说明数

10、据类型长度与其他数据项之间的逻辑关系图书编号图书相关信息Char20图书名称图书相关信息Char40作者图书相关信息Char40出版社图书相关信息Char40出版日期图书相关信息Datetime8总量图书相关信息Int4库存量图书相关信息Int4admin数据项名涵义说明数据类型长度与其他数据项之间的逻辑关系工作号管理员信息Char20管理图书借还密码管理员信息Char10管理图书借还姓名管理员信息Char40管理图书借还住址管理员信息Char40管理图书借还联系电话管理员信息Char13管理图书借还borrow数据项名涵义说明数据类型长度与其他数据项之间的逻辑关系借阅时间借书信息Dateti

11、me8还书时间借书信息Datetime8二、数据流数据结构名含义说明组成读者表定义了读者相关信息读者证号、密码、姓名、性别、住址、联系电话、借书数目图书表定义了图书相关信息图书编号、图书名称、作者、出版社、出版日期、总量、库存量借阅表定义借阅图书相关信息读者证号、读者姓名、图书编号、图书名称、借阅时间、归还时间管理员表定义了管理员相关信息工作号、密码、姓名、住址、联系电话4.2 逻辑设计一、E-R图读者实体的E-R图读者读者证号密码姓名性别住址联系电话借书数目书籍实体的E-R图图书图书编号图书名称作者出版社出版日期总量库存量管理员实体E-R图管理员工作号密码姓名住址联系电话借阅信息E-R图借阅

12、读者证号姓名图书编号图书名称借阅时间还书时间总的信息E-R图读者图书管理员借阅管理二、E-R图到关系模式的转变1、 由于概念设计的结果是ER图,DBMS一般采用关系模型,因此数据库的逻辑设计过程就是把ER图转化为关系模式的过程。由于关系模型所具有的优点,逻辑设计可以充分运用关系数据库规范化理论,使设计过程形式化地进行。设计结果是一组关系模式的定义。将上面的E-R图转变成关系模式如下:(1)、读者(读者证号,密码,姓名,性别,住址,联系电话,借书数目) (2)、书籍(ISBN,图书名称,作者,出版社,出版日期,图书总量,库存量)(3)、管理员(工作号,密码,姓名,性别,地址,联系电话)(4)、借

13、阅(读者证号,ISBN,读者姓名,图书名称,借书时间,还书时间)2、在实际建立时在sqlserver2000中建一个books库其中表的信息如下(1)reader(读者表)readerid(读者证号): char(20) primarykeypwd(密码):char(20) notnullreadername(读者姓名)char(40) notnullreadersex(性别) char(3) notnulladdress(住址) char(40) notnullphone(联系电话) char(13) notnullborrownum(借书数目) int notnull(2)book(图书表

14、) ISBN(图书编号) char(20) primarykey bookname(图书名称) char(40) notnull writer(作者) char(40) notnull publish(出版社) char(40) notnull publishtime(出版日期) datetime notnull total(总量) int notnull bookcount(库存量) int notnull(3)borrow(借阅表) readerid(读者证号) char(20)primarykey readername(读者姓名) char(40) notnull ISBN(图书编号)

15、char(20) primarykey bookname(图书名称) char(40) notnull borrowdate(借阅时间) datetime notnull backtime(还书时间) datetime notnull(4)admin(管理员表) adminid(工作号) char(20) primarykey pwd(密码) char(10) notnull adminname(姓名) char(40) notnull address(住址) char(40) notnull phone(联系电话) char(13) notnull4.3 物理设计reader表book表bo

16、rrow表admin表4.4 关系图4.5 存储过程的创建存储过程是数据库中的子程序,可以在服务端运行,并且运行速度快。运用存储过程可以对库中的表进行查询。在前台中用 execute 存储工程名 (参数)来调用存储过程。create proc p1 (id char(20)asbeginif exists (select * from reader where readerid=id) begin select * from reader where readerid=id endendcreate proc p2 (name char(40)asbeginif exists (select

17、* from reader where readername=name) begin select * from reader where readername=name endendcreate proc p3 (address char(40)asbeginif exists (select * from reader where address=address) begin select * from reader where address=address endend4.6 触发器的创建触发器是一种特殊的存储过程,与表关系密切用于维护表中的数据。当对表有insert、delete、u

18、pdate操作是就发触发触发器。触发器是自动运行的。create trigger t1 on borrowfor insert, deleteasbeginif exists(select * from inserted)and not exists(select * from deleted)beginupdate book set bookcount=bookcount-1 where ISBN in (select ISBN from inserted)endif not exists(select * from inserted)and exists(select * from del

19、eted)beginupdate book set bookcount=bookcount+1 where ISBN in (select ISBN from deleted)endendcreate trigger t2 on borrowfor insert, deleteasbeginif exists(select * from inserted)and not exists(select * from deleted)beginupdate reader set borrownum=borrownum+1 where readerid in (select readerid from

20、 inserted)endif not exists(select * from inserted)and exists(select * from deleted)beginupdate reader set borrownum=borrownum-1 where readerid in (select readerid from deleted)endend4.7 规则的建立规则可以对表的属性进行限制create rule rule_sexassex=男 or sex=女create rule rule_numasnum=8建立了两个规则,分别设置性别输入男或女时才有效,数目小于等于八。在

21、sqlserver2000中找到所建的规则,选中绑定列将rule_sex绑定到reader表的性别属性,将rule_num绑定到borrownum。当读者借书数目超过8时即不能在借书。 第五章 数据库应用开发运用vb设计前台画面来设计一个图书馆管理系统。5.1 主窗体的设计主窗体的界面如下所示在主窗体中设计了一个下拉式菜单有读者登录、管理员登录、系统管理员登录。在vb工具栏下的菜单编辑器下进行下拉菜单的设计。通过登录分别进入不同的界面运用代码Form3.ShowUnload Form1来实现不同界面之间的跳转。5.2 读者功能模块一、读者登录的代码验证(1)定义的两个变量用来连接数据库Dim

22、conn As New ADODB.ConnectionDim rs As New ADODB.Recordset(2)用户名是否为空判断If Trim(Text1.Text = ) Then MsgBox 用户名不能为空!, 48, 警告!ElseIf Trim(Text2.Text = ) Then MsgBox 密码不能为空, 48, 警告!End If(3)连接数据库代码Private Sub Form_Load()conn.ConnectionString = Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security

23、Info=False;Initial Catalog=booksconn.OpenIf conn.State = 1 ThenMsgBox 数据库连接成功!, 64, 提示ElseMsgBox 数据库连接失败!, 48, 警告End IfEnd Sub(4)通过select语句查找用户是否存在str1 = select * from reader where readerid= & Text1.Text & rs.Open str1, conn, 1, 3If rs.EOF ThenMsgBox 该用户不存在!, 48, 警告ElseIf Trim(rs.Fields(1) = Trim(Te

24、xt2.Text) ThenUserName = Trim(Text1.Text)Form5.ShowUnload Form2Else MsgBox 密码不正确!请重新输入!, 48, 警告End IfEnd IfEnd Sub二、个人信息查询功能主要代码Private Sub Form_Load()conn.ConnectionString = Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=booksconn.Openstr2 = select * from r

25、eader where readerid= & UserName & rs.Open str2, conn, adOpenKeysetIf rs.EOF ThenMsgBox 该用户不存在!, 48, 警告ElseLabel7.Caption = UserNameLabel8.Caption = rs.Fields(1)Label9.Caption = rs.Fields(2)Label10.Caption = rs.Fields(3)Label11.Caption = rs.Fields(4)Label12.Caption = rs.Fields(5)End IfEnd Sub三、读者密码修

26、改功能代码Private Sub Command1_Click()If Trim(Text2.Text) = Trim(Text3.Text) Thenstr3 = select * from reader where readerid= & UserName & If rs.State = 1 Thenrs.CloseEnd Ifrs.Open str3, conn, 1, 3rs.Fields(1) = Text2.Textrs.Updaters.CloseMsgBox 密码修改成功!, 64, 信息Me.HideElseMsgBox 两次密码不一致!, 48, 警告End IfEnd S

27、ub四、查询借书记录功能代码Private Sub Form_Load()Label1.Caption = & UserName & 借书记录如下表conn.ConnectionString = Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=booksconn.OpenIf conn.State = 1 ThenMsgBox 数据库连接成功!, 64, 提示ElseMsgBox 数据库连接失败!, 48, 警告End Ifstr4 = select * from

28、borrow where readerid= & UserName & rs.Open str4, conn, adOpenKeysetWith MSFlexGrid1.Rows = 2.CellAlignment = 4.TextMatrix(1, 0) = 学号.TextMatrix(1, 1) = 姓名.TextMatrix(1, 2) = 图书编号.TextMatrix(1, 3) = 图书名称.TextMatrix(1, 4) = 借阅日期.TextMatrix(1, 5) = 最迟还书日期Do While Not rs.EOF .Rows = .Rows + 1 .CellAlig

29、nment = 4 .TextMatrix(.Rows - 1, 0) = UserName .TextMatrix(.Rows - 1, 1) = rs.Fields(1) .TextMatrix(.Rows - 1, 2) = rs.Fields(2) .TextMatrix(.Rows - 1, 3) = rs.Fields(3) .TextMatrix(.Rows - 1, 4) = Format(rs.Fields(4), yyyy-mm-dd) .TextMatrix(.Rows - 1, 5) = Format(rs.Fields(5), yyyy-mm-dd) rs.MoveN

30、extLoopEnd Withrs.CloseEnd Sub此处用到flexgrid来实现将查询结果用一个表来显示用下面的两句代码来实现图书的续借与归还,由于对borrow表建立了触发器t1与t2,当执行到删除语句时就会触发t1与t2对reader表中的结束数目和book表中的库存自动改变续借图书代码Private Sub Command1_Click()If Trim(Text1.Text = ) ThenMsgBox 请输入图书编号, 48, 警告End Ifstr5 = select * from borrow where readerid= & UserName & and ISBN=

31、 & Text1.Text & If rs.State = 1 Thenrs.CloseEnd Ifrs.Open str5, conn, 1, 3If rs.EOF ThenMsgBox 错误, 48, 警告Elseconn.Execute (update borrow set backtime=backtime+15)MsgBox 续借成功, 64, 提示End IfEnd Sub归还图书代码Private Sub Command1_Click()If Trim(Text1.Text = ) ThenMsgBox 请输入归还图书编号, 48, 警告End Ifstr7 = select *

32、 from borrow where readerid= & UserName & and ISBN= & Text1.Text & If rs.State = 1 Thenrs.CloseEnd Ifrs.Open str7, conn, 1, 3If rs.EOF ThenMsgBox 错误, 48, 警告Elseconn.Execute (delete from borrow where readerid= & UserName & and ISBN= & Text1.Text & )MsgBox 归还成功!, 64, 提示rs.CloseEnd IfEnd Sub五、图书借阅功能的实现

33、Private Sub Command1_Click()str8 = select reader.readername,book.bookname from reader join book on (readerid= & UserName & and ISBN= & Text1.Text & )rs.Open str8, conn, 1, 3conn.Execute (insert into borrow values( & UserName & , & rs.Fields(0) & , & Text1.Text & , & rs.Fields(1) & ,getdate(), )MsgBo

34、x 借阅成功!, 64, 信息If rs.State = 1 Thenrs.CloseEnd If六、图书查询功能的实现此处用到模糊查询和vb中的checkbox选项str1 = select * from book where bookname like & Text1.Text & %str1 = select * from book where ISBN like & Text1.Text & %str1 = select * from book where writer like & Text1.Text & %5.3 管理员功能模块一、管理员个人信息查询与图书的添加删除主要代码str

35、1 = select * from book where ISBN= & Text1.Text & If rs.State = 1 Thenrs.CloseEnd Ifrs.Open str1, conn, 1, 3If rs.EOF Thenconn.Execute (insert into book values( & Text1.Text & , & Text2.Text & , & Text3.Text & , & Text4.Text & , & Text5.Text & , & Text6.Text & , & Text6.Text & )MsgBox 新添加图书成功!, 64,

36、信息Elseconn.Execute (update book set total=total+ & Text6.Text & )conn.Execute (update book set bookcount=bookcount+ & Text6.Text & )MsgBox 数量增加成功, 64, 信息End If二、读者信息查询功能的实现这里用到了存储过程p1与p2代码如下If Check1(0).Value Then If Trim(Text1.Text) = Then MsgBox 学号不能为空!, 48, 警告 Else str1 = execute p1 & Text1.Text

37、& End IfEnd IfIf Check1(1).Value Then If Trim(Text1.Text) = Then MsgBox 姓名不能为空!, 48, 警告 Else str1 = execute p2 & Text1.Text & End If End If If Check1(2).Value Then If Trim(Text1.Text) = Then MsgBox 请输入住址, 48, 警告 Else str1 = execute p3 & Text1.Text & End If End If这里的用到vb中的控件checkbox其功能实现代码如下:Option E

38、xplicitDim IsBusy As BooleanPrivate Sub Check1_Click(Index As Integer)If Check1(Index).Value = 0 Or IsBusy Then Exit SubDim i As IntegerIsBusy = TrueFor i = 0 To Check1.UBoundIf i Index Then Check1(i).Value = 0NextIsBusy = FalseEnd Sub5.4 系统管理员功能的实现一、添加读者与管理员添加读者Private Sub Command1_Click()str1 = se

39、lect * from reader where readerid= & Text1.Text & If rs.State = 1 Thenrs.CloseEnd Ifrs.Open str1, conn, 1, 3If rs.EOF Thenconn.Execute (insert into reader values( & Text1.Text & , & Text2.Text & , & Text3.Text & , & Text4.Text & , & Text5.Text & , & Text6.Text & ,0)MsgBox 读者添加成功!, 64, 信息ElseMsgBox 该读者已存在!, 48, 警告rs.CloseEnd IfEnd Sub添加管理员Private Sub Command1_Click()str1 = select * from admin where adminid= & Text1.Text & If rs.State = 1 Thenrs.CloseEnd Ifrs.Ope

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号