-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sell.aspx.vb
87 lines (74 loc) · 4.14 KB
/
Sell.aspx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Imports System.Data.SqlClient
Imports System.Data
Partial Class Sell
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("UserID") Is Nothing Then 'only show the delete listings section if the user is logged in
divdelete.Visible = False
Else
divdelete.Visible = True
End If
Dim data As DataView = sqlDSListSelect.Select(DataSourceSelectArguments.Empty)
Try
If data.Count > 0 Then 'only show the delete listings section if the user has at least 1 listing
divdelete.Visible = True
Else
divdelete.Visible = False
End If
Catch ex As Exception
divdelete.Visible = False
End Try
End Sub
Protected Sub btnCreateList_Click(sender As Object, e As EventArgs) Handles btnCreateList.Click 'Create listing button
If Page.IsValid Then
If Session("UserID") Is Nothing Then 'If the user isnt logged in, redirect them first
Session("LoginRedir") = 2
Response.Redirect("Login.aspx", True)
Else
Try
Dim stock As Int64 = Int64.Parse(inStock.Text) 'this acts as validation since a string that cant be parsed will throw an exception
Dim price As Decimal = Decimal.Parse(inPrice.Text)
If stock > 0 And price >= 0.0000001 Then
lbltest.Text = ""
Dim strCmd As String = "INSERT INTO Listings VALUES (@UserID, @GameID, @Stock, @Price)" 'insert the new listing
Dim conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PlayerVaultConnectionString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand(strCmd, conn)
Dim selectedGameID As Integer = sqlGameSelect.SelectedItem.Value
cmd.Parameters.AddWithValue("UserID", Session("UserID"))
cmd.Parameters.AddWithValue("GameID", selectedGameID)
cmd.Parameters.AddWithValue("Stock", stock)
cmd.Parameters.AddWithValue("Price", price)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
conn.Close()
inPrice.Text = "" 'clear fields and refresh
inStock.Text = ""
Response.Redirect("Sell.aspx", True)
Else
lbltest.Text = "Invalid input, stock greater than 0, price must be at least 0.0000001 per unit."
End If
Catch ex As Exception
lbltest.Text = "Invalid input, please enter stock as an integer and<br/>Price as a decimal with up to 7 digits beyond the decimal point."
End Try
End If
End If
End Sub
Protected Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click 'Delete listing button
Try
lbltest.Text = ""
Dim strCmd As String = "DELETE FROM Listings WHERE ListingID = @ListingID" 'delete the selected listing
Dim conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PlayerVaultConnectionString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand(strCmd, conn)
Dim selectedGameID As Integer = sqlListSelect.SelectedItem.Value
cmd.Parameters.AddWithValue("ListingID", sqlListSelect.SelectedItem.Value)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
conn.Close()
Response.Redirect("Sell.aspx", True)
Catch ex As Exception
lbltest.Text = "Error Deleting Listing, was it deleted already?<br/>If not, refresh and try again." 'for concurrency issues
End Try
End Sub
End Class