javascript:alert('登陆失败!-1 : Response.Write("
赞
踩
摘 要
图书管理系统是典型的信息管理系统(MIS),其开发主要包括后台数据库的建立和维护以及前端应用程序的开发两个方面。对于前者要求建立起数据一致性和完整性强、数据安全性好的库。而对于后者则要求应用程序功能完备,易使用等特点。
因此本人结合开入式图书馆的要求,对MS SQL Server2000数据库管理系统、SQL语言原理、.NET应用程序设计进行了较深入的学习和应用,主要完成对图书管理系统的需求分析、功能模块划分、数据库需求分析,并由此设计了数据库结构和应用程序。系统运行结果证明,本文所设计的图书管理系统可以满足借阅者、图书馆工作人员的双方面的需要。
目录
一、 设计的目的和内容 1
二、 系统需求分析 1
三、 系统总体设计 1
3.1 总体功能结构图 1
3.2 系统流程图 2
四、 数据库设计 3
4.1 需求分析及数据字典 3
4.2 概念设计 4
4.3 逻辑设计 5
4.4 物理设计 6
4.5 SQL语句的实现 6
4.6 创建视图 7
4.7 创建存储过程 8
4.8 创建触发器 9
五、 使用ER/STUDIO完成数据库设计 10
六、 代码实现 11
6.1 “图书管理系统”的功能模块图 11
6.2 插入功能的实现 11
6.3修改/删除功能的实现 11
6.4 查询功能的实现 11
七、 总结 30
图书管理系统
一.系统设计目的和内容:
图书管理系统主要目的是对图书馆种类繁多的书籍进行管理,并且合理管理好用户的借还信息。提高图书馆的工作效率,降低管理成本。其开发主要包括后台数据库的建立和维护,以及前端应用程序的开发。前者要求建立起数据一致性各完整性强、数据安全性好的数据库。而后者则要求应用程序具有功能完备、易用等特点。因此本系统结合开放式图书馆的要求,采用SQL SERVER 2000数据库进行系统的开发。
二.系统需求分析:
三.系统总体设计
四.数据库设计
4.1数据库的需求分析:
本系统使用SQL SERVER2000作为应用程序的数据库。考虑到系统的实际需求,系统至少需要四张数据库表,具体如下:
数字字典
4.2概念设计
4.3逻辑设计
BOOKINFO USERS
MANGER
LENDINFO
六、 代码实现
6.1 “图书管理系统”的功能模块图
系统主界面:
Imports System.Data.SqlClient
Imports System.IO
Public Class searchN
Inherits System.Web.UI.Page
Private connectingstring As String
Private myConn As SqlConnection
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents radiobutton1 As System.Web.UI.WebControls.RadioButton
Protected WithEvents dropdownlist1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Private myCmd As SqlCommand
Public Sub Open()
myConn.Open()
End Sub
Public Sub Close()
myConn.Close()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
If Not IsPostBack Then
If Not Session("UserID") Is Nothing Then
If AllowBooking(Session("UserID")) = True Then
End If
End If
End If
End Sub
'private bind
Public Function GetRowsNum(ByVal sqlstr As String) As Integer
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
Close()
Return ds.Tables(0).Rows.Count
End Function
Public Function AllowBooking(ByVal UserID As String) As Boolean
Dim sqlstr As String = "select * from UserInfo,RoleInfo where UserInfo.RoleID=RoleInfo.RoleID and AllowBooking=1 and UserID='" + UserID + "'"
If GetRowsNum(sqlstr) = 0 Then
Return False
Else
Return True
End If
End Function
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myDBGrd.DataSource = ds.Tables(0).DefaultView
myDBGrd.DataBind()
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid, ByVal SortExp As Object)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
Dim dv As DataView = ds.Tables(0).DefaultView
dv.Sort = SortExp
myDBGrd.DataSource = dv
myDBGrd.DataBind()
End Sub
Private Sub BindGrid()
If Not Session("sqlstr") Is Nothing Then
Dim sqlstr As String = CType(Session("sqlstr"), String)
BindDBGrd(sqlstr, ResultGrid)
Session("sqlstr") = sqlstr
End If
End Sub
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim sign As String = ""
If AnyChoice.Checked = True Then
sign = "%"
End If
Dim sqlstr As String = "select * from BookInfo where 1=1 "sqlstr += " and " + dropdownlist1.SelectedValue + " like '" + sign + txtContent.Text.ToString.Trim + sign + "' "
Session("sqlstr") = sqlstr
BindGrid()
End Sub
Private Sub ResultGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles ResultGrid.PageIndexChanged
ResultGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Private Sub ResultGrid_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles ResultGrid.SortCommand
Dim sqlstr As String
If viewstate("sortexp") Is Nothing Then
viewstate("sortexp") = e.SortExpression.ToString
ElseIf viewstate("sortexp") = e.SortExpression.ToString Then
viewstate("sortexp") += " desc"
Else
viewstate("sortexp") = e.SortExpression.ToString
End If
If Not Session("sqlstr") Is Nothing Then
sqlstr = CType(Session("sqlstr"), String)
BindDBGrd(sqlstr, ResultGrid, Viewstate("sortexp"))
End If
End Sub
Public Sub ExecNonSql(ByVal sqlstr As String)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
myCmd = New SqlCommand(sqlstr, myConn)
myCmd.ExecuteNonQuery()
myCmd.Dispose()
Close()
End Sub
End Class
可以根据书名,内容进行查询,我们选取任意匹配:
如上图所示最上方为自定义用户控件:bar
点击权限维护:
Imports System.Data.SqlClient
Public Class user
Inherits System.Web.UI.Page
Private connectingstring As String
Private myConn As SqlConnection
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Login_trname As System.Web.UI.HtmlControls.HtmlTableRow
Protected WithEvents Login_trpassword As System.Web.UI.HtmlControls.HtmlTableRow
Private myCmd As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
End Sub
Public Function CheckUserberInfo(ByVal Userstr As String, ByVal Pwdstr As String) As Integer
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Dim sqlstr As String
If Pwdstr = "" Then
sqlstr = "select * from manage where manageid='" + Userstr.Trim + "' and Pass is null"
Else
sqlstr = "select * from manage where manageid='" + Userstr.Trim + "' and Pass='" + Pwdstr + "'"
End If
Fill(sqlstr)
If ds.Tables(0).Rows.Count = 0 Then
Close()
Return -1
End If
ds.Clear()
Close()
Return 1
End Function
Public Sub Open()
myConn.Open()
End Sub
Public Sub Close()
myConn.Close()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If CheckUserberInfo(TextBox1.Text, TextBox2.Text) = 1 Then
Session("UserID") = TextBox1.Text.ToString
Response.Redirect("delete.aspx")
Else
Response.Write("<script>javascript:alert('登陆失败!!!');</script>")
Response.Write("javascript:window.location='user.aspx'")
End If
End Sub
End Class
登陆成功后:
点击删除后:
再次查询时:
Imports System.Data.SqlClient
Public Class delete
Inherits System.Web.UI.Page
Dim myconn As SqlConnection
Private connectingstring As String
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Private myCmd As SqlCommand
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myDBGrd.DataSource = ds.Tables(0).DefaultView
myDBGrd.DataBind()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid, ByVal SortExp As Object)
If myconn.State = ConnectionState.Closed Then
myconn.Open()
End If
Fill(sqlstr)
Dim dv As DataView = ds.Tables(0).DefaultView
dv.Sort = SortExp
myDBGrd.DataSource = dv
myDBGrd.DataBind()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myconn = New SqlConnection(connectingstring)
If Not IsPostBack Then
Dim sqlstr As String = "select * from bookinfo "
BindDBGrd(sqlstr, DataGrid1)
Dim ds As DataSet = New DataSet
End If
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim sql As String
Dim getdata As SqlDataReader
Dim mycmd As SqlCommand
Dim uid As String = DataGrid1.Items(e.Item.ItemIndex).Cells(0).Text
sql = "delete from bookinfo where bookid='" + uid + "'"
mycmd = New SqlCommand(sql, myconn)
myconn.Open()
mycmd.ExecuteNonQuery()
myconn.Close()
mycmd.Dispose()
Response.Write("<script>javascript:alert('删除成功!!!');</script>")
End Sub
End Class
点击用户登录后:
Imports System.Data.SqlClient
Imports System.IO
Public Class WebForm1
Inherits System.Web.UI.Page
Private connectingstring As String
Private myConn As SqlConnection
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Private myCmd As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
End Sub
Public Function CheckUserberInfo(ByVal Userstr As String, ByVal Pwdstr As String) As Integer
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Dim sqlstr As String
If Pwdstr = "" Then
sqlstr = "select * from Users where UserID='" + Userstr.Trim + "' and Pass is null"
Else
sqlstr = "select * from Users where UserID='" + Userstr.Trim + "' and Pass='" + Pwdstr + "'"
End If
Fill(sqlstr)
If ds.Tables(0).Rows.Count = 0 Then
Close()
Return -1
End If
ds.Clear()
Close()
Return 1
End Function
Public Sub Open()
myConn.Open()
End Sub
Public Sub Close()
myConn.Close()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If CheckUserberInfo(TextBox1.Text, TextBox2.Text) = 1 Then
Session("UserID") = TextBox1.Text.ToString
Response.Redirect("userlist.aspx")
Else
Response.Write("<script>javascript:alert('登陆失败!!!');</script>")
Response.Write("javascript:window.location='Login.aspx'")
End If
End Sub
End Class
登录成功后:
Imports System.Data.SqlClient
Public Class userlist
Inherits System.Web.UI.Page
Dim myConn As SqlConnection
Private myCmd As SqlCommand
Private connectingstring As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
If Session("UserID") = "" Then
Response.Redirect("Login.aspx")
Else
LoadUserInfo(Session("UserID"))
End If
End Sub
Public Function ExecReaderSql(ByVal sqlstr As String) As SqlDataReader
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
myCmd = New SqlCommand(sqlstr, myConn)
Dim reader As SqlDataReader
reader = myCmd.ExecuteReader
myCmd.Dispose()
Return reader
End Function
Public Sub LoadUserInfo(ByVal UserID As String)
Dim sqlstr As String = "select * from Users where UserID='" + UserID + "'"
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
If myreader.Read Then
txtUserID.Text = myreader("UserID")
txtName.Text = myreader("username")
txtphone.Text = myreader("Phone")
txtaddress.Text = myreader("address")
txtEMail.Text = myreader("EMail")
End If
myConn.Close()
End Sub
End Class
点击查阅信息:
Imports System.Data.SqlClient
Public Class Lend
Inherits System.Web.UI.Page
Dim myConn As SqlConnection
Dim ds As DataSet
Private myAdapter As SqlDataAdapter
Private connectingstring As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
BindDBGrid()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myDBGrd.DataSource = ds.Tables(0).DefaultView
myDBGrd.DataBind()
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid, ByVal SortExp As Object)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
Dim dv As DataView = ds.Tables(0).DefaultView
dv.Sort = SortExp
myDBGrd.DataSource = dv
myDBGrd.DataBind()
End Sub
Private Sub BindDBGrid()
Dim sqlstr As String = "select * from BookInfo,LendInfo where BookInfo.BookID=LendInfo.BookID and UserID='" + Session("UserID") + "'"
BindDBGrd(sqlstr, DataGrid1)
End Sub
End Class
点击图书借阅登记:
Imports System.Data.SqlClient
Public Class lendbook
Inherits System.Web.UI.Page
Private connectingstring As String
Private myConn As SqlConnection
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Private myCmd As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
If txtUserID.Text.ToString.Trim <> "" Then
End If
End Sub
Public Sub ExecNonSql(ByVal sqlstr As String)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
myCmd = New SqlCommand(sqlstr, myConn)
myCmd.ExecuteNonQuery()
myCmd.Dispose()
myConn.Close()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myDBGrd.DataSource = ds.Tables(0).DefaultView
myDBGrd.DataBind()
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid, ByVal SortExp As Object)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
Dim dv As DataView = ds.Tables(0).DefaultView
dv.Sort = SortExp
myDBGrd.DataSource = dv
myDBGrd.DataBind()
End Sub
Private Sub BindDBGrid()
Dim sqlstr As String = "select * from BookInfo,LendInfo where BookInfo.BookID=LendInfo.BookID and IsBack=0 and UserID='" + txtUserID.Text.ToString + "'"
BindDBGrd(sqlstr, ListDGrid)
End Sub
Public Function ExecReaderSql(ByVal sqlstr As String) As SqlDataReader
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
myCmd = New SqlCommand(sqlstr, myConn)
Dim reader As SqlDataReader
reader = myCmd.ExecuteReader
myCmd.Dispose()
Return reader
End Function
Private Function GetBookID() As String
Dim sqlstr As String = "select BookID from BookInfo where BarCode='" + txtBookID.Text.ToString.Trim + "'"
Dim BookID As String = ""
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
If myreader.Read Then
BookID = myreader("BookID")
End If
myConn.Close()
Return BookID
End Function
Public Function GetCurNum(ByVal UserID As String) As Integer
Dim sqlstr As String = "select count(*) as Num from LendInfo where UserID='" + UserID + "' and IsBack=0 "
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
Dim num As Integer = 0
If myreader.Read Then
num = myreader("Num")
End If
myConn.Close()
Return num
End Function
Public Function GetRowsNum(ByVal sqlstr As String) As Integer
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myConn.Close()
Return ds.Tables(0).Rows.Count
End Function
Public Function GetBookState(ByVal BookID As String) As Integer
Dim sqlstr As String = "select * from BookInfo where BookState=1 and BookID=" + BookID
If GetRowsNum(sqlstr) = 0 Then
Return -2
End If
sqlstr = "select * from LendInfo where IsBack=0 and BookID =" + BookID
If GetRowsNum(sqlstr) <> 0 Then
Return -1
End If
sqlstr = "select * from BookingInfo where BookID=" + BookID
If GetRowsNum(sqlstr) <> 0 Then
Return 0
End If
Return 1
End Function
Public Function GetBookDate(ByVal UserID As String) As Integer
Dim sqlstr As String = "select BookDate from UserInfo where UserID='" + UserID + "'"
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
Dim num As Integer = 0
If myreader.Read Then
num = myreader("BookDate")
End If
myConn.Close()
Return num
End Function
Public Function LendBook(ByVal UserID As String, ByVal BookID As String) As Boolean
Dim datenum As Integer = GetBookDate(UserID)
Dim nowdate As Date = Date.Now
Dim ReturnDate As Date = nowdate.AddDays(datenum)
Dim sqlstr As String = "insert into LendInfo(BookID,UserID,LendDate,ReturnDate,IsBack)values( "
sqlstr += "'" + BookID + "'"
sqlstr += ",'" + UserID + "'"
sqlstr += ",'" + nowdate.ToShortDateString + "'"
sqlstr += ",'" + ReturnDate.ToShortDateString + "'"
sqlstr += ",0)"
ExecNonSql(sqlstr)
Return True
End Function
Public Function GetMax(ByVal UserID As String) As Integer
Dim sqlstr As String = "select BookNum from Users where UserID='" + UserID + "'"
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
Dim num As Integer = 0
If myreader.Read Then
num = myreader("BookNum")
End If
myConn.Close()
Return num
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = ""
Dim BookID As String = GetBookID()
If GetCurNum(txtUserID.Text) >= GetMax(txtUserID.Text.ToString) Then
Response.Write("<script>javascript:alert('借书数已满!!!');</script>")
Return
End If
Dim state As Integer = GetBookState(BookID)
If state = 1 Then
LendBook(txtUserID.Text.ToString.Trim, BookID)
Else
Select Case state
Case -2 : Response.Write("<script>javascript:alert('此书不在流通状态或此书不存在!!!');</script>")
Case -1 : Response.Write("<script>javascript:alert('此书不在书架上!!!');</script>")
Case 0 : Response.Write("<script>javascript:alert('此书已经有人预约!!!');</script>")
End Select
End If
BindDBGrid()
End Sub
End Class
七、 总结
这次课程设计用.NET来编写的,通过这次实践让我更进一步了解了.NET的基本的脚本的写法,虽然不是很熟练,但是还是知道不少,对SQL中数据库中基本操作也应用了不少,相信这次训练是受益非浅的。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。