📄 frmquerybook.vb
字号:
Imports System.Data
Imports System.Data.SqlClient
Public Class frmQueryBook
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents cbField As System.Windows.Forms.ComboBox
Friend WithEvents cbCon As System.Windows.Forms.ComboBox
Friend WithEvents tbValue As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents dgRst As System.Windows.Forms.DataGrid
Friend WithEvents bnQuery As System.Windows.Forms.Button
Friend WithEvents bnCancel As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmQueryBook))
Me.cbField = New System.Windows.Forms.ComboBox
Me.cbCon = New System.Windows.Forms.ComboBox
Me.tbValue = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.dgRst = New System.Windows.Forms.DataGrid
Me.bnQuery = New System.Windows.Forms.Button
Me.bnCancel = New System.Windows.Forms.Button
CType(Me.dgRst, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'cbField
'
Me.cbField.Items.AddRange(New Object() {"书名", "作者", "剩余数量", "图书类别"})
Me.cbField.Location = New System.Drawing.Point(8, 48)
Me.cbField.Name = "cbField"
Me.cbField.Size = New System.Drawing.Size(121, 20)
Me.cbField.TabIndex = 0
'
'cbCon
'
Me.cbCon.Items.AddRange(New Object() {"等于", "大于", "小于", "大于等于", "小于等于", "不等于", "模糊查"})
Me.cbCon.Location = New System.Drawing.Point(136, 48)
Me.cbCon.Name = "cbCon"
Me.cbCon.Size = New System.Drawing.Size(80, 20)
Me.cbCon.TabIndex = 1
'
'tbValue
'
Me.tbValue.Location = New System.Drawing.Point(224, 48)
Me.tbValue.Name = "tbValue"
Me.tbValue.Size = New System.Drawing.Size(248, 21)
Me.tbValue.TabIndex = 2
Me.tbValue.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 3
Me.Label1.Text = "查询项目"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(144, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "查询条件"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(216, 24)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 16)
Me.Label3.TabIndex = 5
Me.Label3.Text = "查询值"
'
'dgRst
'
Me.dgRst.DataMember = ""
Me.dgRst.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dgRst.Location = New System.Drawing.Point(8, 88)
Me.dgRst.Name = "dgRst"
Me.dgRst.Size = New System.Drawing.Size(464, 200)
Me.dgRst.TabIndex = 6
'
'bnQuery
'
Me.bnQuery.Location = New System.Drawing.Point(288, 16)
Me.bnQuery.Name = "bnQuery"
Me.bnQuery.TabIndex = 7
Me.bnQuery.Text = "查询"
'
'bnCancel
'
Me.bnCancel.Location = New System.Drawing.Point(384, 16)
Me.bnCancel.Name = "bnCancel"
Me.bnCancel.TabIndex = 8
Me.bnCancel.Text = "取消"
'
'frmQueryBook
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(480, 301)
Me.Controls.Add(Me.bnCancel)
Me.Controls.Add(Me.bnQuery)
Me.Controls.Add(Me.dgRst)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.tbValue)
Me.Controls.Add(Me.cbCon)
Me.Controls.Add(Me.cbField)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmQueryBook"
Me.Text = "frmQueryBook"
CType(Me.dgRst, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnQuery.Click
Dim strField As String = cbField.Text.Trim()
Dim strCon As String = cbCon.Text.Trim()
Dim strValue As String = tbValue.Text.Trim()
Select Case strField
Case "书名"
strField = "bookname"
Case "作者"
strField = "author"
Case "出版社"
strField = "publish"
Case "图书类别"
strField = "bookclass"
End Select
Select Case strCon
Case "等于"
strCon = "="
Case "大于"
strCon = ">"
Case "小于"
strCon = "<"
Case "大于等于"
strCon = ">="
Case "小于等于"
strCon = "<="
Case "不等于"
strCon = "<>"
Case "模糊查"
strCon = "like"
End Select
Dim strSource As String = "workstation id=郭洪博;packet size=4096;integrated security=SSPI;initial catalog=books;persist security info=False"
Dim strSelect As String
If strCon = "like" Then
strSelect = "select * from books where " + strField + " " + strCon + " '%" + strValue + "%'"
Else
If Not strCon = "ava" Then
strSelect = "select * from books where " + strField + " " + strCon + " '" + strValue + "'"
End If
End If
Dim conn As SqlConnection = New SqlConnection(strSource)
Dim da As SqlDataAdapter = New SqlDataAdapter(strSelect, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "books")
dgRst.DataSource = ds
dgRst.DataMember = "books"
End Sub
Private Sub bnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnCancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -