欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

frmuser.vb

需要在.net环境下运行需要安装框架
VB
字号:
Public Class FRMUser
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents DG As System.Windows.Forms.DataGrid
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents tbUname As System.Windows.Forms.TextBox
    Friend WithEvents tbUPass1 As System.Windows.Forms.TextBox
    Friend WithEvents tbUPass2 As System.Windows.Forms.TextBox
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnDel As System.Windows.Forms.Button
    Friend WithEvents btnChg As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DG = New System.Windows.Forms.DataGrid()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.tbUname = New System.Windows.Forms.TextBox()
        Me.tbUPass1 = New System.Windows.Forms.TextBox()
        Me.tbUPass2 = New System.Windows.Forms.TextBox()
        Me.btnAdd = New System.Windows.Forms.Button()
        Me.btnDel = New System.Windows.Forms.Button()
        Me.btnChg = New System.Windows.Forms.Button()
        CType(Me.DG, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DG
        '
        Me.DG.DataMember = ""
        Me.DG.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DG.Location = New System.Drawing.Point(8, 96)
        Me.DG.Name = "DG"
        Me.DG.Size = New System.Drawing.Size(280, 176)
        Me.DG.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(48, 16)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "用户名"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 44)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "密码"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 72)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(48, 16)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "重复"
        '
        'tbUname
        '
        Me.tbUname.Location = New System.Drawing.Point(64, 14)
        Me.tbUname.Name = "tbUname"
        Me.tbUname.Size = New System.Drawing.Size(136, 21)
        Me.tbUname.TabIndex = 4
        Me.tbUname.Text = ""
        '
        'tbUPass1
        '
        Me.tbUPass1.Location = New System.Drawing.Point(64, 42)
        Me.tbUPass1.Name = "tbUPass1"
        Me.tbUPass1.PasswordChar = Microsoft.VisualBasic.ChrW(64)
        Me.tbUPass1.Size = New System.Drawing.Size(136, 21)
        Me.tbUPass1.TabIndex = 5
        Me.tbUPass1.Text = ""
        '
        'tbUPass2
        '
        Me.tbUPass2.Location = New System.Drawing.Point(64, 70)
        Me.tbUPass2.Name = "tbUPass2"
        Me.tbUPass2.PasswordChar = Microsoft.VisualBasic.ChrW(64)
        Me.tbUPass2.Size = New System.Drawing.Size(136, 21)
        Me.tbUPass2.TabIndex = 6
        Me.tbUPass2.Text = ""
        '
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(224, 13)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(64, 23)
        Me.btnAdd.TabIndex = 7
        Me.btnAdd.Text = "添加"
        '
        'btnDel
        '
        Me.btnDel.Location = New System.Drawing.Point(224, 41)
        Me.btnDel.Name = "btnDel"
        Me.btnDel.Size = New System.Drawing.Size(64, 23)
        Me.btnDel.TabIndex = 8
        Me.btnDel.Text = "删除"
        '
        'btnChg
        '
        Me.btnChg.Location = New System.Drawing.Point(224, 69)
        Me.btnChg.Name = "btnChg"
        Me.btnChg.Size = New System.Drawing.Size(64, 23)
        Me.btnChg.TabIndex = 9
        Me.btnChg.Text = "更新"
        '
        'FRMUser
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnChg, Me.btnDel, Me.btnAdd, Me.tbUPass2, Me.tbUPass1, Me.tbUname, Me.Label3, Me.Label2, Me.Label1, Me.DG})
        Me.Name = "FRMUser"
        Me.Text = "用户管理"
        CType(Me.DG, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If Not check() Then
            Exit Sub
        End If
        Dim sqlStr As String = "select uName from myUser where uName='" & tbUname.Text & "'"
        Dim dbopera1 As DbOpera = New DbOpera(sqlStr)
        If dbopera1.checkValid() Then
            MsgBox("已经存在了该名字的用户!", MsgBoxStyle.Exclamation, "OK")
            Exit Sub
        End If
        sqlStr = "insert into myUser(uName,uPass) values('" & tbUname.Text & "','" & tbUPass1.Text & "')"
        dbopera1 = New DbOpera(sqlStr)
        If dbopera1.opera() Then
            MsgBox("成功!", MsgBoxStyle.Exclamation, "OK")
        Else
            MsgBox("失败!", MsgBoxStyle.Exclamation, "OK")
        End If
        Dim sqlStr3 As String = "select uName from myUser"
        Dim dbopera3 As DbOpera = New DbOpera(sqlStr3)
        DG.DataSource = dbopera3.getDG().DataSource
    End Sub
    Private Function check() As Boolean
        If tbUname.Text = "" Or tbUPass1.Text = "" Or tbUPass2.Text = "" Then
            MsgBox("输入完整的信息!", MsgBoxStyle.Exclamation, "OK")
            check = False
            Exit Function
        ElseIf tbUPass1.Text <> tbUPass2.Text Then
            MsgBox("两次密码不一致!", MsgBoxStyle.Exclamation, "OK")
            check = False
            Exit Function
        Else
            check = True
        End If
    End Function

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        If tbUname.Text = "" Then
            MsgBox("用户名不可以为空!", MsgBoxStyle.Exclamation, "OK")
            Exit Sub
        End If
        Dim sqlStr As String = "delete from myUser where uName='" & tbUname.Text & "'"
        Dim dbopera1 As DbOpera = New DbOpera(sqlStr)
        If dbopera1.opera() Then
            MsgBox("成功!", MsgBoxStyle.Exclamation, "OK")
        Else
            MsgBox("失败!", MsgBoxStyle.Exclamation, "OK")
        End If
        Dim sqlStr3 As String = "select uName from myUser"
        Dim dbopera3 As DbOpera = New DbOpera(sqlStr3)
        DG.DataSource = dbopera3.getDG().DataSource
    End Sub

    Private Sub btnChg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChg.Click
        If tbUname.Text <> userName Then
            MsgBox("你不可以更改别的用户的密码!", MsgBoxStyle.Exclamation, "OK")
            Exit Sub
        End If
        Dim sqlStr As String = "update myUser set uPass='" & tbUPass1.Text & "' where uName='" & userName
        Dim dbopera1 As DbOpera = New DbOpera(sqlStr)
        If dbopera1.opera() Then
            MsgBox("成功!", MsgBoxStyle.Exclamation, "OK")
        Else
            MsgBox("失败!", MsgBoxStyle.Exclamation, "OK")
        End If
    End Sub

    Private Sub FRMUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sqlStr3 As String = "select uName from myUser"
        Dim dbopera3 As DbOpera = New DbOpera(sqlStr3)
        DG.DataSource = dbopera3.getDG().DataSource
        DG.NavigateTo(0, "marvin")
    End Sub
End Class

⌨️ 快捷键说明

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