打开数据库 最顶级函数
<%
' Debug Message
Sub Debug (msg)
response.write msg & "<br>"
end sub
' get ComeFrom Cookie
function getComeFromCookie()
dim ret
ret=Request.Cookies("comefrom")
if (comefrom=null) then
ret=""
end if
getComeFromCookie=ret
end function
const myCookieKey="lvzhi"
const myUseCookies="no"
Sub SetSess (field, value)
If myUseCookies<>"Yes" then
Session(field)=value
else
Response.cookies(myCookiekey) (field)=value
end if
end sub
Sub ProcessAccessOpen(connection)
dim strconn
strconn = "provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & Server.MapPath( mydblocation & myDatabase & ".mdb")
Set connection = Server.CreateObject("ADODB.Connection")
on error resume next
connection.open strConn
If connection.errors.count> 0 then
SetSess "Openerror", "Open Messages<br>" & connection.errors(0).description & " <br>" & GetSess("dbc")
else
SetSess "Openerror",""
end if
End Sub
' main database open for shop
Sub ShopOpenDataBase (connection)
ProcessAccessOpen connection
end sub
' close database
Sub CloseRecordSet (irs)
irs.close
set irs=nothing
end sub
'***************
Sub ShopCloseDatabase (connection)
on error resume next
connection.close
set connection=nothing
End sub
'disable property 对应的产品列表
sub disableListFlower(property,value)
dim ret
dim myname
if (property="0") then
myname="List" &property & "F"
else
myname="List" &property & "F" &value
end if
Application(myname)=""
end sub
'List property 对应的产品列表
function GetListFlower(property,value)
dim ret
dim myname
if (property="0") then
myname="List" &property & "F"
else
myname="List" &property & "F" &value
end if
ret=Application(myname)
if (ret="") then
ret=GetListFlowerFromDB(property,value)
Application(myname)=ret
end if
GetListFlower=ret
end function
'List property 对应的产品列表 从数据库
function GetListFlowerFromDb(property,value)
Dim ret,dbc,query,rs,mycondition
shopopendatabase dbc
query = "select result from navigateresult "
mycondition="where sort=0 and property="&property &" and value="&value
query=query & mycondition
set rs = dbc.execute(query)
ret=""
if not rs.EOF then
ret=CStr(rs("result"))
end if
closerecordset rs
shopclosedatabase dbc
GetListFlowerFromDb=ret
end function
'dir 对应的产品列表
function GetDirProduct(dir)
dim ret
if (dir =null or dir="") then
dir=""
end if
dim dirname
dirname="dir" & dir
ret=Application(dirname)
if (ret="") then
ret=GetDirProductFromDB(dir)
Application(dirname)=ret
end if
GetDirProduct=ret
end function
'dir 对应的产品列表,从数据库读出
function GetDirProductFromDB(dir)
dim ret
Dim dbc,query,rs
shopopendatabase dbc
if (dir="") then '读出所有产品
query = "select autoid from product order by priority"
else
query = "select autoid from product where Left(category,"+Cstr(len(dir))+")='"&dir&"'"
end if
set rs = dbc.execute(query)
ret=""
Do WHILE not rs.EOF
if (ret="") then
ret=CStr(rs("autoid"))
else
ret=ret+","+CStr(rs("autoid"))
end if
rs.movenext
Loop
closerecordset rs
shopclosedatabase dbc
GetDirProductFromDb=ret
end function
产品类定义
'Class Product
'public name,autoid,saleprice,Desc,marketPrice,vipPrice,netImageSmall,netImageMid,netImageBig
'End Class
'得到对应的产品
function GetProduct(ID)
dim ret
if (ID =null or ID="") then
ID="1"
end if
dim productname
productname="P" & ID
ret=Application(productname)
if ( not IsArray(ret)) then
ret=GetProductFromDB(ID)
Application(productname)=ret
end if
GetProduct=Application(productname)
end function
'得到对应的产品
sub disableProduct(ID)
dim ret
if (ID =null or ID="") then
ID="1"
end if
dim productname
productname="P" & ID
Application(productname)=""
end sub
'对应的产品,从数据库读出
dim FIELDAUTOID,FIELDNAME,FIELDSALEPRICE,FIELDDESC,FIELDMARKETPRICE
dim FIELDVIPPRICE,FIELDNETIMAGESMALL,FIELDNETIMAGEMID,FIELDNETIMAGEBIG,FIELDCODE
FIELDAUTOID=0
FIELDNAME=1
FIELDSALEPRICE=2
FIELDDESC=3
FIELDMARKETPRICE=4
FIELDVIPPRICE=5
FIELDNETIMAGESMALL=6
FIELDNETIMAGEMID=7
FIELDNETIMAGEBIG=8
FIELDCODE=9
function GetProductFromDB(ID)
dim ret(10)
Dim dbc,query,rs
shopopendatabase dbc
query = "select * from product where autoid="&ID
set rs = dbc.execute(query)
if not rs.EOF then
ret(FIELDAUTOID)=rs("autoid")
ret(FIELDNAME)=rs("name")
ret(FIELDSALEPRICE)=rs("saleprice")
ret(FIELDDESC)=rs("description")
ret(FIELDMARKETPRICE)=rs("marketprice")
ret(FIELDVIPPRICE)=rs("memberprice")
ret(FIELDNETIMAGESMALL)=rs("myimageurl")
ret(FIELDNETIMAGEMID)=rs("myimageurl")
ret(FIELDNETIMAGEBIG)=rs("myimageurl")
ret(FIELDNETIMAGESMALL)=rs("netimageurlsmall")
'ret(FIELDNETIMAGEMID)=rs("netimageurlmid")
'ret(FIELDNETIMAGEBIG)=rs("netimageurlbig")
'ret(FIELDCODE)=rs("code")
else
ret(FIELDAUTOID)=-1
end if
closerecordset rs
shopclosedatabase dbc
GetProductFromDB=ret
end function
%>