<!--#include file="Start.asp"-->
<%
Server.ScriptTimeOut = 9999999
Response.Write "<html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<title>动易SiteWeaver6.5 To SiteWeaver6.6 数据库升级程序</title>" & vbCrLf
Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbCrLf
Response.Write "<link href=""Admin/Admin_STYLE.CSS"" rel=""stylesheet"" type=""text/css"">" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "<body>" & vbCrLf

Action = Trim(request("Action"))
Select Case Action
Case "Upgrade"
    Call Upgrade
Case "Del"
    Call Del
Case Else
    Call Main
End Select
Call CloseConn

Response.Write "</body></html>"

Sub Main()
    Response.Write "<table width=""700""  border=""0"" align=""center"" cellpadding=""1"" cellspacing=""1"" class=""border"">" & vbCrLf
    Response.Write "  <form name=""myform"" method=""post"" action=""Upgrade.asp"">" & vbCrLf
    Response.Write "  <tr align=""center"" class=""topbg"">" & vbCrLf
    Response.Write "    <td height=""25""><strong>SiteWeaver6.5 To SiteWeaver6.6 数据库升级程序</strong></td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  <tr>" & vbCrLf
    Response.Write "    <td height=""60"" align=right>" & vbCrLf
    Response.Write "      <table width=""100%"" height=""60"" border=""0"" cellpadding=""0"" cellspacing=""0"" style=""border-bottom: 1px solid #999999;"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td>" & vbCrLf
    Response.Write "            <strong>适合版本：</strong><br>" & vbCrLf
    Response.Write "            &nbsp;&nbsp;本升级程序适用于官方发布版本动易SiteWeaver6.5到 SiteWeaver6.6的升级。 <br>" & vbCrLf
    Response.Write "            <strong>操作步骤：</strong><br>" & vbCrLf
    Response.Write "            &nbsp;&nbsp;升级前请一定要认真仔细的阅读下面的操作步骤及注意事项！！！" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "          <td align=""right"" width=""200"" Height=""80"" background=""http://www.powereasy.net/images/logo.gif"">&nbsp;</td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "    </td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  <tr class=""tdbg"">" & vbCrLf
    Response.Write "    <td valign=""top "">" & vbCrLf
    Response.Write "      <table width=""90%"" align=""center"" height=""250"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td valign=""top "">" & vbCrLf
    Response.Write "            确定已了解下面的内容后，单击[下一步]继续。" & vbCrLf
    Response.Write "            <textarea style='width:680px;height:200px' style=""font-size: 9pt;"" readonly>"
    Response.Write " ●升级步骤：" & vbCrLf
    Response.Write " 1、将本文件（Upgrade.asp）复制系统根目录下。" & vbCrLf
    Response.Write " 2、在浏览器中输入本文件的地址，如http://localhost/Upgrade.asp，运行本程序。" & vbCrLf
    Response.Write " 3、认真阅读本说明后点“下一步”，开始升级操作。" & vbCrLf
    Response.Write " ●注意事项：" & vbCrLf
    Response.Write " 1、本升级程序只适用于官方发布版本的数据库升级，不适用于其他修改版或美化版的升级工作。" & vbCrLf
    Response.Write " 2、若您是直接在服务器进行升级，则操作成功完成后，一定要删除此文件！以免带来安全隐患。"
    Response.Write "</textarea>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "      <hr>" & vbCrLf
    Response.Write "      <table width=""100%"" height=""30"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td align=""center"">" & vbCrLf
    Response.Write "            <input type=""hidden"" name=""Action"" value=""Upgrade"">" & vbCrLf
    Response.Write "            <input name=""Submit"" type=""submit"" value="" 下一步 "">" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "    </td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  </form>" & vbCrLf
    Response.Write "</table>" & vbCrLf
End Sub

Sub Upgrade()
    'On Error Resume Next
    Dim Table_PE_MailChannel, rsChannel, rsMail, sqlMail, rsCheck
    Table_PE_MailChannel = False


    If SystemDatabaseType = "SQL" Then
        If IsExists("fieldlist", "PE_Label") = True Then
           CONN.execute ("alter table [PE_Label]  alter column  fieldlist  [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL")
        End If
        If IsExists("arrChannelID", "PE_Contacter") = False Then
            CONN.execute ("alter table [PE_Contacter]  add  arrChannelID [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL")
        End If
        If IsExists("ChannelID", "PE_MailChannel") = False Then
            CONN.execute ("create table [PE_MailChannel]( [ChannelID] integer NOT NULL  PRIMARY KEY,[UserID] nvarchar(255),[arrClass] nvarchar(255),[SendNum] integer,[IsUse] bit)")
        End If
    Else
        If IsExists("fieldlist", "PE_Label") = True Then
           CONN.execute ("alter table [PE_Label]  alter  fieldlist  text(255)")
        End If
        If IsExists("arrChannelID", "PE_Contacter") = False Then
            CONN.execute ("alter table [PE_Contacter]  add  COLUMN arrChannelID  text(255)")
        End If
        If IsExists("ChannelID", "PE_MailChannel") = False Then
            CONN.execute ("create table [PE_MailChannel]( [ChannelID] integer not null  PRIMARY KEY,[UserID] text(255) null,[arrClass] text(255),[SendNum] integer, [IsUse] bit )")
        End If
    End If

    Set rsChannel = CONN.execute("select * from PE_Channel where ModuleType = 1")
    sqlMail = "select * from PE_MailChannel"
    Set rsMail = Server.CreateObject("adodb.recordset")
    rsMail.open sqlMail, CONN, 1, 3
    Do While Not rsChannel.EOF
        Set rsCheck = CONN.execute("select * from PE_MailChannel where ChannelID = " & rsChannel("ChannelID"))
        If rsCheck.BOF And rsCheck.EOF Then
            rsMail.addnew
            rsMail("ChannelID") = rsChannel("ChannelID")
            rsMail("UserID") = ""
            rsMail("SendNum") = 10
            rsMail("arrClass") = ""
            rsMail("IsUse") = PE_False
            rsMail.Update
        End If
        rsChannel.movenext
    Loop
    rsMail.Close
    Set rsMail = Nothing
    rsChannel.Close
    Set rsChannel = Nothing
    Call WriteResultInfo

End Sub

Sub WriteResultInfo()
    Response.Write "<table id=""Success_Table"" width=""700"" border=""0"" align=""center"" cellpadding=""1"" cellspacing=""1"" class=""border"">" & vbCrLf
    Response.Write "  <form name=""myform"" method=""post"" action=""Upgrade.asp"">" & vbCrLf
    Response.Write "  <tr align=""center"" class=""topbg"">" & vbCrLf
    Response.Write "    <td height=""25""><strong>SiteWeaver6.5 To SiteWeaver6.5 数据库升级程序</strong></td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  <tr>" & vbCrLf
    Response.Write "    <td height=""60"" align=right>" & vbCrLf
    Response.Write "      <table width=""100%"" height=""60"" border=""0"" cellpadding=""0"" cellspacing=""0"" style=""border-bottom: 1px solid #999999;"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td>" & vbCrLf
    Response.Write "            <strong>升级完成：</strong><br>" & vbCrLf
    Response.Write "            &nbsp;&nbsp;成功将SiteWeaver6.5的数据字段升级至SiteWeaver6.6版！</font><br>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "          <td align=""right"" width=""180"" background=""http://www.powereasy.net/images/logo.gif"">&nbsp;</td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "    </td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  <tr class=""tdbg"">" & vbCrLf
    Response.Write "    <td>" & vbCrLf
    Response.Write "      <table width=""90%"" align=""center"" height=""350"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td valign=""top"">" & vbCrLf
    Response.Write "            <br>" & vbCrLf
    Response.Write "            恭喜您，成功将SiteWeaver6.5的数据字段升级至 SiteWeaver6.6版！！！<br>" & vbCrLf
    Response.Write "            共耗时：<span id=""Info_Timer""></span>秒。<br>" & vbCrLf
    Response.Write "            <font color=red>若您是直接在服务器进行升级，则请立即删除此文件！以免带来安全隐患。</font><br><br>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "      <hr>" & vbCrLf
    Response.Write "      <table width=""100%"" height=""30"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbCrLf
    Response.Write "        <tr>" & vbCrLf
    Response.Write "          <td align=""center"">" & vbCrLf
    Response.Write "            <input type=""hidden"" name=""Action"" value=""SelectDatabase"">" & vbCrLf
    Response.Write "            <input name=""delfile"" type=""button"" value="" 删除此程序 "" onclick=""location='Upgrade.asp?Action=Del'"">" & vbCrLf
    Response.Write "            <input name=""close"" type=""button"" value="" 关闭此窗口 "" onclick=""javascript:onclick=window.close()"">" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>"
    Response.Write "    </td>" & vbCrLf
    Response.Write "  </tr>" & vbCrLf
    Response.Write "  </form>" & vbCrLf
    Response.Write "</table>" & vbCrLf

End Sub

Sub Del()
    On Error Resume Next
    If fso.FileExists(Server.mappath("Upgrade.asp")) Then
        fso.DeleteFile Server.mappath("Upgrade.asp")
    End If
    If Err.Number <> 0 Then
        Response.Write "<li>删除升级程序（Upgrade.asp）失败，错误原因：" & Err.Description & "<br>请使用FTP删除此文件。"
        Err.Clear
        Exit Sub
    Else
        Response.Write "<li>删除升级程序（Upgrade.asp）成功！</li>"
    End If
End Sub
Function IsExists(fieldName, tableName)
    On Error Resume Next
    IsExists = True
    CONN.execute ("select " & fieldName & " from " & tableName)

    If Err Then
        IsExists = False
    End If
    Err.Clear
End Function
%>
