<title>活跃度数据库升级程序</title>
<style type=text/css>
A:link,A:active,A:visited{TEXT-DECORATION:none ;Color:#000000}A:hover{TEXT-DECORATION: underline;Color:#4455aa}
BODY{FONT-SIZE: 12px;COLOR: #000000;FONT-FAMILY:  宋体;
scrollbar-face-color: #DEE3E7;scrollbar-highlight-color: #FFFFFF;scrollbar-shadow-color: #DEE3E7;scrollbar-3dlight-color: #D1D7DC;scrollbar-arrow-color:  #006699;scrollbar-track-color: #EFEFEF;scrollbar-darkshadow-color: #98AAB1;}
font{line-height : normal ;}
TD{font-family: 宋体;font-size: 12px;line-height : 15px ;}
th{background-image: url(bg1.gif);background-color: #4455aa;color: white;font-size: 12px;font-weight:bold;}
td.TableTitle2{background-color: #E4E8EF;}
td.TableBody1{background-color: #FFFFFF;line-height : normal ;}
td.TableBody2{background-color: #E4E8EF;line-height : normal ;}
.tableBorder1{width:760;border: 1px; background-color: #6595D6;}
.tableBorder2{width:760;border: 1px #DEDEDE solid; background-color: #EFEFEF;}
#TableTitleLink A:link, #TableTitleLink A:visited, #TableTitleLink A:active {COLOR: #FFFFFF;	TEXT-DECORATION: none;}#TableTitleLink A:hover {COLOR: #FFFFFF;	TEXT-DECORATION: underline;}
input,select,Textarea,option{font-family:Tahoma,Verdana,"宋体"; font-size: 12px; line-height: 15px;COLOR: #000000;}
.normalTextSmall {     font-size : 11px;    color : #000000;     font-family: Verdana, Arial, Helvetica, sans-serif;}
a.navlink:link {color: #000000; text-decoration:none}
a.navlink:visited {color: #000000; text-decoration:none }
a.navlink:hover {color: #003399; text-decoration:none }
</style>
<%
'===============================
'Access官方版本和SQL非官方版使用
'===============================
'On Error Resume Next
Server.ScriptTimeout=9999999
Dim Conn
TableTop="<TABLE border=""0"" width=""100%"" align=""center"" class=tableBorder1 cellspacing=0 cellpadding=0><tr><td class=tablebody1>"
TableEnd="</td></tr></table>"

Select Case Request("Action")
Case "Step1"
	Step1()
Case "Step2"
	Step2()
Case Else
	Step1()
End Select

Sub Step1()
%>

<table cellspacing=1 cellpadding=3 align=center class=tableBorder1>
<tr>
<th width="100%" height="24" colspan="2" ID=TableTitleLink>活跃度数据库升级程序</th>
</tr>
<tr>
<td width="100%" Class="tablebody1" style="font-size: 12px;line-height : 18px ;">
<B>操作说明，请仔细阅读操作说明后进行操作</B>：<BR>
1、<font color=blue>强烈建议您在本地计算机系统完成升级操作并做好<font color=red>备份</font>工作，如不能在本地进行升级操作也请升级前<font color=red>备份</font>好您的所有文件和数据</font></td>
</tr>
<FORM METHOD=POST ACTION="?Action=Step2">
<tr>
<td width="100%" Class="tablebody1" style="font-size: 12px;line-height : 18px ;">
<B>第一步</B>：选择数据库类型<input type=radio name="DatabaseType" value=0 checked>ACCESS&nbsp;
<input type=radio name="DatabaseType" value=1 >SQL&nbsp;
<br>
<BR>
如果是ACCESS数据库在此输入(SQL忽略此处)<br>
请输入数据库地址：
<input type=text size=20 name="database" value="dvbbs7.mdb"> 
相对路径，如data目录的data/dvbbs7.mdb或者根目录dvbbs7.mdb<BR>
<br>
如果是SQL在此输入参数:(ACCESS忽略此处)<br>
数据库地址:
<input name="SqlLocalName" type=text id="SqlLocalName" value="(local)" size=20><br>
数据库用户名:
<input name="SqlUsername" type=text id="SqlUsername" value="dvbbs" size=20><br>
数据库密码:
<input name="SqlPassword" type=password id="SqlPassword" size=20><br>
数据库名称:
<input name="SqlDatabaseName" type=text id="SqlDatabaseName" value="dvbbs7" size=20><br><BR>
<input name="submit" type="submit" value="升级数据库结构"></td>
</tr>
</FORM>
</table><BR>
<TABLE cellSpacing="0" cellPadding="0" width="98%" border="0" align="center">
<tr><td align="center"><table align="center"><tr>
<td align="center">Powered By ：<a href = "http://www.dvbbs.net/download.asp" target = "_blank">若阑</a><br>
  Copyright &copy;2002 - 2005  <strong><font face="Verdana,"><a href="www.qqpet.com"><br>
  www.qqpet.com</a></font></strong></td>
</tr></table>
</td></tr>
</table>
<%
End Sub

'更新数据库结构
Sub Step2()
	Dim SqlDb
	On Error Resume Next
	If Request("database")="" Then
		Response.Write "请输入正确的数据库名称！"
		Response.End
	End If
	if Request("DatabaseType")=0 then
		Conntting(Request("database"))
	else
		SqlDb=""
		SqlDb=SqlDb & Request("SqlDatabaseName") & "||"
		SqlDb=SqlDb & Request("SqlPassword") & "||"
		SqlDb=SqlDb & Request("SqlUsername") & "||"
		SqlDb=SqlDb & Request("SqlLocalName") 
		Conntting(SqlDb)
	end if
%>
<table cellspacing=1 cellpadding=3 align=center class=tableBorder1>
<tr>
<th width="100%" height="24" colspan="2" ID=TableTitleLink>活跃度数据库升级程序 <span class="tablebody1">更新完成</span></th>
</tr>

<tr>
<td width="100%" Class="tablebody1" style="font-size: 12px;line-height : 18px ;"><BR>
更新完成&nbsp;&nbsp;</td>
</tr>

</table>
<%
	if Request("DatabaseType")=0 then
		AddColumn "Dv_User","RLStartTime","datetime default Now()"
	else
		AddColumn "Dv_User","RLStartTime","datetime default GetDate()"
	end if
	AddColumn "Dv_User","RLActTimeT","int default 0"
	AddColumn "Dv_User","RLActTimeA","int default 0"
	AddColumn "Dv_User","RLTopicCountA","int default 0"
	
	On Error Resume Next
	if Request("DatabaseType")=0 then
		Conn.Execute("Update Dv_User Set RLStartTime=Now(), RLActTimeT=0, RLActTimeA=0, RLTopicCountA=0")
		
	else
		Conn.Execute("Update Dv_User Set RLStartTime=GetDate(),RLActTimeT=0, RLActTimeA=0, RLTopicCountA=0")
	end if
	If Err Then
		Response.Write TableTop & "更新数据出现错误，原因" & Err.Description & "<BR>" & TableEnd
		Err.Clear
		Response.Flush
	Else
		Response.Write TableTop & "更新数据成功!" & TableEnd
		Response.Flush
	End If
	
	Response.Write TableTop & "数据库更新结束！ <BR>" & TableEnd
	Response.Flush
	CloseData()
End Sub



Sub Conntting(db)
	'On Error Resume Next
	Set Conn = Server.CreateObject("ADODB.Connection")
	
	if Request("DatabaseType")=1 then
		Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName,MyDb
		MyDb = split(db,"||")
		SqlDatabaseName = MyDb(0)
		SqlPassword = MyDb(1)
		SqlUsername = MyDb(2)
		SqlLocalName = MyDb(3)
		ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
	else
		ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db)
	end if
	Conn.Open ConnStr
	If Err Then
		Err.Clear
		Set Conn = Nothing
		Response.Write "数据库连接出错，请检查连接字串，请确认您输入的数据库地址是否正确。"&db
		Response.End
	End If
End Sub


Sub CloseData()
	Conn.Close
	Set Conn=Nothing
End Sub

'添加字段通用函数
Sub AddColumn(TableName,ColumnName,ColumnType)
	On Error Resume Next
	Conn.Execute("Alter Table "&TableName&" Add "&ColumnName&" "&ColumnType&"")
	If Err Then
		Response.Write TableTop & "新建 "&TableName&" 表中字段<font color=blue>错误</font>，请手动将数据库中 <B>"&ColumnName&"</B> 字段建立，属性为 <B>"&ColumnType&"</B>，原因" & Err.Description & "<BR>" & TableEnd
		Err.Clear
		Response.Flush
	Else
		Response.Write TableTop & "新建 "&TableName&" 表中字段 "&ColumnName&" 成功 <BR>" & TableEnd
		Response.Flush
	End If
End Sub

%>