?? bookadd.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 + -