📄 form2.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form findform
AutoRedraw = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "查找图书"
ClientHeight = 4080
ClientLeft = 45
ClientTop = 330
ClientWidth = 6795
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
Picture = "Form2.frx":0000
ScaleHeight = 4080
ScaleWidth = 6795
Begin VB.TextBox Text2
Appearance = 0 'Flat
BackColor = &H00E0E0E0&
Height = 270
Left = 2160
TabIndex = 5
Top = 3240
Width = 1695
End
Begin VB.TextBox Text1
Appearance = 0 'Flat
BackColor = &H00E0E0E0&
Height = 270
Left = 2160
TabIndex = 4
Top = 2865
Width = 1695
End
Begin VB.ComboBox Combo1
Appearance = 0 'Flat
BackColor = &H00E0E0E0&
Height = 300
Left = 2160
Style = 2 'Dropdown List
TabIndex = 3
Top = 2400
Width = 1455
End
Begin MSComctlLib.ListView ListView1
Height = 1455
Left = 480
TabIndex = 2
Top = 360
Width = 5655
_ExtentX = 9975
_ExtentY = 2566
Sorted = -1 'True
MultiSelect = -1 'True
LabelWrap = -1 'True
HideSelection = -1 'True
AllowReorder = -1 'True
FullRowSelect = -1 'True
HotTracking = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = 14737632
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CommandButton Command1
Caption = "开始查找"
Height = 375
Left = 4560
Picture = "Form2.frx":9C09
Style = 1 'Graphical
TabIndex = 1
Top = 2400
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "清 空"
Height = 375
Left = 4560
Picture = "Form2.frx":C469
Style = 1 'Graphical
TabIndex = 0
Top = 3120
Width = 1095
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "书 名"
Height = 180
Left = 960
TabIndex = 8
Top = 3360
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "图书编号"
Height = 180
Left = 960
TabIndex = 7
Top = 2880
Width = 720
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "请选择类别"
Height = 180
Left = 960
TabIndex = 6
Top = 2400
Width = 900
End
End
Attribute VB_Name = "findform"
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 booktitle As String
Dim bookno As String
ListView1.ListItems.Clear
bookno = Replace(Trim(Text1.Text), "'", "''")
booktitle = Replace(Trim(Text2.Text), "'", "''")
bookclass = Replace(Trim(Combo1.Text), "'", "''")
If (Not bookno = "") Or (Not booktitle = "") Then
If Combo1.Text = "" Then
sql = "select * from book where (bookno='" & bookno & "'" & "or booktitle like '" & booktitle & "')"
'sql = "select * from book where bookno='" & bookno & "'" & "or charindex('" & booktitle & "',booktitle)>0 "
Else
sql = "select * from book where (bookno='" & bookno & "'" & "or booktitle like'" & booktitle & "')" & "and sort='" & bookclass & "'"
End If
opendb sql, ""
If rs.EOF Then
MsgBox "对不起,您所查找的书没有!", 64, "提示"
Else
For j = 1 To rs.RecordCount
ListView1.ListItems.Add , , rs.Fields("bookno") & vbNullString
With ListView1.ListItems(j)
.SubItems(1) = rs.Fields("booktitle") & vbNullString
.SubItems(2) = rs.Fields("price") & vbNullString
.SubItems(3) = rs.Fields("sort") & Empty
.SubItems(4) = rs.Fields("press") & vbNullString
.SubItems(5) = rs.Fields("stock")
End With
rs.MoveNext
Next
End If
closedb
Else
If bookclass = "" Then
sql = "select * from book"
Else
sql = "select * from book where " & "sort='" & bookclass & "'"
End If
opendb sql, ""
If rs.EOF Then
MsgBox "对不起,您所查找的书没有!", 64, "提示"
Else
For j = 1 To rs.RecordCount
ListView1.ListItems.Add , , rs.Fields("bookno") & vbNullString
With ListView1.ListItems(j)
.SubItems(1) = rs.Fields("booktitle") & vbNullString
.SubItems(2) = rs.Fields("price") & vbNullString
.SubItems(3) = rs.Fields("sort") & Empty
.SubItems(4) = rs.Fields("press") & vbNullString
.SubItems(5) = rs.Fields("stock") & ""
End With
rs.MoveNext
Next
End If
closedb
'MsgBox "对不起,您所查找的书没有!", , "提示"
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
ListView1.ListItems.Clear
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
ListView1.GridLines = True
ListView1.View = lvwReport
Combo1.AddItem "计算机"
Combo1.AddItem "英语"
Combo1.AddItem "体育"
Combo1.AddItem "机电"
Combo1.AddItem "电气工程"
ListView1.ColumnHeaders.Add , , "图书编号"
ListView1.ColumnHeaders.Add , , "书名"
ListView1.ColumnHeaders.Add , , "价格"
ListView1.ColumnHeaders.Add , , "类别"
ListView1.ColumnHeaders.Add , , "出版社"
ListView1.ColumnHeaders.Add , , "库存"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1_Click
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1_Click
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -