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

📄 frm_returnbook.vb

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

    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 readerNo As String = ""

    Dim isbn As String = ""

    Dim isfine As Boolean = False

    Dim rentdate As DateTime
    Dim duedate As DateTime
    Dim overDateNo As Integer
    Dim finePrice As Decimal

    Dim fineperday As Decimal

    Dim isReserved As Boolean = False




  
  


    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.Clear()
                readerNotxt.Focus()

                returnbt.Enabled = False

            End If
        End If
    
    End Sub

    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


                If alrInRentRec() Then


                    If isInFine() Then

                        MsgBox("The Reader has got a fine,because of late returning!" & _
                       ControlChars.NewLine & ControlChars.NewLine & "Enter the fine per day first please!")

                        returnbt.Enabled = False


                        finePerDaytxt.Enabled = True
                        finePerDaytxt.Focus()


                        isfine = True

                    Else

                        admNotxt.Focus()

                        returnbt.Enabled = True
                    End If


                    If isInReserve() Then
                        isReserved = True
                    End If

                Else
                    MsgBox("Reader hasn't rented this book yet!")
                    returnbt.Enabled = False
                End If


            Else
                MsgBox("Invalid book ISBN!")
                ISBNtxt.Clear()
                ISBNtxt.Focus()
                returnbt.Enabled = False
            End If
            End If
    End Sub
    Function alrInRentRec()

        Dim temp As String = ""
        myConnection.Open()
        myCommand = New OleDbCommand("select * from RentBook where ISBN='" & ISBNtxt.Text & _
        "'and ReaderNo='" & readerNotxt.Text & "'", myConnection)
        myReader = myCommand.ExecuteReader()


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

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

        If temp = "" Then
            Return False
        Else

            Return True
        End If
    End Function
    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
    Function isInFine() As Boolean

        Dim temp As String = ""
        myConnection.Open()

        myCommand = New OleDbCommand("select * from Fine where ISBN='" & _
        isbn & "'and ReaderNo='" & readerNo & "'and status ='UnPaid'", myConnection)

        myReader = myCommand.ExecuteReader()


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

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

      
        If temp <> "" Then

            Return True
        Else

            Return False
        End If

       
    End Function
    Private Sub finePerDaytxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles finePerDaytxt.KeyPress

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

            If finePerDaytxt.Text = "" Then
                MsgBox("Must input fine per day first!")
                returnbt.Enabled = False

            Else
                returnbt.Enabled = True

                fineperday = Decimal.Parse(finePerDaytxt.Text)

                Dim oupstr = ""
                finePrice = getOverDueFine()


                oupstr += "Rent Date:" & rentdate & ControlChars.NewLine _
              & "Due Date:" & duedate & ControlChars.NewLine _
               & "Today is:" & Date.Today.ToShortDateString & ControlChars.NewLine _
                & "Exceed overdue date: " & overDateNo & " days" & ControlChars.NewLine & _
                "Total Fine:" & finePrice & ControlChars.NewLine


                MsgBox(oupstr)

                admNotxt.Focus()

            End If
        End If

    End Sub
   
    
    Function getOverDueFine() As Decimal

        Dim overDatetemp As TimeSpan
        Dim fine As Decimal

        myConnection.Open()
        myCommand = New OleDbCommand("select * from RentBook where ISBN='" & isbn & "' and ReaderNo='" & readerno & "'", myConnection)
        myReader = myCommand.ExecuteReader()


        While myReader.Read
            rentdate = DateTime.Parse(myReader("RentDate"))
            duedate = DateTime.Parse(myReader("DueDate"))
        End While

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

        overDatetemp = DateTime.Now.Subtract(duedate)
        overDateNo = overDatetemp.TotalDays

        If overDateNo > 0 Then

            fine = overDateNo * finePerDay

            If fine > 100 Then
                fine = 100.0
            End If

        Else
            fine = 0.0

        End If

        Return fine

    End Function
   

    Function checkValidBook() As Boolean

        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 ISBNtxt.Text <> isbn Then
            Return False
        Else
            Return True
        End If
    End Function
   
   
    Function checkValidReader() As Boolean

        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 readerNotxt.Text <> readerNo Then
            Return False
        Else
            Return True
        End If
    End Function

    Sub updateReturnBook()
      
        myConnection.Open()

        myCommand = New OleDbCommand("INSERT INTO ReturnBook VALUES( " & _
             "'" & readerNotxt.Text & "','" & ISBNtxt.Text & "','" & Date.Today.ToShortDateString & "','" & _
            admNotxt.Text & "')", myConnection)

        myCommand.ExecuteNonQuery()

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

    End Sub

    Sub changeRentBookStatus()

        myConnection.Open()

        myCommand = New OleDbCommand("Update RentBook set Status= 'Returned' where ReaderNo='" & _
          readerNo & "'and ISBN='" & ISBNtxt.Text & "'", myConnection)

        myCommand.ExecuteNonQuery()

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

    End Sub

 

    Private Sub returntbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles returnbt.Click
        Try
            If readerNotxt.Text = "" Or ISBNtxt.Text = "" Or admNotxt.Text = "" Or passwordtxt.Text = "" Then
                MsgBox("Information is not enough!")
            Else

                updateReturnBook()
                changeRentBookStatus()
                changeBookDetailStatus()


                If isfine = True Then
                    changeFine()
                    unFreezeReader()
                End If

                MsgBox("Return successfully!")
                isfine = False

                If isReserved Then
                    MsgBox("Somebody now  reserved this books!")
                End If

            End If
        Catch ex As Exception
            MsgBox("You have already insert this record!")
        End Try
    End Sub

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

    Sub unFreezeReader()
        myConnection.Open()
        myCommand = New OleDbCommand("Update ReaderDetails set Status= 'Nfreeze' where ReaderNo='" & readerNo & "'", myConnection)
        myCommand.ExecuteNonQuery()

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

    Sub changeBookDetailStatus()

        myConnection.Open()

        myCommand = New OleDbCommand("Update BookDetails set Status= 'InLib' where ISBN='" & isbn & "'", myConnection)

        myCommand.ExecuteNonQuery()

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

        myConnection.Open()

        myCommand = New OleDbCommand("Update Fine set Status= 'Paid',PayFineDate='" & Date.Today.ToShortDateString & "',finePrice=" & finePrice & " where isbn='" _
        & isbn & "' and readerNo='" & readerNo & "' and status='UnPaid'", myConnection)

        myCommand.ExecuteNonQuery()

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


    End Sub


  sub checkValidAdm() 
        Dim admNo As String = ""
        Dim password As String = ""


        myConnection.Open()
        myCommand = New OleDbCommand("select * from Administrator where AdmNo = '" & admNotxt.Text & _
           "'", myConnection)
        myReader = myCommand.ExecuteReader()

        While myReader.Read
            admNo = myReader("AdmNo")
            password = myReader("Password")
        End While

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

        If admNotxt.Text <> admNo Then
            MsgBox("Invalid Administrator ID!")
            returnbt.Enabled = False
            admNotxt.Clear()
            admNotxt.Focus()
            passwordtxt.Clear()

        Else

            If password = passwordtxt.Text Then
                returnbt.Enabled = True

            Else

                MsgBox("Invalid Administrator Password!")
                returnbt.Enabled = False
                passwordtxt.Focus()
                passwordtxt.SelectAll()


            End If
        End If
    End Sub


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

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


        finePerDaytxt.Clear()
        admNotxt.Clear()
        passwordtxt.Clear()

    End Sub

    Private Sub frm_ReturnBook_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        readerNotxt.Focus()
    End Sub




End Class

⌨️ 快捷键说明

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