⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm_add.vb

📁 一个用VB.NET做的图书管理系统,功能比较简单
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(120, 25)
        Me.Label4.TabIndex = 4
        Me.Label4.Text = "密码"
        '
        'TxtPassword
        '
        Me.TxtPassword.Location = New System.Drawing.Point(154, 95)
        Me.TxtPassword.Name = "TxtPassword"
        Me.TxtPassword.Size = New System.Drawing.Size(201, 21)
        Me.TxtPassword.TabIndex = 5
        '
        'frm_UserMaintenance
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(405, 514)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.BtnAdd)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.TxtUserID)
        Me.Controls.Add(Me.Label1)
        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_UserMaintenance"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "添加用户"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Sub clearFields()
        TxtUserID.Text = ""
        TxtUserName.Text = ""
        TxtCurrentAddress.Text = ""
        TxtPassword.Text = ""
        TxtPhone.Text = ""
        TxtCellPhone.Text = ""
        TxtEmail.Text = ""
        ComboAdmin.Text = ""
        ComboLib.Text = ""
        ComboGeneral.Text = ""
    End Sub

    Function checkifExists() As Boolean
        Dim temp As String
        MyConnection.Open()
        MyCommand = New OleDbCommand("SELECT * FROM SystemUsers WHERE UserID ='" & TxtUserID.Text & "'", MyConnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            temp = MyReader("UserID")
            ComboAdmin.Text = MyReader("AdminRights")
            ComboLib.Text = MyReader("LibRights")
            ComboGeneral.Text = MyReader("ReaderRights")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.Dispose()
        If temp = TxtUserID.Text Then
            Return True
        Else
            If temp <> TxtUserID.Text Then
                Return False
            End If
        End If
    End Function



    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub



    Private Sub TxtUserID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtUserID.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checktextbox(TxtUserID) = False Then
                    displayMsg("请在文本框中输入信息!")
                Else

                End If
            Case Else
                '什么也不做
        End Select
    End Sub

    Private Sub TxtUserName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtUserName.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checktextbox(TxtUserName) = False Then
                    displayMsg("请在文本框中输入信息!")
                Else
                    If checktextbox(TxtUserName) = True Then
                        TxtCurrentAddress.Focus()
                    End If
                End If
            Case Else
                '什么也不做
        End Select
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtCurrentAddress.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checktextbox(TxtCurrentAddress) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checktextbox(TxtCurrentAddress) = True Then
                        TxtPassword.Focus()
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPassword.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checktextbox(TxtPassword) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checktextbox(TxtPassword) = 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
                    displayMsg("Please Fill in the field!")
                Else
                    If checktextbox(TxtPhone) = True Then
                        TxtCellPhone.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 TxtCellPhone.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checktextbox(TxtCellPhone) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checktextbox(TxtCellPhone) = True Then
                        TxtEmail.Focus()
                    End If
                End If
            Case Else
                'do nothing
        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)
                If checktextbox(TxtEmail) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checktextbox(TxtEmail) = True Then
                        ComboAdmin.Focus()
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub
    Private Sub ComboAdmin_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboAdmin.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checkcombobox(ComboAdmin) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checkcombobox(ComboAdmin) = True Then
                        ComboLib.Focus()
                    End If
                End If
            Case Else
                '什么也不做
        End Select
    End Sub
    Private Sub comboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboLib.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checkcombobox(ComboLib) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checkcombobox(ComboLib) = True Then
                        ComboGeneral.Focus()
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub
    Private Sub comboBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboGeneral.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If checkcombobox(ComboGeneral) = False Then
                    displayMsg("Please Fill in the field!")
                Else
                    If checkcombobox(ComboGeneral) = True Then
                        BtnAdd.Focus()
                    End If
                End If
            Case Else
                'do nothing
        End Select
    End Sub
    Sub displayMsg(ByVal myMsgText As String)
        MsgBox(myMsgText, MsgBoxStyle.Information, "LIS Version 1.00")
    End Sub
    Function checktextbox(ByVal t As TextBox) As Boolean
        If t.Text = "" Then
            Return False
        Else
            Return True
        End If
    End Function
    Function checkcombobox(ByVal t As ComboBox) As Boolean
        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()
        TxtUserID.Focus()
    End Sub

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click

        If checkifExists() = True Then
            displayMsg("数据库中已存在该用户")
            Exit Sub
        End If
        MyConnection.Open()
        MyCommand = New OleDbCommand("INSERT INTO SystemUsers VALUES('" & TxtUserName.Text & "','" & TxtUserID.Text & "','" & TxtPassword.Text & "','ok ','" & TxtCurrentAddress.Text & "','" & TxtPhone.Text & "','" & TxtCellPhone.Text & "','" & TxtEmail.Text & "','" & Me.ComboAdmin.Text & "','" & Me.ComboLib.Text & "','" & Me.ComboGeneral.Text & "')", MyConnection)
        MyCommand.ExecuteNonQuery()
        MyConnection.Close()
        MyCommand.Dispose()
        displayMsg("用户信息已被添加到数据库")
        clearFields()
        TxtUserID.Focus()
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -