CS 3870 Prog5 Shopping Bag
Prog 5 MainMasterPage Prog5MasterPage same as Prog4 Create a new master page
Prog 5 New folder Prog5 New pages Default.aspx Updating.aspx Shoppin.aspx Checkout.aspx Then could copy content from Prog4 Modify as necessary
Prog 5 Do them after Shopping Bag is completed Main Web Site folder Login.aspx CreateUser.aspx UserName: csse cs3870@UWP Do them after Shopping Bag is completed
New Page Checkout Maintain a shopping bag for each session Add items into the shopping bag when shopping GridView to display all items in the shopping bag on checkout Clear the bag when checkout
Shopping Bag Your Choice DataTable ArrayList New class: in folder App_Code . . .
Shopping Bag: Using DataTable // SQLDataClass using System.Data; public static DataTable NewShoppingBag() { DataTable table = new DataTable(); table.Columns.Add("ProductID"); table.Columns.Add("ProductName"); table.Columns.Add("Quantity"); table.Columns.Add("UnitPrice"); table.Columns.Add("Cost"); table.PrimaryKey = new DataColumn[] { table.Columns[0] }; return table; }
Global.vb void Session_Start(object sender, EventArgs e) { //Prog5 Session["Prog5_Bag"] = SQLDataClass.NewShoppingBag(); }
Page Shopping //New Button “Add to Shopping Bag” //Adds the last calculated item to the shopping bag. protected void btnAddToBag_Click(object sender, EventArgs e) { DataTable bag = (DataTable) Session["Prog5_Bag"]; DataRow row = bag.NewRow(); row[0] = txtID.Text; row[1] = txtName.Text; row[2] = txtPrice.Text; row[3] = txtQuantity.Text; row[4] = txtSubTotal.Text; DataRow oldRow = bag.Rows.Find(row[0]); if (oldRow != null) bag.Rows.Remove(oldRow); bag.Rows.Add(row); . . . }
Page Checkout protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = (DataTable)Session["Prog5_Bag"]; GridView1.DataBind(); }
Page Checkout protected void btnCheckout_Click(. . .) { // End the current session // will clear all session variables Session.Abandon(); // Logout of Membership FormsAuthentication.SignOut() // Go to Login.aspx // Response.Redirect("~/Login.aspx"); Response.Redirect(FormsAuthentication.LoginUrl); }