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

📄 admin_classmanage.vb

📁 图书馆管理系统,是数据库的课程设计,报告里面包含了需求分析数据字典概念结构设计逻辑结构设计数据库物理设计数据库实施
💻 VB
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间

Public Class win_classmanage
    Inherits System.Windows.Forms.Form
    Dim sqlstr As String 'SQL语句标记
    Dim objDS As DataSet '数据在内存中的缓存
    Dim i As Integer, classname 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 Label4 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btclose As System.Windows.Forms.Button
    Friend WithEvents btreset As System.Windows.Forms.Button
    Friend WithEvents btmodi As System.Windows.Forms.Button
    Friend WithEvents tbclass As System.Windows.Forms.TextBox
    Friend WithEvents lbclass As System.Windows.Forms.ListBox
    Friend WithEvents Button1 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_classmanage))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.btadd = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.btclose = New System.Windows.Forms.Button
        Me.btreset = New System.Windows.Forms.Button
        Me.btmodi = New System.Windows.Forms.Button
        Me.Label4 = New System.Windows.Forms.Label
        Me.tbclass = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.lbclass = New System.Windows.Forms.ListBox
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.btadd)
        Me.GroupBox1.Controls.Add(Me.Button1)
        Me.GroupBox1.Controls.Add(Me.btclose)
        Me.GroupBox1.Controls.Add(Me.btreset)
        Me.GroupBox1.Controls.Add(Me.btmodi)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.tbclass)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.lbclass)
        Me.GroupBox1.Location = New System.Drawing.Point(0, 2)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(344, 224)
        Me.GroupBox1.TabIndex = 1
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "班级信息"
        '
        'btadd
        '
        Me.btadd.Location = New System.Drawing.Point(152, 136)
        Me.btadd.Name = "btadd"
        Me.btadd.Size = New System.Drawing.Size(48, 24)
        Me.btadd.TabIndex = 2
        Me.btadd.Text = "添加"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(280, 136)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(48, 24)
        Me.Button1.TabIndex = 4
        Me.Button1.Text = "删除"
        '
        'btclose
        '
        Me.btclose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btclose.Location = New System.Drawing.Point(280, 184)
        Me.btclose.Name = "btclose"
        Me.btclose.Size = New System.Drawing.Size(48, 24)
        Me.btclose.TabIndex = 6
        Me.btclose.Text = "关闭"
        '
        'btreset
        '
        Me.btreset.Location = New System.Drawing.Point(216, 184)
        Me.btreset.Name = "btreset"
        Me.btreset.Size = New System.Drawing.Size(48, 24)
        Me.btreset.TabIndex = 5
        Me.btreset.Text = "重置"
        '
        'btmodi
        '
        Me.btmodi.Location = New System.Drawing.Point(216, 136)
        Me.btmodi.Name = "btmodi"
        Me.btmodi.Size = New System.Drawing.Size(48, 24)
        Me.btmodi.TabIndex = 3
        Me.btmodi.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
        '
        'tbclass
        '
        Me.tbclass.Location = New System.Drawing.Point(208, 68)
        Me.tbclass.Name = "tbclass"
        Me.tbclass.Size = New System.Drawing.Size(104, 21)
        Me.tbclass.TabIndex = 1
        Me.tbclass.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
        '
        'lbclass
        '
        Me.lbclass.ItemHeight = 12
        Me.lbclass.Location = New System.Drawing.Point(8, 17)
        Me.lbclass.Name = "lbclass"
        Me.lbclass.Size = New System.Drawing.Size(128, 196)
        Me.lbclass.TabIndex = 7
        '
        'win_classmanage
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.CancelButton = Me.btclose
        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_classmanage"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "图书馆管理系统--班级管理"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclose.Click
        Me.Close()
    End Sub

    Private Sub btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreset.Click
        tbclass.Text = classname
        tbclass.Focus()
    End Sub

    Private Sub btmodi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmodi.Click
        Dim newname As String, canupdate As Boolean = True
        newname = filter(Trim(tbclass.Text))
        If newname = "" Then
            MessageBox.Show("分类名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbclass.Focus()
            canupdate = False
        End If

        If canupdate Then
            sqlstr = "update class set name='" & newname & "' where name='" & classname & "'"
            objDS = GetData(sqlstr)
            tbclass.Text = ""
            classname = ""
            LoadData()
            MessageBox.Show("修改成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub win_classmanage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub lbclass_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbclass.SelectedIndexChanged
        tbclass.Text = lbclass.SelectedItem
        classname = lbclass.SelectedItem
    End Sub

    Function LoadData()
        lbclass.Items.Clear()
        sqlstr = "select * from class"
        objDS = GetData(sqlstr)
        For i = 0 To objDS.Tables(0).Rows.Count - 1
            lbclass.Items.Add(objDS.Tables(0).Rows(i)("name").ToString)
        Next
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If classname <> "" Then
            Try
                sqlstr = "delete from class where name='" & classname & "'"
                UpdateData(sqlstr)
                tbclass.Text = ""
                classname = ""
                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(tbclass.Text))
        If newname = "" Then
            MessageBox.Show("班级名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbclass.Focus()
            canupdate = False
        Else
            sqlstr = "select * from class where name = '" & newname & "'"
            objDS = GetData(sqlstr)
            If objDS.Tables(0).Rows.Count > 0 Then
                MessageBox.Show("班级名重复", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbclass.Text = ""
                tbclass.Focus()
                canupdate = False
            End If
        End If

        If canupdate Then
            sqlstr = "insert into class(name) values('" & newname & "')"
            GetData(sqlstr)
            tbclass.Text = ""
            LoadData()
            MessageBox.Show("添加成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
End Class

⌨️ 快捷键说明

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