📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
BorderStyle = 0 'None
Caption = "图书信息录入"
ClientHeight = 4680
ClientLeft = 3480
ClientTop = 2880
ClientWidth = 8775
LinkTopic = "Form2"
ScaleHeight = 312
ScaleMode = 3 'Pixel
ScaleWidth = 585
ShowInTaskbar = 0 'False
Begin Project1.xp_canvas xp_canvas1
Height = 4695
Left = 0
TabIndex = 0
Top = 0
Width = 8775
_ExtentX = 15478
_ExtentY = 8281
Caption = "图书信息录入"
Icon = "Form2.frx":0000
Begin Project1.xptopbuttons xptopbuttons2
Height = 315
Left = 8040
Top = 120
Width = 315
_ExtentX = 556
_ExtentY = 556
Value = 2
End
Begin Project1.xptopbuttons xptopbuttons1
Height = 315
Left = 8400
Top = 120
Width = 315
_ExtentX = 556
_ExtentY = 556
End
Begin VB.Frame Frame1
Height = 3015
Left = 360
TabIndex = 7
Top = 600
Width = 8055
Begin VB.TextBox Text5
Height = 375
Left = 1320
TabIndex = 16
Top = 2040
Width = 2055
End
Begin VB.TextBox Text4
Height = 375
Left = 4920
TabIndex = 13
Top = 1200
Width = 2055
End
Begin VB.TextBox Text3
Height = 375
Left = 1320
TabIndex = 12
Top = 1200
Width = 2055
End
Begin VB.TextBox Text2
Height = 375
Left = 4920
TabIndex = 11
Top = 480
Width = 2055
End
Begin VB.TextBox Text1
Height = 375
Left = 1320
TabIndex = 10
Top = 480
Width = 2055
End
Begin VB.Label Label5
Caption = "购买时间"
Height = 255
Left = 240
TabIndex = 17
Top = 2100
Width = 975
End
Begin VB.Label Label3
Caption = "作 者"
Height = 255
Left = 240
TabIndex = 15
Top = 1260
Width = 975
End
Begin VB.Label Label1
Caption = "图书编号"
Height = 255
Left = 240
TabIndex = 14
Top = 540
Width = 975
End
Begin VB.Label Label4
Caption = "出 版 社"
Height = 255
Left = 3720
TabIndex = 9
Top = 1260
Width = 975
End
Begin VB.Label Label2
Caption = "图书名称"
Height = 255
Left = 3720
TabIndex = 8
Top = 540
Width = 975
End
End
Begin Project1.xpcmdbutton Command5
Height = 375
Left = 7080
TabIndex = 6
Top = 3840
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 Project1.xpcmdbutton Command4
Height = 375
Left = 5760
TabIndex = 5
Top = 3840
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 Project1.xpcmdbutton Command3
Height = 375
Left = 4440
TabIndex = 4
Top = 3840
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 Project1.xpcmdbutton cmdmodify
Height = 375
Left = 3120
TabIndex = 3
Top = 3840
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 Project1.xpcmdbutton Command2
Height = 375
Left = 1800
TabIndex = 2
Top = 3840
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 Project1.xpcmdbutton Command1
Height = 375
Left = 480
TabIndex = 1
Top = 3840
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
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'*******************************************
' “ 图书信息管理窗体“
' 此窗体主要功能:图书信息录入、删除、修改、逐条浏览
' 图书编号为主键,添加时一定要检测数据库中是否已经存在
'
'作者: 朱宏梅
'制作日期: 2004-5-30
'********************************************
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 + -