📄 查询教师.vb
字号:
Public Class FrmTeacher
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 GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents 教师编号 As System.Windows.Forms.ColumnHeader
Friend WithEvents 教师姓名 As System.Windows.Forms.ColumnHeader
Friend WithEvents 姓别 As System.Windows.Forms.ColumnHeader
Friend WithEvents 所属科室 As System.Windows.Forms.ColumnHeader
Friend WithEvents 职称 As System.Windows.Forms.ColumnHeader
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button5 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.ListView1 = New System.Windows.Forms.ListView
Me.教师编号 = New System.Windows.Forms.ColumnHeader
Me.教师姓名 = New System.Windows.Forms.ColumnHeader
Me.姓别 = New System.Windows.Forms.ColumnHeader
Me.所属科室 = New System.Windows.Forms.ColumnHeader
Me.职称 = New System.Windows.Forms.ColumnHeader
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.Button4 = New System.Windows.Forms.Button
Me.ComboBox2 = New System.Windows.Forms.ComboBox
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button5 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.ListView1)
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(560, 288)
Me.GroupBox1.TabIndex = 11
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "教师信息"
'
'ListView1
'
Me.ListView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.教师编号, Me.教师姓名, Me.姓别, Me.所属科室, Me.职称})
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable
Me.ListView1.HideSelection = False
Me.ListView1.ImeMode = System.Windows.Forms.ImeMode.On
Me.ListView1.Location = New System.Drawing.Point(3, 17)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(554, 268)
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View.Details
'
'教师编号
'
Me.教师编号.Text = "教师编号"
Me.教师编号.Width = 90
'
'教师姓名
'
Me.教师姓名.Text = "教师姓名"
Me.教师姓名.Width = 100
'
'姓别
'
Me.姓别.Text = "姓别"
Me.姓别.Width = 120
'
'所属科室
'
Me.所属科室.Text = "所属科室"
Me.所属科室.Width = 120
'
'职称
'
Me.职称.Text = "职称"
Me.职称.Width = 130
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.WhiteSmoke
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.Location = New System.Drawing.Point(488, 384)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 14
Me.Button3.Text = "删除"
Me.Button3.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.WhiteSmoke
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.Location = New System.Drawing.Point(488, 344)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 13
Me.Button2.Text = "修改"
Me.Button2.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.WhiteSmoke
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.Location = New System.Drawing.Point(488, 304)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 12
Me.Button1.Text = "添加"
Me.Button1.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.Button4)
Me.GroupBox2.Controls.Add(Me.ComboBox2)
Me.GroupBox2.Controls.Add(Me.ComboBox1)
Me.GroupBox2.Controls.Add(Me.Label1)
Me.GroupBox2.Controls.Add(Me.Label2)
Me.GroupBox2.Controls.Add(Me.Button5)
Me.GroupBox2.Location = New System.Drawing.Point(8, 304)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(464, 80)
Me.GroupBox2.TabIndex = 15
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "信息查询"
'
'Button4
'
Me.Button4.BackColor = System.Drawing.Color.WhiteSmoke
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button4.Location = New System.Drawing.Point(384, 48)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 3
Me.Button4.Text = "查询"
Me.Button4.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'ComboBox2
'
Me.ComboBox2.Location = New System.Drawing.Point(280, 19)
Me.ComboBox2.Name = "ComboBox2"
Me.ComboBox2.Size = New System.Drawing.Size(121, 20)
Me.ComboBox2.TabIndex = 2
'
'ComboBox1
'
Me.ComboBox1.Items.AddRange(New Object() {"所属院系", "所属科室", "教师编号", "教师姓名"})
Me.ComboBox1.Location = New System.Drawing.Point(70, 20)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 1
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(60, 17)
Me.Label1.TabIndex = 0
Me.Label1.Text = "查询类型:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(216, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(60, 17)
Me.Label2.TabIndex = 0
Me.Label2.Text = "查询条件:"
'
'Button5
'
Me.Button5.BackColor = System.Drawing.Color.WhiteSmoke
Me.Button5.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button5.Location = New System.Drawing.Point(296, 48)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 3
Me.Button5.Text = "所有信息"
Me.Button5.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'FrmTeacher
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.SystemColors.InactiveCaptionText
Me.ClientSize = New System.Drawing.Size(576, 414)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.GroupBox2)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Name = "FrmTeacher"
Me.Opacity = 0.9
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "查询教师"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub FrmTeacher_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
sql.DBToDS("select * from VW_Teacher", ds, "VW_Teacher")
App(ds, "VW_Teacher")
End Sub
Public Sub App(ByVal ds As DataSet, ByVal str As String)
Dim i As Integer = 0
ListView1.Items.Clear()
Dim item As New ListViewItem
For i = 0 To ds.Tables(str).Rows.Count - 1
item = ListView1.Items.Add(ds.Tables(str).Rows(i)(0))
item.SubItems.Add(ds.Tables(str).Rows(i)(1))
item.SubItems.Add(ds.Tables(str).Rows(i)(2))
item.SubItems.Add(ds.Tables(str).Rows(i)(3))
item.SubItems.Add(ds.Tables(str).Rows(i)(4))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frmadd As New FrmAddTeacher
frmadd.ShowDialog()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim ds As New DataSet
sql.DBToDS("select * from VW_Teacher", ds, "Teacher")
App(ds, "Teacher")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Text = ""
ComboBox2.Items.Clear()
Select Case ComboBox1.Text
Case "所属院系"
sql.SQLDataReader("select * from Department")
While sql.SQLDR.Read
ComboBox2.Items.Add(sql.SQLDR.GetValue(1))
End While
sql.SQLDR.Close()
Case "所属科室"
sql.SQLDataReader("select * from SectionDepartment")
While sql.SQLDR.Read
ComboBox2.Items.Add(sql.SQLDR.GetValue(1))
End While
sql.SQLDR.Close()
Case "教师编号"
sql.SQLDataReader("select * from Teacher")
While sql.SQLDR.Read
ComboBox2.Items.Add(sql.SQLDR.GetValue(0))
End While
sql.SQLDR.Close()
Case "教师姓名"
sql.SQLDataReader("select * from Teacher")
While sql.SQLDR.Read
ComboBox2.Items.Add(sql.SQLDR.GetValue(1))
End While
sql.SQLDR.Close()
End Select
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Select Case ComboBox1.Text
Case "所属院系"
Dim ds As New DataSet
sql.DBToDS("select * from VW_Teacher where Dep_Name='" & ComboBox2.Text & "'", ds, "VW_teacher1")
App(ds, "VW_teacher1")
Case "所属科室"
Dim ds1 As New DataSet
sql.DBToDS("select * from VW_Teacher where SD_Name='" & ComboBox2.Text & "'", ds1, "VW_teacher2")
App(ds1, "VW_teacher2")
Case "教师编号"
Dim ds2 As New DataSet
sql.DBToDS("select * from VW_Teacher where Tea_Number='" & ComboBox2.Text & "'", ds2, "VW_teacher3")
App(ds2, "VW_teacher3")
Case "教师姓名"
Dim ds3 As New DataSet
sql.DBToDS("select * from VW_Teacher where Tea_Name='" & ComboBox2.Text & "'", ds3, "VW_teacher4")
App(ds3, "VW_teacher4")
End Select
End Sub
Dim Teaitem As New ListViewItem
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Teaitem = ListView1.Items(ListView1.SelectedIndices(0))
Catch ex As Exception
MsgBox("还未先择要删除的教师信息!")
Exit Sub
End Try
Try
Dim cmd As New SqlClient.SqlCommand
cmd.CommandText = "up_DeleteTeacher"
cmd.Parameters.Add("@Number", SqlDbType.NVarChar).Value = Teaitem.Text
If sql.SP_SQLCommand(cmd) > 0 Then
MsgBox("删除成功!")
Else
MsgBox("删除失败!")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -