⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_addnewbookcode.vb

📁 基于VBNET编写的图书馆管理系统
💻 VB
字号:
Imports System.Data.OleDb
Imports System.DateTime
Imports System.Math
Public Class frm_AddNewBookCode
    Inherits System.Windows.Forms.Form
    Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Library.mdb")
    Dim MyCommand
    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 TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 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_AddNewBookCode))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TextBox2)
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        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(355, 94)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "书籍索引号信息"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(144, 60)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(192, 21)
        Me.TextBox2.TabIndex = 4
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(144, 26)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(192, 21)
        Me.TextBox1.TabIndex = 3
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(63, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 25)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "描述"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(29, 26)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 25)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "书籍索引号"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(19, 113)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(115, 35)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "添加"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(134, 113)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(106, 35)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "重置"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(240, 113)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(106, 35)
        Me.Button3.TabIndex = 3
        Me.Button3.Text = "退出"
        '
        'frm_AddNewBookCode
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(380, 160)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        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_AddNewBookCode"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "添加书籍索引号"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub

    Private Sub frm_AddNewBookCode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Focus()
    End Sub
    Function clearfields()
        TextBox1.Text = ""
        TextBox2.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 TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checkTextbox(TextBox1) = False Then
                    displayMsg("Please Enter a New Book Code")
                Else
                    If checkIfAlreadyExists() = True Then
                        displayMsg("The BookCode Alredy Exists in the database ,Please enter another BookCode")
                    Else
                        If checkTextbox(TextBox1) = True Then
                            TextBox2.Focus()
                        End If
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub
    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checkTextbox(TextBox2) = False Then
                    displayMsg("Please Enter a Decription for the new book code")
                Else
                    If checkTextbox(TextBox2) = True Then
                        Button1.Focus()
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub
    Function addBookCode()
        MyConnection.Open()
        MyCommand = New OleDbCommand("INSERT INTO BookCode VALUES('" & TextBox1.Text & "','" & TextBox2.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 BookCode WHERE Code ='" & TextBox1.Text & "'", MyConnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            temp = MyReader("Code")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.dispose()

        If temp = TextBox1.Text Then
            Return True
        Else
            If temp <> TextBox1.Text Then
                Return False
            End If
        End If

    End Function
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        clearfields()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 


        addBookCode()
        displayMsg("The Book Code Has Been Entered into the Database")
        clearfields()
        TextBox1.Focus()
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -