判断随机选择题,得了多少分这个地方的代码计算不出正确得分结果.
本帖最后由 wuyazhe 于 2013-03-18 14:38:30 编辑
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Partial Class shiti
Inherits System.Web.UI.Page
Shared int_row3Point As Integer = 0 '单选题分数
Shared int_row3 As Integer = 0 '单选题题号索引
Private strids As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connstr As String
connstr = ConfigurationManager.AppSettings("strconn").ToString
Dim conn As New SqlConnection(connstr)
Dim myadapter6 As SqlDataAdapter = New SqlDataAdapter("select * from suiji", conn) suiji表里放的是题库中选择题的总数和所要随机出题的数量
Dim myds6 As DataSet = New DataSet()
myadapter6.Fill(myds6, "suiji")
Dim total_topic_num As Integer
total_topic_num = Convert.ToInt32(myds6.Tables("suiji").Rows(0)("xzzs").ToString()) xzzs是题库中一种类型题的总数
Dim myadapter7 As SqlDataAdapter = New SqlDataAdapter("select * from suiji", conn)
Dim myds7 As DataSet = New DataSet()
myadapter7.Fill(myds7, "suiji")
Dim test_topic_num As Integer
test_topic_num = Convert.ToInt32(myds7.Tables("suiji").Rows(0)("sjxs").ToString())sjxs是所要随机出题的数量
Dim interval As Integer = total_topic_num \ test_topic_num
Dim big_interval_num As Integer = total_topic_num Mod test_topic_num
Dim array_topic_id(test_topic_num) As Integer
Dim array_topic_id1(2) As Integer
Dim i As Integer = 0
If big_interval_num <> 0 Then
For i = 0 To test_topic_num - 1 - big_interval_num
Randomize()
array_topic_id(i) = Int(interval * Rnd() + i * interval)
strids = strids & array_topic_id(i) & ","
Next
For i = test_topic_num - big_interval_num To test_topic_num - 1
Randomize()
array_topic_id(i) = (test_topic_num - big_interval_num) * interval + Int((interval + 1) * Rnd() + (i - (test_topic_num - big_interval_num)) * (interval + 1))
strids = strids & array_topic_id(i) & ","
Next
Else
For i = 0 To test_topic_num - 1
Randomize()
array_topic_id(i) = Int(interval * Rnd() + i * interval)
strids = strids & array_topic_id(i) & ","
Next
End If
If Not IsPostBack Then
databind1(strids.TrimEnd(","c))
databind3()
End If
End Sub
Sub databind1(ByVal strids As String)
Dim connstr As String
connstr = ConfigurationManager.AppSettings("strconn").ToString
Dim conn As New SqlConnection(connstr)
Dim cmd As New SqlCommand("select * from xuanze where id in (" & strids & ") ", conn)
conn.Open()
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
adp.Fill(ds, "link")
DataList1.DataSource = ds.Tables("link").DefaultView
DataList1.DataBind()
conn.Close()
End Sub
Sub databind3()
Dim connstr As String
connstr = ConfigurationManager.AppSettings("strconn").ToString
Dim conn As New SqlConnection(connstr)
Dim cmd As New SqlCommand("select * from fts", conn) fts表里放的是一种类型题每道题的分数每道题6分
conn.Open()
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
adp.Fill(ds, "link")
DataList3.DataSource = ds.Tables("link").DefaultView
DataList3.DataBind()
DataList4.DataSource = ds.Tables("link").DefaultView
DataList4.DataBind()
DataList5.DataSource = ds.Tables("link").DefaultView
DataList5.DataBind()
conn.Close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("<script lanuage=javascript>alert('您确定要交卷吗?');localtion='shiti.aspx';</script>")
Button1.Enabled = False
strids = strids.TrimEnd(","c)
Dim connstr As String
connstr = ConfigurationManager.AppSettings("strconn").ToString
Dim conn As New SqlConnection(connstr)
Dim myadapter3 As SqlDataAdapter = New SqlDataAdapter("select * from xuanze where id in (" & strids & ") ", conn)xuanze表是选择题的题库
Dim myds3 As DataSet = New DataSet()
myadapter3.Fill(myds3)
Dim row1() As DataRow = myds3.Tables(0).Select()
Dim myadapter4 As SqlDataAdapter = New SqlDataAdapter("select * from fts", conn)
Dim myds4 As DataSet = New DataSet()
myadapter4.Fill(myds4, "fts")
Dim zhengshu2 As Integer
zhengshu2 = Convert.ToInt32(myds4.Tables("fts").Rows(0)("f1").ToString())
'计算单选题成绩
int_row3 = 0
int_row3Point = 0
For Each answer1 As DataRow In row1
int_row3 += 1
Dim rbl As RadioButtonList = CType(DataList1.Items(int_row3 - 1).FindControl("RadioButtonList2"), RadioButtonList)
If (rbl.SelectedValue = "") Then
Label12.Text = "单选题:" + int_row3Point.ToString() + "分"
Else
If (answer1("daan").ToString().Trim() = rbl.SelectedValue.ToString().Trim()) Then
int_row3Point += zhengshu2 zhengshu2是每道题的分
Label12.Text = "单选题:" + int_row3Point.ToString() + "分"
Else
Label12.Text = "单选题:" + int_row3Point.ToString() + "分"
End If
End If
Next
End Sub
End Class