📄 form9.vb
字号:
Dim l As Integer
For l = 0 To Class1.ds.Tables("D").Rows.Count - 1
ComboBox8.Items.Add(Class1.ds.Tables("D").Rows.Item(l).Item("课程号码"))
Next
Class1.ada.SelectCommand.CommandText = "select distinct 课程名称 from 所有课程"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
Dim s As Integer
For s = 0 To Class1.ds.Tables("D").Rows.Count - 1
ComboBox9.Items.Add(Class1.ds.Tables("D").Rows.Item(s).Item("课程名称"))
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'添加一个新课程
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.SelectCommand.CommandText = "select * from 所有课程 where 课程号码='" & ComboBox1.Text & "' or 课程名称='" & TextBox1.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count = 0 Then
If ComboBox1.Text <> "" And ComboBox2.Text <> "" And TextBox1.Text <> "" And TextBox2.Text <> "" Then
Class1.ada.InsertCommand.CommandText = "insert into 所有课程 values('" & ComboBox1.Text & "','" & _
TextBox1.Text & "','" & TextBox2.Text & "','" & ComboBox2.Text & "')"
Class1.con.Open()
Class1.ada.InsertCommand.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("添加成功!")
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Clear()
TextBox2.Clear()
Else
MsgBox("请填写完整!")
End If
Else
MsgBox("这个课程已经存在,您不能再添加!")
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Clear()
TextBox2.Clear()
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("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count <> 0 Then
If ComboBox3.Text <> "" Then
'删除有关这个课程的所有成绩
Class1.ada.SelectCommand.CommandText = "select * from 所有课程 where 课程号码='" & ComboBox3.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
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")
Class1.ada.DeleteCommand.CommandText = "delete from 考试成绩 where 课程名称='" & Class1.ds.Tables("D").Rows.Item(0).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")
'删除课程
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.DeleteCommand.CommandText = "delete from 所有课程 where 课程号码='" & ComboBox3.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("删除成功!")
ComboBox3.Text = ""
Else
MsgBox("请选择要删除的课程!")
End If
Else
MsgBox("对不起,您要删除的课程不存在!")
ComboBox3.Text = ""
End If
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 MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage1.Show()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage2.Show()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage3.Show()
End Sub
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage4.Show()
End Sub
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TabPage5.Show()
End Sub
Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'修改课程资料
Class1.ada.SelectCommand.CommandText = "select * from 所有课程 where 课程号码='" & ComboBox4.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count <> 0 Then
If TextBox3.Text <> "" Then
Class1.ada.SelectCommand.CommandText = "select * from 所有课程 where 课程名称='" & TextBox3.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count = 0 Then
'修改成绩中的相应课程
Class1.ada.SelectCommand.CommandText = "select * from 所有课程 where 课程号码='" & ComboBox4.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
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")
Class1.ada.UpdateCommand.CommandText = "update 考试成绩 set 课程名称='" & TextBox3.Text & "' where 课程名称='" & Class1.ds.Tables("D").Rows.Item(0).Item("课程名称") & "'"
Class1.con.Open()
Class1.ada.UpdateCommand.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")
'修改课程资料
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 课程名称='" & TextBox3.Text & "' where 课程号码='" & ComboBox4.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("修改成功!")
ComboBox4.Text = ""
TextBox3.Clear()
Else
MsgBox("这个课程名称已经在使用中,您的修改无效!")
ComboBox4.Text = ""
TextBox3.Clear()
End If
Else
MsgBox("请填写完整!")
End If
Else
MsgBox("您所要修改的的课程号码不存在!")
ComboBox4.Text = ""
TextBox3.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 Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
'查询班级
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")
DataView2.Sort = "开课班级"
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
'设置某个班级所上的课程
Class1.ada.SelectCommand.CommandText = "select * from 班级 where 班级号='" & ComboBox7.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 课程号码='" & ComboBox8.Text & "' and 课程名称='" & ComboBox9.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count <> 0 Then
Class1.ada.SelectCommand.CommandText = "select * from 所有课程 where 课程号码='" & ComboBox8.Text & "' and 课程名称='" & ComboBox9.Text & "' and 开课班级='" & ComboBox7.Text & "'"
If Not Class1.ds.Tables("D") Is Nothing Then
Class1.ds.Tables("D").Clear()
End If
Class1.ada.Fill(Class1.ds, "D")
If Class1.ds.Tables("D").Rows.Count = 0 Then
Class1.ada.InsertCommand.CommandText = "insert into 所有课程 values('" & ComboBox8.Text & "','" & ComboBox9.Text & "','" & TextBox5.Text & "','" & ComboBox7.Text & "')"
Class1.con.Open()
Class1.ada.InsertCommand.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("设置成功!")
ComboBox7.Text = ""
ComboBox8.Text = ""
ComboBox9.Text = ""
TextBox5.Clear()
Else
MsgBox("这条记录已经存在,您不能再为这个班级设这个课程!")
ComboBox7.Text = ""
ComboBox8.Text = ""
ComboBox9.Text = ""
TextBox5.Clear()
End If
Else
MsgBox("课程号码与课程名称不符!")
ComboBox7.Text = ""
ComboBox8.Text = ""
ComboBox9.Text = ""
TextBox5.Clear()
End If
Else
MsgBox("这个班级不存在!")
ComboBox7.Text = ""
ComboBox8.Text = ""
ComboBox9.Text = ""
TextBox5.Clear()
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -