<%


Dim Conn_Sdms, MM_StudentConn_STRING
MM_StudentConn_STRING = "driver={microsoft access driver (*.mdb)};dbq=" & Server.MapPath("database/Data_Sdms.mdb") & ""

Call OpenSdmsConn

Sub OpenSdmsConn()
    On Error Resume Next
    ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/Data_Sdms.mdb")

    Set Conn_Sdms = Server.CreateObject("ADODB.Connection")
    Conn_Sdms.open ConnStr
    If Err Then
        Err.Clear
        Set Conn_Sdms = Nothing
        Response.Write "数据库连接出错，请检查StudentConn.asp文件中的数据库参数设置。"
        Response.End
    End If
End Sub

Sub CloseSdmsConn()
    On Error Resume Next
    If IsObject(Conn_Sdms) Then
        Conn_Sdms.Close
        Set Conn_Sdms = Nothing
    End If
End Sub

Function ReplaceBadChar(strChar)
    If strChar = "" Or IsNull(strChar) Then
        ReplaceBadChar = ""
        Exit Function
    End If
    Dim strBadChar, arrBadChar, tempChar, i
    strBadChar = "+,',--,%,^,&,?,(,),<,>,[,],{,},/,\,;,:," & Chr(34) & "," & Chr(0) & ""
    arrBadChar = Split(strBadChar, ",")
    tempChar = strChar
    For i = 0 To UBound(arrBadChar)
        tempChar = Replace(tempChar, arrBadChar(i), "")
    Next
    tempChar = Replace(tempChar, "@@", "@")
    ReplaceBadChar = tempChar
End Function

Function IsValidID(Check_ID)
    Dim FixID
    If IsNull(Check_ID) Or Check_ID = "" Then
        IsValidID = False
        Exit Function
    End If
    FixID = Replace(Check_ID, "|", "")
    FixID = Replace(FixID, ",", "")
    FixID = Trim(Replace(FixID, " ", ""))
    If FixID = "" Or IsNull(FixID) Or Not IsNumeric(FixID) Then
        IsValidID = False
    Else
        IsValidID = True
    End If
End Function

Function PE_CLng(ByVal str1)
    If IsNumeric(str1) Then
        PE_CLng = CLng(str1)
    Else
        PE_CLng = 0
    End If
End Function

Function GetGrade_Option()
    Dim rsGKind, strOption, i
    i = 0
    Set rsGKind = Conn_Sdms.Execute("select * from Grade where Disabled=false order by OrderID asc")
    Do While Not rsGKind.EOF
        strOption = strOption & "<option value='" & rsGKind("GradeID") & "'"
        If i = 0 Then
            strOption = strOption & " selected"
        End If
        strOption = strOption & ">" & rsGKind("GradeName") & "</option>"
        i = i + 1
        rsGKind.MoveNext
    Loop
    Set rsGKind = Nothing
    GetGrade_Option = strOption
End Function

Function GetClass_Option(ShowType)
    Dim Rs, Sql, RsClass, SqlClass, strOption
    strOption = "<form name='Classes' method='post' action=''>"
    Set Rs = Server.CreateObject("ADODB.Recordset")
    Sql = "select * from Grade where Disabled=false order by OrderID asc"
    Rs.open Sql, Conn_Sdms, 1, 3
    Do While Not Rs.EOF
        strOption = strOption & "<select name='Grade" & Rs("GradeID") & "'>"
        If ShowType = 0 Then
            strOption = strOption & "<option value='All'>全级</option>"
        End If
        Set RsClass = Server.CreateObject("ADODB.REcordset")
        SqlClass = "select * from Class where GradeID=" & Rs("GradeID") & " order by OrderID asc"
        RsClass.open SqlClass, Conn_Sdms, 1, 3
        While (Not RsClass.EOF)
            strOption = strOption & "<option value='" & RsClass("ClassID") & "' >" & RsClass("ClassName") & "</option>"
            RsClass.MoveNext
        Wend
        Set RsClass = Nothing
        Rs.MoveNext
        strOption = strOption & "</select><br>"
    Loop
    Set Rs = Nothing
    strOption = strOption & "</form>"
    GetClass_Option = strOption
End Function


%>