注册 登录
编程论坛 ASP技术论坛

感谢昨天版主高手们为我简化代码,现在又有一段看能简化不?

ningzhonghui 发布于 2010-12-29 09:48, 694 次点击
由于刚学asp 用的都是笨的代码写法 像以上看起来一大堆又长,希望版主们或高手支招
我现在只能慢慢的向你们学高一点的层次学习拉!呵呵!可不要见怪!我就是爱学!
程序代码:
<%
if session("adminlogin")<>sessionvar then
  response.Write
"权限不足"
response.end
end if
Server.ScriptTimeOut
=5000
%>
<%
if request("action")="modify" then
pass
=request.Form("pass")
pass1
=request.Form("pass1")
pass2
=request.Form("pass2")
password
=request.Form("passd")
name
=request.Form("name")
link
=request.Form("link")
link_target
=request.Form("link_target")
description
=request.Form("description")
logo_id
=request.Form("logo_id")
logo_alpha
=request.Form("logo_alpha")
plugins
=request.Form("plugins")
backgrounds
=request.Form("backgrounds")
bg
=request.Form("bg")
skin
=request.Form("skin")
skins
=request.Form("skins")
skin_id
=request.Form("skin_id")
lists
=request.Form("lists")
list_delete
=request.Form("list_delete")
auto_play
=request.Form("auto_play")
play_id
=request.Form("play_id")
play_mode
=request.Form("play_mode")
mixer_id
=request.Form("mixer_id")
mixer_color
=request.Form("mixer_color")
mixer_displace
=request.Form("mixer_displace")
mixer_filter
=request.Form("mixer_filter")
src_handler
=request.Form("src_handler")
lrc_handler
=request.Form("lrc_handler")
bg_video
=request.Form("bg_video")
bg_lrc
=request.Form("bg_lrc")
plugins_disabled
=request.Form("plugins_disabled")
context_menu
=request.Form("context_menu")
default_skin
=request.Form("default_skin")
counter
=request.Form("counter")
src
=request.Form("src")
lrc
=request.Form("lrc")
label
=request.Form("label")
type_id
=request.Form("type_id")
other
=request.Form("other")
bgmclass
=request.Form("bgmclass")
if pass<> pass then

 r
="no"
  response.write
"<script language=javascript>"   
        response.write
"alert('原来的密码不正确啊??');"   
        response.write
"</script>"
        response.write
"<script language=javascript>location='javascript:history.back(1)'</script>"
   Response.End
end if
  
if pass="" then
  r
="no"
  response.write
"<script language=javascript>"   
        response.write
"alert('请填写原来的密码才能确定成功');"   
        response.write
"</script>"
        response.write
"<script language=javascript>location='javascript:history.back(1)'</script>"
   Response.End
  
end if
  
if pass1<>"" and pass2 <> "" then
   
if pass1 <> pass2 then
    r
="no"
    response.write
"<script language=javascript>"   
        response.write
"alert('两个密码填写不一样!!');"   
        response.write
"</script>"
        response.write
"<script language=javascript>location='javascript:history.back(1)'</script>"
     Response.End   
     
else
     p
="yes"
   
end if
  
end if

 
if r<>"no" then
  sql
="select * from admin where username='"&user&"'"
  
Set rs3=Server.CreateObject("ADODB.RecordSet")
  rs3.open sql,conn,
1,3
  
if p="yes" then
  pass
=md5(pass1)
  rs3(
"password")=pass
  
end if
rs3(
"name")=name
rs3(
"link")=link
rs3(
"link_target")=link_target
rs3(
"description")=description
rs3(
"logo_id")=logo_id
rs3(
"logo_alpha")=logo_alpha
rs3(
"plugins")=plugins
rs3(
"backgrounds")=backgrounds
rs3(
"bg")=bg
rs3(
"skin")=skin
rs3(
"skins")=skins
rs3(
"skin_id")=skin_id
rs3(
"lists")=lists
rs3(
"list_delete")=list_delete
rs3(
"auto_play")=auto_play
rs3(
"play_id")=play_id
rs3(
"play_mode")=play_mode
rs3(
"mixer_id")=mixer_id
rs3(
"mixer_color")=mixer_color
rs3(
"mixer_displace")=mixer_displace
rs3(
"mixer_filter")=mixer_filter
rs3(
"src_handler")=src_handler
rs3(
"lrc_handler")=lrc_handler
rs3(
"bg_video")=bg_video
rs3(
"bg_lrc")=bg_lrc
rs3(
"plugins_disabled")=plugins_disabled
rs3(
"context_menu")=context_menu
rs3(
"default_skin")=default_skin
rs3(
"counter")=counter
rs3(
"src")=src
rs3(
"lrc")=lrc
rs3(
"label")=label
rs3(
"type_id")=type_id
rs3(
"other")=other
rs3(
"bgmclass")=bgmclass
  rs3.update
  rs3.close

 
end if
end if%>

7 回复
#2
hams2010-12-29 09:50
不是所有的东西都是简化的
#3
ningzhonghui2010-12-29 09:54
回复 2楼 hams
rs3("name")=name
rs3("link")=link
rs3("link_target")=link_target
rs3("description")=description
rs3("logo_id")=logo_id
rs3("logo_alpha")=logo_alpha
rs3("plugins")=plugins
rs3("backgrounds")=backgrounds
rs3("bg")=bg
rs3("skin")=skin
rs3("skins")=skins
rs3("skin_id")=skin_id
rs3("lists")=lists
rs3("list_delete")=list_delete
rs3("auto_play")=auto_play
rs3("play_id")=play_id
rs3("play_mode")=play_mode
rs3("mixer_id")=mixer_id
rs3("mixer_color")=mixer_color
rs3("mixer_displace")=mixer_displace
rs3("mixer_filter")=mixer_filter
rs3("src_handler")=src_handler
rs3("lrc_handler")=lrc_handler
rs3("bg_video")=bg_video
rs3("bg_lrc")=bg_lrc
rs3("plugins_disabled")=plugins_disabled
rs3("context_menu")=context_menu
rs3("default_skin")=default_skin
rs3("counter")=counter
rs3("src")=src
rs3("lrc")=lrc
rs3("label")=label
rs3("type_id")=type_id
rs3("other")=other
rs3("bgmclass")=bgmclass
像这些也不能简化吗,不过我想也是!呵呵没什么!
#4
lele20072010-12-29 11:29
呃。楼主简化上瘾了。。

程序代码:
<%
if session("adminlogin")<>sessionvar then
  response.Write
"权限不足"
  response.end
end if
Server.ScriptTimeOut
=5000
%>

<%
if request("action")="modify" then
pass
=request.Form("pass")
pass1
=request.Form("pass1")
pass2
=request.Form("pass2")
password
=request.Form("passd")
name
=request.Form("name")
link
=request.Form("link")
link_target
=request.Form("link_target")
description
=request.Form("description")
logo_id
=request.Form("logo_id")
logo_alpha
=request.Form("logo_alpha")
plugins
=request.Form("plugins")
backgrounds
=request.Form("backgrounds")
bg
=request.Form("bg")
skin
=request.Form("skin")
skins
=request.Form("skins")
skin_id
=request.Form("skin_id")
lists
=request.Form("lists")
list_delete
=request.Form("list_delete")
auto_play
=request.Form("auto_play")
play_id
=request.Form("play_id")
play_mode
=request.Form("play_mode")
mixer_id
=request.Form("mixer_id")
mixer_color
=request.Form("mixer_color")
mixer_displace
=request.Form("mixer_displace")
mixer_filter
=request.Form("mixer_filter")
src_handler
=request.Form("src_handler")
lrc_handler
=request.Form("lrc_handler")
bg_video
=request.Form("bg_video")
bg_lrc
=request.Form("bg_lrc")
plugins_disabled
=request.Form("plugins_disabled")
context_menu
=request.Form("context_menu")
default_skin
=request.Form("default_skin")
counter
=request.Form("counter")
src
=request.Form("src")
lrc
=request.Form("lrc")
label
=request.Form("label")
type_id
=request.Form("type_id")
other
=request.Form("other")
bgmclass
=request.Form("bgmclass")


if pass<> pass then r="no":info="原来的密码不正确啊??"
if pass="" then r="no":info="请填写原来的密码才能确定成功"
if pass1<>"" and pass2 <> "" then
  
if pass1 <> pass2 then
    r
="no":info="两个密码填写不一样!!"
  
else
    p
="yes"
  
end if
end if

if r="no" then


 response.write
"<script language='javascript'>alert('"&info&"');location='javascript:history.back(1);</script>"


 Response.End

end if

'开始写入数据库
  sql="select * from admin where username='"&user&"'"
  
Set rs3=Server.CreateObject("ADODB.RecordSet")
  rs3.open sql,conn,
1,3
  
if p="yes" then
    pass
=md5(pass1)
    rs3(
"password")=pass
  
end if
rs3(
"name")=name
rs3(
"link")=link
rs3(
"link_target")=link_target
rs3(
"description")=description
rs3(
"logo_id")=logo_id
rs3(
"logo_alpha")=logo_alpha
rs3(
"plugins")=plugins
rs3(
"backgrounds")=backgrounds
rs3(
"bg")=bg
rs3(
"skin")=skin
rs3(
"skins")=skins
rs3(
"skin_id")=skin_id
rs3(
"lists")=lists
rs3(
"list_delete")=list_delete
rs3(
"auto_play")=auto_play
rs3(
"play_id")=play_id
rs3(
"play_mode")=play_mode
rs3(
"mixer_id")=mixer_id
rs3(
"mixer_color")=mixer_color
rs3(
"mixer_displace")=mixer_displace
rs3(
"mixer_filter")=mixer_filter
rs3(
"src_handler")=src_handler
rs3(
"lrc_handler")=lrc_handler
rs3(
"bg_video")=bg_video
rs3(
"bg_lrc")=bg_lrc
rs3(
"plugins_disabled")=plugins_disabled
rs3(
"context_menu")=context_menu
rs3(
"default_skin")=default_skin
rs3(
"counter")=counter
rs3(
"src")=src
rs3(
"lrc")=lrc
rs3(
"label")=label
rs3(
"type_id")=type_id
rs3(
"other")=other
rs3(
"bgmclass")=bgmclass
  rs3.update
  rs3.close
end if
%>

仅供参考哟。。
#5
dzt00012010-12-29 11:33
如果表单里没有什么多余的字段(表单所有控件和数据库字段一一对应,没有多余),也不用加判断,可以用下面的代码。
for each ho in Request.Form
     Rs(ho)=Request(ho)
next

否则,就要加一些判断语句,把例外的排除
#6
lele20072010-12-29 11:41
以下是引用dzt0001在2010-12-29 11:33:03的发言:

如果表单里没有什么多余的字段(表单所有控件和数据库字段一一对应,没有多余),也不用加判断,可以用下面的代码。
for each ho in Request.Form
     Rs(ho)=Request(ho)
next

否则,就要加一些判断语句,把例外的排除
这个精辟。。 收藏试下。^_^..
#7
ningzhonghui2010-12-29 13:24
回复 4楼 lele2007
呵呵谢谢!有点吧见笑拉!
#8
ningzhonghui2010-12-29 13:28
回复 5楼 dzt0001
对于我来说有点深 ,试试看!能解释下这两句的意思?
1