Shopping Cart Demo.

Slides:



Advertisements
Similar presentations
Coding ADO.Net DataSet Objects ISYS 512. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set.
Advertisements

Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user.
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys Define.
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys Define.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
Shopping Cart Demo. Shopping Cart Search and display product information Add item to cart View cart contents Check out Note: WebsiteCart.
ASP.NET and ADO.NET. ASP.NET Server Controls Intrinsic Controls: These controls correspond to their HTML counterparts. –Ex. Textbox, listbox, button,
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
Coding ADO.NET Objects: Connection, Command, DataReader.
Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows.
ASP.Net AJAX. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc.
Shopping Cart. ASP.NET State Management Session: User state Application: Application state Cache Static variables: –Public Shared interestRate as Single.
ASP.NET and ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Shopping Cart. ASP.NET State Management Session: User state Application: Application state Cache Static variables: –Public Shared interestRate as Single.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
Web Site Security ISYS 512/812. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows:
Coding ADO.NET Objects: Connection, Command, DataReader.
Working with Session and Application Objects. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to Web Application Development with.Net and Web Service ISYS 350.
ASP.NET and ADO.NET. Bind the DataReader to a DataGrid Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn.
Introduction to ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Coding ADO.NET Objects: Connection, Command, DataReader.
Working with Session. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and lose their values.
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys: A collection.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
Website Security ISYS 512. Cookies Data in Cookies System.Web Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One.
Shopping Cart. Search and display product information Add item to cart View cart contents Check out.
Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in.
Introduction to ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX.
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys: A collection.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
Working with GridView Control: Adding Columns. Adding Buttons to a Bound GridView: 1. Drag the WebProduct table from Data connection to a page 2. Demo.
Working with the Application Object. Session VS Application Object The Session object helps to preserve data on a per user basis. What if we want to initialize.
ASP.NET Rina Zviel-Girshin Lecture 5
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user.
Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in.
ASP.Net and HTML. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data.
Command Object’s ExecuteNonQuery Method ISYS 512.
ASP.NET Binding and an Introduction to Database Queries Please use speaker notes for additional information!
CSCI 4230 Homework #3 Group Three Samer Al Jefri * Kevin Odom * David Hood * JD * Phil.
1 CS387/CS587: Note 08 Shopping Bag DataTable. 2 DataClass Public Shared Function NewShoppingBag() As Data.DataTable Dim bag As New Data.DataTable bag.Columns.Add("Product.
Introduction to XML and Web Service ISYS 512/812.
Working With ASP.NET Application. Create a new virtual directory The procedure to create a new virtual directory Internet Services Manager Right click.
AJAX Asynchronous JavaScript and XML: –JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc. Partial refresh:
Coding ADO.NET Objects: Connection, Command, DataReader.
1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
DataGridView. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
Coding ADO.Net DataSet Objects ISYS 512. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set.
PLACING ORDERS- SHOPPPING CARTS. Introduction There are several stages to the order process, starting with an order page, which allows customers to add.
Shopping Cart Demo. Shopping Cart Search and display product information Add item to cart View cart contents Check out.
Coding ADO.NET Objects: Connection, Command, DataReader.
Coding ADO.NET Objects: Connection, Command, DataReader
SQL commands from C# and ASP.net
ASP.NET and ADO.NET.
CS 3870 Prog5 Shopping Bag.
CS 3870 Web User Control Events.
Coding ADO.NET Objects: Connection, Command, DataReader
Database Handling Class and Service
ASP.NET and ADO.NET.
VB Classes ISYS 512.
Grocery Store Outline csc242 – web programming.
Working with Session and Application Objects
Introduction to ADO.NET
Command Object’s ExecuteNonQuery Method
Presentation transcript:

Shopping Cart Demo

Shopping Cart Search and display product information Add item to cart Delete item from cart View cart contents Change quantities of a cart item Check out Note: Project: ShopCart

Shopping Cart Example Database: OrderID: SessionID WebCustomer: CustID, CustName, Addr, Phone, Email WebOrder: OrderID, CustID, OrderDate, CreditCardType, CreditCardNo WebLine: OrderID, PID, Qty WebProduct: Pid, Pname, Price, UnitsInStock OrderID: SessionID Login user using cookie

Implementing Shopping Cart as Class Shopping Cart Properties: public string oid; public string cid; public DateTime ODate; public string CreditCardType; public string CreditCardNo; public List<CartLine> detailLines = new List<CartLine>(); public double CartTotal **** Read only calculated property Methods: AddItem, DeleteItem, ViewCart, CheckOut DetailLine Properties: OID PID Pname Price Qty Amount = Qty * Price **** read only calculated property

Adding a Class to a Website Project/Add Class

ShopCart Class Properties public string oid { get; set; } public string cid { get; set; } public DateTime ODate { get; set; } public string CreditCardType { get; set; } public string CreditCardNo { get; set; } public List<CartLine> detailLines = new List<CartLine>(); public double CartTotal { get { double total=0; foreach (CartLine item in detailLines) { total+=item.amount; } return total; } }

AddItem Method public void AddItem(CartLine line) { Boolean incart=false; if (detailLines.Count>0) foreach(CartLine item in detailLines) if (item.pid==line.pid) item.qty=line.qty; incart=true; break; } if (incart==false) detailLines.Add(line);

public void deleteItem(int deleteIndex) { detailLines.RemoveAt(deleteIndex); } public void checkOut() string strConn = "Data Source=(localdb)\\projects;Initial Catalog=SalesDB;Integrated Security=True"; SqlConnection objConn = new SqlConnection(strConn); string strSQL = "insert into weborder values ('" + oid + "','" + cid + "','" + ODate.ToString() + "','" + CreditCardType + "','" + CreditCardNo + "')"; SqlCommand objComm = new SqlCommand(strSQL,objConn); objConn.Open(); objComm.ExecuteNonQuery(); foreach(CartLine objLine in detailLines) strSQL = "insert into webline values ('" + objLine.oid + "','" + objLine.pid + "'," + objLine.qty.ToString() + ")"; objComm.CommandText = strSQL; objConn.Close(); }

CartLine Class { public string oid { get; set; } public class CartLine { public string oid { get; set; } public string pid { get; set; } public string pname { get; set; } public double price { get; set; } public double qty { get; set; } public double amount { get {return qty*price;}} }

Home Page Reading cookie: ViewProduct button event: protected void Page_Load(object sender, EventArgs e) { String CID; CID = Request.Cookies["CID"].Value; Session["CID"] = CID; } ViewProduct button event: ShopCart MyCart = new ShopCart(); MyCart.oid = Session.SessionID; MyCart.cid = (string)Session["CID"]; Session["MyCart"] = MyCart; Response.Redirect("ViewProduct.aspx");

ViewProduct PageLoad event DataSet objDataSet = new DataSet(); ShopCart MyCart = new ShopCart(); protected void Page_Load(object sender, EventArgs e) { string strConn = "Data Source=(localdb)\\projects;Initial Catalog=SalesDB;Integrated Security=True"; SqlConnection objConn = new SqlConnection(strConn); string strSQL = "select * from WebProducts;"; SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL,strConn); if (!Page.IsPostBack) objAdapter.Fill(objDataSet, "WebProducts"); Session["MyDs"]= objDataSet; } else MyCart = (ShopCart)Session["MyCart"]; objDataSet = (DataSet)Session["MyDs"];

Price Radiobutton Event DataView objDataView = new DataView(); objDataView = objDataSet.Tables["WebProducts"].DefaultView; objDataView.RowFilter = "price " + RadioButtonList1.SelectedValue.ToString(); GridView1.DataSource = objDataView; GridView1.DataBind();

AddToCart Event CartLine objLine = new CartLine(); MyCart = (ShopCart)Session["MyCart"]; objLine.oid = MyCart.oid; objLine.pid = GridView1.SelectedRow.Cells[0].Text; objLine.pname = GridView1.SelectedRow.Cells[1].Text; objLine.price = double.Parse(GridView1.SelectedRow.Cells[2].Text); TextBox t = (TextBox)(GridView1.SelectedRow.Cells[4].Controls[1]); objLine.qty = double.Parse(t.Text); MyCart.AddItem(objLine); Response.Write("number of items in cart:" + MyCart.detailLines.Count.ToString()); Session["MyCart"] = MyCart;

ViewCart event DeleteLine event: ShopCart MyCart = new ShopCart(); protected void Page_Load(object sender, EventArgs e) { MyCart =(ShopCart) Session["MyCart"]; GridView1.DataSource = MyCart.detailLines; GridView1.DataBind(); TextBox1.Text = MyCart.CartTotal.ToString("C"); } DeleteLine event: MyCart.deleteItem(e.RowIndex); Session["MyCart"] = MyCart; GridView1.DataSource = MyCart.detailLines; GridView1.DataBind(); TextBox1.Text = MyCart.CartTotal.ToString("C");

CheckOut Procedure ShopCart MyCart = new ShopCart(); protected void Page_Load(object sender, EventArgs e) { MyCart = (ShopCart) Session["MyCart"]; } protected void Button1_Click(object sender, EventArgs e) MyCart.ODate = DateTime.Now; MyCart.CreditCardType = RadioButtonList1.SelectedValue.ToString(); MyCart.CreditCardNo = TextBox1.Text; MyCart.checkOut(); Response.Write("<p align='center'><font size='5'><b>Thank you for shopping at My.Com</b></font></p>"); Session.Abandon();

Cookies

Data in Cookies System.Web Which web site set the cookie Expiration date DateTime data type TimeSpan data type One or more pieces of data Keys: A collection of cookie’s names Define a new cookie: HttpCookie cookieCID = new HttpCookie("CID"); Write cookie to user: Response.Cookies.Add(cookieCID);

Cookie’s Properties Properties To write a cookie: Name Value Expires Response.Cookies.Add(cookieObj)

Creating Cookies DateTime dt; dt=DateTime.Now; TimeSpan ts = new TimeSpan(30,0,0,0); HttpCookie cookieCID = new HttpCookie("CID"); HttpCookie cookieCname = new HttpCookie("Cname"); cookieCID.Value = Login1.UserName; cookieCID.Expires = dt.Add(ts); Response.Cookies.Add(cookieCID); Note: The name(or key)of cookieCID is "CID";

Reading Cookies Response.Write(Request.Cookies["CID"].Name); Response.Write(Request.Cookies["CID"].Value);

Using Cookie with DataReader string strConn = "Data Source=(localdb)\\projects;Initial Catalog=SalesDB;Integrated Security=True"; SqlConnection objConn = new SqlConnection(strConn); String CID; CID = Request.Cookies["CID"].Value; string strSQL = "select * from webcustomer where CustID= '" + CID + "'"; SqlCommand objComm = new SqlCommand(strSQL, objConn); SqlDataReader objDataReader; objConn.Open(); objDataReader = objComm.ExecuteReader(); if (objDataReader.Read()) { Session["Cname"] = objDataReader["CustName"]; Response.Write("<hr>Welcome:" + objDataReader["CustName"] + "<hr>"); } else Response.Write("<hr>We don't have your record <hr>"); objConn.Close();