📄 frm_user.vb
字号:
Public Class Frm_User
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
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 Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Button5 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.GroupBox1.SuspendLayout()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(19, 22)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "添加用户"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(107, 22)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 0
Me.Button2.Text = "删除用户"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(195, 22)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 0
Me.Button3.Text = "刷新"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(432, 22)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 0
Me.Button4.Text = "退出"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(18, 70)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 23)
Me.Label1.TabIndex = 1
Me.Label1.Text = "查询条件:"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(432, 64)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 0
Me.Button5.Text = "查询"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(218, 70)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 23)
Me.Label2.TabIndex = 1
Me.Label2.Text = "查询数值:"
'
'GroupBox1
'
Me.GroupBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.GroupBox1.Controls.Add(Me.ComboBox1)
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Button4)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.Button3)
Me.GroupBox1.Controls.Add(Me.Button5)
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(520, 96)
Me.GroupBox1.TabIndex = 3
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "基本操作"
'
'DataGrid1
'
Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(4, 96)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.ReadOnly = True
Me.DataGrid1.Size = New System.Drawing.Size(512, 248)
Me.DataGrid1.TabIndex = 4
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(287, 67)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Items.AddRange(New Object() {"用户名", "姓名"})
Me.ComboBox1.Location = New System.Drawing.Point(95, 67)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(105, 20)
Me.ComboBox1.TabIndex = 3
'
'Frm_User
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(520, 350)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.GroupBox1)
Me.Name = "Frm_User"
Me.Text = "用户管理"
Me.GroupBox1.ResumeLayout(False)
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private db As New DataBase
'加载
Private Sub Frm_User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sqlstr As String
sqlstr = "select * from 用户表"
Dim ds As New DataSet
ds = db.RunSelectDataSet(sqlstr)
'定义一个DataGrid表的样式
Dim MyTable As New DataGridTableStyle
'设置DataGrid1中奇数行的背景颜色
MyTable.AlternatingBackColor = Color.LightGray
'不允许单击列标头对网格进行重新排序
MyTable.AllowSorting = False
'将表样式MyTable添加到DataGrid1中
DataGrid1.TableStyles.Add(MyTable)
MyTable.MappingName = ds.Tables(0).TableName
DataGrid1.DataSource = ds.Tables(0)
End Sub
'添加用户
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Frm_AddUser
frm.ShowDialog()
End Sub
'删除用户
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim frm As New Frm_DelUser
frm.ShowDialog()
End Sub
'刷新
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim sqlstr As String
sqlstr = "select * from 用户表"
db.Open()
DataGrid1.DataSource = db.RunSelectSQL(sqlstr)
db.Close()
End Sub
'退出
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
'查询
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim str1, str2 As String
str1 = Trim(ComboBox1.Text)
str2 = Trim(TextBox1.Text)
If str1 = "" Then
MessageBox.Show("请选择查询条件!", "提示", MessageBoxButtons.OK)
Exit Sub
End If
If str2 = "" Then
MessageBox.Show("请输入要查询的相关数值!", "提示", MessageBoxButtons.OK)
Exit Sub
End If
Try
Dim sqlstr As String
Dim dv As New DataView
sqlstr = "select * from 用户表 where " & ComboBox1.Text & " like '%" & TextBox1.Text & "%'"
db.Open()
dv = db.RunSelectSQL(sqlstr)
If dv.Count() <> 0 Then
DataGrid1.DataSource = dv
Else
MessageBox.Show("没有您要查找的记录?", "提示", MessageBoxButtons.OK)
End If
db.Close()
Catch ex As Exception
MessageBox.Show("没有您要查找的记录?", "提示", MessageBoxButtons.OK)
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -