Hello everyone i have created a website, and on the website there is a page where the bid take place
(i) so, i have a list of item ;)
(ii) each item has a enddate, i take the endate and calculate the duration
(iii) when the item expired, it is remove from the list and the timer refresh the page without postback
(IIII) a mail is send to the winner
my main problem is that when i left the page
the function to calculate the winner and send email
went off
How with SignalR would i resolve this problem : letting the timer continue to run on the bidding page even if i'm not on it or if it is not load and calculate the winner and send the email as a background function
i put my code here hope to have someone to help me p.s i''m using webform not mvc
Private Sub UpdateDuration()
Dim ts = (DateTime.Now - DateTime.Parse(Label4.Text))
Dim travelTime As New TimeSpan(0, 0, 0, 0)
Dim result2 As Integer = TimeSpan.Compare(ts, travelTime)
If result2 <= 0 Then
'Now you can output your time as you please (excluding any decimal points)'
Label5.Text = String.Format("Time Left: {0:dd\:hh\:mm\:ss}", ts)
Else
TextBox1.Enabled = False
Dim con1 As New SqlConnection(_start)
Dim sql12 As String = "SELECT Auction.AuctionID FROM Item INNER JOIN Auction ON Item.ItemID = Auction.ItemID Where Auction.Status='Valid' AND Auction.EndDate<=@endate "
Dim cmd12 As New SqlCommand(sql12, con1)
con1.Open()
cmd12.Parameters.AddWithValue("@endate", DateTime.Now)
Dim query As Integer = cmd12.ExecuteScalar
Dim sql123 As String = "UPDATE Auction SET Status ='Expired' WHERE AuctionID =@auction"
Dim cmd21 As New SqlCommand(sql123, con1)
cmd21.Parameters.AddWithValue("@auction", query)
cmd21.ExecuteNonQuery()
CalculateWinningPrice(query)
WinningBet()
timer1.Enabled = True
Response.Redirect("../Part1/Main.aspx")
End If
End Sub
Protected Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
'--this method will fetch the end date from repeater item label and update the duration
UpdateDuration()
End Sub
Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim BiddingPrice As String
Dim dataToSave As String = TextBox1.Text
Dim price As String = Label2.Text
Dim constr As String = ConfigurationManager.ConnectionStrings("VirgoPlaza").ConnectionString
Dim con As New SqlConnection(constr)
Dim Price1 As Double = Convert.ToDouble(price)
Dim Biddingcmd As New SqlCommand("SELECT BID.BiddingPrice FROM Item INNER JOIN Auction ON Item.ItemID = Auction.ItemID INNER JOIN BID ON Auction.AuctionID = BID.AuctionID WHERE (Auction.AuctionID = @auction)")
Biddingcmd.CommandType = CommandType.Text
Biddingcmd.Parameters.AddWithValue("@auction", lblauction.Text)
con.Open()
Biddingcmd.Connection = con
Dim result21 As String = Biddingcmd.ExecuteScalar()
BiddingPrice = result21
Dim txtbid As Integer = Convert.ToInt32(dataToSave)
Dim auction1 As Integer = Convert.ToInt32(lblauction.Text)
Dim con1 As New SqlConnection(constr)
con1.Open()
If (txtbid > Price1) AndAlso (BiddingPrice = "") Then
Dim cmd As New SqlCommand("INSERT INTO BID VALUES(@Date, @BiddingPrice,@Status,@AuctionID,@BuyerID,@WinningPrice)")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Date", DateTime.Now)
cmd.Parameters.AddWithValue("@BiddingPrice", dataToSave)
cmd.Parameters.AddWithValue("@Status", "Available")
cmd.Parameters.AddWithValue("@AuctionID", auction1)
cmd.Parameters.AddWithValue("@BuyerID", 1)
cmd.Parameters.AddWithValue("@WinningPrice", "")
cmd.Connection = con1
cmd.ExecuteNonQuery()
MsgBox("SAVE")
ElseIf (txtbid > price) AndAlso (txtbid > Convert.ToInt32(BiddingPrice)) And BiddingPrice <> "" Then
Dim cmd As New SqlCommand("INSERT INTO BID VALUES(@Date, @BiddingPrice,@Status,@AuctionID,@BuyerID,@WinningPrice)")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Date", DateTime.Now)
cmd.Parameters.AddWithValue("@BiddingPrice", dataToSave)
cmd.Parameters.AddWithValue("@Status", "Available")
cmd.Parameters.AddWithValue("@AuctionID", auction1)
cmd.Parameters.AddWithValue("@BuyerID", 1)
cmd.Parameters.AddWithValue("@WinningPrice", "")
cmd.Connection = con1
cmd.ExecuteNonQuery()
MsgBox("Save")
losingemail()
Else
MsgBox("bID IS TOO LOW")
End If
End Sub
Public Sub CalculateWinningPrice(ByVal query As Integer)
Dim price As Integer
Using con1 As New SqlConnection(_start)
con1.Open()
Dim sql1 As String = "SELECT MAX(BiddingPrice) AS Expr1 FROM BID WHERE (AuctionID = @auction)"
Dim cmd1 As New SqlCommand(sql1, con1)
cmd1.Parameters.AddWithValue("@auction", query)
Dim max As Double = Convert.ToDouble(cmd1.ExecuteScalar)
Dim cmd2 As New SqlCommand("SELECT MAX(BiddingPrice) AS Expr1 FROM BID WHERE (BiddingPrice <( SELECT MAX(BiddingPrice) AS Expr2 FROM BID AS BID_1 WHERE (AuctionID = @auction)))", con1)
cmd2.Parameters.AddWithValue("@auction", query)
Dim second As Double = Convert.ToDouble(cmd2.ExecuteScalar)
Dim cmd3 As New SqlCommand("SELECT BuyerID FROM BID WHERE(BiddingPrice =(SELECT MAX(BiddingPrice) AS Expr1 FROM BID AS BID_1 WHERE(AuctionID = @auction)))", con1)
cmd3.Parameters.AddWithValue("@auction", query)
Dim Buyer As Integer = Convert.ToInt32(cmd3.ExecuteScalar)
If max - second = 1 Then
price = second
Else
If max - second > 10 Then
price = second + 1
Else
If max - second > 100 Then
price = second + 10
Else
If max - second > 1000 Then
price = second + 1000
End If
End If
End If
End If
Dim cmd As New SqlCommand("INSERT INTO BID VALUES(@Date, @BiddingPrice,@Status,@AuctionID,@BuyerID,@WinningPrice)")
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Date", DateTime.Now)
cmd.Parameters.AddWithValue("@BiddingPrice", max)
cmd.Parameters.AddWithValue("@Status", "Won")
cmd.Parameters.AddWithValue("@AuctionID", query)
cmd.Parameters.AddWithValue("@BuyerID", Buyer)
cmd.Parameters.AddWithValue("@WinningPrice", price)
cmd.Connection = con1
cmd.ExecuteNonQuery()
End Using
End Sub
Public Sub losingemail()
Dim Email As String
Dim auction1 As Integer = Convert.ToInt32(lblauction.Text)
Using con1 As New SqlConnection(_start)
con1.Open()
Dim sql1 As String = "SELECT TOP (1) Member.Email FROM (SELECT TOP (2) BidID, Date, BiddingPrice, Status, AuctionID, BuyerID, WinningPrice from BID ORDER BY BidID DESC) AS tabel1 INNER JOIN Buyer ON tabel1.BuyerID = Buyer.BuyerID INNER JOIN Member ON Buyer.MemberID = Member.MemberID INNER JOIN Auction ON tabel1.AuctionID = Auction.AuctionID WHERE(Auction.AuctionID = @auction) ORDER BY tabel1.BidID"
Dim sqlcommand As New SqlCommand(sql1, con1)
sqlcommand.Parameters.AddWithValue("@auction", auction1)
Email = sqlcommand.ExecuteScalar()
End Using
Dim [to] As String = Email
Dim from As String = "virgoplaza11@gmail.com"
Dim password As String = "virgo7172648"
Dim subject As String = "BID"
Dim body As String = "Your bid has been overbid, Please bid against"
Dim email1 As New Thread(Sub() SendEmail([to], from, password, subject, body))
email1.IsBackground = True
email1.Start()
End Sub
you can reslove your issue by creating window service which will run on server and check bidding winner and execute process from there, you need to run webservice in certain interval of time then only it works.
please let me know if you need any more assistance.
the tutorial you give me is not the same as in a website, i''m very lost and confuse now , please help, i have create the webservice but how to place my function in it :(
Member
130 Points
656 Posts
Make an auction bidding process
Jan 20, 2014 04:40 PM|Jdaniel13|LINK
Hello everyone i have created a website, and on the website there is a page where the bid take place
(i) so, i have a list of item ;)
(ii) each item has a enddate, i take the endate and calculate the duration
(iii) when the item expired, it is remove from the list and the timer refresh the page without postback
(IIII) a mail is send to the winner
my main problem is that when i left the page
the function to calculate the winner and send email
went off
How with SignalR would i resolve this problem : letting the timer continue to run on the bidding page even if i'm not on it or if it is not load and calculate the winner and send the email as a background function
i put my code here hope to have someone to help me p.s i''m using webform not mvc
Participant
1365 Points
408 Posts
Re: Make an auction bidding process
Jan 20, 2014 05:04 PM|megh1207|LINK
you can reslove your issue by creating window service which will run on server and check bidding winner and execute process from there, you need to run webservice in certain interval of time then only it works.
please let me know if you need any more assistance.
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 20, 2014 06:27 PM|Jdaniel13|LINK
how will i create the web service please
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 20, 2014 06:33 PM|Jdaniel13|LINK
can you help how to write the code please
Participant
1365 Points
408 Posts
Re: Make an auction bidding process
Jan 21, 2014 01:04 AM|megh1207|LINK
here checkout this tutoral
http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html
please let me know if you still find any difficulty.
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 21, 2014 01:47 AM|Jdaniel13|LINK
please wll the webservice run even if i''m not on the page of bidding. will it run through out my whole website.:
if i''m not on bidding page
i'm on home
the website send the email and look for the winner?
Participant
1365 Points
408 Posts
Re: Make an auction bidding process
Jan 21, 2014 01:55 AM|megh1207|LINK
actually service run on windows background as soon as system starts and it will handle all other item bid closing and updating database.
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 21, 2014 02:05 AM|Jdaniel13|LINK
when i will host my website, will i need to install the webservice on my server?? just want to know to be sure
Participant
1365 Points
408 Posts
Re: Make an auction bidding process
Jan 21, 2014 02:12 AM|megh1207|LINK
yes, and you need to set that webservice in startup so if any case server will restart it will start webservice as well.
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 21, 2014 02:18 AM|Jdaniel13|LINK
ok i will start to right the code and come back to u for any help ok :)
Member
130 Points
656 Posts
Re: Make an auction bidding process
Jan 21, 2014 03:17 AM|Jdaniel13|LINK
the tutorial you give me is not the same as in a website, i''m very lost and confuse now , please help, i have create the webservice but how to place my function in it :(