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

📄 studentteacherupdownloadform.vb

📁 管理毕业设计的管理系统 VB+SQL2000....
💻 VB
字号:
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Core

Public Class StudentTeacherUpdownloadForm

    '初始化为0
    Private umode As Integer = UserMode.NobodyMode
    Private dmode As Integer = DocumentMode.NoneMode

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

    Public Sub SetDocumentMode(ByVal value As Integer)
        dmode = value
    End Sub

    Private Sub StudentTeacherUpdownloadForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If umode = UserMode.EduMode Then
            ButtonExcel.Visible = True
            ButtonEmail.Visible = True
        End If

        If umode = UserMode.StudentMode Then
            GroupBoxL.Visible = False
        Else
            ListStudentName.Items.Clear()

            Dim strSQL As String
            If umode = UserMode.TeacherMode Then
                Dim strUser As String = LoginForm.TextUser.Text
                '查询语句中,学生表和指导老师表作关联
                strSQL = "select * from student s, teacher t where s.tid=t.tid and t.tuser='" + strUser + "'"
            Else
                strSQL = "select * from student order by suser"
            End If

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

            '指导老师没有指导任何学生
            If ListStudentName.Items.Count = 0 Then
                MsgBox("没有合适的学生信息!", MsgBoxStyle.Exclamation, "信息框")
                Me.Close()
                Exit Sub
            End If

            ListStudentName.SelectedIndex = 0
        End If
    End Sub

    Private Sub ButtonUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpload.Click
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim fileName As String = OpenFileDialog1.FileName
            Dim fileByte() As Byte = My.Computer.FileSystem.ReadAllBytes(fileName)

            Dim strUser As String
            Dim strSQL As String

            If umode = UserMode.StudentMode Then
                strUser = LoginForm.TextUser.Text
            Else
                Dim strListName As String = ListStudentName.SelectedItem().ToString
                strSQL = "select * from student where sname='" + strListName + "'"
                Dim UserTable As DataTable = DBOperation.Search(strSQL)
                strUser = UserTable.Rows(0)("suser")
            End If

            Dim strRow As String
            '上传
            Select Case dmode
                Case DocumentMode.StartMode
                    strSQL = "update student set sstart=@sstart where suser='" + strUser + "'"
                    strRow = "sstart"
                Case DocumentMode.LiteratureMode
                    strSQL = "update student set sliterature=@sliterature where suser='" + strUser + "'"
                    strRow = "sliterature"
                Case DocumentMode.MiddleMode
                    strSQL = "update student set smiddle=@smiddle where suser='" + strUser + "'"
                    strRow = "smiddle"
                Case DocumentMode.GuidanceMode
                    strSQL = "update student set sguidance=@sguidance where suser='" + strUser + "'"
                    strRow = "sguidance"
                Case DocumentMode.ThesisMode
                    strSQL = "update student set sthesis=@sthesis where suser='" + strUser + "'"
                    strRow = "sthesis"
                Case Else
                    MsgBox("Select Error!", MsgBoxStyle.Exclamation, "信息框")
                    Exit Sub
            End Select

            If DBOperation.Update(strSQL, strRow, fileByte) Then
                MsgBox("文件上传成功!", MsgBoxStyle.OkOnly, "文件上传")
            Else
                MsgBox("文件上传失败!", MsgBoxStyle.Exclamation, "文件上传")
            End If
        End If
    End Sub

    Private Sub ButtonDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDownload.Click
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim filePath As String = FolderBrowserDialog1.SelectedPath
            My.Computer.FileSystem.CreateDirectory(filePath)

            Dim strUser As String
            Dim strSQL As String
            Dim UserTable As DataTable

            If umode = UserMode.StudentMode Then
                strUser = LoginForm.TextUser.Text
            Else
                Dim strListName As String = ListStudentName.SelectedItem().ToString
                strSQL = "select * from student where sname='" + strListName + "'"
                UserTable = DBOperation.Search(strSQL)
                strUser = UserTable.Rows(0)("suser")
            End If

            strSQL = "select * from student where suser='" + strUser + "'"
            UserTable = DBOperation.Search(strSQL)
            Dim fileByte As Byte()
            '下载
            Select Case dmode
                Case DocumentMode.StartMode
                    fileByte = UserTable.Rows(0)("sstart")
                    My.Computer.FileSystem.WriteAllBytes(filePath + "\开题报告.doc", fileByte, False)
                Case DocumentMode.LiteratureMode
                    fileByte = UserTable.Rows(0)("sliterature")
                    My.Computer.FileSystem.WriteAllBytes(filePath + "\文献综述.doc", fileByte, False)
                Case DocumentMode.MiddleMode
                    fileByte = UserTable.Rows(0)("smiddle")
                    My.Computer.FileSystem.WriteAllBytes(filePath + "\中期检查.doc", fileByte, False)
                Case DocumentMode.GuidanceMode
                    fileByte = UserTable.Rows(0)("sguidance")
                    My.Computer.FileSystem.WriteAllBytes(filePath + "\指导记录.doc", fileByte, False)
                Case DocumentMode.ThesisMode
                    fileByte = UserTable.Rows(0)("sthesis")
                    My.Computer.FileSystem.WriteAllBytes(filePath + "\毕业论文.doc", fileByte, False)
                Case Else
                    MsgBox("Select Error!", MsgBoxStyle.Exclamation, "信息框")
                    Exit Sub
            End Select

            MsgBox("保存成功!", MsgBoxStyle.OkOnly, "文件下载")
        End If
    End Sub

    Private Sub ButtonExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExcel.Click
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim filePath As String = FolderBrowserDialog1.SelectedPath
            My.Computer.FileSystem.CreateDirectory(filePath)

            Dim isSaveOK As Boolean = True
            '保存
            Select Case dmode
                Case DocumentMode.StartMode
                    If ExcelOperation.ExcelSave(DocumentMode.StartMode, filePath) = False Then
                        isSaveOK = False
                    End If
                Case DocumentMode.LiteratureMode
                    If ExcelOperation.ExcelSave(DocumentMode.LiteratureMode, filePath) = False Then
                        isSaveOK = False
                    End If
                Case DocumentMode.MiddleMode
                    If ExcelOperation.ExcelSave(DocumentMode.MiddleMode, filePath) = False Then
                        isSaveOK = False
                    End If
                Case DocumentMode.GuidanceMode
                    If ExcelOperation.ExcelSave(DocumentMode.GuidanceMode, filePath) = False Then
                        isSaveOK = False
                    End If
                Case DocumentMode.ThesisMode
                    If ExcelOperation.ExcelSave(DocumentMode.ThesisMode, filePath) = False Then
                        isSaveOK = False
                    End If
                Case Else
                    MsgBox("Select Error!", MsgBoxStyle.Exclamation, "情况汇总")
                    Exit Sub
            End Select

            If isSaveOK Then
                MsgBox("保存成功!", MsgBoxStyle.Exclamation, "情况汇总")
            Else
                MsgBox("保存失败!", MsgBoxStyle.Exclamation, "情况汇总")
            End If
        End If
    End Sub

    Private Sub ButtonEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEmail.Click
        Dim strSQL As String = "select s.sname, s.sschedule, s.semail, t.temail from student s, teacher t where s.tid=t.tid"
        Dim UserTable As DataTable = DBOperation.Search(strSQL)
        Dim UserRow As DataRow
        Dim strSchedule As String
        Dim strSubSchedule As String

        Dim response As Integer = MsgBox("是否需要提醒未完成学生和其指导老师?", vbOKCancel + vbQuestion, "确认")
        If response = 2 Then
            Exit Sub
        End If

        Dim strTitle As String
        Dim strSBody As String
        Dim strTBody As String
        Dim isSendOK As Boolean = True

        For Each UserRow In UserTable.Rows
            strSchedule = UserRow("sschedule")
            strSubSchedule = strSchedule.Substring(dmode, 1)
            If strSubSchedule = "0" Then
                Select Case dmode
                    Case DocumentMode.StartMode
                        strTitle = "开题报告完成情况"
                        strSBody = "您的开题报告尚未完成,请加快进度!"
                        strTBody = "您的学生:" + UserRow("sname") + "开题报告尚未完成,请加以督促,谢谢!"
                    Case DocumentMode.LiteratureMode
                        strTitle = "文献综述完成情况"
                        strSBody = "您的文献综述尚未完成,请加快进度!"
                        strTBody = "您的学生:" + UserRow("sname") + "文献综述尚未完成,请加以督促,谢谢!"
                    Case DocumentMode.MiddleMode
                        strTitle = "中期检查完成情况"
                        strSBody = "您的中期检查尚未完成,请加快进度!"
                        strTBody = "您的学生:" + UserRow("sname") + "中期检查尚未完成,请加以督促,谢谢!"
                    Case DocumentMode.GuidanceMode
                        strTitle = "指导记录完成情况"
                        strSBody = "您的指导记录尚未完成,请加快进度!"
                        strTBody = "您的学生:" + UserRow("sname") + "指导记录尚未完成,请加以督促,谢谢!"
                    Case DocumentMode.ThesisMode
                        strTitle = "毕业论文完成情况"
                        strSBody = "您的毕业论文尚未完成,请加快进度!"
                        strTBody = "您的学生:" + UserRow("sname") + "毕业论文尚未完成,请加以督促,谢谢!"
                    Case Else
                        MsgBox("Select Error!", MsgBoxStyle.Exclamation, "Email")
                        Exit Sub
                End Select

                If EmailOperation.SendEmail("001010806@163.com", UserRow("semail"), strTitle, strSBody, "") = False Then
                    isSendOK = False
                End If
                If EmailOperation.SendEmail("001010806@163.com", UserRow("temail"), strTitle, strTBody, "") = False Then
                    isSendOK = False
                End If
            End If
        Next

        If isSendOK Then
            MsgBox("邮件发送成功!", MsgBoxStyle.Exclamation, "发送邮件")
        Else
            MsgBox("邮件发送失败!", MsgBoxStyle.Exclamation, "发送邮件")
        End If
    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 + -