Web表单到控制台应用程序与计时器

时间:2014-01-25 09:06:00

标签: asp.net vb.net console

我在asp.net webform中创建了一个代码

现在我希望此代码在控制台应用程序中运行

但我不知道

如何调用我的计时器

以及放置代码的位置

有人可以帮我转换

这些代码进入控制台应用程序

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


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

然后计算中标价格

Private Sub WinningBet()

    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, BID.BidID FROM BID INNER JOIN Auction ON BID.AuctionID = Auction.AuctionID INNER JOIN Buyer ON BID.BuyerID = Buyer.BuyerID INNER JOIN Member ON Buyer.MemberID = Member.MemberID WHERE(Auction.AuctionID = @auction) and (BID.WinningPrice <>0) ORDER BY BID.BidID DESC"






        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 = ""
    Dim subject As String = "BID"
    Dim body As String = "Your bid has been Successfull Login to shoppingCart to Make Payment"

    Dim email1 As New Thread(Sub() SendEmail1([to], from, password, subject, body))
    email1.IsBackground = True
    email1.Start()

End Sub

Private Sub SendEmail1(ByVal [to] As String, ByVal from As String, ByVal password As String, ByVal subject As String, ByVal body As String)
    Using mm As New MailMessage(from, [to])
        mm.Subject = subject
        mm.Body = body

        mm.IsBodyHtml = False
        Dim smtp As New SmtpClient()
        smtp.Host = "smtp.gmail.com"
        smtp.EnableSsl = True
        Dim NetworkCred As New NetworkCredential(from, password)
        smtp.UseDefaultCredentials = True
        smtp.Credentials = NetworkCred
        smtp.Port = 587
        smtp.Send(mm)
    End Using
End Sub

1 个答案:

答案 0 :(得分:0)

使用Forms计时器:

Add a reference to System.Windows.Forms
Imports System.Windows.Forms

对于Web.UI计时器:

Add references to System.Web and System.Web.Extensions
Imports System.Web.UI

在模块级别声明新的计时器:

Dim timer1 As New Timer