⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 班级管理.vb

📁 Here we are at the crossroads once again Youre telling me youre so confused You cant make up your
💻 VB
字号:
Public Class Form1
    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 备注 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    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 GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        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.备注 = New System.Windows.Forms.ColumnHeader
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = 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 = 1
        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.备注})
        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
        '
        '班级编号
        '
        Me.班级编号.Text = "班级编号"
        Me.班级编号.Width = 90
        '
        '班级
        '
        Me.班级.Text = "班级"
        Me.班级.Width = 100
        '
        '所属院系
        '
        Me.所属院系.Text = "所属院系"
        Me.所属院系.Width = 120
        '
        '人数
        '
        Me.人数.Text = "人数"
        '
        '班导
        '
        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
        '
        '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 = 2
        Me.Button1.Text = "添加"
        Me.Button1.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 = 3
        Me.Button2.Text = "修改"
        Me.Button2.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        '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 = 4
        Me.Button3.Text = "删除"
        Me.Button3.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 = 5
        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
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.InactiveCaptionText
        Me.ClientSize = New System.Drawing.Size(574, 436)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Name = "Form1"
        Me.Opacity = 0.96
        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 Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet
        sql.DBToDS("select * from VW_Class", ds, "Class")
    
        App(ds, "class")
    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))
            item.SubItems.Add(ds.Tables(str).Rows(i)(5))
        Next
    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_Class", dsId, "ClassID")
                Dim i As Integer = 0
                For i = 0 To dsId.Tables("classid").Rows.Count - 1
                    ComboBox2.Items.Add(dsId.Tables("classid").Rows(i)(0))
                Next
            Case "班级"
                sql.DBToDS("select * from VW_Class", dsId, "ClassName")
                Dim i As Integer = 0
                For i = 0 To dsId.Tables("classname").Rows.Count - 1
                    ComboBox2.Items.Add(dsId.Tables("classname").Rows(i)(1))
                Next
            Case "班导"
                sql.DBToDS("select * from VW_Class", dsId, "Classt")
                Dim i As Integer = 0
                For i = 0 To dsId.Tables("classt").Rows.Count - 1
                    ComboBox2.Items.Add(dsId.Tables("classt").Rows(i)(4))
                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_Class where [Class_ID]='" & ComboBox2.Text & "'", dsid, "Class1")
                App(dsid, "class1")

            Case "班级"
                Dim dsName As New DataSet
                sql.DBToDS("select * from VW_Class where [Class_Name]='" & ComboBox2.Text & "'", dsName, "Class2")
                App(dsName, "class2")

            Case "班导"
                Dim DsC As New DataSet
                sql.DBToDS("select * from VW_Class where [Tea_Name]='" & ComboBox2.Text & "'", DsC, "Class3")
                App(DsC, "Class3")
        End Select
    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_Class", ds, "Class")
        App(ds, "class")
    End Sub

    Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frmadd As New FrmAddClass
        frmadd.ShowDialog()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Classitem = ListView1.Items(ListView1.SelectedIndices(0))
        Catch ex As Exception
            MsgBox("还未先择要修改的班级信息!")
            Exit Sub
        End Try

            Dim frmupdate As New frmUpdateClass
            frmupdate.ShowDialog()


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Classitem = ListView1.Items(ListView1.SelectedIndices(0))
        Catch ex As Exception
            MsgBox("还未先择要删除的班级信息!")
            Exit Sub
        End Try
        Try
            Dim cmd As New SqlClient.SqlCommand
            cmd.CommandText = "up_deleteClass"
            cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = Classitem.Text
            If sql.SP_SQLCommand(cmd) > 0 Then
                MsgBox("删除成功!")
            Else
                MsgBox("删除失败!")
            End If
            Dim dsdelete As New DataSet
            sql.DBToDS("select * from VW_Class", dsdelete, "Class")
            App(dsdelete, "class")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -