📄 frm_renewalbook.vb
字号:
Imports System.Data.OleDb
Public Class frm_renewalBook
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 maxRenewalNo As String
Dim alrRenewalNo As String
Dim readerTypeCode As String
Dim updateRenewalNo As Integer
Dim freezeStatus As Boolean = False
Dim newDueDate As Date
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 readerNotxt.Text <> "" Then
If checkValidReader() Then
ISBNtxt.Focus()
renewalbt.Enabled = True
Else
If freezeStatus = False Then
MsgBox("Invalid reader ID!")
readerNotxt.Focus()
readerNotxt.SelectAll()
renewalbt.Enabled = False
End If
End If
Else
MsgBox("Reader no can not be empty!")
renewalbt.Enabled = False
End If
End If
freezeStatus = False
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 ISBNtxt.Text <> "" Then
If checkValidBook() Then
If alrInRentRec() = False Then
MsgBox("Reader has not borrowed this book yet,so need not to renewal! ")
renewalbt.Enabled = False
Else
setMaxRenewal()
setAlrRenewalNoAndDate()
displayRewInfo()
admNotxt.Focus()
renewalbt.Enabled = True
End If
Else
MsgBox("Invalid book ISBN!")
ISBNtxt.Focus()
ISBNtxt.SelectAll()
renewalbt.Enabled = False
End If
Else
MsgBox("ISBN no can not be empty!")
renewalbt.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 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
Function checkValidReader() As Boolean
Dim readerNo As String = ""
Dim status As String = ""
myConnection.Open()
myCommand = New OleDbCommand("select * from ReaderDetails where ReaderNo='" & readerNotxt.Text & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
readerNo = myReader("ReaderNo")
readerTypeCode = myReader("ReaderTypeCode")
status = myReader("status")
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
If readerNo = "" Then
Return False
ElseIf status = "freeze" Then
freezeStatus = True
MsgBox("The user is frozen now, can not be serviced!")
renewalbt.Enabled = False
Return False
Else
Return True
End If
End Function
Sub setMaxRenewal()
myConnection.Open()
myCommand = New OleDbCommand("select * from ReaderType where ReaderTypeCode='" & readerTypeCode & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
maxRenewalNo = myReader("RenewalNo")
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
End Sub
Sub setAlrRenewalNoAndDate()
Dim oldDueDate As Date
myConnection.Open()
myCommand = New OleDbCommand("select * from RentBook where ReaderNo='" & readerNotxt.Text & _
"' and ISBN ='" & ISBNtxt.Text & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
alrRenewalNo = myReader("AlrRenewalNo")
oldDueDate = Date.Parse(myReader("Duedate"))
End While
updateRenewalNo = Integer.Parse(alrRenewalNo) + 1
newDueDate = oldDueDate.AddDays(10)
myConnection.Close()
myCommand.Dispose()
myReader.Close()
End Sub
Sub displayRewInfo()
maxRewNotxt.Text = maxRenewalNo
alrRewNotxt.Text = alrRenewalNo
End Sub
Private Sub renewalbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles renewalbt.Click
If readerNotxt.Text = "" Or ISBNtxt.Text = "" Or admNotxt.Text = "" Or passwordtxt.Text = "" Then
MsgBox("Information is not enough!")
Else
renewal()
End If
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
Function checkValidAdm() As Boolean
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 admNo = "" Then
MsgBox("Invalid Administrator ID!")
admNotxt.Clear()
admNotxt.Focus()
passwordtxt.Clear()
renewalbt.Enabled = False
Else
If password = passwordtxt.Text Then
renewalbt.Enabled = True
Return True
Else
MsgBox("Invalid Administrator Password!")
passwordtxt.Focus()
passwordtxt.SelectAll()
renewalbt.Enabled = False
Return False
End If
End If
End Function
Sub renewal()
If Integer.Parse(alrRewNotxt.Text) >= Integer.Parse(maxRewNotxt.Text) Then
MsgBox("Can not renewal any more book!")
renewalbt.Enabled = False
Else
myConnection.Open()
myCommand = New OleDbCommand("Update RentBook set AlrRenewalNO= " & updateRenewalNo & _
",DueDate=#" & newDueDate.ToShortDateString & "# where ReaderNo='" & _
readerNotxt.Text & "' and ISBN ='" & ISBNtxt.Text & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
alrRenewalNo = myReader("AlrRenewalNo")
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
MsgBox("Renewal successfully!")
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()
maxRewNotxt.Clear()
alrRewNotxt.Clear()
admNotxt.Clear()
passwordtxt.Clear()
readerNotxt.Focus()
renewalbt.Enabled = True
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -