c# code 39 barcode generator Retrieving Shopping Cart Items in Visual C#.NET

Drawer USS Code 39 in Visual C#.NET Retrieving Shopping Cart Items

Retrieving Shopping Cart Items
Paint Code 3/9 In C#
Using Barcode creator for .NET Control to generate, create Code 39 Extended image in .NET applications.
www.OnBarcode.com
Code39 Reader In C#
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
The client application may need to display a complete list of items selected by a user in their shopping cart. This is accomplished with the help of the GetCart() web method, shown in Listing B-7. Listing B-7. Retrieving Shopping Cart Items [WebMethod] public DataSet GetCart(string cartid) { string sql = "SELECT * FROM shoppingcart c,products p WHERE c.productid=p.id AND c.cartid=@cartid"; SqlParameter[] p = new SqlParameter[1]; p[0] = new SqlParameter("@cartid", cartid); DataSet ds = SqlHelper.GetDataSet(sql, p); return ds; } The GetCart() web method accepts the shopping cart identifier and returns all the items from that cart to the caller in the form of a DataSet. Notice that the SELECT query is based on two tables ShoppingCart and Products because the product name and unit price also need to be sent back to the client application.
Generating Matrix 2D Barcode In Visual C#
Using Barcode generator for .NET framework Control to generate, create Matrix Barcode image in .NET framework applications.
www.OnBarcode.com
UPC - 13 Encoder In Visual C#.NET
Using Barcode generation for Visual Studio .NET Control to generate, create European Article Number 13 image in VS .NET applications.
www.OnBarcode.com
APPEN DI X B CAS E S TUD Y: A WEB S ERVI CE D RI VEN SH OPPI NG C ART
Barcode Encoder In Visual C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
Code 3/9 Printer In C#.NET
Using Barcode creation for VS .NET Control to generate, create Code 39 Full ASCII image in .NET framework applications.
www.OnBarcode.com
Retrieving the Shopping Cart Amount
Generating ECC200 In C#
Using Barcode creation for .NET Control to generate, create DataMatrix image in .NET framework applications.
www.OnBarcode.com
Painting EAN 8 In C#
Using Barcode encoder for .NET Control to generate, create EAN-8 image in VS .NET applications.
www.OnBarcode.com
Often shopping cart web pages need to display the total amount of the cart. This is achieved by a web method named GetCartAmount(), shown in Listing B-8. Listing B-8. Retrieving the Cart Amount [WebMethod] public decimal GetCartAmount(string cartid) { string sql1 = "SELECT SUM(c.Qty * p.UnitPrice) AS Total FROM Products AS p INNER JOIN ShoppingCart AS c ON p.Id = c.ProductID WHERE c.CartID = @cartid"; SqlParameter[] p1 = new SqlParameter[1]; p1[0] = new SqlParameter("@cartid", cartid); object obj = SqlHelper.ExecuteScalar(sql1, p1); if (obj != DBNull.Value) { decimal amount = (decimal)obj; return amount; } else { return 0; } } The GetCartAmount() web method accepts a unique cart identifier and returns the total amount for that cart. Inside it executes a SUM() aggregate query. If the query returns NULL, a value of 0 is returned to the caller. Otherwise, the actual cart total is returned as a decimal value.
Printing Code 39 Full ASCII In Java
Using Barcode generator for Java Control to generate, create Code 39 Extended image in Java applications.
www.OnBarcode.com
Code 39 Encoder In None
Using Barcode maker for Font Control to generate, create Code 39 Full ASCII image in Font applications.
www.OnBarcode.com
Placing Orders
Recognize Barcode In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Draw Barcode In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
When an order is placed, the Orders table should have an entry for that order. Moreover, all the items from the shopping cart must be moved to the OrderDetails table. This is accomplished with the help of the PlaceOrder() web method, shown in Listing B-9. Listing B-9. Placing an Order [WebMethod] public int PlaceOrder(string cartid,string street,string city,string state, string country,string postalcode) { string sql1 = "SELECT SUM(c.Qty * p.UnitPrice) AS Total FROM Products AS p INNER JOIN ShoppingCart AS c ON p.Id = c.ProductID WHERE c.CartID = @cartid";
PDF-417 2d Barcode Maker In Java
Using Barcode drawer for BIRT Control to generate, create PDF-417 2d barcode image in BIRT applications.
www.OnBarcode.com
Quick Response Code Creation In None
Using Barcode creator for Excel Control to generate, create QR Code image in Excel applications.
www.OnBarcode.com
APPENDIX B C AS E STUDY: A WEB S ERVICE DRIV EN S HOPPIN G CA RT
USS-128 Generator In None
Using Barcode printer for Office Excel Control to generate, create UCC - 12 image in Excel applications.
www.OnBarcode.com
Recognizing Code 128B In Visual C#.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
SqlParameter[] p1 = new SqlParameter[1]; p1[0] = new SqlParameter("@cartid", cartid); object obj=SqlHelper.ExecuteScalar(sql1, p1); decimal amount = (decimal)obj; string sql2 = "INSERT INTO Orders(cartid,orderdate,amount,street, country,state,city,postalcode) VALUES(@cartid,@orderdate,@amount,@street, @country,@state,@city,@postalcode)"; SqlParameter[] p2 = new SqlParameter[8]; p2[0] = new SqlParameter("@cartid", cartid); p2[1] = new SqlParameter("@orderdate", DateTime.Now); p2[2] = new SqlParameter("@amount", amount); p2[3] = new SqlParameter("@street", street); p2[4] = new SqlParameter("@country", country); p2[5] = new SqlParameter("@state", state); p2[6] = new SqlParameter("@city", city); p2[7] = new SqlParameter("@postalcode", postalcode); int i=SqlHelper.ExecuteNonQuery(sql2, p2); string sql3 = "INSERT INTO orderdetails(cartid,productid,qty) SELECT cartid,productid,qty FROM shoppingcart WHERE cartid=@cartid"; SqlParameter[] p3 = new SqlParameter[1]; p3[0] = new SqlParameter("@cartid", cartid); SqlHelper.ExecuteNonQuery(sql3, p3); string sql4 = "DELETE FROM shoppingcart WHERE cartid=@cartid"; SqlParameter[] p4 = new SqlParameter[1]; p4[0] = new SqlParameter("@cartid", cartid); SqlHelper.ExecuteNonQuery(sql4, p4); return i; } The PlaceOrder() method accepts six parameters. These parameters essentially capture the unique cart identifier and shipping address. Inside, the method retrieves the total amount of the cart. The shopping cart ID and shipping address are stored in the Orders table. Then product details such as product ID and quantity are added to the OrderDetails table. The link between the Orders and OrderDetails tables is CartID. The records are then deleted from the ShoppingCart table. This completes the web service. Compile it to ensure that there are no syntactical errors.
Encode EAN 13 In Objective-C
Using Barcode printer for iPad Control to generate, create EAN 13 image in iPad applications.
www.OnBarcode.com
Printing Code 128 In Java
Using Barcode generator for Android Control to generate, create Code 128B image in Android applications.
www.OnBarcode.com
APPEN DI X B CAS E S TUD Y: A WEB S ERVI CE D RI VEN SH OPPI NG C ART
ANSI/AIM Code 39 Drawer In None
Using Barcode encoder for Font Control to generate, create Code 39 image in Font applications.
www.OnBarcode.com
Code128 Generation In Visual Basic .NET
Using Barcode creation for Visual Studio .NET Control to generate, create USS Code 128 image in .NET framework applications.
www.OnBarcode.com
Creating the Shopping Cart
Now that you have created the Ecommerce web service, you are ready to consume it in a client application. To do so, add a new website to the web service project you just created. Add three web forms to the website: Default.aspx, ShoppingCart.aspx, and Success.aspx. The Default.aspx web form will act as a product catalog and displays a list of products. Users can add items from the product catalog to their shopping cart. The shopping cart is displayed on ShoppingCart.aspx. Users can add, modify, or remove selected items here. When the order is placed successfully, the Success.aspx web form displays a success message to the end user.
Copyright © OnBarcode.com . All rights reserved.