📄 frm_adduser.vb
字号:
Imports System.Data.OleDb
Public Class AddUser
Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
Dim myCommand As OleDbCommand
Dim myReader As OleDbDataReader
Private Sub okbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles okbt.Click
If completeEnterInfo() Then
Try
addReaderInfo()
MsgBox("Insert success!")
Catch ex As Exception
MsgBox("You have insert this record!")
End Try
Else
MsgBox("Information is not enough!")
End If
End Sub
Function checkIfAreadyExists(ByVal id) As Boolean
Dim temp As String
temp = ""
myConnection.Open()
myCommand = New OleDbCommand("select * from ReaderDetails where ReaderNo='" & readerNotxt.Text & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
temp = myReader.Read()
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
If temp = "" Then
Return False
Else
Return True
End If
End Function
Sub addReaderInfo()
myConnection.Open()
myCommand = New OleDbCommand("INSERT INTO ReaderDetails VALUES('" & _
readerNotxt.Text & "','" & typeCodecombo.Text & "','" & passwordtxt.Text & "','" & _
phonetxt.Text & "','" & nametxt.Text & "','" & addresstxt.Text & "','" & emailtxt.Text & _
"','" & sexcombo.Text & "',0,'Nfreeze')", myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
myCommand.Dispose()
End Sub
Function completeEnterInfo() As Boolean
If readerNotxt.Text = "" Or nametxt.Text = "" Or passwordtxt.Text = "" Or sexcombo.Text = "" Or _
typeCodecombo.Text = "" Or addresstxt.Text = "" Or phonetxt.Text = "" Or emailtxt.Text = "" Then
Return False
Else
Return True
End If
End Function
Private Sub readerNotxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles readerNotxt.TextChanged
If checkIfAreadyExists(readerNotxt.Text) Then
MsgBox("This SN is already in the record,enter a new one Please!")
readerNotxt.Focus()
readerNotxt.SelectAll()
End If
End Sub
Private Sub AddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
addToReaderCodeCombo()
readerNotxt.Focus()
End Sub
Sub addToReaderCodeCombo()
myConnection.Open()
myCommand = New OleDbCommand("select * from ReaderType", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
typeCodecombo.Items.Add(myReader("ReaderTypeCode"))
typecombo.Items.Add(myReader("Type"))
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
End Sub
Private Sub typeCodecombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles typeCodecombo.SelectedIndexChanged
typecombo.SelectedIndex = typeCodecombo.SelectedIndex
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()
passwordtxt.Clear()
nametxt.Clear()
addresstxt.Clear()
phonetxt.Clear()
emailtxt.Clear()
sexcombo.Text = ""
typeCodecombo.Text = ""
typecombo.Text = ""
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -