VB+access评分系统
发布网友
发布时间:2022-05-15 09:26
我来回答
共1个回答
热心网友
时间:2023-08-24 19:06
Option Explicit
Dim X As Integer
Dim Y As Integer
Dim fnt As Byte
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rscm As ADODB.Recordset
Public adoCon As ADODB.Connection
Public adoRS As ADODB.Recordset
Dim cn As ADODB.Connection
Dim mlink As String, mysql As String
Dim sh As String
Private Sub Command1_Click()
On Error GoTo ErrMsg
If Option1 = True Then
Label14.Visible = True
Text11.Visible = True
mysql = "select * from 成绩表 where 学号='" & Text1 & "'order by 学号"
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;"
cn.Open
sh = "select MAX(成绩) from 成绩表 where 学号='" & Text1 & "'" '查找最高成绩
Set adoRS = cn.Execute(sh)
Text2.Text = adoRS(0)
sh = "select MIN(成绩) from 成绩表 where 学号='" & Text1 & "'" '查找最低分
Set adoRS = cn.Execute(sh)
Text3.Text = adoRS(0)
sh = "select AVG(成绩) from 成绩表 where 学号='" & Text1 & "'" '计算平均分
Set adoRS = cn.Execute(sh)
Text4.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 学号='" & Text1 & "'" & " and 成绩<60" '统计不及格门(次)
Set adoRS = cn.Execute(sh)
Text5.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 学号='" & Text1 & "'" & " and 成绩 BETWEEN 90 AND 100" '统计优秀门(次)
Set adoRS = cn.Execute(sh)
Text6.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 学号='" & Text1 & "'" & " and 成绩 BETWEEN 80 AND 89" '统计良好门(次)
Set adoRS = cn.Execute(sh)
Text7.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 学号='" & Text1 & "'" '统计总门(次)数
Set adoRS = cn.Execute(sh)
Text8.Text = adoRS(0)
Text9.Text = ((Text8.Text - Text5.Text) / Text8.Text) * 100 & "%" '计算合格率
sh = "select 姓名 from 成绩表 where 学号='" & Text1 & "'"
Set adoRS = cn.Execute(sh)
Text11.Text = adoRS(0)
End If
If Option2 = True Then
Label14.Visible = False
Text11.Visible = False
If Text11.Visible = False Then
Text11.Text = ""
End If
mysql = "select * from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'order by 学号"
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;"
cn.Open
sh = "select MAX(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'"
Set adoRS = cn.Execute(sh)
Text2.Text = adoRS(0)
sh = "select MIN(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'"
Set adoRS = cn.Execute(sh)
Text3.Text = adoRS(0)
sh = "select AVG(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'"
Set adoRS = cn.Execute(sh)
Text4.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'" & " and 成绩<60"
Set adoRS = cn.Execute(sh)
Text5.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'" & " and 成绩 BETWEEN 90 AND 100"
Set adoRS = cn.Execute(sh)
Text6.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'" & " and 成绩 BETWEEN 80 AND 89"
Set adoRS = cn.Execute(sh)
Text7.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 所在班级='" & DataCombo1 & "'" & " And 课程='" & DataCombo2 & "'"
Set adoRS = cn.Execute(sh)
Text8.Text = adoRS(0)
Text9.Text = ((Text8.Text - Text5.Text) / Text8.Text) * 100 & "%"
End If
If Option3 = True Then
Label14.Visible = False
Text11.Visible = False
mysql = "select * from 成绩表 where 姓名='" & Text10 & "'order by 学号"
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;"
cn.Open
sh = "select MAX(成绩) from 成绩表 where 姓名='" & Text10 & "'"
Set adoRS = cn.Execute(sh)
Text2.Text = adoRS(0)
sh = "select MIN(成绩) from 成绩表 where 姓名='" & Text10 & "'"
Set adoRS = cn.Execute(sh)
Text3.Text = adoRS(0)
sh = "select AVG(成绩) from 成绩表 where 姓名='" & Text10 & "'"
Set adoRS = cn.Execute(sh)
Text4.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 姓名='" & Text10 & "'" & " and 成绩<60"
Set adoRS = cn.Execute(sh)
Text5.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 姓名='" & Text10 & "'" & " and 成绩 BETWEEN 90 AND 100"
Set adoRS = cn.Execute(sh)
Text6.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 姓名='" & Text10 & "'" & " and 成绩 BETWEEN 80 AND 89"
Set adoRS = cn.Execute(sh)
Text7.Text = adoRS(0)
sh = "select COUNT(成绩) from 成绩表 where 姓名='" & Text10 & "'"
Set adoRS = cn.Execute(sh)
Text8.Text = adoRS(0)
Text9.Text = ((Text8.Text - Text5.Text) / Text8.Text) * 100 & "%"
End If
If rs.State <> adStateClosed Then
rs.Close
End If
rs.Open mysql, db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs '传递表值
rs.MoveLast
If rs.EOF = True Then
MsgBox "无此信息,请确认!"
End If
ErrMsg:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + Err.Description, vbOKOnly + vbCritical, "错误提示"
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
On Error GoTo ErrMsg
fnt = 15
X = 1000
Y = 1000
Printer.CurrentX = X
Printer.CurrentY = Y
Printer.FontSize = fnt
Printer.Print "学号:" & Text1
Printer.CurrentX = X
Printer.CurrentY = Y + 300
Printer.Print Label14 & Text11
Printer.CurrentX = X
Printer.CurrentY = Y + 600
Printer.Print Label5 & Text2
Printer.CurrentX = X
Printer.CurrentY = Y + 900
Printer.Print Label6 & Text3
Printer.CurrentX = X
Printer.CurrentY = Y + 1200
Printer.Print Label7 & Text4
Printer.CurrentX = X
Printer.CurrentY = Y + 1500
Printer.Print Label8 & Text5
Printer.CurrentX = X
Printer.CurrentY = Y + 1800
Printer.Print Label9 & Text6
Printer.CurrentX = X
Printer.CurrentY = Y + 2100
Printer.Print Label10 & Text7
Printer.CurrentX = X
Printer.CurrentY = Y + 2400
Printer.Print Label11 & Text8
Printer.CurrentX = X
Printer.CurrentY = Y + 2700
Printer.Print Label12 & Text9
Dim i As Long, J As Long, K As Long
Dim PrintString As String
Y = 4400
Printer.CurrentX = 1000
Printer.CurrentY = 4000
Printer.FontSize = 13
Printer.Print "学号/姓名 /课程/成绩/班级"
For i = 0 To DataGrid1.Row
If K = DataGrid1.VisibleRows Then
DataGrid1.Scroll 0, DataGrid1.VisibleRows
K = 0
End If
For J = 0 To DataGrid1.Columns.Count - 1
PrintString = PrintString & _
DataGrid1.Columns(J).CellText(DataGrid1.RowBookmark(K)) & "/"
Next
Printer.CurrentX = 1000
Printer.CurrentY = Y
Printer.FontSize = 10
Printer.Print PrintString
PrintString = ""
K = K + 1
Y = Y + 300
DoEvents
If i = DataGrid1.Row Then '无此条件则打印机与计算机不断开,不能进行新的打印任务
Printer.EndDoc
End If
Next
ErrMsg:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + Err.Description, vbOKOnly + vbCritical, "错误提示"
Exit Sub
End If
End Sub
Private Sub Command4_Click()
DataReport2.Show
End Sub
Private Sub Form_Load()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.CursorLocation = adUseClient
mlink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;"
db.Open mlink
mysql = "select * from 成绩表 order by 学号"
rs.Open mysql, db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub