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

📄 bookjieyue.vb

📁 图书管理系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
            For i = 0 To myset.Tables("Book").Rows.Count - 1
                With myset.Tables("Book").Rows(i)
                    item = New ListViewItem
                    SubItem2 = New ListViewItem.ListViewSubItem
                    SubItem3 = New ListViewItem.ListViewSubItem
                    SubItem4 = New ListViewItem.ListViewSubItem
                    SubItem5 = New ListViewItem.ListViewSubItem
                    item.Text = .Item("ID") & ""
                    SubItem2.Text = .Item("Name") & ""
                    SubItem3.Text = .Item("Anchor") & ""
                    SubItem4.Text = .Item("Publisher") & ""
                    SubItem5.Text = .Item("Price") & ""
                    item.SubItems.Add(SubItem2)
                    item.SubItems.Add(SubItem3)
                    item.SubItems.Add(SubItem4)
                    item.SubItems.Add(SubItem5)
                    ListView1.Items.Add(item)
                End With
            Next
            '      myset_Row = myset.Tables("Book").Rows.Count
            If Not ListView1.Items Is Nothing Then
                Button2.Enabled = True
                'MessageBox.Show("书籍已经全部借完,学校太穷了!望大家体谅", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else

                Button2.Enabled = False
                MessageBox.Show("书籍已经全部借完,学校太穷了!望大家体谅", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
            mycon.Close()
        Catch ex As Exception
            MessageBox.Show("请选择你要借阅的书籍!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub
    Private Sub FillDataToListView2()
        ListView2.Items.Clear()
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim sqlstr As String = "Select [ID],[Name],BeginDate,RemainDays From S_BS_Book Where Sno='" & TextBox1.Text & "'"
            Dim myda As New SqlDataAdapter(sqlstr, mycon)
            Dim myset As New DataSet
            myset.Clear()
            myda.Fill(myset, "information")
            Dim i As Integer
            Dim item As ListViewItem
            Dim Subitem2 As ListViewItem.ListViewSubItem
            Dim Subitem3 As ListViewItem.ListViewSubItem
            Dim Subitem4 As ListViewItem.ListViewSubItem
            For i = 0 To myset.Tables("information").Rows.Count - 1
                With myset.Tables("information").Rows(i)
                    item = New ListViewItem
                    Subitem2 = New ListViewItem.ListViewSubItem
                    Subitem3 = New ListViewItem.ListViewSubItem
                    Subitem4 = New ListViewItem.ListViewSubItem
                    item.Text = .Item(0) & ""
                    Subitem2.Text = .Item(1) & ""
                    Subitem3.Text = .Item(2) & ""
                    Subitem4.Text = .Item(3) & ""
                    item.SubItems.Add(Subitem2)
                    item.SubItems.Add(Subitem3)
                    item.SubItems.Add(Subitem4)
                    ListView2.Items.Add(item)
                End With
            Next
            If Not myset.Tables("information").Rows.Count = 0 Then
                Button3.Enabled = True
                Button2.Enabled = True
            Else
                Button3.Enabled = False
                Button2.Enabled = True
                '  MessageBox.Show("该读者注意一定要好好学习!至今还未借过一本书", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
        Catch ex As Exception
            MessageBox.Show("请选择你要归还的书籍!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub
    Function IsCheckSno() As Boolean
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim sqlstr As String = "Select Count(*) from Students where Sno='" & TextBox1.Text & "'"
            Dim mycom1 As New SqlCommand(sqlstr, mycon)
            If mycom1.ExecuteScalar <> 1 Then
                Return False
                Exit Function
            Else
                Return True
                Exit Function
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function
    Private Sub Bookjieyue_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "当前时间:" & Now
        '将内容填充到myset中
        Call FillDataToListView1()
        Button3.Enabled = False
        Button2.Enabled = False
        '  ListView1.SelectedItems[1]
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '查询情况按钮的代码
        '判断是否合法
        If TextBox1.Text = "" Then
            MessageBox.Show("输入的学号选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        '检验学入的学号的正确性
        If IsCheckSno() = False Then
            MessageBox.Show("你输入的学号不正确!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox1.Focus()
            Exit Sub
        End If
        Call FillDataToListView2()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '借阅按钮的代码
        '由学号到学生的SID号,呵呵
        If CheckButton2() = False Then
            MessageBox.Show("请选中你要借阅的书籍!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        Try '判断其已经借阅的书脊册数,如果<1则退出过程
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim myreader3 As SqlDataReader
            Dim mycom2 As New SqlCommand("Select RemainNumber From Students Where Sno='" & TextBox1.Text & "'", mycon)
            myreader3 = mycom2.ExecuteReader()
            While myreader3.Read
                If myreader3("RemainNumber") < 1 Then
                    myreader3.Close()
                    MessageBox.Show("该读者不能在借!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    Exit Sub
                End If
            End While
            myreader3.Close()
            mycon.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Try '由Sno到SID的转变
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim myreader1 As SqlDataReader
            Dim mycom1 As New SqlCommand("Select SID From Students Where Sno='" & TextBox1.Text & "'", mycon)
            myreader1 = mycom1.ExecuteReader
            While myreader1.Read
                StudentsSID = Val(myreader1.Item("SID"))
            End While
            mycon.Close()
            myreader1.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim CurrentIndex As Integer
            CurrentIndex = ListView1.SelectedIndices(0)
            ListView_BookID = Val(ListView1.Items(CurrentIndex).SubItems(0).Text)
            Dim StudentsSID1 As New SqlParameter("@StudentsSID1", SqlDbType.Int)
            Dim ListView_BookID1 As New SqlParameter("@ListView_BookID1", SqlDbType.Int)
            StudentsSID1.Value = StudentsSID
            ListView_BookID1.Value = ListView_BookID
            Dim sqlstr As String = "Exec Lend @SID=@StudentsSID1,@ID=@ListView_BookID1" '此处的代码可能有问题,呵呵
            Dim mycom1 As New SqlCommand(sqlstr, mycon)
            mycom1.Parameters.Add(StudentsSID1)
            mycom1.Parameters.Add(ListView_BookID1)
            mycom1.ExecuteNonQuery()
            FillDataToListView2()
            FillDataToListView1()
            MessageBox.Show("借阅成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            mycon.Close()
            '完成向数据库中的Book_HisTory完成插入操作
            mycon.Open()
            StudentsSID1 = New SqlParameter("@StudentsSID1", SqlDbType.Int)
            ListView_BookID1 = New SqlParameter("@ListView_BookID1", SqlDbType.Int)
            StudentsSID1.Value = StudentsSID
            ListView_BookID1.Value = ListView_BookID
            sqlstr = "Exec Book_HisTory_Insert @SID=@StudentsSID1,@ID=@Listview_BookID1"
            Dim mycom2 As New SqlCommand(sqlstr, mycon)
            mycom2.Parameters.Add(StudentsSID1)
            mycom2.Parameters.Add(ListView_BookID1)
            mycom2.ExecuteNonQuery()
            mycon.Close()
            ' MessageBox.Show("呵呵,恭喜!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning) '标志成功,呵呵
        Catch ex As Exception
            MessageBox.Show("请选择你要借阅的书籍!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '归还按钮的代码
        If CheckButton3() = False Then
            MessageBox.Show("请选种你要归还的书籍", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If

        Try  '由Sno到SID的转变
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim myreader1 As SqlDataReader
            Dim mycom1 As New SqlCommand("Select SID From Students Where Sno='" & TextBox1.Text & "'", mycon)
            myreader1 = mycom1.ExecuteReader
            While myreader1.Read
                StudentsSID = Val(myreader1.Item("SID"))
            End While
            mycon.Close()
            myreader1.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Dim CurrentIndex As Integer
        CurrentIndex = ListView2.SelectedIndices(0)
        ListView_BookID = Val(ListView2.Items(CurrentIndex).SubItems(0).Text)
        Try '实现归还书脊的功能
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim StudentsSID1 As New SqlParameter("@StudentsSID1", SqlDbType.Int)
            Dim ListView_BookID1 As New SqlParameter("@ListView_bookID1", SqlDbType.Int)
            StudentsSID1.Value = StudentsSID
            ListView_BookID1.Value = ListView_BookID
            Dim sqlstr As String = "Exec guihuan @SID=@StudentsSID1,@ID=@ListView_BookID1"
            Dim mycom2 As New SqlCommand(sqlstr, mycon)
            mycom2.Parameters.Add(StudentsSID1)
            mycom2.Parameters.Add(ListView_BookID1)
            mycom2.ExecuteNonQuery()
            FillDataToListView1()
            FillDataToListView2()
            MessageBox.Show("归还成功,谢谢使用!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            mycon.Close()
            '实现向Book_History中更新数据,呵呵
            mycon.Open()
            StudentsSID1 = New SqlParameter("@StudentsSID1", SqlDbType.Int)
            ListView_BookID1 = New SqlParameter("@ListView_BookID1", SqlDbType.Int)
            StudentsSID1.Value = StudentsSID
            ListView_BookID1.Value = ListView_BookID
            sqlstr = "Exec Book_HisTory_Update @SID=@StudentsSID1,@ID=@ListView_BookID1"
            Dim mycom3 As New SqlCommand(sqlstr, mycon)
            mycom3.Parameters.Add(StudentsSID1)
            mycom3.Parameters.Add(ListView_BookID1)
            mycom3.ExecuteNonQuery()
            mycon.Close()
            ' MessageBox.Show("哈哈,更新成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        '退出按钮的代码
        Me.Close()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'timer的click事件的代码,呵呵
        Label2.Text = "当前时间:" & Now
    End Sub


    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = System.Windows.Forms.Keys.Enter Then
            Button1.PerformClick()
        End If
    End Sub


    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        ListView2.Items.Clear() '当学号改变时清空里面的内容,呵呵
        Button2.Enabled = False
        Button3.Enabled = False
    End Sub

    ' Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    '     Dim CurrentIndex As Integer
    '    CurrentIndex = ListView1.SelectedIndices(0)
    '   ListView_BookID = Val(ListView1.Items(CurrentIndex).SubItems(0).Text)
    ' End Sub '此处代码也有问题,数组超出了有效的范围,呵呵
End Class

⌨️ 快捷键说明

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