|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
减少客户内IT专业人才缺乏带来的影响。ASP的客户员工利用浏览器进入相关的应用软件,简单易用,无需专业技术支持。ChrisPayne
September11,2000
Well,nowyourauctioncanrunforanindefinitetime.Peoplecankeepplacingbidsuntilyoudecideto
stopthem(goodfortheseller,butmakesbidderskindofunhappy,tosaytheleast).Letsdiscussthe
mechanismsforstoppinganauction.
Therearetwoeasywaystodoit.Thefirst,andeasiesttoperform,thoughrequiringmoremanual
interventioninthelongrun,istosimplybuildinan"Active"bitfieldintoyourtblAuctionstable.
Whenyoudecidetostoptheauction,flipthebit,andtheauctionisover.(Youllalsohavetoaddsome
codetomakesurethattheDoBidsandResolveBidsfunctionsdontoperateonclosedauctions.)Thensimply
querythedatabase,findoutthewinner(s),andletthemandthesellerknow.Easyaspie.
Thesecondmethodistogobytheenddatethesellerspecifies(betterbusiness,believeme).Todothis,
youcanmanuallystoptheauction(viatheprocessabove)whentheappropriatedatecomes,oryoucan
scheduleatasktoturnanauctionoffattheappropriatetimes.Thereareafewwaystodothis,viayour
databaseprogramandtheWindowsNTTaskScheduler,soIwontgothrougheachone.Youcouldsimplyset
thescripttoruneverymidnightorsotostoptheauctionanddeterminethewinners.
Ifyouletthesellerspecifyanexacttimefortheauctiontoend,thenyoureintroducingawholenew
setofcomplications.Onewaytohandlethisistoprogrammaticallysetascheduledtaskassoonasthe
sellersubmitstheauction,fortheenddateoftheauction.Thisrequiresminimumintervention,but
requiresyoutoknowhowtodothat(fordocumentationontheTaskScheduler,readthisMSDNarticle).
Anothermethodistocreateyourownspecificversionoftaskscheduler;createasmallprogramthatwill
runinthebackgroundandwatchthetimesonauctions.Whenanauctionenddatepasses,flipthebit.
Okay,sotheauctionisover.Nowwhat?
Assumingthatyouwouldlikeminimalmanualintervention,andyoudontreallycarewhowins(likethe
headguysatEbaycarewhowinseverysingleauction),thenyoucouldcreateafunctiontosendalertsto
thewinner(s)andsellerthatwillkickoffwhentheauctionisover.Thisfunctioncouldalsointurn
kickoffsometypeofpaymentsystem,butthatisbeyondthescopeofthisarticle.Letslookatthe
function:
FunctionSelectWinners(AuctionID,itemID)
Setvariablesandcreateobjects
dimtotItems,intAvailable
totItems=0
strConnectionString="DSN=MyAuction;UID=username;PWD=password;Database=MyAuctionDB"
setrst=Server.CreateObject("ADODB.Recordset")
Findthenumberofitemsavailable
strSQL="SELECTAvailableFROMtblAuctionItemsWHERE"&_
"IID="&ItemID
rst.openstrSQL,strConnectionString
intAvailable=rst(1)
rst.close
findthewinners
Iftwocustomersbidthesameamount,thecustomerrequesting
moreitemswillwin.Ifstilltied,thecustomerplacingthe
earliestbidwillwin
strSQL="SELECTUID,WinPrice,WinItemsFROMtblAuctionBids"&_
"WHEREIID="&itemID&"ORDERBYWinItemsDESC,Time"
rst.openstrSQL,strConnectionString
ifnotrst.eofthen
dountilrst.eofORtotItems>=intAvailable
Keeparunningtallyofitemsdistributed
totItems=totItems+rst(2)
IftotItems<=intAvailablethenThisbuyerwon
Sendanemailalertingthisbuyer
callSendWinningEmail(rst(0))
Endif
rst.movenext
loop
endif
EndFunction
Thisisaprettysimplefunction.Simplyloopthroughthebidsinthecorrectorder(bynumberofitems
wonfirst,andthenbydate),andalertthebuyersthattheyvewon.Oncethenumberofitemsbidforgets
higherthanthenumberofitemsavailable,everyoneelseloses,andyoucanstoptheloop.Iwontgo
intotheSendWinningEmail()function,butallitdoesissendtheuserspecifiedbyrst(0)anemailthat
saystheyvewonandforhowmuchandhowmany.(Foranexampleusingemail,checkoutthisWDVLarticle.)
ASP脚本是采用明文(plaintext)方式来编写的。 |
|