download Catalog.ascx.cs
Language: C#
LOC: 132
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;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

public partial class Commerce_PageControls_Catalog : System.Web.UI.UserControl
{
    protected string thisLink = "";
    protected string categoryName = "";
    protected int categoryID = 0;
    protected string categoryGUID = string.Empty;
    DataSet ds = null;

    protected void Page_Load(object sender, EventArgs e)
    {


        //this page can be accessed using a CategoryID (cid)
        //or by categoryName using the UrlRewriter

        categoryID = Utility.GetIntParameter("cid");
        categoryName = Utility.GetParameter("n");
        categoryGUID = Utility.GetParameter("guid");

        if (!Page.IsPostBack)
            LoadData();


        //###############################################################################
        //  Page Validators - these must be implemented or they will be redirected
        //###############################################################################
        try
        {
            TestCondition.IsTrue(ds.Tables.Count == 6, "Invalid Query");
            TestCondition.IsTrue(ds.Tables[0].Rows.Count > 0, "Invalid Query");
        }
        catch (Exception ex)
        {
            ExceptionPolicy.HandleException(ex, "Application Exception");
            //Response.Redirect(Page.ResolveUrl("~/ExceptionPage.aspx"), false);
        }
        //##############################################################################

        //track this
        LoadPage();

    }

    void LoadData()
    {
        //this page will bounce if the dataset didn't fire properly

        if (categoryName != string.Empty)
        {
            ds = CategoryController.GetPageByName(categoryName);
            thisLink = Page.ResolveUrl("~/catalog/" + categoryName + ".aspx");
        }
        else if (categoryID != 0)
        {
            ds = CategoryController.GetPageByID(categoryID);

        }
        else if (categoryGUID != string.Empty)
        {
            ds = CategoryController.GetPageByGUID(categoryGUID);
            thisLink = Page.ResolveUrl("~/catalog/" + categoryGUID + ".aspx");
        }

    }

    void LoadPage()
    {
        if (ds != null)
        {
            categoryID = (int)ds.Tables[0].Rows[0]["categoryID"];
            categoryName = ds.Tables[0].Rows[0]["categoryName"].ToString();

            Page.Title = categoryName;

            BindCategoryInfo();
            BindProductList();
            BindSubs();
            LoadCrumbs();
        }

    }
    void BindCategoryInfo()
    {
        Category category = new Category();
        category.Load(ds.Tables[0]);

        lblSubHead.Text = category.CategoryName;

        if (category.ImageFile != string.Empty)
        {
            imgHead.ImageUrl = category.ImageFile;
        }
        else
        {
            imgHead.Visible = false;
        }
        lblDescription.Text = category.LongDescription;

    }
    void BindProductList()
    {

        //the product list is effected by 2 things
        //if it's a straight cateogry view or
        //a "Narrow By" view
        int manID = Utility.GetIntParameter("m");
        string sPriceStart = Utility.GetParameter("ps");
        string sPriceEnd = Utility.GetParameter("pe");
        decimal priceStart = 0;
        decimal priceEnd = 0;

        if (sPriceStart != string.Empty)
            priceStart = decimal.Parse(sPriceStart);


        if (sPriceEnd != string.Empty)
            priceEnd = decimal.Parse(sPriceEnd);

        //if the manufacturer or the price range was sent in
        //grab the reader and use it to populate the product list
        if (manID > 0)
        {
            dtProducts.DataSource = ProductController.GetByManufacturerID(categoryID, manID);
        }
        else if (priceStart >= 0 && priceEnd > 0)
        {

            dtProducts.DataSource = ProductController.GetByPriceRange(categoryID, priceStart, priceEnd);

        }
        else
        {
            dtProducts.DataSource = ds.Tables[4];

        }


        dtProducts.DataBind();
    }
    void BindSubs()
    {
        if (ds.Tables[1].Rows.Count > 0)
        {
            rptSubs.DataSource = ds.Tables[1];
            rptSubs.DataBind();
        }
        else
        {
            rptSubs.Visible = false;
        }

    }
    void LoadCrumbs()
    {
        DataRow dr;
        int lastCount = 0;
        for (int i = 0; i < ds.Tables[5].Rows.Count - 1; i++)

        {
            dr = ds.Tables[5].Rows[i];

            lblBreadCrumb.Text += "<a href='" + Utility.GetRewriterUrl("catalog", dr["Category"].ToString() + "_" + dr["CategoryID"].ToString(), "" ) + "'>" + dr["Category"] + "</a> &raquo; ";
            //lblBreadCrumb.Text += " <a href='" + Utility.GetAppPath() + "/catalog/" + dr["Category"].ToString() + "_" + dr["categoryID"] + ".aspx'>" + dr["Category"] + "</a> &raquo; ";
            lastCount++;

        }
        lblBreadCrumb.Text += ds.Tables[5].Rows[lastCount]["Category"].ToString();

    }

}

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