📄 frmselect.vb
字号:
Me.Label8.Size = New System.Drawing.Size(56, 15)
Me.Label8.TabIndex = 10
Me.Label8.Text = " 课序号"
'
'txbCNumber
'
Me.txbCNumber.Location = New System.Drawing.Point(208, 48)
Me.txbCNumber.Name = "txbCNumber"
Me.txbCNumber.Size = New System.Drawing.Size(56, 21)
Me.txbCNumber.TabIndex = 9
Me.txbCNumber.Text = ""
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(24, 52)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(56, 15)
Me.Label7.TabIndex = 8
Me.Label7.Text = "课程编号"
'
'txbCId
'
Me.txbCId.Location = New System.Drawing.Point(80, 48)
Me.txbCId.Name = "txbCId"
Me.txbCId.Size = New System.Drawing.Size(56, 21)
Me.txbCId.TabIndex = 7
Me.txbCId.Text = ""
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(152, 21)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(56, 15)
Me.Label6.TabIndex = 6
Me.Label6.Text = "课程名称"
'
'txbCName
'
Me.txbCName.Location = New System.Drawing.Point(208, 16)
Me.txbCName.Name = "txbCName"
Me.txbCName.Size = New System.Drawing.Size(56, 21)
Me.txbCName.TabIndex = 5
Me.txbCName.Text = ""
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(24, 21)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(56, 15)
Me.Label5.TabIndex = 4
Me.Label5.Text = "课程拼音"
'
'txbPY
'
Me.txbPY.Location = New System.Drawing.Point(80, 16)
Me.txbPY.Name = "txbPY"
Me.txbPY.Size = New System.Drawing.Size(56, 21)
Me.txbPY.TabIndex = 3
Me.txbPY.Text = ""
'
'frmSelect
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(640, 325)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.grbTop)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmSelect"
Me.Text = "学生选课"
Me.grbTop.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
CType(Me.dgdList, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox2.ResumeLayout(False)
CType(Me.dgdSubject, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnSearch_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSearch.Click
SetDGDSubject()
End Sub
Private Sub btnSelect_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSelect.Click
If dgdList.CurrentCell.RowNumber = -1 Or _
dgdSubject.CurrentCell.RowNumber = -1 Then
Exit Sub
End If
Dim db As DataBase = New DataBase
Dim dv As DataView
Dim strSQL As String = ""
Dim strTmp As String = dtSubject. _
Rows(dgdSubject.CurrentCell.RowNumber)(1).ToString.Trim()
strSQL = "select * from 选课表 where 学号='" + txbId.Text.Trim
strSQL += "' and 课序号 in(select 课序号 from 课程表 where 课程编号='"
strSQL += strTmp + "')"
dv = db.RunSelectSQL(strSQL)
If dv.Count <> 0 Then
MessageBox.Show("该课程已经选择!")
db.Dispose()
Exit Sub
End If
Dim strCId As String = dtSubject. _
Rows(dgdSubject.CurrentCell.RowNumber)(0).ToString.Trim()
strSQL = "select * from 选课表 as a, 课程表 as b "
strSQL += "where a.课序号=b.课序号 and a.学号='"
strSQL += txbId.Text.Trim + "' and 100*b.上课时间天+"
strSQL += "b.上课时间节 in (select 100*上课时间天+上课时间节"
strSQL += " from 课程表 where 课序号='" + strCId + "')"
dv = db.RunSelectSQL(strSQL)
If dv.Count <> 0 Then
MessageBox.Show("该课序号时间和已经选择的课程冲突!")
Exit Sub
Else
strSQL = "insert into 选课表(学号,课序号) values('"
strSQL += txbId.Text.Trim + "','" + strCId + " ')"
db.RunDelOrInsSQL(strSQL)
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,"
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 "
strSQL += "as c, 课程表 as a, 课程信息 as b where "
strSQL += "a.课程编号=b.课程编号 and c.课序号=a.课序号 and 学号='"
strSQL += txbId.Text.Trim + "' order by a.课序号"
dv = db.RunSelectSQL(strSQL)
dv.AllowDelete = False
dv.AllowEdit = False
dv.AllowNew = False
dtData = dv.Table
Me.dgdList.DataSource = dtData
End If
db.Dispose()
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDel.Click
If Me.dgdList.CurrentCell.RowNumber = -1 Then
Exit Sub
End If
Dim dlgResult As DialogResult = MessageBox. _
Show("确定删除指定的已选课程吗?", "提示", _
MessageBoxButtons.YesNo)
If dlgResult = DialogResult.Yes Then
Dim strCId As String = dtData. _
Rows(dgdList.CurrentCell.RowNumber)(1).ToString.Trim()
Dim strSQL As String = "delete from 选课表 where 学号='"
strSQL += Me.txbId.Text.Trim
strSQL += "' and 课序号 = '" + strCId + "'"
Dim db As DataBase = New DataBase
db.RunDelOrInsSQL(strSQL)
Dim dv As DataView
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,"
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 "
strSQL += "as c, 课程表 as a, 课程信息 as b where "
strSQL += "a.课程编号=b.课程编号 and c.课序号=a.课序号 "
strSQL += "and 学号='" + txbId.Text.Trim + "' order by a.课序号"
dv = db.RunSelectSQL(strSQL)
dv.AllowDelete = False
dv.AllowEdit = False
dv.AllowNew = False
dtData = dv.Table
Me.dgdList.DataSource = dtData
db.Dispose()
End If
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim dlgChild As frmCourse = New frmCourse
dlgChild.Show()
End Sub
Private Sub txbId_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbId.KeyDown
If e.KeyCode = Keys.Enter And txbId.Text.Trim.Length <> 0 Then
Dim db As DataBase = New DataBase
Dim strSQL As String = ""
strSQL = "select 姓名, 班级名称, 学籍编号 from 学生信息 as a,"
strSQL += " 班级信息 as b where a.班级编号=b.班级编号 "
strSQL += "and 学号='" + Me.txbId.Text.Trim + "'"
Dim dv As DataView = db.RunSelectSQL(strSQL)
If dv.Count = 0 Then
MessageBox.Show("不是在籍的学生")
Me.txbId.Text = ""
Else
Me.txbName.Text = dv(0)(0).ToString.Trim
Me.txbGrade.Text = dv(0)(1).ToString.Trim
End If
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,"
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 "
strSQL += "as c, 课程表 as a, 课程信息 as b where a.课程编号 "
strSQL += "=b.课程编号 and c.课序号=a.课序号 and 学号='"
strSQL += txbId.Text.Trim
strSQL += "' order by a.课序号"
dv = db.RunSelectSQL(strSQL)
If dv.Count = 0 Then
MessageBox.Show("不是在籍的学生")
Me.txbId.Text = ""
Else
dv.AllowDelete = False
dv.AllowEdit = False
dv.AllowNew = False
dtData = dv.Table
Me.dgdList.DataSource = dtData
End If
db.Dispose()
End If
End Sub
Private Sub txbPY_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbPY.KeyDown
If e.KeyCode = Keys.Enter Then
SetDGDSubject()
End If
End Sub
Private Sub SetDGDSubject()
'根据查询条件组合SQL语句
Dim strSQL As String = "select a.课序号,b.课程编号,b.课程名称,b.教师,"
strSQL += "b.开课系别,a.上课时间天,a.上课时间节,a.上课地点 from 课程表"
strSQL += " as a, 课程信息 as b where a.课程编号=b.课程编号"
Dim strFilter As String = ""
If Me.txbPY.Text.Trim.Length <> 0 Then
strFilter += " and 拼音码 like '" + Me.txbPY.Text.Trim + "%'"
End If
If Me.txbCName.Text.Trim.Length <> 0 Then
strFilter += " and 课程名称 like '" + Me.txbCName.Text.Trim + "%'"
End If
If Me.txbCId.Text.Trim.Length <> 0 Then
strFilter += " and b.课程编号 like '" + Me.txbCId.Text.Trim + "%'"
End If
If Me.txbCNumber.Text.Trim.Length <> 0 Then
strFilter += " and 课序号 like '" + Me.txbCNumber.Text.Trim + "%'"
End If
If strFilter.Trim.Length = 0 Then
Exit Sub
End If
strFilter += " order by 课序号"
'执行SQL语句
Dim db As DataBase = New DataBase
Dim dv As DataView = db.RunSelectSQL(strSQL + strFilter)
dv.AllowDelete = False
dv.AllowEdit = False
dv.AllowNew = False
Me.dgdSubject.AllowSorting = False
dtSubject = dv.Table
'设置数据源
Me.dgdSubject.DataSource = dtSubject
db.Dispose()
End Sub
Private Sub txbCName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbCName.KeyDown
If e.KeyCode = Keys.Enter Then
SetDGDSubject()
End If
End Sub
Private Sub txbCNumber_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbCNumber.KeyDown
If e.KeyCode = Keys.Enter Then
SetDGDSubject()
End If
End Sub
Private Sub txbCId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbCId.KeyDown
If e.KeyCode = Keys.Enter Then
SetDGDSubject()
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -