📄 frm_editbookdetails.vb
字号:
'frm_EditBookDetails
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(608, 362)
Me.Controls.Add(Me.BtnRead)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.BtnEdit)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.TxtSN)
Me.Controls.Add(Me.Label1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frm_EditBookDetails"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "编辑书籍信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub BtnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChange.Click
MsgBox("图片的尺寸大于 " + PictureBox1.Width.ToString + " X" + PictureBox1.Height.ToString, MsgBoxStyle.Information, "图书馆管理系统")
OpenFileDialog1.Filter = "Picture Files|*.jpg|*.bmp|*.gif"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.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
Function display_MsgBox(ByVal myMsg As String)
MsgBox(myMsg, MsgBoxStyle.Information, "图书馆管理系统")
End Function
Function updateBook()
MyConnection.Open()
Try
MyCommand = New OleDbCommand("UPDATE BookDetails SET BookName ='" & TxtBookName.Text & "',AuthorName = '" & TxtBookAuthor.Text & "',BookType = '" & ComboBookType.Text & "',BookCode = '" & ComboBookCode.Text & "', BookDes = '" & TxtBookDes.Text & "', PublishDate = '" & TxtPublishdate.Text & "', LibDate = '" & TxtAdditionDate.Text & "',Picture ='" & picPath & "' WHERE SN = '" & TxtSN.Text & "'", MyConnection)
MyCommand.ExecuteNonQuery()
Catch c As Exception
MsgBox(c.ToString)
End Try
MyConnection.Close()
MyCommand.Dispose()
End Function
Function loadBookDetails()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookDetails WHERE SN ='" & TxtSN.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TxtBookName.Text = MyReader("BookName")
TxtBookAuthor.Text = MyReader("AuthorName")
TxtBookDes.Text = MyReader("BookDes")
TxtPublishdate.Text = MyReader("Publishdate")
TxtAdditionDate.Text = MyReader("Libdate")
bookcode1 = MyReader("BookCode")
booktype1 = MyReader("BookType")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
loadCodeDes()
loadTypeDes()
End Function
Private Sub TxtSN_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtSN.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
Case Else
'什么也不做
End Select
End Sub
Private Sub TxtBookName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtBookName.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If TxtBookName.Text = "" Then
Else
If TxtBookName.Text <> "" Then
TxtBookAuthor.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub TextBox3_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 TxtBookAuthor.Text = "" Then
Else
If TxtBookAuthor.Text <> "" Then
ComboBookType.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub combobox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBookType.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If ComboBookType.Text = "" Then
Else
If ComboBookType.Text <> "" Then
ComboBookCode.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub combobox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBookCode.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If ComboBookCode.Text = "" Then
Else
If ComboBookCode.Text <> "" Then
TxtBookDes.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtBookDes.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If TxtBookDes.Text = "" Then
Else
If TxtBookDes.Text <> "" Then
TxtPublishdate.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub TextBox7_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 TxtPublishdate.Text = "" Then
Else
If TxtPublishdate.Text <> "" Then
TxtAdditionDate.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtAdditionDate.KeyPress
Dim strChar As String
Dim temp As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If TxtAdditionDate.Text = "" Then
Else
If TxtAdditionDate.Text <> "" Then
BtnEdit.Focus()
End If
End If
Case Else
'nothing
End Select
End Sub
Function loadBookType()
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
Function loadBookCode()
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
Private Sub frm_EditBookDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loadBookCode()
loadBookType()
End Sub
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
TxtBookCode.Text = MyReader("Desc")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Private Sub ComboBox2_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
TxtBookType.Text = MyReader("Desc1")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Function getPicPath() As String
Dim myTempString As String
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookDetails WHERE SN ='" & TxtSN.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
myTempString = MyReader("Picture")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
Return myTempString
End Function
Sub setPicture()
Try
bookPicture = System.Drawing.Bitmap.FromFile(getPicPath())
Catch c As Exception
MsgBox("错误:" + c.ToString, MsgBoxStyle.Exclamation, "图书馆管理系统")
End Try
PictureBox1.Image = bookPicture
End Sub
Sub loadCodeDes()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookType WHERE Type ='" & booktype1 & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TxtBookCode.Text = MyReader("Desc")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Sub loadTypeDes()
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM BookCode WHERE Code ='" & bookcode1 & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
TxtBookType.Text = MyReader("Desc1")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
End Sub
Function clearfields()
TxtSN.Text = ""
TxtBookName.Text = ""
TxtBookAuthor.Text = ""
TxtBookCode.Text = ""
TxtBookType.Text = ""
TxtBookDes.Text = ""
TxtPublishdate.Text = ""
TxtAdditionDate.Text = ""
ComboBookType.Text = ""
ComboBookCode.Text = ""
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
clearfields()
TxtSN.Focus()
End Sub
Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
updateBook()
display_MsgBox("书籍信息已被更新!")
clearfields()
End Sub
Private Sub BtnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRead.Click
If TxtSN.Text = "" Then
Else
If TxtSN.Text <> "" Then
setPicture()
loadBookDetails()
TxtBookName.Focus()
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -