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

📄 adminmanagestudentform.vb

📁 管理毕业设计的管理系统 VB+SQL2000....
💻 VB
字号:
Public Class AdminManageStudentForm

    Private isComboFirstChoose = True

    Private Sub UpdateInfo(ByVal table As DataTable, ByVal index As Integer)
        TextUser.Text = table.Rows(index)("suser")
        TextKey.Text = table.Rows(index)("skey")
        TextName.Text = table.Rows(index)("sname")
        TextEmail.Text = table.Rows(index)("semail")
        TextDirection.Text = table.Rows(index)("sdirection")
        TextQq.Text = table.Rows(index)("sqq")
        TextQqgroup.Text = table.Rows(index)("sqqgroup")

        Dim strTeacherName As String = table.Rows(index)("tname")
        Dim i As Integer = 0

        For i = 1 To ComboTeacherName.Items.Count
            If ComboTeacherName.Items(i) = strTeacherName Then
                ComboTeacherName.SelectedIndex = i
                Exit For
            End If
        Next
    End Sub

    Private Sub AdminManageStudentForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListStudentName.Items.Clear()
        ListStudentName.Items.Add("添加新同学...")
        Dim strSQL As String = "select sname from student order by suser"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow

        For Each UserRow In UserTable.Rows
            ListStudentName.Items.Add(UserRow("sname"))
        Next
        ListStudentName.SelectedIndex = 0

        ComboTeacherName.Items.Clear()
        ComboTeacherName.Items.Add("请选择...")
        strSQL = "select tname from teacher"
        UserTable = DBOperation.Search(strSQL)

        For Each UserRow In UserTable.Rows
            ComboTeacherName.Items.Add(UserRow("tname"))
        Next
        ComboTeacherName.SelectedIndex = 0
    End Sub

    Private Sub ListStudentName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListStudentName.SelectedIndexChanged
        If ListStudentName.SelectedIndex = 0 Then
            ButtonInsert.Enabled = True
            ButtonUpdate.Enabled = False
            ButtonDelete.Enabled = False
            TextKey.Enabled = True
            TextUser.Text = ""
            TextKey.Text = "123456"
            TextName.Text = ""
            TextEmail.Text = ""
            TextDirection.Text = ""
            TextQq.Text = ""
            TextQqgroup.Text = ""

            If isComboFirstChoose Then
                ComboTeacherName.SelectedIndex = -1
                isComboFirstChoose = False
            Else
                ComboTeacherName.SelectedIndex = 0
            End If
        Else
            ButtonInsert.Enabled = False
            ButtonUpdate.Enabled = True
            ButtonDelete.Enabled = True
            TextKey.Enabled = False

            Dim strListName As String = ListStudentName.SelectedItem().ToString
            Dim strSQL As String = "select * from student s, teacher t where s.tid=t.tid and s.sname='" + strListName + "'"
            Dim UserTable As DataTable = DBOperation.Search(strSQL)
            UpdateInfo(UserTable, 0)
        End If
    End Sub

    Private Sub ButtonInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonInsert.Click
        If TextUser.Text.Trim() = "" Then
            MsgBox("请输入学号!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextKey.Text.Trim() = "" Then
            MsgBox("请输入密码!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextName.Text.Trim() = "" Then
            MsgBox("请输入姓名!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextEmail.Text.Trim() = "" Then
            MsgBox("请输入邮箱!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextDirection.Text.Trim() = "" Then
            MsgBox("请输入专业方向!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If ComboTeacherName.SelectedIndex = 0 Then
            MsgBox("请选择指导老师!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        Dim strTeacherName As String = ComboTeacherName.SelectedItem.ToString
        Dim strSQL As String = "select tid from teacher where tname='" + strTeacherName + "'"
        Dim strTeacherId As String = DBOperation.Search(strSQL).Rows(0)("tid")

        strSQL = "select sid from student where tid='" + strTeacherId + "'"
        Dim studentCount As Integer = DBOperation.Search(strSQL).Rows.Count
        If studentCount >= 6 Then
            MsgBox("一位指导老师不能指导6名以上的学生!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        strSQL = "select sid from student"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim strStudentId As String
        Dim nid As Integer

        If UserTable.Rows.Count = 0 Then
            strStudentId = "s001"
        Else
            strStudentId = UserTable.Rows(UserTable.Rows.Count - 1)("sid")
            nid = Val(strStudentId.Substring(1)) + 1
            If nid < 10 Then
                strStudentId = "s00" + nid.ToString
            ElseIf nid < 100 Then
                strStudentId = "s0" + nid.ToString
            Else
                strStudentId = "s" + nid.ToString
            End If
        End If

        strSQL = "insert into student values('" + strStudentId + "', '" + TextUser.Text.Trim() + "', '" + TextKey.Text.Trim() + "', '" + TextName.Text.Trim() + "', '" + TextEmail.Text.Trim() + "', '" + TextDirection.Text.Trim() + "', '" + TextQq.Text.Trim() + "', '" + TextQqgroup.Text.Trim() + "', '','0000001', null, null, null, null, null, 0, 0, 0, 0, '" + strTeacherId + "')"
        If DBOperation.Insert(strSQL) Then
            MsgBox("添加成功!", MsgBoxStyle.OkOnly, "添加新同学")
        Else
            MsgBox("添加失败!", MsgBoxStyle.Exclamation, "添加新同学")
        End If

        '更新ListBox
        ListStudentName.Items.Clear()
        ListStudentName.Items.Add("添加新同学...")
        strSQL = "select * from student order by suser"
        UserTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListStudentName.Items.Add(UserRow("sname"))
        Next
        ListStudentName.SelectedIndex = 0
    End Sub

    Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
        If TextUser.Text.Trim() = "" Then
            MsgBox("请输入学号!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextName.Text.Trim() = "" Then
            MsgBox("请输入姓名!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextEmail.Text.Trim() = "" Then
            MsgBox("请输入邮箱!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextDirection.Text.Trim() = "" Then
            MsgBox("请输入专业方向!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If ComboTeacherName.SelectedIndex = 0 Then
            MsgBox("请选择指导老师!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        Dim strListName As String = ListStudentName.SelectedItem().ToString

        Dim strTeacherName As String = ComboTeacherName.SelectedItem.ToString
        Dim strSQL As String = "select tid from teacher where tname='" + strTeacherName + "'"
        Dim strTeacherId As String = DBOperation.Search(strSQL).Rows(0)("tid")

        strSQL = "update student set suser='" + TextUser.Text.Trim() + "', sname='" + TextName.Text.Trim() + "', semail='" + TextEmail.Text.Trim() + "', sdirection='" + TextDirection.Text.Trim() + "', sqq='" + TextQq.Text.Trim() + "', sqqgroup='" + TextQqgroup.Text.Trim() + "', tid='" + strTeacherId + "' where sname='" + strListName + "'"
        If DBOperation.Update(strSQL) Then
            MsgBox("更新成功!", MsgBoxStyle.OkOnly, "更新资料")
        Else
            MsgBox("更新失败!", MsgBoxStyle.Exclamation, "更新资料")
        End If

        '更新ListBox
        ListStudentName.Items.Clear()
        ListStudentName.Items.Add("添加新同学...")
        strSQL = "select * from student order by suser"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListStudentName.Items.Add(UserRow("sname"))
        Next
        ListStudentName.SelectedIndex = 0
    End Sub

    Private Sub ButtonDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDelete.Click
        Dim response As Integer = MsgBox("确定删除该学生?", vbOKCancel + vbQuestion, "确认")
        If response = 2 Then
            Exit Sub
        End If

        Dim strListName As String = ListStudentName.SelectedItem().ToString
        Dim strSQL = "delete student where sname='" + strListName + "'"
        If DBOperation.Delete(strSQL) Then
            MsgBox("删除成功!", MsgBoxStyle.OkOnly, "删除用户")
        Else
            MsgBox("删除失败!", MsgBoxStyle.Exclamation, "删除用户")
        End If

        '更新ListBox
        ListStudentName.Items.Clear()
        ListStudentName.Items.Add("添加新同学...")
        strSQL = "select * from student order by suser"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListStudentName.Items.Add(UserRow("sname"))
        Next
        ListStudentName.SelectedIndex = 0
    End Sub

    Private Sub ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click
        Me.Close()
    End Sub
End Class

⌨️ 快捷键说明

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