vb学生系统如何制作,谁有源代码。

vb学生系统如何制作,谁有源代码。,第1张

代码如下:代码如下:

(一) 登陆代码

Option Explicit

Const USERNAME As String = "d" '定义窗体级常量表示用户名

Const PASSWORD As String = "1" '定义窗体级常量表示密码

Private Sub cmdCancel_Click()

Me.Hide

End Sub

Private Sub cmdOK_Click()

'检查正确的用户名和密码

If txtUserName = USERNAME And txtPassword = PASSWORD Then

Me.Hide

MDIfrmMain.mnuEdit.Enabled = True

MDIfrmMain.mnuQuery.Enabled = True

Else

MsgBox "无效的密码,请重试!", , "登录"

txtPassword.SetFocus

SendKeys "{Home}+{End}"

End If

End Sub

'成功登录系统前禁用编辑命令和查询命令

Private Sub MDIForm_Load()

mnuEdit.Enabled = False

mnuQuery.Enabled = False

End Sub

'打开编辑窗体

(二)最初代码

Private Sub mnuEdit_Click()

frmEdit.Show

frmEdit.WindowState = vbMaximized

End Sub

'打开登录窗体

Private Sub mnuLogin_Click()

frmLogin.Show

frmLogin.WindowState = vbMaximized

End Sub

'退出系统

Private Sub mnuLogout_Click()

End

End Sub

'打开查询窗体

Private Sub mnuQuery_Click()

frmQuery.Show

frmQuery.WindowState = vbMaximized

End Sub

(三)编辑代码

'"添加"按钮的单击事件过程

Private Sub cmdAdd_Click()

'根据当前按钮的标题进行不同的 *** 作

Select Case cmdAdd.Caption

Case "添加"

'向当前选项卡所对应表中添加记录

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.AddNew

Case 1

datCourse.Recordset.AddNew

Case 2

datScore.Recordset.AddNew

End Select

'在添加 *** 作完成前禁止进行其他 *** 作

SSTab1.TabEnabled(0) = False

SSTab1.TabEnabled(1) = False

SSTab1.TabEnabled(2) = False

cmdAdd.Caption = "确定"

cmdEdit.Enabled = False

cmdDel.Enabled = False

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = False

cmdLast.Enabled = False

Case "确定"

Select Case SSTab1.Tab

Case 0

datStudent.UpdateRecord

Case 1

datCourse.UpdateRecord

Case 2

datScore.UpdateRecord

End Select

SSTab1.TabEnabled(0) = True

SSTab1.TabEnabled(1) = True

SSTab1.TabEnabled(2) = True

cmdAdd.Caption = "添加"

cmdEdit.Enabled = True

cmdDel.Enabled = True

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = True

cmdLast.Enabled = True

End Select

End Sub

'"删除"按钮的单击事件过程

Private Sub cmdDel_Click()

Dim i As Integer

i = MsgBox("确定要删除此记录?", vbYesNo + vbExclamation + vbDefaultButton1, "编辑")

If i = vbYes Then

'删除当前选项卡所对应表中的记录

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.Delete

datStudent.Refresh

Case 1

datCourse.Recordset.Delete

datCourse.Refresh

Case 2

datScore.Recordset.Delete

datScore.Refresh

End Select

End If

End Sub

'"修改"按钮的单击事件过程

Private Sub cmdEdit_Click()

'根据当前按钮的标题进行不同的 *** 作

Select Case cmdEdit.Caption

Case "修改"

'修改当前选项卡所对应表中的记录

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.Edit

Case 1

datCourse.Recordset.Edit

Case 2

datScore.Recordset.Edit

End Select

'在修改 *** 作完成前禁止进行其他 *** 作

SSTab1.TabEnabled(0) = False

SSTab1.TabEnabled(1) = False

SSTab1.TabEnabled(2) = False

cmdEdit.Caption = "确定"

cmdAdd.Enabled = False

cmdDel.Enabled = False

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = False

cmdLast.Enabled = False

Case "确定"

Select Case SSTab1.Tab

Case 0

datStudent.UpdateRecord

Case 1

datCourse.UpdateRecord

Case 2

datScore.UpdateRecord

End Select

SSTab1.TabEnabled(0) = True

SSTab1.TabEnabled(1) = True

SSTab1.TabEnabled(2) = True

cmdEdit.Caption = "修改"

cmdAdd.Enabled = True

cmdDel.Enabled = True

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = True

cmdLast.Enabled = True

End Select

End Sub

'"首记录"按钮的单击事件过程

Private Sub cmdFirst_Click()

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.MoveFirst

Case 1

datCourse.Recordset.MoveFirst

Case 2

datScore.Recordset.MoveFirst

End Select

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = True

cmdLast.Enabled = True

End Sub

'"尾记录"按钮的单击事件过程

Private Sub cmdLast_Click()

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.MoveLast

Case 1

datCourse.Recordset.MoveLast

Case 2

datScore.Recordset.MoveLast

End Select

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = False

cmdLast.Enabled = False

End Sub

'"下一条"按钮的单击事件过程

Private Sub cmdNext_Click()

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.MoveNext

If datStudent.Recordset.EOF Then

datStudent.Recordset.MoveLast

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = False

cmdLast.Enabled = False

End If

Case 1

datCourse.Recordset.MoveNext

If datCourse.Recordset.EOF Then

datCourse.Recordset.MoveLast

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = False

cmdLast.Enabled = False

End If

Case 2

datScore.Recordset.MoveNext

If datScore.Recordset.EOF Then

datScore.Recordset.MoveLast

cmdFirst.Enabled = True

cmdPrev.Enabled = True

cmdNext.Enabled = False

cmdLast.Enabled = False

End If

End Select

End Sub

'"上一条"按钮的单击事件过程

Private Sub cmdPrev_Click()

Select Case SSTab1.Tab

Case 0

datStudent.Recordset.MovePrevious

If datStudent.Recordset.BOF Then

datStudent.Recordset.MoveFirst

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = True

cmdLast.Enabled = True

End If

Case 1

datCourse.Recordset.MovePrevious

If datCourse.Recordset.BOF Then

datCourse.Recordset.MoveFirst

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = True

cmdLast.Enabled = True

End If

Case 2

datScore.Recordset.MovePrevious

If datScore.Recordset.BOF Then

datScore.Recordset.MoveFirst

cmdFirst.Enabled = False

cmdPrev.Enabled = False

cmdNext.Enabled = True

cmdLast.Enabled = True

End If

End Select

End Sub

'初始化编辑窗体

Private Sub Form_Load()

datStudent.Visible = False

'连接数据库

If Right(App.Path, 1) = "\" Then

datStudent.DatabaseName = App.Path + "mydb.mdb"

Else

datStudent.DatabaseName = App.Path + "\mydb.mdb"

End If

'设置记录源

datStudent.RecordSource = "学生"

datStudent.Refresh

'绑定控件

txtSID.DataField = "学号"

txtSName.DataField = "姓名"

optMale.Value = datStudent.Recordset.Fields("性别").Value

datCourse.Visible = False

datCourse.DatabaseName = datStudent.DatabaseName

datCourse.RecordSource = "课程"

datCourse.Refresh

txtCID.DataField = "课程号"

txtCName.DataField = "课程名"

txtPeriod.DataField = "学时"

txtCredit.DataField = "学分"

datScore.Visible = False

datScore.DatabaseName = datStudent.DatabaseName

datScore.RecordSource = "成绩"

datScore.Refresh

txtSSID.DataField = "学号"

txtSCID.DataField = "课程号"

txtScore.DataField = "成绩"

SSTab1.Tab = 0 '设置当前选项卡为"学生"选项卡

End Sub

(四)查询代码

'"确定" 按钮的单击事件过程

Private Sub cmdOK_Click()

Dim sql As String, fld As String, condition As String

'显示的字段列表

fld = "学生.学号,学生.姓名,课程.课程名,成绩.成绩"

'查询条件

condition = "学生.学号=成绩.学号 and 课程.课程号=成绩.课程号 "

If optChoice(0).Value Then

condition = condition + "and 学生.学号='" + txtID(0).Text + "'"

Else

condition = condition + "and 课程.课程号='" + txtID(1).Text + "'"

End If

sql = "select " + fld + " from 学生,课程,成绩 where " + condition

'改变记录源

Adodc1.RecordSource = sql

Adodc1.Refresh

End Sub

'初始化查询窗体

Private Sub Form_Load()

Adodc1.Visible = False

Set DataGrid1.DataSource = Adodc1 '绑定 *** 作

DataGrid1.AllowUpdate = False '禁止更新

End Sub

'处理单选按钮的焦点切换

Private Sub optChoice_Click(Index As Integer)

txtID(Index).SetFocus

End Sub

'处理文本框的焦点切换

Private Sub txtID_GotFocus(Index As Integer)

optChoice(Index).Value = True

End Sub

然后上机调试一下,不过你的电脑必须要能建立Access数据库。

Private Sub Command3_Click()

If Combo1.Text = "职工信息添加" Then

Frame1.Visible = True

Frame2.Visible = False

Frame3.Visible = False

ElseIf Combo1.Text = "课程信息添加" Then

Frame2.Visible = True

Frame1.Visible = False

Frame3.Visible = False

ElseIf Combo1.Text = "院系信息添加" Then

Frame3.Visible = True

Frame1.Visible = False

Frame2.Visible = False

Else

Frame1.Visible = False

Frame2.Visible = False

Frame3.Visible = False

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11636559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存