📄 admin_timeout.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class win_timeout
Inherits System.Windows.Forms.Form
Dim sqlstr, sqlstr2 As String 'SQL语句标记
Dim objDS, objDS2 As DataSet, i As Integer, CheckEvery As Boolean = True '数据在内存中的缓存
#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 GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents ListView1 As System.Windows.Forms.ListView
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 Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents labelnow As System.Windows.Forms.Label
Friend WithEvents clblockedstu As System.Windows.Forms.CheckedListBox
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(win_timeout))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.labelnow = New System.Windows.Forms.Label
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.ListView1 = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader5 = 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.Button3 = New System.Windows.Forms.Button
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.Button4 = New System.Windows.Forms.Button
Me.clblockedstu = New System.Windows.Forms.CheckedListBox
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.labelnow)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.ListView1)
Me.GroupBox1.ForeColor = System.Drawing.SystemColors.ControlDark
Me.GroupBox1.Location = New System.Drawing.Point(3, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(528, 280)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "超时图书信息"
'
'labelnow
'
Me.labelnow.ForeColor = System.Drawing.SystemColors.ControlText
Me.labelnow.Location = New System.Drawing.Point(104, 248)
Me.labelnow.Name = "labelnow"
Me.labelnow.Size = New System.Drawing.Size(208, 24)
Me.labelnow.TabIndex = 3
Me.labelnow.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button2
'
Me.Button2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Button2.Location = New System.Drawing.Point(344, 248)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 24)
Me.Button2.TabIndex = 2
Me.Button2.Text = "锁定"
'
'Button1
'
Me.Button1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Button1.Location = New System.Drawing.Point(440, 248)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "关闭"
'
'ListView1
'
Me.ListView1.BackColor = System.Drawing.Color.DarkGray
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader5, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.Location = New System.Drawing.Point(8, 17)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(512, 223)
Me.ListView1.TabIndex = 0
Me.ListView1.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "图书名"
Me.ColumnHeader1.Width = 108
'
'ColumnHeader5
'
Me.ColumnHeader5.Text = "学生学号"
Me.ColumnHeader5.Width = 97
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "借阅学生"
Me.ColumnHeader2.Width = 90
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "该归还时间"
Me.ColumnHeader3.Width = 150
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "超时天数"
Me.ColumnHeader4.Width = 63
'
'Button3
'
Me.Button3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Button3.Location = New System.Drawing.Point(68, 248)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 24)
Me.Button3.TabIndex = 3
Me.Button3.Text = "解锁"
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.Button4)
Me.GroupBox2.Controls.Add(Me.clblockedstu)
Me.GroupBox2.Controls.Add(Me.Button3)
Me.GroupBox2.Location = New System.Drawing.Point(533, 0)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(128, 280)
Me.GroupBox2.TabIndex = 1
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "锁定的学生"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(12, 248)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(48, 24)
Me.Button4.TabIndex = 5
Me.Button4.Text = "全部"
'
'clblockedstu
'
Me.clblockedstu.BackColor = System.Drawing.Color.DarkGray
Me.clblockedstu.CheckOnClick = True
Me.clblockedstu.Location = New System.Drawing.Point(8, 17)
Me.clblockedstu.Name = "clblockedstu"
Me.clblockedstu.Size = New System.Drawing.Size(112, 212)
Me.clblockedstu.TabIndex = 4
Me.clblockedstu.ThreeDCheckBoxes = True
'
'win_timeout
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(664, 285)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "win_timeout"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "图书馆管理系统--超时管理"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub win_timeout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
labelnow.Text = "现在是:" & Now()
LoadData()
LoadLockStu()
End Sub
Function LoadLockStu()
sqlstr = "select * from studentinfo where islock=1" '读取锁定的学生
objDS = GetData(sqlstr)
clblockedstu.Items.Clear()
For i = 0 To objDS.Tables(0).Rows.Count - 1
clblockedstu.Items.Add(objDS.Tables(0).Rows(i)("name").ToString & " ," & objDS.Tables(0).Rows(i)("id"), False) '写入CheckedListBox,也将学生自动编号隐藏入box中
Next
End Function
Function LoadData()
sqlstr = "select * from landinfo where DateDiff('d',shouldreturntime,now())>0" '读取借阅超时的图书
objDS = GetData(sqlstr)
ListView1.Items.Clear()
For i = 0 To objDS.Tables(0).Rows.Count - 1
Dim li As New ListViewItem
li.SubItems.Clear()
li.SubItems(0).Text = showbookname(objDS.Tables(0).Rows(i)("bookid"))
sqlstr2 = "select * from studentinfo where id=" & objDS.Tables(0).Rows(i)("studentid") & ""
objDS2 = GetData(sqlstr2)
If objDS2.Tables(0).Rows.Count > 0 Then
li.SubItems.Add(objDS2.Tables(0).Rows(0)("learnid"))
li.SubItems.Add(objDS2.Tables(0).Rows(0)("name").ToString())
Else
li.SubItems.Add("不详")
li.SubItems.Add("不详")
End If
li.SubItems.Add(objDS.Tables(0).Rows(i)("shouldreturntime").ToString)
li.SubItems.Add(DateDiff("d", objDS.Tables(0).Rows(i)("shouldreturntime"), Now()))
ListView1.Items.Add(li) '插入到ListView1
Next
End Function
Function showbookname(ByVal bookid) As String
sqlstr2 = "select * from bookinfo where id=" & bookid & ""
objDS2 = GetData(sqlstr2)
If objDS2.Tables(0).Rows.Count > 0 Then
Return objDS2.Tables(0).Rows(0)("name").ToString
Else
Return "不详"
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If clblockedstu.CheckedItems.Count > 0 Then
Dim dstu() As String
For i = 0 To clblockedstu.CheckedItems.Count - 1
dstu = Split(clblockedstu.CheckedItems(i), ",") '从列表中读出学生ID
Try
sqlstr = "update studentinfo set islock=0 where id=" & dstu(1) & ""
objDS = GetData(sqlstr)
Catch
MessageBox.Show("更新数据库错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Next
LoadLockStu()
MessageBox.Show("解锁成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("没有选择要解锁的学生", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If clblockedstu.Items.Count <> 0 Then '全选功能
Dim k As Integer
If CheckEvery Then
For k = 0 To clblockedstu.Items.Count - 1
clblockedstu.SetItemCheckState(k, CheckState.Checked)
Next
CheckEvery = False
Else
For k = 0 To clblockedstu.Items.Count - 1
clblockedstu.SetItemCheckState(k, CheckState.Unchecked)
Next
CheckEvery = True
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ListView1.SelectedItems.Count > 0 Then
Try
For i = 0 To ListView1.SelectedItems.Count - 1
sqlstr = "update studentinfo set islock=1 where learnid='" & ListView1.SelectedItems(i).SubItems(1).Text & "'"
UpdateData(sqlstr)
Next
Catch
MessageBox.Show("更新数据库错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
LoadData()
LoadLockStu()
MessageBox.Show("锁定成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("没有选择要锁定的学生", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -