form5.vb
来自「学生信息管理系统」· VB 代码 · 共 675 行 · 第 1/2 页
VB
675 行
'Button8
'
Me.Button8.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button8.Location = New System.Drawing.Point(216, 56)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(80, 32)
Me.Button8.TabIndex = 3
Me.Button8.Text = "退出"
'
'GroupBox3
'
Me.GroupBox3.Controls.Add(Me.DataGrid1)
Me.GroupBox3.Location = New System.Drawing.Point(16, 96)
Me.GroupBox3.Name = "GroupBox3"
Me.GroupBox3.Size = New System.Drawing.Size(328, 120)
Me.GroupBox3.TabIndex = 2
Me.GroupBox3.TabStop = False
Me.GroupBox3.Text = "查询结果"
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataView1
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 24)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(312, 88)
Me.DataGrid1.TabIndex = 0
'
'ComboBox4
'
Me.ComboBox4.Location = New System.Drawing.Point(40, 56)
Me.ComboBox4.Name = "ComboBox4"
Me.ComboBox4.Size = New System.Drawing.Size(121, 20)
Me.ComboBox4.TabIndex = 1
'
'Label7
'
Me.Label7.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label7.Location = New System.Drawing.Point(32, 16)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(152, 24)
Me.Label7.TabIndex = 0
Me.Label7.Text = "请选择班主任姓名:"
'
'Button7
'
Me.Button7.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button7.Location = New System.Drawing.Point(216, 8)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(80, 32)
Me.Button7.TabIndex = 1
Me.Button7.Text = "查询"
'
'Form5
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(408, 305)
Me.Controls.Add(Me.TabControl1)
Me.Name = "Form5"
Me.Text = "班级管理系统"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.TabPage3.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.TabPage4.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataView1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage2.Show()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage3.Show()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage4.Show()
End Sub
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'删除班级
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 班级"
Class1.ada.Fill(Class1.ds, "C")
Dim i As Integer
For i = 0 To Class1.ds.Tables("C").Rows.Count - 1
ComboBox2.Items.Add(Class1.ds.Tables("C").Rows.Item(i).Item("班级号"))
Next
'修改班级资料
Dim j As Integer
For j = 0 To Class1.ds.Tables("C").Rows.Count - 1
ComboBox3.Items.Add(Class1.ds.Tables("C").Rows.Item(j).Item("班级号"))
Next
'查询班级资料
Class1.ada.SelectCommand.CommandText = "select distinct 班主任 from 班级"
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
Dim l As Integer
For l = 0 To Class1.ds.Tables("C").Rows.Count - 1
ComboBox4.Items.Add(Class1.ds.Tables("C").Rows.Item(l).Item("班主任"))
Next
DataView1.Table = Class1.ds.Tables("C")
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
'添加班级
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 班级"
Class1.ada.Fill(Class1.ds, "C")
Class1.ada.SelectCommand.CommandText = "select * from 班级 where 班级号='" & ComboBox1.Text & "'"
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
If Class1.ds.Tables("C").Rows.Count = 0 Then
If ComboBox1.Text <> "" And TextBox1.Text <> "" Then
Class1.ada.InsertCommand.CommandText = "insert into 班级 values('" & ComboBox1.Text & "','" & TextBox1.Text _
& "')"
Class1.con.Open()
Class1.ada.InsertCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
MsgBox("您已成功添加!")
ComboBox1.Text = ""
TextBox1.Clear()
Else
MsgBox("请您填写完整!")
TextBox1.Clear()
End If
Else
MsgBox("这个班级已经存在!")
ComboBox1.Text = ""
TextBox1.Clear()
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'删除班级
Class1.ada.SelectCommand.CommandText = "select * from 班级 where 班级号='" & ComboBox2.Text & "'"
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
If Class1.ds.Tables("C").Rows.Count <> 0 Then
If ComboBox2.Text <> "" Then
Class1.ada.DeleteCommand.CommandText = "delete from 班级 where 班级号='" & ComboBox2.Text & "'"
Class1.con.Open()
Class1.ada.DeleteCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
'删除相应班级中的学生成绩
If Not Class1.ds.Tables("B") Is Nothing Then
Class1.ds.Tables("B").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 学生 where 班级='" & ComboBox2.Text & "'"
Class1.ada.Fill(Class1.ds, "B")
If Not Class1.ds.Tables("E") Is Nothing Then
Class1.ds.Tables("E").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 考试成绩"
Class1.ada.Fill(Class1.ds, "E")
Dim i As Integer
For i = 0 To Class1.ds.Tables("B").Rows.Count - 1
Class1.ada.DeleteCommand.CommandText = "delete from 考试成绩 where 学号='" & Class1.ds.Tables("B").Rows.Item(i).Item("学号") & "'"
Class1.con.Open()
Class1.ada.DeleteCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("E") Is Nothing Then
Class1.ds.Tables("E").Clear()
End If
Class1.ada.Fill(Class1.ds, "E")
Next
'删除相应班级中的学生
Class1.ada.DeleteCommand.CommandText = "delete from 学生 where 班级='" & ComboBox2.Text & "' "
Class1.con.Open()
Class1.ada.DeleteCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("B") Is Nothing Then
Class1.ds.Tables("b").Clear()
End If
Class1.ada.Fill(Class1.ds, "B")
'删除为该班级所设的课程
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.DeleteCommand.CommandText = "select * from 所有课程"
Class1.ada.Fill(Class1.ds, "D")
Class1.ada.DeleteCommand.CommandText = "delete from 所有课程 where 开课班级='" & ComboBox2.Text & "'"
Class1.con.Open()
Class1.ada.DeleteCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
MsgBox("您已成功删除!")
ComboBox2.Text = ""
Else
MsgBox("请选择一个班级!")
End If
Else
MsgBox("这个学生不存在,您不能删除!")
ComboBox2.Text = ""
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'修改班级资料
Class1.ada.SelectCommand.CommandText = "select * from 班级 where 班级号='" & ComboBox3.Text & "'"
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
If Class1.ds.Tables("C").Rows.Count <> 0 Then
Class1.ada.SelectCommand.CommandText = "select * from 班级 where 班级号='" & ComboBox5.Text & "'"
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.Fill(Class1.ds, "C")
If Class1.ds.Tables("C").Rows.Count = 0 Then
If ComboBox3.Text <> "" And ComboBox5.Text <> "" And TextBox3.Text <> "" Then
Class1.ada.UpdateCommand.CommandText = "update 班级 set 班级号='" & ComboBox5.Text & "',班主任='" & _
TextBox3.Text & "' where 班级号='" & ComboBox3.Text & "'"
Class1.con.Open()
Class1.ada.UpdateCommand.ExecuteNonQuery()
Class1.con.Close()
Class1.ada.Fill(Class1.ds, "C")
'修改学生的相应班级
If Not Class1.ds.Tables("B") Is Nothing Then
Class1.ds.Tables("B").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 学生 "
Class1.ada.Fill(Class1.ds, "B")
Class1.ada.UpdateCommand.CommandText = "update 学生 set 班级='" & ComboBox5.Text & "' where 班级='" & ComboBox3.Text & "'"
Class1.con.Open()
Class1.ada.UpdateCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("B") Is Nothing Then
Class1.ds.Tables("B").Clear()
End If
Class1.ada.Fill(Class1.ds, "B")
'修改课程中的相应开课班级
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 所有课程"
Class1.ada.Fill(Class1.ds, "D")
Class1.ada.UpdateCommand.CommandText = "update 所有课程 set 开课班级='" & ComboBox5.Text & "' where 开课班级='" & ComboBox3.Text & "'"
Class1.con.Open()
Class1.ada.UpdateCommand.ExecuteNonQuery()
Class1.con.Close()
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
MsgBox("恭喜您修改成功!")
ComboBox3.Text = ""
ComboBox5.Text = ""
TextBox3.Clear()
Else
MsgBox("请填写完整!")
End If
Else
MsgBox("这个班级号已在使用中,您不能修改成为这个号码!")
ComboBox3.Text = ""
ComboBox5.Text = ""
TextBox3.Clear()
End If
Else
MsgBox("这个班级不存在,您无法修改资料!")
ComboBox3.Text = ""
ComboBox5.Text = ""
TextBox3.Clear()
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
'查询班级资料
If Not Class1.ds.Tables("C") Is Nothing Then
Class1.ds.Tables("C").Clear()
End If
Class1.ada.SelectCommand.CommandText = "select * from 班级"
Class1.ada.Fill(Class1.ds, "C")
DataView1.RowFilter = "班主任='" & ComboBox4.Text & "'"
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage1.Show()
End Sub
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?