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

📄 viewhistory.vb

📁 vb.net写的图书管理系统,功能完备,能正常使用,可用于二次开发.
💻 VB
字号:
Public Class ViewHistory
    Inherits System.Windows.Forms.Form
    '定义变量curID,用于记录当前人员ID
    Dim curID As Long
#Region " Windows 窗体设计器生成的代码 "

    Public Sub New(ByVal id As Long)
        MyBase.New()
        curID = id
        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

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

    End Sub
    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 Label2 As System.Windows.Forms.Label
    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 btnExit As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents lblMsg As System.Windows.Forms.Label
    Friend WithEvents lsvHistory As System.Windows.Forms.ListView
    Friend WithEvents txtReaderName As System.Windows.Forms.TextBox
    Friend WithEvents btnSearch As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.lsvHistory = 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.btnExit = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.lblMsg = New System.Windows.Forms.Label
        Me.txtReaderName = New System.Windows.Forms.TextBox
        Me.btnSearch = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(16, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(29, 17)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "姓名"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(16, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(79, 17)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "借阅历史记录"
        '
        'lsvHistory
        '
        Me.lsvHistory.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5})
        Me.lsvHistory.Location = New System.Drawing.Point(16, 72)
        Me.lsvHistory.Name = "lsvHistory"
        Me.lsvHistory.Size = New System.Drawing.Size(406, 232)
        Me.lsvHistory.TabIndex = 31
        Me.lsvHistory.View = System.Windows.Forms.View.Details
        '
        'ColumnHeader1
        '
        Me.ColumnHeader1.Text = "ISBN"
        Me.ColumnHeader1.Width = 50
        '
        'ColumnHeader2
        '
        Me.ColumnHeader2.Text = "书籍名称"
        Me.ColumnHeader2.Width = 110
        '
        'ColumnHeader3
        '
        Me.ColumnHeader3.Text = "借入日期"
        Me.ColumnHeader3.Width = 80
        '
        'ColumnHeader4
        '
        Me.ColumnHeader4.Text = "归还日期"
        Me.ColumnHeader4.Width = 80
        '
        'ColumnHeader5
        '
        Me.ColumnHeader5.Text = "到期时间"
        Me.ColumnHeader5.Width = 80
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(344, 320)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(72, 28)
        Me.btnExit.TabIndex = 33
        Me.btnExit.Text = "退出"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(240, 320)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(88, 28)
        Me.btnClear.TabIndex = 32
        Me.btnClear.Text = "清空历史记录"
        '
        'lblMsg
        '
        Me.lblMsg.Location = New System.Drawing.Point(16, 320)
        Me.lblMsg.Name = "lblMsg"
        Me.lblMsg.Size = New System.Drawing.Size(200, 23)
        Me.lblMsg.TabIndex = 34
        '
        'txtReaderName
        '
        Me.txtReaderName.Location = New System.Drawing.Point(64, 16)
        Me.txtReaderName.Name = "txtReaderName"
        Me.txtReaderName.TabIndex = 36
        Me.txtReaderName.Text = ""
        '
        'btnSearch
        '
        Me.btnSearch.Location = New System.Drawing.Point(176, 16)
        Me.btnSearch.Name = "btnSearch"
        Me.btnSearch.Size = New System.Drawing.Size(56, 24)
        Me.btnSearch.TabIndex = 37
        Me.btnSearch.Text = "查询"
        '
        'ViewHistory
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(440, 365)
        Me.Controls.Add(Me.btnSearch)
        Me.Controls.Add(Me.txtReaderName)
        Me.Controls.Add(Me.lblMsg)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.lsvHistory)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "ViewHistory"
        Me.Text = "借阅历史记录查看"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub ViewHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '当前读者不为空时,填充其历史纪录
        If curID <> 0 Then
            '查询输入框文本设为当前读者姓名
            txtReaderName.Text = getField("Name", "ID=" & curID, "ReaderInfo")
            '填充历史记录
            fullHistory()
            '设置【清空】按钮为可用
            btnClear.Enabled = True
        Else
            '当前读者为空时,设置【清空】按钮为不可用
            btnClear.Enabled = False
        End If
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Dim strSql As String
        Dim isSuccess As Boolean
        '删除历史记录时,只删除该读者曾经借阅并且已经归还的书籍记录
        '生成SQL语句
        strSql = "delete from BookBorrow where ReaderID=" & curID & " and ReturnDate is not null and ReturnDate<>''"
        '执行SQL语句,完成删除操作
        isSuccess = DBManager.executeNonQuery(strSql)
        If isSuccess Then
            '若删除成功,给出提示信息
            InfoMSG("成功清除历史记录!")
            '重新填充历史纪录
            fullHistory()
        Else
            '若删除失败,给出错误信息
            ErrorMSG("未能成功清除历史纪录!")
        End If
    End Sub
    Private Sub fullHistory()
        Dim strSql As String
        Dim mydet As DataSet
        '生成SQL语句
        strSql = "select ISBN,BorrowDate,ReturnDate,Deadline from BookBorrow where ReaderID=" & curID & " and ReturnDate is not null and ReturnDate<>''"
        '执行SQL语句,取出结果集
        mydet = DBManager.executeSelectQuery(strSql, "ViewHistory")
        If mydet Is Nothing OrElse mydet.Tables(0).Rows.Count = 0 Then
            '若当前读者没有历史纪录,设置提示信息并退出
            lblMsg.Text = "该人员没有借阅历史记录!"
            Exit Sub
        End If
        '变量定义
        Dim item As ListViewItem
        Dim subItem1 As ListViewItem.ListViewSubItem
        Dim subItem2 As ListViewItem.ListViewSubItem
        Dim subItem3 As ListViewItem.ListViewSubItem
        Dim subItem4 As ListViewItem.ListViewSubItem

        Dim i As Integer
        Dim str As String
        '设置提示信息
        lblMsg.Text = "该人员共有" & mydet.Tables(0).Rows.Count & "条历史记录"
        '清空显示控件
        lsvHistory.Items.Clear()
        '填充历史纪录
        For i = 0 To mydet.Tables(0).Rows.Count - 1
            With mydet.Tables(0).Rows(i)
                str = .Item("ISBN")
                item = New ListViewItem(str)
                '书籍名称
                subItem1 = New ListViewItem.ListViewSubItem(item, getField("Name", "ISBN=" & str, "BookInfo"))
                '借阅日期
                subItem2 = New ListViewItem.ListViewSubItem(item, .Item("BorrowDate") & "")
                '还入日期
                subItem3 = New ListViewItem.ListViewSubItem(item, .Item("ReturnDate") & "")
                '到期时间
                subItem4 = New ListViewItem.ListViewSubItem(item, .Item("Deadline") & "")
                item.SubItems.Add(subItem1)
                item.SubItems.Add(subItem2)
                item.SubItems.Add(subItem3)
                item.SubItems.Add(subItem4)
                lsvHistory.Items.Add(item)
            End With
        Next
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim strSql As String
        Dim mydet As DataSet
        '生成SQL语句
        strSql = "select ID from ReaderInfo where Name='" & txtReaderName.Text.Trim & "'"
        '执行SQL语句,取出结果集
        mydet = DBManager.executeSelectQuery(strSql, "ViewHistory")
        '若该读者不存在,给出提示信息
        If mydet Is Nothing OrElse mydet.Tables(0).Rows.Count = 0 Then
            lblMsg.Text = "该人员不存在!"
            '设置【清空】按钮不可用
            btnClear.Enabled = False
            '退出
            Exit Sub
        End If
        '得到当前读者ID
        curID = mydet.Tables(0).Rows(0).Item("ID")
        '填充历史纪录
        fullHistory()
    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Dispose()
    End Sub

End Class

⌨️ 快捷键说明

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