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

📄 admin_stumanage.vb

📁 图书馆管理系统,是数据库的课程设计,报告里面包含了需求分析数据字典概念结构设计逻辑结构设计数据库物理设计数据库实施
💻 VB
📖 第 1 页 / 共 3 页
字号:
            li.SubItems(0).Text = objDS.Tables(0).Rows(i)("id").ToString
            li.SubItems.Add(objDS.Tables(0).Rows(i)("name").ToString)
            li.SubItems.Add(objDS.Tables(0).Rows(i)("learnid").ToString)
            li.SubItems.Add(showclass(objDS.Tables(0).Rows(i)("class")))
            li.SubItems.Add(objDS.Tables(0).Rows(i)("phone").ToString)
            li.SubItems.Add(objDS.Tables(0).Rows(i)("lands").ToString)
            li.SubItems.Add(objDS.Tables(0).Rows(i)("logins").ToString)
            li.SubItems.Add(objDS.Tables(0).Rows(i)("lastlogin").ToString)
            ListView1.Items.Add(li) '插入到ListView1
        Next
    End Function

    Private Sub btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclose.Click
        Me.Close()
    End Sub

    Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
        Dim lvcItem As ListView.SelectedListViewItemCollection = New ListView.SelectedListViewItemCollection(ListView1)
        LabeID.Text = lvcItem(0).SubItems(0).Text.ToString
        tbstuname.Text = lvcItem(0).SubItems(1).Text.ToString
        tbstulearnid.Text = lvcItem(0).SubItems(2).Text.ToString
        cbclass.SelectedItem = lvcItem(0).SubItems(3).Text
        tbphone.Text = lvcItem(0).SubItems(4).Text.ToString
        stuid = lvcItem(0).SubItems(0).Text
    End Sub

    Private Sub btmodi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmodi.Click
        If stuid <> "" Then
            Dim stuname, stulearnid, classname, phone As String, canupdate As Boolean = True
            stuname = filter(Trim(tbstuname.Text).ToString)
            stulearnid = filter(Trim(tbstulearnid.Text).ToString)
            classname = filter(Trim(cbclass.SelectedIndex))
            phone = filter(Trim(tbphone.Text).ToString)
            If stuname = "" Then
                MessageBox.Show("学生名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbstuname.Focus()
                canupdate = False
            ElseIf stulearnid = "" Then
                MessageBox.Show("学生学号不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbstulearnid.Focus()
                canupdate = False
            ElseIf classname = "" Then
                MessageBox.Show("学生班级不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                cbclass.Focus()
                canupdate = False
            ElseIf Not isnum(stulearnid) Then
                MessageBox.Show("学生学号不是数字", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbstulearnid.Focus()
                canupdate = False
            ElseIf Not isnum(tbphone.Text) And tbphone.Text <> "" Then
                MessageBox.Show("学生联系电话不是数字", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbphone.Focus()
                canupdate = False
            End If

            Try
                If canupdate Then
                    sqlstr = "update studentinfo set name='" & stuname & "',learnid='" & stulearnid & "',class=" & classname & ",phone='" & phone & "' where id=" & stuid & ""
                    GetData(sqlstr)
                    LabeID.Text = ""
                    tbstuname.Text = ""
                    tbstulearnid.Text = ""
                    cbclass.SelectedIndex = 0
                    tbphone.Text = ""
                    stuid = ""
                    reloadData()
                    MessageBox.Show("数据更新成功", "更新成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            Catch
                MessageBox.Show("数据更新错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
        Else
            MessageBox.Show("没有选择学生资料", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub btdelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdelete.Click
        If stuid <> "" Then
            Try
                If MsgBox("确定要删除该学生吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "查询") = MsgBoxResult.Yes Then
                    sqlstr = "delete from studentinfo where id=" & stuid & ""
                    UpdateData(sqlstr)
                    reloadData()
                    LabeID.Text = ""
                    tbstuname.Text = ""
                    tbstulearnid.Text = ""
                    cbclass.SelectedItem = 0
                    tbphone.Text = ""
                    stuid = ""
                    MessageBox.Show("删除数据成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            Catch
                MessageBox.Show("删除数据错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
        Else
            MessageBox.Show("没有选择学生资料", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub btseach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btseach.Click
        Try
            Dim bywhat, keyword As String
            bywhat = changeby(filter(Trim(cbby.Text).ToString))
            keyword = filter(Trim(tbkeyword.Text).ToString)
            If keyword = "" Then
                MessageBox.Show("查询关键词不能为空", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbkeyword.Focus()
            ElseIf bywhat = "" Then
                MessageBox.Show("查询根据不能为空", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                cbby.Focus()
            Else

                If bywhat <> "class" Then '''不是查找"班级"
                    gsqlstr = "select * from studentinfo where " & bywhat & " like '%" & keyword & "%'"
                    reloadData()
                Else ''是查找"班级"
                    Dim j As Integer
                    ListView1.Items.Clear()
                    sqlstr = "select * from class where name like '%" & keyword & "%'"
                    objDS2 = GetData(sqlstr)
                    For i = 0 To objDS2.Tables(0).Rows.Count - 1
                        gsqlstr = "select * from studentinfo where class=" & objDS2.Tables(0).Rows(i)("id") & ""
                        objDS = GetData(gsqlstr)
                        For j = 0 To objDS.Tables(0).Rows.Count - 1
                            Dim li As New ListViewItem
                            li.SubItems.Clear()
                            li.SubItems(0).Text = objDS.Tables(0).Rows(i)("id").ToString
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("name").ToString)
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("learnid").ToString)
                            li.SubItems.Add(showclass(objDS.Tables(0).Rows(i)("class")))
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("phone").ToString)
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("lands").ToString)
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("logins").ToString)
                            li.SubItems.Add(objDS.Tables(0).Rows(i)("lastlogin").ToString)
                            ListView1.Items.Add(li) '插入到ListView1
                        Next
                    Next
                End If
            End If
        Catch
            MessageBox.Show("资料查询错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Function changeby(ByVal fstring) As String
        If fstring <> "" Then
            Select Case fstring
                Case "编号"
                    Return "id"
                Case "学生名"
                    Return "name"
                Case "学号"
                    Return "learnid"
                Case "班级"
                    Return "class"
                Case "联系电话"
                    Return "phone"
                Case "借阅次数"
                    Return "lands"
                Case "登陆次数"
                    Return "logins"
            End Select
        End If
    End Function

    Private Sub cblist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cblist.SelectedIndexChanged
        Select Case cblist.Text.ToString
            Case "编号"
                list = "id"
            Case "学生名"
                list = "name"
            Case "学号"
                list = "learnid"
            Case "班级"
                list = "class"
            Case "联系电话"
                list = "phone"
            Case "借阅次数"
                list = "lands"
            Case "登陆次数"
                list = "logins"
            Case "最后登陆时间"
                list = "lastlogin"
            Case Else
                list = "id"
        End Select
        gsqlstr = "select * from studentinfo order by " & list & " " & zandd & ""
        reloadData()
    End Sub

    Private Sub cbzandd_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbzandd.SelectedIndexChanged
        Select Case cbzandd.Text.ToString
            Case "正序"
                zandd = "DESC"
            Case "倒序"
                zandd = ""
        End Select
        gsqlstr = "select * from studentinfo order by " & list & " " & zandd & ""
        reloadData()
    End Sub

    Private Sub btadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btadd.Click
        Dim stuname, stulearnid, classname, phone As String, caninsert As Boolean = True
        stuname = filter(Trim(tbstuname.Text).ToString)
        stulearnid = filter(Trim(tbstulearnid.Text).ToString)
        classname = filter(Trim(cbclass.SelectedIndex))
        phone = filter(Trim(tbphone.Text).ToString)
        If stuname = "" Then
            MessageBox.Show("学生名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbstuname.Focus()
            caninsert = False
        ElseIf stulearnid = "" Then
            MessageBox.Show("学生学号不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbstulearnid.Focus()
            caninsert = False
        ElseIf classname = "" Then
            MessageBox.Show("学生班级不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cbclass.Focus()
            caninsert = False
        ElseIf Not isnum(stulearnid) Then
            MessageBox.Show("学生学号不是数字", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbstulearnid.Focus()
            caninsert = False
        ElseIf Not isnum(phone) And phone <> "" Then
            MessageBox.Show("学生联系电话不是数字", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbphone.Focus()
            caninsert = False
        Else
            sqlstr = "select * from studentinfo where learnid='" & stulearnid & "'"
            objDS = GetData(sqlstr)
            If objDS.Tables(0).Rows.Count > 0 Then
                MessageBox.Show("学生学号重复", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbstulearnid.Text = ""
                tbstulearnid.Focus()
                caninsert = False
            End If
        End If

        Try
            If caninsert Then
                sqlstr = "insert into studentinfo(name,learnid,class,phone) values('" & stuname & "','" & stulearnid & "'," & classname & ",'" & phone & "')"
                GetData(sqlstr)
                LabeID.Text = ""
                tbstuname.Text = ""
                tbstulearnid.Text = ""
                cbclass.SelectedIndex = 0
                tbphone.Text = ""
                stuid = ""
                reloadData()
                MessageBox.Show("数据更新成功", "更新成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch
            MessageBox.Show("数据更新错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
End Class

⌨️ 快捷键说明

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