📄 readeradd.vb
字号:
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 btnClear As System.Windows.Forms.Button
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 Label2 As System.Windows.Forms.Label
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents label6 As System.Windows.Forms.Label
Friend WithEvents cmbGender As System.Windows.Forms.ComboBox
Friend WithEvents txtMaxTime As System.Windows.Forms.TextBox
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents txtMaxNum As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnClear = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.label6 = New System.Windows.Forms.Label
Me.txtMaxTime = New System.Windows.Forms.TextBox
Me.txtName = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.txtMaxNum = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.cmbGender = New System.Windows.Forms.ComboBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnAdd = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'btnClear
'
Me.btnClear.Location = New System.Drawing.Point(144, 208)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(75, 25)
Me.btnClear.TabIndex = 17
Me.btnClear.Text = "清空"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.label6)
Me.GroupBox1.Controls.Add(Me.txtMaxTime)
Me.GroupBox1.Controls.Add(Me.txtName)
Me.GroupBox1.Controls.Add(Me.Label4)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.txtMaxNum)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.cmbGender)
Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(320, 176)
Me.GroupBox1.TabIndex = 16
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "读者信息"
'
'label6
'
Me.label6.AutoSize = True
Me.label6.Location = New System.Drawing.Point(40, 104)
Me.label6.Name = "label6"
Me.label6.Size = New System.Drawing.Size(79, 17)
Me.label6.TabIndex = 13
Me.label6.Text = "最大借阅册数"
'
'txtMaxTime
'
Me.txtMaxTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtMaxTime.Location = New System.Drawing.Point(144, 128)
Me.txtMaxTime.Name = "txtMaxTime"
Me.txtMaxTime.Size = New System.Drawing.Size(128, 21)
Me.txtMaxTime.TabIndex = 14
Me.txtMaxTime.Text = ""
'
'txtName
'
Me.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtName.Location = New System.Drawing.Point(144, 24)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(128, 21)
Me.txtName.TabIndex = 7
Me.txtName.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(29, 17)
Me.Label4.TabIndex = 3
Me.Label4.Text = "姓名"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(40, 64)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(29, 17)
Me.Label1.TabIndex = 0
Me.Label1.Text = "性别"
'
'txtMaxNum
'
Me.txtMaxNum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtMaxNum.Location = New System.Drawing.Point(144, 96)
Me.txtMaxNum.Name = "txtMaxNum"
Me.txtMaxNum.Size = New System.Drawing.Size(128, 21)
Me.txtMaxNum.TabIndex = 8
Me.txtMaxNum.Text = ""
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(40, 136)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(79, 17)
Me.Label2.TabIndex = 1
Me.Label2.Text = "最大借阅天数"
'
'cmbGender
'
Me.cmbGender.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbGender.Items.AddRange(New Object() {"", "男", "女"})
Me.cmbGender.Location = New System.Drawing.Point(144, 56)
Me.cmbGender.Name = "cmbGender"
Me.cmbGender.Size = New System.Drawing.Size(128, 20)
Me.cmbGender.TabIndex = 11
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(240, 208)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(75, 25)
Me.btnCancel.TabIndex = 15
Me.btnCancel.Text = "取消"
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(48, 208)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(75, 25)
Me.btnAdd.TabIndex = 14
Me.btnAdd.Text = "确定"
'
'ReaderAdd
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(352, 245)
Me.Controls.Add(Me.btnClear)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnAdd)
Me.Name = "ReaderAdd"
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
'变量定义
Dim strSQL As String
Dim ret As Boolean
Dim newID As Long
'得到新ID
newID = getID()
'生成sql语句
strSQL = "Insert into ReaderInfo(ID , Name , Gender , MaxNumber , MaxTime ) values("
strSQL = strSQL & "'" & newID & "',"
strSQL = strSQL & "'" & txtName.Text.Trim & "',"
strSQL = strSQL & "'" & cmbGender.Text.Trim & "',"
strSQL = strSQL & "'" & txtMaxNum.Text.Trim & "',"
strSQL = strSQL & "'" & txtMaxTime.Text.Trim & "')"
'执行SQL语句,将新信息插入到数据库
ret = DBManager.executeNonQuery(strSQL)
If ret Then
'若新增成功,则清空输入框,方便下一步操作
ClearTextBox()
'给出提示信息
InfoMSG("成功添加!")
Else
'若不成功,给出错误信息
ErrorMSG("添加失败!")
End If
End Sub
Private Function checkData() As Boolean
'判断读者姓名是否为空
If txtName.Text.Trim = "" Then
ErrorMSG("读者姓名不允许为空!")
Return False
End If
'判断读者性别是否为空
If cmbGender.Text.Trim = "" Then
ErrorMSG("读者性别不允许为空!")
Return False
End If
'判断最大借阅册数是否为空
If txtMaxNum.Text.Trim = "" Then
ErrorMSG("最大借阅册数不允许为空!")
Return False
Else
'判断最大借阅册数是否为数字
If Not IsNumeric(txtMaxNum.Text.Trim) Then
ErrorMSG("最大借阅册数必须为数字!")
Return False
End If
End If
'判断最大借阅天数是否为空
If txtMaxTime.Text.Trim = "" Then
ErrorMSG("最大借阅天数不允许为空!")
Return False
Else
'判断最大借阅天数是否为数字
If Not IsNumeric(txtMaxTime.Text.Trim) Then
ErrorMSG("最大借阅天数必须为数字!")
Return False
End If
End If
Return True
End Function
Sub ClearTextBox()
txtName.Text = ""
cmbGender.Text = ""
txtMaxNum.Text = ""
txtMaxTime.Text = ""
End Sub
Private Function getID() As Long
Dim id As Long
Dim strSQL As String
Dim mydt As DataSet
'生成执行查询操作的SQL语句
strSQL = "select ID from ReaderInfo order by ID asc"
'得到结果集
mydt = executeSelectQuery(strSQL, "select")
'取得数据
If mydt Is Nothing OrElse mydt.Tables("select").Rows.Count = 0 Then
id = 1
Else
'得到最大ID
id = mydt.Tables("select").Rows(mydt.Tables("select").Rows.Count - 1).Item("ID")
'得到新ID
id = id + 1
End If
Return id
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ClearTextBox()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -