Ejemplo n.º 1
0
    // deletes old shopping carts
    protected void deleteButton_Click(object sender, EventArgs e)
    {
        byte days = byte.Parse(daysList.SelectedItem.Value);

        ShoppingCartBLO.DeleteOldCarts(days);
        countLabel.Text = "The old shopping carts were removed from the database";
    }
Ejemplo n.º 2
0
    // fill shopping cart controls with data
    private void PopulateControls()
    {
        // set the title of the page
        this.Title = ShopConfiguration.SiteName + " : Shopping Cart";
        // get the items in the shopping cart
        DataTable dt = ShoppingCartBLO.GetItems();

        // if the shopping cart is empty...
        if (dt.Rows.Count == 0)
        {
            titleLabel.Text        = "Your shopping cart is empty!";
            grid.Visible           = false;
            updateButton.Enabled   = false;
            checkoutButton.Enabled = false;
            totalAmountLabel.Text  = String.Format("{0:c}", 0);
        }
        else
        // if the shopping cart is not empty...
        {
            // populate the list with the shopping cart contents
            grid.DataSource = dt;
            grid.DataBind();
            // setup controls
            titleLabel.Text        = "These are the products in your shopping cart:";
            grid.Visible           = true;
            updateButton.Enabled   = true;
            checkoutButton.Enabled = true;
            // display the total amount
            decimal amount = ShoppingCartBLO.GetTotalAmount();
            totalAmountLabel.Text = String.Format("{0:c}", amount);
        }
    }
Ejemplo n.º 3
0
    // fill the controls with data
    private void PopulateControls()
    {
        // get the items in the shopping cart
        DataTable dt = ShoppingCartBLO.GetItems();

        // if the shopping cart is empty...
        if (dt.Rows.Count == 0)
        {
            cartSummaryLabel.Text = "Your shopping cart is empty.";
            totalAmountLabel.Text = String.Format("{0:c}", 0);
            viewCartLink.Visible  = false;
            list.Visible          = false;
        }
        else
        // if the shopping cart is not empty...
        {
            // populate the list with the shopping cart contents
            list.Visible    = true;
            list.DataSource = dt;
            list.DataBind();
            // setup controls
            cartSummaryLabel.Text = "Cart summary ";
            viewCartLink.Visible  = true;
            // display the total amount
            decimal amount = ShoppingCartBLO.GetTotalAmount();
            totalAmountLabel.Text = String.Format("{0:c}", amount);
        }
    }
Ejemplo n.º 4
0
    // create a new order and redirect to a payment page
    protected void checkoutButton_Click(object sender, EventArgs e)
    {
        // Store the total amount because the cart
        // is emptied when creating the order
        decimal amount = ShoppingCartBLO.GetTotalAmount();
        // Create the order and store the order ID
        string username        = Session["username"] == null ? null : Session["username"].ToString();
        string customerEmail   = Session["useremail"] == null ? null : Session["useremail"].ToString();
        string custoemrAddress = Session["useraddress"] == null ? null : Session["useraddress"].ToString();

        string orderId = ShoppingCartBLO.CreateOrder(username, customerEmail, custoemrAddress);
        // Obtain the site name from the configuration settings
        string siteName = ShopConfiguration.SiteName;
        // Create the PayPal redirect location
        string redirect = "";

        redirect += "https://www.paypal.com/xclick/[email protected]";
        redirect += "&item_name=" + siteName + " Order " + orderId;
        redirect += "&item_number=" + orderId;
        redirect += "&amount=" + String.Format("{0:0.00} ", amount);
        redirect += "&currency=USD";
        redirect += "&return=http://www." + siteName + ".com";
        redirect += "&cancel_return=http://www." + siteName + ".com";
        // Redirect to the payment page
        Response.Redirect(redirect);
    }
Ejemplo n.º 5
0
    // Add the product to cart
    protected void addToCartButton_Click(object sender, EventArgs e)
    {
        // Retrieve ProductID from the query string
        string productId = Request.QueryString["ProductID"];

        // Add the product to the shopping cart
        ShoppingCartBLO.AddItem(productId);
    }
Ejemplo n.º 6
0
    // fires when an Add to Cart button is clicked
    protected void list_ItemCommand(object source, DataListCommandEventArgs e)
    {
        // The CommandArgument of the clicked Button contains the ProductID
        string productId = e.CommandArgument.ToString();

        // Add the product to the shopping cart
        ShoppingCartBLO.AddItem(productId);
    }
Ejemplo n.º 7
0
    // remove a product from the cart
    protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        // Index of the row being deleted
        int rowIndex = e.RowIndex;
        // The ID of the product being deleted
        string productId = grid.DataKeys[rowIndex].Value.ToString();
        // Remove the product from the shopping cart
        bool success = ShoppingCartBLO.RemoveItem(productId);

        // Display status
        statusLabel.Text = success ? "<br />Product successfully removed!<br />" :
                           "<br />There was an error removing the product!<br />";
        // Repopulate the control
        PopulateControls();
    }
Ejemplo n.º 8
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        // Get the currently loaded page
        string currentLocation = Request.AppRelativeCurrentExecutionFilePath;

        // If we're in Product.aspx...
        if (currentLocation == "~/Product.aspx")
        {
            // get the product ID
            string productId = Request.QueryString["ProductID"];
            // get product recommendations
            DataTable table;
            // display recommendations
            table           = CatalogBLO.GetRecommendations(productId);
            list.DataSource = table;
            list.DataBind();
            // display header
            if (table.Rows.Count > 0)
            {
                recommendationsHeader.Text =
                    "Customers who bought this product also bought:";
            }
            else
            {
                recommendationsHeader.Text = "";
            }
        }
        // If we're in ShoppingCart.aspx...
        else if (currentLocation == "~/ShoppingCart.aspx")
        {
            // get product recommendations
            DataTable table;
            // display recommendations
            table           = ShoppingCartBLO.GetRecommendations();
            list.DataSource = table;
            list.DataBind();
            // display header
            if (table.Rows.Count > 0)
            {
                recommendationsHeader.Text =
                    "Customers who bought these products also bought:";
            }
            else
            {
                recommendationsHeader.Text = "";
            }
        }
    }
Ejemplo n.º 9
0
    // counts old shopping carts
    protected void countButton_Click(object sender, EventArgs e)
    {
        byte days     = byte.Parse(daysList.SelectedItem.Value);
        int  oldItems = ShoppingCartBLO.CountOldCarts(days);

        if (oldItems == -1)
        {
            countLabel.Text = "Could not count the old shopping carts!";
        }
        else if (oldItems == 0)
        {
            countLabel.Text = "There are no old shopping carts.";
        }
        else
        {
            countLabel.Text = "There are " + oldItems.ToString() +
                              " old shopping carts.";
        }
    }
Ejemplo n.º 10
0
    // update shopping cart product quantities
    protected void updateButton_Click(object sender, EventArgs e)
    {
        // Number of rows in the GridView
        int rowsCount = grid.Rows.Count;
        // Will store a row of the GridView
        GridViewRow gridRow;
        // Will reference a quantity TextBox in the GridView
        TextBox quantityTextBox;
        // Variables to store product ID and quantity
        string productId;
        int    quantity;
        // Was the update successful?
        bool success = true;

        // Go through the rows of the GridView
        for (int i = 0; i < rowsCount; i++)
        {
            // Get a row
            gridRow = grid.Rows[i];
            // The ID of the product being deleted
            productId = grid.DataKeys[i].Value.ToString();
            // Get the quantity TextBox in the Row
            quantityTextBox = (TextBox)gridRow.FindControl("editQuantity");
            // Get the quantity, guarding against bogus values
            if (Int32.TryParse(quantityTextBox.Text, out quantity))
            {
                // Update product quantity
                success = success && ShoppingCartBLO.UpdateItem(productId, quantity);
            }
            else
            {
                // if TryParse didn't succeed
                success = false;
            }
            // Display status message
            statusLabel.Text = success ?
                               "<br />Your shopping cart was successfully updated!<br />" :
                               "<br />Some quantity updates failed! Please verify your cart!<br />";
        }
        // Repopulate the control
        PopulateControls();
    }