📄 frm_delreader.vb
字号:
Imports System.Data.OleDb
Public Class frm_DelReader
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
Friend WithEvents BtnSearch As System.Windows.Forms.Button
Friend WithEvents DGResult As System.Windows.Forms.DataGridView
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 GroupBox1 As System.Windows.Forms.GroupBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_DelReader))
Me.TxtCondition = New System.Windows.Forms.TextBox
Me.ChkBookName = New System.Windows.Forms.CheckBox
Me.ChkISDN = New System.Windows.Forms.CheckBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.BtnSearch = New System.Windows.Forms.Button
Me.DGResult = New System.Windows.Forms.DataGridView
Me.GroupBox1.SuspendLayout()
CType(Me.DGResult, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'TxtCondition
'
Me.TxtCondition.Location = New System.Drawing.Point(38, 57)
Me.TxtCondition.Name = "TxtCondition"
Me.TxtCondition.Size = New System.Drawing.Size(297, 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 = "通过读者编号"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.TxtCondition)
Me.GroupBox1.Controls.Add(Me.ChkISDN)
Me.GroupBox1.Controls.Add(Me.ChkBookName)
Me.GroupBox1.Controls.Add(Me.BtnSearch)
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(367, 55)
Me.BtnSearch.Name = "BtnSearch"
Me.BtnSearch.Size = New System.Drawing.Size(152, 23)
Me.BtnSearch.TabIndex = 4
Me.BtnSearch.Text = "查找"
'
'DGResult
'
Me.DGResult.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.DGResult.Location = New System.Drawing.Point(12, 124)
Me.DGResult.Name = "DGResult"
Me.DGResult.RowTemplate.Height = 23
Me.DGResult.Size = New System.Drawing.Size(547, 150)
Me.DGResult.TabIndex = 6
'
'frm_DelReader
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(578, 288)
Me.Controls.Add(Me.DGResult)
Me.Controls.Add(Me.GroupBox1)
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_DelReader"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "删除读者信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
CType(Me.DGResult, System.ComponentModel.ISupportInitialize).EndInit()
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
TxtCondition.Focus()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Sub findByName()
dbset.Clear()
MyConnection.Open()
MyCommand = New OleDbCommand("Select * from ReaderDetails WHERE ReaderName LIKE '" & TxtCondition.Text & "%'", MyConnection)
dataA = New OleDbDataAdapter(MyCommand)
dataA.Fill(dbset, "ReaderDetails")
DGResult.ReadOnly = True
DGResult.DataSource = dbset.Tables("ReaderDetails")
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Sub findByNo()
dbset.Clear()
MyConnection.Open()
MyCommand = New OleDbCommand("Select * from ReaderDetails WHERE ReaderNo= '" & TxtCondition.Text & "'", MyConnection)
dataA = New OleDbDataAdapter(MyCommand)
dataA.Fill(dbset, "ReaderDetails")
DGResult.ReadOnly = True
DGResult.DataSource = dbset.Tables("ReaderDetails")
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
findByNo()
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
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkISDN.CheckedChanged
ChkBookName.Checked = False
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
ChkISDN.Checked = False
ChkBookName.Checked = False
End Sub
Private Sub DGResult_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGResult.CellContentDoubleClick
If DGResult.SelectedCells.Count <> -1 Then
Dim DR As DialogResult
DR = MsgBox("请确认是否删除 " & DGResult.Rows(e.RowIndex).Cells(1).Value & " 这条记录", MsgBoxStyle.YesNo, "信息框")
If DR = Windows.Forms.DialogResult.Yes Then
MyConnection.Open()
MyCommand = New OleDbCommand("DELETE FROM ReaderDetails WHERE ReaderNo='" & DGResult.Rows(e.RowIndex).Cells(0).Value & "'", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
Else
Exit Sub
End If
BtnSearch_Click(sender, e)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -