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

📄 studentteacherleavewordform.vb

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

    Private umode As Integer = UserMode.NobodyMode
    Private sLid As String

    Public Sub SetUserMode(ByVal value As Integer)
        umode = value
    End Sub

    Private Sub StudentTeacherLeaveWordForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strSQL As String = ""
        Dim strUser As String = LoginForm.TextUser.Text
        Dim UserTable As DataTable
        Dim UserRow As DataRow

        If umode = UserMode.StudentMode Then
            ListStudentName.Visible = False
        Else
            ListStudentName.Items.Clear()
            strSQL = "select * from student s, teacher t where s.tid=t.tid and t.tuser='" + strUser + "'"

            UserTable = DBOperation.Search(strSQL)
            For Each UserRow In UserTable.Rows
                ListStudentName.Items.Add(UserRow("sname"))
            Next

            '指导老师没有指导任何学生
            If ListStudentName.Items.Count = 0 Then
                MsgBox("没有合适的学生信息!", MsgBoxStyle.Exclamation, "信息框")
                ButtonSend.Enabled = False
            Else
                ListStudentName.SelectedIndex = 0
            End If
        End If

        ListViewWord.Items.Clear()
        Dim strReceiveid As String

        If umode = UserMode.StudentMode Then
            strSQL = "select sid from student where suser='" + strUser + "'"
            strReceiveid = DBOperation.Search(strSQL).Rows(0)("sid")
        Else
            strSQL = "select tid from teacher where tuser='" + strUser + "'"
            strReceiveid = DBOperation.Search(strSQL).Rows(0)("tid")
        End If

        strSQL = "select * from leaveWord where lreceiveid='" + strReceiveid + "'"
        UserTable = DBOperation.Search(strSQL)
        Dim LItem As ListViewItem
        Dim strDate As String
        Dim nMode As Integer
        Dim i As Integer = 0
        Dim n As Integer = 0

        For Each UserRow In UserTable.Rows
            i = i + 1
            LItem = New ListViewItem(i.ToString)

            If umode = UserMode.StudentMode Then
                strSQL = "select tname from teacher where tid='" + UserRow("lsendid") + "'"
                LItem.SubItems.Add(DBOperation.Search(strSQL).Rows(0)("tname"))
            Else
                strSQL = "select sname from student where sid='" + UserRow("lsendid") + "'"
                LItem.SubItems.Add(DBOperation.Search(strSQL).Rows(0)("sname"))
            End If

            strDate = UserRow("ldate")
            n = InStr(strDate, " ")
            LItem.SubItems.Add(strDate.Substring(0, n - 1))

            nMode = Val(UserRow("lmode"))
            Select Case nMode
                Case 1
                    LItem.SubItems.Add("普通留言")
                Case 2
                    LItem.SubItems.Add("改题申请(未指示)")
                Case 3
                    LItem.SubItems.Add("改题申请(已指示)")
                Case 4
                    LItem.SubItems.Add("改题申请(回复)")
            End Select

            ListViewWord.Items.Add(LItem)
        Next
    End Sub

    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click
        If TextSendContent.Text.Trim = "" Then
            MsgBox("请正确输入您的留言!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        Dim response As Integer = MsgBox("确定发送留言?", vbOKCancel + vbQuestion, "确认")
        If response = 2 Then
            Exit Sub
        End If

        Dim strUser As String = LoginForm.TextUser.Text
        Dim strSQL As String
        Dim UserTable As DataTable
        Dim strSendid As String
        Dim strReceiveid As String

        If umode = UserMode.StudentMode Then
            strSQL = "select s.sid, t.tid from student s, teacher t where s.tid=t.tid and s.suser='" + strUser + "'"
            UserTable = DBOperation.Search(strSQL)
            strSendid = UserTable.Rows(0)("sid")
            strReceiveid = UserTable.Rows(0)("tid")
        Else
            Dim strListName As String = ListStudentName.SelectedItems(0).ToString
            strSQL = "select s.sid, t.tid from student s, teacher t where s.tid=t.tid and t.tuser='" + strUser + "' and sname='" + strListName + "'"
            UserTable = DBOperation.Search(strSQL)
            strSendid = UserTable.Rows(0)("tid")
            strReceiveid = UserTable.Rows(0)("sid")
        End If
        
        Dim strLid As String
        Dim nid As Integer
        strSQL = "select lid from leaveWord"
        UserTable = DBOperation.Search(strSQL)

        If UserTable.Rows.Count = 0 Then
            strLid = "l001"
        Else
            strLid = UserTable.Rows(UserTable.Rows.Count - 1)("lid")
            nid = Val(strLid.Substring(1)) + 1
            If nid < 10 Then
                strLid = "l00" + nid.ToString
            ElseIf nid < 100 Then
                strLid = "l0" + nid.ToString
            Else
                strLid = "l" + nid.ToString
            End If
        End If

        Dim contentByte() As Byte = System.Text.Encoding.Default.GetBytes(TextSendContent.Text.Trim)

        strSQL = "insert into leaveWord values('" + strLid + "', '" + strSendid + "', '" + strReceiveid + "', '" + Now().ToString + "', '1', @lcontent)"
        Dim strRow As String = "lcontent"

        If DBOperation.Insert(strSQL, strRow, contentByte) Then
            MsgBox("留言成功!", MsgBoxStyle.OkOnly, "留言板")
        Else
            MsgBox("留言失败!", MsgBoxStyle.Exclamation, "留言板")
        End If
        TextSendContent.Text = ""
    End Sub

    Private Sub ListViewWord_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListViewWord.SelectedIndexChanged
        If ListViewWord.SelectedItems.Count <> 0 Then
            ButtonSee.Enabled = True
        Else
            ButtonSee.Enabled = False
        End If
    End Sub

    Private Sub ButtonSee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSee.Click
        Dim strUser As String = LoginForm.TextUser.Text
        Dim strSQL As String
        Dim strReceiveid As String

        If umode = UserMode.StudentMode Then
            strSQL = "select sid from student where suser='" + strUser + "'"
            strReceiveid = DBOperation.Search(strSQL).Rows(0)("sid")
        Else
            strSQL = "select tid from teacher where tuser='" + strUser + "'"
            strReceiveid = DBOperation.Search(strSQL).Rows(0)("tid")
        End If

        Dim nListViewChoose As Integer = Val(ListViewWord.SelectedItems(0).SubItems(0).Text) - 1
        strSQL = "select * from leaveWord where lreceiveid='" + strReceiveid + "'"

        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim contentByte As Byte() = UserTable.Rows(nListViewChoose)("lcontent")
        TextReceiveContent.Text = System.Text.Encoding.Default.GetString(contentByte)

        Dim nMode As Integer = UserTable.Rows(nListViewChoose)("lmode")
        If nMode = 2 Then
            sLid = UserTable.Rows(nListViewChoose)("lid")
            ButtonYes.Visible = True
            ButtonNo.Visible = True
        End If
    End Sub

    Private Sub ButtonYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonYes.Click
        Dim response As Integer = MsgBox("确定同意其更改课题?", vbOKCancel + vbQuestion, "确认")
        If response = 2 Then
            Exit Sub
        End If

        Dim strContent As String = TextReceiveContent.Text

        Dim nLeft As Integer
        Dim nRight As Integer
        nLeft = InStrRev(strContent, "《")
        nRight = InStrRev(strContent, "》")
        Dim strNewTask As String = ""
        If nLeft > 0 And nRight > 0 Then
            strNewTask = strContent.Substring(nLeft, nRight - nLeft - 1)
        Else
            MsgBox("获取课题名失败!", MsgBoxStyle.Exclamation, "错误")
            Exit Sub
        End If

        Dim strName As String = ListViewWord.SelectedItems(0).SubItems(1).Text

        Dim strSQL As String = "update student set stask='" + strNewTask + "' where sname='" + strName + "'"
        If DBOperation.Update(strSQL) Then
            MsgBox("已完成指示!", MsgBoxStyle.OkOnly, "指示")
        Else
            MsgBox("更新出错!未完成指示!", MsgBoxStyle.Exclamation, "指示")
        End If

        ModifyMode()
        ReplyStudent(strName, True)

        ButtonYes.Visible = False
        ButtonNo.Visible = False
    End Sub

    Private Function ModifyMode() As Boolean
        Dim strSQL As String = "update leaveWord set lmode='3' where lid='" + sLid + "'"
        If DBOperation.Update(strSQL) Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Function ReplyStudent(ByVal strName As String, ByVal isYes As Boolean) As Boolean
        Dim strSQL As String = "select s.sid, t.tid from student s, teacher t where s.tid=t.tid and s.sname='" + strName + "'"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim strSendid As String = UserTable.Rows(0)("tid")
        Dim strReceiveid As String = UserTable.Rows(0)("sid")

        Dim strLid As String
        Dim nid As Integer
        strSQL = "select lid from leaveWord"
        UserTable = DBOperation.Search(strSQL)

        If UserTable.Rows.Count = 0 Then
            strLid = "l001"
        Else
            strLid = UserTable.Rows(UserTable.Rows.Count - 1)("lid")
            nid = Val(strLid.Substring(1)) + 1
            If nid < 10 Then
                strLid = "l00" + nid.ToString
            ElseIf nid < 100 Then
                strLid = "l0" + nid.ToString
            Else
                strLid = "l" + nid.ToString
            End If
        End If

        Dim strContent As String
        If isYes Then
            strContent = "指导老师同意了您的改题请求!"
        Else
            strContent = "指导老师拒绝了您的改题请求!"
        End If

        Dim contentByte() As Byte = System.Text.Encoding.Default.GetBytes(strContent)
        strSQL = "insert into leaveWord values('" + strLid + "', '" + strSendid + "', '" + strReceiveid + "', '" + Now().ToString + "', '4', @lcontent)"
        Dim strRow As String = "lcontent"

        If DBOperation.Insert(strSQL, strRow, contentByte) Then
            MsgBox("给学生答复成功!", MsgBoxStyle.OkOnly, "给学生答复")
            Return True
        Else
            MsgBox("给学生答复失败!", MsgBoxStyle.Exclamation, "给学生答复")
            Return False
        End If
    End Function

    Private Sub ButtonNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNo.Click
        Dim response As Integer = MsgBox("确定拒绝其更改课题?", vbOKCancel + vbQuestion, "确认")
        If response = 2 Then
            Exit Sub
        End If

        Dim strName As String = ListViewWord.SelectedItems(0).SubItems(1).Text
        ModifyMode()
        ReplyStudent(strName, False)

        ButtonYes.Visible = False
        ButtonNo.Visible = False
    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 + -