Advertisement
Guest User

Untitled

a guest
Aug 15th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using System.Web.UI.HtmlControls;
  7.  
  8. using Crafted.Helpers;
  9. using Crafted.ECommerce.BO;
  10. using Crafted.ECommerce.CL;
  11. using Crafted.ECommerce.DAL;
  12.  
  13. namespace Crafted.Bonlays.UserControls
  14. {
  15.     public partial class SideMenu : System.Web.UI.UserControl
  16.     {
  17.         private bool useImage = false;
  18.  
  19.         protected void Page_Load(object sender, EventArgs e)
  20.         {
  21.  
  22.         }
  23.  
  24.         public bool GroupLink
  25.         {
  26.             get
  27.             {
  28.                 return !litGroupName.Visible;
  29.             }
  30.             set
  31.             {
  32.                 litGroupName.Visible = !value;
  33.                 lnkGroupName.Visible = value;
  34.             }
  35.         }
  36.  
  37.         public bool UseImage
  38.         {
  39.             get { return this.useImage; }
  40.             set { this.useImage = value; }
  41.         }
  42.  
  43.  
  44.         public CategoryGroup Group
  45.         {
  46.             set
  47.             {
  48.                 lnkGroupName.NavigateUrl = UrlHelper.Url(UrlHelper.PageType.CategoryGroup, value, false);
  49.                 lnkGroupName.Text = value.Name;
  50.                 litGroupName.Text = String.Format("<span>{0}</span>", value.Name);
  51.                 rptCategories.DataSource = value.Categories;
  52.                 rptCategories.DataBind();
  53.                 pnlMenu.Visible = rptCategories.Items.Count != 0;
  54.             }
  55.         }
  56.  
  57.         public void RenderAllGroups(CategoryGroupCollection cgl)
  58.         {
  59.             string cat = "Categories";
  60.             this.lnkGroupName.NavigateUrl = "/";
  61.             this.lnkGroupName.Text = cat;
  62.             this.litGroupName.Text = string.Format("<span>{0}</span>", cat);
  63.             this.rptGroups.DataSource = cgl;
  64.             this.rptGroups.DataBind();
  65.             this.pnlMenu.Visible = true;
  66.             this.pnlMenuSingle.Visible = false;
  67.             this.pnlMenuMulti.Visible = true;
  68.         }
  69.  
  70.         public void rptCategories_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  71.         {
  72.             if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
  73.             {
  74.                 Category category = (Category)e.Item.DataItem;
  75.                 HyperLink lnkCategory = (HyperLink)e.Item.FindControl("lnkCategory");
  76.                 Literal litCategory = (Literal)e.Item.FindControl("litCategory");
  77.                 HtmlGenericControl liCategory = (HtmlGenericControl)e.Item.FindControl("liCategory");
  78.  
  79.                 HtmlGenericControl liSubCategory = (HtmlGenericControl)e.Item.FindControl("liSubCategory");
  80.                 Image imgMan = (Image)e.Item.FindControl("imgMan");
  81.                 PlaceHolder pnlSubCategories = (PlaceHolder)liSubCategory.FindControl("pnlSubCategories");
  82.  
  83.  
  84.                 //PlaceHolder pnlSubCategories = (PlaceHolder)e.Item.FindControl("pnlSubCategories");
  85.                 Repeater subCategories = (Repeater)e.Item.FindControl("rptSubCategories");
  86.  
  87.                 //If the category is a sub category
  88.                 if (category.ParentCategoryId != 0)
  89.                 {
  90.                     foreach (var topLevelCategory in CategoriesCL.GetTopLevelCategories())
  91.                     {
  92.                         if (category.ParentCategoryId == topLevelCategory.Id) //Match parent
  93.                         {
  94.                             pnlSubCategories.Visible = true;
  95.                             CategoryCollection subCategoriesCollection = CategoriesDALC.GetSubCategories(category.ParentCategoryId); //Get all subcategories for that parent
  96.                             List<Category> sc = new List<Category>(subCategoriesCollection);
  97.                             subCategories.DataSource = sc;
  98.                             subCategories.DataBind();
  99.                         }
  100.                     }
  101.                 }
  102.                 else
  103.                 {
  104.                     pnlSubCategories.Visible = false;
  105.                
  106.                     lnkCategory.NavigateUrl = UrlHelper.Url(UrlHelper.PageType.Category, category, false);
  107.                     litCategory.Text = HttpUtility.HtmlEncode(category.Title);
  108.                     if ((base.Request.QueryString["fullurl"] != null) && base.Request.QueryString["fullurl"].Contains(lnkCategory.NavigateUrl))
  109.                     {
  110.                         lnkCategory.CssClass = "selected";
  111.                     }
  112.                     if (this.UseImage)
  113.                     {
  114.                         litCategory.Visible = false;
  115.                         imgMan.Visible = true;
  116.                         if (category.Imaging.Count > 0)
  117.                         {
  118.                             imgMan.ImageUrl = category.Imaging.MainImage.Images.ByType("Thumbnail").HtmlUrl;
  119.                             imgMan.AlternateText = string.IsNullOrEmpty(category.Imaging.MainImage.AlternateText) ? category.Imaging.MainImage.AlternateText : category.Title;
  120.                         }
  121.                         imgMan.Attributes.Add("style", "padding-left:16px; padding-bottom:10px;");
  122.                         liCategory.Attributes.Add("style", "height:auto;float:left;width:90px;");
  123.                         lnkCategory.Attributes.Add("style", "height: auto; background:#F7F7F4;");
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.  
  129.         public void rptGroups_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  130.         {
  131.             if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
  132.             {
  133.                 CategoryGroup categoryGroup = (CategoryGroup)e.Item.DataItem;
  134.                 HyperLink lnkCategoryGroup = (HyperLink)e.Item.FindControl("lnkCategoryGroup");
  135.                 Literal litCategoryGroup = (Literal)e.Item.FindControl("litCategoryGroup");
  136.                 PlaceHolder pnlShow = (PlaceHolder)e.Item.FindControl("pnlShow");
  137.                 Repeater rptInnerCategories = (Repeater)e.Item.FindControl("rptInnerCategories");
  138.                 lnkCategoryGroup.NavigateUrl = UrlHelper.Url(UrlHelper.PageType.CategoryGroup, categoryGroup, false);
  139.                 litCategoryGroup.Text = HttpUtility.HtmlEncode(categoryGroup.Name);
  140.                 if ((categoryGroup.Categories.Count > 0) && (categoryGroup.Id != CategoriesCL.GetCategoryGroups("manufacturers").Id))
  141.                 {
  142.                     List<Category> cc = new List<Category>(categoryGroup.Categories);
  143.                     cc.Sort(new Comparison<Category>(delegate(Category nameA, Category nameB) { return nameA.Title.ToLower().CompareTo(nameB.Title.ToLower()); }));
  144.                     rptInnerCategories.DataSource = cc;
  145.                     rptInnerCategories.DataBind();
  146.                 }
  147.                 else
  148.                 {
  149.                     pnlShow.Visible = false;
  150.                 }
  151.             }
  152.         }
  153.  
  154.  
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement