📄 部门查询.vb
字号:
Public Class FrmDepartment
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 ImageList1 As System.Windows.Forms.ImageList
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
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents ListView1 As System.Windows.Forms.ListView
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 部门负责人 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
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.部门负责人 = New System.Windows.Forms.ColumnHeader
Me.部门编号 = New System.Windows.Forms.ColumnHeader
Me.部门 = New System.Windows.Forms.ColumnHeader
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.备注 = New System.Windows.Forms.ColumnHeader
Me.联系电话 = New System.Windows.Forms.ColumnHeader
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 = New System.Windows.Forms.GroupBox
Me.ListView1 = New System.Windows.Forms.ListView
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.GroupBox2.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'部门负责人
'
Me.部门负责人.Text = "部门负责人"
Me.部门负责人.Width = 120
'
'部门编号
'
Me.部门编号.Text = "部门编号"
Me.部门编号.Width = 90
'
'部门
'
Me.部门.Text = "部门"
Me.部门.Width = 100
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'备注
'
Me.备注.Text = "备注"
Me.备注.Width = 130
'
'联系电话
'
Me.联系电话.Text = "联系电话"
Me.联系电话.Width = 120
'
'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 = 10
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
'
'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 = 6
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.Location = New System.Drawing.Point(3, 17)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(554, 268)
Me.ListView1.SmallImageList = Me.ImageList1
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View.Details
'
'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 = 9
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 = 8
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 = 7
Me.Button1.Text = "添加"
Me.Button1.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'FrmDepartment
'
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.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Name = "FrmDepartment"
Me.Opacity = 0.9
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "部门查询"
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub FrmDepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
sql.DBToDS("select * from VW_depar", ds, "VW_depar")
App(ds, "VW_depar")
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 Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim dsAPP As New DataSet
sql.DBToDS("select * from VW_depar", dsAPP, "VW_depar")
App(dsAPP, "VW_depar")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frmadd As New FrmAddDep
frmadd.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
DepItem = ListView1.Items(ListView1.SelectedIndices(0))
Catch ex As Exception
MsgBox("还未先择要修改的部门信息!")
Exit Sub
End Try
Dim frmupdate As New FrmUpdateDep
frmupdate.ShowDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
DepItem = ListView1.Items(ListView1.SelectedIndices(0))
Catch ex As Exception
MsgBox("还未先择要删除的部门信息!")
Exit Sub
End Try
Try
Dim cmd As New SqlClient.SqlCommand
cmd.CommandText = "up_DeleteDep"
cmd.Parameters.Add("@Number", SqlDbType.NVarChar).Value = DepItem.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
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Clear()
Dim dsId As New DataSet
Select Case ComboBox1.Text
Case "部门编号"
sql.DBToDS("select * from VW_depar", dsId, "Dep1")
Dim i As Integer = 0
For i = 0 To dsId.Tables("Dep1").Rows.Count - 1
ComboBox2.Items.Add(dsId.Tables("Dep1").Rows(i)(0))
Next
Case "部门名称"
sql.DBToDS("select * from VW_depar", dsId, "Dep2")
Dim i As Integer = 0
For i = 0 To dsId.Tables("Dep2").Rows.Count - 1
ComboBox2.Items.Add(dsId.Tables("Dep2").Rows(i)(1))
Next
Case "负责人"
sql.DBToDS("select * from VW_depar", dsId, "Dep3")
Dim i As Integer = 0
For i = 0 To dsId.Tables("Dep3").Rows.Count - 1
ComboBox2.Items.Add(dsId.Tables("Dep3").Rows(i)(2))
Next
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 dsid As New DataSet
sql.DBToDS("select * from VW_depar where [Dep_number]='" & ComboBox2.Text & "'", dsid, "dep1")
App(dsid, "dep1")
Case "部门名称"
Dim dsName As New DataSet
sql.DBToDS("select * from VW_depar where [Dep_name]='" & ComboBox2.Text & "'", dsName, "dep2")
App(dsName, "dep2")
Case "负责人"
Dim DsC As New DataSet
sql.DBToDS("select * from VW_depar where [Tea_Name]='" & ComboBox2.Text & "'", DsC, "dep3")
App(DsC, "dep3")
End Select
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -