关于两个类重复代码精简问题
这是.asp网页中的一小段 bcls还有scls这些是传给另一张网页的参数
我想问如何把两个类并成一个类让参数都可以传进去
实在不行分两个类 让重复的代码利用可以吗?
'修改大类
Sub bclsed
bcls=request("bcls")
bclsod=request("bclsod")
sql="update sort set bcls='" & bcls & "' where bcls='" & bclsod & "'"
conn.Execute (sql)
set conn=nothing
'Response.Write sql
Response.Write "<script language=javascript>alert('类修改成功!');"
Response.Write "window.document.location.href='sort.asp';</script>"
end Sub
'修改小类
Sub sclsed
scls=request("scls")
sclsod=request("sclsod")
sql="update sort set scls='" & scls & "' where scls='" & sclsod & "'"
conn.Execute (sql)
set conn=nothing
'Response.Write sql
Response.Write "<script language=javascript>alert('类修改成功!');"
Response.Write "window.document.location.href='sort.asp';</script>"
end Sub
整张网页代码如下
<%If session("userid")="" Then Response.Redirect "index.asp"%>
<!--#include file="conn.asp"-->
<%
Select case Request.QueryString("action")
case "bclsed"
Call bclsed
case "sclsed"
Call sclsed
case else
Response.Write "<script language=javascript>alert('无效提交!');"
Response.Write "window.document.location.href='sort.asp';</script>"
End Select
'修改大类
Sub sclsed
'修改小类
Sub sclsed
%>
[解决办法]
Sub updSort(string_cls,string_clsod)
cls=request(string_cls)
clsod=request(string_clsod)
sql="update sort set " & string_cls & "='" & cls & "' where " & string_cls & "='" & clsod & "'"
conn.Execute (sql)
...
end Sub
类似这样写,就可以了,sub是过程,过程不是类。
[解决办法]
Sub clsed(c$)
cls=request(c & "cls")
clsod=request(c & "clsod")
sql="update sort set " & c & "cls='" & cls & "' where " & c & "cls='" & clsod & "'"
conn.Execute (sql)
set conn=nothing
'Response.Write sql
Response.Write "<script language=javascript>alert('类修改成功!');"
Response.Write "window.document.location.href='sort.asp';</script>"
end Sub
调用就是:
"bcls" 就:
clsed("b")
"scls" 就:
clsed("s")
....