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

📄 readeradd.vb

📁 图书管理系统
💻 VB
字号:
Imports System.Data.SqlClient
Public Class ReaderAdd
    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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    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 Panel1 As System.Windows.Forms.Panel
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.RadioButton2 = New System.Windows.Forms.RadioButton
        Me.RadioButton1 = New System.Windows.Forms.RadioButton
        Me.TextBox4 = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Panel1)
        Me.GroupBox1.Controls.Add(Me.TextBox4)
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Controls.Add(Me.TextBox3)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.TextBox2)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(40, 40)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(392, 296)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "增加读者"
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.RadioButton2)
        Me.Panel1.Controls.Add(Me.RadioButton1)
        Me.Panel1.Location = New System.Drawing.Point(168, 120)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(176, 32)
        Me.Panel1.TabIndex = 11
        '
        'RadioButton2
        '
        Me.RadioButton2.Location = New System.Drawing.Point(128, 8)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.TabIndex = 1
        Me.RadioButton2.Text = "女"
        '
        'RadioButton1
        '
        Me.RadioButton1.Location = New System.Drawing.Point(8, 8)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.TabIndex = 0
        Me.RadioButton1.Text = "男"
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(168, 224)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(176, 21)
        Me.TextBox4.TabIndex = 10
        Me.TextBox4.Text = ""
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(24, 224)
        Me.Label5.Name = "Label5"
        Me.Label5.TabIndex = 9
        Me.Label5.Text = "最大借阅天数"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(168, 176)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(176, 21)
        Me.TextBox3.TabIndex = 8
        Me.TextBox3.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(24, 176)
        Me.Label4.Name = "Label4"
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "最大借阅册数"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(168, 80)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(176, 21)
        Me.TextBox2.TabIndex = 6
        Me.TextBox2.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "姓        名"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(24, 128)
        Me.Label3.Name = "Label3"
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "性        别"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(168, 40)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(176, 21)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 40)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "学        号"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(64, 376)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "增加"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(200, 376)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "清空"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(344, 376)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 3
        Me.Button3.Text = "退出"
        '
        'ReaderAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.ClientSize = New System.Drawing.Size(488, 437)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.Name = "ReaderAdd"
        Me.Text = "增加读者"
        Me.GroupBox1.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Function CheckData() As Boolean
        If TextBox1.Text = "" Then
            MessageBox.Show("学号选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        Else
            If IsNumeric(TextBox1.Text) = False Then
                MessageBox.Show("学号选项必须为整数值", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Return False
                Exit Function
            End If
        End If
        If TextBox2.Text = "" Then
            MessageBox.Show("姓名选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        End If
        If TextBox3.Text = "" Then
            MessageBox.Show("最大借阅册数选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        Else
            If IsNumeric(TextBox3.Text) = False Then
                MessageBox.Show("最大借阅数选项的输入数据不是整数!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox3.Text = ""
                TextBox3.Focus()
                Return False
                Exit Function
            End If
        End If
        If TextBox4.Text = "" Then
            MessageBox.Show(" 最大借阅天数不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        Else
            If IsNumeric(TextBox4.Text) = False Then
                MessageBox.Show("最大借阅天数选项的输入数据不是整数!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox4.Text = ""
                TextBox4.Focus()
                Return False
                Exit Function
            End If
        End If
        Return True
    End Function

    Private Sub ReaderAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RadioButton1.Checked = True
        RadioButton2.Checked = False
    End Sub
    Private Function GetHightID() As Integer
        '获取最大的ID
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim myda1 As New SqlDataAdapter("select * from Students", mycon)
            Dim myset1 As New DataSet
            Dim ID As Integer
            myda1.Fill(myset1, "Students")
            If myset1 Is Nothing OrElse myset1.Tables("Students").Rows.Count = 0 Then
                ID = 1
                Return ID
            Else
                '得大最大的ID
                ID = myset1.Tables("Students").Rows(myset1.Tables("Students").Rows.Count - 1).Item("SID")
                Return ID
            End If
            mycon.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function
    Private Sub ClearData()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox1.Focus()
    End Sub
    Private Function IsCheckSno() As Boolean
        '从数据库中将所有内容取出来与TextBox1中的内容比较
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim myreader1 As SqlDataReader
            Dim mycom1 As New SqlCommand("select *from Students", mycon)
            myreader1 = mycom1.ExecuteReader
            Dim Sno As String = TextBox1.Text
            While myreader1.Read
                If Sno = myreader1("Sno") Then
                    myreader1.Close()
                    Return False
                    Exit Function
                End If
            End While
            myreader1.Close()
            mycon.Close()
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '增加按钮的代码
        '首先检验数据的合法性
        If CheckData() = False Then
            Exit Sub
        End If
        Try
            Dim ID As New SqlParameter("@ID", SqlDbType.Int, 4)
            ID.Value = GetHightID() + 1
            Dim Sex As New SqlParameter("@Sex", SqlDbType.VarChar, 2)
            If RadioButton1.Checked = True Then
                Sex.Value = RadioButton1.Text
            Else
                Sex.Value = RadioButton2.Text
            End If
            If IsCheckSno() = False Then
                MessageBox.Show("你输入的学号不正确,请重新输入", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox1.Text = ""
                Exit Sub
            End If
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim sqlstr As String = "insert into Students(SID,Sno,SName,Sex,MaxNumber,MaxDays,RemainNumber) Values(@ID,'" & TextBox1.Text & "','" & TextBox2.Text & "',@Sex,'" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox3.Text & "')"
            Dim mycom1 As New SqlCommand(sqlstr, mycon)
            mycom1.Parameters.Add(ID)
            mycom1.Parameters.Add(Sex)
            mycom1.ExecuteNonQuery()
            MessageBox.Show("增加读者成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information)
            mycon.Close()
            Call ClearData()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '清空按钮的代码()
        Call ClearData()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '退出按钮的代码
        Me.Close()
    End Sub
End Class

⌨️ 快捷键说明

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