📄 addbook.frm
字号:
VERSION 5.00
Begin VB.Form addbook
BorderStyle = 1 'Fixed Single
Caption = "添加图书"
ClientHeight = 3960
ClientLeft = 45
ClientTop = 330
ClientWidth = 7125
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 3960
ScaleWidth = 7125
Begin VB.CommandButton CancelAdd
Caption = "取消"
Height = 495
Left = 3840
TabIndex = 17
Top = 3240
Width = 1095
End
Begin VB.CommandButton addBook
Caption = "添加"
Height = 495
Left = 2160
TabIndex = 16
Top = 3240
Width = 1095
End
Begin VB.Timer Timer1
Interval = 1000
Left = 240
Top = 3240
End
Begin VB.TextBox bookRentPrice
Height = 375
Left = 1680
TabIndex = 13
Top = 2040
Width = 1575
End
Begin VB.TextBox bookPrice
Height = 375
Left = 5160
TabIndex = 12
Top = 1440
Width = 1575
End
Begin VB.TextBox bookPress
Height = 375
Left = 1680
TabIndex = 11
Top = 1440
Width = 1575
End
Begin VB.TextBox bookType
Height = 375
Left = 5160
TabIndex = 10
Top = 840
Width = 1575
End
Begin VB.TextBox bookPy
Height = 375
Left = 1680
TabIndex = 9
Top = 840
Width = 1575
End
Begin VB.TextBox bookName
Height = 375
Left = 5160
TabIndex = 8
Top = 240
Width = 1575
End
Begin VB.TextBox bookId
Height = 375
Left = 1680
TabIndex = 7
Top = 240
Width = 1575
End
Begin VB.Label Label3
Caption = "注意: 图书类型 1为文学类,2为社科类 出版商类型 1,2,3等等。不要填错"
Height = 615
Left = 600
TabIndex = 18
Top = 2640
Width = 6495
End
Begin VB.Label Label1
Caption = "当前时间"
Height = 375
Index = 7
Left = 3960
TabIndex = 15
Top = 2040
Width = 975
End
Begin VB.Label Label2
Alignment = 2 'Center
Height = 375
Left = 5160
TabIndex = 14
Top = 2040
Width = 1575
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "出租价格"
Height = 375
Index = 6
Left = 360
TabIndex = 6
Top = 2040
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "购买价格"
Height = 375
Index = 5
Left = 3840
TabIndex = 5
Top = 1440
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "出版商"
Height = 375
Index = 4
Left = 360
TabIndex = 4
Top = 1440
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "图书名称"
Height = 375
Index = 3
Left = 3840
TabIndex = 3
Top = 240
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "拼音简写"
Height = 375
Index = 2
Left = 360
TabIndex = 2
Top = 840
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "图书类型"
Height = 375
Index = 1
Left = 3840
TabIndex = 1
Top = 840
Width = 1095
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "图书编号"
Height = 375
Index = 0
Left = 360
TabIndex = 0
Top = 240
Width = 1095
End
End
Attribute VB_Name = "addbook"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim GetId, GetName, GetPy As String
Dim GetType, GetPress, GetState, GetTimes As Integer
Dim GetPrice, GetRentPrice As Double
Dim GetDate As Date
Private Sub addBook_Click() '添加新书
If Label2.Caption <> "" Then
Timer1.Enabled = False '将记时器停止,添加的时间即是Label2的标题属性
GetId = bookId
GetName = bookName '分别将图书信息存入变量
GetPy = bookPy
GetType = Val(bookType)
GetPress = Val(bookPress)
GetPrice = Val(bookPrice)
GetRentPrice = Val(bookRentPrice)
GetState = 1
GetTimes = 0
GetDate = Label2.Caption
If bookId = "" Or bookName = "" Or bookPy = "" Or bookType = "" Or bookPress = "" Or bookPrice = "" Or bookRentPrice = "" Then
MsgBox "所有项都必须填写", vbOKOnly, "错误"
Else
Dim rst1 As ADODB.Recordset
Set rst1 = New ADODB.Recordset '该记录集用于判断ID是否重复
rst1.Open "select id from bookinfo where id='" & GetId & "'", cnn, adOpenDynamic, adLockReadOnly
If Not rst1.EOF Then
MsgBox "该书号已经存在!", vbOKOnly, "错误"
rst1.Close
Set rst1 = Nothing
Else
On Error Resume Next
Err.Clear
Dim rst As ADODB.Recordset '打开记录集,用ADDNEW方法添加新记录
Set rst = New ADODB.Recordset
rst.Open "select * from bookinfo where id is null", cnn, adOpenDynamic, adLockPessimistic
rst.AddNew
rst("id") = GetId
rst("name") = GetName
rst("py") = GetPy
rst("type") = GetType
rst("press") = GetPress
rst("state") = GetState
rst("buyprice") = GetPrice
rst("rentprice") = GetRentPrice
rst("times") = GetTimes
rst("Joindate") = GetDate
rst.Update
If Err.Number <> 0 Then
MsgBox "输入项有错,请检查 " & Err.Description, vbOKOnly, "出错"
Timer1.Enabled = True
Else
Timer1.Enabled = True
MsgBox GetName & "添加成功。 " & GetDate, vbOKOnly, "操作成功"
End If
rst1.Close
Set rst1 = Nothing
End If
End If
End If
End Sub
Private Sub CancelAdd_Click()
Unload Me
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Now()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -