📄 frm_addbooktype.vb
字号:
Imports System.Data.OleDb
Public Class frm_AddBookType
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
#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 GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TxtTypeNo As System.Windows.Forms.TextBox
Friend WithEvents TxtDescript As System.Windows.Forms.TextBox
Friend WithEvents BtnAdd As System.Windows.Forms.Button
Friend WithEvents BtnClear As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_AddBookType))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.TxtDescript = New System.Windows.Forms.TextBox
Me.TxtTypeNo = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.BtnAdd = New System.Windows.Forms.Button
Me.BtnClear = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.TxtDescript)
Me.GroupBox1.Controls.Add(Me.TxtTypeNo)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Location = New System.Drawing.Point(10, 9)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(307, 94)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "书籍类型信息"
'
'TxtDescript
'
Me.TxtDescript.Location = New System.Drawing.Point(144, 60)
Me.TxtDescript.Name = "TxtDescript"
Me.TxtDescript.Size = New System.Drawing.Size(144, 21)
Me.TxtDescript.TabIndex = 3
'
'TxtTypeNo
'
Me.TxtTypeNo.Location = New System.Drawing.Point(144, 26)
Me.TxtTypeNo.Name = "TxtTypeNo"
Me.TxtTypeNo.Size = New System.Drawing.Size(144, 21)
Me.TxtTypeNo.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(46, 60)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(95, 25)
Me.Label2.TabIndex = 1
Me.Label2.Text = "描述"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 26)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(120, 25)
Me.Label1.TabIndex = 0
Me.Label1.Text = "类型编号"
'
'BtnAdd
'
Me.BtnAdd.Location = New System.Drawing.Point(29, 112)
Me.BtnAdd.Name = "BtnAdd"
Me.BtnAdd.Size = New System.Drawing.Size(86, 35)
Me.BtnAdd.TabIndex = 1
Me.BtnAdd.Text = "添加"
'
'BtnClear
'
Me.BtnClear.Location = New System.Drawing.Point(115, 112)
Me.BtnClear.Name = "BtnClear"
Me.BtnClear.Size = New System.Drawing.Size(87, 35)
Me.BtnClear.TabIndex = 2
Me.BtnClear.Text = "重置"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(202, 112)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(76, 35)
Me.Button3.TabIndex = 3
Me.Button3.Text = "退出"
'
'frm_AddBookType
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(328, 161)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.BtnClear)
Me.Controls.Add(Me.BtnAdd)
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_AddBookType"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "添加书籍类型"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
#End Region
Function clearfields()
TxtTypeNo.Text = ""
TxtDescript.Text = ""
End Function
Function checkTextbox(ByVal t As TextBox) As Boolean
If t.Text = "" Then
Return (False)
Else
Return True
End If
End Function
Function displayMsg(ByVal myMsgText As String)
MsgBox(myMsgText, MsgBoxStyle.Information, "图书管管理系统")
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Function addBookType()
MyConnection.Open()
MyCommand = New OleDbCommand("INSERT INTO BookType VALUES('" & TxtTypeNo.Text & "','" & TxtDescript.Text & "')", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyCommand.dispose()
End Function
Function checkIfAlreadyExists() As Boolean
Dim temp As String
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookType WHERE Type ='" & TxtTypeNo.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
temp = MyReader("Type")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.dispose()
If temp = TxtTypeNo.Text Then
Return True
Else
If temp <> TxtTypeNo.Text Then
Return False
End If
End If
End Function
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
clearfields()
End Sub
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
If checkTextbox(TxtTypeNo) = False Then
displayMsg("请输入新的书籍类型编号")
Else
If checkIfAlreadyExists() = True Then
displayMsg("书籍类型编号已经存在,请重新输入")
Exit Sub
Else
If checkTextbox(TxtTypeNo) = True Then
TxtDescript.Focus()
End If
End If
End If
If checkTextbox(TxtDescript) = False Then
displayMsg("请输入类型描述信息")
Exit Sub
Else
If checkTextbox(TxtDescript) = True Then
BtnAdd.Focus()
End If
End If
addBookType()
displayMsg("新的书籍类型信息已被添加到数据库中")
clearfields()
TxtTypeNo.Focus()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -