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

📄 lend_history.vb

📁 图书管理系统
💻 VB
字号:
Imports System.Data.SqlClient
Public Class Lend_HisTory
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(104, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "学号"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Button1)
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(496, 64)
        Me.GroupBox1.TabIndex = 1
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "设置查询条件"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(392, 24)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "查询"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(120, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(200, 21)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 88)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "借阅历史记录"
        '
        'ListView1
        '
        Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5})
        Me.ListView1.Location = New System.Drawing.Point(16, 112)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(496, 136)
        Me.ListView1.TabIndex = 3
        Me.ListView1.View = System.Windows.Forms.View.Details
        '
        'ColumnHeader1
        '
        Me.ColumnHeader1.Text = "书籍编号"
        Me.ColumnHeader1.Width = 91
        '
        'ColumnHeader2
        '
        Me.ColumnHeader2.Text = "书籍姓名"
        Me.ColumnHeader2.Width = 102
        '
        'ColumnHeader3
        '
        Me.ColumnHeader3.Text = "借阅开始日期"
        Me.ColumnHeader3.Width = 101
        '
        'ColumnHeader4
        '
        Me.ColumnHeader4.Text = "书籍归还日期"
        Me.ColumnHeader4.Width = 92
        '
        'ColumnHeader5
        '
        Me.ColumnHeader5.Text = "书籍到期日期"
        Me.ColumnHeader5.Width = 248
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(112, 264)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(88, 23)
        Me.Button2.TabIndex = 4
        Me.Button2.Text = "清空列表框"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(320, 264)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(104, 23)
        Me.Button3.TabIndex = 5
        Me.Button3.Text = "退出"
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.Label3.ForeColor = System.Drawing.Color.Red
        Me.Label3.Location = New System.Drawing.Point(272, 88)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(216, 16)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "书籍归还日期未空的表示该书籍未归还"
        '
        'Lend_HisTory
        '
        Me.AcceptButton = Me.Button1
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.ClientSize = New System.Drawing.Size(544, 301)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.ListView1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.Name = "Lend_HisTory"
        Me.Text = "借阅历史查看"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Function CheckData() As Boolean
        If TextBox1.Text <> "" Then
            If IsNumeric(TextBox1.Text) = False Then
                MessageBox.Show("学号输入选项必须为整数", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox1.Focus()
                Return False
                Exit Function
            End If
        Else
            MessageBox.Show("学号输入选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox1.Focus()
            Return False
        End If
        Return True
    End Function
    Private Function ExistSno() 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
                MessageBox.Show("学号输入不正确!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox1.Focus()
                Return False
            Else
                Return True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function

    Private Sub FillDataToListView1()
        ListView1.Items.Clear()
        If mycon.State = ConnectionState.Closed Then
            mycon.Open()
        End If
        Dim myset As New DataSet
        myset.Clear()
        'Dim sqlstr As String = "Select BookID,BookName,BookBeginDate,BookGuihuanDate,EndDate From Book_HisTory Where SID=@SID order by BookID asc"
        Dim sqlstr As String = "Exec Book_HisTory_Select @Sno='" & TextBox1.Text & "'"
        Dim myda As New SqlDataAdapter(sqlstr, mycon)
        myda.Fill(myset, "Book_HisTory")
        '然后将myset中的内容显示在ListView控件中,呵呵
        Dim i As Integer
        Dim item As ListViewItem
        Dim SubItem2 As ListViewItem.ListViewSubItem
        Dim SubItem3 As ListViewItem.ListViewSubItem
        Dim SubItem4 As ListViewItem.ListViewSubItem
        Dim SubItem5 As ListViewItem.ListViewSubItem
        Try
            For i = 0 To myset.Tables("Book_HisTory").Rows.Count - 1
                With myset.Tables("Book_HisTory").Rows(i)
                    item = New ListViewItem
                    SubItem2 = New ListViewItem.ListViewSubItem
                    SubItem3 = New ListViewItem.ListViewSubItem
                    SubItem4 = New ListViewItem.ListViewSubItem
                    SubItem5 = New ListViewItem.ListViewSubItem
                    item.Text = .Item("BookID") & ""
                    SubItem2.Text = .Item("BookName") & ""
                    SubItem3.Text = .Item("BookBeginDate") & ""
                    SubItem4.Text = .Item("BookGuihuanDate") & ""
                    SubItem5.Text = .Item("EndDate") & ""
                    item.SubItems.Add(SubItem2)
                    item.SubItems.Add(SubItem3)
                    item.SubItems.Add(SubItem4)
                    item.SubItems.Add(SubItem5)
                    ListView1.Items.Add(item)
                End With
            Next
            If myset.Tables("Book_HisTory").Rows.Count = 0 Then
                MessageBox.Show("没有任何该学生的记录", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
            mycon.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '查询按钮的代码
        If CheckData() = False Then
            Exit Sub
        End If
        If ExistSno() = False Then
            Exit Sub
        End If
        FillDataToListView1()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '清空列表框的代码
        ListView1.Items.Clear()
    End Sub

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

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        ListView1.Items.Clear()
    End Sub
End Class

⌨️ 快捷键说明

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