📄 special.vb
字号:
Public Class frmSpecial
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 btnAdd As System.Windows.Forms.Button
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 txtBound As System.Windows.Forms.TextBox
Friend WithEvents txtDemo 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 stbSpecial As System.Windows.Forms.StatusBar
Friend WithEvents cmbYear As System.Windows.Forms.ComboBox
Friend WithEvents cmbName As System.Windows.Forms.ComboBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents cmbCollege 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.Label4 = New System.Windows.Forms.Label
Me.txtBound = New System.Windows.Forms.TextBox
Me.txtDemo = 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.stbSpecial = New System.Windows.Forms.StatusBar
Me.cmbYear = New System.Windows.Forms.ComboBox
Me.cmbName = New System.Windows.Forms.ComboBox
Me.Label5 = New System.Windows.Forms.Label
Me.cmbCollege = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "专业名"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(56, 240)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(40, 23)
Me.btnAdd.TabIndex = 5
Me.btnAdd.Text = "增加"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(40, 16)
Me.Label2.TabIndex = 0
Me.Label2.Text = "学制"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 112)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(80, 23)
Me.Label3.TabIndex = 0
Me.Label3.Text = "毕业最低学分"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(16, 144)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(32, 16)
Me.Label4.TabIndex = 0
Me.Label4.Text = "备注"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtBound
'
Me.txtBound.Location = New System.Drawing.Point(104, 112)
Me.txtBound.Name = "txtBound"
Me.txtBound.Size = New System.Drawing.Size(152, 21)
Me.txtBound.TabIndex = 3
Me.txtBound.Text = ""
'
'txtDemo
'
Me.txtDemo.Location = New System.Drawing.Point(56, 144)
Me.txtDemo.Multiline = True
Me.txtDemo.Name = "txtDemo"
Me.txtDemo.Size = New System.Drawing.Size(200, 80)
Me.txtDemo.TabIndex = 4
Me.txtDemo.Text = ""
'
'btnModify
'
Me.btnModify.Location = New System.Drawing.Point(96, 240)
Me.btnModify.Name = "btnModify"
Me.btnModify.Size = New System.Drawing.Size(40, 23)
Me.btnModify.TabIndex = 6
Me.btnModify.Text = "修改"
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(136, 240)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(40, 23)
Me.btnDelete.TabIndex = 7
Me.btnDelete.Text = "删除"
'
'btnConfirm
'
Me.btnConfirm.Location = New System.Drawing.Point(176, 240)
Me.btnConfirm.Name = "btnConfirm"
Me.btnConfirm.Size = New System.Drawing.Size(40, 23)
Me.btnConfirm.TabIndex = 8
Me.btnConfirm.Text = "确定"
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(216, 240)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(40, 23)
Me.btnCancel.TabIndex = 9
Me.btnCancel.Text = "取消"
'
'stbSpecial
'
Me.stbSpecial.Location = New System.Drawing.Point(0, 279)
Me.stbSpecial.Name = "stbSpecial"
Me.stbSpecial.Size = New System.Drawing.Size(272, 22)
Me.stbSpecial.TabIndex = 3
'
'cmbYear
'
Me.cmbYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbYear.Items.AddRange(New Object() {"一", "二", "三", "四"})
Me.cmbYear.Location = New System.Drawing.Point(104, 80)
Me.cmbYear.Name = "cmbYear"
Me.cmbYear.Size = New System.Drawing.Size(152, 20)
Me.cmbYear.TabIndex = 2
'
'cmbName
'
Me.cmbName.Location = New System.Drawing.Point(104, 16)
Me.cmbName.Name = "cmbName"
Me.cmbName.Size = New System.Drawing.Size(152, 20)
Me.cmbName.TabIndex = 0
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(16, 48)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(56, 16)
Me.Label5.TabIndex = 0
Me.Label5.Text = "所属学院"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'cmbCollege
'
Me.cmbCollege.Location = New System.Drawing.Point(104, 48)
Me.cmbCollege.Name = "cmbCollege"
Me.cmbCollege.Size = New System.Drawing.Size(152, 20)
Me.cmbCollege.TabIndex = 1
'
'frmSpecial
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(272, 301)
Me.Controls.Add(Me.cmbYear)
Me.Controls.Add(Me.stbSpecial)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.txtBound)
Me.Controls.Add(Me.txtDemo)
Me.Controls.Add(Me.btnModify)
Me.Controls.Add(Me.btnDelete)
Me.Controls.Add(Me.btnConfirm)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.cmbName)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.cmbCollege)
Me.MaximizeBox = False
Me.Name = "frmSpecial"
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 DataReader As System.Data.OleDb.OleDbDataReader
Private Sub frmSpecial_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
If OleConn.SelectQuery("select 学院名称 from 学院信息", DataReader) Then
While DataReader.Read
cmbCollege.Items.Add(DataReader.Item(0))
End While
DataReader.Close()
End If
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
stbSpecial.Text = "就绪"
Else
stbSpecial.Text = "查询专业信息表失败"
End If
Else
stbSpecial.Text = "查询专业信息表失败"
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If cmbName.Text = "" Then
stbSpecial.Text = "专业名不能为空"
ElseIf cmbCollege.SelectedIndex < 0 Then
stbSpecial.Text = "请指定所属学院"
ElseIf cmbYear.SelectedIndex < 0 Then
stbSpecial.Text = "请指定学制"
ElseIf txtBound.Text = "" Then
stbSpecial.Text = "请指定总学分"
Else
Dim dr As DataRow = myDataSet.Tables(0).NewRow
Try
dr.Item("专业名") = cmbName.Text
dr.Item("学制") = cmbYear.SelectedIndex + 1
dr.Item("总学分") = CInt(txtBound.Text)
dr.Item("备注") = txtDemo.Text
dr.Item("学院名称") = cmbCollege.SelectedItem
myDataSet.Tables(0).Rows.Add(dr)
stbSpecial.Text = "增加成功"
cmbName.Items.Add(cmbName.Text)
Catch ex As Exception
DisplayError(ex)
End Try
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
DisplayError(ex)
End Try
If succ Then
stbSpecial.Text = "更新数据库成功"
Else
stbSpecial.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()
cmbName.Items.Clear()
For i = 0 To myDataSet.Tables(0).Rows.Count - 1
cmbName.Items.Add(myDataSet.Tables(0).Rows(i).Item("专业名"))
Next
stbSpecial.Text = "你已经取消了所有的改动"
End Sub
Private Sub cmbName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbName.SelectedIndexChanged
Dim dr As DataRow()
Dim str As String
index = cmbName.SelectedIndex
str = "专业名='" & cmbName.SelectedItem & "'"
Try
dr = myDataSet.Tables(0).Select(str)
cmbYear.SelectedIndex = CInt(dr(0).Item("学制")) - 1
txtBound.Text = CStr(dr(0).Item("总学分"))
txtDemo.Text = CStr(dr(0).Item("备注"))
cmbCollege.SelectedItem = dr(0).Item("学院名称")
Catch ex As Exception
DisplayError(ex)
End Try
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
stbSpecial.Text = "专业名不能为空"
ElseIf index < 0 Then
stbSpecial.Text = "请先选择要修改的专业记录"
ElseIf cmbCollege.SelectedIndex < 0 Then
stbSpecial.Text = "请指定所属学院"
ElseIf cmbYear.SelectedIndex < 0 Then
stbSpecial.Text = "请指定学制"
ElseIf txtBound.Text = "" Then
stbSpecial.Text = "请指定总学分"
Else
Try
Dim dr As DataRow()
Dim str As String
str = "专业名='" & cmbName.Items.Item(index) & "'"
dr = myDataSet.Tables(0).Select(str)
dr(0).BeginEdit()
dr(0).Item("专业名") = cmbName.Text
dr(0).Item("学制") = cmbYear.SelectedIndex + 1
dr(0).Item("总学分") = CInt(txtBound.Text)
dr(0).Item("备注") = txtDemo.Text
dr(0).Item("学院名称") = cmbCollege.SelectedItem
dr(0).EndEdit()
cmbName.Items.Item(index) = cmbName.Text
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbSpecial.Text = "修改成功"
Else
stbSpecial.Text = "修改失败"
End If
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 index < 0 Then
stbSpecial.Text = "请先选择要删除的专业记录"
Else
Try
Dim dr As DataRow()
Dim str As String
str = "专业名='" & cmbName.Items.Item(index) & "'"
dr = myDataSet.Tables(0).Select(str)
dr(0).Delete()
cmbName.Items.RemoveAt(index)
txtDemo.Text = ""
txtBound.Text = ""
Catch ex As Exception
succ = False
DisplayError(ex)
End Try
If succ Then
stbSpecial.Text = "删除成功"
Else
stbSpecial.Text = "删除失败"
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -