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

📄 addbookinfo.vb

📁 是关于图书管理系统的用vb.net 和access开发的
💻 VB
字号:
Imports System.Data.OleDb
Public Class AddBookInfo

    Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
    Dim myCommand As OleDbCommand
    Dim myReader As OleDbDataReader

    Private Sub AddBookInfo_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        ISBNtxt.Focus()
        addToBookCodeCombo()
    End Sub

 

    Sub addToBookCodeCombo()

        myConnection.Open()
        myCommand = New OleDbCommand("select * from BookType", myConnection)
        myReader = myCommand.ExecuteReader

        While myReader.Read
            codecombo.Items.Add(myReader("TypeCode"))
            typecombo.Items.Add(myReader("Type"))
        End While


        myConnection.Close()
        myCommand.Dispose()
        myReader.Close()
    End Sub

    Private Sub codecombo_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles codecombo.SelectedValueChanged
        typecombo.SelectedIndex = codecombo.SelectedIndex
    End Sub



    Private Sub addbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbt.Click

        If completeEnterInfo() Then
            AddBookInfo()

        Else
            MsgBox("Information is not enough!")
        End If
    End Sub

    
    Function checkAlreadyExist()
        Dim temp As String = ""

        myConnection.Open()
        myCommand = New OleDbCommand("select * from BookDetails where ISBN ='" & ISBNtxt.Text & "'", myConnection)
        myReader = myCommand.ExecuteReader

        While myReader.Read
            temp = myReader("BookNo")
        End While

        myConnection.Close()
        myCommand.Dispose()
        myReader.Close()

        If temp = "" Then
            Return False
        Else
            Return True

        End If

    End Function


    Function completeEnterInfo()

        If ISBNtxt.Text = "" Or nametxt.Text = "" Or authortxt.Text = "" Or _
        editiontxt.Text = "" Or pubDatetxt.Text = "" Or publishertxt.Text = "" Or _
       pricetxt.Text = "" Or codecombo.Text = "" Then
            Return False
        Else
            Return True
        End If

    End Function
    Sub AddBookInfo()

        If isPriceValid() = False Then
            MsgBox("The Price form is not correct!")
            pricetxt.Focus()
            pricetxt.SelectAll()

            Exit Sub
        End If

        If isDateValid() = False Then
            MsgBox("The Dateform is not correct!")
            pubDatetxt.Focus()
            pubDatetxt.SelectAll()

            Exit Sub
        End If

        Try

            myConnection.Open()
            myCommand = New OleDbCommand("INSERT INTO BookDetails VALUES('" & _
         ISBNtxt.Text & "','" & nametxt.Text & "','" & codecombo.Text & "','" & _
           authortxt.Text & "','" & pubDatetxt.Text & "','" & editiontxt.Text & "','InLib','" & _
    Date.Today.ToShortDateString & "','" & publishertxt.Text & "','" & pricetxt.Text & "')", myConnection)

            myCommand.ExecuteNonQuery()

            MsgBox("Insert success!")

        Catch ex As Exception
            'MsgBox(ex.ToString)
            MsgBox("This book is already in the database!")
        End Try


        myConnection.Close()
        myCommand.Dispose()
        myReader.Close()
    
    End Sub
    Function isPriceValid() As Boolean
        Dim isValid As Boolean
        isValid = IsNumeric(pricetxt.Text)

        Return isValid

    End Function
    Function isDateValid() As Boolean
        Dim isValid As Boolean
        isValid = IsDate(pubDatetxt.Text)

        Return isValid
    End Function

    Private Sub resetbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbt.Click


        ISBNtxt.Text = ""
        nametxt.Text = ""
        codecombo.Text = ""
        typecombo.Text = ""
        authortxt.Text = ""
        editiontxt.Text = ""
        pubDatetxt.Text = ""


        publishertxt.Text = ""

        pricetxt.Text = ""

    End Sub

    Private Sub exitbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbt.Click
        Me.Close()


    End Sub
End Class

⌨️ 快捷键说明

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