添加用户示例
作者:admin 日期:2008-06-01
Imports System.Data.OleDb
Public Class frm_AddUser
Inherits System.Windows.Forms.Form
Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\library.mdb")
Dim MyCommand As OleDbCommand
Dim MyReader As OleDbDataReader
#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 TxtUserID 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 Label3 As System.Windows.Forms.Label
Friend WithEvents TxtName As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents ComboLib As System.Windows.Forms.ComboBox
Friend WithEvents ComboAdmin As System.Windows.Forms.ComboBox
Friend WithEvents ComboGeneral As System.Windows.Forms.ComboBox
Friend WithEvents Label11 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents TxtAddress As System.Windows.Forms.TextBox
Friend WithEvents TxtPhone As System.Windows.Forms.TextBox
Friend WithEvents TxtCellPhone As System.Windows.Forms.TextBox
Friend WithEvents TxtEmail As System.Windows.Forms.TextBox
Friend WithEvents ComboStatus As System.Windows.Forms.ComboBox
Friend WithEvents BtOK As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TxtPassword = New System.Windows.Forms.TextBox
Me.TxtUserID = 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.TxtName = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.ComboGeneral = New System.Windows.Forms.ComboBox
Me.Label11 = New System.Windows.Forms.Label
Me.ComboLib = New System.Windows.Forms.ComboBox
Me.ComboAdmin = New System.Windows.Forms.ComboBox
Me.Label6 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label10 = New System.Windows.Forms.Label
Me.TxtAddress = New System.Windows.Forms.TextBox
Me.TxtPhone = New System.Windows.Forms.TextBox
Me.TxtCellPhone = New System.Windows.Forms.TextBox
Me.TxtEmail = New System.Windows.Forms.TextBox
Me.ComboStatus = New System.Windows.Forms.ComboBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TxtPassword
'
Me.TxtPassword.Location = New System.Drawing.Point(77, 53)
Me.TxtPassword.MaxLength = 10
Me.TxtPassword.Name = "TxtPassword"
Me.TxtPassword.Size = New System.Drawing.Size(120, 21)
Me.TxtPassword.TabIndex = 11
'
'TxtUserID
'
Me.TxtUserID.Location = New System.Drawing.Point(77, 15)
Me.TxtUserID.MaxLength = 10
Me.TxtUserID.Name = "TxtUserID"
Me.TxtUserID.Size = New System.Drawing.Size(120, 21)
Me.TxtUserID.TabIndex = 10
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(23, 57)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 24)
Me.Label2.TabIndex = 9
Me.Label2.Text = "密码"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(15, 18)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 24)
Me.Label1.TabIndex = 8
Me.Label1.Text = "用户编号"
'
'BtCancel
'
Me.BtCancel.Location = New System.Drawing.Point(231, 327)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(95, 24)
Me.BtCancel.TabIndex = 7
Me.BtCancel.Text = "关闭"
'
'BtOK
'
Me.BtOK.Location = New System.Drawing.Point(78, 327)
Me.BtOK.Name = "BtOK"
Me.BtOK.Size = New System.Drawing.Size(92, 24)
Me.BtOK.TabIndex = 6
Me.BtOK.Text = "确定"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(216, 21)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(53, 12)
Me.Label3.TabIndex = 12
Me.Label3.Text = "用户姓名"
'
'TxtName
'
Me.TxtName.Location = New System.Drawing.Point(287, 15)
Me.TxtName.Name = "TxtName"
Me.TxtName.Size = New System.Drawing.Size(120, 21)
Me.TxtName.TabIndex = 13
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(233, 62)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 24)
Me.Label4.TabIndex = 14
Me.Label4.Text = "状态"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.ComboGeneral)
Me.GroupBox1.Controls.Add(Me.Label11)
Me.GroupBox1.Controls.Add(Me.ComboLib)
Me.GroupBox1.Controls.Add(Me.ComboAdmin)
Me.GroupBox1.Controls.Add(Me.Label6)
Me.GroupBox1.Controls.Add(Me.Label5)
Me.GroupBox1.Location = New System.Drawing.Point(11, 169)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(398, 146)
Me.GroupBox1.TabIndex = 16
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "权限设置"
'
'ComboGeneral
'
Me.ComboGeneral.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboGeneral.FormattingEnabled = True
Me.ComboGeneral.Items.AddRange(New Object() {"是", "否"})
Me.ComboGeneral.Location = New System.Drawing.Point(122, 103)
Me.ComboGeneral.Name = "ComboGeneral"
Me.ComboGeneral.Size = New System.Drawing.Size(252, 20)
Me.ComboGeneral.TabIndex = 5
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Location = New System.Drawing.Point(15, 106)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(89, 12)
Me.Label11.TabIndex = 4
Me.Label11.Text = "一般管理员权限"
'
'ComboLib
'
Me.ComboLib.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboLib.FormattingEnabled = True
Me.ComboLib.Items.AddRange(New Object() {"是", "否"})
Me.ComboLib.Location = New System.Drawing.Point(122, 65)
Me.ComboLib.Name = "ComboLib"
Me.ComboLib.Size = New System.Drawing.Size(252, 20)
Me.ComboLib.TabIndex = 3
'
'ComboAdmin
'
Me.ComboAdmin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboAdmin.FormattingEnabled = True
Me.ComboAdmin.Items.AddRange(New Object() {"是", "否"})
Me.ComboAdmin.Location = New System.Drawing.Point(120, 28)
Me.ComboAdmin.Name = "ComboAdmin"
Me.ComboAdmin.Size = New System.Drawing.Size(254, 20)
Me.ComboAdmin.TabIndex = 2
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(17, 68)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(89, 12)
Me.Label6.TabIndex = 1
Me.Label6.Text = "图书管理员权限"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(16, 31)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(89, 12)
Me.Label5.TabIndex = 0
Me.Label5.Text = "系统管理员权限"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(23, 100)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(48, 24)
Me.Label7.TabIndex = 17
Me.Label7.Text = "地址"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(233, 100)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(48, 24)
Me.Label8.TabIndex = 18
Me.Label8.Text = "电话"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(23, 135)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(48, 24)
Me.Label9.TabIndex = 19
Me.Label9.Text = "手机"
'
'Label10
'
Me.Label10.Location = New System.Drawing.Point(233, 135)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(48, 24)
Me.Label10.TabIndex = 20
Me.Label10.Text = "Email"
'
'TxtAddress
'
Me.TxtAddress.Location = New System.Drawing.Point(77, 97)
Me.TxtAddress.MaxLength = 10
Me.TxtAddress.Name = "TxtAddress"
Me.TxtAddress.Size = New System.Drawing.Size(120, 21)
Me.TxtAddress.TabIndex = 21
'
'TxtPhone
'
Me.TxtPhone.Location = New System.Drawing.Point(287, 97)
Me.TxtPhone.MaxLength = 10
Me.TxtPhone.Name = "TxtPhone"
Me.TxtPhone.Size = New System.Drawing.Size(120, 21)
Me.TxtPhone.TabIndex = 22
'
'TxtCellPhone
'
Me.TxtCellPhone.Location = New System.Drawing.Point(77, 132)
Me.TxtCellPhone.MaxLength = 10
Me.TxtCellPhone.Name = "TxtCellPhone"
Me.TxtCellPhone.Size = New System.Drawing.Size(120, 21)
Me.TxtCellPhone.TabIndex = 23
'
'TxtEmail
'
Me.TxtEmail.Location = New System.Drawing.Point(289, 135)
Me.TxtEmail.MaxLength = 10
Me.TxtEmail.Name = "TxtEmail"
Me.TxtEmail.Size = New System.Drawing.Size(120, 21)
Me.TxtEmail.TabIndex = 24
'
'ComboStatus
'
Me.ComboStatus.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboStatus.FormattingEnabled = True
Me.ComboStatus.Items.AddRange(New Object() {"正常", "冻结"})
Me.ComboStatus.Location = New System.Drawing.Point(287, 55)
Me.ComboStatus.Name = "ComboStatus"
Me.ComboStatus.Size = New System.Drawing.Size(120, 20)
Me.ComboStatus.TabIndex = 25
'
'frm_AddUser
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(419, 361)
Me.Controls.Add(Me.ComboStatus)
Me.Controls.Add(Me.TxtEmail)
Me.Controls.Add(Me.TxtCellPhone)
Me.Controls.Add(Me.TxtPhone)
Me.Controls.Add(Me.TxtAddress)
Me.Controls.Add(Me.Label10)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.TxtName)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TxtPassword)
Me.Controls.Add(Me.TxtUserID)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.BtCancel)
Me.Controls.Add(Me.BtOK)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frm_AddUser"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "添加用户信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
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
Sub addUser()
MyConnection.Open()
MyCommand = New OleDbCommand("Insert INTO SystemUsers VALUES('" & TxtUserID.Text & "','" & TxtName.Text & "','" & TxtPassword.Text & "','" & ComboStatus.Text & "','" & TxtAddress.Text & "','" & TxtPhone.Text & "','" & TxtCellPhone.Text & "','" & TxtEmail.Text & "','" & ComboAdmin.Text & "','" & ComboLib.Text & "','" & ComboGeneral.Text & "')", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyCommand.Dispose()
End Sub
Function checkIfAlreadyExists() 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")
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 BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
If Trim(TxtUserID.Text) = "" Then
displayMsg("输入的用户编号不能为空!")
Exit Sub
End If
If Trim(TxtName.Text) = "" Then
displayMsg("输入的用户姓名不能为空!")
Exit Sub
End If
If Trim(TxtPassword.Text) = "" Then
displayMsg("输入的密码不能为空!")
Exit Sub
End If
If checkIfAlreadyExists() = True Then
displayMsg("用户编号已经存在请重新输入!")
Exit Sub
Else
addUser()
displayMsg("用户信息已被成功添加到数据库!")
End If
End Sub
Sub displayMsg(ByVal myMsgText As String)
MsgBox(myMsgText, MsgBoxStyle.Information, "图书管管理系统")
End Sub
Private Sub FrmAddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboAdmin.SelectedIndex = 0
ComboLib.SelectedIndex = 0
ComboGeneral.SelectedIndex = 0
ComboStatus.SelectedIndex = 0
End Sub
End Class
Public Class frm_AddUser
Inherits System.Windows.Forms.Form
Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\library.mdb")
Dim MyCommand As OleDbCommand
Dim MyReader As OleDbDataReader
#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 TxtUserID 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 Label3 As System.Windows.Forms.Label
Friend WithEvents TxtName As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents ComboLib As System.Windows.Forms.ComboBox
Friend WithEvents ComboAdmin As System.Windows.Forms.ComboBox
Friend WithEvents ComboGeneral As System.Windows.Forms.ComboBox
Friend WithEvents Label11 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents TxtAddress As System.Windows.Forms.TextBox
Friend WithEvents TxtPhone As System.Windows.Forms.TextBox
Friend WithEvents TxtCellPhone As System.Windows.Forms.TextBox
Friend WithEvents TxtEmail As System.Windows.Forms.TextBox
Friend WithEvents ComboStatus As System.Windows.Forms.ComboBox
Friend WithEvents BtOK As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TxtPassword = New System.Windows.Forms.TextBox
Me.TxtUserID = 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.TxtName = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.ComboGeneral = New System.Windows.Forms.ComboBox
Me.Label11 = New System.Windows.Forms.Label
Me.ComboLib = New System.Windows.Forms.ComboBox
Me.ComboAdmin = New System.Windows.Forms.ComboBox
Me.Label6 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label10 = New System.Windows.Forms.Label
Me.TxtAddress = New System.Windows.Forms.TextBox
Me.TxtPhone = New System.Windows.Forms.TextBox
Me.TxtCellPhone = New System.Windows.Forms.TextBox
Me.TxtEmail = New System.Windows.Forms.TextBox
Me.ComboStatus = New System.Windows.Forms.ComboBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TxtPassword
'
Me.TxtPassword.Location = New System.Drawing.Point(77, 53)
Me.TxtPassword.MaxLength = 10
Me.TxtPassword.Name = "TxtPassword"
Me.TxtPassword.Size = New System.Drawing.Size(120, 21)
Me.TxtPassword.TabIndex = 11
'
'TxtUserID
'
Me.TxtUserID.Location = New System.Drawing.Point(77, 15)
Me.TxtUserID.MaxLength = 10
Me.TxtUserID.Name = "TxtUserID"
Me.TxtUserID.Size = New System.Drawing.Size(120, 21)
Me.TxtUserID.TabIndex = 10
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(23, 57)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 24)
Me.Label2.TabIndex = 9
Me.Label2.Text = "密码"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(15, 18)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 24)
Me.Label1.TabIndex = 8
Me.Label1.Text = "用户编号"
'
'BtCancel
'
Me.BtCancel.Location = New System.Drawing.Point(231, 327)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(95, 24)
Me.BtCancel.TabIndex = 7
Me.BtCancel.Text = "关闭"
'
'BtOK
'
Me.BtOK.Location = New System.Drawing.Point(78, 327)
Me.BtOK.Name = "BtOK"
Me.BtOK.Size = New System.Drawing.Size(92, 24)
Me.BtOK.TabIndex = 6
Me.BtOK.Text = "确定"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(216, 21)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(53, 12)
Me.Label3.TabIndex = 12
Me.Label3.Text = "用户姓名"
'
'TxtName
'
Me.TxtName.Location = New System.Drawing.Point(287, 15)
Me.TxtName.Name = "TxtName"
Me.TxtName.Size = New System.Drawing.Size(120, 21)
Me.TxtName.TabIndex = 13
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(233, 62)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 24)
Me.Label4.TabIndex = 14
Me.Label4.Text = "状态"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.ComboGeneral)
Me.GroupBox1.Controls.Add(Me.Label11)
Me.GroupBox1.Controls.Add(Me.ComboLib)
Me.GroupBox1.Controls.Add(Me.ComboAdmin)
Me.GroupBox1.Controls.Add(Me.Label6)
Me.GroupBox1.Controls.Add(Me.Label5)
Me.GroupBox1.Location = New System.Drawing.Point(11, 169)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(398, 146)
Me.GroupBox1.TabIndex = 16
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "权限设置"
'
'ComboGeneral
'
Me.ComboGeneral.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboGeneral.FormattingEnabled = True
Me.ComboGeneral.Items.AddRange(New Object() {"是", "否"})
Me.ComboGeneral.Location = New System.Drawing.Point(122, 103)
Me.ComboGeneral.Name = "ComboGeneral"
Me.ComboGeneral.Size = New System.Drawing.Size(252, 20)
Me.ComboGeneral.TabIndex = 5
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Location = New System.Drawing.Point(15, 106)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(89, 12)
Me.Label11.TabIndex = 4
Me.Label11.Text = "一般管理员权限"
'
'ComboLib
'
Me.ComboLib.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboLib.FormattingEnabled = True
Me.ComboLib.Items.AddRange(New Object() {"是", "否"})
Me.ComboLib.Location = New System.Drawing.Point(122, 65)
Me.ComboLib.Name = "ComboLib"
Me.ComboLib.Size = New System.Drawing.Size(252, 20)
Me.ComboLib.TabIndex = 3
'
'ComboAdmin
'
Me.ComboAdmin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboAdmin.FormattingEnabled = True
Me.ComboAdmin.Items.AddRange(New Object() {"是", "否"})
Me.ComboAdmin.Location = New System.Drawing.Point(120, 28)
Me.ComboAdmin.Name = "ComboAdmin"
Me.ComboAdmin.Size = New System.Drawing.Size(254, 20)
Me.ComboAdmin.TabIndex = 2
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(17, 68)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(89, 12)
Me.Label6.TabIndex = 1
Me.Label6.Text = "图书管理员权限"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(16, 31)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(89, 12)
Me.Label5.TabIndex = 0
Me.Label5.Text = "系统管理员权限"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(23, 100)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(48, 24)
Me.Label7.TabIndex = 17
Me.Label7.Text = "地址"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(233, 100)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(48, 24)
Me.Label8.TabIndex = 18
Me.Label8.Text = "电话"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(23, 135)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(48, 24)
Me.Label9.TabIndex = 19
Me.Label9.Text = "手机"
'
'Label10
'
Me.Label10.Location = New System.Drawing.Point(233, 135)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(48, 24)
Me.Label10.TabIndex = 20
Me.Label10.Text = "Email"
'
'TxtAddress
'
Me.TxtAddress.Location = New System.Drawing.Point(77, 97)
Me.TxtAddress.MaxLength = 10
Me.TxtAddress.Name = "TxtAddress"
Me.TxtAddress.Size = New System.Drawing.Size(120, 21)
Me.TxtAddress.TabIndex = 21
'
'TxtPhone
'
Me.TxtPhone.Location = New System.Drawing.Point(287, 97)
Me.TxtPhone.MaxLength = 10
Me.TxtPhone.Name = "TxtPhone"
Me.TxtPhone.Size = New System.Drawing.Size(120, 21)
Me.TxtPhone.TabIndex = 22
'
'TxtCellPhone
'
Me.TxtCellPhone.Location = New System.Drawing.Point(77, 132)
Me.TxtCellPhone.MaxLength = 10
Me.TxtCellPhone.Name = "TxtCellPhone"
Me.TxtCellPhone.Size = New System.Drawing.Size(120, 21)
Me.TxtCellPhone.TabIndex = 23
'
'TxtEmail
'
Me.TxtEmail.Location = New System.Drawing.Point(289, 135)
Me.TxtEmail.MaxLength = 10
Me.TxtEmail.Name = "TxtEmail"
Me.TxtEmail.Size = New System.Drawing.Size(120, 21)
Me.TxtEmail.TabIndex = 24
'
'ComboStatus
'
Me.ComboStatus.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboStatus.FormattingEnabled = True
Me.ComboStatus.Items.AddRange(New Object() {"正常", "冻结"})
Me.ComboStatus.Location = New System.Drawing.Point(287, 55)
Me.ComboStatus.Name = "ComboStatus"
Me.ComboStatus.Size = New System.Drawing.Size(120, 20)
Me.ComboStatus.TabIndex = 25
'
'frm_AddUser
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(419, 361)
Me.Controls.Add(Me.ComboStatus)
Me.Controls.Add(Me.TxtEmail)
Me.Controls.Add(Me.TxtCellPhone)
Me.Controls.Add(Me.TxtPhone)
Me.Controls.Add(Me.TxtAddress)
Me.Controls.Add(Me.Label10)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.TxtName)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TxtPassword)
Me.Controls.Add(Me.TxtUserID)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.BtCancel)
Me.Controls.Add(Me.BtOK)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frm_AddUser"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "添加用户信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
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
Sub addUser()
MyConnection.Open()
MyCommand = New OleDbCommand("Insert INTO SystemUsers VALUES('" & TxtUserID.Text & "','" & TxtName.Text & "','" & TxtPassword.Text & "','" & ComboStatus.Text & "','" & TxtAddress.Text & "','" & TxtPhone.Text & "','" & TxtCellPhone.Text & "','" & TxtEmail.Text & "','" & ComboAdmin.Text & "','" & ComboLib.Text & "','" & ComboGeneral.Text & "')", MyConnection)
MyCommand.ExecuteNonQuery()
MyConnection.Close()
MyCommand.Dispose()
End Sub
Function checkIfAlreadyExists() 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")
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 BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
If Trim(TxtUserID.Text) = "" Then
displayMsg("输入的用户编号不能为空!")
Exit Sub
End If
If Trim(TxtName.Text) = "" Then
displayMsg("输入的用户姓名不能为空!")
Exit Sub
End If
If Trim(TxtPassword.Text) = "" Then
displayMsg("输入的密码不能为空!")
Exit Sub
End If
If checkIfAlreadyExists() = True Then
displayMsg("用户编号已经存在请重新输入!")
Exit Sub
Else
addUser()
displayMsg("用户信息已被成功添加到数据库!")
End If
End Sub
Sub displayMsg(ByVal myMsgText As String)
MsgBox(myMsgText, MsgBoxStyle.Information, "图书管管理系统")
End Sub
Private Sub FrmAddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboAdmin.SelectedIndex = 0
ComboLib.SelectedIndex = 0
ComboGeneral.SelectedIndex = 0
ComboStatus.SelectedIndex = 0
End Sub
End Class
评论: 0 | 引用: 0 | 查看次数: 1845
发表评论
你没有权限发表留言!