download AddItemResult.ascx.cs
Language: C#
LOC: 98
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_AddItemResult : System.Web.UI.UserControl
{
    protected DataSet ds;
    protected DataRow drLastAdded=null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Request["cmspagemode"] == "edit")
        {
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl("<p class=\"cmsDefaultEmptyControl\">This page is currently in edit mode</p>"));
            return;
        }

        if (!Page.IsPostBack) {
          LoadLists();
        } else {
            return;
        }
    }
    void LoadLists()
    {
        ds = ProductController.GetPostAddPage();
        //multi set return
        //0=recently added item 
        //1=recently viewed
        //2=Cross Sells
        if (ds != null) {
            if (ds.Tables[0].Rows.Count > 0) {
                drLastAdded = ds.Tables[0].Rows[0];
                LoadJustAdded(drLastAdded);
            } else {
                Response.Redirect("basket.aspx", false);
            }

            if (ds.Tables[2] != null) {
                dtCrossProducts.DataSource = ds.Tables[2];
                dtCrossProducts.DataBind();
            }

            if (ds.Tables[1] != null) {
                dtRecent.DataSource = ds.Tables[1];
                dtRecent.DataBind();
            }

            pnlCross.Visible = dtCrossProducts.Items.Count > 0;
            pnlRecent.Visible = dtRecent.Items.Count > 0;

        } else {
            Response.Redirect("basket.aspx", false);
        }

    }

    void LoadJustAdded(DataRow dr)
    {
        OrderItem item = new OrderItem();
        item.Load(dr);
				if((item.ImageFile == null) || (item.ImageFile.Length == 0)) {
					imgJustAdded.ImageUrl = "~/images/ProductImages/no_image_available.gif";
				}
				else {
        imgJustAdded.ImageUrl = "~/" + item.ImageFile;
				}
        lblJustAddedLineTotal.Text = item.LineTotal.ToString("c");
        lblJustAddedOurPrice.Text = item.PricePaid.ToString("c");
        lblJustAddedRetail.Text = item.OriginalPrice.ToString("c");
        lblJustAddedQuantity.Text = item.Quantity.ToString();
        lblJustAddedName.Text = item.ProductName.ToString();
		lblSelectedAtts.Text = item.Attributes;
    }
    
    protected void lnkAddRecent(object sender, DataListCommandEventArgs e)
    {
        Label lblProductID = (Label)e.Item.FindControl("lblProductID");
        if (lblProductID != null)
        {

            //there's no attribute selection here
            //so if this product is in the basket
            //it will be doubled up
            AddToCart(int.Parse(lblProductID.Text));
            
        }
        Response.Redirect("additemresult.aspx", false);
    }
    
    protected void lnkAddCross(object sender, DataListCommandEventArgs e)
    {
        Label lblProductID = (Label)e.Item.FindControl("lblProductID");
        if (lblProductID != null)
        {
            AddToCart(int.Parse(lblProductID.Text));
            
        }
        Response.Redirect("additemresult.aspx", false);

    }
    
    protected void AddToCart(int productID)
    {
        Commerce.Common.Product prod = new Commerce.Common.Product(productID);
        prod.Quantity = 1;
        prod.ImageFile = prod.DefaultImage;
        //prod.SelectedAttributes = "";
        prod.PromoCode = "";
        prod.DiscountAmount = 0;

        OrderController.AddItem(prod);

    }

}

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