📄 frm_readerdetails.vb
字号:
'frm_ReaderDetails
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(411, 289)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.BtnAdd)
Me.Controls.Add(Me.GroupBox1)
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_ReaderDetails"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "添加读者信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
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
Sub clearFields()
TxtReaderNo.Text = ""
TxtReaderName.Text = ""
TxtAddress.Text = ""
TxtPhone.Text = ""
TxtCell.Text = ""
TxtEmail.Text = ""
End Sub
Sub display_MSG(ByVal myMsg As String)
MsgBox(myMsg, MsgBoxStyle.Information, "图书馆管理系统")
End Sub
Private Sub TxtReaderNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtReaderNo.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtReaderNo) = False Then
display_MSG("请在文本框中输入读者信息!")
Else
If checkIfValidNumber() = False Then
display_MSG("无效读者编号,请重新输入!")
Else
If checkTextbox(TxtReaderNo) = True Then
TxtReaderName.Focus()
End If
End If
End If
Case Else
'什么也不做
End Select
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtReaderName.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtReaderName) = False Then
display_MSG("Please fill in the field!")
Else
If checkTextbox(TxtReaderName) = True Then
TxtAddress.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtAddress.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtAddress) = False Then
display_MSG("Please fill in the field!")
Else
If checkTextbox(TxtAddress) = True Then
TxtPhone.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPhone.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
If checkTextbox(TxtPhone) = False Then
display_MSG("Please fill in the field!")
Else
If checkTextbox(TxtPhone) = True Then
TxtCell.Focus()
End If
End If
Case Else
'do nothing
End Select
End Sub
Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtCell.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
TxtEmail.Focus()
Case Else
'什么也不做
End Select
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtEmail.KeyPress
Dim strChar As String
strChar = e.KeyChar
Select Case strChar
Case ChrW(System.Windows.Forms.Keys.Enter)
BtnAdd.Focus()
Case Else
'do nothing
End Select
End Sub
Function checkTextbox(ByVal t As TextBox)
If t.Text = "" Then
Return False
Else
Return True
End If
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
clearFields()
TxtReaderNo.Focus()
End Sub
Function RegisterReader()
IssueTag = "3"
IssueTagUsed = "0"
MyConnection.Open()
Try
MyCommand = New OleDbCommand("INSERT INTO ReaderDetails VALUES('" & TxtReaderNo.Text & "','" & TxtReaderName.Text & "', '" & TxtAddress.Text & "','" & TxtPhone.Text & "','" & TxtCell.Text & "','" & TxtEmail.Text & "','" & IssueTag & "','" & IssueTagUsed & "')", MyConnection)
MyCommand.ExecuteNonQuery()
Catch c As Exception
MsgBox(c.ToString)
End Try
MyConnection.Close()
MyCommand.Dispose()
End Function
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
If checkIfAlreadyExists() = True Then
display_MSG("读者编号已存在,请重新输入!")
ElseIf checkIfAlreadyExists() = False Then
RegisterReader()
MsgBox("新读者已注册!", MsgBoxStyle.Information, "图书馆管理系统")
clearFields()
End If
End Sub
Function checkIfAlreadyExists() As Boolean
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM ReaderDetails WHERE ReaderNo ='" & TxtReaderNo.Text & "'", MyConnection)
MyReader = MyCommand.ExecuteReader()
Dim TempString As String
While MyReader.Read
TempString = MyReader("ReaderNo")
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
If TxtReaderNo.Text = TempString Then
Return True
Else
If TxtReaderNo.Text <> TempString Then
Return False
End If
End If
End Function
Function checkIfValidNumber() As Boolean
Dim myBool As Boolean = False
MyConnection.Open()
MyCommand = New OleDbCommand("SELECT * FROM ReaderNo ", MyConnection)
MyReader = MyCommand.ExecuteReader()
While MyReader.Read
If TxtReaderNo.Text = MyReader("RNo") Then
myBool = True
End If
End While
MyConnection.Close()
MyReader.Close()
MyCommand.Dispose()
Return myBool
End Function
Private Sub frm_ReaderDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -