📄 frmaddbookstyle.frm
字号:
VERSION 5.00
Begin VB.Form 添加图书类别
BackColor = &H00C0C0C0&
Caption = "添加图书类别"
ClientHeight = 1545
ClientLeft = 60
ClientTop = 450
ClientWidth = 3045
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 1545
ScaleWidth = 3045
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command2
Caption = "取消"
Height = 375
Left = 1680
TabIndex = 5
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 120
TabIndex = 4
Top = 1080
Width = 1215
End
Begin VB.TextBox Text2
BackColor = &H00E0E0E0&
Height = 375
Left = 1080
TabIndex = 3
Top = 600
Width = 1815
End
Begin VB.TextBox Text1
BackColor = &H00E0E0E0&
Height = 375
Left = 1080
TabIndex = 2
Top = 120
Width = 1815
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "类别编号:"
Height = 375
Left = 120
TabIndex = 1
Top = 600
Width = 975
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "图书类别:"
Height = 255
Left = 120
TabIndex = 0
Top = 120
Width = 1215
End
End
Attribute VB_Name = "添加图书类别"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim sql As String
Dim conn As New ADODB.Connection
Dim rs_bookstyle As New ADODB.Recordset
'判断图书类别是否为空
If Trim(Text1.Text) = "" Then
MsgBox "图书类别不能为空 ", vbOK0nly + vbExclamation, ""
Text1.SetFocus
Exit Sub
End If
'判断类别编号是否为空
If Trim(Text2.Text) = "" Then
MsgBox "类别编号不能为空", vbOK0nly + vbExclamation, ""
Text2.SetFocus
Exit Sub
End If
Provider = "Microsoft.Jet.OLEDB.3.5.1 ;Persist Security Info=false;data source=D:\图书管理系统\database.mdb"
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\database.mdb"
Dim a As Boolean, b As Boolean
'判定是否有相同类别
sql = "select * from 图书类别 where 类别名称='" & Text1.Text & "'"
rs_bookstyle.Open sql, conn, adOpenKeyset, adLockPessimistic
a = rs_bookstyle.EOF
rs_bookstyle.Close
'判定是否有相同编号
sql = "select * from 图书类别 where 类别编号='" & Text2.Text & "'"
rs_bookstyle.Open sql, conn, adOpenKeyset, adLockPessimistic
b = rs_bookstyle.EOF
If a And b Then '如果没有相同类别和编号
rs_bookstyle.AddNew
rs_bookstyle.Fields(0) = Trim(Text1.Text)
rs_bookstyle.Fields(1) = Trim(Text2.Text)
rs_bookstyle.Update
MsgBox "添加图书类别成功!", vbOKOnly, ""
rs_bookstyle.Close
Unload Me
'刷新图书类别
Unload 图书类别管理
图书类别管理.Show
Else
If a = 0 And b = 0 Then
MsgBox "图书类别和编号重复!", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
Text2.SetFocus
Text2.Text = ""
rs_bookstyle.Close
ElseIf a = 0 And b <> 0 Then
MsgBox "图书类别重复!", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
ElseIf a <> 0 And b = 0 Then
MsgBox "图书编号重复!", vbOKOnly + vbExclamation, ""
Text2.SetFocus
Text2.Text = ""
End If
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -