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

📄 frm_reservebook.vb

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

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

    Dim reserveNo As Integer = 0
    Dim status As String


    Private Sub readerNotxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles readerNotxt.KeyPress
        If e.KeyChar = ChrW(System.Windows.Forms.Keys.Enter) Then

            If checkValidReader() Then

                ISBNtxt.Focus()
            Else

                MsgBox("Invalid reader ID!")
                readerNotxt.Focus()
                readerNotxt.SelectAll()

            End If
        End If

    End Sub
    Function checkValidReader() As Boolean
        Dim readerNo As String = ""

        myConnection.Open()
        myCommand = New OleDbCommand("select * from ReaderDetails where ReaderNo='" & readerNotxt.Text & "'", myConnection)
        myReader = myCommand.ExecuteReader()


        While myReader.Read
            readerNo = myReader("ReaderNo")
        End While



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

        If readerNo = "" Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub isbntxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ISBNtxt.KeyPress

        If e.KeyChar = ChrW(System.Windows.Forms.Keys.Enter) Then

            If checkValidBook() = True Then

                updateDataGridView()

                setBookStatus()

                If status = "OutLib" Then
                    setReserveNo()
                    reservebt.Enabled = True
                ElseIf status = "InLib" And isInReserve() = False Then
                    MsgBox("The book is in library now,you need not to reserve!")
                    reservebt.Enabled = False
                ElseIf status = "Reserved" Or (status = "InLib" And isInReserve()) Then
                    MsgBox("The book is already been Reserved!")
                    reservebt.Enabled = False
                ElseIf status = "lost" Then
                    MsgBox("Unlucky, the book is lost!")
                    reservebt.Enabled = False
                End If

            Else
                MsgBox("Invalid book ISBN!")
                ISBNtxt.Focus()
                ISBNtxt.SelectAll()
            End If
        End If
    End Sub
    Function isInReserve() As Boolean
        Dim isbn As String = ""
        Dim readerNo As String = ""

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

        While myReader.Read
            isbn = myReader("ISBN")

        End While

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

        If isbn = "" Then
            Return False
        Else

            Return True
        End If

        

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


        While myReader.Read
            status = myReader("Status")
        End While

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

    Sub updateDataGridView()
        Dim dataset1 As DataSet
        Dim dataAd As OleDbDataAdapter

        dataset1 = New DataSet("dataset1")
        dataAd = New OleDbDataAdapter()

        myConnection.Open()

        myCommand = New OleDbCommand("select BookName,Status,Author,PublishDate,Edition,Publisher,Price " & _
 "from BookDetails where ISBN='" & ISBNtxt.Text & "'", myConnection)

        ' myConnection.Open()

        dataAd.SelectCommand = myCommand
        dataAd.Fill(dataset1, "BookDetails")

        DataGridView1.DataSource = dataset1

        DataGridView1.DataMember = "BookDetails"

        myConnection.Close()
        myCommand.Dispose()

    End Sub
    Function checkValidBook() As Boolean
        Dim isbn As String = ""

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


        While myReader.Read
            isbn = myReader("ISBN")
        End While

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

        If isbn = "" Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub reservebt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reservebt.Click
        Try
            myConnection.Open()

            myCommand = New OleDbCommand("insert into ReserveBook values(" & reserveNo & ",'" & ISBNtxt.Text & _
            "','" & readerNotxt.Text & "',null,'Ncalled')", myConnection)

            myCommand.ExecuteNonQuery()

            MsgBox("Reserve this book success!")
        Catch ex As Exception
            MsgBox("You have already reserved this book")
        End Try

        myConnection.Close()
        myCommand.Dispose()

        changeBookDetailStatus()
    End Sub
    Sub changeBookDetailStatus()

        myConnection.Open()

        myCommand = New OleDbCommand("Update BookDetails set Status= 'Reserved' where ISBN='" & ISBNtxt.Text & "'", myConnection)

        myCommand.ExecuteNonQuery()

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

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

        While myReader.Read()
            reserveNo = reserveNo + 1
        End While

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

        reserveNo = reserveNo + 1
    End Sub

    Private Sub frm_ReserveBook_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        readerNotxt.Focus()
    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 + -