?? college.vb
字號(hào):
Public Class frmCollege
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
Public Sub New()
MyBase.New()
'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent()
'在 InitializeComponent() 調(diào)用之后添加任何初始化
End Sub
'窗體重寫(xiě) 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 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下過(guò)程是 Windows 窗體設(shè)計(jì)器所必需的
'可以使用 Windows 窗體設(shè)計(jì)器修改此過(guò)程。
'不要使用代碼編輯器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtDean As System.Windows.Forms.TextBox
Friend WithEvents txtSecretary As System.Windows.Forms.TextBox
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 stbCollege As System.Windows.Forms.StatusBar
Friend WithEvents cmbName As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.btnAdd = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.txtDean = New System.Windows.Forms.TextBox
Me.txtSecretary = 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.stbCollege = New System.Windows.Forms.StatusBar
Me.cmbName = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 23)
Me.Label1.TabIndex = 0
Me.Label1.Text = "學(xué)院名稱(chēng)"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(24, 136)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(40, 23)
Me.btnAdd.TabIndex = 2
Me.btnAdd.Text = "增加"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 23)
Me.Label2.TabIndex = 0
Me.Label2.Text = "院長(zhǎng)"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(24, 96)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 23)
Me.Label3.TabIndex = 0
Me.Label3.Text = "教務(wù)秘書(shū)"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtDean
'
Me.txtDean.Location = New System.Drawing.Point(96, 60)
Me.txtDean.Name = "txtDean"
Me.txtDean.Size = New System.Drawing.Size(136, 21)
Me.txtDean.TabIndex = 3
Me.txtDean.Text = ""
'
'txtSecretary
'
Me.txtSecretary.Location = New System.Drawing.Point(96, 96)
Me.txtSecretary.Name = "txtSecretary"
Me.txtSecretary.Size = New System.Drawing.Size(136, 21)
Me.txtSecretary.TabIndex = 3
Me.txtSecretary.Text = ""
'
'btnModify
'
Me.btnModify.Location = New System.Drawing.Point(66, 136)
Me.btnModify.Name = "btnModify"
Me.btnModify.Size = New System.Drawing.Size(40, 23)
Me.btnModify.TabIndex = 2
Me.btnModify.Text = "修改"
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(108, 136)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(40, 23)
Me.btnDelete.TabIndex = 2
Me.btnDelete.Text = "刪除"
'
'btnConfirm
'
Me.btnConfirm.Location = New System.Drawing.Point(150, 136)
Me.btnConfirm.Name = "btnConfirm"
Me.btnConfirm.Size = New System.Drawing.Size(40, 23)
Me.btnConfirm.TabIndex = 2
Me.btnConfirm.Text = "確定"
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(192, 136)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(40, 23)
Me.btnCancel.TabIndex = 2
Me.btnCancel.Text = "取消"
'
'stbCollege
'
Me.stbCollege.Location = New System.Drawing.Point(0, 181)
Me.stbCollege.Name = "stbCollege"
Me.stbCollege.Size = New System.Drawing.Size(264, 16)
Me.stbCollege.TabIndex = 4
'
'cmbName
'
Me.cmbName.Location = New System.Drawing.Point(96, 24)
Me.cmbName.Name = "cmbName"
Me.cmbName.Size = New System.Drawing.Size(136, 20)
Me.cmbName.TabIndex = 5
'
'frmCollege
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(264, 197)
Me.Controls.Add(Me.cmbName)
Me.Controls.Add(Me.stbCollege)
Me.Controls.Add(Me.txtDean)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtSecretary)
Me.Controls.Add(Me.btnModify)
Me.Controls.Add(Me.btnDelete)
Me.Controls.Add(Me.btnConfirm)
Me.Controls.Add(Me.btnCancel)
Me.MaximizeBox = False
Me.Name = "frmCollege"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "學(xué)院設(shè)置"
Me.ResumeLayout(False)
End Sub
#End Region
Private myDataset As New DataSet
Private index As Integer = -1
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
stbCollege.Text = "學(xué)院名稱(chēng)不能為空"
Else
Try
Dim dr As DataRow = myDataset.Tables(0).NewRow
dr.Item("學(xué)院名稱(chēng)") = cmbName.Text
dr.Item("院長(zhǎng)") = txtDean.Text
dr.Item("教務(wù)秘書(shū)") = txtSecretary.Text
myDataset.Tables(0).Rows.Add(dr)
cmbName.Items.Add(cmbName.Text)
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbCollege.Text = "增加成功"
Else
stbCollege.Text = "增加失敗"
End If
End If
End Sub
Private Sub frmCollege_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
If OleConn.SelectQuery("select * from 學(xué)院信息", 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("學(xué)院名稱(chēng)"))
Next
stbCollege.Text = "就緒"
Else
stbCollege.Text = "查詢(xún)學(xué)院信息失敗"
End If
Else
stbCollege.Text = "查詢(xún)學(xué)院信息失敗"
End If
End Sub
Private Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
Dim succ As Boolean = True
If cmbName.Text <> "" Then
If index >= 0 Then
Try
Dim dr As DataRow()
Dim str As String
str = "學(xué)院名稱(chēng)='" & cmbName.Items.Item(index) & "'"
dr = myDataset.Tables(0).Select(str)
dr(0).BeginEdit()
dr(0).Item("學(xué)院名稱(chēng)") = cmbName.Text
dr(0).Item("院長(zhǎng)") = txtDean.Text
dr(0).Item("教務(wù)秘書(shū)") = txtSecretary.Text
dr(0).EndEdit()
cmbName.Items.Item(index) = cmbName.Text
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbCollege.Text = "修改成功"
Else
stbCollege.Text = "修改失敗"
End If
Else
stbCollege.Text = "請(qǐng)先選擇要修改的記錄"
End If
Else
stbCollege.Text = "學(xué)院名稱(chēng)不能為空"
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
str = "學(xué)院名稱(chēng)='" & cmbName.SelectedItem & "'"
dr = myDataset.Tables(0).Select(str)
txtDean.Text = Trim(dr(0).Item("院長(zhǎng)"))
txtSecretary.Text = Trim(dr(0).Item("教務(wù)秘書(shū)"))
End Sub
Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim succ As Boolean = True
If index >= 0 Then
Try
Dim dr As DataRow()
Dim str As String
str = "學(xué)院名稱(chēng)='" & cmbName.Items.Item(index) & "'"
dr = myDataset.Tables(0).Select(str)
dr(0).Delete()
cmbName.Items.RemoveAt(index)
txtDean.Text = ""
txtSecretary.Text = ""
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbCollege.Text = "刪除成功"
Else
stbCollege.Text = "刪除失敗"
End If
Else
stbCollege.Text = "請(qǐng)先選擇要修改的記錄"
End If
End Sub
Private Sub btnConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
Dim succ As Boolean = True
Try
OleConn.UpDate(myDataset.Tables(0))
myDataset.AcceptChanges()
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbCollege.Text = "更新數(shù)據(jù)庫(kù)成功"
Else
stbCollege.Text = "更新數(shù)據(jù)庫(kù)失敗"
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Dim i As Integer
myDataset.RejectChanges()
cmbName.Items.Clear()
For i = 0 To myDataset.Tables(0).Rows.Count - 1
cmbName.Items.Add(myDataset.Tables(0).Rows(i).Item("學(xué)院名稱(chēng)"))
Next
stbCollege.Text = "你已經(jīng)取消了所有的改動(dòng)"
End Sub
End Class
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -