ASP Application of function

  1, often write system, then login procedures are generally from the beginning, each on a system to write a login, good trouble. 

  Sign simply be a function test it, for me, can be most competent:) 



<%
  Function chk_regist (requestname, requestpwd, tablename, namefield, pwdfield, reurl) 
  Dim cn_name, cn_pwd 
  Cn_name = trim (request.form ( "" & requestname &"")) 
  Cn_pwd = trim (request.form ( "" & requestpwd &"")) 
  If cn_name = "" or cn_pwd = "" then 
  Response.Write ( "<script language=javascript> alert (" "Please complete account password integrity, cooperation Thank you 。""); history.go (-1) </ script>") 
  End if 
  Set rs = Server.CreateObject ( "ADODB.Recordset") 
  Sql = "Select * from the" tablename & & "where" namefield &"='"& cn_name & & " '" 
  Rs.open sql, conn, 1,1 
  If rs.eof then 
  Response.Write ( "<script language=javascript> alert (" "the absence of the Member ID, the application has not been confirmed 。""); history.go (-1) </ script>") 
  Else 
  If rs ( "" & pwdfield &"")= cn_pwd then 
  Session ( "cn_name") = rs ( "" namefield & & "") 
  Response.Redirect (reurl) 
  Else 
  Response.Write ( "<script language=javascript> alert (" "remind your ID and password is not anastomosis. Attention to the figures and case 。""); history.go (-1) </ script>") 
  End if 
  End if 
  Rs.close 
  Set rs = Nothing 
  End Function 
%>



  Parameters: 
  Chk_regist (requestname, requestpwd, tablename, namefield, pwdfield, reurl) 

  Requestname to accept HTML page of the names of the input controls were INPUT 
  Requestpwd to accept HTML page enter a password control of the INPUT 
  Tablename preservation registered in the database for information table 
  Namefield table for the information stored in the user name field of 
  Pwdfield table for the information stored in the name of user passwords 
  Reurl to correct login page after Jump 

  Examples cited are as follows: 



<%
  Call chk_regist ( "b_name", "b_pwd", "cn_admin", "cn_name", "cn_pwd", "admin.asp") 
%>


  Debugging Address: http://www.cnbruce.com/test/function/regist.asp 


  2, a regular things are likely to carry out the current state of judgement, that is, doing a general field (numerical types, the default value of 0) 
  Value of the field through the state to modify the effect of switching.    Well, I have done a function, easily let themselves easily. 



<%
  Function pvouch (tablename, fildname, autoidname, indexid) 
  Dim fildvalue 
  Set rs = Server.CreateObject ( "ADODB.Recordset") 
  Sql = "Select * from" & & tablename "where" & autoidname &"="& indexid 
  Rs.Open sql, conn, 2,3 
  Fildvalue = rs ( "" fildname & & "") 
  = 0 then if fildvalue 
  Fildvalue = 1 
  Else 
  Fildvalue = 0 
  End if 
  Rs ( "" & fildname &"")= fildvalue 
  Rs.update 
  Rs.close 
  Set rs = Nothing 
  End Function 
%>



  Parameters: 
  Pvouch (tablename, fildname, autoidname, indexid) 

  Tablename of the things in the database table 
  Fildname things to show that the state of the fields (field-type numerical) 
  Autoidname in the form of automatic code 
  Indexid state counterparts to amend the value of automatic code 

  Examples cited are as follows: 


<%
  Dowhat = request.QueryString ( "dowhat") 
  P_id = cint (request.QueryString ( "p_id")) 

  If dowhat = "tj" and p_id <> "" then 
  Call pvouch ( "cn_products", "p_vouch", "p_id" p_id) 
  End if 
%>

  <% If rs ( "p_vouch") = 0 then%> 
  <A href = showpro.asp? Dowhat & p_id = = tj <% = rs ( "p_id ")%>> recommend </ a> 
  <% Else%> 
  <A href = showpro.asp? Dowhat & p_id = = tj <% = rs ( "p_id ")%>> recommend cancellation </ a> 
  <% End if%> 



  Debugging Address: http://www.cnbruce.com/test/function/showpro.asp 

  3, written site for many SMEs, in general Products is a big project, then made the pages is different. 
  Otherwise is horizontally to several, or is Shubai to several, or even to the station several times again and the Gao Ge, trouble also tired. 
  Simply write a function to ease what was to become Below 



<%
  Function showpros (tablename, topnum, fildname, loopnum, typenum) 
  Set rs = Server.CreateObject ( "ADODB.Recordset") 
  Sql = "Select top" topnum & & "* from" & tablename 
  Rs.Open sql, conn, 1,1 
  If rs.eof and rs.bof then 
  Response.Write ( "temporarily the record") 
  Else 
  Response.Write ( "<table width='100%'>") 
  For i = 1 to rs.recordcount 
  If (i mod loopnum = 1) then 
  Response.write "<tr>" 
  End if 
  Select case typenum 
  Case "1" 
  Response.Write ( "<td> <table width='100%'> <tr> <td bgcolor=red width='50%'>") 
  Response.Write (rs ( "" & fildname &"")) 
  Response.Write ( "</ td> <td bgcolor=black>") 
  Response.Write ( "mode 1" & & i "record") 'here "mode 1" can be replaced for the remaining field shows that the value of 
  Response.Write ( "</ td> </ tr>") 'If more fields and continue to add new tables to display line 
  Response.Write ( "</ table> </ td>") 
  Case "2" 
  Response.Write ( "<td> <table width='100%'> <tr> <td bgcolor=red>") 
  Response.Write (rs ( "" & fildname &"")) 
  Response.Write ( "</ td> </ tr>") 
  Response.Write ( "<tr> <td bgcolor=black>") 
  Response.Write ( "Type 2" & & i "record") 
  Response.Write ( "</ td> </ tr>") 
  Response.Write ( "</ table> </ td>") 
  End select 
  If (i mod loopnum = 0) then 
  Response.write "</ tr>" 
  End if 
  Rs.movenext 
  Next 
  Response.Write ( "</ table>") 
  End if 
  Rs.close 
  Set rs = Nothing 
  End function 
%>



  Parameter Description: showpros (tablename, topnum, fildname, loopnum, typenum) 

  Whichpro to choose what type of products 
  Topnum said that the number of records extraction 
  Fildname debugging show that the field, eliminating the specific application of the parameters used directly in the internal function 
  Loopnum show that the cycle of each row of the few records 
  Typenum show that the cycle: at present the two types of horizontal parallel, vertical display the same data records tied to the different records 

  Examples cited are as follows: 


<%
  If request.form ( "then submit ")<>"" 
  Topnum = request.form ( "topnum") 
  Loopnum = request.form ( "loopnum") 
  Typenum = request.form ( "typenum") 
  Else 
  Topnum = 8 
  Loopnum = 2 
  Typenum = 1 
  End if 
%>
  <% Call showpros ( "cn_products" topnum, "p_name" loopnum, typenum)%> 
  <form Action=index.asp method=post> 
  Records show that the total number of: <input name = topnum value = <= topnum%%>> 
  Showing rows cycle: <input name = loopnum value = <= loopnum%%>> 
  Showing the way type: <typenum select name => 
  <option Value="1"> Mode 1 </ option> 
  <option Value="2"> method 2 </ option> 
  </ Select> 
  <input Type=submit name=submit value=Sure> 
  </ Form> 



  Debugging Address: http://www.cnbruce.com/test/function/index.asp 


  Finally, you can choose to download documents Show: http://www.cnbruce.com/test/function/function.rar 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: ,

Releated Articles


0 Comments to “ASP Application of function”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.