📄 frm_findbook.vb
字号:
Imports System.Data.OleDb
Public Class frm_FindBook
Inherits System.Windows.Forms.Form
Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Library.mdb")
Dim MyCommand As OleDbCommand
Dim MyReader As OleDbDataReader
Dim dbset As New DataSet
Dim dataA As OleDbDataAdapter
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TxtCondition As System.Windows.Forms.TextBox
Friend WithEvents ChkBookName As System.Windows.Forms.CheckBox
Friend WithEvents ChkISDN As System.Windows.Forms.CheckBox
Friend WithEvents ChckAuthor As System.Windows.Forms.CheckBox
Friend WithEvents DGResult As System.Windows.Forms.DataGrid
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents BtnSearch As System.Windows.Forms.Button
Friend WithEvents BtnClear As System.Windows.Forms.Button
Friend WithEvents BtnExit As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_FindBook))
Me.TxtCondition = New System.Windows.Forms.TextBox
Me.ChkBookName = New System.Windows.Forms.CheckBox
Me.ChkISDN = New System.Windows.Forms.CheckBox
Me.ChckAuthor = New System.Windows.Forms.CheckBox
Me.DGResult = New System.Windows.Forms.DataGrid
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.BtnSearch = New System.Windows.Forms.Button
Me.BtnClear = New System.Windows.Forms.Button
Me.BtnExit = New System.Windows.Forms.Button
CType(Me.DGResult, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TxtCondition
'
Me.TxtCondition.Location = New System.Drawing.Point(38, 57)
Me.TxtCondition.Name = "TxtCondition"
Me.TxtCondition.Size = New System.Drawing.Size(451, 21)
Me.TxtCondition.TabIndex = 0
'
'ChkBookName
'
Me.ChkBookName.Location = New System.Drawing.Point(38, 23)
Me.ChkBookName.Name = "ChkBookName"
Me.ChkBookName.Size = New System.Drawing.Size(125, 26)
Me.ChkBookName.TabIndex = 1
Me.ChkBookName.Text = "通过书籍名称"
'
'ChkISDN
'
Me.ChkISDN.Location = New System.Drawing.Point(211, 23)
Me.ChkISDN.Name = "ChkISDN"
Me.ChkISDN.Size = New System.Drawing.Size(124, 26)
Me.ChkISDN.TabIndex = 2
Me.ChkISDN.Text = "通过ISDN号码"
'
'ChckAuthor
'
Me.ChckAuthor.Location = New System.Drawing.Point(383, 23)
Me.ChckAuthor.Name = "ChckAuthor"
Me.ChckAuthor.Size = New System.Drawing.Size(125, 26)
Me.ChckAuthor.TabIndex = 3
Me.ChckAuthor.Text = "通过作者"
'
'DGResult
'
Me.DGResult.DataMember = ""
Me.DGResult.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DGResult.Location = New System.Drawing.Point(12, 109)
Me.DGResult.Name = "DGResult"
Me.DGResult.Size = New System.Drawing.Size(547, 164)
Me.DGResult.TabIndex = 4
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.TxtCondition)
Me.GroupBox1.Controls.Add(Me.ChkISDN)
Me.GroupBox1.Controls.Add(Me.ChckAuthor)
Me.GroupBox1.Controls.Add(Me.ChkBookName)
Me.GroupBox1.Location = New System.Drawing.Point(10, 9)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(549, 94)
Me.GroupBox1.TabIndex = 5
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "查找规则"
'
'BtnSearch
'
Me.BtnSearch.Location = New System.Drawing.Point(32, 298)
Me.BtnSearch.Name = "BtnSearch"
Me.BtnSearch.Size = New System.Drawing.Size(153, 25)
Me.BtnSearch.TabIndex = 4
Me.BtnSearch.Text = "查找"
'
'BtnClear
'
Me.BtnClear.Location = New System.Drawing.Point(195, 298)
Me.BtnClear.Name = "BtnClear"
Me.BtnClear.Size = New System.Drawing.Size(173, 25)
Me.BtnClear.TabIndex = 6
Me.BtnClear.Text = "重置"
'
'BtnExit
'
Me.BtnExit.Location = New System.Drawing.Point(377, 298)
Me.BtnExit.Name = "BtnExit"
Me.BtnExit.Size = New System.Drawing.Size(163, 25)
Me.BtnExit.TabIndex = 7
Me.BtnExit.Text = "退出"
'
'frm_FindBook
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(578, 335)
Me.Controls.Add(Me.BtnExit)
Me.Controls.Add(Me.BtnClear)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.DGResult)
Me.Controls.Add(Me.BtnSearch)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frm_FindBook"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "查找书籍信息"
CType(Me.DGResult, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frm_FindBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DGResult.BorderStyle = BorderStyle.FixedSingle
DGResult.GridLineStyle = DataGridLineStyle.Solid
TxtCondition.Focus()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Sub findByName()
dbset.Clear()
MyConnection.Open()
MyCommand = New OleDbCommand("Select * from BookDetails WHERE BookName LIKE '" & TxtCondition.Text & "%'", MyConnection)
dataA = New OleDbDataAdapter(MyCommand)
dataA.fill(dbset, "BookDetails")
DGResult.ReadOnly = True
DGResult.DataSource = dbset.Tables("BookDetails")
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Sub findByAuthorName()
dbset.Clear()
MyConnection.Open()
MyCommand = New OleDbCommand("Select * from BookDetails WHERE AuthorName LIKE '" & TxtCondition.Text & "%'", MyConnection)
dataA = New OleDbDataAdapter(MyCommand)
dataA.fill(dbset, "BookDetails")
DGResult.ReadOnly = True
DGResult.DataSource = dbset.Tables("BookDetails")
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
End While
MyConnection.Close()
MyReader.Close()
MyCommand.dispose()
End Sub
Sub findByISDN()
dbset.Clear()
MyConnection.Open()
MyCommand = New OleDbCommand("Select * from BookDetails WHERE ISDN = '" & TxtCondition.Text & "'", MyConnection)
dataA = New OleDbDataAdapter(MyCommand)
dataA.fill(dbset, "BookDetails")
DGResult.ReadOnly = True
DGResult.DataSource = dbset.Tables("BookDetails")
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
End While
MyConnection.Close()
MyReader.Close()
MyCommand.dispose()
End Sub
Sub clearFields()
TxtCondition.Text = ""
ChkBookName.Focus()
dbset.Clear()
DGResult.Update()
End Sub
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
If ChkBookName.Checked = True Then
findByName()
Else
If ChckAuthor.Checked = True Then
findByAuthorName()
Else
If ChkISDN.Checked = True Then
findByISDN()
Else
End If
End If
End If
End Sub
Private Sub TxtCondition_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtCondition.KeyPress
Dim strChar As Object
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtCondition) = False Then
MsgBox("请输入搜索条件", MsgBoxStyle.Information, "图书管管理系统")
Else
If checkTextbox(TxtCondition) = True Then
BtnSearch.Focus()
End If
End If
Case Else
'什么也不做
End Select
End Sub
Function checkTextbox(ByVal t As TextBox) As Boolean
If t.Text = "" Then
Return False
Else
If t.Text <> "" Then
Return True
End If
End If
End Function
Private Sub ChkBookName_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkBookName.CheckedChanged
ChkISDN.Checked = False
ChckAuthor.Checked = False
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkISDN.CheckedChanged
ChkBookName.Checked = False
ChckAuthor.Checked = False
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChckAuthor.CheckedChanged
ChkISDN.Checked = False
ChkBookName.Checked = False
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -