?? admin_classifymanage.vb
字號:
Imports System.Data
'引入數據庫操作類命名空間
Imports System.Data.OleDb
'引入ADO.NET操作命名空間
Public Class win_classifymanage
Inherits System.Windows.Forms.Form
Dim sqlstr As String 'SQL語句標記
Dim objDS As DataSet '數據在內存中的緩存
Dim i As Integer, classifyname As String
#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 Label1 As System.Windows.Forms.Label
Friend WithEvents tbclassify As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
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 lbclassify As System.Windows.Forms.ListBox
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents btadd As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(win_classifymanage))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.btadd = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.Label4 = New System.Windows.Forms.Label
Me.tbclassify = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.lbclassify = New System.Windows.Forms.ListBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.btadd)
Me.GroupBox1.Controls.Add(Me.Button4)
Me.GroupBox1.Controls.Add(Me.Button3)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.Label4)
Me.GroupBox1.Controls.Add(Me.tbclassify)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.lbclassify)
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(344, 224)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "分類信息"
'
'btadd
'
Me.btadd.Location = New System.Drawing.Point(152, 132)
Me.btadd.Name = "btadd"
Me.btadd.Size = New System.Drawing.Size(48, 24)
Me.btadd.TabIndex = 2
Me.btadd.Text = "添加"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(280, 132)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(48, 24)
Me.Button4.TabIndex = 4
Me.Button4.Text = "刪除"
'
'Button3
'
Me.Button3.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button3.Location = New System.Drawing.Point(280, 176)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 24)
Me.Button3.TabIndex = 6
Me.Button3.Text = "關閉"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(216, 176)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 24)
Me.Button2.TabIndex = 5
Me.Button2.Text = "重置"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(216, 132)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 24)
Me.Button1.TabIndex = 3
Me.Button1.Text = "修改"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(136, 108)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(200, 16)
Me.Label4.TabIndex = 11
Me.Label4.Text = "系統自動過濾 ' "" + & | 字符"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.Label4.UseMnemonic = False
'
'tbclassify
'
Me.tbclassify.Location = New System.Drawing.Point(208, 68)
Me.tbclassify.MaxLength = 10
Me.tbclassify.Name = "tbclassify"
Me.tbclassify.Size = New System.Drawing.Size(104, 21)
Me.tbclassify.TabIndex = 1
Me.tbclassify.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(136, 68)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 24)
Me.Label1.TabIndex = 1
Me.Label1.Text = "分類名:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'lbclassify
'
Me.lbclassify.ItemHeight = 12
Me.lbclassify.Location = New System.Drawing.Point(8, 17)
Me.lbclassify.Name = "lbclassify"
Me.lbclassify.Size = New System.Drawing.Size(128, 196)
Me.lbclassify.TabIndex = 7
'
'win_classifymanage
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.Button3
Me.ClientSize = New System.Drawing.Size(344, 229)
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(352, 256)
Me.MinimumSize = New System.Drawing.Size(352, 256)
Me.Name = "win_classifymanage"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "圖書館管理系統--分類管理"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub win_classifymanage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
Function LoadData()
lbclassify.Items.Clear()
sqlstr = "select * from classify"
objDS = GetData(sqlstr)
For i = 0 To objDS.Tables(0).Rows.Count - 1
lbclassify.Items.Add(objDS.Tables(0).Rows(i)("name").ToString)
Next
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
tbclassify.Text = classifyname
tbclassify.Focus()
End Sub
Private Sub lbclassify_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbclassify.SelectedIndexChanged
tbclassify.Text = lbclassify.SelectedItem
classifyname = lbclassify.SelectedItem
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newname As String, canupdate As Boolean = True
newname = filter(Trim(tbclassify.Text))
If newname = "" Then
MessageBox.Show("分類名不能為空", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbclassify.Focus()
canupdate = False
End If
If canupdate Then
sqlstr = "update classify set name='" & newname & "' where name='" & classifyname & "'"
objDS = GetData(sqlstr)
tbclassify.Text = ""
classifyname = ""
LoadData()
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 classifyname <> "" Then
Try
sqlstr = "delete from classify where name='" & classifyname & "'"
UpdateData(sqlstr)
tbclassify.Text = ""
classifyname = ""
LoadData()
MessageBox.Show("數據庫更新成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch
MessageBox.Show("數據庫更新錯誤", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
Else
MessageBox.Show("沒有選擇分類", "操作錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btadd.Click
Dim newname As String, canupdate As Boolean = True
newname = filter(Trim(tbclassify.Text))
If newname = "" Then
MessageBox.Show("分類名不能為空", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbclassify.Focus()
canupdate = False
Else
sqlstr = "select * from classify where name = '" & newname & "'"
objDS = GetData(sqlstr)
If objDS.Tables(0).Rows.Count > 0 Then
MessageBox.Show("分類名重復", "操作錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbclassify.Text = ""
tbclassify.Focus()
canupdate = False
End If
End If
If canupdate Then
sqlstr = "insert into classify(name) values('" & newname & "')"
GetData(sqlstr)
tbclassify.Text = ""
LoadData()
MessageBox.Show("添加成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -