📄 frm_addnewbook.vb
字号:
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtBookAuthor.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtBookAuthor) = False Then
display_MsgBox("Please Fill in the field")
Else
If checkTextbox(TxtBookAuthor) = True Then
TxtEdition.Focus()
End If
End If
Case Else
'dotnothing
End Select
End Sub
Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtEdition.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtEdition) = False Then
display_MsgBox("Please Fill in the field")
Else
If checkTextbox(TxtEdition) = True Then
TxtPublishdate.Focus()
End If
End If
Case Else
'dotnothing
End Select
End Sub
Private Sub TextBox9_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPublishdate.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtPublishdate) = False Then
display_MsgBox("Please Fill in the field")
Else
If checkTextbox(TxtPublishdate) = True Then
Dim myText As String = TxtPublishdate.Text
ComboStatus.Focus()
End If
End If
Case Else
'dotnothing
End Select
End Sub
Private Sub ComboboxBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboStatus.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkCombobox(ComboStatus) = False Then
display_MsgBox("请在文本框中输入信息")
Else
If checkCombobox(ComboStatus) = True Then
TxtAdditionDate.Focus()
End If
End If
Case Else
'什么也不做
End Select
End Sub
Private Sub TextBox10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtAdditionDate.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtAdditionDate) = False Then
display_MsgBox("Please Fill in the field")
Else
If checkTextbox(TxtAdditionDate) = True Then
Dim myText2 = TxtAdditionDate.Text
BtnAdd.Focus()
End If
End If
Case Else
'dotnothing
End Select
End Sub
Function checkCombobox(ByVal t As ComboBox) As Boolean
If t.Text = "" Then
Return False
Else
Return True
End If
End Function
Function clearFields()
TxtSN.Text = ""
TxtISBN.Text = ""
TxtBookName.Text = ""
TxtBookCode.Text = ""
TxtBookType.Text = ""
TxtBookDes.Text = ""
TxtBookAuthor.Text = ""
TxtEdition.Text = ""
TxtPublishdate.Text = ""
TxtAdditionDate.Text = ""
ComboBookCode.Text = ""
ComboBookType.Text = ""
ComboStatus.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 display_MsgBox(ByVal myMsg As String)
MsgBox(myMsg, MsgBoxStyle.Information, "图书馆管理系统")
End Function
Function add_IntoComboBookCode()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookCode", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
ComboBookCode.Items.Add(MyReader("Code"))
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Function
Function add_IntoComboBookType()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookType", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
ComboBookType.Items.Add(MyReader("Type"))
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Function
Private Sub ComboBookType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBookType.SelectedIndexChanged
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookType WHERE Type ='" & ComboBookType.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TxtBookType.Text = MyReader("Desc")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Private Sub ComboBookCode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBookCode.SelectedIndexChanged
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookCode WHERE Code ='" & ComboBookCode.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TxtBookCode.Text = MyReader("Desc1")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Function add_BookIntoDatabase()
MyConnection.Open()
MyCommand = New OleDbCommand("INSERT INTO BookDetails VALUES('" & TxtSN.Text & "','" & TxtISBN.Text & "', '" & TxtBookName.Text & "','" & ComboBookCode.Text & "','" & ComboBookType.Text & "','" & TxtBookDes.Text & "','" & TxtBookAuthor.Text & "','" & TxtPublishdate.Text & "','" & TxtEdition.Text & "','" & ComboStatus.Text & "','" & picPath & "','" & TxtAdditionDate.Text & "')", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyCommand.Dispose()
End Function
' Function processDate(ByVal dateString As String) As String
' Dim strLength As Integer = dateString.Length
' Dim tempString1 As String
' Dim tempString2 As String
' Dim tempString22 As String
' Dim tempString3 As String
' If strLength > 8 Or strLength < 8 Then
' display_MsgBox("Cannot Process Format Of String")
' Else
' tempString1 = dateString.Chars(0).ToString + dateString.Chars(1).ToString
' tempString22 = dateString.Chars(2).ToString + dateString.Chars(3).ToString
' tempString2 = get_Month(tempString22)
' tempString3 = dateString.Chars(4).ToString + dateString.Chars(5).ToString + dateString.Chars(6).ToString + dateString.Chars(7).ToString
' Return tempString1 + "-" + tempString2 + "-" + tempString3
' End If
' End Function
'Function get_Month(ByVal oMonth As String) As String
' Dim monthString As String = "NIL"
'Select Case oMonth
' Case "01"
' monthString = "JAN"
' Case "02"
' monthString = "FEB"
' Case "03"
' monthString = "MAR"
' Case "04"
' monthString = "APR"
' Case "05"
' monthString = "MAY"
' Case "06"
' monthString = "JUN"
' Case "07"
' monthString = "JUL"
' Case "08"
' monthString = "AUG"
' Case "09"
' monthString = "SEP"
' Case "10"
' monthString = "OCT"
' Case "11"
' monthString = "NOV"
' Case "12"
' monthString = "DEC"
' Case Else
'do nothing
' End Select
' Return monthString
' End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
clearFields()
TxtSN.Focus()
Beep()
End Sub
Function checkSpecificFields() As Boolean
If TxtSN.Text = "" Or TxtISBN.Text = "" Or TxtBookName.Text = "" Or TxtBookDes.Text = "" Or TxtBookAuthor.Text = "" Or TxtEdition.Text = "" Or TxtPublishdate.Text = "" Or TxtAdditionDate.Text = "" Then
Return False
Else
Return True
End If
End Function
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
If checkSpecificFields() = False Then
display_MsgBox("请在相应的文本框中添加书籍信息")
Else
If checkSpecificFields() = True Then
add_BookIntoDatabase()
Beep()
TxtSN.Focus()
display_MsgBox("书籍信息已被添加到数据库")
clearFields()
End If
End If
End Sub
Function checkIfAlreadyExists() As Boolean
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookDetails WHERE SN ='" & TxtSN.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
Dim TempString As String
While MyReader.Read
TempString = MyReader("SN")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
If TxtSN.Text = TempString Then
Return True
Else
If TxtSN.Text <> TempString Then
Return False
End If
End If
End Function
Private Sub OpenFileDialog1_FileOk1(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim width As Integer = 100
Dim height As Integer = 100
bookPicture = System.Drawing.Bitmap.FromFile(OpenFileDialog1.FileName)
picPath = OpenFileDialog1.FileName.ToString
PictureBox1.Image = bookPicture
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -