📄 frmborrowbook.frm
字号:
VERSION 5.00
Begin VB.Form frmBorrowBook
Caption = "图书借阅"
ClientHeight = 4575
ClientLeft = 60
ClientTop = 450
ClientWidth = 3495
LinkTopic = "Form2"
MaxButton = 0 'False
ScaleHeight = 4575
ScaleWidth = 3495
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame2
Height = 735
Left = 120
TabIndex = 10
Top = 3720
Width = 3255
Begin VB.CommandButton cmdReturn
Caption = "返回"
Height = 375
Left = 2160
TabIndex = 12
Top = 240
Width = 735
End
Begin VB.CommandButton cmdOK
Caption = "借阅"
Height = 375
Left = 360
TabIndex = 11
Top = 240
Width = 735
End
End
Begin VB.Frame frabook
Caption = "图书信息"
Height = 1695
Left = 120
TabIndex = 3
Top = 2040
Width = 3255
Begin VB.TextBox txtState
Appearance = 0 'Flat
BackColor = &H00C0FFFF&
Enabled = 0 'False
Height = 375
Left = 1200
TabIndex = 9
Top = 1200
Width = 855
End
Begin VB.TextBox txtBookName
Appearance = 0 'Flat
BackColor = &H00C0FFFF&
Height = 375
Left = 1200
TabIndex = 7
Top = 720
Width = 1815
End
Begin VB.TextBox txtBookID
Appearance = 0 'Flat
Height = 375
Left = 1200
TabIndex = 6
Top = 240
Width = 1815
End
Begin VB.Label Label5
Caption = "图书状态:"
Height = 255
Left = 240
TabIndex = 8
Top = 1320
Width = 975
End
Begin VB.Label Label4
Caption = "图书名称:"
Height = 255
Left = 240
TabIndex = 5
Top = 840
Width = 1095
End
Begin VB.Label label3
Caption = "图书编号:"
Height = 375
Left = 240
TabIndex = 4
Top = 360
Width = 975
End
End
Begin VB.Frame Frame1
Caption = "学生信息:"
Height = 1815
Left = 120
TabIndex = 0
Top = 120
Width = 3255
Begin VB.OptionButton optSname
Caption = "姓名"
Height = 375
Left = 120
TabIndex = 16
Top = 720
Width = 735
End
Begin VB.OptionButton optSID
Caption = "学号"
Height = 255
Left = 120
TabIndex = 15
Top = 240
Width = 735
End
Begin VB.TextBox txtPSW
Appearance = 0 'Flat
Height = 375
IMEMode = 3 'DISABLE
Left = 960
PasswordChar = "*"
TabIndex = 14
Top = 1200
Width = 1815
End
Begin VB.TextBox txtSname
Appearance = 0 'Flat
Height = 375
Left = 960
TabIndex = 2
Top = 720
Width = 1815
End
Begin VB.TextBox txtSID
Appearance = 0 'Flat
Height = 375
Left = 960
TabIndex = 1
Top = 240
Width = 1815
End
Begin VB.Label Label6
Caption = "密码:"
Height = 255
Left = 360
TabIndex = 13
Top = 1320
Width = 735
End
End
End
Attribute VB_Name = "frmBorrowBook"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdOK_Click()
Dim strsql As String
Dim rsinfo As New ADODB.Recordset
Dim strSID As String
Dim strBID As String
'验证学生
If optSID.Value = True Then
If txtSID.Text = "" Then
MsgBox "请输入借阅者号码!", vbOKOnly, "错误"
txtSID.SetFocus
Exit Sub
Else
If txtPSW.Text = "" Then
MsgBox "请输入密码", vbOKOnly, "错误"
txtPSW.SetFocus
Exit Sub
Else
strsql = "select * from tblstudents where sid='" & txtSID.Text & "' and spsw='" & txtPSW.Text & "'"
End If
End If
End If
If optSname.Value = True Then
If txtSname.Text = "" Then
MsgBox "请输入借阅者姓名!", vbOKOnly, "错误"
txtSname.SetFocus
Exit Sub
Else
If txtPSW.Text = "" Then
MsgBox "请输入密码", vbOKOnly, "错误"
txtPSW.SetFocus
Exit Sub
Else
strsql = "select * from tblstudents where sname='" & txtSname.Text & "' and spsw='" & txtPSW.Text & "'"
End If
End If
End If
rsinfo.Open strsql, conLIB, adOpenDynamic, adLockOptimistic
If rsinfo.EOF And rsinfo.BOF Then
MsgBox "不存在此学生,或密码错误!", vbOKOnly, "错误"
rsinfo.Close
Set rsinfo = Nothing
txtSID.SelStart = 0
txtSID.SelLength = Len(txtSID.Text)
Exit Sub
Else
'学生验证通过
strSID = rsinfo!sid
If rsinfo.State = adStateOpen Then rsinfo.Close
'学号及密码在数据库中存在,可以借书
If txtBookID = "" Then
MsgBox "请输入要借阅的图书号!", vbOKOnly, "提示"
txtBookID.SetFocus
Exit Sub
Else
If txtBookID.Text <> "" Then
strsql = "select * from tblbooks where bookid='" & txtBookID.Text & "'"
End If
rsinfo.Open strsql, conLIB, adOpenDynamic, adLockOptimistic
If rsinfo.EOF And rsinfo.BOF Then
MsgBox "数据库中不存在此书,查证后再借阅", vbOKOnly, "提示"
rsinfo.Close
Set rsinfo = Nothing
Exit Sub
Else
If rsinfo!State <> 0 Then
'可以借,有库存
strBID = rsinfo!bookid
'更新书库表,此书标记已借出
strsql = "update tblbooks set state='0' where bookid='" & strBID & "'"
conLIB.Execute strsql
rsinfo.Close
Set rsinfo = Nothing
' 添加借阅信息到借阅表 ''''''''''''
strsql = "insert into tblborrow values('" & strSID & "','" & strBID & "','" & CDate(Date) & "','" & DateAdd("m", 1, Date) & "')"
conLIB.Execute strsql
MsgBox "借阅成功!", vbOKOnly, "提示"
txtSname.Text = ""
txtSID.Text = ""
txtBookID.Text = ""
txtBookName.Text = ""
txtState.Text = ""
txtPSW.Text = ""
Exit Sub
Else
rsinfo.Close
Set rsinfo = Nothing
MsgBox "此书已借出,请等其它人归还后再借!", vbOKOnly, "提示"
Exit Sub
End If
End If
End If
End If
End Sub
Private Sub cmdReturn_Click()
Unload Me
End Sub
Private Sub Form_Load()
optSID.Value = True
' txtSID.Enabled = True
optSname.Value = False
txtSname.Enabled = False
txtState.Enabled = False
txtBookName.Enabled = False
End Sub
Private Sub optSID_Click()
txtSID.Enabled = True
' txtSID.SetFocus
txtSname.Enabled = False
End Sub
Private Sub optSname_Click()
txtSID.Enabled = False
txtSname.Enabled = True
' txtSName.SetFocus
End Sub
Private Sub txtBookID_LostFocus()
Dim strsql As String
Dim rsbooks As New ADODB.Recordset
strsql = "select * from tblbooks where bookid='" & Trim(txtBookID.Text) & "'"
rsbooks.Open strsql, conLIB, adOpenDynamic, adLockOptimistic
If rsbooks.EOF And rsbooks.BOF Then
Else
txtBookName.Text = rsbooks!bookname
If rsbooks!State = 1 Then
txtState.Text = "库存"
Else
txtState.Text = "借出 "
End If
End If
rsbooks.Close
Set rsbooks = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -