图3.4借书模块运行界面
借书模块代码如下:
首先在代码窗口声明如下一些变量:
Private bookds As New DataSet ‘图书数据集
Private readerds As New DataSet ‘读者数据集
Private borrowds As New DataSet ‘借出图书数据集
Private bookstr As String ‘查询图书表字串
Private readerstr As String ‘查询读者表字串
Private borrowstr As String ‘查询借出图书表字串
窗体的load事件设置借书时间为系统的当前日期:
txtBorrowTime.Text = Date.Now.ToShortDateString
在“读者编号”文本框按下回车键,如果输入的读者编号不为空,则从读者表中查询读者编号为输入的编号的读者资料,如果找到,显示该读者的信息,然后从借出图书表查询该读者的已借书信息,“图书编号”文本框有效并获得焦点。代码如下:
Private Sub txtReaderId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtReaderId.KeyDown
If e.KeyCode = Keys.Return Then
If txtReaderId.Text <> "" Then
readerstr = "select * from 读者 where 编号='" & txtReaderId.Text & "'"
Try
readerds.Clear()
OleConn.SelectQuery(readerstr, readerds)
If readerds.Tables.Count < 1 Or readerds.Tables(0).Rows.Count < 1 Then
MsgBox("找不到此读者")
Else
Dim dr As DataRow = readerds.Tables(0).Rows(0)
If Not dr.IsNull("姓名") Then
txtReaderName.Text = dr("姓名")
End If
If Not dr.IsNull("性别") Then
txtReaderSex.Text = dr("性别")
End If
If Not dr.IsNull("类别") Then
txtReaderType.Text = dr("类别")
End If
If Not dr.IsNull("联系电话") Then
txtReaderTelephone.Text = dr("联系电话")
End If
If Not dr.IsNull("住址") Then
txtReaderAddress.Text = dr("住址")
End If
If Not dr.IsNull("登记日期") Then
txtReaderAddTime.Text = dr("登记日期")
End If
If Not dr.IsNull("借书次数") Then
txtLendCount.Text = dr("借书次数")
End If
If Not dr.IsNull("可借书数") Then
txtCanBorrowCount.Text = dr("可借书数")
End If
If Not dr.IsNull("未还书数") Then
txtUnReturnedCount.Text = dr("未还书数")
End If
txtReturnTime.Text = CDate(txtBorrowTime.Text).AddDays(CInt(dr.Item("借书期限")))
borrowstr = "select * from 借出图书 where 借书者编号='" & txtReaderId.Text & "' and 在馆='否'"
borrowds.Clear()
OleConn.SelectQuery(borrowstr, borrowds)
grdLendBook.SetDataBinding(borrowds, "Table")
txtBookId.Enabled = True
btnLend.Enabled = False
txtBookId.Focus()
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End If
End Sub
在“图书编号”文本框按下回车键,查询借出图书表,查询字串如下:
Private Sub txtBookId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBookId.KeyDown
If e.KeyCode = Keys.Return Then
If txtBookId.Text <> "" Then
Try
If rdoBookId.Checked Then
bookstr = "select * from 图书 where 图书编号='" & txtBookId.Text & "'"
Else
bookstr = "select * from 图书 where 条形码='" & txtBookId.Text & "'"
End If
bookds.Clear()
OleConn.SelectQuery(bookstr, bookds)
If bookds.Tables.Count < 1 Or bookds.Tables(0).Rows.Count < 1 Then
MsgBox("找不到此书")
Else
Dim dr As DataRow = bookds.Tables(0).Rows(0)
If Not dr.IsNull("书名") Then
txtBookName.Text = dr.Item("书名")
End If
If Not dr.IsNull("类别") Then
txtBookType.Text = dr("类别")
End If
If Not dr.IsNull("作者") Then
若图片无法显示请联系QQ752018766,本论文免费,转发请注明源于www.youerw.com
OleConn.DisplayError(ex)
End Try
End If
End If
End Sub
单击“借书”按钮,修改借出图书表的还书日期字段值为系统的当前日期,“在馆”字段值为“否”,将读者表的已借书数字的段值加1,借书日期字段值为系统的当前日期,图书表的现存数量字段值减1,“借书”按钮失效,提示借书成功如图3.5所示:
图3.5借书成功
代码如下:
Private Sub btnLend_Click(ByVal sender As Object, ByVal e As
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页