您的位置:首页网页设计ASP实例 → 制作我们自己的Ebay拍卖系统6

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

时间:2004/11/7 2:52:00来源:本站整理作者:蓝点我要评论(0)

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 we're 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 user's 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 bidder's 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 bidder's bid is not the highest bid,

THEN increment the current bidder's 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 everyone's 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).






相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码