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

📄 frmadduser.vb

📁 vb。net 2003数据库设计整套源代码
💻 VB
字号:
Public Class FrmAddUser
    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 TxtPassword As System.Windows.Forms.TextBox
    Friend WithEvents TxtName As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents BtCancel As System.Windows.Forms.Button
    Friend WithEvents BtOK As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TxtTime As System.Windows.Forms.TextBox
    Friend WithEvents TxtIDOrder As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TxtPassword = New System.Windows.Forms.TextBox()
        Me.TxtName = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.BtCancel = New System.Windows.Forms.Button()
        Me.BtOK = New System.Windows.Forms.Button()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.TxtIDOrder = New System.Windows.Forms.TextBox()
        Me.TxtTime = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'TxtPassword
        '
        Me.TxtPassword.Location = New System.Drawing.Point(160, 112)
        Me.TxtPassword.MaxLength = 10
        Me.TxtPassword.Name = "TxtPassword"
        Me.TxtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TxtPassword.Size = New System.Drawing.Size(120, 21)
        Me.TxtPassword.TabIndex = 17
        Me.TxtPassword.Text = ""
        '
        'TxtName
        '
        Me.TxtName.Location = New System.Drawing.Point(160, 72)
        Me.TxtName.MaxLength = 10
        Me.TxtName.Name = "TxtName"
        Me.TxtName.Size = New System.Drawing.Size(120, 21)
        Me.TxtName.TabIndex = 16
        Me.TxtName.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(56, 114)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 24)
        Me.Label2.TabIndex = 15
        Me.Label2.Text = "密码:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(56, 77)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 24)
        Me.Label1.TabIndex = 14
        Me.Label1.Text = "姓名:"
        '
        'BtCancel
        '
        Me.BtCancel.Location = New System.Drawing.Point(184, 200)
        Me.BtCancel.Name = "BtCancel"
        Me.BtCancel.Size = New System.Drawing.Size(80, 32)
        Me.BtCancel.TabIndex = 13
        Me.BtCancel.Text = "取消"
        '
        'BtOK
        '
        Me.BtOK.Location = New System.Drawing.Point(64, 200)
        Me.BtOK.Name = "BtOK"
        Me.BtOK.Size = New System.Drawing.Size(72, 32)
        Me.BtOK.TabIndex = 12
        Me.BtOK.Text = "确定"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(56, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(48, 32)
        Me.Label3.TabIndex = 18
        Me.Label3.Text = "编号:"
        '
        'TxtIDOrder
        '
        Me.TxtIDOrder.Location = New System.Drawing.Point(160, 32)
        Me.TxtIDOrder.MaxLength = 6
        Me.TxtIDOrder.Name = "TxtIDOrder"
        Me.TxtIDOrder.Size = New System.Drawing.Size(120, 21)
        Me.TxtIDOrder.TabIndex = 19
        Me.TxtIDOrder.Text = ""
        '
        'TxtTime
        '
        Me.TxtTime.Location = New System.Drawing.Point(160, 152)
        Me.TxtTime.MaxLength = 3
        Me.TxtTime.Name = "TxtTime"
        Me.TxtTime.Size = New System.Drawing.Size(120, 21)
        Me.TxtTime.TabIndex = 21
        Me.TxtTime.Text = "0"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(56, 151)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(48, 24)
        Me.Label4.TabIndex = 20
        Me.Label4.Text = "机时:"
        '
        'FrmAddUser
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(336, 262)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TxtTime, Me.Label4, Me.TxtIDOrder, Me.Label3, Me.TxtPassword, Me.TxtName, Me.Label2, Me.Label1, Me.BtCancel, Me.BtOK})
        Me.MaximizeBox = False
        Me.Name = "FrmAddUser"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "添加用户"
        Me.ResumeLayout(False)

    End Sub

#End Region

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

    Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
        If UserExist() = True Then
            '判断用户的编号是否已经存在
            MsgBox("该用户名已经存在!", MsgBoxStyle.Exclamation, Me.Text)
            TxtIDOrder.Text = ""
            TxtName.Text = ""
            TxtPassword.Text = ""
            TxtTime.Text = "0"
            TxtIDOrder.Focus()
            Exit Sub
        End If
        If Trim(TxtName.Text) = "" Then
            MsgBox("输入的用户名不能为空!", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If
        If Trim(TxtPassword.Text) = "" Then
            MsgBox("输入的密码不能为空!", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If
        If Not IsNumeric(TxtTime.Text) Then
            MsgBox("输入的机时只能为数字!", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If
        Dim oleconn As New OleDb.OleDbConnection(CONN)
        Dim SQLString As String
        SQLString = "INSERT INTO tbUser(IDOrder,UserName,Pwd,RemainTime)" & _
        "VALUES('" & Trim(TxtIDOrder.Text) & "','" & Trim(TxtName.Text) & "'," & _
        "'" & Trim(TxtPassword.Text) & "','" & Val(TxtTime.Text) & "')"
        CommandRecord(SQLString)  '执行SQL语句
        AddLog(ManagerName & "添加用户" & TxtName.Text) '写日志
        MsgBox("恭喜你,添加用户成功!", , Me.Text)
    End Sub
    Function UserExist() As Boolean
        Dim SQLString As String
        SQLString = "SELECT * FROM tbUser WHERE IDOrder='" & Trim(TxtIDOrder.Text) & "' "
        Dim ObjectdsDataSet As New DataSet()
        Dim oleconn As New OleDb.OleDbConnection(CONN)
        Dim adapter As New OleDb.OleDbDataAdapter()
        adapter.TableMappings.Add("Table", "User")
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SQLString, oleconn)
        cmd.CommandType = CommandType.Text
        adapter.SelectCommand = cmd
        If oleconn.State <> ConnectionState.Open Then
            oleconn.Open() '打开数据库连接
        End If
        cmd.ExecuteNonQuery()  '执行SQL语句
        If oleconn.State <> ConnectionState.Closed Then
            oleconn.Close()  '关闭数据库连接
        End If
        adapter.Fill(ObjectdsDataSet)
        If ObjectdsDataSet.Tables("User").Rows.Count <> 0 Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

⌨️ 快捷键说明

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