欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

制作我们自己的Ebay(拍卖系统)(6)

程序员文章站 2022-05-27 08:08:41
resolving bids - page 6 chris payneseptember 11, 2000function resolvebids(itemid)set varia...
resolving bids - page 6

chris payne

september 11, 2000



function resolvebids(itemid)


set variables and create objects
dim monincrement, monhighprice, intavailable, inttotitems, flgquit
dim blnresolved


assume bids are resolved
blnresolved = true
strconnectionstring = "dsn=myauction;uid=username;pwd=password;database=myauctiondb"
set rst = server.createobject("adodb.recordset")


get information from items table
strsql = "select increment, available from tblauctionitems where " & _
"iid = " & itemid
rst.open strsql, strconnectionstring
monincrement = rst(0)
intavailable = rst(1)
rst.close


find the highest bid and total number items bid for
strsql = "select max(winprice) as winprice, sum(winitems) as " & _
"winitems from tblauctionbids where " & _
"itemid = " & itemid
rst.open strsql, strconnectionstring
monhighprice = rst(0)
inttotitems = rst(1)
rst.close


if a user with a higher max bid exists, then
update their bid if and only if available items is exceeded
strsql = "select maxbid, uid, biditems, winprice from " & _
"tblauctionbids where itemid = " & itemid
rst.open strsql, strconnectionstring
if not rst.eof then
do until rst.eof
if (rst(0) > monhighprice + monincrement) and (inttotitems > intavailable) & _
and (rst(3) <> monhighprice) then
monhighprice = monhighprice + monincrement
call dobids(itemid, rst(1), monhighprice)
blnresolved = false
end if
rst.movenext
if were at the end of the recordset
and the bids are not yet resolved, go back to the beginning
if not blnresolved and rst.eof then
rst.movefirst
blnresolved = true
end if
loop
end if
rst.close

end function


the main part of the above code is the last do...loop section. the process is as follows:


enter a users bid (using the dobids() function)
find the highest bid for the item, and total number of items bid for
loop through database and:
if the current bidders maximum bid is higher than the highest winning bid,
and the total number of items bid for is greater than the number of items available,
and the current bidders bid is not the highest bid,
then increment the current bidders bid by the increment value.
if we reach the end of the recordset, and the bids are still not resolved, the start over.
this process will automatically update all bids appropriately, and weed out those whose max bids are not
high enough. the reason we check to make sure the total number of items bid for is greater than the number
of total items available in step 4 is because if all bids are placed and items claimed, and there are
still lots available, then everyone wins and bids do not need to be incremented.

for example, imagine there are 10 lots available, and there are 3 bidders. if bidder a wants 3 lots at $3,
bidder b wants 3 lots at $2, and bidder c wants 3 lots at $1, everyone will win because there is enough
lots to go around, and then some. the do loop above will only have to go through once.

however, suppose bidder c now wants 5 items. since there are not enough items to go around, someone will
have to lose out. the loop in the code above weeds this person out by checking max bids and updating the
winning bids. if everyones max bids in this scenario was $20, and the increment was $2, then bidder c and
whichever of bidder a and b placed the first bid would win (remember that bid priority is placed on most
lots bid for, followed by bid time).