| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 694 人关注过本帖
标题:感谢昨天版主高手们为我简化代码,现在又有一段看能简化不?
只看楼主 加入收藏
ningzhonghui
Rank: 2
等 级:论坛游民
帖 子:74
专家分:13
注 册:2010-11-19
结帖率:84.62%
收藏
已结贴  问题点数:5 回复次数:7 
感谢昨天版主高手们为我简化代码,现在又有一段看能简化不?
由于刚学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%>

2010-12-29 09:48
hams
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:18
帖 子:912
专家分:3670
注 册:2008-7-30
收藏
得分:2 
不是所有的东西都是简化的

俺不高手,俺也是来学习的。
俺的意见不一定就对,当你不认同时请点忽视按钮。
当走到十字路口不知该如何走时,可在论坛问下路,但你若希望别人能一路把你送到目的地,显然是不现实的,因为别人也有自己要走的路。
2010-12-29 09:50
ningzhonghui
Rank: 2
等 级:论坛游民
帖 子:74
专家分:13
注 册:2010-11-19
收藏
得分:0 
回复 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
像这些也不能简化吗,不过我想也是!呵呵没什么!
2010-12-29 09:54
lele2007
Rank: 5Rank: 5
来 自:广东省深圳
等 级:职业侠客
威 望:6
帖 子:1028
专家分:305
注 册:2007-9-4
收藏
得分:2 
呃。楼主简化上瘾了。。

程序代码:
<%
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
%>

仅供参考哟。。

学习编程www.
2010-12-29 11:29
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:2 
如果表单里没有什么多余的字段(表单所有控件和数据库字段一一对应,没有多余),也不用加判断,可以用下面的代码。
for each ho in Request.Form
     Rs(ho)=Request(ho)
next

否则,就要加一些判断语句,把例外的排除

----我怎能在别人的苦难面前转过脸去----
2010-12-29 11:33
lele2007
Rank: 5Rank: 5
来 自:广东省深圳
等 级:职业侠客
威 望:6
帖 子:1028
专家分:305
注 册:2007-9-4
收藏
得分:0 
以下是引用dzt0001在2010-12-29 11:33:03的发言:

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

否则,就要加一些判断语句,把例外的排除
这个精辟。。 收藏试下。^_^..

学习编程www.
2010-12-29 11:41
ningzhonghui
Rank: 2
等 级:论坛游民
帖 子:74
专家分:13
注 册:2010-11-19
收藏
得分:0 
回复 4楼 lele2007
呵呵谢谢!有点吧见笑拉!
2010-12-29 13:24
ningzhonghui
Rank: 2
等 级:论坛游民
帖 子:74
专家分:13
注 册:2010-11-19
收藏
得分:0 
回复 5楼 dzt0001
对于我来说有点深 ,试试看!能解释下这两句的意思?
2010-12-29 13:28
快速回复:感谢昨天版主高手们为我简化代码,现在又有一段看能简化不?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033087 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved