📄 formxtgl.vb
字号:
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class FrmXTGL
Inherits System.Windows.Forms.Form
Private MyTag As String
Private Username As String
#Region " Windows 窗体设计器生成的代码 "
Public Sub New(ByVal myttag As Integer, ByVal Usn As String)
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
MyTag = myttag
Username = Usn
End Sub
'窗体重写 dispose 以清理组件列表。
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 ListView1 As System.Windows.Forms.ListView
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListView1 = New System.Windows.Forms.ListView
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.MultiSelect = False
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(360, 160)
Me.ListView1.TabIndex = 18
Me.ListView1.View = System.Windows.Forms.View.Details
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(224, 176)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(120, 20)
Me.ComboBox1.TabIndex = 26
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(64, 176)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(88, 21)
Me.TextBox1.TabIndex = 25
Me.TextBox1.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(160, 176)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 24)
Me.Label3.TabIndex = 24
Me.Label3.Text = "用户类型:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 216)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 23)
Me.Label2.TabIndex = 23
Me.Label2.Text = "口令:"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(232, 208)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 23)
Me.Button3.TabIndex = 22
Me.Button3.Text = "退出 "
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(160, 208)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 23)
Me.Button2.TabIndex = 21
Me.Button2.Text = "确认"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(63, 209)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(88, 21)
Me.TextBox2.TabIndex = 20
Me.TextBox2.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 176)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 21)
Me.Label1.TabIndex = 19
Me.Label1.Text = "用户名:"
'
'FrmXTGL
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(360, 238)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ListView1)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "FrmXTGL"
Me.Text = "系统管理"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetUser()
ComboBox1.Items.Add("普通用户")
ComboBox1.Items.Add("系统用户")
Button2.Enabled = False
If MyTag = 1 Then
Button2.Text = "添加"
Button2.Enabled = True
ElseIf MyTag = 2 Then
Label1.Visible = False
TextBox1.Visible = False
Label3.Visible = False
ComboBox1.Visible = False
Label2.Visible = False
TextBox2.Visible = False
Button2.Text = "删除"
ElseIf MyTag = 3 Then
TextBox1.ReadOnly = True
Button2.Text = "修改"
ElseIf MyTag = 4 Then
Label1.Visible = False
TextBox1.Visible = False
Label3.Visible = False
ComboBox1.Visible = False
Button2.Text = "修改"
End If
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim myIndex As Integer
If MyTag = 1 Then Exit Sub
If (ListView1.SelectedItems.Count > 0) Then
Me.TextBox1.Text = ListView1.SelectedItems(0).Text
If ListView1.SelectedItems(0).SubItems(1).Text = "系统用户" Then
ComboBox1.SelectedIndex = 1
Else
ComboBox1.SelectedIndex = 0
End If
Button2.Enabled = True
End If
End Sub
Private Sub GetUser()
Dim connstr As New String("provider=SQLOLEDB.1;User ID=sa;PassWord=110;Persist Security Info=false;Initial Catalog=wage;Data Source=.;")
Dim Cn As New OleDbConnection
Dim searchSql As String
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
searchSql = "select * from 用户信息表"
' 定义两个数据列
ListView1.Items.Clear()
ListView1.View = View.Details
ListView1.Columns.Add("用户名", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("用户类型", 100, HorizontalAlignment.Left)
Try
Cn.ConnectionString = connstr
Cn.Open()
cmd = New OleDbCommand(searchSql, Cn)
dr = cmd.ExecuteReader()
Dim i As Integer = 0
Do While dr.Read()
ListView1.Items.Add(dr.GetString(0))
If dr.GetInt32(2) = 1 Then
ListView1.Items(i).SubItems.Add("系统用户")
Else
ListView1.Items(i).SubItems.Add("普通用户")
End If
i = i + 1
Loop
dr.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Cn.Dispose()
cmd.Dispose()
End Sub
Private Function GetPsw(ByVal PassWord As String)
Dim connstr As New String("provider=SQLOLEDB.1;User ID=sa;PassWord=110;Persist Security Info=false;Initial Catalog=wage;Data Source=.;")
Dim Cn As New OleDbConnection
Dim searchSql As String
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
searchSql = "select * from 用户信息表 where 用户名='" & PassWord & "'"
Try
Cn.ConnectionString = connstr
Cn.Open()
cmd = New OleDbCommand(searchSql, Cn)
dr = cmd.ExecuteReader()
Do While dr.Read()
Return Trim(dr.GetString(1))
Loop
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim connstr As New String("provider=SQLOLEDB.1;User ID=sa;PassWord=110;Persist Security Info=false;Initial Catalog=wage;Data Source=.;")
Dim Cn As New OleDbConnection
Dim cmd As OleDbCommand
Dim SQLString As String
If TextBox1.Text = Username And MyTag = 2 Then
If MsgBox("如果删除自己的账户,将不能在使用本系统。", MsgBoxStyle.YesNo, "警告!") = MsgBoxResult.No Then Exit Sub
End If
Try
If MyTag = 1 Then
SQLString = "INSERT INTO 用户信息表 (用户名,用户密码,用户类型)" & _
" VALUES('" & TextBox1.Text & "'," & CInt(TextBox2.Text) & "," & _
ComboBox1.SelectedIndex & ")"
ElseIf MyTag = 2 Then
SQLString = "DELETE 用户信息表 WHERE 用户名='" & _
TextBox1.Text & "'"
ElseIf MyTag = 3 Then
SQLString = "UpDate 用户信息表 SET 用户密码='" & TextBox2.Text & _
"',用户类型=" & ComboBox1.SelectedIndex & " WHERE 用户名='" & _
TextBox1.Text & "'"
ElseIf MyTag = 4 Then
If TextBox1.Text = Username Then
SQLString = "UpDate 用户信息表 SET 用户密码='" & TextBox2.Text & _
"' WHERE 用户名='" & TextBox1.Text & "'"
Else
MsgBox("您无权修改别人的密码!")
Button2.Enabled = False
Exit Sub
End If
End If
Cn.ConnectionString = connstr
Cn.Open()
cmd = New OleDbCommand(SQLString, Cn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
cmd.Dispose()
Cn.Dispose()
Button2.Enabled = False
GetUser()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -