⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_replace.asp

📁 淘客网上商店网站程序 淘客网上商店网站程序 淘客网上商店网站程序
💻 ASP
📖 第 1 页 / 共 2 页
字号:
	TableName	= Cl.ReplaceBadChar(trim(request("TableName")))
	ColumnName	= Cl.ReplaceBadChar(trim(request("ColumnName")))
	OtherSql	= trim(request("OtherSql"))
	strOld		= trim(request("strOld"))
	strOld1		= trim(request("strOld1"))
	strNew		= trim(request("strNew"))
	thnum		= trim(request("thnum"))
	if thnum="" then
		thnum=0
	End if
	if TableName="" then
		response.write "请输入要替换的数据表名!"
		exit sub
	end if
	if ColumnName="" then
		response.write "请输入要替换的字段名!"
		exit sub
	end if
	if action="Replace1" then
		if strOld="" then
			response.write "请输入要替换的字符!"
			exit sub
		end if
	else 
		if action="Replace2" then
			if strOld="" then
				response.write "请输入要替换的字符开始代码!"
				exit sub
			end if
			if strOld1="" then
				response.write "请输入要替换的字符结束代码!"
				exit sub
			end if
		End if		
	End if
	on error resume next
	Set rs = Server.CreateObject("ADODB.Recordset")
	if thnum<>0 then
		sql = "select Top " & thnum & " " & ColumnName & "  from " & TableName
	else
		sql = "select " & ColumnName & "  from " & TableName
	End if
	if OtherSql<>"" then
	  sql = sql & " where " & OtherSql
	end if
	OpenConn : rs.open sql,conn,1,1
	if err.number<>0 then
		response.write "<font color=red>数据库操作失败,请检查数据表名和字段名添写是否正确</font>"
		exit sub
	end if
	set rs=nothing
	on error GoTo 0
	response.write "正在替换有关数据……<font color=red>在此过程中请勿刷新页面或关闭窗口!</font><br />"
	call ReplaceData(TableName,ColumnName,OtherSql,strOld,strOld1,strNew,thnum)	
	EndTime=timer	

    Response.Write "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center><tr align='center' class='title'><td height='22'><strong>恭喜你!</strong></td></tr>" & vbCrLf
    Response.Write "  <tr class='tdbg'><td height='100' valign='top'><br />" & "共替换:<font color='#0000ff'>"&i&"</font> 项数据。<br />共耗时:<font color='#0000ff'>"&FormatNumber((EndTime-BeginTime)*1000,2)&"</font> 毫秒。" & "</td></tr>" & vbCrLf
    Response.Write "  <tr align='center' class='tdbg'><td><a href='#' onclick=history.go(-1) >&lt;&lt; 返回上一页</a></td></tr></table>"& vbCrLf

End Sub

'**************************************************
'过程名:ReplaceData
'作  用:显示数据表列表
'参  数:TableName	----数据表名
'        ColumnName	----字段名
'        OtherSql	----其他条件
'        strOld		----查找字符(或查找开始代码)
'        strOld1	----查找结束代码
'        strNew		----替换字符
'        thnum		----替换项目数
'**************************************************
Sub ReplaceData(TableName,ColumnName,OtherSql,strOld,strOld1,strNew,thnum)
	dim rs,sql,tt
	Response.Write "<li>正在替换数据</li>&nbsp;&nbsp;"
	Set rs = Server.CreateObject("ADODB.Recordset")
	if thnum<>0 then
		sql = "select top " & thnum & " " & ColumnName & "  from " & TableName 
	else
		sql = "select " & ColumnName & "  from " & TableName 
	End if
	if OtherSql<>"" then
	  sql = sql & " where " & OtherSql
	end if
	rs.open sql,conn,1,3
	
	Select Case Action
	Case "Replace1"
		do while not rs.eof
			if instr(rs(ColumnName),strOld)<>0 then
				rs(ColumnName)=replace(rs(ColumnName),strOld,strNew)
				i=i+1
				Response.Write "."
			end if
			rs.update
			rs.movenext
		loop
	Case "Replace2"
		Set tt=new RegExp
  		tt.IgnoreCase =true
  		tt.Global=True
  		tt.Pattern=strOld&"[^"&strOld1&"]*"&strOld1
		do while not rs.eof
 			rs(ColumnName) = tt.Replace(rs(ColumnName),strNew) 
  			i=i+1
			Response.Write "."
			rs.update
			rs.movenext
		loop
		Set tt=Nothing
	Case "Replace3"
		do while not rs.eof
			Response.Write strNew
			rs(ColumnName)=strNew
			i=i+1
			Response.Write "."
			rs.update
			rs.movenext
		loop
	End Select
	rs.close
	set rs=nothing
	response.write "&nbsp;&nbsp;<font color='#009900'>替换数据成功!</font>"
End Sub

'**************************************************
'过程名:ShowMain
'作  用:显示数据表列表
'参  数:无
'**************************************************
Sub ShowMain()
	dim rs,tablename,temptable
	OpenConn : Set rs = Conn.OpenSchema(4)
	tablename=""
	response.write "<select name='TableName' onChange='changedb()'><option value=''>请选择一个数据表</option>"
	Do Until rs.EOF
		temptable=rs("Table_name")
		if temptable <> tablename and temptable <> "Cl_Admin" and temptable <> "Cl_NotDownload" and temptable <> "MSysAccessXML" and temptable <> "MSysAccessObjects" then
			Response.write "<option value='" & temptable & "'>" & temptable & "</option>"
			Tablename = temptable
		end if
	rs.MoveNext
	Loop
	response.write "</select>"
	rs.close:set rs=nothing
End Sub

'**************************************************
'过程名:ShowChird
'作  用:显示指定数据表的字段列表
'参  数:无
'**************************************************
Sub ShowChird()
	dim rs
	response.write "<body class='tdbg'><form method='post' name='myform11' action='Admin_Replace.asp'><select name='dbname2' onChange=parent.document.myform.ColumnName.value=document.myform11.dbname2.value><option value=''>请选择一个字段 </option>"
	if trim(request("type"))<>"" then	
		OpenConn : Set rs = Conn.OpenSchema(4)	
		Do Until rs.EOF or rs("Table_name") = trim(request("type"))
			rs.MoveNext
		Loop
		Do Until rs.EOF or rs("Table_name") <> trim(request("type"))
			response.write "<option value='"&rs("column_Name")&"'>"&rs("column_Name")&"</option>"
			rs.MoveNext
		loop
		rs.close:set rs=nothing
	End if
	response.write "</select><font color=red> *</font></form><script language = 'JavaScript'>parent.document.myform.ColumnName.value=document.myform11.dbname2.value;</script></body>"
End Sub
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -