\'开始新的练习
Dim e As RequestEventArgs = Args(0)
Dim vtext As String = e.PlainText \'ajex传入
MessageBox.Show(vtext)
If vtext > "" Then
Dim varr() As String = vtext.Split("|")
If varr.Length = 3 Then
Dim drU As DataRow = Functions.Execute("CheckToken",varr(0),e) \'权限验证
If drU IsNot Nothing Then
Dim qttype As String
Dim qt As String = e.Cookies("cqt")
MessageBox.Show(e.Cookies("cqt"))
If qt = 2 Then
qttype = " and TestType = 5" \'属于考试项目
Else
qttype = " and TestType <> 5"
End If
Dim openid As String = drU("OpenID")
MessageBox.Show(openid)
If Functions.Execute("UpdateLogonTime",openid) Then \'更新用户操作时间
Dim dt As DataTable = DataTables("UsersTestForm")
dt.ReplaceFor("IsCompleted",1,"[OpenId] = \'" & openid & "\' and IsCompleted = 0" & qttype) \'如果其它的练习没有完成,则统一设置为完成
Dim drnew As DataRow = dt.AddNew
drnew("TestID") = _BizCodeBuilder.GetNextCode("UsersTestForm") \'使用专门的类获取编号,避免并发的时候产生重复编号
MessageBox.Show(drnew("TestID"))
drnew("OpenId") = openid
drnew("UserNick") = drU("Nickname")
drnew("TestDate") = Date.Now
Dim qty As Integer = val(varr(2))
MessageBox.Show(qty)
If qty = 0 Then qty = 1
drnew("QuestionQty") = qty \'选择的题目数量
drnew("AnswerQty") = 0
drnew("AnswerCodeQty") = 0
drnew("CorrectQty") = 0
drnew("CorrectRate") = 0 \'如果=1准确率默认为100%
drnew("IsCompleted") = 0
drnew("CompleteRate") = 0
\'设置选择的练习题型
Dim drDict As DataRow = DataTables("uSysDictionarys").Find("ItemName=\'" & varr(1) & "\' and GroupName=\'做题题型\'")
Dim subType As Integer = 0
If drDict IsNot Nothing Then
subType = val(drDict("ItemValue"))
MessageBox.Show(val(drDict("ItemValue")))
End If
drnew("TestType") = subType
dt.Save
\'把已经完成的练习移除,避免占用内存
Dim ids As List(Of String) = dt.GetValues("TestID","IsCompleted = 1")
dt.RemoveFor("IsCompleted = 1")
DataTables("UsersCodeAnswerForm").RemoveFor("TestID in (\'" & String.Join("\',\'",ids.ToArray) & "\')")
DataTables("UsersTestForm").RemoveFor("TestID in (\'" & String.Join("\',\'",ids.ToArray) & "\')")
\'从问题顺序表获取一道题
Dim sql As String = CExp("exec [upd_GetNextNewQuestionFor] @OpenID=\'{0}\',@SelectTestType={1}",openid ,subType)
dt = Functions.Execute("Cmd_GetDataTable","Q",sql)
Dim drQs As DataRow
If dt.DataRows.Count > 0 Then
drQs = dt.DataRows(0)
Dim htmJson As String = Functions.Execute("GetNewAnswerHtm",openid ,drQs("QuestionID"),drQs("QuestionType"),drnew) \'生成题目html代码
e.WriteString(htmJson)
Return ""
End If
End If
End If
End If
End If
e.WriteString("错误: 无法创建新的练习, 请通知官方客服!")