-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Enrique Yanez
committed
Feb 20, 2014
0 parents
commit eaba0a9
Showing
42 changed files
with
10,849 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
Imports System.Data | ||
Imports System.Data.SqlClient | ||
Imports System.Net | ||
Imports System.IO | ||
Imports System.Net.Mail | ||
|
||
Partial Class Checkout | ||
Inherits System.Web.UI.Page | ||
|
||
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load | ||
Dim strCartID As String | ||
' Retrieve cookie | ||
Dim CookieBack As HttpCookie | ||
CookieBack = HttpContext.Current.Request.Cookies("CartID") | ||
' Set cookie value | ||
strCartID = CookieBack.Value | ||
|
||
' Retrieve cart items from the Cartline table by CartID | ||
ViewCart.SelectCommand = "SELECT * FROM Cartline WHERE CartID = '" + strCartID + "'" | ||
' Bind the cart table so that it refreshes it everytime this is processed | ||
ViewCart.DataBind() | ||
|
||
' Open SQL Data Reader | ||
Dim dr As SqlDataReader | ||
Dim strSQLStatement As String | ||
Dim strSQL As SqlCommand | ||
' Get the connection configuration from the Web.Config file | ||
Dim strConnectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" | ||
|
||
strSQLStatement = "SELECT SUM(ProductPrice * Quantity) AS Subtotal FROM Cartline WHERE CartID = '" + strCartID + "'" | ||
|
||
' Open connection and execute the SQL statement | ||
Dim conn As New SqlConnection(strConnectionString) | ||
strSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = strSQL.ExecuteReader() | ||
|
||
If dr.Read() Then | ||
' Set subtotal labels | ||
subtotal.Text = dr.Item("Subtotal") | ||
subtotal.DataBind() | ||
End If | ||
conn.Close() | ||
End Sub | ||
|
||
Protected Sub SubmitCheckout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitCheckout.Click | ||
' Get cookie ID | ||
Dim strCartID As String | ||
Dim CookieBack As HttpCookie | ||
CookieBack = HttpContext.Current.Request.Cookies("CartID") | ||
strCartID = CookieBack.Value | ||
|
||
Dim dr As SqlDataReader | ||
Dim strSQLStatement As String | ||
Dim cmdSQL As SqlCommand | ||
' Get connection from Web.Config | ||
Dim strConnectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" | ||
|
||
Dim CreditCardDate As String = CStr(CreditCardExpirationMonth.Text + "/" + CreditCardExpirationYear.Text) | ||
|
||
strSQLStatement = "INSERT INTO Customer (OrderLineID, FirstName, Email, LastName, StreetAddress, City, State, Zip, PhoneNumber, CreditCardNumber, CreditCardType, CreditCardExpirationDate) VALUES ('" + strCartID + "', '" + FirstName.Text + "', '" + LastName.Text + "', '" + Email.Text + "', '" + StreetAddress.Text + "', '" + City.Text + "', '" + State.Text + "', '" + Zip.Text + "', '" + PhoneNumber.Text + "', '" + CreditCardNumber.Text + "', '" + CreditCardType.Text + "', '" + CStr(CreditCardDate) + "'); SELECT @@Identity;" | ||
|
||
Dim conn As New SqlConnection(strConnectionString) | ||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
conn.Close() | ||
|
||
' Use the cookie CartID to transfer items from cart to the orerline table and store orderlineID as CartID | ||
|
||
strSQLStatement = "SELECT * FROM Cartline WHERE CartID = '" + strCartID + "'" | ||
|
||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
|
||
|
||
Dim strProductCode As String = "" | ||
Dim strProductName As String = "" | ||
Dim decProductPrice As Decimal | ||
Dim intQuantity As Integer | ||
|
||
Dim products As String = "" | ||
|
||
Dim myList As New List(Of String) | ||
|
||
While dr.Read() | ||
strProductCode = dr.Item("ProductID") | ||
strProductName = dr.Item("ProductName") | ||
decProductPrice = dr.Item("ProductPrice") | ||
intQuantity = dr.Item("Quantity") | ||
|
||
products += dr.Item("ProductName") + " <br />" | ||
|
||
myList.Add("INSERT INTO Orderline (OrderlineID, ProductCode, ProductName, ProductPrice, Quantity) VALUES ('" & strCartID & "', '" & CStr(strProductCode) & "', '" & CStr(strProductName) & "', " & CDec(decProductPrice) & ", " & CInt(intQuantity) & ")") | ||
|
||
End While | ||
conn.Close() | ||
|
||
For Each myListing In myList | ||
cmdSQL = New SqlCommand(myListing, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
conn.Close() | ||
Next | ||
|
||
' Possibly create another table to hold order info and have columns, ID, OrderID, Subtotal, Total And CustomerID | ||
' OrderID will be the OrderlineID that is the same from the cookie of cartId | ||
' If so, calculate subtotal, total and if california is state, calculate 8.75% tax | ||
|
||
strSQLStatement = "SELECT SUM(ProductPrice * Quantity) AS Subtotal FROM Cartline WHERE CartID = '" & strCartID & "'" | ||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
|
||
Dim subtotal As Decimal | ||
Dim totalBeforeRound As Decimal | ||
Dim total As Decimal | ||
Dim tax As Decimal = 0.0875 | ||
Dim totalTax As Decimal | ||
|
||
If dr.Read() Then | ||
If State.Text = "CA" Then | ||
subtotal = dr.Item("Subtotal") | ||
totalTax = subtotal * tax | ||
totalBeforeRound = totalTax + subtotal | ||
total = totalBeforeRound | ||
Else | ||
subtotal = dr.Item("Subtotal") | ||
total = subtotal | ||
End If | ||
End If | ||
conn.Close() | ||
|
||
' Get Customer ID By OrderLINE ID | ||
|
||
strSQLStatement = "SELECT * FROM Customer WHERE OrderlineID = '" & strCartID & "'" | ||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
|
||
Dim customerID As Integer | ||
|
||
If dr.Read() Then | ||
customerID = dr.Item("ID") | ||
End If | ||
conn.Close() | ||
|
||
strSQLStatement = "INSERT INTO OrderInfo (OrderlineID, Subtotal, Total, CustomerID) VALUES ('" & strCartID & "', " & subtotal & ", " & total & ", " & customerID & ")" | ||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
conn.Close() | ||
|
||
' By default, this sample code is designed to post to our test server for | ||
' developer accounts: https://test.authorize.net/gateway/transact.dll | ||
' for real accounts (even in test mode), please make sure that you are | ||
' posting to: https://secure.authorize.net/gateway/transact.dll | ||
Dim post_url As String | ||
post_url = "https://test.authorize.net/gateway/transact.dll" | ||
|
||
Dim post_values As New Dictionary(Of String, String) | ||
|
||
'the API Login ID and Transaction Key must be replaced with valid values | ||
post_values.Add("x_login", "55UhxX87") | ||
post_values.Add("x_tran_key", "66NvERFwq5k9753g") | ||
|
||
post_values.Add("x_delim_data", "TRUE") | ||
post_values.Add("x_delim_char", "|") | ||
post_values.Add("x_relay_response", "FALSE") | ||
|
||
post_values.Add("x_type", "AUTH_CAPTURE") | ||
post_values.Add("x_method", "CC") | ||
post_values.Add("x_card_num", CreditCardNumber.Text) | ||
post_values.Add("x_exp_date", "0115") | ||
|
||
post_values.Add("x_amount", total) | ||
post_values.Add("x_description", "CIS 451 Transaction") | ||
|
||
post_values.Add("x_first_name", FirstName.Text) | ||
post_values.Add("x_last_name", LastName.Text) | ||
post_values.Add("x_address", StreetAddress.Text) | ||
post_values.Add("x_state", State.Text) | ||
post_values.Add("x_zip", Zip.Text) | ||
' Additional fields can be added here as outlined in the AIM integration | ||
' guide at: http://developer.authorize.net | ||
|
||
' This section takes the input fields and converts them to the proper format | ||
' for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4" | ||
Dim post_string As String = "" | ||
For Each field As KeyValuePair(Of String, String) In post_values | ||
post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&" | ||
Next | ||
post_string = Left(post_string, Len(post_string) - 1) | ||
|
||
' The following section provides an example of how to add line item details to | ||
' the post string. Because line items may consist of multiple values with the | ||
' same key/name, they cannot be simply added into the above array. | ||
' | ||
' This section is commented out by default. | ||
'Dim line_items() As String = { _ | ||
' "item1<|>golf balls<|><|>2<|>18.95<|>Y", _ | ||
' "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y", _ | ||
' "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y"} | ||
' | ||
'For Each value As String In line_items | ||
' post_string += "&x_line_item=" + HttpUtility.UrlEncode(value) | ||
'Next | ||
|
||
' create an HttpWebRequest object to communicate with Authorize.net | ||
Dim objRequest As HttpWebRequest = CType(WebRequest.Create(post_url), HttpWebRequest) | ||
objRequest.Method = "POST" | ||
objRequest.ContentLength = post_string.Length | ||
objRequest.ContentType = "application/x-www-form-urlencoded" | ||
|
||
' post data is sent as a stream | ||
Dim myWriter As StreamWriter = Nothing | ||
myWriter = New StreamWriter(objRequest.GetRequestStream()) | ||
myWriter.Write(post_string) | ||
myWriter.Close() | ||
|
||
' returned values are returned as a stream, then read into a string | ||
Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse) | ||
Dim responseStream As New StreamReader(objResponse.GetResponseStream()) | ||
Dim post_response As String = responseStream.ReadToEnd() | ||
responseStream.Close() | ||
|
||
' the response string is broken into an array | ||
Dim response_array As Array = Split(post_response, post_values("x_delim_char"), -1) | ||
|
||
'resultSpan.InnerHtml += "<OL>" & vbCrLf | ||
'For Each value In response_array | ||
'resultSpan.InnerHtml += "<LI>" & value & " </LI>" & vbCrLf | ||
'Next | ||
'resultSpan.InnerHtml += "</OL>" & vbCrLf | ||
|
||
' individual elements of the array could be accessed to read certain response | ||
' fields. For example, response_array(0) would return the Response Code, | ||
' response_array(2) would return the Response Reason Code. | ||
' for a list of response fields, please review the AIM Implementation Guide | ||
|
||
strSQLStatement = "UPDATE OrderInfo SET AuthCode = '" & response_array(4) & "' WHERE CustomerID = " & customerID & " AND OrderlineID = '" & strCartID & "'" | ||
cmdSQL = New SqlCommand(strSQLStatement, conn) | ||
conn.Open() | ||
dr = cmdSQL.ExecuteReader() | ||
conn.Close() | ||
|
||
'Emailing a receipt | ||
|
||
Dim MyMailMessage As New MailMessage() | ||
MyMailMessage.IsBodyHtml = True | ||
MyMailMessage.From = New MailAddress("[email protected]") | ||
' strEmail is from getting user | ||
Dim strEmail As String | ||
strEmail = Email.Text | ||
MyMailMessage.To.Add(strEmail) | ||
MyMailMessage.Subject = "Order Confirmation" | ||
'MyMailMessage.Body = "<html>" & strOrderline & "Total: $" & strTotal & "<br/> " & "Tax: $" & strTaxAmount & "<br/> " & "SubTotal: $" & strSubTotal & "<br/> " & "</html>" | ||
|
||
MyMailMessage.Body = "<html>Thank you for placing an order with us! <br/> Hello " & FirstName.Text & ", <br/><br/> Confirmation ID: " & strCartID & "<br/> Items: " & products & "Order Total: " & total & "<br/><br/> Have any questions? <br/> Email us at [email protected] </html>" | ||
|
||
'Create the SMTPClient object and specify the SMTP GMail server | ||
Dim SMTPServer As New SmtpClient("smtp.gmail.com") | ||
SMTPServer.Port = 587 | ||
SMTPServer.Credentials = New System.Net.NetworkCredential("[email protected]", "6PvzrZV5") | ||
SMTPServer.EnableSsl = True | ||
|
||
Try | ||
SMTPServer.Send(MyMailMessage) | ||
'MessageBox.Show("Email Sent") | ||
Catch ex As SmtpException | ||
'MessageBox.Show(ex.Message) | ||
End Try | ||
|
||
Response.Redirect("Receipt.aspx") | ||
End Sub | ||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> | ||
|
||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> | ||
<div class="container"> | ||
<div class="row-fluid"> | ||
<div class="col-md-2"> | ||
<ul class="nav nav-list bs-docs-sidenav affix"> | ||
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="ProductCategorySubmenu"> | ||
<ItemTemplate> | ||
<li> | ||
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("CategoryName")%>' NavigateUrl='<%# "Default.aspx?category=" + CStr(Eval("MenuGroup")) + "&category_id=" + CStr(Eval("CategoryID"))%>'></asp:HyperLink> | ||
</li> | ||
</ItemTemplate> | ||
</asp:Repeater> | ||
</ul> | ||
</div> | ||
<div class="col-md-10"> | ||
<asp:Label ID="adTitleLabel" Runat="server" Text='<%# Eval("Title") %>'></asp:Label> | ||
<asp:GridView CssClass="table table-striped" GridLines="None" ID="GridView1" runat="server" DataSourceID="ProductInventory" AutoGenerateColumns="False" DataKeyNames="id"> | ||
<Columns> | ||
<asp:BoundField DataField="ProductCode" HeaderText="Product Code" SortExpression="ProductCode" /> | ||
<asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" /> | ||
<asp:BoundField DataField="ProductCost" HeaderText="Product Cost" SortExpression="ProductCost" /> | ||
<asp:BoundField DataField="StockQTY" HeaderText="Stock Quantity" SortExpression="StockQTY" /> | ||
<asp:TemplateField HeaderText="Available Actions"> | ||
<ItemTemplate> | ||
<asp:Hyperlink ID="ViewProduct" runat="server" Text="Product Details" NavigateUrl='<%# "ProductView.aspx?category=" + Request.QueryString("category") + "&product_code=" + CStr(Eval("ProductCode"))%>' Font-Size="Small"></asp:Hyperlink> | ||
</ItemTemplate> | ||
</asp:TemplateField> | ||
</Columns> | ||
</asp:GridView> | ||
</div> | ||
</div> | ||
</div> | ||
<asp:SqlDataSource ID="ProductCategorySubmenu" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnection %>" ProviderName="<%$ ConnectionStrings:DatabaseConnection.ProviderName %>"></asp:SqlDataSource> | ||
<asp:SqlDataSource ID="ProductInventory" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnection %>" ProviderName="<%$ ConnectionStrings:DatabaseConnection.ProviderName %>"></asp:SqlDataSource> | ||
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Partial Class _Default | ||
Inherits System.Web.UI.Page | ||
|
||
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load | ||
If Request.QueryString("category") <> "" Then | ||
ProductCategorySubmenu.SelectCommand = "SELECT * FROM Category WHERE parent != 0 AND MenuGroup = '" + CStr(Request.QueryString("category") + "'") | ||
ProductCategorySubmenu.DataBind() | ||
Session("category") = Request.QueryString("category") | ||
End If | ||
|
||
If Request.QueryString("category_id") <> "" Then | ||
ProductInventory.SelectCommand = "SELECT * FROM Product WHERE CategoryID = '" + CStr(Request.QueryString("category_id") + "'") | ||
ProductInventory.DataBind() | ||
Session("category_id") = Request.QueryString("category_id") | ||
ElseIf Request.QueryString("category_id") = "" Then | ||
adTitleLabel.Text = "<h4>Please select a brand category from the menu on the left.</h4>" | ||
End If | ||
End Sub | ||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Index.aspx.vb" Inherits="Index" %> | ||
|
||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> | ||
<div class="jumbotron"> | ||
<div class="container"> | ||
<h1>Welcome!</h1> | ||
<p> | ||
This is an online store that sells electronic goods and was developed for the sole purpose of CIS 451. | ||
</p> | ||
</div> | ||
</div> | ||
<div class="container"> | ||
<!-- Example row of columns --> | ||
<div class="row"> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p> | ||
<p><a class="btn btn-default" href="#">View details »</a></p> | ||
</div> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p> | ||
<p><a class="btn btn-default" href="#">View details »</a></p> | ||
</div> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> | ||
<p><a class="btn btn-default" href="#">View details »</a></p> | ||
</div> | ||
</div> | ||
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Partial Class Index | ||
Inherits System.Web.UI.Page | ||
End Class |
Oops, something went wrong.