📄 exam.asmx.vb
字号:
'
' Copyright(C)2006,济南大学材料科学与工程学院
' All right reserved.
'
' 文件名称:exam.asmx.vb
' 文件标识:
' 摘 要:考试
'
' 当前版本:1.0.0
' 作 者:梁 海
' 完成日期:2006-12-3
'
' 取代版本:
' 原作者 :
' 完成日期:
'
' 修改历史:
'
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.IO
<System.Web.Services.WebService(Namespace:="http://mse.ujn.edu.cn/autocad/exam")> _
Public Class Exam
Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
'
' 函数名称:GetStudentInfo(ByVal SID As String,ByRef oStudentInfo As StudentInfo) As Boolean
' 摘 要:获取考生信息
'
<WebMethod(Description:="根据考号获取考生基本信息,通过参数oStudentInfo返回考生信息,返回的Boolean表示存在该考生,True存在,False不存在")> _
Public Function GetStudentInfo(ByVal SID As String, ByRef oStudentInfo As StudentInfo) As Boolean
Dim strSql As String
Dim oReader As SqlDataReader
Dim oSql As New SqlDataAccess
'从数据库中查找考号为SID的考生信息
strSql = "Select * From vStudent Where (SID='" + SID + "')"
oSql.Sql = strSql
oReader = oSql.DataReader()
If oReader.Read Then
Try
oStudentInfo.SID = CType(oReader.Item("SID"), String) '考号
oStudentInfo.Name = CType(oReader.Item("Name"), String) '姓名
oStudentInfo.Team = CType(oReader.Item("Team"), String) '班级
oStudentInfo.Mayor = CType(oReader.Item("Mayor"), String) '专业
oStudentInfo.Department = CType(oReader.Item("Department"), String) '学院
oStudentInfo.CardID = CType(oReader.Item("CardID"), String) '身份证号
'性别
If CType(oReader.Item("Sex"), Boolean) Then
oStudentInfo.Sex = "M"
Else
oStudentInfo.Sex = "F"
End If
oReader.Close()
Catch ex As Exception
'不处理强制转换可能产生的出错
End Try
Return True
Else
Return False
End If
End Function
'
' 函数名称:GetExamInfo(ByVal SID As String, ByRef oExamInfo As ExamInfo) As Boolean
' 摘 要:获取考试安排信息
'
<WebMethod(Description:="根据考号获取考试安排信息,通过参数oExamInfo返回考试安排信息,返回的Boolean表示存在考试安排,True存在,False不存在")> _
Public Function GetExamInfo(ByVal SID As String, ByRef oExamInfo As ExamInfo) As Boolean
Dim strSql As String
Dim oReader As SqlDataReader
Dim oSql As New SqlDataAccess
'从数据库中查找考号为SID的考生的考试安排
strSql = "Select * From vExam Where (SID='" + SID + "')"
oSql.Sql = strSql
oReader = oSql.DataReader()
If oReader.Read Then
Try
oExamInfo.SID = CType(oReader.Item("SID"), String) '考号
oExamInfo.EID = CType(oReader.Item("EID"), Integer) '考场号
oExamInfo.IsExamed = CType(oReader.Item("IsExamed"), Boolean) '是否已经参加考试
'考试开始时间
If oReader.Item("StartDateTime") Is DBNull.Value Then
oExamInfo.StartDateTime = Now()
Else
oExamInfo.StartDateTime = CType(oReader.Item("StartDateTime"), DateTime)
End If
'考试结束时间
If oReader.Item("EndDateTime") Is DBNull.Value Then
oExamInfo.EndDateTime = Now.AddMinutes(120)
Else
oExamInfo.EndDateTime = CType(oReader.Item("EndDateTime"), DateTime)
End If
oReader.Close()
Catch ex As Exception
'不处理强制转换可能产生的出错
End Try
Return True
Else
Return False
End If
End Function
'
' 函数名称:GetPaper(ByVal SID As String) As DataSet
' 摘 要:抽取考试题
'
<WebMethod(Description:="根据考号抽取相对应的考试题,返回考试题的数据集")> _
Public Function GetPaper(ByVal SID As String) As DataSet
Dim PaperFile As FileInfo
Dim FileName As String
Dim dsPaper As DataSet
'根据考号获取试卷的文件全名
FileName = GetExamFile(SID)
'如果考题xml文件存在
'直接读取xml文件
'否则重新抽取考试题
PaperFile = New FileInfo(FileName)
If PaperFile.Exists Then
dsPaper = New DataSet
dsPaper.ReadXml(FileName)
Else
dsPaper = Common.ExamPaper(SID)
'将试题写入文件
If Not (dsPaper Is Nothing) Then
dsPaper.WriteXml(FileName)
End If
End If
PaperFile = Nothing
Return dsPaper
End Function
'
' 函数名称:ReGetPaper(ByVal SID As String) As DataSet
' 摘 要:重新抽取考试题
'
<WebMethod(Description:="根据考号重新抽取相对应的考试题,返回考试题的数据集")> _
Public Function ReGetPaper(ByVal SID As String) As DataSet
Dim dsPaper As DataSet
Dim FileName As String
'考生考题文件路径
FileName = GetExamFile(SID)
'重新抽取试题
dsPaper = Common.ExamPaper(SID)
'将考题写放文件文件
dsPaper.WriteXml(FileName)
'返回试卷数据集
Return dsPaper
End Function
'
' 函数名称:GetDrawingFile(ByVal FileName As String) As DataSet
' 摘 要:读取作图文件
'
<WebMethod(Description:="根据文件名读取相应的作图题XML文件,作图题XML文件的字符流", Bufferresponse:=True, CacheDuration:=60, EnableSession:=False)> _
Public Function GetDrawingFile(ByVal FileName As String) As Byte()
Dim FileInfo As System.IO.FileInfo
Dim LocalFileName As String
LocalFileName = GetDrawFilePath() + "\" + FileName
FileInfo = New System.IO.FileInfo(LocalFileName)
If FileInfo.Exists Then
Dim FileStream As FileStream
Dim int2byte As Integer
Try
FileStream = File.OpenRead(LocalFileName)
Dim tempStream As System.IO.MemoryStream
tempStream = New System.IO.MemoryStream
int2byte = FileStream.ReadByte()
While (int2byte <> -1)
tempStream.WriteByte(CType(int2byte, Byte))
int2byte = FileStream.ReadByte()
End While
Return tempStream.ToArray()
Catch ex As Exception
Return Nothing
End Try
Else
'本地文件不存在,从数据库中读取数据,并存存到本地文件
Dim strSql As String
Dim dsDrawing As DataSet
Dim oSql As SqlDataAccess
Dim FileData As Byte()
strSql = "Select Top 1 * From Drawing Where (XmlFile='" + FileName + "')"
oSql = New SqlDataAccess(strSql)
dsDrawing = oSql.DataSet()
'将数据库数据保存到本地文件
Dim oStreamWrite As StreamWriter
oStreamWrite = New StreamWriter(LocalFileName, False, System.Text.Encoding.UTF8)
oStreamWrite.Write(CType(dsDrawing.Tables(0).Rows(0).Item("XmlData"), String))
oStreamWrite.Flush()
oStreamWrite.Close()
'将本地的文件读出来,返回
Dim FileStream As FileStream
Dim int2byte As Integer
Try
FileStream = File.OpenRead(LocalFileName)
Dim tempStream As System.IO.MemoryStream
tempStream = New System.IO.MemoryStream
int2byte = FileStream.ReadByte()
While (int2byte <> -1)
tempStream.WriteByte(CType(int2byte, Byte))
int2byte = FileStream.ReadByte()
End While
Return tempStream.ToArray()
Catch ex As Exception
Return Nothing
End Try
End If
End Function
'
' 函数名称:GetTmpFile() As DataSet
' 摘 要:读取CAD模板文件
'
<WebMethod(Description:="读取CAD模板文件,返回CAD模板文件的字符流", Bufferresponse:=True, CacheDuration:=60, EnableSession:=False)> _
Public Function GetTmpFile() As Byte()
Dim dsDrawing As New DataSet
Dim FileName As String
Dim FileInfo As System.IO.FileInfo
FileName = Server.MapPath(getParameters("TMPFILE"))
FileInfo = New System.IO.FileInfo(FileName)
If FileInfo.Exists Then
Dim FileStream As FileStream
Dim int2byte As Integer
Try
FileStream = File.OpenRead(FileName)
Dim tempStream As System.IO.MemoryStream
tempStream = New System.IO.MemoryStream
int2byte = FileStream.ReadByte()
While (int2byte <> -1)
tempStream.WriteByte(CType(int2byte, Byte))
int2byte = FileStream.ReadByte()
End While
Return tempStream.ToArray()
Catch ex As Exception
Return Nothing
End Try
Else
Return Nothing
End If
End Function
'
' 函数名称:SubPaper(ByVal dsPaper As DataSet, ByVal Answers As String, ByVal SID As String) As Boolean
' 摘 要:提交考试卷,返回交卷是否成功
'
<WebMethod(Description:="提交考试卷,返回交卷是否成功,True为提交成功;False为提交失败.", CacheDuration:=0, BufferResponse:=False, EnableSession:=False)> _
Public Function SubPaper(ByVal dsPaper As DataSet, ByVal Answers As String, ByVal SID As String) As Boolean
Dim strAnswer As String() '考试答案数组
Dim strSql As String
Dim oSql As SqlDataAccess
strAnswer = Answers.Split("|"c)
'验证输入的字符串合法性
If strAnswer.Length < 3 Then
Return False
End If
strSql = "Update Paper Set CAnswer='" + Common.TextEncode(strAnswer(0)) + _
"',VAnswer='" + Common.TextEncode(strAnswer(1)) + _
"',DAnswer='" + Common.TextEncode(strAnswer(2)) + _
"' Where (SID='" + SID + "');"
strSql += "Update ExamStudent Set HandOn=1 Where (SID='" + SID + "')"
'录入考生试卷答案 + 已交卷登记
'事务处理
Dim oCnn As SqlConnection
Dim oCmd As SqlCommand
Dim oTran As SqlTransaction
Try
oCnn = New SqlConnection(getParameters("SQL"))
If oCnn.State = ConnectionState.Closed Then
oCnn.Open()
End If
oCmd = New SqlCommand
oCmd.Connection = oCnn
oCmd.CommandType = CommandType.Text
oTran = oCnn.BeginTransaction '启动事务处理
oCmd.Transaction = oTran
oCmd.CommandText = strSql
oCmd.ExecuteNonQuery()
oTran.Commit() '进行事务处理
Catch ex As Exception
WriteLog("提交考卷发生错误!" + SID + Chr(10) + Chr(10) + ex.ToString)
oTran.Rollback() '事务处理出错,回滚操作
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -