📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H00C0FFFF&
BorderStyle = 0 'None
Caption = "图书信息录入"
ClientHeight = 4095
ClientLeft = 3480
ClientTop = 2880
ClientWidth = 5280
Icon = "Form2.frx":0000
LinkTopic = "Form2"
ScaleHeight = 273
ScaleMode = 3 'Pixel
ScaleWidth = 352
ShowInTaskbar = 0 'False
Begin VB.PictureBox Picture1
BorderStyle = 0 'None
Height = 615
Left = 0
Picture = "Form2.frx":0CCA
ScaleHeight = 615
ScaleWidth = 5295
TabIndex = 16
Top = 3600
Width = 5295
End
Begin VB.TextBox Text4
Height = 270
Left = 1080
TabIndex = 15
Top = 3000
Width = 2055
End
Begin VB.TextBox Text2
Height = 270
Left = 1080
TabIndex = 14
Top = 2520
Width = 2055
End
Begin VB.TextBox Text5
Height = 270
Left = 1080
TabIndex = 13
Top = 2040
Width = 2055
End
Begin VB.TextBox Text3
Height = 270
Left = 1080
TabIndex = 12
Top = 1560
Width = 2055
End
Begin VB.TextBox Text1
Height = 270
Left = 1080
TabIndex = 11
Top = 1080
Width = 2055
End
Begin 计算机图书管理系统2008.xp_canvas xp_canvas1
Height = 2775
Left = 1080
TabIndex = 0
Top = 720
Width = 4215
_ExtentX = 7435
_ExtentY = 4895
Begin 计算机图书管理系统2008.xpcmdbutton Command4
Height = 375
Left = 2400
TabIndex = 5
Top = 1800
Width = 1215
_ExtentX = 2143
_ExtentY = 661
Caption = "下一记录"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin 计算机图书管理系统2008.xpcmdbutton Command3
Height = 375
Left = 2400
TabIndex = 4
Top = 1320
Width = 1215
_ExtentX = 2143
_ExtentY = 661
Caption = "上一记录"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin 计算机图书管理系统2008.xpcmdbutton cmdmodify
Height = 375
Left = 2400
TabIndex = 3
Top = 2280
Width = 1215
_ExtentX = 2143
_ExtentY = 661
Caption = "修改记录"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin 计算机图书管理系统2008.xpcmdbutton Command2
Height = 375
Left = 2400
TabIndex = 2
Top = 840
Width = 1215
_ExtentX = 2143
_ExtentY = 661
Caption = "删除记录"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin 计算机图书管理系统2008.xpcmdbutton Command1
Height = 375
Left = 2400
TabIndex = 1
Top = 360
Width = 1215
_ExtentX = 2143
_ExtentY = 661
Caption = "添加记录"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
End
Begin 计算机图书管理系统2008.xptopbuttons xptopbuttons2
Height = 315
Left = 4440
Top = 240
Width = 315
_ExtentX = 556
_ExtentY = 556
Value = 2
End
Begin 计算机图书管理系统2008.xptopbuttons xptopbuttons1
Height = 315
Left = 4800
Top = 240
Width = 315
_ExtentX = 556
_ExtentY = 556
End
Begin VB.Label Label4
BackColor = &H00C0FFFF&
Caption = "出 版 社:"
Height = 255
Left = 120
TabIndex = 10
Top = 3120
Width = 975
End
Begin VB.Label Label2
BackColor = &H00C0FFFF&
Caption = "图书名称:"
Height = 255
Left = 120
TabIndex = 9
Top = 2520
Width = 975
End
Begin VB.Label Label5
BackColor = &H00C0FFFF&
Caption = "入库时间:"
Height = 255
Left = 120
TabIndex = 8
Top = 2040
Width = 975
End
Begin VB.Label Label3
BackColor = &H00C0FFFF&
Caption = "作 者:"
Height = 255
Left = 120
TabIndex = 7
Top = 1560
Width = 975
End
Begin VB.Label Label1
BackColor = &H00C0FFFF&
Caption = "图书编号:"
Height = 255
Left = 120
TabIndex = 6
Top = 1080
Width = 975
End
Begin VB.Image Image1
Height = 690
Left = 0
Picture = "Form2.frx":2BAA4
Top = 0
Width = 7305
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdmodify_Click() '修改记录按钮
Dim sqlstr As String
Dim rst1 As New ADODB.Recordset
Dim param As ADODB.Parameter
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Set param = New ADODB.Parameter
sqlstr = "select * from book where [图书编码]= '" & Trim(Text1.Text) & "'"
With param
.Direction = adParamInput
.Type = adBSTR
.Size = 8
.Value = Text1.Text
End With
cmd.Parameters.Append param
cmd.CommandText = sqlstr
cmd.CommandType = adCmdText
Set cmd.ActiveConnection = con
Set rst1 = cmd.Execute
If rst1.RecordCount > 0 Then
frmMsg.Show
frmMsg.notice.Visible = True
frmMsg.Text1.Text = "此书号已经存在!"
rst.Cancel
Exit Sub
End If
rst.Update
frmMsg.Show
frmMsg.info.Visible = True
frmMsg.Text1.Text = "修改成功!"
End Sub
Private Sub Command1_Click()
Dim sql As String
Dim param As ADODB.Parameter
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Set param = New ADODB.Parameter
sql = "select * from book where [图书编码]= ? "
If Command1.Caption = "添加记录" Then
Command1.Caption = "确 定"
Command2.Enabled = False '屏蔽删除、修改、下一记录、上一记录按钮,避免出现数据库错误
Command3.Enabled = False
Command4.Enabled = False
cmdmodify.Enabled = False
rst.AddNew
Else
If Text1.Text = "" Then
frmMsg.Show
frmMsg.notice.Visible = True
frmMsg.Text1.Text = "图书编号不能为空!"
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command1.Caption = "添加记录"
Exit Sub
End If
With param
.Direction = adParamInput
.Type = adBSTR
.Size = 8
.Value = Text1.Text
End With
cmd.Parameters.Append param
cmd.CommandText = sql
cmd.CommandType = adCmdText
Set cmd.ActiveConnection = con
Set rst1 = cmd.Execute
If rst1.RecordCount > 0 Then
frmMsg.Show
frmMsg.notice.Visible = True
frmMsg.Text1.Text = "此书号已经存在!"
rst.Cancel
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
cmdmodify.Enabled = True
Command1.Caption = "添加记录"
Command2.Enabled = True
Exit Sub
End If
rst.Update
Command2.Enabled = True '数据库更新结束后才可以点击其他几个按钮
Command3.Enabled = True
Command4.Enabled = True
cmdmodify.Enabled = True
Command1.Caption = "添加记录"
End If
End Sub
Private Sub Command2_Click() '删除记录
Dim ans As String
ans = Msgbox("确定要删除此记录吗?", vbYesNo, "提示")
If ans = vbYes Then
rst.Delete
rst.Requery
Else
Exit Sub
End If
End Sub
Private Sub Command3_Click() '上一记录
If rst.BOF Then
frmMsg.Show
frmMsg.info.Visible = True
frmMsg.Text1.Text = "已经到达记录顶端!"
Exit Sub
Else
rst.MovePrevious
End If
End Sub
Private Sub Command4_Click() '下一记录
If rst.EOF Then
frmMsg.Show
frmMsg.info.Visible = True
frmMsg.Text1.Text = "已经到达记录底端! "
Exit Sub
Else
rst.MoveNext
End If
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim sql1 As String
Set rst = New ADODB.Recordset
sql1 = "select * from book"
Call connect_db
rst.Open sql1, con, adOpenDynamic, adLockOptimistic
Set Text1.DataSource = rst
Set Text2.DataSource = rst
Set Text3.DataSource = rst
Set Text4.DataSource = rst
Set Text5.DataSource = rst
Text1.DataField = "图书编码"
Text2.DataField = "图书名称"
Text3.DataField = "作者"
Text4.DataField = "出版社"
Text5.DataField = "入库时间"
End Sub
Private Sub xptopbuttons1_Click()
Unload Me
End Sub
Private Sub xptopbuttons2_Click()
Me.WindowState = 1
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -