📄 frmcatlogue.vb
字号:
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Data.OleDb
Public Class frmCatlogue
Inherits System.Windows.Forms.Form
Dim sqlstr As String
Dim Days() As Integer
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
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 Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
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 ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button4 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.GroupBox2 = New System.Windows.Forms.GroupBox()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(224, Byte), CType(192, Byte))
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button4, Me.TextBox2, Me.GroupBox2, Me.Label1})
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(304, 223)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
'
'Button4
'
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button4.ForeColor = System.Drawing.Color.Navy
Me.Button4.Location = New System.Drawing.Point(216, 48)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 24)
Me.Button4.TabIndex = 5
Me.Button4.Text = "编目"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(112, 24)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(168, 21)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = ""
'
'GroupBox2
'
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.ComboBox1, Me.Button3, Me.Button2, Me.Button1, Me.Label3, Me.Label2})
Me.GroupBox2.Location = New System.Drawing.Point(8, 80)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(288, 136)
Me.GroupBox2.TabIndex = 3
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "图书类别信息"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(104, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(168, 21)
Me.TextBox1.TabIndex = 7
Me.TextBox1.Text = ""
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(104, 32)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(168, 20)
Me.ComboBox1.TabIndex = 6
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.ForeColor = System.Drawing.Color.Navy
Me.Button3.Location = New System.Drawing.Point(232, 104)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 24)
Me.Button3.TabIndex = 5
Me.Button3.Text = "更新"
'
'Button2
'
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.ForeColor = System.Drawing.Color.Navy
Me.Button2.Location = New System.Drawing.Point(176, 104)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 24)
Me.Button2.TabIndex = 4
Me.Button2.Text = "删除"
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.ForeColor = System.Drawing.Color.Navy
Me.Button1.Location = New System.Drawing.Point(120, 104)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 24)
Me.Button1.TabIndex = 3
Me.Button1.Text = "添加"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 69)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(96, 24)
Me.Label3.TabIndex = 2
Me.Label3.Text = "借阅天数"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 28)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(96, 24)
Me.Label2.TabIndex = 1
Me.Label2.Text = "图书类别"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 21)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "图书 ISBN 号"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'frmCatlogue
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(304, 223)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "frmCatlogue"
Me.Text = "图书编目管理"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmCatlogue_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
Public Sub LoadData()
Dim count As Integer
Dim i As Integer
sqlstr = "SELECT * FROM BorrowType "
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
If Not ds Is Nothing Then
count = ds.Tables(0).Rows.Count
ReDim Days(count)
Me.ComboBox1.Items.Clear()
For i = 0 To count - 1
Dim temp As BorrowType
temp.Type = Trim(ds.Tables(0).Rows(i)("Type"))
temp.Days = CInt(Val(ds.Tables(0).Rows(i)("BorrowDays")))
Me.ComboBox1.Items.Add(temp.Type)
Days(i) = temp.Days
Next
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim i As Integer
i = Me.ComboBox1.SelectedIndex
If i < 0 Then
Exit Sub
End If
Me.TextBox1.Text = Days(i)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
Dim isbn As String
Dim type As String
type = Me.ComboBox1.Text
isbn = Trim(Me.TextBox2.Text)
If isbn = "" Then
Exit Sub
End If
sqlstr = "SELECT * FROM BookInfo WHERE ISBN='" & isbn & "'"
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
If Not ds Is Nothing Then
MsgBox("对不起,没有该图书信息。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "图书不存在")
Exit Sub
End If
sqlstr = "UPDATE BookInfo SET Type='" & type & "' WHERE ISBN='" & isbn & "'"
If UpdateDataBase(sqlstr) = True Then
MsgBox("祝贺你,图书编目成功。", MsgBoxStyle.OKOnly + _
MsgBoxStyle.Information, "编目成功")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim type As New BorrowType()
type.Days = CInt(Val(Me.ComboBox1.SelectedItem))
type.Type = Trim(Me.ComboBox1.Text)
sqlstr = "INSERT INTO BorrowType (Type,BorrowDays) VALUES " & _
"('" & type.Type & "','" & type.Days & "') "
UpdateDataBase(sqlstr)
LoadData()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim type As String = Trim(Me.ComboBox1.SelectedItem)
sqlstr = "DELETE FROM BorrowType WHERE Type='" & type & "'"
UpdateDataBase(sqlstr)
LoadData()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Dim type As String = Trim(Me.ComboBox1.SelectedItem)
Dim days As Integer = CInt(Val(Me.TextBox1.Text))
sqlstr = "UPDATE BorrowType SET BorrowDays = " & _
"'" & days & "' WHERE Type='" & type & "'"
UpdateDataBase(sqlstr)
LoadData()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -