How to Make an Auction
This sample demonstrates how to make an auction.
Files
used in this sample are located in the folder:
C:\Program Files\CodeSegment\SMS Studio\Samples\InfoService\Auction
Upon receiving an incoming message, the script
ProcessBid.vbs processes the bid sent by the user and updates the database accordingly. When you close the auction, the highest bid for each item in the auction will be registered in the database.
The contents of the ProcessBid.vbs file:
if WScript.Arguments.Count = 5 then
PipeName = WScript.Arguments(0)
UserPhone = WScript.Arguments(1)
UserAccountID = WScript.Arguments(2)
ItemID = Replace(WScript.Arguments(3),"'","''")
BidStr = WScript.Arguments(4)
if PipeName <> "" then
strDSN = "SMS Auction Database"
strUser = ""
strPass = ""
set database = CreateObject("ADODB.Connection")
database.Open strDSN, strUser, strPass
CurrentPriceText = ""
set R = database.Execute("SELECT * FROM Items WHERE ItemID = '" & ItemID & "'")
if R.EOF then
ReplyText = "You have sent an invalid item id."
else
ItemID = R("ItemID")
ItemName = R("ItemName")
StartPrice = R("StartPrice")
CurrentPrice = R("CurrentPrice")
MaxRaise = R("MaxRaise")
OldUserPhone = R("UserPhone")
OldUserAccountID = R("UserAccountID")
if IsNumeric(BidStr) then
Bid = CInt(BidStr)
if Bid > StartPrice and Bid > CurrentPrice and Bid <= CurrentPrice + MaxRaise then
ReplyText = "Your bid has been accepted!"
CurrentPrice = Bid
database.Execute("UPDATE Items SET CurrentPrice = '" & CurrentPrice & "', UserPhone = '" & UserPhone & "', UserAccountID = '" &
UserAccountID & "', BidTime = '" & Now() & "' WHERE ItemID = '" & ItemID & "'")
else
ReplyText = "Your bid has not been accepted."
end if
else
ReplyText = "You have sent an ivalid bid."
end if
CurrentPriceText = " The highest bid for '" & ItemName & "' is " & CurrentPrice & "."
end if
database.Close
set fso = CreateObject("Scripting.FileSystemObject")
set pipe = fso.CreateTextFile("\\.\pipe\" & PipeName)
pipe.WriteLine("AccountID:" & UserAccountID)
pipe.WriteLine("To:" & UserPhone)
pipe.WriteLine("Text:" & ReplyText & CurrentPriceText)
pipe.WriteLine("<Send>")
if OldUserPhone <> "" then
pipe.WriteLine("AccountID:" & OldUserAccountID)
pipe.WriteLine("To:" & OldUserPhone)
pipe.WriteLine("Text:" & "We are sorry to inform you that your bid is not the highest anymore." & CurrentPriceText)
pipe.WriteLine("<Send>")
end if
pipe.Close
WScript.Quit(0)
else
MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Auction Sample"
WScript.Quit(1)
end if
else
MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Auction Sample"
WScript.Quit(1)
end if
How to run this sample
- Create a new ODBC Data Source and set its name to SMS Auction Database. See How to Create an ODBC Data Source for detailed instructions.
- Open Windows Explorer and locate the CreateTables.vbs file. Double-click on this file to run the script. When asked for the name of the Data Source enter SMS Auction Database. A new table will be created in the database filled with some sample data.
- Click the New button on the main toolbar and select the Info service option in the New Service dialog.
- Click the Setup button on the main toolbar to display the Info Setup dialog.
- In the General tab of the Info Setup dialog click the Add button to display the Add Rule dialog.
- In the General tab of the Add Rule dialog enter the following parameters:
Name: Bid
Pattern: Bid *
Required number of parameters: 2
Action: Execute external application
- In the Execute tab of the Add Rule dialog enter the following parameters:
External application: ProcessBid.vbs - use the selection button ( ... ) to locate and select the external application.
Application parameters:
"%PipeName%" "%MsgFromPhone%" "%AccountID%" "%P1%" "%P2%"
- Click the Add button to close the Add Rule dialog.
- In the Advanced tab of the Info Setup dialog enter the name of the pipe:
Pipe name: AuctionPipe
- Click the OK button to close the Info Setup dialog.
- Click the Start
button on the main toolbar to start the Info service.
- Use Tools / Receive Message option in the main menu to
display the Receive Message dialog. Fill in the
Text field with the text Bid MP9 250 and click the Receive
button. The Info
service will receive this message and run the ProcessBid.vbs
application which will update the database with the new bid and inform the user about its bid status by sending back a reply which will be
placed in the Outbox.
Related topics
Named Pipe