📄 b借书.frm
字号:
Left = 2880
TabIndex = 15
Top = 1080
Width = 855
End
Begin VB.Label Label5
Caption = "罚款金额:"
Height = 375
Index = 2
Left = 240
TabIndex = 14
Top = 2160
Width = 975
End
Begin VB.Label Label6
Caption = "借书日期:"
Height = 375
Index = 1
Left = 240
TabIndex = 13
Top = 1560
Width = 975
End
Begin VB.Label Label1
Caption = $"B借书.frx":0000
Height = 495
Index = 1
Left = 600
TabIndex = 12
Top = 2520
Width = 735
End
Begin VB.Label Label8
Caption = "(4位)"
Enabled = 0 'False
ForeColor = &H000000FF&
Height = 255
Index = 0
Left = 2880
TabIndex = 11
Top = 480
Width = 855
End
Begin VB.Label Label2
Caption = "读者号:"
Height = 255
Left = 405
TabIndex = 10
Top = 480
Width = 735
End
Begin VB.Label Label4
Caption = "图书号:"
Height = 255
Left = 405
TabIndex = 9
Top = 1080
Width = 735
End
End
End
Attribute VB_Name = "B借书"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs As ADODB.Recordset
Dim SQL As String
Dim msg As String
Dim Index As Integer
Private Sub txtReadNo_Change()
'得到读者借书信息 罚款、未还图书数目、超期图书数目
'得到罚款
SQL = " select 罚款金额 from 读者信息表 where 读者号='" & Trim(txtReadNo.Text) & "'"
Set rs = SelectSQL(SQL, msg)
If rs.RecordCount > 0 Then '如果存在此读者号
Me.LblPenalty.Caption = rs.Fields("罚款金额")
Else
Me.LblPenalty.Caption = "无"
End If
'得到未还图书数
SQL = " select count(*) as num from 借还信息表 where 读者号='" & Trim(txtReadNo.Text) & "'"
SQL = SQL & " and 还书日期 is null "
Set rs = SelectSQL(SQL, msg)
If rs.RecordCount > 0 Then '如果存在统计结果
Me.LblNoReturn.Caption = rs.Fields("num")
Else
Me.LblNoReturn.Caption = "0"
End If
'得到超期图书数
Dim validNum As Integer
'如果没有续借
SQL = " select count(*) as num from 借还信息表 where 读者号='" & Trim(txtReadNo.Text) & "'"
SQL = SQL & " and 还书日期 is null and 续借日期 is null "
SQL = SQL & "and datediff(day,借书日期,getdate())>" & Sys_BorrowLimite
Set rs = SelectSQL(SQL, msg)
If rs.RecordCount > 0 Then '如果存在统计结果
validNum = rs.Fields("num")
End If
'如果已经续借了
SQL = " select count(*) as num from 借还信息表 where 读者号='" & Trim(txtReadNo.Text) & "'"
SQL = SQL & " and 还书日期 is null and 续借日期 is not null "
SQL = SQL & "and datediff(day,借书日期,getdate())>" & Sys_BorrowLimite + Sys_ContinueLimite
Set rs = SelectSQL(SQL, msg)
If rs.RecordCount > 0 Then '如果存在统计结果
validNum = validNum + rs.Fields("num")
Else
Me.LblValid.Caption = "0"
End If
If validNum = 0 Then
Me.LblValid.Caption = "0"
Else
Me.LblValid.Caption = validNum
End If
rs.Close
End Sub
Private Sub txtBookNo_Change()
'得到图书名称
SQL = " select 题名,作者,版次,图书数量 from 图书信息表 where 图书号='" & Trim(txtBookNo.Text) & "'"
Set rs = SelectSQL(SQL, msg)
If rs.RecordCount > 0 Then '如果存在查询结果
Me.LblBookName.Caption = rs.Fields("题名")
Me.LblAuthor.Caption = rs.Fields("作者")
Me.LblPubNo.Caption = rs.Fields("版次")
Me.LblNum.Caption = rs.Fields("图书数量")
Else
Me.LblBookName.Caption = "无"
Me.LblAuthor.Caption = "无"
Me.LblPubNo.Caption = "无"
Me.LblNum.Caption = "0"
End If
rs.Close
End Sub
Private Sub CmdSave_Click()
On Error GoTo ErrMsg '出错处理
If Not CheckData Then
Exit Sub '如果数据不合法就退出
'*******************************************************************************************************************************************
Else
'添加新数据
Call setData
Call ExecuteSQL(SQL, msg)
'图书的存储数量减少1
SQL = " update 图书信息表 set 图书数量=图书数量-1 where 图书号='"
SQL = SQL & Trim(Me.txtBookNo.Text) & "'"
Call ExecuteSQL(SQL, msg)
SQL = " update 借还信息表 set 图书号=Trim(txtBookNo.Text) and 读者号=Trim(txtReadNo.Text) and 借书日期=Trim(DTPicker1.Value)"
SQL = SQL & Trim(txtReadNo.Text) & "'"
Call ExecuteSQL(SQL, msg)
MsgBox ("成功添加数据!")
Call txtBookNo_Change '重新获得数据
Call txtReadNo_Change '重新获得数据
End If
Exit Sub
'*******************************************************************************************************************************************
ErrMsg:
MsgBox Err.Description, vbExclamation, "出错"
End Sub
Private Function CheckData() As Boolean
'检查数据的合法性
Dim msgt As String
msgt = ""
'检查数据
If Trim(Me.txtReadNo.Text) = "" Then '检查读者号是否为空
msgt = "读者号为空; "
ElseIf Trim(Me.txtBookNo.Text) = "" Then '检查图书号是否为空
msgt = "图书号为空; "
ElseIf Not Len(Trim(txtReadNo.Text)) = 4 Then '检查读者号是否为4位
msgt = "读者号不是4位; "
ElseIf Not Len(Trim(txtBookNo.Text)) = 6 Then '检查图书号是否为6位
msgt = "图书号不是6位; "
End If
If Not msgt = "" Then '如果错误消息不为空,给出错误提示
MsgBox (msgt)
CheckData = False '返回False
Exit Function
End If
'检查读者号的合法性,以及借书的合法性
If (Me.LblPenalty.Caption = "无") Then '如果查不到读者的罚款金额,说明该读者不存在
MsgBox ("读者号输入错误!")
CheckData = False '返回False
Exit Function
End If
If CInt(Me.LblNum.Caption) < 1 Then
MsgBox ("此书已被借出!")
CheckData = False '返回False
Exit Function
End If
If CDbl(Me.LblPenalty.Caption) > Sys_MaxPenalty Then
MsgBox ("请读者先交罚款!")
CheckData = False '返回False
Exit Function
End If
If CInt(Me.LblValid.Caption) > 0 Then
MsgBox ("请读者先归还超期的图书!")
CheckData = False '返回False
Exit Function
End If
If CInt(Me.LblNoReturn.Caption) >= Sys_MaxBorrow Then
MsgBox ("读者借书已经超过最大数量!")
CheckData = False '返回False
Exit Function
End If
'检查图书号的合法性
If (Me.LblBookName.Caption = "无") Then '如果查不到图书题名,说明不错在该图书
MsgBox ("图书号输入错误!")
CheckData = False '返回False
Exit Function
End If
CheckData = True '合法返回True
End Function
Private Sub setData()
SQL = "insert into 借还信息表 (读者号,图书号,借书日期,备注) values('"
SQL = SQL & Trim(Me.txtReadNo.Text) & "','"
SQL = SQL & Trim(Me.txtBookNo.Text) & "','"
SQL = SQL & Trim(Me.DTPicker1.Value) & "','"
SQL = SQL & Trim(Me.txtNotes.Text) & "')"
End Sub
Private Sub cmdCancel_Click()
'取消操作
'重置控件
Me.txtBookNo.Text = ""
Me.txtReadNo.Text = ""
Me.DTPicker1.Refresh
Me.txtNotes.Text = ""
End Sub
Private Sub CmdExit_Click()
'退出操作
图书管理系统.Enabled = True
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出操作
图书管理系统.Enabled = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -