📄 addbook.frm
字号:
VERSION 5.00
Begin VB.Form AddBook
BorderStyle = 1 'Fixed Single
Caption = "添加新书"
ClientHeight = 3300
ClientLeft = 3390
ClientTop = 3825
ClientWidth = 7725
FillStyle = 2 'Horizontal Line
Icon = "AddBook.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3300
ScaleWidth = 7725
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Caption = "书籍信息"
Height = 3135
Left = 0
TabIndex = 0
Top = 120
Width = 7695
Begin VB.CommandButton Command1
Caption = "删除本条纪录"
Height = 375
Left = 2640
TabIndex = 23
Top = 2520
Width = 1335
End
Begin VB.ComboBox ComSort
BackColor = &H00C0FFFF&
Height = 300
Left = 1200
TabIndex = 22
Text = "选择类别"
Top = 1200
Width = 1215
End
Begin VB.TextBox Text1
DataField = "入库时间"
Height = 270
Index = 6
Left = 5760
TabIndex = 21
Text = "选择时间"
Top = 1920
Width = 1335
End
Begin VB.TextBox Text1
DataField = "出版时间"
Height = 270
Index = 5
Left = 3480
TabIndex = 20
Text = "选择时间"
Top = 1920
Width = 1215
End
Begin VB.CommandButton CmdNext
Caption = "后一条"
Height = 375
Left = 1440
TabIndex = 19
Top = 2520
Width = 855
End
Begin VB.CommandButton CmdPrev
Caption = "前一条"
Height = 375
Left = 360
TabIndex = 18
Top = 2520
Width = 855
End
Begin VB.CommandButton CmdExit
Caption = "退 出"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 6120
TabIndex = 17
Top = 2520
Width = 1095
End
Begin VB.CommandButton CmdAddNew
Caption = "新加纪录"
Height = 375
Left = 4680
TabIndex = 16
Top = 2520
Width = 1095
End
Begin VB.CommandButton CmdCancel
Caption = "取 消"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 6120
TabIndex = 15
Top = 2520
Width = 1095
End
Begin VB.CommandButton CmdSave
Caption = "保 存"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4680
TabIndex = 14
Top = 2520
Width = 1095
End
Begin VB.TextBox Text1
DataField = "图书价格"
Height = 270
Index = 4
Left = 1200
TabIndex = 11
Top = 1875
Width = 1215
End
Begin VB.TextBox Text1
DataField = "出版社"
Height = 270
Index = 3
Left = 3480
TabIndex = 7
Top = 1155
Width = 3615
End
Begin VB.TextBox Text1
DataField = "图书作者"
Height = 270
Index = 2
Left = 5880
TabIndex = 6
Top = 435
Width = 1215
End
Begin VB.TextBox Text1
DataField = "图书名称"
Height = 270
Index = 1
Left = 3480
TabIndex = 5
Top = 435
Width = 1215
End
Begin VB.TextBox Text1
DataField = "图书编号"
Height = 270
Index = 0
Left = 1200
TabIndex = 3
Top = 435
Width = 1215
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "入库时间"
DataField = "入库时间"
Height = 180
Index = 7
Left = 4920
TabIndex = 13
Top = 1920
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "出版时间"
Height = 180
Index = 6
Left = 2640
TabIndex = 12
Top = 1920
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "图书价格"
Height = 180
Index = 5
Left = 360
TabIndex = 10
Top = 1920
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "出版社"
Height = 180
Index = 4
Left = 2640
TabIndex = 9
Top = 1200
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "图书作者"
Height = 180
Index = 3
Left = 4920
TabIndex = 8
Top = 480
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "图书名称"
Height = 180
Index = 2
Left = 2640
TabIndex = 4
Top = 480
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "图书类别"
Height = 180
Index = 1
Left = 360
TabIndex = 2
Top = 1200
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "图书编号"
Height = 180
Index = 0
Left = 360
TabIndex = 1
Top = 480
Width = 720
End
End
End
Attribute VB_Name = "AddBook"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim WithEvents adoPrimaryRS As Recordset
Attribute adoPrimaryRS.VB_VarHelpID = -1
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Private Sub CmdExit_Click()
Unload Me
End Sub
Private Sub cmdNext_Click()
On Error GoTo GoNextError
If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'已到最后返回
adoPrimaryRS.MoveLast
End If
'显示当前记录
mbDataChanged = False
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Private Sub Cmdprev_Click()
On Error GoTo GoPrevError
If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious
If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'已到最后返回
adoPrimaryRS.MoveFirst
End If
'显示当前记录
mbDataChanged = False
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
Private Sub CmdSave_Click()
On Error GoTo UpdateErr
adoPrimaryRS.Fields(3) = ComSort.Text
Save_Data
SetButtons False
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
adoPrimaryRS.CancelUpdate
Con_Data
If mvBookMark > 0 Then
adoPrimaryRS.Bookmark = mvBookMark
adoPrimaryRS.MovePrevious
Else
adoPrimaryRS.MoveFirst
End If
SetButtons False
End Sub
Private Sub CmdAddNew_Click()
On Error GoTo AddErr
adoPrimaryRS.AddNew
Text1(5) = "双击选择时间"
Text1(6) = Date
SetTxt_BackColor 0
SetButtons True
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Private Sub Command1_Click()
On Error GoTo UpdateErr
adoPrimaryRS.Delete
Con_Data
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub Form_Load()
Ini_Form
Con_Data
SetButtons False
End Sub
Private Sub Ini_Form()
On Error GoTo IniRee
Dim i As Integer
Dim sSql As String
sSql = "select 类别代码,类别名称,借阅天数 from sort Order by 类别代码"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open sSql, tsdata.db, adOpenStatic, adLockOptimistic
For i = 0 To adoPrimaryRS.RecordCount - 1
ComSort.AddItem adoPrimaryRS.Fields(1)
adoPrimaryRS.MoveNext
Next i
Set adoPrimaryRS = Nothing
Exit Sub
IniRee:
MsgBox Err.Description
End Sub
Private Sub Con_Data()
Dim sSql As String
On Error GoTo ConErr
sSql = "select 图书编号,图书名称,图书作者,图书类别,出版社,图书价格,出版时间,入库时间 from books Order by 图书编号"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open sSql, tsdata.db, adOpenStatic, adLockOptimistic
Dim oText As TextBox
'绑定文本框到数据提供者
For Each oText In Me.Text1
Set oText.DataSource = adoPrimaryRS
Next
mbDataChanged = False
Exit Sub
ConErr:
MsgBox Err.Description
End Sub
Private Sub Save_Data()
Dim sSql As String
On Error GoTo SaveErr
sSql = "select 图书编号,图书名称,图书作者,图书类别,出版社,图书价格,出版时间,入库时间 from books Order by 图书编号"
Dim ado As New ADODB.Recordset
ado.Open sSql, tsdata.db, adOpenStatic, adLockOptimistic
ado.Update
SaveErr:
MsgBox Err.Description
End Sub
Private Sub Text1_Click(Index As Integer)
SetTxt_BackColor Index
End Sub
Private Sub Text1_DblClick(Index As Integer)
If Index = 5 Then
CaleFrm.Show
CaleFrm.Text1 = 1
AddBook.Enabled = False
End If
If Index = 6 Then
CaleFrm.Show
CaleFrm.Text1 = 2
AddBook.Enabled = False
End If
End Sub
Private Sub SetTxt_BackColor(Index As Integer)
Dim i As Integer
For i = 0 To 6
Text1(i).BackColor = &H80000005
Next i
Text1(Index).BackColor = &H80FF80
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
If Index < 0 Or Index > 4 Then Exit Sub
Index = Index + 1
SetTxt_BackColor Index
Text1(Index).SetFocus
End If
End Sub
Private Sub SetButtons(bVal As Boolean)
'byval 为True 时表示新纪录,否则表示正常状态
CmdSave.Visible = bVal '保存
CmdCancel.Visible = bVal '取 消
CmdAddNew.Visible = Not bVal '新加纪录
CmdExit.Visible = Not bVal '退 出
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -