?? admin_boardmanage.vb
字號(hào):
Imports System.Data
'引入數(shù)據(jù)庫操作類命名空間
Imports System.Data.OleDb
'引入ADO.NET操作命名空間
Public Class win_boardmanage
Inherits System.Windows.Forms.Form
Dim sqlstr As String 'SQL語句標(biāo)記
Dim objDS As DataSet '數(shù)據(jù)在內(nèi)存中的緩存
Dim boardid As Integer, i As Integer
Dim login As New library2.win_login
#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
Public Sub New()
MyBase.New()
'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent()
'在 InitializeComponent() 調(diào)用之后添加任何初始化
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 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的
'可以使用 Windows 窗體設(shè)計(jì)器修改此過程。
'不要使用代碼編輯器修改它。
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 = "關(guān)閉"
'
'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 = "公告內(nèi)容"
'
'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 = "發(fā)布管理員:"
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 = "最大長(zhǎng)度 60,當(dāng)前字?jǐn)?shù):"
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 = "圖書館管理系統(tǒng)--公告管理"
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("公告內(nèi)容不能為空", "錯(cuò)誤", 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("讀取數(shù)據(jù)庫錯(cuò)誤。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "錯(cuò)誤")
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("數(shù)據(jù)庫更新錯(cuò)誤。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "錯(cuò)誤")
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("讀取數(shù)據(jù)庫錯(cuò)誤。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "錯(cuò)誤")
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("公告內(nèi)容不能為空", "錯(cuò)誤", 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("更新數(shù)據(jù)庫成功。", 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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -