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

📄 adminmanageteacherform.vb

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

    Private Sub UpdateInfo(ByVal table As DataTable, ByVal index As Integer)
        TextUser.Text = table.Rows(index)("tuser")
        TextKey.Text = table.Rows(index)("tkey")
        TextName.Text = table.Rows(index)("tname")
        TextPost.Text = table.Rows(index)("tpost")
        TextDegree.Text = table.Rows(index)("tdegree")
        TextEmail.Text = table.Rows(index)("temail")
        TextQq.Text = table.Rows(index)("tqq")
        TextQqgroup.Text = table.Rows(index)("tqqgroup")
    End Sub

    Private Sub AdminManageTeacherForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListTeacherName.Items.Clear()
        ListTeacherName.Items.Add("添加新教师...")
        Dim strSQL As String = "select tname from teacher"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow

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

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

            Dim strListName As String = ListTeacherName.SelectedItem().ToString
            Dim strSQL As String = "select * from teacher where tname='" + 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 TextPost.Text.Trim() = "" Then
            MsgBox("请输入职称!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextDegree.Text.Trim() = "" Then
            MsgBox("请输入学历!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextEmail.Text.Trim() = "" Then
            MsgBox("请输入邮箱!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        Dim strSQL As String = "select tid from teacher"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim strId As String
        Dim nid As Integer

        If UserTable.Rows.Count = 0 Then
            strId = "t001"
        Else
            strId = UserTable.Rows(UserTable.Rows.Count - 1)("tid")
            nid = Val(strId.Substring(1)) + 1
            If nid < 10 Then
                strId = "t00" + nid.ToString
            ElseIf nid < 100 Then
                strId = "t0" + nid.ToString
            Else
                strId = "t" + nid.ToString
            End If
        End If

        strSQL = "insert into teacher values('" + strId + "', '" + TextUser.Text.Trim() + "', '" + TextKey.Text.Trim() + "', '" + TextName.Text.Trim() + "', '" + TextPost.Text.Trim() + "', '" + TextDegree.Text.Trim() + "', '" + TextEmail.Text.Trim() + "', '" + TextQq.Text.Trim() + "', '" + TextQqgroup.Text.Trim() + "', '')"
        If DBOperation.Insert(strSQL) Then
            MsgBox("添加成功!", MsgBoxStyle.OkOnly, "添加新教师")
        Else
            MsgBox("添加失败!", MsgBoxStyle.Exclamation, "添加新教师")
        End If

        '更新ListBox
        ListTeacherName.Items.Clear()
        ListTeacherName.Items.Add("添加新教师...")
        strSQL = "select * from teacher"
        UserTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListTeacherName.Items.Add(UserRow("tname"))
        Next
        ListTeacherName.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 TextPost.Text.Trim() = "" Then
            MsgBox("请输入职称!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextDegree.Text.Trim() = "" Then
            MsgBox("请输入学历!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If
        If TextEmail.Text.Trim() = "" Then
            MsgBox("请输入邮箱!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

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

        Dim strSQL As String = "update teacher set tuser='" + TextUser.Text.Trim() + "', tname='" + TextName.Text.Trim() + "', tpost='" + TextPost.Text.Trim() + "', tdegree='" + TextDegree.Text.Trim() + "', temail='" + TextEmail.Text.Trim() + "', tqq='" + TextQq.Text.Trim() + "', tqqgroup='" + TextQqgroup.Text.Trim() + "' where tname='" + strListName + "'"
        If DBOperation.Update(strSQL) Then
            MsgBox("更新成功!", MsgBoxStyle.OkOnly, "更新资料")
        Else
            MsgBox("更新失败!", MsgBoxStyle.Exclamation, "更新资料")
        End If

        '更新ListBox
        ListTeacherName.Items.Clear()
        ListTeacherName.Items.Add("添加新教师...")
        strSQL = "select * from teacher"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListTeacherName.Items.Add(UserRow("tname"))
        Next
        ListTeacherName.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 = ListTeacherName.SelectedItem().ToString
        Dim strSQL = "delete teacher where tname='" + strListName + "'"
        If DBOperation.Delete(strSQL) Then
            MsgBox("删除成功!", MsgBoxStyle.OkOnly, "删除用户")
        Else
            MsgBox("删除失败!", MsgBoxStyle.Exclamation, "删除用户")
        End If

        '更新ListBox
        ListTeacherName.Items.Clear()
        ListTeacherName.Items.Add("添加新教师...")
        strSQL = "select * from teacher"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        For Each UserRow In UserTable.Rows
            ListTeacherName.Items.Add(UserRow("tname"))
        Next
        ListTeacherName.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 + -