?? class.vb
字號:
Public Class frmClass
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 btnAdd As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents btnModify As System.Windows.Forms.Button
Friend WithEvents btnDelete As System.Windows.Forms.Button
Friend WithEvents btnConfirm As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents stbClass As System.Windows.Forms.StatusBar
Friend WithEvents cmbName As System.Windows.Forms.ComboBox
Friend WithEvents txtCharge As System.Windows.Forms.TextBox
Friend WithEvents txtMonitor As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.stbClass = New System.Windows.Forms.StatusBar
Me.cmbName = New System.Windows.Forms.ComboBox
Me.btnAdd = New System.Windows.Forms.Button
Me.txtCharge = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtMonitor = New System.Windows.Forms.TextBox
Me.btnModify = New System.Windows.Forms.Button
Me.btnDelete = New System.Windows.Forms.Button
Me.btnConfirm = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
Me.Label5 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'stbClass
'
Me.stbClass.Location = New System.Drawing.Point(0, 149)
Me.stbClass.Name = "stbClass"
Me.stbClass.Size = New System.Drawing.Size(248, 24)
Me.stbClass.TabIndex = 25
'
'cmbName
'
Me.cmbName.Location = New System.Drawing.Point(88, 16)
Me.cmbName.Name = "cmbName"
Me.cmbName.Size = New System.Drawing.Size(136, 20)
Me.cmbName.TabIndex = 0
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(16, 112)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(40, 24)
Me.btnAdd.TabIndex = 3
Me.btnAdd.Text = "增加"
'
'txtCharge
'
Me.txtCharge.Location = New System.Drawing.Point(88, 71)
Me.txtCharge.Name = "txtCharge"
Me.txtCharge.Size = New System.Drawing.Size(136, 21)
Me.txtCharge.TabIndex = 2
Me.txtCharge.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 44)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 8
Me.Label1.Text = "班長"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 72)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 9
Me.Label2.Text = "班主任"
'
'txtMonitor
'
Me.txtMonitor.Location = New System.Drawing.Point(88, 43)
Me.txtMonitor.Name = "txtMonitor"
Me.txtMonitor.Size = New System.Drawing.Size(136, 21)
Me.txtMonitor.TabIndex = 1
Me.txtMonitor.Text = ""
'
'btnModify
'
Me.btnModify.Location = New System.Drawing.Point(58, 112)
Me.btnModify.Name = "btnModify"
Me.btnModify.Size = New System.Drawing.Size(40, 24)
Me.btnModify.TabIndex = 4
Me.btnModify.Text = "修改"
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(100, 112)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(40, 24)
Me.btnDelete.TabIndex = 5
Me.btnDelete.Text = "刪除"
'
'btnConfirm
'
Me.btnConfirm.Location = New System.Drawing.Point(142, 112)
Me.btnConfirm.Name = "btnConfirm"
Me.btnConfirm.Size = New System.Drawing.Size(40, 24)
Me.btnConfirm.TabIndex = 6
Me.btnConfirm.Text = "確定"
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(184, 112)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(40, 24)
Me.btnCancel.TabIndex = 7
Me.btnCancel.Text = "取消"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(16, 16)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(56, 16)
Me.Label5.TabIndex = 12
Me.Label5.Text = "班級名稱"
'
'frmClass
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(248, 173)
Me.Controls.Add(Me.stbClass)
Me.Controls.Add(Me.cmbName)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.txtCharge)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.txtMonitor)
Me.Controls.Add(Me.btnModify)
Me.Controls.Add(Me.btnDelete)
Me.Controls.Add(Me.btnConfirm)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.Label5)
Me.MaximizeBox = False
Me.Name = "frmClass"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "班級管理"
Me.ResumeLayout(False)
End Sub
#End Region
Private myDataSet As New DataSet
Private index As Integer = -1
Private Sub frmClass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
If OleConn.SelectQuery("select * from 班級信息", myDataSet) Then
If myDataSet.Tables.Count > 0 Then
For i = 0 To myDataSet.Tables(0).Rows.Count - 1
cmbName.Items.Add(myDataSet.Tables(0).Rows(i).Item("班名"))
Next
stbClass.Text = "就緒"
Else
stbClass.Text = "查詢班級信息表失敗"
End If
Else
stbClass.Text = "查詢班級信息表失敗"
End If
End Sub
Private Sub cmbName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbName.SelectedIndexChanged
index = cmbName.SelectedIndex
Dim dr As DataRow()
Dim str As String
Try
str = "班名='" & cmbName.SelectedItem & "'"
dr = myDataSet.Tables(0).Select(str)
txtMonitor.Text = Trim(dr(0).Item("班長"))
txtCharge.Text = Trim(dr(0).Item("班主任"))
stbClass.Text = "就緒"
Catch ex As Exception
DisplayError(ex)
End Try
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim succ As Boolean = True
If cmbName.Text <> "" Then
Try
Dim dr As DataRow = myDataSet.Tables(0).NewRow
dr("班名") = cmbName.Text
dr("班長") = txtMonitor.Text
dr("班主任") = txtCharge.Text
myDataSet.Tables(0).Rows.Add(dr)
cmbName.Items.Add(cmbName.Text)
cmbName.SelectedItem = cmbName.Text
stbClass.Text = "增加成功"
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbClass.Text = "增加成功"
Else
stbClass.Text = "增加失敗"
End If
Else
stbClass.Text = "班級名稱不能為空"
End If
End Sub
Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click
Dim succ As Boolean = True
If cmbName.Text <> "" Then
If index >= 0 Then
Dim dr As DataRow()
Dim str As String
Try
str = "班名='" & cmbName.Items.Item(index) & "'"
dr = myDataSet.Tables(0).Select(str)
dr(0).BeginEdit()
dr(0).Item("班名") = cmbName.Text
dr(0).Item("班長") = txtMonitor.Text
dr(0).Item("班主任") = txtCharge.Text
dr(0).EndEdit()
cmbName.Items.Item(index) = cmbName.Text
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbClass.Text = "修改成功"
Else
stbClass.Text = "修改失敗"
End If
Else
stbClass.Text = "請先選擇要修改的記錄"
End If
Else
stbClass.Text = "班級名稱不能為空"
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim succ As Boolean = True
If cmbName.Text <> "" Then
If index >= 0 Then
Dim dr As DataRow()
Dim str As String
Try
str = "班名='" & cmbName.Items.Item(index) & "'"
dr = myDataSet.Tables(0).Select(str)
dr(0).Delete()
cmbName.Items.RemoveAt(index)
cmbName.Text = ""
txtMonitor.Text = ""
txtCharge.Text = ""
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbClass.Text = "修改成功"
Else
stbClass.Text = "修改失敗"
End If
Else
stbClass.Text = "請先選擇要刪除的記錄"
End If
Else
stbClass.Text = "班級名稱不能為空"
End If
End Sub
Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
Dim succ As Boolean = True
Try
OleConn.UpDate(myDataSet)
myDataSet.AcceptChanges()
Catch ex As Exception
succ = False
End Try
If succ Then
stbClass.Text = "更新數據庫成功"
Else
stbClass.Text = "更新數據庫失敗"
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Dim i As Integer
myDataSet.RejectChanges()
For i = 0 To myDataSet.Tables(0).Rows.Count - 1
cmbName.Items.Add(myDataSet.Tables(0).Rows(i).Item("班名"))
Next
stbClass.Text = "你已經取消了所有的改動"
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -