📄 booktype.vb
字号:
Public Class frmBookType
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 Label1 As System.Windows.Forms.Label
Friend WithEvents grdBookType As System.Windows.Forms.DataGrid
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents btnModify As System.Windows.Forms.Button
Friend WithEvents txtBookType As System.Windows.Forms.TextBox
Friend WithEvents btnDelete As System.Windows.Forms.Button
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents btnSave As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.grdBookType = New System.Windows.Forms.DataGrid
Me.btnAdd = New System.Windows.Forms.Button
Me.btnModify = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.txtBookType = New System.Windows.Forms.TextBox
Me.btnDelete = New System.Windows.Forms.Button
Me.btnClose = New System.Windows.Forms.Button
Me.btnSave = New System.Windows.Forms.Button
CType(Me.grdBookType, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'grdBookType
'
Me.grdBookType.DataMember = ""
Me.grdBookType.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grdBookType.Location = New System.Drawing.Point(8, 8)
Me.grdBookType.Name = "grdBookType"
Me.grdBookType.ReadOnly = True
Me.grdBookType.Size = New System.Drawing.Size(136, 232)
Me.grdBookType.TabIndex = 0
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(152, 88)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(48, 23)
Me.btnAdd.TabIndex = 1
Me.btnAdd.Text = "添加"
'
'btnModify
'
Me.btnModify.Location = New System.Drawing.Point(216, 88)
Me.btnModify.Name = "btnModify"
Me.btnModify.Size = New System.Drawing.Size(48, 23)
Me.btnModify.TabIndex = 2
Me.btnModify.Text = "修改"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(160, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "图书类别"
'
'txtBookType
'
Me.txtBookType.Location = New System.Drawing.Point(160, 40)
Me.txtBookType.Name = "txtBookType"
Me.txtBookType.Size = New System.Drawing.Size(120, 21)
Me.txtBookType.TabIndex = 4
Me.txtBookType.Text = ""
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(152, 144)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(48, 23)
Me.btnDelete.TabIndex = 2
Me.btnDelete.Text = "删除"
'
'btnClose
'
Me.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnClose.Location = New System.Drawing.Point(152, 200)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(48, 23)
Me.btnClose.TabIndex = 2
Me.btnClose.Text = "关闭"
'
'btnSave
'
Me.btnSave.Location = New System.Drawing.Point(224, 144)
Me.btnSave.Name = "btnSave"
Me.btnSave.Size = New System.Drawing.Size(48, 23)
Me.btnSave.TabIndex = 2
Me.btnSave.Text = "保存"
'
'frmBookType
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btnClose
Me.ClientSize = New System.Drawing.Size(288, 263)
Me.Controls.Add(Me.txtBookType)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnModify)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.grdBookType)
Me.Controls.Add(Me.btnDelete)
Me.Controls.Add(Me.btnClose)
Me.Controls.Add(Me.btnSave)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.Name = "frmBookType"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "设置图书类别"
CType(Me.grdBookType, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private typeds As New DataSet
Private Sub frmBookType_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
OleConn.SelectQuery("select * from 图书类别", typeds)
If typeds.Tables.Count > 0 Then
grdBookType.SetDataBinding(typeds, "Table")
grdBookType.CurrentRowIndex = 0
txtBookType.Text = grdBookType.Item(0, 0)
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End Sub
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If txtBookType.Text = "" Then
MsgBox("请输入图书类别")
txtBookType.Focus()
Else
Try
Dim dr As DataRow = typeds.Tables(0).NewRow()
dr(0) = txtBookType.Text
typeds.Tables(0).Rows.Add(dr)
If grdBookType.CurrentRowIndex > 0 Then
txtBookType.Text = grdBookType.Item(grdBookType.CurrentRowIndex, 0)
Else
grdBookType.CurrentRowIndex = 0
txtBookType.Text = grdBookType.Item(0, 0)
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End Sub
Private Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
If txtBookType.Text = "" Then
MsgBox("请输入图书类别")
txtBookType.Focus()
ElseIf grdBookType.CurrentRowIndex < 0 Then
MsgBox("请先选择要修改的图书类别")
grdBookType.Focus()
Else
Try
Dim str As String = "类别='" & grdBookType.Item(grdBookType.CurrentRowIndex, 0) & "'"
Dim dr As DataRow() = typeds.Tables(0).Select(str)
dr(0).BeginEdit()
dr(0).Item(0) = txtBookType.Text
dr(0).EndEdit()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
MsgBox("修改成功")
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If grdBookType.CurrentRowIndex < 0 Then
MsgBox("请先选择要删除的图书类别")
grdBookType.Focus()
Else
Try
Dim str As String = "类别='" & grdBookType.Item(grdBookType.CurrentRowIndex, 0) & "'"
Dim dr As DataRow() = typeds.Tables(0).Select(str)
dr(0).Delete()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
MsgBox("删除成功")
End If
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
OleConn.UpDate(typeds.Tables(0))
typeds.AcceptChanges()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
MsgBox("保存成功")
End Sub
Private Sub grdBookType_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdBookType.MouseDown
Dim hti As DataGrid.HitTestInfo
hti = grdBookType.HitTest(e.X, e.Y)
If hti.Type = DataGrid.HitTestType.Cell Or hti.Type = DataGrid.HitTestType.RowHeader Then
txtBookType.Text = grdBookType.Item(hti.Row, 0)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -