download ShoppingBasket.ascx.cs
Language: C#
LOC: 109
Project Info
commercefinity - An open source eCommerce ...odule(commercefinity)
Server: Google
Type: svn
...runk\Commerce\PageControls\
   AddItemResult.ascx
   AddItemResult.ascx.cs
   Catalog.ascx
   Catalog.ascx.cs
   Checkout.ascx
   Checkout.ascx.cs
   MyOrders.ascx
   MyOrders.ascx.cs
   PPCheckout.ascx
   PPCheckout.ascx.cs
   Product.ascx
   Product.ascx.cs
   Receipt.ascx
   Receipt.ascx.cs
   ShoppingBasket.ascx
   ShoppingBasket.ascx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Commerce.Common;

public partial class Commerce_PageControls_ShoppingBasket : System.Web.UI.UserControl
{
    protected DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        pnlNada.Visible = false;
        if (!Page.IsPostBack)
        {
            BindBasket();
        }
    }
    void BindBasket()
    {

        int orderID = OrderController.GetCartOrderID();
        Order currentOrder = null;
        if (orderID != 0)
        {
            currentOrder = OrderController.GetOrder(orderID);
            //Load up the no_image_available.gif image in the event there is no ImageFile
            OrderItemCollection orderItemCollection = currentOrder.Items;
            foreach (OrderItem currentItem in orderItemCollection)
            {
                if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))
                {
                    currentItem.ImageFile = "images/ProductImages/no_image_available.gif";
                }
                else
                {
                    currentItem.ImageFile = Utility.GetThumbnail(currentItem.ImageFile);
                }
            }
            //Bind it up
            rptBasket.DataSource = currentOrder.Items;
            rptBasket.DataBind();

            if (rptBasket.Items.Count == 0)
                HideBits();

            lblSubtotal.Text = currentOrder.CalculateSubTotal().ToString("c");
        }
        else
        {
            HideBits();
        }

    }

    void rptBasket_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        throw new Exception("The method or operation is not implemented.");

    }


    void HideBits()
    {
        btnAdjust.Visible = false;
        pnlCheckout.Visible = false;
        lblSubtotal.Visible = false;
        pnlNada.Visible = true;

        //give them something to look at, other than a blank page ;)
        dtProducts.DataSource = ProductController.GetMostPopular();
        dtProducts.DataBind();

    }
    protected void DeleteItem(object sender, RepeaterCommandEventArgs e)
    {
        Label lblProductID = (Label)e.Item.FindControl("lblProductID");
        Label lblSelectedAtts = (Label)e.Item.FindControl("lblSelectedAtts");
        if (lblProductID != null && lblSelectedAtts != null)
        {
            OrderController.RemoveItem(int.Parse(lblProductID.Text), lblSelectedAtts.Text);
        }
        Response.Redirect("Basket.aspx", false);
    }

    protected void AdjustBasket(object sender, System.EventArgs e)
    {
        TextBox txtQ = null;
        Label lblProductID = null;
        Label lblSelectedAtts = null;
        int productID = 0;
        int newQuantity = 0;
        string selectedAtts = "";
        int orderID = OrderController.GetCartOrderID();

        foreach (RepeaterItem item in rptBasket.Items)
        {
            txtQ = (TextBox)item.FindControl("txtQuantity");
            lblSelectedAtts = (Label)item.FindControl("lblSelectedAtts");
            lblProductID = (Label)item.FindControl("lblProductID");
            if (txtQ != null && lblProductID != null)
            {
                productID = int.Parse(lblProductID.Text);
                if (int.TryParse(txtQ.Text, out newQuantity))
                {
                    if (newQuantity > 0)
                    {
                        selectedAtts = lblSelectedAtts.Text;
                        OrderController.AdjustQuantity(orderID, productID, selectedAtts, newQuantity);
                    }
                    else
                    {
                        OrderController.RemoveItem(productID, selectedAtts);
                    }
                }
            }
        }
        Response.Redirect("Basket.aspx", false);
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us