Esempio n. 1
0
    private void RecursivelyPopulateMenuBrands(EasyMenu parentMenuItem, int rows, int columns)
    {
        //check if the product already exists in the cache
        System.Data.DataSet ds = (System.Data.DataSet)HttpContext.Current.Cache["MenuBrands"];

        if (ds == null)
        {
            GoOpticCategoryHelper categoryHelper = new GoOpticCategoryHelper();
            ds = categoryHelper.GetBrandNavigationItems(ZNodeConfigManager.SiteConfig.PortalID);

            HttpContext.Current.Cache["MenuBrands"] = ds;
        }

        parentMenuItem.Align = MenuAlign.Under;
        parentMenuItem.Position = MenuPosition.Horizontal;
        parentMenuItem.ShowEvent = MenuShowEvent.MouseOver;
        if (columns >= 2)
            parentMenuItem.RepeatColumns = 2*columns-1;
        parentMenuItem.Width = (100 * columns).ToString();
        parentMenuItem.UseIcons = true;
        parentMenuItem.ZIndex = 400;
        parentMenuItem.ExpandStyle = ExpandStyle.Slide;
        string iconPath = "~/Images/home/";
        iconPath = iconPath.Replace("~", "");
        parentMenuItem.IconsFolder = iconPath;
        int alphabetLetters = 0;
        string alphabet =String.Empty;
        foreach (DataRow dbRow in ds.Tables[0].Rows)
        {
            string brandName = dbRow["Name"].ToString();
            string firstLetter = brandName.Substring(0, 1);
            if (alphabet != firstLetter)
            {
                alphabet = firstLetter;
                alphabetLetters++;
            }
        }
        int BrandsPerCol=(int)Math.Ceiling((double)(ds.Tables[0].Rows.Count+alphabetLetters)/columns);
        int  brandNo = 0;
        int currentCol = 0;
        alphabet = String.Empty;
        OboutInc.EasyMenu_Pro.MenuItem miBrand;
        foreach (DataRow dbRow in ds.Tables[0].Rows)
        {
            string brandName = dbRow["Name"].ToString();
            string firstLetter= brandName.Substring(0, 1);
            string itemBrandName = brandName.Replace(" ","");

            if (alphabet != firstLetter)
            {
                alphabet = firstLetter;
                miBrand = new OboutInc.EasyMenu_Pro.MenuItem(alphabet, "<span id=\"alphabet\">" + alphabet.ToUpper() + "</span>", "", "", "", "");
                miBrand.Disabled = true;
                if (currentCol == 0)
                {
                    parentMenuItem.AddItemAt(brandNo,miBrand);
                }else{
                    parentMenuItem.AddItemAt((brandNo+1) *(currentCol+1)-1, miBrand);
                }
                brandNo++;
                if (brandNo+1 == BrandsPerCol)
                {
                    currentCol++;
                    brandNo = 0;
                }
            }
            string seoURL = " ";// = childRow["SEOURL"].ToString();
            // seoURL = ZNodeSEOUrl.MakeURL(categoryId, SEOUrlType.Category, seoURL);
            miBrand = new OboutInc.EasyMenu_Pro.MenuItem(itemBrandName, "<span >" + brandName + "</span>", "",seoURL, "", "");//id=\"menu_item\"
                if (currentCol == 0)
                {
                    parentMenuItem.AddItemAt(brandNo, miBrand);
                }
                else
                {
                    parentMenuItem.AddItemAt((brandNo + 1) * (currentCol + 1) - 1, miBrand);
                }
                brandNo++;
                if (brandNo+1 == BrandsPerCol)
                {
                    currentCol++;
                    brandNo = 0;
                }

        }
        int sepCount=1;
        int colSepCount = 1;
        string sepPath = "<img  src=\"~/Images/home/split_brand.jpg\"/>";
        sepPath = sepPath.Replace("~", "");
        for (int i = 0; i < (columns-1) * BrandsPerCol;i++ )
        {
            parentMenuItem.AddSeparatorAt(sepCount, "sep" + sepCount.ToString(), sepPath);
            sepCount+=2*columns-1;
            if ((i + 1)%BrandsPerCol==0)
            {
                colSepCount += 2; sepCount = colSepCount;
            }
        }
    }