protected void Page_Load(object sender, EventArgs e) { // Get the upc from the query string. string upc = Request.QueryString["upc"].Trim(); string userName = User.Identity.Name; ShoppingCart cart = (ShoppingCart)HttpContext.Current.Session["MyShoppingCart"]; // Remove the item from the shopping cart. RemoveCart test = new RemoveCart(cart, userName, upc,false); // View the shopping cart. Response.Redirect("~/MemberOnly/ViewShoppingCart.aspx"); }
protected void LoginStatus_LoggingOut(object sender, EventArgs e) { string userName = HttpContext.Current.User.Identity.Name; ShoppingCart cart = ShoppingCart.GetShoppingCart(userName); RemoveCart removeall; List<string> upc = new List<string>{}; foreach (CartItem item in cart.Items) upc.Add(item.UPC); foreach(string UPC in upc) removeall = new RemoveCart(cart, userName, UPC, true); cart.Items.Clear(); }
public static void CheckOutOfTime(string connectionString, string UserName) { string query = "SELECT [lastSeen] FROM [Member] WHERE ([userName] = N'" + UserName + "')"; using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString)) using (SqlCommand command = new SqlCommand(query, connection)) { command.Connection.Open(); // Execute the SELECT query and place the result in a DataReader. SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Iterate through the table to get the retrieved values. reader.Read(); if (!reader.IsDBNull(0)) { DateTime Expiry = DateTime.Now.AddMinutes(-15); DateTime LastSeen = reader.GetDateTime(0); if (Expiry > LastSeen) { ShoppingCart cart = ShoppingCart.GetShoppingCart(UserName); RemoveCart removeall; List<string> upc = new List<string> { }; foreach (CartItem item in cart.Items) upc.Add(item.UPC); foreach (string UPC in upc) removeall = new RemoveCart(cart, UserName, UPC, false); cart.Items.Clear(); } } command.Connection.Close(); // Close the connection and the DataReader. reader.Close(); } } return; }