adoconn.asp

来自「《动态网页设计基础教程》,胡杰,科学出版社」· ASP 代码 · 共 270 行

ASP
270
字号
<!-- #include file="adovbs.inc" -->
<%
Dim Adoconn

Function Adoconnection()
Dim connstr

   '*************************************************
   '*        Link SQL Server mode                   *
   '*************************************************
   connstr="Driver={SQL Server};Database=Evaluation;Server=(local);uid=sa;pwd="
   Set Adoconnection=Server.CreateObject("ADODB.Connection")
   
   '************************************************************************************************************
   '*        Link Access mode                                                                                  *
   '* connstr="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("Mydb\Evaluation.MDB")*   
   '************************************************************************************************************
   Adoconnection.open connstr
   Set Adoconn=Adoconnection
End Function

Function GetRecordset(sqlstr)
   Adoconnection()
   Set GetRecordset=Server.CreateObject("ADODB.Recordset")
   GetRecordset.Open sqlstr,Adoconn,adOpenKeyset,adLockOptimistic,adCmdText
End Function

Function PutRecordset(sqlstr)
   Adoconnection()
   Adoconn.Execute(sqlstr)
   if Err.Number <> 0 then
       response.write "保存失败!"
       Set Adoconn=nothing
       PutRecordset=False
   else
       Set Adoconn=nothing
       PutRecordset=True
   end if
End Function


Sub SetSupervisor()
Dim myrs
   Set myrs=GetRecordset("Select Dbacode from Operators where DbaCode='super'")
   If myrs.eof then
      Adoconn.Execute "Insert into Operators(dbaCode,DbaName,DbaPW) values('super','王风茂','my7578')"
   End if
   Set Adoconn=Nothing
   Set myrs=nothing
End Sub

Function Call_SP(SPname,var1,var2)
   Adoconnection()
   
   Set cmdQuery=Server.CreateObject("ADODB.Command")
   Set cmdQuery.ActiveConnection = Adoconn
   cmdQuery.CommandText=SPname
   cmdQuery.CommandType=adCmdStoredProc
   
   Set paraList=Server.CreateObject("ADODB.Parameter")
   paraList.Name=SPname
   paraList.Direction=adParamInput
   ParaList.Type=adVarChar
   ParaList.Size=Len(var1)
   paraList.Value=Var1
   
   cmdQuery.Parameters.Append paraList
   
   Set Call_sp=cmdQuery.Execute()
   
End Function   
   
Dim ItemArray,ItemCount
Sub ListItem(sqlstr)
Dim rs
 
   Set rs=GetRecordset(sqlstr)
   
   if not rs.eof then
      ItemCount=rs.recordcount
      ItemArray=rs.GetRows()
      'ItemArray(field_i,record_i)
   end if
   set rs=Nothing
   set Adoconn=Nothing 
End sub

Function ValidPersonal(uid,pwd,sqlstr)
Dim rs
   Adoconnection()
   
   Set rs=Adoconn.Execute(sqlstr)

   if not rs.eof then
      Session("uid")=uid
      Session("uname")=rs(1)
      If (Session("Kind")="学生") then
         Session("College")=rs("Scollege")
         Session("ClassNo")=rs("SClass")
      ElseIf (Session("Kind")="教师" or Session("Kind")="室主任" or Session("Kind")="主任") Then
         Session("College")=rs("Tcollege")
         Session("Department")=rs("TDepartment")
      End if
      Session("pwd")=pwd
      Session("logined")=True
      Session("logintime")=now
      ValidPersonal=True
   else
      Session("logined")=False
      ValidPersonal=False
   end if
   Set rs=nothing
   Set Adoconn=nothing
End Function

Function UpdatePWD(pwd1,pwd2,sqlstr)
   Adoconnection()
   Adoconn.Execute sqlstr

   If err.number=0 then
      UpdatePWD=True
      Session("pwd")=pwd1
   Else
      UpdatePWD=False
   End if
   Set Adoconn=Nothing
End Function

Sub WriteLoginLog(msg)
dim sql
    
    session("LoginTime")=now()
    sql="Insert into Operatorlog(OperatorID,OperatorName,LoginTime,Operated) "
    sql=sql+"values ('"& session("uid") & "','" & session("uname") & "','" & session("LoginTime") & "','" & msg & "')"
    
    Adoconnection()
    
    Adoconn.Execute(sql)

    set Adoconn=nothing
End Sub
    
Sub ScoreStatistic()
  Dim rs
  Dim sqlstr
  
  sqlstr="insert into ScoreResult "
  sqlstr=sqlstr & "select T.tid,T.tname,T.tdepartment,TV.tscore,SV.sscore,TV.tscore+SV.sscore,TV.yeartoyear,TV.term "
  sqlstr=sqlstr & "from Teachers T,TScoreView TV, SscoreView SV"
  sqlstr=sqlstr & " Where T.Tid=TV.Tid and TV.Tid=SV.Tid and TV.YeartoYear=SV.YeartoYear and TV.term=SV.term"

  Adoconnection()
  Adoconn.Execute sqlstr
  Set Adoconn=nothing
End Sub  
%>

<%
Sub CA_Supervisor() 
If (Session("uid")<>"super") Then
%>
<script language="vbscript">
        MsgBox "对不起,只有超级管理员(supervisor)有权使用此功能!"
        History.back
</script>
<%
End if
End Sub
%>

<%
Sub Certificate()
If (Session("logined")<>True) then
%>
<script language="VBscript">
  MsgBox "您无权使用!"
  history.back
</script>
<%
End If
End Sub
%>

<%
Sub CA_Supervisor() 
If (Session("uid")<>"super") Then
%>
<script language="vbscript">
        MsgBox "对不起,只有超级管理员有权使用此功能!"
        History.back
</script>
<%
End if
End Sub
%>

<%
Sub CheckKey(sqlstr)
  set Rs=GetRecordset(sqlstr)
  If Not rs.EOF then
     Set Adoconn=nothing
%>
<script language="vbscript">
        MsgBox "输入了重复编码!"
        History.back
</script>
<%
  Else
     Set Adoconn=nothing
  End if  
End Sub
%>

<%
Function SearchTeacher(Tno,Tpw)
Dim Rs 
     
    set RS=GetRecordset("select * from Teachers where TID='" & TNo & "' and Tpw='" & Tpw & "'") 
    If Rs.recordcount <= 0 Then
       Set RS=nothing
       Set Adoconn=Nothing
       SearchTeacher=0 
%>
  <script language="vbscript">
        MsgBox "没有所查教师信息!"
        History.back
  </script>
<%
    Else
       Set RS=nothing 
       Set Adoconn=Nothing
       SearchTeacher=1
    End if        
End Function
%>

<%
Sub SplitString(instr)
Dim SubStrArray
SubStrArray = split(instr,",",-1, 1)
for i=0 to uBound(SubStrArray)

Next

End sub
%>

<%
Sub GenerateTerm()
Dim year,month,day

    year=DATEPART("YYYY",DATE())
    month=DATEPART("M",DATE())
    day=DATEPART("D",DATE())
    
    If month>=2 and month<=8 then
       Session("Term")="二"
       Session("TermYear")=cstr(year-1)+ "至" + cstr(year)
    Else
       Session("Term")="一"
       Session("TermYear")=cstr(year)+ "至" + cstr(year+1)
    End If
    
    Session("Year")=year
    Session("Month")=month
    Session("Day")=day
End Sub
%>

⌨️ 快捷键说明

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