<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Sub startUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_start.Click
       
        Dim examPath As String = WebExam.Common.Configuration.examRootPath
        upPaper_d(examPath)
        Dim s As String = IO.Path.Combine(WebExam.Common.Configuration.appRoot, "data/staticexam/")
        upPaper_d(s)
        Dim ex As String = IO.Path.Combine(WebExam.Common.Configuration.appRoot, "data/exercise/")
        Dim eP As New IO.DirectoryInfo(ex)
        If eP.Exists Then
            For Each subP As IO.DirectoryInfo In eP.GetDirectories
                '练习科目目录
                For Each n As IO.DirectoryInfo In subP.GetDirectories
                    For Each y As IO.DirectoryInfo In n.GetDirectories
                        For Each r As IO.DirectoryInfo In y.GetDirectories
                            For Each f As IO.FileInfo In r.GetFiles
                                If f.Name.ToLower = "testpaper.xml" Then
                                    upPaper(f.FullName)
                                End If
                            Next
                        Next
                    Next
                Next
            
            
            Next
        End If
        
        upUserScript()
        upL(s)
        L_message.Text = "静态文件升级成功！"
    End Sub
    Private Sub upL(ByVal d As String)
        Dim eP As New IO.DirectoryInfo(d)
        If eP.Exists Then
            For Each subP As IO.DirectoryInfo In eP.GetDirectories
                '考试目录
                For Each f As IO.FileInfo In subP.GetFiles
                    If f.Name.ToLower = "scorelist.xml" Then
                        upScoreList(f.FullName)
                    End If
                Next
        
            
            Next
        End If
        
    End Sub
    Private Sub upUserScript()
        Dim ex As String = IO.Path.Combine(WebExam.Common.Configuration.appRoot, "App_Data/usersData/")
        Dim eP As New IO.DirectoryInfo(ex)
        If eP.Exists Then
            For Each subP As IO.DirectoryInfo In eP.GetDirectories
                '人名目录
                Dim ps As New IO.DirectoryInfo(IO.Path.Combine(subP.FullName, "paperscript"))
                If ps.Exists Then
                    For Each n As IO.DirectoryInfo In ps.GetDirectories
                        For Each f As IO.FileInfo In n.GetFiles
                            If f.Name.ToLower = "testpaper.xml" Then
                                upPaper(f.FullName)
                            End If
                        Next
                    Next
                End If
            
            
            
            Next
        End If
        
    End Sub
    
    Private Sub upPaper_d(ByVal d As String)
        Dim eP As New IO.DirectoryInfo(d)
        If eP.Exists Then
            For Each subP As IO.DirectoryInfo In eP.GetDirectories
                '考试目录
                For Each f As IO.FileInfo In subP.GetFiles
                    If f.Name.ToLower = "testpaper.xml" Then
                        upPaper(f.FullName)
                    End If
                Next
                Dim stuKeyMulu As String = IO.Path.Combine(subP.FullName, "stukey")
                Dim sp As New IO.DirectoryInfo(stuKeyMulu)
                If sp.Exists Then
                
                    For Each s As IO.FileInfo In sp.GetFiles
                        If (Not s.Name.EndsWith(".n.xml")) And (Not s.Name.EndsWith(".k.xml")) Then
                            upPaper(s.FullName)
                        End If
                    Next
                End If
            
            Next
        End If
        
    End Sub
    Private Sub upPaper(ByVal fileName As String)
        Dim p As WESoft.TestPaperSystem.ePaper
        p = WESoft.TestPaperSystem.ePaper.getInstanc(fileName)
        
        Dim v As String = p.ver
        p = Nothing
        If v = "3.1" Then
            Dim sp As WESoft.TestPaperSystem.TestPaper = WESoft.TestPaperSystem.TestPaper.getInstanc(fileName)
            sp.getXMLDoc.SelectSingleNode("/paper/ver").InnerText = "3.2"
            sp.save("")
            
        End If
        If v = "1.0" Then
            Dim sp As WESoft.TestPaperSystem.WholePaper = WESoft.TestPaperSystem.WholePaper.getInstanc(fileName)
            Dim xmlDoc As System.Xml.XmlDocument = sp.getXMLDoc
            xmlDoc.SelectSingleNode("/paper/ver").InnerText = "2.0"
            Dim floats As System.Xml.XmlElement = xmlDoc.CreateElement("floats")
            xmlDoc.DocumentElement.AppendChild(floats)
            Dim texts As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/textareas")
            If texts IsNot Nothing Then
                For Each node As System.Xml.XmlElement In texts.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("id"))
                    float.SetAttribute("group", node.GetAttribute("id"))
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                    float.SetAttribute("height", node.GetAttribute("height"))
                    float.SetAttribute("width", node.GetAttribute("width"))
                    float.SetAttribute("type", "t")
                    
                Next
                texts.ParentNode.RemoveChild(texts)
            End If
            Dim medias As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/medias")
            If medias IsNot Nothing Then
                For Each node As System.Xml.XmlElement In medias.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("id"))
                    
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                   
                    float.SetAttribute("type", "m")
                    
                Next
                medias.ParentNode.RemoveChild(medias)
            End If
            Dim drops As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/drops")
            If drops IsNot Nothing Then
                For Each node As System.Xml.XmlElement In drops.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("id"))
                    float.SetAttribute("group", node.GetAttribute("id"))
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                    float.SetAttribute("value", node.GetAttribute("value"))
                    float.SetAttribute("type", "d")
                    float.InnerText = node.GetAttribute("text")
                    
                Next
                drops.ParentNode.RemoveChild(drops)
            End If
            Dim inputs As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/inputs")
            If inputs IsNot Nothing Then
                For Each node As System.Xml.XmlElement In inputs.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("group") + "_" + node.GetAttribute("index"))
                    float.SetAttribute("group", node.GetAttribute("group"))
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                   
                    float.SetAttribute("width", node.GetAttribute("width"))
                    float.SetAttribute("type", "i")
                    
                Next
                inputs.ParentNode.RemoveChild(inputs)
            End If
            Dim radios As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/radios")
            If radios IsNot Nothing Then
                For Each node As System.Xml.XmlElement In radios.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("group") + "_" + node.GetAttribute("value"))
                    float.SetAttribute("group", node.GetAttribute("group"))
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                    float.SetAttribute("height", node.GetAttribute("height"))
                    float.SetAttribute("width", node.GetAttribute("width"))
                    float.SetAttribute("type", "c")
                    
                Next
                radios.ParentNode.RemoveChild(radios)
            End If
            Dim checks As System.Xml.XmlNode = xmlDoc.SelectSingleNode("/paper/main/checks")
            If checks IsNot Nothing Then
                For Each node As System.Xml.XmlElement In checks.ChildNodes
                    
                    Dim float As System.Xml.XmlElement = xmlDoc.CreateElement("float")
                    floats.AppendChild(float)
                    float.SetAttribute("id", node.GetAttribute("group") + "_" + node.GetAttribute("value"))
                    float.SetAttribute("group", node.GetAttribute("group"))
                    float.SetAttribute("left", node.GetAttribute("left"))
                    float.SetAttribute("top", node.GetAttribute("top"))
                    float.SetAttribute("height", node.GetAttribute("height"))
                    float.SetAttribute("width", node.GetAttribute("width"))
                    float.SetAttribute("type", "c")
                    
                Next
                checks.ParentNode.RemoveChild(checks)
            End If
            sp.save("")
        End If
    End Sub
    Private Sub upScoreList(ByVal s As String)
        
        Dim d As String = s.Substring(0, s.Length - 4) + "_0.xml"
        Try
            IO.File.Move(s, d)
           
        Catch ex As Exception

        End Try
        
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>从6.1版本升级到6.2版本</title>
</head>
<body>
    <form id="form1" runat="server">
    <h3>从6.1版本升级到6.2版本</h3>
    
    <p>请在升级前请手动做好数据备份工作，包括数据库和考试系统文件</p>
    <p>为安全起见，请在升级成功后手动删除install文件夹。</p>
    <p>请依次点击下列按钮</p>
    <p><asp:Button runat="server" Text="升级数据库" OnClientClick="if(!confirm('确定升级吗？请在升级前做好数据备份工作！'))return false;var t=window.open();t.location='updb.aspx';return false;" /><asp:Button runat="server" Text="升级静态文件" OnClientClick="return confirm('确定升级吗？请在升级前做好数据备份工作！')" Id="btn_start" /></p>
    
    <p><asp:Label runat="server" id="L_message" ForeColor="Red"></asp:Label></p>
    
    </form>
</body>
</html>
