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

📄 bookadd.vb

📁 vb.net写的图书管理系统,功能完备,能正常使用,可用于二次开发.
💻 VB
字号:
Public Class BookAdd
    Inherits System.Windows.Forms.Form

#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 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 Label5 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents txtBookName As System.Windows.Forms.TextBox
    Friend WithEvents txtBookPrice As System.Windows.Forms.TextBox
    Friend WithEvents dtpPressDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents txtAuthorName As System.Windows.Forms.TextBox
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents cmbBookType As System.Windows.Forms.ComboBox
    Friend WithEvents txtBookISBN As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents txtPress As System.Windows.Forms.TextBox
    Friend WithEvents btnClear As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.txtBookISBN = New System.Windows.Forms.TextBox
        Me.txtBookName = New System.Windows.Forms.TextBox
        Me.txtBookPrice = New System.Windows.Forms.TextBox
        Me.cmbBookType = New System.Windows.Forms.ComboBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.txtPress = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.txtAuthorName = New System.Windows.Forms.TextBox
        Me.dtpPressDate = New System.Windows.Forms.DateTimePicker
        Me.btnClear = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(40, 72)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(29, 17)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "名称"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(40, 152)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 17)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "所属种类"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(40, 224)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(29, 17)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "定价"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(40, 32)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(54, 17)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "书籍ISBN"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(40, 264)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(54, 17)
        Me.Label5.TabIndex = 4
        Me.Label5.Text = "出版日期"
        '
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(64, 328)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(75, 25)
        Me.btnAdd.TabIndex = 5
        Me.btnAdd.Text = "确定"
        '
        'btnCancel
        '
        Me.btnCancel.Location = New System.Drawing.Point(272, 328)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 25)
        Me.btnCancel.TabIndex = 6
        Me.btnCancel.Text = "取消"
        '
        'txtBookISBN
        '
        Me.txtBookISBN.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBookISBN.Location = New System.Drawing.Point(136, 28)
        Me.txtBookISBN.Name = "txtBookISBN"
        Me.txtBookISBN.Size = New System.Drawing.Size(211, 21)
        Me.txtBookISBN.TabIndex = 7
        Me.txtBookISBN.Text = ""
        '
        'txtBookName
        '
        Me.txtBookName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBookName.Location = New System.Drawing.Point(136, 66)
        Me.txtBookName.Name = "txtBookName"
        Me.txtBookName.Size = New System.Drawing.Size(211, 21)
        Me.txtBookName.TabIndex = 8
        Me.txtBookName.Text = ""
        '
        'txtBookPrice
        '
        Me.txtBookPrice.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBookPrice.Location = New System.Drawing.Point(136, 217)
        Me.txtBookPrice.Name = "txtBookPrice"
        Me.txtBookPrice.Size = New System.Drawing.Size(211, 21)
        Me.txtBookPrice.TabIndex = 9
        Me.txtBookPrice.Text = ""
        '
        'cmbBookType
        '
        Me.cmbBookType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbBookType.Items.AddRange(New Object() {""})
        Me.cmbBookType.Location = New System.Drawing.Point(136, 142)
        Me.cmbBookType.Name = "cmbBookType"
        Me.cmbBookType.Size = New System.Drawing.Size(211, 20)
        Me.cmbBookType.TabIndex = 11
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label7)
        Me.GroupBox1.Controls.Add(Me.txtPress)
        Me.GroupBox1.Controls.Add(Me.Label6)
        Me.GroupBox1.Controls.Add(Me.txtAuthorName)
        Me.GroupBox1.Controls.Add(Me.dtpPressDate)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Controls.Add(Me.txtBookPrice)
        Me.GroupBox1.Controls.Add(Me.txtBookISBN)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.txtBookName)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.cmbBookType)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(384, 304)
        Me.GroupBox1.TabIndex = 12
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "书籍信息"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(40, 184)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(42, 17)
        Me.Label7.TabIndex = 15
        Me.Label7.Text = "出版社"
        '
        'txtPress
        '
        Me.txtPress.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPress.Location = New System.Drawing.Point(136, 179)
        Me.txtPress.Name = "txtPress"
        Me.txtPress.Size = New System.Drawing.Size(211, 21)
        Me.txtPress.TabIndex = 16
        Me.txtPress.Text = ""
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(40, 112)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(29, 17)
        Me.Label6.TabIndex = 13
        Me.Label6.Text = "作者"
        '
        'txtAuthorName
        '
        Me.txtAuthorName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtAuthorName.Location = New System.Drawing.Point(136, 104)
        Me.txtAuthorName.Name = "txtAuthorName"
        Me.txtAuthorName.Size = New System.Drawing.Size(211, 21)
        Me.txtAuthorName.TabIndex = 14
        Me.txtAuthorName.Text = ""
        '
        'dtpPressDate
        '
        Me.dtpPressDate.Location = New System.Drawing.Point(136, 255)
        Me.dtpPressDate.Name = "dtpPressDate"
        Me.dtpPressDate.Size = New System.Drawing.Size(211, 21)
        Me.dtpPressDate.TabIndex = 12
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(168, 328)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(75, 25)
        Me.btnClear.TabIndex = 13
        Me.btnClear.Text = "清空"
        '
        'BookAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(416, 365)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnAdd)
        Me.Name = "BookAdd"
        Me.Text = "书籍添加"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        '校验用户输入信息
        If Not checkData() Then
            '如果有不合法数据,退出新增过程 
            Exit Sub
        End If
        '生成sql语句
        Dim strSQL As String
        strSQL = "Insert into BookInfo(ISBN , NAME , AUTHOR , TYPE , PRESS , PRICE , PRESSDATE ) values("
        strSQL = strSQL & "'" & txtBookISBN.Text.Trim & "',"
        strSQL = strSQL & "'" & txtBookName.Text.Trim & "',"
        strSQL = strSQL & "'" & txtAuthorName.Text.Trim & "',"
        strSQL = strSQL & "'" & cmbBookType.SelectedValue & "',"
        strSQL = strSQL & "'" & txtPress.Text.Trim & "',"
        strSQL = strSQL & "'" & txtBookPrice.Text.Trim & "',"
        strSQL = strSQL & "'" & dtpPressDate.Value.Date & "')"
        Dim ret As Boolean
        '将新信息插入到数据库
        ret = DBManager.executeNonQuery(strSQL)
        If ret Then
            '新增成功后,清空输入框,方便下一步操作
            ClearTextBox()
            '给出提示信息
            InfoMSG("成功添加!")
        Else
            '给出错误信息
            ErrorMSG("添加失败!")
        End If
    End Sub

    '退出窗体
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    '清空文本框信息
    Sub ClearTextBox()
        txtBookISBN.Text = ""
        txtBookName.Text = ""
        txtAuthorName.Text = ""
        cmbBookType.Text = ""
        txtPress.Text = ""
        txtBookPrice.Text = ""
    End Sub

    '窗体启动时加载对应数据
    Private Sub BookAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim mydt As DataSet
            Dim strSQL As String
            '生成SQL语句
            strSQL = "select code , name from BookType"
            '得到结果集
            mydt = DBManager.executeSelectQuery(strSQL, "BookType")
            '初始化书籍类型数据
            cmbBookType.DataSource = mydt.Tables("BookType")
            cmbBookType.DisplayMember = "name"
            cmbBookType.ValueMember = "code"
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Function checkData() As Boolean
        '判断ISBN是否为空
        If txtBookISBN.Text.Trim = "" Then
            ErrorMSG("ISBN不允许为空!")
            Return False
        End If
        '判断书名是否为空
        If txtBookName.Text.Trim = "" Then
            ErrorMSG("书名不允许为空!")
            Return False
        End If
        '判断作者是否为空
        If txtAuthorName.Text.Trim = "" Then
            ErrorMSG("作者不允许为空!")
            Return False
        End If
        '判断书籍类别是否为空
        If cmbBookType.Text.Trim = "" Then
            ErrorMSG("书籍种类不允许为空!")
            Return False
        End If
        '判断出版社是否为空
        If txtPress.Text.Trim = "" Then
            ErrorMSG("出版社不允许为空!")
            Return False
        End If
        '判断定价是否为空
        If txtBookPrice.Text.Trim = "" Then
            ErrorMSG("定价不允许为空!")
            Return False
        Else
            '判断定价是否为数字
            If Not IsNumeric(txtBookPrice.Text.Trim) Then
                ErrorMSG("定价必须为数字!")
                Return False
            End If
        End If
        Return True
    End Function

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        '清空信息项输入框
        ClearTextBox()
    End Sub
End Class

⌨️ 快捷键说明

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