📄 admin_boardmanage.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class win_boardmanage
Inherits System.Windows.Forms.Form
Dim sqlstr As String 'SQL语句标记
Dim objDS As DataSet '数据在内存中的缓存
Dim boardid As Integer, i As Integer
Dim login As New library2.win_login
#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 GroupBox3 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents rtbboardcontent As System.Windows.Forms.RichTextBox
Friend WithEvents lblistboard As System.Windows.Forms.ListBox
Friend WithEvents btmodi As System.Windows.Forms.Button
Friend WithEvents btdelete As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents btadd As System.Windows.Forms.Button
Friend WithEvents btreset As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(win_boardmanage))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.btreset = New System.Windows.Forms.Button
Me.btadd = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.GroupBox3 = New System.Windows.Forms.GroupBox
Me.Label4 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.rtbboardcontent = New System.Windows.Forms.RichTextBox
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.lblistboard = New System.Windows.Forms.ListBox
Me.btmodi = New System.Windows.Forms.Button
Me.btdelete = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.GroupBox3.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.btreset)
Me.GroupBox1.Controls.Add(Me.btadd)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.GroupBox3)
Me.GroupBox1.Controls.Add(Me.GroupBox2)
Me.GroupBox1.Controls.Add(Me.btmodi)
Me.GroupBox1.Controls.Add(Me.btdelete)
Me.GroupBox1.ForeColor = System.Drawing.SystemColors.ControlDark
Me.GroupBox1.Location = New System.Drawing.Point(4, 2)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(368, 206)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "公告管理"
'
'btreset
'
Me.btreset.ForeColor = System.Drawing.SystemColors.ControlText
Me.btreset.Location = New System.Drawing.Point(179, 175)
Me.btreset.Name = "btreset"
Me.btreset.Size = New System.Drawing.Size(48, 24)
Me.btreset.TabIndex = 4
Me.btreset.Text = "重置"
'
'btadd
'
Me.btadd.ForeColor = System.Drawing.SystemColors.ControlText
Me.btadd.Location = New System.Drawing.Point(47, 175)
Me.btadd.Name = "btadd"
Me.btadd.Size = New System.Drawing.Size(48, 24)
Me.btadd.TabIndex = 2
Me.btadd.Text = "添加"
'
'Button1
'
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Button1.Location = New System.Drawing.Point(311, 174)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 24)
Me.Button1.TabIndex = 6
Me.Button1.Text = "关闭"
'
'GroupBox3
'
Me.GroupBox3.Controls.Add(Me.Label4)
Me.GroupBox3.Controls.Add(Me.Label3)
Me.GroupBox3.Controls.Add(Me.Label1)
Me.GroupBox3.Controls.Add(Me.Label2)
Me.GroupBox3.Controls.Add(Me.rtbboardcontent)
Me.GroupBox3.Location = New System.Drawing.Point(144, 16)
Me.GroupBox3.Name = "GroupBox3"
Me.GroupBox3.Size = New System.Drawing.Size(216, 151)
Me.GroupBox3.TabIndex = 8
Me.GroupBox3.TabStop = False
Me.GroupBox3.Text = "公告内容"
'
'Label4
'
Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label4.Location = New System.Drawing.Point(109, 108)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(89, 18)
Me.Label4.TabIndex = 12
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label3
'
Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label3.Location = New System.Drawing.Point(27, 110)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(84, 17)
Me.Label3.TabIndex = 11
Me.Label3.Text = "发布管理员:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(156, 128)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 10
Me.Label1.Text = "0"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label2
'
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label2.Location = New System.Drawing.Point(12, 128)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(152, 16)
Me.Label2.TabIndex = 9
Me.Label2.Text = "最大长度 60,当前字数:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'rtbboardcontent
'
Me.rtbboardcontent.Location = New System.Drawing.Point(8, 16)
Me.rtbboardcontent.MaxLength = 59
Me.rtbboardcontent.Name = "rtbboardcontent"
Me.rtbboardcontent.Size = New System.Drawing.Size(200, 89)
Me.rtbboardcontent.TabIndex = 1
Me.rtbboardcontent.Text = ""
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.lblistboard)
Me.GroupBox2.Location = New System.Drawing.Point(8, 16)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(128, 151)
Me.GroupBox2.TabIndex = 7
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "公告列表"
'
'lblistboard
'
Me.lblistboard.ItemHeight = 12
Me.lblistboard.Location = New System.Drawing.Point(8, 16)
Me.lblistboard.Name = "lblistboard"
Me.lblistboard.Size = New System.Drawing.Size(112, 124)
Me.lblistboard.TabIndex = 7
'
'btmodi
'
Me.btmodi.ForeColor = System.Drawing.SystemColors.ControlText
Me.btmodi.Location = New System.Drawing.Point(113, 175)
Me.btmodi.Name = "btmodi"
Me.btmodi.Size = New System.Drawing.Size(48, 24)
Me.btmodi.TabIndex = 3
Me.btmodi.Text = "修改"
'
'btdelete
'
Me.btdelete.ForeColor = System.Drawing.SystemColors.ControlText
Me.btdelete.Location = New System.Drawing.Point(245, 175)
Me.btdelete.Name = "btdelete"
Me.btdelete.Size = New System.Drawing.Size(48, 24)
Me.btdelete.TabIndex = 5
Me.btdelete.Text = "删除"
'
'win_boardmanage
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.Button1
Me.ClientSize = New System.Drawing.Size(376, 213)
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(384, 240)
Me.MinimumSize = New System.Drawing.Size(384, 240)
Me.Name = "win_boardmanage"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "图书馆管理系统--公告管理"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btmodi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmodi.Click
If rtbboardcontent.Text = "" Then
MessageBox.Show("公告内容不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
rtbboardcontent.Focus()
Else
sqlstr = "update board set content='" & filter(Trim(rtbboardcontent.Text.ToString)) & "' where id=" & boardid & ""
GetData(sqlstr)
rtbboardcontent.Clear()
rtbboardcontent.Text = ""
loaddata()
MessageBox.Show("公告修改成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub win_boardmanage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loaddata()
End Sub
Function loaddata()
lblistboard.Items.Clear()
Try
sqlstr = "select * from board"
objDS = GetData(sqlstr)
For i = 0 To objDS.Tables(0).Rows.Count - 1
If objDS.Tables(0).Rows(i)("content").ToString.Length > 7 Then
lblistboard.Items.Insert(0, Mid(objDS.Tables(0).Rows(i)("content").ToString, 1, 7) & "... ," & objDS.Tables(0).Rows(i)("id").ToString) '将公告ID隐藏在列表中
Else
lblistboard.Items.Insert(0, objDS.Tables(0).Rows(i)("content").ToString & " ," & objDS.Tables(0).Rows(i)("id").ToString)
End If
Next
Catch
MsgBox("读取数据库错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Close()
End Sub
Private Sub btdelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdelete.Click
Try
If boardid <> 0 Then
sqlstr = "delete from board where id=" & boardid & ""
UpdateData(sqlstr)
rtbboardcontent.Clear()
rtbboardcontent.Text = ""
loaddata()
MessageBox.Show("删除公告成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch
MsgBox("数据库更新错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
End Sub
Private Sub rtbboardcontent_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbboardcontent.TextChanged
Label1.Text = rtbboardcontent.Text.Length
End Sub
Private Sub lblistboard_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblistboard.SelectedIndexChanged
Try
Dim splitboard() As String, showboard As String, adminid As Integer
splitboard = Split(lblistboard.SelectedItem.ToString, ",")
boardid = CLng(splitboard(1))
sqlstr = "select * from board where id=" & boardid & ""
objDS = GetData(sqlstr)
showboard = objDS.Tables(0).Rows(0)("content").ToString
rtbboardcontent.Text = showboard
Label1.Text = showboard.Length
adminid = CInt(objDS.Tables(0).Rows(0)("admin"))
Label4.Text = showadminname(adminid)
Catch
MsgBox("读取数据库错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
End Sub
Private Sub btadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btadd.Click
Try
If rtbboardcontent.Text = "" Then
MessageBox.Show("公告内容不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
rtbboardcontent.Focus()
Else
sqlstr = "insert into board(content,admin) values('" & filter(Trim(rtbboardcontent.Text.ToString)) & "'," & login.loginid & ")"
GetData(sqlstr)
rtbboardcontent.Clear()
rtbboardcontent.Text = ""
loaddata()
MessageBox.Show("公告添加成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch
MsgBox("更新数据库成功。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "成功")
End Try
End Sub
Private Sub btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreset.Click
rtbboardcontent.Text = ""
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -