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

📄 addreader.vb

📁 图书借阅系统
💻 VB
字号:
Public Class frmAddReader
    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 txtId As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    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 txtAddr As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents txtDept As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents txtDemo As System.Windows.Forms.TextBox
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents txtTel As System.Windows.Forms.TextBox
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnClose As System.Windows.Forms.Button
    Friend WithEvents cmbSex As System.Windows.Forms.ComboBox
    Friend WithEvents cmbType As System.Windows.Forms.ComboBox
    Friend WithEvents btnClear As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.cmbSex = New System.Windows.Forms.ComboBox
        Me.txtId = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtName = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.txtAddr = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.txtDept = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.txtDemo = New System.Windows.Forms.TextBox
        Me.Label8 = New System.Windows.Forms.Label
        Me.txtTel = New System.Windows.Forms.TextBox
        Me.cmbType = New System.Windows.Forms.ComboBox
        Me.btnSave = New System.Windows.Forms.Button
        Me.btnClose = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.cmbSex)
        Me.GroupBox1.Controls.Add(Me.txtId)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.txtName)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Controls.Add(Me.txtAddr)
        Me.GroupBox1.Controls.Add(Me.Label6)
        Me.GroupBox1.Controls.Add(Me.txtDept)
        Me.GroupBox1.Controls.Add(Me.Label7)
        Me.GroupBox1.Controls.Add(Me.txtDemo)
        Me.GroupBox1.Controls.Add(Me.Label8)
        Me.GroupBox1.Controls.Add(Me.txtTel)
        Me.GroupBox1.Controls.Add(Me.cmbType)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(416, 208)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "添加读者"
        '
        'cmbSex
        '
        Me.cmbSex.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbSex.Items.AddRange(New Object() {"男", "女"})
        Me.cmbSex.Location = New System.Drawing.Point(80, 100)
        Me.cmbSex.Name = "cmbSex"
        Me.cmbSex.Size = New System.Drawing.Size(100, 20)
        Me.cmbSex.TabIndex = 2
        '
        'txtId
        '
        Me.txtId.Location = New System.Drawing.Point(80, 32)
        Me.txtId.Name = "txtId"
        Me.txtId.TabIndex = 0
        Me.txtId.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(32, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "学号"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 66)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(32, 23)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "姓名"
        '
        'txtName
        '
        Me.txtName.Location = New System.Drawing.Point(80, 66)
        Me.txtName.Name = "txtName"
        Me.txtName.TabIndex = 1
        Me.txtName.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 134)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(32, 23)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "类别"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 100)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(32, 23)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "性别"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(192, 32)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(56, 23)
        Me.Label5.TabIndex = 0
        Me.Label5.Text = "宿舍"
        '
        'txtAddr
        '
        Me.txtAddr.Location = New System.Drawing.Point(256, 32)
        Me.txtAddr.Name = "txtAddr"
        Me.txtAddr.Size = New System.Drawing.Size(144, 21)
        Me.txtAddr.TabIndex = 5
        Me.txtAddr.Text = "无"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(192, 66)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(56, 23)
        Me.Label6.TabIndex = 0
        Me.Label6.Text = "系别"
        '
        'txtDept
        '
        Me.txtDept.Location = New System.Drawing.Point(256, 66)
        Me.txtDept.Name = "txtDept"
        Me.txtDept.Size = New System.Drawing.Size(144, 21)
        Me.txtDept.TabIndex = 6
        Me.txtDept.Text = "无"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(192, 100)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(56, 23)
        Me.Label7.TabIndex = 0
        Me.Label7.Text = "备注"
        '
        'txtDemo
        '
        Me.txtDemo.Location = New System.Drawing.Point(256, 100)
        Me.txtDemo.Multiline = True
        Me.txtDemo.Name = "txtDemo"
        Me.txtDemo.Size = New System.Drawing.Size(144, 92)
        Me.txtDemo.TabIndex = 7
        Me.txtDemo.Text = "无"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(16, 168)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(56, 23)
        Me.Label8.TabIndex = 0
        Me.Label8.Text = "联系电话"
        '
        'txtTel
        '
        Me.txtTel.Location = New System.Drawing.Point(80, 166)
        Me.txtTel.Name = "txtTel"
        Me.txtTel.TabIndex = 4
        Me.txtTel.Text = ""
        '
        'cmbType
        '
        Me.cmbType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbType.Location = New System.Drawing.Point(80, 133)
        Me.cmbType.Name = "cmbType"
        Me.cmbType.Size = New System.Drawing.Size(100, 20)
        Me.cmbType.TabIndex = 3
        '
        'btnSave
        '
        Me.btnSave.Location = New System.Drawing.Point(8, 232)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(48, 32)
        Me.btnSave.TabIndex = 1
        Me.btnSave.Text = "保存"
        '
        'btnClose
        '
        Me.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnClose.Location = New System.Drawing.Point(376, 232)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(48, 32)
        Me.btnClose.TabIndex = 2
        Me.btnClose.Text = "关闭"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(192, 232)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(48, 32)
        Me.btnClear.TabIndex = 1
        Me.btnClear.Text = "清空"
        '
        'frmAddReader
        '
        Me.AcceptButton = Me.btnSave
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.CancelButton = Me.btnClose
        Me.ClientSize = New System.Drawing.Size(432, 269)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnClear)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.Name = "frmAddReader"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "添加读者"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private typeds As New DataSet

    Private Sub frmAddReader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        cmbSex.SelectedIndex = 0
        Try
            If OleConn.SelectQuery("select * from 读者类别", typeds) Then
                If typeds.Tables.Count > 0 Then
                    For i = 0 To typeds.Tables(0).Rows.Count - 1
                        cmbType.Items.Add(typeds.Tables(0).Rows(i).Item(0))
                    Next
                End If
            Else
                MsgBox("查询读者类别表失败")
            End If
        Catch ex As Exception
            OleConn.DisplayError(ex)
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtId.Text = "" Then
            MsgBox("请输入读者学号")
            txtId.Focus()
        ElseIf txtName.Text = "" Then
            MsgBox("请输入读者姓名")
            txtName.Focus()
        ElseIf cmbSex.SelectedIndex < 0 Then
            MsgBox("请选择读者性别")
            cmbSex.Focus()
        ElseIf cmbType.SelectedIndex < 0 Then
            MsgBox("请选择读者类别")
            cmbType.Focus()
        ElseIf txtTel.Text = "" Then
            MsgBox("请输入读者联系电话")
            txtTel.Focus()
        ElseIf txtAddr.Text = "" Then
            MsgBox("请输入读者宿舍")
            txtAddr.Focus()
        ElseIf txtDept.Text = "" Then
            MsgBox("请输入读者系别")
            txtDept.Focus()
        ElseIf txtDemo.Text = "" Then
            MsgBox("请输入读者备注")
            txtDemo.Focus()
        Else
            Dim typedr As DataRow() = typeds.Tables(0).Select("类别='" & cmbType.SelectedItem & "'")

            Dim str As String = "INSERT INTO 读者(学号, 姓名, 性别, 类别, 联系电话, 宿舍, 系别, 备注, 登记日期, 借书期限, 可借书数) VALUES('" & _
              txtId.Text & "', '" & txtName.Text & "', '" & cmbSex.SelectedItem & "', '" & cmbType.SelectedItem & _
              "', '" & txtTel.Text & "', '" & txtAddr.Text & "', '" & txtDept.Text & "', '" & _
              txtDemo.Text & "', '" & Date.Now.ToShortDateString & "'," & typedr(0).Item("借书期限") & ", " & typedr(0).Item("可借书数") & ")"
            Try
                OleConn.InsertQuery(str)
                txtId.Text = ""
                txtName.Text = ""
                txtId.Focus()
            Catch ex As Exception
                OleConn.DisplayError(ex)
            End Try
        End If
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtId.Text = ""
        txtName.Text = ""
        txtTel.Text = ""
        txtAddr.Text = ""
        txtDept.Text = ""
        txtDemo.Text = ""
        cmbSex.SelectedIndex = -1
        cmbType.SelectedIndex = -1
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class

⌨️ 快捷键说明

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